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 <davidedmundson@kde.org>
This commit is contained in:
Kai Uwe Broulik 2024-01-08 14:25:19 +01:00
parent 468e59f478
commit a96b58798e
3 changed files with 11 additions and 15 deletions

View File

@ -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 &region)
void QWaylandShmBackingStore::beginPaint(const QRegion &region)
{
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 &region, 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

View File

@ -61,7 +61,6 @@ public:
QPaintDevice *paintDevice() override;
void flush(QWindow *window, const QRegion &region, const QPoint &offset) override;
void resize(const QSize &size, const QRegion &staticContents) override;
void resize(const QSize &size);
void beginPaint(const QRegion &region) 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();

View File

@ -90,8 +90,10 @@ QWaylandWindow::~QWaylandWindow()
void QWaylandWindow::ensureSize()
{
if (mBackingStore)
mBackingStore->ensureSize();
if (mBackingStore) {
setBackingStore(mBackingStore);
mBackingStore->ensureBackBuffer();
}
}
void QWaylandWindow::initWindow()