From: Alexandros Frantzis alexandros.frantzis@collabora.com
Use the fractional-scale-v1 protocol to keep track of the preferred scale the compositor would like for each surface. --- dlls/winewayland.drv/Makefile.in | 1 + dlls/winewayland.drv/fractional-scale-v1.xml | 102 +++++++++++++++++++ dlls/winewayland.drv/wayland.c | 5 + dlls/winewayland.drv/wayland_surface.c | 46 +++++++++ dlls/winewayland.drv/waylanddrv.h | 4 + 5 files changed, 158 insertions(+) create mode 100644 dlls/winewayland.drv/fractional-scale-v1.xml
diff --git a/dlls/winewayland.drv/Makefile.in b/dlls/winewayland.drv/Makefile.in index e1019ad8348..b450f80dd1a 100644 --- a/dlls/winewayland.drv/Makefile.in +++ b/dlls/winewayland.drv/Makefile.in @@ -6,6 +6,7 @@ UNIX_LIBS = -lwin32u $(WAYLAND_CLIENT_LIBS) $(PTHREAD_LIBS) -lm SOURCES = \ display.c \ dllmain.c \ + fractional-scale-v1.xml \ version.rc \ wayland.c \ wayland_output.c \ diff --git a/dlls/winewayland.drv/fractional-scale-v1.xml b/dlls/winewayland.drv/fractional-scale-v1.xml new file mode 100644 index 00000000000..350bfc01eaf --- /dev/null +++ b/dlls/winewayland.drv/fractional-scale-v1.xml @@ -0,0 +1,102 @@ +<?xml version="1.0" encoding="UTF-8"?> +<protocol name="fractional_scale_v1"> + <copyright> + Copyright © 2022 Kenny Levinsen + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice (including the next + paragraph) shall be included in all copies or substantial portions of the + Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. + </copyright> + + <description summary="Protocol for requesting fractional surface scales"> + This protocol allows a compositor to suggest for surfaces to render at + fractional scales. + + A client can submit scaled content by utilizing wp_viewport. This is done by + creating a wp_viewport object for the surface and setting the destination + rectangle to the surface size before the scale factor is applied. + + The buffer size is calculated by multiplying the surface size by the + intended scale. + + The wl_surface buffer scale should remain set to 1. + + If a surface has a surface-local size of 100 px by 50 px and wishes to + submit buffers with a scale of 1.5, then a buffer of 150px by 75 px should + be used and the wp_viewport destination rectangle should be 100 px by 50 px. + + For toplevel surfaces, the size is rounded halfway away from zero. The + rounding algorithm for subsurface position and size is not defined. + </description> + + <interface name="wp_fractional_scale_manager_v1" version="1"> + <description summary="fractional surface scale information"> + A global interface for requesting surfaces to use fractional scales. + </description> + + <request name="destroy" type="destructor"> + <description summary="unbind the fractional surface scale interface"> + Informs the server that the client will not be using this protocol + object anymore. This does not affect any other objects, + wp_fractional_scale_v1 objects included. + </description> + </request> + + <enum name="error"> + <entry name="fractional_scale_exists" value="0" + summary="the surface already has a fractional_scale object associated"/> + </enum> + + <request name="get_fractional_scale"> + <description summary="extend surface interface for scale information"> + Create an add-on object for the the wl_surface to let the compositor + request fractional scales. If the given wl_surface already has a + wp_fractional_scale_v1 object associated, the fractional_scale_exists + protocol error is raised. + </description> + <arg name="id" type="new_id" interface="wp_fractional_scale_v1" + summary="the new surface scale info interface id"/> + <arg name="surface" type="object" interface="wl_surface" + summary="the surface"/> + </request> + </interface> + + <interface name="wp_fractional_scale_v1" version="1"> + <description summary="fractional scale interface to a wl_surface"> + An additional interface to a wl_surface object which allows the compositor + to inform the client of the preferred scale. + </description> + + <request name="destroy" type="destructor"> + <description summary="remove surface scale information for surface"> + Destroy the fractional scale object. When this object is destroyed, + preferred_scale events will no longer be sent. + </description> + </request> + + <event name="preferred_scale"> + <description summary="notify of new preferred scale"> + Notification of a new preferred scale for this surface that the + compositor suggests that the client should use. + + The sent scale is the numerator of a fraction with a denominator of 120. + </description> + <arg name="scale" type="uint" summary="the new preferred scale"/> + </event> + </interface> +</protocol> diff --git a/dlls/winewayland.drv/wayland.c b/dlls/winewayland.drv/wayland.c index b8c69a105cb..cf3fd4748e9 100644 --- a/dlls/winewayland.drv/wayland.c +++ b/dlls/winewayland.drv/wayland.c @@ -138,6 +138,11 @@ static void registry_handle_global(void *data, struct wl_registry *registry, wl_seat_add_listener(seat->wl_seat, &seat_listener, NULL); pthread_mutex_unlock(&seat->mutex); } + else if (strcmp(interface, "wp_fractional_scale_manager_v1") == 0) + { + process_wayland.wp_fractional_scale_manager_v1 = + wl_registry_bind(registry, id, &wp_fractional_scale_manager_v1_interface, 1); + } }
static void registry_handle_global_remove(void *data, struct wl_registry *registry, diff --git a/dlls/winewayland.drv/wayland_surface.c b/dlls/winewayland.drv/wayland_surface.c index 0ace11e3a0b..c7d81c0b967 100644 --- a/dlls/winewayland.drv/wayland_surface.c +++ b/dlls/winewayland.drv/wayland_surface.c @@ -131,6 +131,25 @@ static const struct xdg_toplevel_listener xdg_toplevel_listener = xdg_toplevel_handle_close };
+static void wp_fractional_scale_v1_handle_preferred_scale( + void *data, + struct wp_fractional_scale_v1 *wp_fractional_scale_v1, + uint32_t scale) +{ + HWND hwnd = data; + struct wayland_surface *surface; + + if (!(surface = wayland_surface_lock_hwnd(hwnd))) return; + TRACE("hwnd=%p preferred_scale=%u\n", hwnd, scale); + surface->preferred_scale = scale / 120.0; + pthread_mutex_unlock(&surface->mutex); +} + +static const struct wp_fractional_scale_v1_listener wp_fractional_scale_v1_listener = +{ + wp_fractional_scale_v1_handle_preferred_scale +}; + /********************************************************************** * wayland_surface_create * @@ -160,6 +179,27 @@ struct wayland_surface *wayland_surface_create(HWND hwnd) } wl_surface_set_user_data(surface->wl_surface, hwnd);
+ surface->preferred_scale = 1.0; + if (process_wayland.wp_fractional_scale_manager_v1) + { + surface->wp_fractional_scale_v1 = + wp_fractional_scale_manager_v1_get_fractional_scale( + process_wayland.wp_fractional_scale_manager_v1, + surface->wl_surface); + /* Note: Since we are dispatching events from a different thread, it + * is possible (although not likely) that we receive a preferred + * scale event before we get the chance to add the listener, and + * thus miss the event. Fixing this requires synchronization with + * the dispatch thread, so for now we accept the risk and will + * revisit as needed. */ + if (surface->wp_fractional_scale_v1) + { + wp_fractional_scale_v1_add_listener(surface->wp_fractional_scale_v1, + &wp_fractional_scale_v1_listener, + hwnd); + } + } + return surface;
err: @@ -184,6 +224,12 @@ void wayland_surface_destroy(struct wayland_surface *surface)
pthread_mutex_lock(&surface->mutex);
+ if (surface->wp_fractional_scale_v1) + { + wp_fractional_scale_v1_destroy(surface->wp_fractional_scale_v1); + surface->wp_fractional_scale_v1 = NULL; + } + if (surface->xdg_toplevel) { xdg_toplevel_destroy(surface->xdg_toplevel); diff --git a/dlls/winewayland.drv/waylanddrv.h b/dlls/winewayland.drv/waylanddrv.h index 340b792ba11..0fdb06922b3 100644 --- a/dlls/winewayland.drv/waylanddrv.h +++ b/dlls/winewayland.drv/waylanddrv.h @@ -27,6 +27,7 @@
#include <pthread.h> #include <wayland-client.h> +#include "fractional-scale-v1-client-protocol.h" #include "xdg-output-unstable-v1-client-protocol.h" #include "xdg-shell-client-protocol.h"
@@ -99,6 +100,7 @@ struct wayland struct wl_compositor *wl_compositor; struct xdg_wm_base *xdg_wm_base; struct wl_shm *wl_shm; + struct wp_fractional_scale_manager_v1 *wp_fractional_scale_manager_v1; struct wayland_seat seat; struct wayland_pointer pointer; struct wl_list output_list; @@ -154,11 +156,13 @@ struct wayland_surface struct wl_surface *wl_surface; struct xdg_surface *xdg_surface; struct xdg_toplevel *xdg_toplevel; + struct wp_fractional_scale_v1 *wp_fractional_scale_v1; pthread_mutex_t mutex; struct wayland_surface_config pending, requested, processing, current; struct wayland_shm_buffer *latest_window_buffer; BOOL resizing; struct wayland_window_config window; + double preferred_scale; };
struct wayland_shm_buffer