Skip to content

Commit

Permalink
Rebase of wakira's wp_fractional_scale_v1 support (#15965)
Browse files Browse the repository at this point in the history
A rebase of earlier PR #15355
No changes added (except for one log).
  • Loading branch information
zoltanvb authored Nov 30, 2023
1 parent fb864b8 commit fd04c8c
Show file tree
Hide file tree
Showing 10 changed files with 220 additions and 47 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ retroarch_switch.nso
*_irx.c

# Wayland
gfx/common/wayland/fractional-scale-v1.c
gfx/common/wayland/fractional-scale-v1.h
gfx/common/wayland/viewporter.c
gfx/common/wayland/viewporter.h
gfx/common/wayland/idle-inhibit-unstable-v1.c
gfx/common/wayland/idle-inhibit-unstable-v1.h
gfx/common/wayland/xdg-shell-unstable-v6.c
Expand Down
1 change: 1 addition & 0 deletions Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,7 @@ ifeq ($(HAVE_WAYLAND), 1)
input/common/wayland_common.o \
input/drivers/wayland_input.o \
gfx/common/wayland_common.o \
gfx/common/wayland/fractional-scale-v1.o \
gfx/common/wayland/viewporter.o \
gfx/common/wayland/xdg-shell.o \
gfx/common/wayland/idle-inhibit-unstable-v1.o \
Expand Down
4 changes: 4 additions & 0 deletions deps/wayland-protocols/staging/fractional-scale/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
wp fractional scale protocol

Maintainers:
Kenny Levinsen <[email protected]>
Original file line number Diff line number Diff line change
@@ -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>
2 changes: 1 addition & 1 deletion gfx/common/wayland/generate_wayland_protos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ generate_source 'unstable/xdg-decoration' 'xdg-decoration-unstable-v1'
generate_source 'unstable/idle-inhibit' 'idle-inhibit-unstable-v1'
generate_source 'unstable/pointer-constraints' 'pointer-constraints-unstable-v1'
generate_source 'unstable/relative-pointer' 'relative-pointer-unstable-v1'

