[vlc-commits] [Git][videolan/vlc][master] 3 commits: qt: provide wayland protocol `viewporter`
Felix Paul Kühne (@fkuehne)
gitlab at videolan.org
Fri Sep 13 14:52:17 UTC 2024
Felix Paul Kühne pushed to branch master at VideoLAN / VLC
Commits:
2f65308b by Fatih Uzunoglu at 2024-09-13T14:39:26+00:00
qt: provide wayland protocol `viewporter`
- - - - -
5d33c4ea by Fatih Uzunoglu at 2024-09-13T14:39:26+00:00
qt: support fractional scaling in wayland compositor
- - - - -
69ad3238 by Fatih Uzunoglu at 2024-09-13T14:39:26+00:00
qt: use `wl_surface_set_buffer_scale()` only when applicable
- - - - -
3 changed files:
- modules/gui/qt/Makefile.am
- modules/gui/qt/maininterface/compositor_wayland.cpp
- modules/gui/qt/maininterface/compositor_wayland_module.c
Changes:
=====================================
modules/gui/qt/Makefile.am
=====================================
@@ -605,6 +605,28 @@ libqt_wayland_plugin_la_SOURCES = \
maininterface/compositor_wayland_module.c \
maininterface/compositor_wayland_module.h
+#if WAYLAND_PROTOCOLS
+#if WAYLAND_SCANNER
+libqt_wayland_plugin_la_CFLAGS += -DQT_HAS_WAYLAND_PROTOCOLS -I$(builddir)/maininterface
+
+nodist_libqt_wayland_plugin_la_SOURCES = \
+ maininterface/viewporter-client-protocol.h \
+ maininterface/viewporter-protocol.c
+
+BUILT_SOURCES += $(nodist_libqt_wayland_plugin_la_SOURCES)
+
+maininterface/viewporter-client-protocol.h: \
+ $(WAYLAND_PROTOCOLS)/stable/viewporter/viewporter.xml
+ $(AM_V_GEN)$(WAYLAND_SCANNER) client-header $< $@
+
+maininterface/viewporter-protocol.c: \
+ $(WAYLAND_PROTOCOLS)/stable/viewporter/viewporter.xml \
+ maininterface/viewporter-client-protocol.h
+ $(AM_V_GEN)$(WAYLAND_SCANNER) private-code $< $@
+
+#endif
+#endif
+
if ENABLE_QT
gui_LTLIBRARIES += libqt_wayland_plugin.la
endif
=====================================
modules/gui/qt/maininterface/compositor_wayland.cpp
=====================================
@@ -17,6 +17,8 @@
*****************************************************************************/
#include "compositor_wayland.hpp"
+#include <cmath>
+
#include "maininterface/mainctx.hpp"
#include "maininterface/interface_window_handler.hpp"
@@ -115,7 +117,7 @@ bool CompositorWayland::makeMainInterface(MainCtx* mainCtx)
if (!interfaceSurface)
return false;
- m_waylandImpl->setupInterface(m_waylandImpl, interfaceSurface, dprForWindow(m_qmlView.get()));
+ m_waylandImpl->setupInterface(m_waylandImpl, interfaceSurface, std::ceil(dprForWindow(m_qmlView.get())));
CompositorVideo::Flags flags = CompositorVideo::CAN_SHOW_PIP | CompositorVideo::HAS_ACRYLIC;
=====================================
modules/gui/qt/maininterface/compositor_wayland_module.c
=====================================
@@ -25,6 +25,10 @@
#include <vlc_plugin.h>
#include <wayland-client.h>
+#ifdef QT_HAS_WAYLAND_PROTOCOLS
+#include "viewporter-client-protocol.h"
+#endif
+
#include <assert.h>
typedef struct
@@ -34,26 +38,38 @@ typedef struct
struct wl_compositor* compositor;
struct wl_subcompositor* subcompositor;
+#ifdef QT_HAS_WAYLAND_PROTOCOLS
+ struct wp_viewport* viewport;
+ struct wp_viewporter* viewporter;
+#endif
+
struct wl_surface* interface_surface;
struct wl_surface* video_surface;
struct wl_subsurface* video_subsurface;
int buffer_scale;
+
+ uint32_t compositor_interface_version;
} qtwayland_priv_t;
static void registry_global_cb(void* data, struct wl_registry* registry,
uint32_t id, const char* iface, uint32_t version)
{
- VLC_UNUSED(version);
-
qtwayland_t* obj = (qtwayland_t*)data;
qtwayland_priv_t* sys = (qtwayland_priv_t*)obj->p_sys;
if (!strcmp(iface, "wl_subcompositor"))
sys->subcompositor = (struct wl_subcompositor*)wl_registry_bind(registry, id, &wl_subcompositor_interface, version);
if (!strcmp(iface, "wl_compositor"))
+ {
+ sys->compositor_interface_version = version;
sys->compositor = (struct wl_compositor*)wl_registry_bind(registry, id, &wl_compositor_interface, version);
+ }
+#ifdef QT_HAS_WAYLAND_PROTOCOLS
+ if (!strcmp(iface, "wp_viewporter"))
+ sys->viewporter = (struct wp_viewporter*)wl_registry_bind(registry, id, &wp_viewporter_interface, version);
+#endif
}
static void registry_global_remove_cb(void* data, struct wl_registry* registry, uint32_t id)
@@ -90,7 +106,29 @@ static int SetupVoutWindow(qtwayland_t* obj, vlc_window_t* wnd)
if (!sys->video_surface)
return VLC_EGENERIC;
- wl_surface_set_buffer_scale(sys->video_surface, sys->buffer_scale);
+#ifdef QT_HAS_WAYLAND_PROTOCOLS
+ if (sys->viewporter)
+ sys->viewport = wp_viewporter_get_viewport(sys->viewporter, sys->video_surface);
+ else
+#endif
+ {
+ // The buffer scale must remain 1 when fractional scaling is used
+ if (sys->buffer_scale != 1)
+ {
+ msg_Dbg(obj, "Viewporter protocol is not available, and scale is not 1." \
+ "Only integer scaling may be possible.");
+
+ if (sys->compositor_interface_version >= 3)
+ {
+ wl_surface_set_buffer_scale(sys->video_surface, sys->buffer_scale);
+ }
+ else
+ {
+ msg_Dbg(obj, "Compositor interface version is below 3, integer scaling " \
+ "is not possible.");
+ }
+ }
+ }
struct wl_region* region = wl_compositor_create_region(sys->compositor);
if (!region)
@@ -116,6 +154,15 @@ static int SetupVoutWindow(qtwayland_t* obj, vlc_window_t* wnd)
static void TeardownVoutWindow(struct qtwayland_t* obj)
{
qtwayland_priv_t* sys = (qtwayland_priv_t*)obj->p_sys;
+
+#ifdef QT_HAS_WAYLAND_PROTOCOLS
+ if (sys->viewport)
+ {
+ wp_viewport_destroy(sys->viewport);
+ sys->viewport = NULL;
+ }
+#endif
+
vlc_assert(sys->video_surface);
wl_surface_destroy(sys->video_surface);
sys->video_surface = NULL;
@@ -158,9 +205,22 @@ static void Move(struct qtwayland_t* obj, int x, int y)
static void Resize(struct qtwayland_t* obj, size_t width, size_t height)
{
- VLC_UNUSED(obj);
- VLC_UNUSED(width);
- VLC_UNUSED(height);
+#ifdef QT_HAS_WAYLAND_PROTOCOLS
+ qtwayland_priv_t* sys = (qtwayland_priv_t*)obj->p_sys;
+ assert(sys);
+ if (!sys->video_surface)
+ return;
+ if (sys->viewport)
+ {
+ // width and height here represent the final size, after scaling
+ // is taken into account. The fractional scaling protocol is not
+ // necessary, because the (fractional) scale is retrieved from the
+ // Qt Quick window which uses the fractional scale protocol itself
+ // to determine the device pixel ratio.
+ wp_viewport_set_destination(sys->viewport, width, height);
+ wl_surface_commit(sys->video_surface);
+ }
+#endif
}
static void Close(qtwayland_t* obj)
@@ -168,6 +228,11 @@ static void Close(qtwayland_t* obj)
qtwayland_priv_t* sys = (qtwayland_priv_t*)(obj->p_sys);
wl_display_flush(sys->display);
+#ifdef QT_HAS_WAYLAND_PROTOCOLS
+ if (sys->viewporter)
+ wp_viewporter_destroy(sys->viewporter);
+#endif
+
wl_subcompositor_destroy(sys->subcompositor);
wl_compositor_destroy(sys->compositor);
wl_event_queue_destroy(sys->queue);
@@ -189,6 +254,11 @@ static bool Init(qtwayland_t* obj, void* qpni_display)
void* wrapper = wl_proxy_create_wrapper(display);
wl_proxy_set_queue((struct wl_proxy*)wrapper, sys->queue);
+#ifdef QT_HAS_WAYLAND_PROTOCOLS
+ sys->viewporter = NULL;
+ sys->viewport = NULL;
+#endif
+
struct wl_registry* registry = wl_display_get_registry((struct wl_display*)wrapper);
wl_proxy_wrapper_destroy(wrapper);
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/f482c6017586b5242ba6422d3b6cc43c3d3b11ac...69ad32384f749e9cd8f07dbb1a9854bde872bf7e
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/f482c6017586b5242ba6422d3b6cc43c3d3b11ac...69ad32384f749e9cd8f07dbb1a9854bde872bf7e
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list