From 3a3f3eb92478028d7e68c19353d65e4aada09bba Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Thu, 25 Apr 2019 08:58:49 +0200 Subject: [PATCH] Client: Avoid unnecessarily redrawing decorations Note: QWaylandAbstractDecoration::update() doesn't actually update anything, it just sets a dirty flag, and this is done explicitly in the other cases when the decorations need to be redrawn as well (title and icon changes). Fixes: QTBUG-75377 Change-Id: I2e8bd3abd3664c741e69a3e83ebf409872ddf31a Reviewed-by: Paul Olav Tvete --- .../platforms/wayland/qwaylandshmbackingstore.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/plugins/platforms/wayland/qwaylandshmbackingstore.cpp b/src/plugins/platforms/wayland/qwaylandshmbackingstore.cpp index 34044ec9bca..c16d346eb3f 100644 --- a/src/plugins/platforms/wayland/qwaylandshmbackingstore.cpp +++ b/src/plugins/platforms/wayland/qwaylandshmbackingstore.cpp @@ -288,12 +288,15 @@ void QWaylandShmBackingStore::resize(const QSize &size) buffer = getBuffer(sizeWithMargins); } - qsizetype oldSize = mBackBuffer ? mBackBuffer->image()->sizeInBytes() : 0; + qsizetype oldSizeInBytes = mBackBuffer ? mBackBuffer->image()->sizeInBytes() : 0; + qsizetype newSizeInBytes = buffer->image()->sizeInBytes(); + // mBackBuffer may have been deleted here but if so it means its size was different so we wouldn't copy it anyway - if (mBackBuffer != buffer && oldSize == buffer->image()->sizeInBytes()) { - memcpy(buffer->image()->bits(), mBackBuffer->image()->constBits(), buffer->image()->sizeInBytes()); - } + if (mBackBuffer != buffer && oldSizeInBytes == newSizeInBytes) + memcpy(buffer->image()->bits(), mBackBuffer->image()->constBits(), newSizeInBytes); + 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) { @@ -301,7 +304,7 @@ void QWaylandShmBackingStore::resize(const QSize &size) mBuffers.prepend(buffer); } - if (windowDecoration() && window()->isVisible()) + if (windowDecoration() && window()->isVisible() && oldSizeInBytes != newSizeInBytes) windowDecoration()->update(); }