generate_source 'staging/fractional-scale' 'fractional-scale-v1'
73 changes: 49 additions & 24 deletions gfx/common/wayland_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,13 @@ void xdg_toplevel_handle_configure_common(gfx_ctx_wayland_data_t *wl,
if ( (width > 0)
&& (height > 0))
{
wl->width = width;
wl->height = height;
wl->buffer_width = wl->width * wl->buffer_scale;
wl->buffer_height = wl->height * wl->buffer_scale;
wl->resize = true;
wl->width = width;
wl->height = height;
wl->buffer_width = wl->fractional_scale ?
FRACTIONAL_SCALE_MULT(wl->width, wl->fractional_scale_num) : wl->width * wl->buffer_scale;
wl->buffer_height = wl->fractional_scale ?
FRACTIONAL_SCALE_MULT(wl->height, wl->fractional_scale_num) : wl->height * wl->buffer_scale;
wl->resize = true;
if (wl->viewport) /* Update viewport */
wp_viewport_set_destination(wl->viewport, wl->width, wl->height);
}
Expand Down Expand Up @@ -193,8 +195,10 @@ void libdecor_frame_handle_configure_common(struct libdecor_frame *frame,
{
wl->width = width;
wl->height = height;
wl->buffer_width = width * wl->buffer_scale;
wl->buffer_height = height * wl->buffer_scale;
wl->buffer_width = wl->fractional_scale ?
FRACTIONAL_SCALE_MULT(width, wl->fractional_scale_num) : width * wl->buffer_scale;
wl->buffer_height = wl->fractional_scale ?
FRACTIONAL_SCALE_MULT(height, wl->fractional_scale_num) : height * wl->buffer_scale;
wl->resize = true;
if (wl->viewport) /* Update viewport */
wp_viewport_set_destination(wl->viewport, wl->width, wl->height);
Expand Down Expand Up @@ -243,8 +247,10 @@ void gfx_ctx_wl_get_video_size_common(void *data,
}
else
{
*width = wl->width * wl->pending_buffer_scale;
*height = wl->height * wl->pending_buffer_scale;
*width = wl->fractional_scale ?
FRACTIONAL_SCALE_MULT(wl->width, wl->pending_fractional_scale_num) : wl->width * wl->pending_buffer_scale;
*height = wl->fractional_scale ?
FRACTIONAL_SCALE_MULT(wl->height, wl->pending_fractional_scale_num) : wl->height * wl->pending_buffer_scale;
}
}

Expand All @@ -271,6 +277,8 @@ void gfx_ctx_wl_destroy_resources_common(gfx_ctx_wayland_data_t *wl)

if (wl->viewport)
wp_viewport_destroy(wl->viewport);
if (wl->fractional_scale)
wp_fractional_scale_v1_destroy(wl->fractional_scale);
if (wl->idle_inhibitor)
zwp_idle_inhibitor_v1_destroy(wl->idle_inhibitor);
if (wl->deco)
Expand Down Expand Up @@ -322,6 +330,8 @@ void gfx_ctx_wl_destroy_resources_common(gfx_ctx_wayland_data_t *wl)
wl_shm_destroy (wl->shm);
if (wl->viewporter)
wp_viewporter_destroy(wl->viewporter);
if (wl->fractional_scale_manager)
wp_fractional_scale_manager_v1_destroy(wl->fractional_scale_manager);
if (wl->compositor)
wl_compositor_destroy(wl->compositor);
if (wl->registry)
Expand Down Expand Up @@ -578,8 +588,8 @@ static void shm_buffer_paint_checkerboard(
static bool wl_draw_splash_screen(gfx_ctx_wayland_data_t *wl)
{
shm_buffer_t *buffer = create_shm_buffer(wl,
wl->width * wl->buffer_scale,
wl->height * wl->buffer_scale,
wl->buffer_width,
wl->buffer_height,
WL_SHM_FORMAT_XRGB8888);

if (!buffer)
Expand Down Expand Up @@ -630,12 +640,15 @@ bool gfx_ctx_wl_init_common(

frontend_driver_destroy_signal_handler_state();

wl->input.dpy = wl_display_connect(NULL);
wl->last_buffer_scale = 1;
wl->buffer_scale = 1;
wl->pending_buffer_scale = 1;
wl->floating_width = SPLASH_WINDOW_WIDTH;
wl->floating_height = SPLASH_WINDOW_HEIGHT;
wl->input.dpy = wl_display_connect(NULL);
wl->last_buffer_scale = 1;
wl->buffer_scale = 1;
wl->pending_buffer_scale = 1;
wl->last_fractional_scale_num = FRACTIONAL_SCALE_V1_DEN;
wl->fractional_scale_num = FRACTIONAL_SCALE_V1_DEN;
wl->pending_fractional_scale_num = FRACTIONAL_SCALE_V1_DEN;
wl->floating_width = SPLASH_WINDOW_WIDTH;
wl->floating_height = SPLASH_WINDOW_HEIGHT;

if (!wl->input.dpy)
{
Expand Down Expand Up @@ -683,6 +696,13 @@ bool gfx_ctx_wl_init_common(
wl->surface = wl_compositor_create_surface(wl->compositor);
if (wl->viewporter)
wl->viewport = wp_viewporter_get_viewport(wl->viewporter, wl->surface);
if (wl->fractional_scale_manager)
{
wl->fractional_scale = wp_fractional_scale_manager_v1_get_fractional_scale(
wl->fractional_scale_manager, wl->surface);
wp_fractional_scale_v1_add_listener(wl->fractional_scale, &wp_fractional_scale_v1_listener, wl);
RARCH_LOG("[Wayland]: fractional_scale_v1 enabled\n");
}

wl_surface_add_listener(wl->surface, &wl_surface_listener, wl);

Expand Down Expand Up @@ -809,9 +829,12 @@ bool gfx_ctx_wl_set_video_mode_common_size(gfx_ctx_wayland_data_t *wl,

if (!fullscreen)
{
wl->buffer_scale = wl->pending_buffer_scale;
wl->buffer_width *= wl->buffer_scale;
wl->buffer_height *= wl->buffer_scale;
wl->buffer_scale = wl->pending_buffer_scale;
wl->fractional_scale_num = wl->pending_fractional_scale_num;
wl->buffer_width = wl->fractional_scale ?
FRACTIONAL_SCALE_MULT(wl->buffer_width, wl->fractional_scale_num) : wl->buffer_width * wl->buffer_scale;
wl->buffer_height = wl->fractional_scale ?
FRACTIONAL_SCALE_MULT(wl->buffer_height, wl->fractional_scale_num) : wl->buffer_height * wl->buffer_scale;
}
if (wl->viewport) /* Update viewport */
wp_viewport_set_destination(wl->viewport, wl->width, wl->height);
Expand Down Expand Up @@ -944,13 +967,15 @@ void gfx_ctx_wl_check_window_common(gfx_ctx_wayland_data_t *wl,
get_video_size(wl, &new_width, &new_height);

if ( wl->pending_buffer_scale != wl->buffer_scale
|| wl->pending_fractional_scale_num != wl->fractional_scale_num
|| new_width != *width
|| new_height != *height)
{
wl->buffer_scale = wl->pending_buffer_scale;
*width = new_width;
*height = new_height;
*resize = true;
wl->buffer_scale = wl->pending_buffer_scale;
wl->fractional_scale_num = wl->pending_fractional_scale_num;
*width = new_width;
*height = new_height;
*resize = true;
}

*quit = (bool)frontend_driver_get_signal_handler_state();
Expand Down
9 changes: 5 additions & 4 deletions gfx/drivers_context/wayland_ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,11 @@ static void gfx_ctx_wl_check_window(void *data, bool *quit,

static bool gfx_ctx_wl_set_resize(void *data, unsigned width, unsigned height)
{
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data;

wl->last_buffer_scale = wl->buffer_scale;
wl_surface_set_buffer_scale(wl->surface, wl->buffer_scale);
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data;
wl->last_buffer_scale = wl->buffer_scale;
wl->last_fractional_scale_num = wl->fractional_scale_num;
if (!wl->fractional_scale)
wl_surface_set_buffer_scale(wl->surface, wl->buffer_scale);

#ifdef HAVE_EGL
wl_egl_window_resize(wl->win, width, height, 0, 0);
Expand Down
4 changes: 3 additions & 1 deletion gfx/drivers_context/wayland_vk_ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ static bool gfx_ctx_wl_set_resize(void *data, unsigned width, unsigned height)
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data;

wl->last_buffer_scale = wl->buffer_scale;
wl_surface_set_buffer_scale(wl->surface, wl->buffer_scale);
wl->last_fractional_scale_num = wl->fractional_scale_num;
if (!wl->fractional_scale)
wl_surface_set_buffer_scale(wl->surface, wl->buffer_scale);

if (vulkan_create_swapchain(&wl->vk, width, height, wl->swap_interval))
{
Expand Down
Loading

0 comments on commit fd04c8c

Please sign in to comment.