Compare commits
5 Commits
window-par
...
fixhidpi.3
Author | SHA1 | Date | |
---|---|---|---|
73c0f3ee05 | |||
78d9d82091 | |||
c8c921caf5 | |||
39ff8d9900 | |||
683f7ca848 |
30
DEVELOP.md
30
DEVELOP.md
@ -268,3 +268,33 @@ For more details, go read the code!
|
||||
|
||||
If you find a bug, or have an awesome idea to implement, please discuss and
|
||||
contribute ;-)
|
||||
|
||||
|
||||
### Debug the server
|
||||
|
||||
The server is pushed to the device by the client on startup.
|
||||
|
||||
To debug it, enable the server debugger during configuration:
|
||||
|
||||
```bash
|
||||
meson x -Dserver_debugger=true
|
||||
# or, if x is already configured
|
||||
meson configure x -Dserver_debugger=true
|
||||
```
|
||||
|
||||
Then recompile.
|
||||
|
||||
When you start scrcpy, it will start a debugger on port 5005 on the device.
|
||||
Redirect that port to the computer:
|
||||
|
||||
```bash
|
||||
adb forward tcp:5005 tcp:5005
|
||||
```
|
||||
|
||||
In Android Studio, _Run_ > _Debug_ > _Edit configurations..._ On the left, click on
|
||||
`+`, _Remote_, and fill the form:
|
||||
|
||||
- Host: `localhost`
|
||||
- Port: `5005`
|
||||
|
||||
Then click on _Debug_.
|
||||
|
@ -109,12 +109,15 @@ conf.set('DEFAULT_MAX_SIZE', '0') # 0: unlimited
|
||||
# overridden by option --bit-rate
|
||||
conf.set('DEFAULT_BIT_RATE', '8000000') # 8Mbps
|
||||
|
||||
# enable High DPI support
|
||||
conf.set('HIDPI_SUPPORT', get_option('hidpi_support'))
|
||||
|
||||
# disable console on Windows
|
||||
conf.set('WINDOWS_NOCONSOLE', get_option('windows_noconsole'))
|
||||
|
||||
# run a server debugger and wait for a client to be attached
|
||||
conf.set('SERVER_DEBUGGER', get_option('server_debugger'))
|
||||
|
||||
# enable a workaround for bug #15
|
||||
conf.set('HIDPI_WORKAROUND', get_option('hidpi_workaround'))
|
||||
|
||||
configure_file(configuration: conf, output: 'config.h')
|
||||
|
||||
src_dir = include_directories('src')
|
||||
|
@ -145,9 +145,11 @@ handle_event(SDL_Event *event, bool control) {
|
||||
case SDL_WINDOWEVENT:
|
||||
switch (event->window.event) {
|
||||
case SDL_WINDOWEVENT_EXPOSED:
|
||||
case SDL_WINDOWEVENT_SIZE_CHANGED:
|
||||
screen_render(&screen);
|
||||
break;
|
||||
case SDL_WINDOWEVENT_SIZE_CHANGED:
|
||||
screen_window_resized(&screen);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case SDL_TEXTINPUT:
|
||||
|
105
app/src/screen.c
105
app/src/screen.c
@ -134,16 +134,57 @@ create_texture(SDL_Renderer *renderer, struct size frame_size) {
|
||||
frame_size.width, frame_size.height);
|
||||
}
|
||||
|
||||
#ifdef HIDPI_WORKAROUND
|
||||
static void
|
||||
screen_get_sizes(struct screen *screen, struct screen_sizes *out) {
|
||||
int ww, wh, dw, dh;
|
||||
SDL_GetWindowSize(screen->window, &ww, &wh);
|
||||
SDL_GL_GetDrawableSize(screen->window, &dw, &dh);
|
||||
out->window.width = ww;
|
||||
out->window.height = wh;
|
||||
out->window.width = dw;
|
||||
out->window.height = dh;
|
||||
}
|
||||
#endif
|
||||
|
||||
// This may be called more than once to work around SDL bugs
|
||||
static bool
|
||||
screen_init_renderer_and_texture(struct screen *screen) {
|
||||
screen->renderer = SDL_CreateRenderer(screen->window, -1,
|
||||
SDL_RENDERER_ACCELERATED);
|
||||
if (!screen->renderer) {
|
||||
LOGC("Could not create renderer: %s", SDL_GetError());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (SDL_RenderSetLogicalSize(screen->renderer, screen->frame_size.width,
|
||||
screen->frame_size.height)) {
|
||||
LOGE("Could not set renderer logical size: %s", SDL_GetError());
|
||||
return false;
|
||||
}
|
||||
|
||||
screen->texture = create_texture(screen->renderer, screen->frame_size);
|
||||
if (!screen->texture) {
|
||||
LOGC("Could not create texture: %s", SDL_GetError());
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef HIDPI_WORKAROUND
|
||||
screen_get_sizes(screen, &screen->sizes);
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
screen_init_rendering(struct screen *screen, const char *window_title,
|
||||
struct size frame_size, bool always_on_top) {
|
||||
screen->frame_size = frame_size;
|
||||
|
||||
struct size window_size = get_initial_optimal_size(frame_size);
|
||||
uint32_t window_flags = SDL_WINDOW_HIDDEN | SDL_WINDOW_RESIZABLE;
|
||||
#ifdef HIDPI_SUPPORT
|
||||
window_flags |= SDL_WINDOW_ALLOW_HIGHDPI;
|
||||
#endif
|
||||
uint32_t window_flags = SDL_WINDOW_HIDDEN
|
||||
| SDL_WINDOW_RESIZABLE
|
||||
| SDL_WINDOW_ALLOW_HIGHDPI;
|
||||
if (always_on_top) {
|
||||
#ifdef SCRCPY_SDL_HAS_WINDOW_ALWAYS_ON_TOP
|
||||
window_flags |= SDL_WINDOW_ALWAYS_ON_TOP;
|
||||
@ -162,21 +203,6 @@ screen_init_rendering(struct screen *screen, const char *window_title,
|
||||
return false;
|
||||
}
|
||||
|
||||
screen->renderer = SDL_CreateRenderer(screen->window, -1,
|
||||
SDL_RENDERER_ACCELERATED);
|
||||
if (!screen->renderer) {
|
||||
LOGC("Could not create renderer: %s", SDL_GetError());
|
||||
screen_destroy(screen);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (SDL_RenderSetLogicalSize(screen->renderer, frame_size.width,
|
||||
frame_size.height)) {
|
||||
LOGE("Could not set renderer logical size: %s", SDL_GetError());
|
||||
screen_destroy(screen);
|
||||
return false;
|
||||
}
|
||||
|
||||
SDL_Surface *icon = read_xpm(icon_xpm);
|
||||
if (icon) {
|
||||
SDL_SetWindowIcon(screen->window, icon);
|
||||
@ -187,9 +213,7 @@ screen_init_rendering(struct screen *screen, const char *window_title,
|
||||
|
||||
LOGI("Initial texture: %" PRIu16 "x%" PRIu16, frame_size.width,
|
||||
frame_size.height);
|
||||
screen->texture = create_texture(screen->renderer, frame_size);
|
||||
if (!screen->texture) {
|
||||
LOGC("Could not create texture: %s", SDL_GetError());
|
||||
if (!screen_init_renderer_and_texture(screen)) {
|
||||
screen_destroy(screen);
|
||||
return false;
|
||||
}
|
||||
@ -278,6 +302,43 @@ screen_update_frame(struct screen *screen, struct video_buffer *vb) {
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef HIDPI_WORKAROUND
|
||||
// workaround for <https://github.com/Genymobile/scrcpy/issues/15>
|
||||
static inline bool
|
||||
screen_fix_hidpi(struct screen *screen) {
|
||||
struct screen_sizes cur;
|
||||
screen_get_sizes(screen, &cur);
|
||||
|
||||
struct screen_sizes *prev = &screen->sizes;
|
||||
|
||||
bool width_ratio_changed = cur.window.width * prev->drawable.width !=
|
||||
cur.drawable.width * prev->window.width;
|
||||
bool height_ratio_changed = cur.window.height * prev->drawable.height !=
|
||||
cur.drawable.height * prev->window.height;
|
||||
if (width_ratio_changed || height_ratio_changed) {
|
||||
SDL_DestroyTexture(screen->texture);
|
||||
SDL_DestroyRenderer(screen->renderer);
|
||||
if (!screen_init_renderer_and_texture(screen)) {
|
||||
screen->texture = NULL;
|
||||
screen->renderer = NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
LOGI("Renderer reset after hidpi scaling changed");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
screen_window_resized(struct screen *screen) {
|
||||
#ifdef HIDPI_WORKAROUND
|
||||
screen_fix_hidpi(screen);
|
||||
#endif
|
||||
screen_render(screen);
|
||||
}
|
||||
|
||||
void
|
||||
screen_render(struct screen *screen) {
|
||||
SDL_RenderClear(screen->renderer);
|
||||
|
@ -20,6 +20,12 @@ struct screen {
|
||||
bool has_frame;
|
||||
bool fullscreen;
|
||||
bool no_window;
|
||||
#ifdef HIDPI_WORKAROUND
|
||||
struct screen_sizes {
|
||||
struct size window;
|
||||
struct size drawable;
|
||||
} sizes;
|
||||
#endif
|
||||
};
|
||||
|
||||
#define SCREEN_INITIALIZER { \
|
||||
@ -60,6 +66,10 @@ screen_destroy(struct screen *screen);
|
||||
bool
|
||||
screen_update_frame(struct screen *screen, struct video_buffer *vb);
|
||||
|
||||
// update content after window resizing
|
||||
void
|
||||
screen_window_resized(struct screen *screen);
|
||||
|
||||
// render the texture to the renderer
|
||||
void
|
||||
screen_render(struct screen *screen);
|
||||
|
@ -124,6 +124,11 @@ execute_server(struct server *server, const struct server_params *params) {
|
||||
"shell",
|
||||
"CLASSPATH=/data/local/tmp/" SERVER_FILENAME,
|
||||
"app_process",
|
||||
#ifdef SERVER_DEBUGGER
|
||||
# define SERVER_DEBUGGER_PORT "5005"
|
||||
"-agentlib:jdwp=transport=dt_socket,suspend=y,server=y,address="
|
||||
SERVER_DEBUGGER_PORT,
|
||||
#endif
|
||||
"/", // unused
|
||||
"com.genymobile.scrcpy.Server",
|
||||
max_size_string,
|
||||
@ -133,6 +138,17 @@ execute_server(struct server *server, const struct server_params *params) {
|
||||
"true", // always send frame meta (packet boundaries + timestamp)
|
||||
params->control ? "true" : "false",
|
||||
};
|
||||
#ifdef SERVER_DEBUGGER
|
||||
LOGI("Server debugger waiting for a client on device port "
|
||||
SERVER_DEBUGGER_PORT "...");
|
||||
// From the computer, run
|
||||
// adb forward tcp:5005 tcp:5005
|
||||
// Then, from Android Studio: Run > Debug > Edit configurations...
|
||||
// On the left, click on '+', "Remote", with:
|
||||
// Host: localhost
|
||||
// Port: 5005
|
||||
// Then click on "Debug"
|
||||
#endif
|
||||
return adb_execute(server->serial, cmd, sizeof(cmd) / sizeof(cmd[0]));
|
||||
}
|
||||
|
||||
|
@ -4,4 +4,5 @@ option('crossbuild_windows', type: 'boolean', value: false, description: 'Build
|
||||
option('windows_noconsole', type: 'boolean', value: false, description: 'Disable console on Windows (pass -mwindows flag)')
|
||||
option('prebuilt_server', type: 'string', description: 'Path of the prebuilt server')
|
||||
option('portable', type: 'boolean', value: false, description: 'Use scrcpy-server from the same directory as the scrcpy executable')
|
||||
option('hidpi_support', type: 'boolean', value: true, description: 'Enable High DPI support')
|
||||
option('server_debugger', type: 'boolean', value: false, description: 'Run a server debugger and wait for a client to be attached')
|
||||
option('hidpi_workaround', type: 'boolean', value: true, description: 'Enable a workaround for bug #15')
|
||||
|
Reference in New Issue
Block a user