1From 9c07bab33a0bd57fb74a0368a3d5483cc2820d77 Mon Sep 17 00:00:00 2001
2From: Michael Forney <mforney@mforney.org>
3Date: Wed, 14 Aug 2024 23:01:11 -0700
4Subject: [PATCH] Revert "wayland: drop buffer_scale use for viewporter"
5
6This reverts commit e32554cd570d984efb712a7214a40237233a3cea.
7---
8 video/out/opengl/context_wayland.c | 4 ++--
9 video/out/vo_dmabuf_wayland.c | 6 ++++++
10 video/out/vo_wlshm.c | 2 +-
11 video/out/vulkan/context_wayland.c | 2 +-
12 video/out/wayland_common.c | 34 ++++++++++++++----------------
13 video/out/wayland_common.h | 2 +-
14 6 files changed, 27 insertions(+), 23 deletions(-)
15
16diff --git a/video/out/opengl/context_wayland.c b/video/out/opengl/context_wayland.c
17index 2c5611b2e6..26c52688d3 100644
18--- a/video/out/opengl/context_wayland.c
19+++ b/video/out/opengl/context_wayland.c
20@@ -47,14 +47,14 @@ static void resize(struct ra_ctx *ctx)
21 const int32_t width = mp_rect_w(wl->geometry);
22 const int32_t height = mp_rect_h(wl->geometry);
23
24- vo_wayland_handle_scale(wl);
25-
26 vo_wayland_set_opaque_region(wl, ctx->opts.want_alpha);
27 if (p->egl_window)
28 wl_egl_window_resize(p->egl_window, width, height, 0, 0);
29
30 wl->vo->dwidth = width;
31 wl->vo->dheight = height;
32+
33+ vo_wayland_handle_fractional_scale(wl);
34 }
35
36 static bool wayland_egl_check_visible(struct ra_ctx *ctx)
37diff --git a/video/out/vo_dmabuf_wayland.c b/video/out/vo_dmabuf_wayland.c
38index 35a4dac464..040c73e8a1 100644
39--- a/video/out/vo_dmabuf_wayland.c
40+++ b/video/out/vo_dmabuf_wayland.c
41@@ -781,6 +781,12 @@ static int preinit(struct vo *vo)
42 goto err;
43 }
44
45+ if (!vo->wl->viewport) {
46+ MP_FATAL(vo->wl, "Compositor doesn't support the %s protocol!\n",
47+ wp_viewporter_interface.name);
48+ goto err;
49+ }
50+
51 if (vo->wl->single_pixel_manager) {
52 #if HAVE_WAYLAND_PROTOCOLS_1_27
53 p->solid_buffer = wp_single_pixel_buffer_manager_v1_create_u32_rgba_buffer(
54diff --git a/video/out/vo_wlshm.c b/video/out/vo_wlshm.c
55index 0b63426a23..0dd22ae940 100644
56--- a/video/out/vo_wlshm.c
57+++ b/video/out/vo_wlshm.c
58@@ -215,7 +215,7 @@ static int resize(struct vo *vo)
59 talloc_free(buf);
60 }
61
62- vo_wayland_handle_scale(wl);
63+ vo_wayland_handle_fractional_scale(wl);
64
65 return mp_sws_reinit(p->sws);
66 }
67diff --git a/video/out/vulkan/context_wayland.c b/video/out/vulkan/context_wayland.c
68index cdf1ba60b8..761ff5b12c 100644
69--- a/video/out/vulkan/context_wayland.c
70+++ b/video/out/vulkan/context_wayland.c
71@@ -118,7 +118,7 @@ static bool resize(struct ra_ctx *ctx)
72 const int32_t height = mp_rect_h(wl->geometry);
73
74 vo_wayland_set_opaque_region(wl, ctx->opts.want_alpha);
75- vo_wayland_handle_scale(wl);
76+ vo_wayland_handle_fractional_scale(wl);
77 return ra_vk_ctx_resize(ctx, width, height);
78 }
79
80diff --git a/video/out/wayland_common.c b/video/out/wayland_common.c
81index 4ccd4bda9c..7da864b59f 100644
82--- a/video/out/wayland_common.c
83+++ b/video/out/wayland_common.c
84@@ -1185,13 +1185,13 @@ static void handle_toplevel_config(void *data, struct xdg_toplevel *toplevel,
85 apply_keepaspect(wl, &width, &height);
86 wl->window_size.x0 = 0;
87 wl->window_size.y0 = 0;
88- wl->window_size.x1 = lround(width * wl->scaling);
89- wl->window_size.y1 = lround(height * wl->scaling);
90+ wl->window_size.x1 = round(width * wl->scaling);
91+ wl->window_size.y1 = round(height * wl->scaling);
92 }
93 wl->geometry.x0 = 0;
94 wl->geometry.y0 = 0;
95- wl->geometry.x1 = lround(width * wl->scaling);
96- wl->geometry.y1 = lround(height * wl->scaling);
97+ wl->geometry.x1 = round(width * wl->scaling);
98+ wl->geometry.y1 = round(height * wl->scaling);
99
100 if (mp_rect_equals(&old_geometry, &wl->geometry))
101 return;
102@@ -1713,11 +1713,13 @@ static bool create_input(struct vo_wayland_state *wl)
103
104 static int create_viewports(struct vo_wayland_state *wl)
105 {
106- wl->viewport = wp_viewporter_get_viewport(wl->viewporter, wl->surface);
107- wl->osd_viewport = wp_viewporter_get_viewport(wl->viewporter, wl->osd_surface);
108- wl->video_viewport = wp_viewporter_get_viewport(wl->viewporter, wl->video_surface);
109+ if (wl->viewporter) {
110+ wl->viewport = wp_viewporter_get_viewport(wl->viewporter, wl->surface);
111+ wl->osd_viewport = wp_viewporter_get_viewport(wl->viewporter, wl->osd_surface);
112+ wl->video_viewport = wp_viewporter_get_viewport(wl->viewporter, wl->video_surface);
113+ }
114
115- if (!wl->viewport || !wl->osd_viewport || !wl->video_viewport) {
116+ if (wl->viewporter && (!wl->viewport || !wl->osd_viewport || !wl->video_viewport)) {
117 MP_ERR(wl, "failed to create viewport interfaces!\n");
118 return 1;
119 }
120@@ -2125,6 +2127,7 @@ static void set_surface_scaling(struct vo_wayland_state *wl)
121 wl->scaling = wl->current_output->scale;
122 rescale_geometry(wl, old_scale);
123 wl->pending_vo_events |= VO_EVENT_DPI;
124+ wl_surface_set_buffer_scale(wl->surface, wl->scaling);
125 }
126
127 static void set_window_bounds(struct vo_wayland_state *wl)
128@@ -2510,11 +2513,12 @@ int vo_wayland_control(struct vo *vo, int *events, int request, void *arg)
129 return VO_NOTIMPL;
130 }
131
132-void vo_wayland_handle_scale(struct vo_wayland_state *wl)
133+void vo_wayland_handle_fractional_scale(struct vo_wayland_state *wl)
134 {
135- wp_viewport_set_destination(wl->viewport,
136- lround(mp_rect_w(wl->geometry) / wl->scaling),
137- lround(mp_rect_h(wl->geometry) / wl->scaling));
138+ if (wl->fractional_scale_manager && wl->viewport)
139+ wp_viewport_set_destination(wl->viewport,
140+ round(mp_rect_w(wl->geometry) / wl->scaling),
141+ round(mp_rect_h(wl->geometry) / wl->scaling));
142 }
143
144 bool vo_wayland_init(struct vo *vo)
145@@ -2575,12 +2579,6 @@ bool vo_wayland_init(struct vo *vo)
146 goto err;
147 }
148
149- if (!wl->viewporter) {
150- MP_FATAL(wl, "Compositor doesn't support the required %s protocol!\n",
151- wp_viewporter_interface.name);
152- goto err;
153- }
154-
155 /* Can't be initialized during registry due to multi-protocol dependence */
156 if (create_viewports(wl))
157 goto err;
158diff --git a/video/out/wayland_common.h b/video/out/wayland_common.h
159index f5fcb80445..c489c5db98 100644
160--- a/video/out/wayland_common.h
161+++ b/video/out/wayland_common.h
162@@ -170,7 +170,7 @@ bool vo_wayland_reconfig(struct vo *vo);
163 int vo_wayland_allocate_memfd(struct vo *vo, size_t size);
164 int vo_wayland_control(struct vo *vo, int *events, int request, void *arg);
165
166-void vo_wayland_handle_scale(struct vo_wayland_state *wl);
167+void vo_wayland_handle_fractional_scale(struct vo_wayland_state *wl);
168 void vo_wayland_set_opaque_region(struct vo_wayland_state *wl, bool alpha);
169 void vo_wayland_sync_swap(struct vo_wayland_state *wl);
170 void vo_wayland_uninit(struct vo *vo);
171--
1722.44.0
173