Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6093235a96 | ||
|
|
9307cb3c96 | ||
|
|
350d9bfbfb | ||
|
|
082083b83e | ||
|
|
58c2619a6d | ||
|
|
6ba6ec40e3 | ||
|
|
070525de06 | ||
|
|
3fb0594fe8 | ||
|
|
d470943505 | ||
|
|
1be76c5113 | ||
|
|
6ff4e5c926 | ||
|
|
b2e9270e53 | ||
|
|
f3879fc92d | ||
|
|
042ace4b4e | ||
|
|
f43d66d5d6 | ||
|
|
e1b2824730 | ||
|
|
19b518bf24 | ||
|
|
3ffea72fa6 | ||
|
|
a34bd5c43b |
@@ -126,6 +126,30 @@ sdl_init_and_configure(bool display, const char *render_driver,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(__APPLE__) || defined(__WINDOWS__)
|
||||||
|
# define CONTINUOUS_RESIZING_WORKAROUND
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONTINUOUS_RESIZING_WORKAROUND
|
||||||
|
// On Windows and MacOS, resizing blocks the event loop, so resizing events are
|
||||||
|
// not triggered. As a workaround, handle them in an event handler.
|
||||||
|
//
|
||||||
|
// <https://bugzilla.libsdl.org/show_bug.cgi?id=2077>
|
||||||
|
// <https://stackoverflow.com/a/40693139/1987178>
|
||||||
|
static int
|
||||||
|
event_watcher(void *data, SDL_Event *event) {
|
||||||
|
(void) data;
|
||||||
|
if (event->type == SDL_WINDOWEVENT
|
||||||
|
&& event->window.event == SDL_WINDOWEVENT_RESIZED) {
|
||||||
|
// In practice, it seems to always be called from the same thread in
|
||||||
|
// that specific case. Anyway, it's just a workaround.
|
||||||
|
screen_render(&screen, true);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
is_apk(const char *file) {
|
is_apk(const char *file) {
|
||||||
const char *ext = strrchr(file, '.');
|
const char *ext = strrchr(file, '.');
|
||||||
@@ -165,7 +189,7 @@ handle_event(SDL_Event *event, const struct scrcpy_options *options) {
|
|||||||
action = ACTION_PUSH_FILE;
|
action = ACTION_PUSH_FILE;
|
||||||
}
|
}
|
||||||
file_handler_request(&file_handler, action, file);
|
file_handler_request(&file_handler, action, file);
|
||||||
goto end;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,6 +207,11 @@ end:
|
|||||||
|
|
||||||
static bool
|
static bool
|
||||||
event_loop(const struct scrcpy_options *options) {
|
event_loop(const struct scrcpy_options *options) {
|
||||||
|
#ifdef CONTINUOUS_RESIZING_WORKAROUND
|
||||||
|
if (options->display) {
|
||||||
|
SDL_AddEventWatch(event_watcher, NULL);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
while (SDL_WaitEvent(&event)) {
|
while (SDL_WaitEvent(&event)) {
|
||||||
enum event_result result = handle_event(&event, options);
|
enum event_result result = handle_event(&event, options);
|
||||||
@@ -365,7 +394,6 @@ scrcpy(const struct scrcpy_options *options) {
|
|||||||
.window_borderless = options->window_borderless,
|
.window_borderless = options->window_borderless,
|
||||||
.rotation = options->rotation,
|
.rotation = options->rotation,
|
||||||
.mipmaps = options->mipmaps,
|
.mipmaps = options->mipmaps,
|
||||||
.fullscreen = options->fullscreen,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!screen_init(&screen, &fps_counter, &screen_params)) {
|
if (!screen_init(&screen, &fps_counter, &screen_params)) {
|
||||||
@@ -384,6 +412,10 @@ scrcpy(const struct scrcpy_options *options) {
|
|||||||
LOGW("Could not request 'set screen power mode'");
|
LOGW("Could not request 'set screen power mode'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options->fullscreen) {
|
||||||
|
screen_switch_fullscreen(&screen);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// now we consumed the header values, the socket receives the video stream
|
// now we consumed the header values, the socket receives the video stream
|
||||||
@@ -398,10 +430,6 @@ scrcpy(const struct scrcpy_options *options) {
|
|||||||
ret = event_loop(options);
|
ret = event_loop(options);
|
||||||
LOGD("quit...");
|
LOGD("quit...");
|
||||||
|
|
||||||
// Close the window immediately on closing, because screen_destroy() may
|
|
||||||
// only be called once the stream thread is joined (it may take time)
|
|
||||||
screen_hide_window(&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
|
||||||
// end-of-stream
|
// end-of-stream
|
||||||
|
|||||||
@@ -220,29 +220,6 @@ create_texture(struct screen *screen) {
|
|||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(__APPLE__) || defined(__WINDOWS__)
|
|
||||||
# define CONTINUOUS_RESIZING_WORKAROUND
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CONTINUOUS_RESIZING_WORKAROUND
|
|
||||||
// On Windows and MacOS, resizing blocks the event loop, so resizing events are
|
|
||||||
// not triggered. As a workaround, handle them in an event handler.
|
|
||||||
//
|
|
||||||
// <https://bugzilla.libsdl.org/show_bug.cgi?id=2077>
|
|
||||||
// <https://stackoverflow.com/a/40693139/1987178>
|
|
||||||
static int
|
|
||||||
event_watcher(void *data, SDL_Event *event) {
|
|
||||||
struct screen *screen = data;
|
|
||||||
if (event->type == SDL_WINDOWEVENT
|
|
||||||
&& event->window.event == SDL_WINDOWEVENT_RESIZED) {
|
|
||||||
// In practice, it seems to always be called from the same thread in
|
|
||||||
// that specific case. Anyway, it's just a workaround.
|
|
||||||
screen_render(screen, true);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
screen_frame_sink_open(struct sc_frame_sink *sink) {
|
screen_frame_sink_open(struct sc_frame_sink *sink) {
|
||||||
struct screen *screen = DOWNCAST(sink);
|
struct screen *screen = DOWNCAST(sink);
|
||||||
@@ -425,14 +402,6 @@ screen_init(struct screen *screen, struct fps_counter *fps_counter,
|
|||||||
|
|
||||||
screen_update_content_rect(screen);
|
screen_update_content_rect(screen);
|
||||||
|
|
||||||
if (params->fullscreen) {
|
|
||||||
screen_switch_fullscreen(screen);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef CONTINUOUS_RESIZING_WORKAROUND
|
|
||||||
SDL_AddEventWatch(event_watcher, screen);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static const struct sc_frame_sink_ops ops = {
|
static const struct sc_frame_sink_ops ops = {
|
||||||
.open = screen_frame_sink_open,
|
.open = screen_frame_sink_open,
|
||||||
.close = screen_frame_sink_close,
|
.close = screen_frame_sink_close,
|
||||||
@@ -448,16 +417,11 @@ screen_init(struct screen *screen, struct fps_counter *fps_counter,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
void
|
||||||
screen_show_window(struct screen *screen) {
|
screen_show_window(struct screen *screen) {
|
||||||
SDL_ShowWindow(screen->window);
|
SDL_ShowWindow(screen->window);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
screen_hide_window(struct screen *screen) {
|
|
||||||
SDL_HideWindow(screen->window);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
screen_destroy(struct screen *screen) {
|
screen_destroy(struct screen *screen) {
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
|
|||||||
@@ -62,8 +62,6 @@ struct screen_params {
|
|||||||
|
|
||||||
uint8_t rotation;
|
uint8_t rotation;
|
||||||
bool mipmaps;
|
bool mipmaps;
|
||||||
|
|
||||||
bool fullscreen;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// initialize screen, create window, renderer and texture (window is hidden)
|
// initialize screen, create window, renderer and texture (window is hidden)
|
||||||
@@ -71,17 +69,14 @@ bool
|
|||||||
screen_init(struct screen *screen, struct fps_counter *fps_counter,
|
screen_init(struct screen *screen, struct fps_counter *fps_counter,
|
||||||
const struct screen_params *params);
|
const struct screen_params *params);
|
||||||
|
|
||||||
|
// show the window
|
||||||
|
void
|
||||||
|
screen_show_window(struct screen *screen);
|
||||||
|
|
||||||
// destroy window, renderer and texture (if any)
|
// destroy window, renderer and texture (if any)
|
||||||
void
|
void
|
||||||
screen_destroy(struct screen *screen);
|
screen_destroy(struct screen *screen);
|
||||||
|
|
||||||
// hide the window
|
|
||||||
//
|
|
||||||
// It is used to hide the window immediately on closing without waiting for
|
|
||||||
// screen_destroy()
|
|
||||||
void
|
|
||||||
screen_hide_window(struct screen *screen);
|
|
||||||
|
|
||||||
// render the texture to the renderer
|
// render the texture to the renderer
|
||||||
//
|
//
|
||||||
// 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
|
||||||
|
|||||||
Reference in New Issue
Block a user