From 1fbffb9dfb011c3b7c7aaa41b7be3a8167ce0c8a Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Wed, 18 Oct 2017 20:41:50 +0200 Subject: [PATCH] Ref count buffer usage The QPlatformBackingStore can get flushed multiple times between paints. Flush sets the front buffer, but it does not create a new backbuffer. We can't do so without doing an expensive pre-emptive copy. This means we send the same front buffer multiple times. This is somewhat questionable with regards to the Wayland specification, but seems to work. If we do send a buffer multiple times we can't consider it free until the last attached buffer is released; otherwise we end up painting into a buffer whilst the server is still using it, leading to flickering. Change-Id: I8235eed6a85f0d52b37544e7bcb623b16a9dd832 Reviewed-by: Marco Martin Reviewed-by: Johan Helsing --- src/plugins/platforms/wayland/qwaylandbuffer.cpp | 2 +- src/plugins/platforms/wayland/qwaylandbuffer_p.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/plugins/platforms/wayland/qwaylandbuffer.cpp b/src/plugins/platforms/wayland/qwaylandbuffer.cpp index a0fcc532f5b..076a0d57d74 100644 --- a/src/plugins/platforms/wayland/qwaylandbuffer.cpp +++ b/src/plugins/platforms/wayland/qwaylandbuffer.cpp @@ -66,7 +66,7 @@ void QWaylandBuffer::init(wl_buffer *buf) void QWaylandBuffer::release(void *data, wl_buffer *) { - static_cast(data)->mBusy = false; + static_cast(data)->mBusy--; } const wl_buffer_listener QWaylandBuffer::listener = { diff --git a/src/plugins/platforms/wayland/qwaylandbuffer_p.h b/src/plugins/platforms/wayland/qwaylandbuffer_p.h index 9e8cba2e490..b3513d1515e 100644 --- a/src/plugins/platforms/wayland/qwaylandbuffer_p.h +++ b/src/plugins/platforms/wayland/qwaylandbuffer_p.h @@ -73,14 +73,14 @@ public: virtual QSize size() const = 0; virtual int scale() const { return 1; } - void setBusy() { mBusy = true; } - bool busy() const { return mBusy; } + void setBusy() { mBusy++; } + bool busy() const { return mBusy > 0; } protected: struct wl_buffer *mBuffer; private: - bool mBusy; + int mBusy; static void release(void *data, wl_buffer *); static const wl_buffer_listener listener;