mirror of
https://github.com/Genymobile/scrcpy.git
synced 2026-03-14 16:14:37 +01:00
Compare commits
24 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7fa922d8e6 | ||
|
|
ac7dca42b0 | ||
|
|
492162a24f | ||
|
|
2ab148bd79 | ||
|
|
6795564044 | ||
|
|
b7cdbce8e5 | ||
|
|
5cd847a856 | ||
|
|
3d36915d9b | ||
|
|
c64f5ff71e | ||
|
|
db418d0825 | ||
|
|
b481ab0aaf | ||
|
|
cb7017e2c1 | ||
|
|
5c6b04cf01 | ||
|
|
153d5e4892 | ||
|
|
620b117a15 | ||
|
|
14e83175a6 | ||
|
|
0d46d0b376 | ||
|
|
4632ef224c | ||
|
|
bc07943624 | ||
|
|
003fcb0442 | ||
|
|
8ef4c044fa | ||
|
|
c23c38f99d | ||
|
|
65c4f487b3 | ||
|
|
c6d7f5ee96 |
@@ -126,30 +126,6 @@ sdl_init_and_configure(bool display, const char *render_driver,
|
||||
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
|
||||
is_apk(const char *file) {
|
||||
const char *ext = strrchr(file, '.');
|
||||
@@ -189,7 +165,7 @@ handle_event(SDL_Event *event, const struct scrcpy_options *options) {
|
||||
action = ACTION_PUSH_FILE;
|
||||
}
|
||||
file_handler_request(&file_handler, action, file);
|
||||
break;
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,11 +183,6 @@ end:
|
||||
|
||||
static bool
|
||||
event_loop(const struct scrcpy_options *options) {
|
||||
#ifdef CONTINUOUS_RESIZING_WORKAROUND
|
||||
if (options->display) {
|
||||
SDL_AddEventWatch(event_watcher, NULL);
|
||||
}
|
||||
#endif
|
||||
SDL_Event event;
|
||||
while (SDL_WaitEvent(&event)) {
|
||||
enum event_result result = handle_event(&event, options);
|
||||
@@ -394,6 +365,7 @@ scrcpy(const struct scrcpy_options *options) {
|
||||
.window_borderless = options->window_borderless,
|
||||
.rotation = options->rotation,
|
||||
.mipmaps = options->mipmaps,
|
||||
.fullscreen = options->fullscreen,
|
||||
};
|
||||
|
||||
if (!screen_init(&screen, &fps_counter, &screen_params)) {
|
||||
@@ -412,10 +384,6 @@ scrcpy(const struct scrcpy_options *options) {
|
||||
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
|
||||
@@ -430,6 +398,10 @@ scrcpy(const struct scrcpy_options *options) {
|
||||
ret = event_loop(options);
|
||||
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:
|
||||
// The stream is not stopped explicitly, because it will stop by itself on
|
||||
// end-of-stream
|
||||
|
||||
@@ -220,6 +220,29 @@ create_texture(struct screen *screen) {
|
||||
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
|
||||
screen_frame_sink_open(struct sc_frame_sink *sink) {
|
||||
struct screen *screen = DOWNCAST(sink);
|
||||
@@ -402,6 +425,14 @@ screen_init(struct screen *screen, struct fps_counter *fps_counter,
|
||||
|
||||
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 = {
|
||||
.open = screen_frame_sink_open,
|
||||
.close = screen_frame_sink_close,
|
||||
@@ -417,11 +448,16 @@ screen_init(struct screen *screen, struct fps_counter *fps_counter,
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
screen_show_window(struct screen *screen) {
|
||||
SDL_ShowWindow(screen->window);
|
||||
}
|
||||
|
||||
void
|
||||
screen_hide_window(struct screen *screen) {
|
||||
SDL_HideWindow(screen->window);
|
||||
}
|
||||
|
||||
void
|
||||
screen_destroy(struct screen *screen) {
|
||||
#ifndef NDEBUG
|
||||
|
||||
@@ -62,6 +62,8 @@ struct screen_params {
|
||||
|
||||
uint8_t rotation;
|
||||
bool mipmaps;
|
||||
|
||||
bool fullscreen;
|
||||
};
|
||||
|
||||
// initialize screen, create window, renderer and texture (window is hidden)
|
||||
@@ -69,14 +71,17 @@ bool
|
||||
screen_init(struct screen *screen, struct fps_counter *fps_counter,
|
||||
const struct screen_params *params);
|
||||
|
||||
// show the window
|
||||
void
|
||||
screen_show_window(struct screen *screen);
|
||||
|
||||
// destroy window, renderer and texture (if any)
|
||||
void
|
||||
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
|
||||
//
|
||||
// Set the update_content_rect flag if the window or content size may have
|
||||
|
||||
Reference in New Issue
Block a user