summaryrefslogtreecommitdiff
path: root/pkg/mpv/patch/0008-Revert-wayland-drop-buffer_scale-use-for-viewporter.patch
blob: fda8f3588e292d6c3dcdd18ce0476ede4f4ef133 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
From 9c07bab33a0bd57fb74a0368a3d5483cc2820d77 Mon Sep 17 00:00:00 2001
From: Michael Forney <mforney@mforney.org>
Date: Wed, 14 Aug 2024 23:01:11 -0700
Subject: [PATCH] Revert "wayland: drop buffer_scale use for viewporter"

This reverts commit e32554cd570d984efb712a7214a40237233a3cea.
---
 video/out/opengl/context_wayland.c |  4 ++--
 video/out/vo_dmabuf_wayland.c      |  6 ++++++
 video/out/vo_wlshm.c               |  2 +-
 video/out/vulkan/context_wayland.c |  2 +-
 video/out/wayland_common.c         | 34 ++++++++++++++----------------
 video/out/wayland_common.h         |  2 +-
 6 files changed, 27 insertions(+), 23 deletions(-)

diff --git a/video/out/opengl/context_wayland.c b/video/out/opengl/context_wayland.c
index 2c5611b2e6..26c52688d3 100644
--- a/video/out/opengl/context_wayland.c
+++ b/video/out/opengl/context_wayland.c
@@ -47,14 +47,14 @@ static void resize(struct ra_ctx *ctx)
     const int32_t width = mp_rect_w(wl->geometry);
     const int32_t height = mp_rect_h(wl->geometry);
 
-    vo_wayland_handle_scale(wl);
-
     vo_wayland_set_opaque_region(wl, ctx->opts.want_alpha);
     if (p->egl_window)
         wl_egl_window_resize(p->egl_window, width, height, 0, 0);
 
     wl->vo->dwidth  = width;
     wl->vo->dheight = height;
+
+    vo_wayland_handle_fractional_scale(wl);
 }
 
 static bool wayland_egl_check_visible(struct ra_ctx *ctx)
diff --git a/video/out/vo_dmabuf_wayland.c b/video/out/vo_dmabuf_wayland.c
index 35a4dac464..040c73e8a1 100644
--- a/video/out/vo_dmabuf_wayland.c
+++ b/video/out/vo_dmabuf_wayland.c
@@ -781,6 +781,12 @@ static int preinit(struct vo *vo)
         goto err;
     }
 
+    if (!vo->wl->viewport) {
+        MP_FATAL(vo->wl, "Compositor doesn't support the %s protocol!\n",
+                 wp_viewporter_interface.name);
+        goto err;
+    }
+
     if (vo->wl->single_pixel_manager) {
 #if HAVE_WAYLAND_PROTOCOLS_1_27
         p->solid_buffer = wp_single_pixel_buffer_manager_v1_create_u32_rgba_buffer(
diff --git a/video/out/vo_wlshm.c b/video/out/vo_wlshm.c
index 0b63426a23..0dd22ae940 100644
--- a/video/out/vo_wlshm.c
+++ b/video/out/vo_wlshm.c
@@ -215,7 +215,7 @@ static int resize(struct vo *vo)
         talloc_free(buf);
     }
 
-    vo_wayland_handle_scale(wl);
+    vo_wayland_handle_fractional_scale(wl);
 
     return mp_sws_reinit(p->sws);
 }
diff --git a/video/out/vulkan/context_wayland.c b/video/out/vulkan/context_wayland.c
index cdf1ba60b8..761ff5b12c 100644
--- a/video/out/vulkan/context_wayland.c
+++ b/video/out/vulkan/context_wayland.c
@@ -118,7 +118,7 @@ static bool resize(struct ra_ctx *ctx)
     const int32_t height = mp_rect_h(wl->geometry);
 
     vo_wayland_set_opaque_region(wl, ctx->opts.want_alpha);
-    vo_wayland_handle_scale(wl);
+    vo_wayland_handle_fractional_scale(wl);
     return ra_vk_ctx_resize(ctx, width, height);
 }
 
diff --git a/video/out/wayland_common.c b/video/out/wayland_common.c
index 4ccd4bda9c..7da864b59f 100644
--- a/video/out/wayland_common.c
+++ b/video/out/wayland_common.c
@@ -1185,13 +1185,13 @@ static void handle_toplevel_config(void *data, struct xdg_toplevel *toplevel,
         apply_keepaspect(wl, &width, &height);
         wl->window_size.x0 = 0;
         wl->window_size.y0 = 0;
-        wl->window_size.x1 = lround(width * wl->scaling);
-        wl->window_size.y1 = lround(height * wl->scaling);
+        wl->window_size.x1 = round(width * wl->scaling);
+        wl->window_size.y1 = round(height * wl->scaling);
     }
     wl->geometry.x0 = 0;
     wl->geometry.y0 = 0;
