Paste P115

Masterwork From Distant Lands
ActivePublic

Authored by davidedmundson on Oct 17 2017, 10:08 AM.
From dbe272165b8c4a4662277775c5ef22be89877856 Mon Sep 17 00:00:00 2001
From: David Edmundson <davidedmundson@kde.org>
Date: Sat, 14 Oct 2017 07:32:28 +0200
Subject: [PATCH] Swap buffers after painting finishes
Backing stores can have the pattern:
beginPainting()
flush()
flush()
endPainting()
With a flush per region being painted.
QtWayland finds a new empty buffer in beginPainting, but performs the
swap and commit on every flush. This doesn't create a new backbuffer.
The end result is we attach and commit the same buffer multiple times
before the buffer is released. This is illegal wayland behaviour and
leads to extreme flickering in.
With this patch, when flushing during an active paint the active
backbuffer is not swapped, but copied into a new front buffer.
---
src/client/qwaylandshmbackingstore.cpp | 18 +++++++++++++-----
src/client/qwaylandshmbackingstore_p.h | 2 +-
2 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/src/client/qwaylandshmbackingstore.cpp b/src/client/qwaylandshmbackingstore.cpp
index 2085bc59..79ef544c 100644
--- a/src/client/qwaylandshmbackingstore.cpp
+++ b/src/client/qwaylandshmbackingstore.cpp
@@ -210,7 +210,7 @@ void QWaylandShmBackingStore::ensureSize()
{
waylandWindow()->setBackingStore(this);
waylandWindow()->createDecoration();
- resize(mRequestedSize);
+ mBackBuffer = resize(mRequestedSize);
}
void QWaylandShmBackingStore::flush(QWindow *window, const QRegion &region, const QPoint &offset)
@@ -228,11 +228,15 @@ void QWaylandShmBackingStore::flush(QWindow *window, const QRegion &region, cons
if (windowDecoration() && windowDecoration()->isDirty())
updateDecorations();
- mFrontBuffer = mBackBuffer;
+ //if the back buffer is still being painted into, copy the data from the current active backbuffer
+ if (mPainting)
+ mFrontBuffer = resize(mBackBuffer->size());
+ else
+ mFrontBuffer = mBackBuffer;
QMargins margins = windowDecorationMargins();
- waylandWindow()->commit(mFrontBuffer, region.translated(margins.left(), margins.top()));
+ waylandWindow()->commit(mFrontBuffer, region.translated(margins.top(), margins.top()));
}
void QWaylandShmBackingStore::resize(const QSize &size, const QRegion &)
@@ -243,6 +247,9 @@ void QWaylandShmBackingStore::resize(const QSize &size, const QRegion &)
QWaylandShmBuffer *QWaylandShmBackingStore::getBuffer(const QSize &size)
{
foreach (QWaylandShmBuffer *b, mBuffers) {
+ if (mPainting && b == mBackBuffer)
+ continue;
+
if (!b->busy()) {
if (b->size() == size) {
return b;
@@ -265,7 +272,7 @@ QWaylandShmBuffer *QWaylandShmBackingStore::getBuffer(const QSize &size)
return 0;
}
-void QWaylandShmBackingStore::resize(const QSize &size)
+QWaylandShmBuffer* QWaylandShmBackingStore::resize(const QSize &size)
{
QMargins margins = windowDecorationMargins();
int scale = waylandWindow()->scale();
@@ -292,7 +299,6 @@ void QWaylandShmBackingStore::resize(const QSize &size)
if (mBackBuffer != buffer && oldSize == buffer->image()->byteCount()) {
memcpy(buffer->image()->bits(), mBackBuffer->image()->constBits(), buffer->image()->byteCount());
}
- mBackBuffer = buffer;
// ensure the new buffer is at the beginning of the list so next time getBuffer() will pick
// it if possible
if (mBuffers.first() != buffer) {
@@ -302,6 +308,8 @@ void QWaylandShmBackingStore::resize(const QSize &size)
if (windowDecoration() && window()->isVisible())
windowDecoration()->update();
+
+ return buffer;
}
QImage *QWaylandShmBackingStore::entireSurface() const
diff --git a/src/client/qwaylandshmbackingstore_p.h b/src/client/qwaylandshmbackingstore_p.h
index 251368ef..81a15895 100644
--- a/src/client/qwaylandshmbackingstore_p.h
+++ b/src/client/qwaylandshmbackingstore_p.h
@@ -93,7 +93,7 @@ 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);
+ QWaylandShmBuffer* resize(const QSize &size);
void beginPaint(const QRegion &region) override;
void endPaint() override;
--
2.14.1
davidedmundson edited the content of this paste. (Show Details)Oct 17 2017, 10:08 AM
davidedmundson changed the title of this paste from untitled to Masterwork From Distant Lands.
davidedmundson updated the paste's language from autodetect to autodetect.