From f3e4495e4471204768eaf98d5128e92869e3b435 Mon Sep 17 00:00:00 2001 From: Mouse Zhang Date: Mon, 22 May 2023 16:52:13 +0800 Subject: [PATCH] plugins/qpa: initialize buffer in backingstore BUG: 437062 --- src/plugins/qpa/backingstore.cpp | 13 +++++++++++++ src/plugins/qpa/backingstore.h | 1 + 2 files changed, 14 insertions(+) diff --git a/src/plugins/qpa/backingstore.cpp b/src/plugins/qpa/backingstore.cpp index 55862c3424..89307b73f2 100644 --- a/src/plugins/qpa/backingstore.cpp +++ b/src/plugins/qpa/backingstore.cpp @@ -47,6 +47,18 @@ void BackingStore::resize(const QSize &size, const QRegion &staticContents) m_frontBuffer.setDevicePixelRatio(devicePixelRatio); } +void BackingStore::beginPaint(const QRegion ®ion) +{ + if (m_backBuffer.hasAlphaChannel()) { + QPainter p(paintDevice()); + p.setCompositionMode(QPainter::CompositionMode_Source); + const QColor blank = Qt::transparent; + for (const QRect &rect : region) { + p.fillRect(rect, blank); + } + } +} + static QRect scaledRect(const QRect &rect, qreal devicePixelRatio) { return QRect(rect.topLeft() * devicePixelRatio, rect.size() * devicePixelRatio); @@ -55,6 +67,7 @@ static QRect scaledRect(const QRect &rect, qreal devicePixelRatio) static void blitImage(const QImage &source, QImage &target, const QRegion ®ion) { QPainter painter(&target); + painter.setCompositionMode(QPainter::CompositionMode_Source); for (const QRect &rect : region) { painter.drawImage(rect, source, scaledRect(rect, source.devicePixelRatio())); } diff --git a/src/plugins/qpa/backingstore.h b/src/plugins/qpa/backingstore.h index 09e4672891..a204e4213f 100644 --- a/src/plugins/qpa/backingstore.h +++ b/src/plugins/qpa/backingstore.h @@ -27,6 +27,7 @@ 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 beginPaint(const QRegion ®ion) override; private: QImage m_backBuffer;