From a96b58798e957395a0e5e54f2b160859d9f9c58e Mon Sep 17 00:00:00 2001 From: Kai Uwe Broulik Date: Mon, 8 Jan 2024 14:25:19 +0100 Subject: [PATCH] QWaylandShmBackingStore: Split buffer preparation into dedicated method Drop "resize(QRect)" since it is ambiguous with the resize coming from QPlatformBackingStore. This allows to ensure a back buffer from multiple places, such as the upcoming "scroll" support. Change-Id: I43a5ece2d0e25e64b41335ba59b2b8c4ffcfff74 Reviewed-by: David Edmundson --- .../wayland/qwaylandshmbackingstore.cpp | 17 ++++++----------- .../wayland/qwaylandshmbackingstore_p.h | 3 +-- .../platforms/wayland/qwaylandwindow.cpp | 6 ++++-- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/plugins/platforms/wayland/qwaylandshmbackingstore.cpp b/src/plugins/platforms/wayland/qwaylandshmbackingstore.cpp index 723b264d518..a1e9e0e4a34 100644 --- a/src/plugins/platforms/wayland/qwaylandshmbackingstore.cpp +++ b/src/plugins/platforms/wayland/qwaylandshmbackingstore.cpp @@ -144,9 +144,9 @@ QWaylandShmBackingStore::QWaylandShmBackingStore(QWindow *window, QWaylandDispla // contents from the back buffer mBuffers.clear(); mFrontBuffer = nullptr; - // resize always resets mBackBuffer + // ensureBackBuffer always resets mBackBuffer if (mRequestedSize.isValid() && waylandWindow()) - resize(mRequestedSize); + ensureBackBuffer(); qDeleteAll(copy); }); } @@ -180,7 +180,8 @@ void QWaylandShmBackingStore::updateDirtyStates(const QRegion ®ion) void QWaylandShmBackingStore::beginPaint(const QRegion ®ion) { mPainting = true; - ensureSize(); + waylandWindow()->setBackingStore(this); + ensureBackBuffer(); const QMargins margins = windowDecorationMargins(); updateDirtyStates(region.translated(margins.left(), margins.top())); @@ -201,12 +202,6 @@ void QWaylandShmBackingStore::endPaint() flush(window(), mPendingRegion, QPoint()); } -void QWaylandShmBackingStore::ensureSize() -{ - waylandWindow()->setBackingStore(this); - resize(mRequestedSize); -} - void QWaylandShmBackingStore::flush(QWindow *window, const QRegion ®ion, const QPoint &offset) { // Invoked when the window is of type RasterSurface or when the window is @@ -269,11 +264,11 @@ QWaylandShmBuffer *QWaylandShmBackingStore::getBuffer(const QSize &size) return nullptr; } -void QWaylandShmBackingStore::resize(const QSize &size) +void QWaylandShmBackingStore::ensureBackBuffer() { QMargins margins = windowDecorationMargins(); qreal scale = waylandWindow()->scale(); - QSize sizeWithMargins = (size + QSize(margins.left()+margins.right(),margins.top()+margins.bottom())) * scale; + const QSize sizeWithMargins = (mRequestedSize + QSize(margins.left() + margins.right(), margins.top() + margins.bottom())) * scale; // We look for a free buffer to draw into. If the buffer is not the last buffer we used, // that is mBackBuffer, and the size is the same we copy the damaged content into the new diff --git a/src/plugins/platforms/wayland/qwaylandshmbackingstore_p.h b/src/plugins/platforms/wayland/qwaylandshmbackingstore_p.h index 8c7b83dbb48..78889336010 100644 --- a/src/plugins/platforms/wayland/qwaylandshmbackingstore_p.h +++ b/src/plugins/platforms/wayland/qwaylandshmbackingstore_p.h @@ -61,7 +61,6 @@ public: QPaintDevice *paintDevice() override; void flush(QWindow *window, const QRegion ®ion, const QPoint &offset) override; void resize(const QSize &size, const QRegion &staticContents) override; - void resize(const QSize &size); void beginPaint(const QRegion ®ion) override; void endPaint() override; @@ -70,7 +69,7 @@ public: QMargins windowDecorationMargins() const; QImage *entireSurface() const; QImage *contentSurface() const; - void ensureSize(); + void ensureBackBuffer(); QWaylandWindow *waylandWindow() const; void iterateBuffer(); diff --git a/src/plugins/platforms/wayland/qwaylandwindow.cpp b/src/plugins/platforms/wayland/qwaylandwindow.cpp index 7bc79eb8abd..bb33a747f6a 100644 --- a/src/plugins/platforms/wayland/qwaylandwindow.cpp +++ b/src/plugins/platforms/wayland/qwaylandwindow.cpp @@ -90,8 +90,10 @@ QWaylandWindow::~QWaylandWindow() void QWaylandWindow::ensureSize() { - if (mBackingStore) - mBackingStore->ensureSize(); + if (mBackingStore) { + setBackingStore(mBackingStore); + mBackingStore->ensureBackBuffer(); + } } void QWaylandWindow::initWindow()