summaryrefslogtreecommitdiffstats
path: root/video/out/wayland_common.c
diff options
context:
space:
mode:
authorRostislav Pehlivanov <atomnuker@gmail.com>2016-05-30 18:34:31 +0100
committerwm4 <wm4@nowhere>2016-05-30 20:17:26 +0200
commit098ff4174c6c9cc59e65c6f09b23b3adaee03983 (patch)
treeac5c85fcb7519e6d394df6367a3422bd2652c553 /video/out/wayland_common.c
parent9009601c2d3b2a6d7806d63346c900e0a4c9e2ca (diff)
downloadmpv-098ff4174c6c9cc59e65c6f09b23b3adaee03983.tar.bz2
mpv-098ff4174c6c9cc59e65c6f09b23b3adaee03983.tar.xz
wayland: implement HIDPI support
The wayland protocol exposes scaling done by the compositor to compensate for small window sizes on small high DPI displays. If the program ignores the scaling done, what'll happen is the compositor is going to ask the program to be scaled down by N times the window size and then it'll upscale the program's surface by N times. The scaling algorithm seems to be bilinear so the scaling is quite obvious. This commit sets up callbacks to listen for the scaling factor of each output and, on rescale events, notifies the compositor that the surface's scale is what the compositor asked for and changes the player's surface to the appropriate size, causing no scaling to be done by the compositor. Compositors not supporting this interface will ignore the callbacks and do nothing, keeping program behaviour the same. For compositors supporting and using this interface (mutter), this will fix the rendering to be pixel precise as it should be. Both the opengl wayland backend and the wayland vo have been fixed to support this. Verified to not break either on weston and mutter. Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
Diffstat (limited to 'video/out/wayland_common.c')
-rw-r--r--video/out/wayland_common.c33
1 files changed, 27 insertions, 6 deletions
diff --git a/video/out/wayland_common.c b/video/out/wayland_common.c
index 817e77102b..c27136f207 100644
--- a/video/out/wayland_common.c
+++ b/video/out/wayland_common.c
@@ -189,9 +189,22 @@ static void output_handle_mode(void *data,
output->refresh_rate = refresh;
}
+static void output_handle_done(void* data, struct wl_output *wl_output)
+{
+}
+
+static void output_handle_scale(void* data, struct wl_output *wl_output,
+ int32_t factor)
+{
+ struct vo_wayland_output *output = data;
+ output->scale = factor;
+}
+
static const struct wl_output_listener output_listener = {
output_handle_geometry,
- output_handle_mode
+ output_handle_mode,
+ output_handle_done,
+ output_handle_scale
};
@@ -401,11 +414,15 @@ static void pointer_handle_motion(void *data,
wl_fixed_t sx_w,
wl_fixed_t sy_w)
{
+ int32_t scale = 1;
struct vo_wayland_state *wl = data;
+ if (wl->display.current_output)
+ scale = wl->display.current_output->scale;
+
wl->cursor.pointer = pointer;
- wl->window.mouse_x = wl_fixed_to_int(sx_w);
- wl->window.mouse_y = wl_fixed_to_int(sy_w);
+ wl->window.mouse_x = scale*wl_fixed_to_int(sx_w);
+ wl->window.mouse_y = scale*wl_fixed_to_int(sy_w);
mp_input_set_mouse_pos(wl->vo->input_ctx, wl->window.mouse_x,
wl->window.mouse_y);
@@ -606,7 +623,8 @@ static void registry_handle_global (void *data,
if (strcmp(interface, "wl_compositor") == 0) {
wl->display.compositor = wl_registry_bind(reg, id,
- &wl_compositor_interface, 1);
+ &wl_compositor_interface,
+ MPMIN(3, version));
}
else if (strcmp(interface, "wl_shell") == 0) {
@@ -625,7 +643,9 @@ static void registry_handle_global (void *data,
talloc_zero(wl, struct vo_wayland_output);
output->id = id;
- output->output = wl_registry_bind(reg, id, &wl_output_interface, 1);
+ output->scale = 1;
+ output->output = wl_registry_bind(reg, id, &wl_output_interface,
+ MPMIN(2, version));
wl_output_add_listener(output->output, &output_listener, output);
wl_list_insert(&wl->display.output_list, &output->link);
@@ -1016,9 +1036,10 @@ int vo_wayland_init (struct vo *vo)
"\tvendor: %s\n"
"\tmodel: %s\n"
"\tw: %d, h: %d\n"
+ "\tscale: %d\n"
"\tHz: %d\n",
o->make, o->model,
- o->width, o->height,
+ o->width, o->height, o->scale,
o->refresh_rate / 1000);
}