1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: stransky <stransky@redhat.com>
3 Date: Thu, 30 Mar 2023 11:49:53 +0000
4 Subject: [PATCH] Bug 1803016 [Wayland] Don't commit wl_buffer if buffer scale
5 doesn't match its size r=emilio
7 Differential Revision: https://phabricator.services.mozilla.com/D173814
9 widget/gtk/MozContainerWayland.cpp | 7 +++++++
10 widget/gtk/MozContainerWayland.h | 3 +++
11 widget/gtk/WindowSurfaceWaylandMultiBuffer.cpp | 17 ++++++++++++++---
12 3 files changed, 24 insertions(+), 3 deletions(-)
14 diff --git a/widget/gtk/MozContainerWayland.cpp b/widget/gtk/MozContainerWayland.cpp
15 index 2a4a492077c3..0d9aacc954b7 100644
16 --- a/widget/gtk/MozContainerWayland.cpp
17 +++ b/widget/gtk/MozContainerWayland.cpp
18 @@ -597,6 +597,13 @@ void moz_container_wayland_set_scale_factor(MozContainer* container) {
22 +bool moz_container_wayland_size_matches_scale_factor_locked(
23 + const MutexAutoLock& aProofOfLock, MozContainer* container, int aWidth,
25 + return aWidth % container->wl_container.buffer_scale == 0 &&
26 + aHeight % container->wl_container.buffer_scale == 0;
29 static bool moz_container_wayland_surface_create_locked(
30 const MutexAutoLock& aProofOfLock, MozContainer* container) {
31 MozContainerWayland* wl_container = &container->wl_container;
32 diff --git a/widget/gtk/MozContainerWayland.h b/widget/gtk/MozContainerWayland.h
33 index d3c49baae8ac..369d40a55250 100644
34 --- a/widget/gtk/MozContainerWayland.h
35 +++ b/widget/gtk/MozContainerWayland.h
36 @@ -85,6 +85,9 @@ bool moz_container_wayland_egl_window_needs_size_update(MozContainer* container,
37 void moz_container_wayland_set_scale_factor(MozContainer* container);
38 void moz_container_wayland_set_scale_factor_locked(
39 const mozilla::MutexAutoLock& aProofOfLock, MozContainer* container);
40 +bool moz_container_wayland_size_matches_scale_factor_locked(
41 + const mozilla::MutexAutoLock& aProofOfLock, MozContainer* container,
42 + int aWidth, int aHeight);
44 void moz_container_wayland_add_initial_draw_callback_locked(
45 MozContainer* container, const std::function<void(void)>& initial_draw_cb);
46 diff --git a/widget/gtk/WindowSurfaceWaylandMultiBuffer.cpp b/widget/gtk/WindowSurfaceWaylandMultiBuffer.cpp
47 index 85ab1942d9e6..31091f4b9848 100644
48 --- a/widget/gtk/WindowSurfaceWaylandMultiBuffer.cpp
49 +++ b/widget/gtk/WindowSurfaceWaylandMultiBuffer.cpp
50 @@ -285,8 +285,8 @@ void WindowSurfaceWaylandMB::Commit(
51 mFrameInProcess = false;
53 MozContainer* container = mWindow->GetMozContainer();
54 - MozContainerSurfaceLock lock(container);
55 - struct wl_surface* waylandSurface = lock.GetSurface();
56 + MozContainerSurfaceLock MozContainerLock(container);
57 + struct wl_surface* waylandSurface = MozContainerLock.GetSurface();
58 if (!waylandSurface) {
60 "WindowSurfaceWaylandMB::Commit [%p] frame queued: can't lock "
61 @@ -319,8 +319,19 @@ void WindowSurfaceWaylandMB::Commit(
65 + // aProofOfLock is a kind of substitution of MozContainerSurfaceLock.
66 + // MozContainer is locked but MozContainerSurfaceLock doen't convert to
67 + // MutexAutoLock& so we use aProofOfLock here.
68 moz_container_wayland_set_scale_factor_locked(aProofOfLock, container);
69 - mInProgressBuffer->AttachAndCommit(waylandSurface);
71 + // It's possible that scale factor changed between Lock() and Commit()
72 + // but window size is the same.
73 + // Don't attach such buffer as it may have incorrect size,
74 + // we'll paint new content soon.
75 + if (moz_container_wayland_size_matches_scale_factor_locked(
76 + aProofOfLock, container, mWindowSize.width, mWindowSize.height)) {
77 + mInProgressBuffer->AttachAndCommit(waylandSurface);
80 mInProgressBuffer->ResetBufferAge();
81 mFrontBuffer = mInProgressBuffer;