Use sc_ prefix for screen

This commit is contained in:
Romain Vimont 2022-01-14 22:17:30 +01:00
parent a6644e831b
commit 2a0c2e5e99
5 changed files with 112 additions and 108 deletions

View file

@ -369,15 +369,15 @@ rotate_device(struct controller *controller) {
} }
static void static void
rotate_client_left(struct screen *screen) { rotate_client_left(struct sc_screen *screen) {
unsigned new_rotation = (screen->rotation + 1) % 4; unsigned new_rotation = (screen->rotation + 1) % 4;
screen_set_rotation(screen, new_rotation); sc_screen_set_rotation(screen, new_rotation);
} }
static void static void
rotate_client_right(struct screen *screen) { rotate_client_right(struct sc_screen *screen) {
unsigned new_rotation = (screen->rotation + 3) % 4; unsigned new_rotation = (screen->rotation + 3) % 4;
screen_set_rotation(screen, new_rotation); sc_screen_set_rotation(screen, new_rotation);
} }
static void static void
@ -544,17 +544,17 @@ input_manager_process_key(struct input_manager *im,
return; return;
case SDLK_f: case SDLK_f:
if (!shift && !repeat && down) { if (!shift && !repeat && down) {
screen_switch_fullscreen(im->screen); sc_screen_switch_fullscreen(im->screen);
} }
return; return;
case SDLK_w: case SDLK_w:
if (!shift && !repeat && down) { if (!shift && !repeat && down) {
screen_resize_to_fit(im->screen); sc_screen_resize_to_fit(im->screen);
} }
return; return;
case SDLK_g: case SDLK_g:
if (!shift && !repeat && down) { if (!shift && !repeat && down) {
screen_resize_to_pixel_perfect(im->screen); sc_screen_resize_to_pixel_perfect(im->screen);
} }
return; return;
case SDLK_i: case SDLK_i:
@ -640,8 +640,9 @@ input_manager_process_mouse_motion(struct input_manager *im,
struct sc_mouse_motion_event evt = { struct sc_mouse_motion_event evt = {
.position = { .position = {
.screen_size = im->screen->frame_size, .screen_size = im->screen->frame_size,
.point = screen_convert_window_to_frame_coords(im->screen, .point = sc_screen_convert_window_to_frame_coords(im->screen,
event->x, event->y), event->x,
event->y),
}, },
.xrel = event->xrel, .xrel = event->xrel,
.yrel = event->yrel, .yrel = event->yrel,
@ -659,7 +660,7 @@ input_manager_process_mouse_motion(struct input_manager *im,
if (im->vfinger_down) { if (im->vfinger_down) {
assert(!im->mp->relative_mode); // assert one more time assert(!im->mp->relative_mode); // assert one more time
struct sc_point mouse = struct sc_point mouse =
screen_convert_window_to_frame_coords(im->screen, event->x, sc_screen_convert_window_to_frame_coords(im->screen, event->x,
event->y); event->y);
struct sc_point vfinger = inverse_point(mouse, im->screen->frame_size); struct sc_point vfinger = inverse_point(mouse, im->screen->frame_size);
simulate_virtual_finger(im, AMOTION_EVENT_ACTION_MOVE, vfinger); simulate_virtual_finger(im, AMOTION_EVENT_ACTION_MOVE, vfinger);
@ -685,7 +686,8 @@ input_manager_process_touch(struct input_manager *im,
struct sc_touch_event evt = { struct sc_touch_event evt = {
.position = { .position = {
.screen_size = im->screen->frame_size, .screen_size = im->screen->frame_size,
.point = screen_convert_drawable_to_frame_coords(im->screen, x, y), .point =
sc_screen_convert_drawable_to_frame_coords(im->screen, x, y),
}, },
.action = sc_touch_action_from_sdl(event->type), .action = sc_touch_action_from_sdl(event->type),
.pointer_id = event->fingerId, .pointer_id = event->fingerId,
@ -734,13 +736,13 @@ input_manager_process_mouse_button(struct input_manager *im,
if (event->button == SDL_BUTTON_LEFT && event->clicks == 2) { if (event->button == SDL_BUTTON_LEFT && event->clicks == 2) {
int32_t x = event->x; int32_t x = event->x;
int32_t y = event->y; int32_t y = event->y;
screen_hidpi_scale_coords(im->screen, &x, &y); sc_screen_hidpi_scale_coords(im->screen, &x, &y);
SDL_Rect *r = &im->screen->rect; SDL_Rect *r = &im->screen->rect;
bool outside = x < r->x || x >= r->x + r->w bool outside = x < r->x || x >= r->x + r->w
|| y < r->y || y >= r->y + r->h; || y < r->y || y >= r->y + r->h;
if (outside) { if (outside) {
if (down) { if (down) {
screen_resize_to_fit(im->screen); sc_screen_resize_to_fit(im->screen);
} }
return; return;
} }
@ -757,7 +759,8 @@ input_manager_process_mouse_button(struct input_manager *im,
struct sc_mouse_click_event evt = { struct sc_mouse_click_event evt = {
.position = { .position = {
.screen_size = im->screen->frame_size, .screen_size = im->screen->frame_size,
.point = screen_convert_window_to_frame_coords(im->screen, event->x, .point = sc_screen_convert_window_to_frame_coords(im->screen,
event->x,
event->y), event->y),
}, },
.action = sc_action_from_sdl_mousebutton_type(event->type), .action = sc_action_from_sdl_mousebutton_type(event->type),
@ -790,7 +793,7 @@ input_manager_process_mouse_button(struct input_manager *im,
((down && !im->vfinger_down && CTRL_PRESSED) || ((down && !im->vfinger_down && CTRL_PRESSED) ||
(!down && im->vfinger_down))) { (!down && im->vfinger_down))) {
struct sc_point mouse = struct sc_point mouse =
screen_convert_window_to_frame_coords(im->screen, event->x, sc_screen_convert_window_to_frame_coords(im->screen, event->x,
event->y); event->y);
struct sc_point vfinger = inverse_point(mouse, im->screen->frame_size); struct sc_point vfinger = inverse_point(mouse, im->screen->frame_size);
enum android_motionevent_action action = down enum android_motionevent_action action = down
@ -819,7 +822,7 @@ input_manager_process_mouse_wheel(struct input_manager *im,
struct sc_mouse_scroll_event evt = { struct sc_mouse_scroll_event evt = {
.position = { .position = {
.screen_size = im->screen->frame_size, .screen_size = im->screen->frame_size,
.point = screen_convert_window_to_frame_coords(im->screen, .point = sc_screen_convert_window_to_frame_coords(im->screen,
mouse_x, mouse_y), mouse_x, mouse_y),
}, },
.hscroll = event->x, .hscroll = event->x,

View file

@ -15,7 +15,7 @@
struct input_manager { struct input_manager {
struct controller *controller; struct controller *controller;
struct screen *screen; struct sc_screen *screen;
struct sc_key_processor *kp; struct sc_key_processor *kp;
struct sc_mouse_processor *mp; struct sc_mouse_processor *mp;
@ -44,7 +44,7 @@ struct input_manager {
struct input_manager_params { struct input_manager_params {
struct controller *controller; struct controller *controller;
struct screen *screen; struct sc_screen *screen;
struct sc_key_processor *kp; struct sc_key_processor *kp;
struct sc_mouse_processor *mp; struct sc_mouse_processor *mp;

View file

@ -36,7 +36,7 @@
struct scrcpy { struct scrcpy {
struct sc_server server; struct sc_server server;
struct screen screen; struct sc_screen screen;
struct stream stream; struct stream stream;
struct decoder decoder; struct decoder decoder;
struct recorder recorder; struct recorder recorder;
@ -192,7 +192,7 @@ handle_event(struct scrcpy *s, const struct scrcpy_options *options,
} }
} }
bool consumed = screen_handle_event(&s->screen, event); bool consumed = sc_screen_handle_event(&s->screen, event);
(void) consumed; (void) consumed;
end: end:
@ -573,7 +573,7 @@ aoa_hid_end:
const char *window_title = const char *window_title =
options->window_title ? options->window_title : info->device_name; options->window_title ? options->window_title : info->device_name;
struct screen_params screen_params = { struct sc_screen_params screen_params = {
.controller = &s->controller, .controller = &s->controller,
.kp = kp, .kp = kp,
.mp = mp, .mp = mp,
@ -596,7 +596,7 @@ aoa_hid_end:
.buffering_time = options->display_buffer, .buffering_time = options->display_buffer,
}; };
if (!screen_init(&s->screen, &screen_params)) { if (!sc_screen_init(&s->screen, &screen_params)) {
goto end; goto end;
} }
screen_initialized = true; screen_initialized = true;
@ -629,7 +629,7 @@ aoa_hid_end:
// Close the window immediately on closing, because screen_destroy() may // Close the window immediately on closing, because screen_destroy() may
// only be called once the stream thread is joined (it may take time) // only be called once the stream thread is joined (it may take time)
screen_hide_window(&s->screen); sc_screen_hide_window(&s->screen);
end: end:
// The stream is not stopped explicitly, because it will stop by itself on // The stream is not stopped explicitly, because it will stop by itself on
@ -652,7 +652,7 @@ end:
file_handler_stop(&s->file_handler); file_handler_stop(&s->file_handler);
} }
if (screen_initialized) { if (screen_initialized) {
screen_interrupt(&s->screen); sc_screen_interrupt(&s->screen);
} }
if (server_started) { if (server_started) {
@ -682,8 +682,8 @@ end:
// Destroy the screen only after the stream is guaranteed to be finished, // Destroy the screen only after the stream is guaranteed to be finished,
// because otherwise the screen could receive new frames after destruction // because otherwise the screen could receive new frames after destruction
if (screen_initialized) { if (screen_initialized) {
screen_join(&s->screen); sc_screen_join(&s->screen);
screen_destroy(&s->screen); sc_screen_destroy(&s->screen);
} }
if (controller_started) { if (controller_started) {

View file

@ -12,7 +12,7 @@
#define DISPLAY_MARGINS 96 #define DISPLAY_MARGINS 96
#define DOWNCAST(SINK) container_of(SINK, struct screen, frame_sink) #define DOWNCAST(SINK) container_of(SINK, struct sc_screen, frame_sink)
static inline struct sc_size static inline struct sc_size
get_rotated_size(struct sc_size size, int rotation) { get_rotated_size(struct sc_size size, int rotation) {
@ -29,7 +29,7 @@ get_rotated_size(struct sc_size size, int rotation) {
// get the window size in a struct sc_size // get the window size in a struct sc_size
static struct sc_size static struct sc_size
get_window_size(const struct screen *screen) { get_window_size(const struct sc_screen *screen) {
int width; int width;
int height; int height;
SDL_GetWindowSize(screen->window, &width, &height); SDL_GetWindowSize(screen->window, &width, &height);
@ -41,7 +41,7 @@ get_window_size(const struct screen *screen) {
} }
static struct sc_point static struct sc_point
get_window_position(const struct screen *screen) { get_window_position(const struct sc_screen *screen) {
int x; int x;
int y; int y;
SDL_GetWindowPosition(screen->window, &x, &y); SDL_GetWindowPosition(screen->window, &x, &y);
@ -54,7 +54,7 @@ get_window_position(const struct screen *screen) {
// set the window size to be applied when fullscreen is disabled // set the window size to be applied when fullscreen is disabled
static void static void
set_window_size(struct screen *screen, struct sc_size new_size) { set_window_size(struct sc_screen *screen, struct sc_size new_size) {
assert(!screen->fullscreen); assert(!screen->fullscreen);
assert(!screen->maximized); assert(!screen->maximized);
SDL_SetWindowSize(screen->window, new_size.width, new_size.height); SDL_SetWindowSize(screen->window, new_size.width, new_size.height);
@ -157,7 +157,7 @@ get_initial_optimal_size(struct sc_size content_size, uint16_t req_width,
} }
static inline void static inline void
screen_capture_mouse(struct screen *screen, bool capture) { sc_screen_capture_mouse(struct sc_screen *screen, bool capture) {
if (SDL_SetRelativeMouseMode(capture)) { if (SDL_SetRelativeMouseMode(capture)) {
LOGE("Could not set relative mouse mode to %s: %s", LOGE("Could not set relative mouse mode to %s: %s",
capture ? "true" : "false", SDL_GetError()); capture ? "true" : "false", SDL_GetError());
@ -168,7 +168,7 @@ screen_capture_mouse(struct screen *screen, bool capture) {
} }
static void static void
screen_update_content_rect(struct screen *screen) { sc_screen_update_content_rect(struct sc_screen *screen) {
int dw; int dw;
int dh; int dh;
SDL_GL_GetDrawableSize(screen->window, &dw, &dh); SDL_GL_GetDrawableSize(screen->window, &dw, &dh);
@ -205,7 +205,7 @@ screen_update_content_rect(struct screen *screen) {
} }
static inline SDL_Texture * static inline SDL_Texture *
create_texture(struct screen *screen) { create_texture(struct sc_screen *screen) {
SDL_Renderer *renderer = screen->renderer; SDL_Renderer *renderer = screen->renderer;
struct sc_size size = screen->frame_size; struct sc_size size = screen->frame_size;
SDL_Texture *texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_YV12, SDL_Texture *texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_YV12,
@ -236,9 +236,9 @@ create_texture(struct screen *screen) {
// Set the update_content_rect flag if the window or content size may have // Set the update_content_rect flag if the window or content size may have
// changed, so that the content rectangle is recomputed // changed, so that the content rectangle is recomputed
static void static void
screen_render(struct screen *screen, bool update_content_rect) { sc_screen_render(struct sc_screen *screen, bool update_content_rect) {
if (update_content_rect) { if (update_content_rect) {
screen_update_content_rect(screen); sc_screen_update_content_rect(screen);
} }
SDL_RenderClear(screen->renderer); SDL_RenderClear(screen->renderer);
@ -282,20 +282,20 @@ screen_render(struct screen *screen, bool update_content_rect) {
// <https://stackoverflow.com/a/40693139/1987178> // <https://stackoverflow.com/a/40693139/1987178>
static int static int
event_watcher(void *data, SDL_Event *event) { event_watcher(void *data, SDL_Event *event) {
struct screen *screen = data; struct sc_screen *screen = data;
if (event->type == SDL_WINDOWEVENT if (event->type == SDL_WINDOWEVENT
&& event->window.event == SDL_WINDOWEVENT_RESIZED) { && event->window.event == SDL_WINDOWEVENT_RESIZED) {
// In practice, it seems to always be called from the same thread in // In practice, it seems to always be called from the same thread in
// that specific case. Anyway, it's just a workaround. // that specific case. Anyway, it's just a workaround.
screen_render(screen, true); sc_screen_render(screen, true);
} }
return 0; return 0;
} }
#endif #endif
static bool static bool
screen_frame_sink_open(struct sc_frame_sink *sink) { sc_screen_frame_sink_open(struct sc_frame_sink *sink) {
struct screen *screen = DOWNCAST(sink); struct sc_screen *screen = DOWNCAST(sink);
(void) screen; (void) screen;
#ifndef NDEBUG #ifndef NDEBUG
screen->open = true; screen->open = true;
@ -306,8 +306,8 @@ screen_frame_sink_open(struct sc_frame_sink *sink) {
} }
static void static void
screen_frame_sink_close(struct sc_frame_sink *sink) { sc_screen_frame_sink_close(struct sc_frame_sink *sink) {
struct screen *screen = DOWNCAST(sink); struct sc_screen *screen = DOWNCAST(sink);
(void) screen; (void) screen;
#ifndef NDEBUG #ifndef NDEBUG
screen->open = false; screen->open = false;
@ -317,8 +317,8 @@ screen_frame_sink_close(struct sc_frame_sink *sink) {
} }
static bool static bool
screen_frame_sink_push(struct sc_frame_sink *sink, const AVFrame *frame) { sc_screen_frame_sink_push(struct sc_frame_sink *sink, const AVFrame *frame) {
struct screen *screen = DOWNCAST(sink); struct sc_screen *screen = DOWNCAST(sink);
return sc_video_buffer_push(&screen->vb, frame); return sc_video_buffer_push(&screen->vb, frame);
} }
@ -326,7 +326,7 @@ static void
sc_video_buffer_on_new_frame(struct sc_video_buffer *vb, bool previous_skipped, sc_video_buffer_on_new_frame(struct sc_video_buffer *vb, bool previous_skipped,
void *userdata) { void *userdata) {
(void) vb; (void) vb;
struct screen *screen = userdata; struct sc_screen *screen = userdata;
// event_failed implies previous_skipped (the previous frame may not have // event_failed implies previous_skipped (the previous frame may not have
// been consumed if the event was not sent) // been consumed if the event was not sent)
@ -359,7 +359,8 @@ sc_video_buffer_on_new_frame(struct sc_video_buffer *vb, bool previous_skipped,
} }
bool bool
screen_init(struct screen *screen, const struct screen_params *params) { sc_screen_init(struct sc_screen *screen,
const struct sc_screen_params *params) {
screen->resize_pending = false; screen->resize_pending = false;
screen->has_frame = false; screen->has_frame = false;
screen->fullscreen = false; screen->fullscreen = false;
@ -502,10 +503,10 @@ screen_init(struct screen *screen, const struct screen_params *params) {
// different HiDPI scaling are connected // different HiDPI scaling are connected
SDL_SetWindowSize(screen->window, window_size.width, window_size.height); SDL_SetWindowSize(screen->window, window_size.width, window_size.height);
screen_update_content_rect(screen); sc_screen_update_content_rect(screen);
if (params->fullscreen) { if (params->fullscreen) {
screen_switch_fullscreen(screen); sc_screen_switch_fullscreen(screen);
} }
#ifdef CONTINUOUS_RESIZING_WORKAROUND #ifdef CONTINUOUS_RESIZING_WORKAROUND
@ -513,9 +514,9 @@ screen_init(struct screen *screen, const struct screen_params *params) {
#endif #endif
static const struct sc_frame_sink_ops ops = { static const struct sc_frame_sink_ops ops = {
.open = screen_frame_sink_open, .open = sc_screen_frame_sink_open,
.close = screen_frame_sink_close, .close = sc_screen_frame_sink_close,
.push = screen_frame_sink_push, .push = sc_screen_frame_sink_push,
}; };
screen->frame_sink.ops = &ops; screen->frame_sink.ops = &ops;
@ -544,29 +545,29 @@ error_destroy_video_buffer:
} }
static void static void
screen_show_window(struct screen *screen) { sc_screen_show_window(struct sc_screen *screen) {
SDL_ShowWindow(screen->window); SDL_ShowWindow(screen->window);
} }
void void
screen_hide_window(struct screen *screen) { sc_screen_hide_window(struct sc_screen *screen) {
SDL_HideWindow(screen->window); SDL_HideWindow(screen->window);
} }
void void
screen_interrupt(struct screen *screen) { sc_screen_interrupt(struct sc_screen *screen) {
sc_video_buffer_stop(&screen->vb); sc_video_buffer_stop(&screen->vb);
fps_counter_interrupt(&screen->fps_counter); fps_counter_interrupt(&screen->fps_counter);
} }
void void
screen_join(struct screen *screen) { sc_screen_join(struct sc_screen *screen) {
sc_video_buffer_join(&screen->vb); sc_video_buffer_join(&screen->vb);
fps_counter_join(&screen->fps_counter); fps_counter_join(&screen->fps_counter);
} }
void void
screen_destroy(struct screen *screen) { sc_screen_destroy(struct sc_screen *screen) {
#ifndef NDEBUG #ifndef NDEBUG
assert(!screen->open); assert(!screen->open);
#endif #endif
@ -579,7 +580,7 @@ screen_destroy(struct screen *screen) {
} }
static void static void
resize_for_content(struct screen *screen, struct sc_size old_content_size, resize_for_content(struct sc_screen *screen, struct sc_size old_content_size,
struct sc_size new_content_size) { struct sc_size new_content_size) {
struct sc_size window_size = get_window_size(screen); struct sc_size window_size = get_window_size(screen);
struct sc_size target_size = { struct sc_size target_size = {
@ -593,7 +594,7 @@ resize_for_content(struct screen *screen, struct sc_size old_content_size,
} }
static void static void
set_content_size(struct screen *screen, struct sc_size new_content_size) { set_content_size(struct sc_screen *screen, struct sc_size new_content_size) {
if (!screen->fullscreen && !screen->maximized) { if (!screen->fullscreen && !screen->maximized) {
resize_for_content(screen, screen->content_size, new_content_size); resize_for_content(screen, screen->content_size, new_content_size);
} else if (!screen->resize_pending) { } else if (!screen->resize_pending) {
@ -607,7 +608,7 @@ set_content_size(struct screen *screen, struct sc_size new_content_size) {
} }
static void static void
apply_pending_resize(struct screen *screen) { apply_pending_resize(struct sc_screen *screen) {
assert(!screen->fullscreen); assert(!screen->fullscreen);
assert(!screen->maximized); assert(!screen->maximized);
if (screen->resize_pending) { if (screen->resize_pending) {
@ -618,7 +619,7 @@ apply_pending_resize(struct screen *screen) {
} }
void void
screen_set_rotation(struct screen *screen, unsigned rotation) { sc_screen_set_rotation(struct sc_screen *screen, unsigned rotation) {
assert(rotation < 4); assert(rotation < 4);
if (rotation == screen->rotation) { if (rotation == screen->rotation) {
return; return;
@ -632,12 +633,12 @@ screen_set_rotation(struct screen *screen, unsigned rotation) {
screen->rotation = rotation; screen->rotation = rotation;
LOGI("Display rotation set to %u", rotation); LOGI("Display rotation set to %u", rotation);
screen_render(screen, true); sc_screen_render(screen, true);
} }
// recreate the texture and resize the window if the frame size has changed // recreate the texture and resize the window if the frame size has changed
static bool static bool
prepare_for_frame(struct screen *screen, struct sc_size new_frame_size) { prepare_for_frame(struct sc_screen *screen, struct sc_size new_frame_size) {
if (screen->frame_size.width != new_frame_size.width if (screen->frame_size.width != new_frame_size.width
|| screen->frame_size.height != new_frame_size.height) { || screen->frame_size.height != new_frame_size.height) {
// frame dimension changed, destroy texture // frame dimension changed, destroy texture
@ -649,7 +650,7 @@ prepare_for_frame(struct screen *screen, struct sc_size new_frame_size) {
get_rotated_size(new_frame_size, screen->rotation); get_rotated_size(new_frame_size, screen->rotation);
set_content_size(screen, new_content_size); set_content_size(screen, new_content_size);
screen_update_content_rect(screen); sc_screen_update_content_rect(screen);
LOGI("New texture: %" PRIu16 "x%" PRIu16, LOGI("New texture: %" PRIu16 "x%" PRIu16,
screen->frame_size.width, screen->frame_size.height); screen->frame_size.width, screen->frame_size.height);
@ -665,7 +666,7 @@ prepare_for_frame(struct screen *screen, struct sc_size new_frame_size) {
// write the frame into the texture // write the frame into the texture
static void static void
update_texture(struct screen *screen, const AVFrame *frame) { update_texture(struct sc_screen *screen, const AVFrame *frame) {
SDL_UpdateYUVTexture(screen->texture, NULL, SDL_UpdateYUVTexture(screen->texture, NULL,
frame->data[0], frame->linesize[0], frame->data[0], frame->linesize[0],
frame->data[1], frame->linesize[1], frame->data[1], frame->linesize[1],
@ -679,7 +680,7 @@ update_texture(struct screen *screen, const AVFrame *frame) {
} }
static bool static bool
screen_update_frame(struct screen *screen) { sc_screen_update_frame(struct sc_screen *screen) {
av_frame_unref(screen->frame); av_frame_unref(screen->frame);
sc_video_buffer_consume(&screen->vb, screen->frame); sc_video_buffer_consume(&screen->vb, screen->frame);
AVFrame *frame = screen->frame; AVFrame *frame = screen->frame;
@ -692,12 +693,12 @@ screen_update_frame(struct screen *screen) {
} }
update_texture(screen, frame); update_texture(screen, frame);
screen_render(screen, false); sc_screen_render(screen, false);
return true; return true;
} }
void void
screen_switch_fullscreen(struct screen *screen) { sc_screen_switch_fullscreen(struct sc_screen *screen) {
uint32_t new_mode = screen->fullscreen ? 0 : SDL_WINDOW_FULLSCREEN_DESKTOP; uint32_t new_mode = screen->fullscreen ? 0 : SDL_WINDOW_FULLSCREEN_DESKTOP;
if (SDL_SetWindowFullscreen(screen->window, new_mode)) { if (SDL_SetWindowFullscreen(screen->window, new_mode)) {
LOGW("Could not switch fullscreen mode: %s", SDL_GetError()); LOGW("Could not switch fullscreen mode: %s", SDL_GetError());
@ -710,11 +711,11 @@ screen_switch_fullscreen(struct screen *screen) {
} }
LOGD("Switched to %s mode", screen->fullscreen ? "fullscreen" : "windowed"); LOGD("Switched to %s mode", screen->fullscreen ? "fullscreen" : "windowed");
screen_render(screen, true); sc_screen_render(screen, true);
} }
void void
screen_resize_to_fit(struct screen *screen) { sc_screen_resize_to_fit(struct sc_screen *screen) {
if (screen->fullscreen || screen->maximized) { if (screen->fullscreen || screen->maximized) {
return; return;
} }
@ -738,7 +739,7 @@ screen_resize_to_fit(struct screen *screen) {
} }
void void
screen_resize_to_pixel_perfect(struct screen *screen) { sc_screen_resize_to_pixel_perfect(struct sc_screen *screen) {
if (screen->fullscreen) { if (screen->fullscreen) {
return; return;
} }
@ -755,20 +756,20 @@ screen_resize_to_pixel_perfect(struct screen *screen) {
} }
static inline bool static inline bool
screen_is_mouse_capture_key(SDL_Keycode key) { sc_screen_is_mouse_capture_key(SDL_Keycode key) {
return key == SDLK_LALT || key == SDLK_LGUI || key == SDLK_RGUI; return key == SDLK_LALT || key == SDLK_LGUI || key == SDLK_RGUI;
} }
bool bool
screen_handle_event(struct screen *screen, SDL_Event *event) { sc_screen_handle_event(struct sc_screen *screen, SDL_Event *event) {
switch (event->type) { switch (event->type) {
case EVENT_NEW_FRAME: case EVENT_NEW_FRAME:
if (!screen->has_frame) { if (!screen->has_frame) {
screen->has_frame = true; screen->has_frame = true;
// this is the very first frame, show the window // this is the very first frame, show the window
screen_show_window(screen); sc_screen_show_window(screen);
} }
bool ok = screen_update_frame(screen); bool ok = sc_screen_update_frame(screen);
if (!ok) { if (!ok) {
LOGW("Frame update failed\n"); LOGW("Frame update failed\n");
} }
@ -780,10 +781,10 @@ screen_handle_event(struct screen *screen, SDL_Event *event) {
} }
switch (event->window.event) { switch (event->window.event) {
case SDL_WINDOWEVENT_EXPOSED: case SDL_WINDOWEVENT_EXPOSED:
screen_render(screen, true); sc_screen_render(screen, true);
break; break;
case SDL_WINDOWEVENT_SIZE_CHANGED: case SDL_WINDOWEVENT_SIZE_CHANGED:
screen_render(screen, true); sc_screen_render(screen, true);
break; break;
case SDL_WINDOWEVENT_MAXIMIZED: case SDL_WINDOWEVENT_MAXIMIZED:
screen->maximized = true; screen->maximized = true;
@ -799,11 +800,11 @@ screen_handle_event(struct screen *screen, SDL_Event *event) {
} }
screen->maximized = false; screen->maximized = false;
apply_pending_resize(screen); apply_pending_resize(screen);
screen_render(screen, true); sc_screen_render(screen, true);
break; break;
case SDL_WINDOWEVENT_FOCUS_LOST: case SDL_WINDOWEVENT_FOCUS_LOST:
if (screen->im.mp->relative_mode) { if (screen->im.mp->relative_mode) {
screen_capture_mouse(screen, false); sc_screen_capture_mouse(screen, false);
} }
break; break;
} }
@ -811,7 +812,7 @@ screen_handle_event(struct screen *screen, SDL_Event *event) {
case SDL_KEYDOWN: case SDL_KEYDOWN:
if (screen->im.mp->relative_mode) { if (screen->im.mp->relative_mode) {
SDL_Keycode key = event->key.keysym.sym; SDL_Keycode key = event->key.keysym.sym;
if (screen_is_mouse_capture_key(key)) { if (sc_screen_is_mouse_capture_key(key)) {
if (!screen->mouse_capture_key_pressed) { if (!screen->mouse_capture_key_pressed) {
screen->mouse_capture_key_pressed = key; screen->mouse_capture_key_pressed = key;
return true; return true;
@ -833,7 +834,7 @@ screen_handle_event(struct screen *screen, SDL_Event *event) {
if (key == cap) { if (key == cap) {
// A mouse capture key has been pressed then released: // A mouse capture key has been pressed then released:
// toggle the capture mouse mode // toggle the capture mouse mode
screen_capture_mouse(screen, !screen->mouse_captured); sc_screen_capture_mouse(screen, !screen->mouse_captured);
return true; return true;
} }
// Do not return, the event must be forwarded to the input // Do not return, the event must be forwarded to the input
@ -860,7 +861,7 @@ screen_handle_event(struct screen *screen, SDL_Event *event) {
break; break;
case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONUP:
if (screen->im.mp->relative_mode && !screen->mouse_captured) { if (screen->im.mp->relative_mode && !screen->mouse_captured) {
screen_capture_mouse(screen, true); sc_screen_capture_mouse(screen, true);
return true; return true;
} }
} }
@ -869,7 +870,7 @@ screen_handle_event(struct screen *screen, SDL_Event *event) {
} }
struct sc_point struct sc_point
screen_convert_drawable_to_frame_coords(struct screen *screen, sc_screen_convert_drawable_to_frame_coords(struct sc_screen *screen,
int32_t x, int32_t y) { int32_t x, int32_t y) {
unsigned rotation = screen->rotation; unsigned rotation = screen->rotation;
assert(rotation < 4); assert(rotation < 4);
@ -906,14 +907,14 @@ screen_convert_drawable_to_frame_coords(struct screen *screen,
} }
struct sc_point struct sc_point
screen_convert_window_to_frame_coords(struct screen *screen, sc_screen_convert_window_to_frame_coords(struct sc_screen *screen,
int32_t x, int32_t y) { int32_t x, int32_t y) {
screen_hidpi_scale_coords(screen, &x, &y); sc_screen_hidpi_scale_coords(screen, &x, &y);
return screen_convert_drawable_to_frame_coords(screen, x, y); return sc_screen_convert_drawable_to_frame_coords(screen, x, y);
} }
void void
screen_hidpi_scale_coords(struct screen *screen, int32_t *x, int32_t *y) { sc_screen_hidpi_scale_coords(struct sc_screen *screen, int32_t *x, int32_t *y) {
// take the HiDPI scaling (dw/ww and dh/wh) into account // take the HiDPI scaling (dw/ww and dh/wh) into account
int ww, wh, dw, dh; int ww, wh, dw, dh;
SDL_GetWindowSize(screen->window, &ww, &wh); SDL_GetWindowSize(screen->window, &ww, &wh);

View file

@ -17,7 +17,7 @@
#include "trait/mouse_processor.h" #include "trait/mouse_processor.h"
#include "video_buffer.h" #include "video_buffer.h"
struct screen { struct sc_screen {
struct sc_frame_sink frame_sink; // frame sink trait struct sc_frame_sink frame_sink; // frame sink trait
#ifndef NDEBUG #ifndef NDEBUG
@ -59,7 +59,7 @@ struct screen {
AVFrame *frame; AVFrame *frame;
}; };
struct screen_params { struct sc_screen_params {
struct controller *controller; struct controller *controller;
struct sc_key_processor *kp; struct sc_key_processor *kp;
struct sc_mouse_processor *mp; struct sc_mouse_processor *mp;
@ -91,58 +91,58 @@ struct screen_params {
// initialize screen, create window, renderer and texture (window is hidden) // initialize screen, create window, renderer and texture (window is hidden)
bool bool
screen_init(struct screen *screen, const struct screen_params *params); sc_screen_init(struct sc_screen *screen, const struct sc_screen_params *params);
// request to interrupt any inner thread // request to interrupt any inner thread
// must be called before screen_join() // must be called before screen_join()
void void
screen_interrupt(struct screen *screen); sc_screen_interrupt(struct sc_screen *screen);
// join any inner thread // join any inner thread
void void
screen_join(struct screen *screen); sc_screen_join(struct sc_screen *screen);
// destroy window, renderer and texture (if any) // destroy window, renderer and texture (if any)
void void
screen_destroy(struct screen *screen); sc_screen_destroy(struct sc_screen *screen);
// hide the window // hide the window
// //
// It is used to hide the window immediately on closing without waiting for // It is used to hide the window immediately on closing without waiting for
// screen_destroy() // screen_destroy()
void void
screen_hide_window(struct screen *screen); sc_screen_hide_window(struct sc_screen *screen);
// switch the fullscreen mode // switch the fullscreen mode
void void
screen_switch_fullscreen(struct screen *screen); sc_screen_switch_fullscreen(struct sc_screen *screen);
// resize window to optimal size (remove black borders) // resize window to optimal size (remove black borders)
void void
screen_resize_to_fit(struct screen *screen); sc_screen_resize_to_fit(struct sc_screen *screen);
// resize window to 1:1 (pixel-perfect) // resize window to 1:1 (pixel-perfect)
void void
screen_resize_to_pixel_perfect(struct screen *screen); sc_screen_resize_to_pixel_perfect(struct sc_screen *screen);
// set the display rotation (0, 1, 2 or 3, x90 degrees counterclockwise) // set the display rotation (0, 1, 2 or 3, x90 degrees counterclockwise)
void void
screen_set_rotation(struct screen *screen, unsigned rotation); sc_screen_set_rotation(struct sc_screen *screen, unsigned rotation);
// react to SDL events // react to SDL events
bool bool
screen_handle_event(struct screen *screen, SDL_Event *event); sc_screen_handle_event(struct sc_screen *screen, SDL_Event *event);
// convert point from window coordinates to frame coordinates // convert point from window coordinates to frame coordinates
// x and y are expressed in pixels // x and y are expressed in pixels
struct sc_point struct sc_point
screen_convert_window_to_frame_coords(struct screen *screen, sc_screen_convert_window_to_frame_coords(struct sc_screen *screen,
int32_t x, int32_t y); int32_t x, int32_t y);
// convert point from drawable coordinates to frame coordinates // convert point from drawable coordinates to frame coordinates
// x and y are expressed in pixels // x and y are expressed in pixels
struct sc_point struct sc_point
screen_convert_drawable_to_frame_coords(struct screen *screen, sc_screen_convert_drawable_to_frame_coords(struct sc_screen *screen,
int32_t x, int32_t y); int32_t x, int32_t y);
// Convert coordinates from window to drawable. // Convert coordinates from window to drawable.
@ -150,6 +150,6 @@ screen_convert_drawable_to_frame_coords(struct screen *screen,
// drawable coordinates. They are the same if HiDPI scaling is 1, but differ // drawable coordinates. They are the same if HiDPI scaling is 1, but differ
// otherwise. // otherwise.
void void
screen_hidpi_scale_coords(struct screen *screen, int32_t *x, int32_t *y); sc_screen_hidpi_scale_coords(struct sc_screen *screen, int32_t *x, int32_t *y);
#endif #endif