-    wl->geometry.x1 = lround(width * wl->scaling);
-    wl->geometry.y1 = lround(height * wl->scaling);
+    wl->geometry.x1 = round(width * wl->scaling);
+    wl->geometry.y1 = round(height * wl->scaling);
 
     if (mp_rect_equals(&old_geometry, &wl->geometry))
         return;
@@ -1713,11 +1713,13 @@ static bool create_input(struct vo_wayland_state *wl)
 
 static int create_viewports(struct vo_wayland_state *wl)
 {
-    wl->viewport = wp_viewporter_get_viewport(wl->viewporter, wl->surface);
-    wl->osd_viewport = wp_viewporter_get_viewport(wl->viewporter, wl->osd_surface);
-    wl->video_viewport = wp_viewporter_get_viewport(wl->viewporter, wl->video_surface);
+    if (wl->viewporter) {
+        wl->viewport = wp_viewporter_get_viewport(wl->viewporter, wl->surface);
+        wl->osd_viewport = wp_viewporter_get_viewport(wl->viewporter, wl->osd_surface);
+        wl->video_viewport = wp_viewporter_get_viewport(wl->viewporter, wl->video_surface);
+    }
 
-    if (!wl->viewport || !wl->osd_viewport || !wl->video_viewport) {
+    if (wl->viewporter && (!wl->viewport || !wl->osd_viewport || !wl->video_viewport)) {
         MP_ERR(wl, "failed to create viewport interfaces!\n");
         return 1;
     }
@@ -2125,6 +2127,7 @@ static void set_surface_scaling(struct vo_wayland_state *wl)
     wl->scaling = wl->current_output->scale;
     rescale_geometry(wl, old_scale);
     wl->pending_vo_events |= VO_EVENT_DPI;
+    wl_surface_set_buffer_scale(wl->surface, wl->scaling);
 }
 
 static void set_window_bounds(struct vo_wayland_state *wl)
@@ -2510,11 +2513,12 @@ int vo_wayland_control(struct vo *vo, int *events, int request, void *arg)
     return VO_NOTIMPL;
 }
 
-void vo_wayland_handle_scale(struct vo_wayland_state *wl)
+void vo_wayland_handle_fractional_scale(struct vo_wayland_state *wl)
 {
-    wp_viewport_set_destination(wl->viewport,
-                                lround(mp_rect_w(wl->geometry) / wl->scaling),
-                                lround(mp_rect_h(wl->geometry) / wl->scaling));
+    if (wl->fractional_scale_manager && wl->viewport)
+        wp_viewport_set_destination(wl->viewport,
+                                    round(mp_rect_w(wl->geometry) / wl->scaling),
+                                    round(mp_rect_h(wl->geometry) / wl->scaling));
 }
 
 bool vo_wayland_init(struct vo *vo)
@@ -2575,12 +2579,6 @@ bool vo_wayland_init(struct vo *vo)
         goto err;
     }
 
-    if (!wl->viewporter) {
-        MP_FATAL(wl, "Compositor doesn't support the required %s protocol!\n",
-                 wp_viewporter_interface.name);
-        goto err;
-    }
-
     /* Can't be initialized during registry due to multi-protocol dependence */
     if (create_viewports(wl))
         goto err;
diff --git a/video/out/wayland_common.h b/video/out/wayland_common.h
index f5fcb80445..c489c5db98 100644
--- a/video/out/wayland_common.h
+++ b/video/out/wayland_common.h
@@ -170,7 +170,7 @@ bool vo_wayland_reconfig(struct vo *vo);
 int vo_wayland_allocate_memfd(struct vo *vo, size_t size);
 int vo_wayland_control(struct vo *vo, int *events, int request, void *arg);
 
-void vo_wayland_handle_scale(struct vo_wayland_state *wl);
+void vo_wayland_handle_fractional_scale(struct vo_wayland_state *wl);
 void vo_wayland_set_opaque_region(struct vo_wayland_state *wl, bool alpha);
 void vo_wayland_sync_swap(struct vo_wayland_state *wl);
 void vo_wayland_uninit(struct vo *vo);
-- 
2.44.0