plugins/qpa: Simplify backing store buffer handling
The main reasoning behind double buffering was to avoid InternalWindow's copy of m_frontBuffer detaching. But it already detaches when the qpa calls blitImage(). So remove double buffering to simplify the backing store.
This commit is contained in:
parent
fc02990b77
commit
665e05d711
2 changed files with 11 additions and 31 deletions
|
@ -28,28 +28,25 @@ BackingStore::~BackingStore() = default;
|
|||
|
||||
QPaintDevice *BackingStore::paintDevice()
|
||||
{
|
||||
return &m_backBuffer;
|
||||
return &m_buffer;
|
||||
}
|
||||
|
||||
void BackingStore::resize(const QSize &size, const QRegion &staticContents)
|
||||
{
|
||||
if (m_backBuffer.size() == size) {
|
||||
if (m_buffer.size() == size) {
|
||||
return;
|
||||
}
|
||||
|
||||
const QPlatformWindow *platformWindow = static_cast<QPlatformWindow *>(window()->handle());
|
||||
const qreal devicePixelRatio = platformWindow->devicePixelRatio();
|
||||
|
||||
m_backBuffer = QImage(size * devicePixelRatio, QImage::Format_ARGB32_Premultiplied);
|
||||
m_backBuffer.setDevicePixelRatio(devicePixelRatio);
|
||||
|
||||
m_frontBuffer = QImage(size * devicePixelRatio, QImage::Format_ARGB32_Premultiplied);
|
||||
m_frontBuffer.setDevicePixelRatio(devicePixelRatio);
|
||||
m_buffer = QImage(size * devicePixelRatio, QImage::Format_ARGB32_Premultiplied);
|
||||
m_buffer.setDevicePixelRatio(devicePixelRatio);
|
||||
}
|
||||
|
||||
void BackingStore::beginPaint(const QRegion ®ion)
|
||||
{
|
||||
if (m_backBuffer.hasAlphaChannel()) {
|
||||
if (m_buffer.hasAlphaChannel()) {
|
||||
QPainter p(paintDevice());
|
||||
p.setCompositionMode(QPainter::CompositionMode_Source);
|
||||
const QColor blank = Qt::transparent;
|
||||
|
@ -59,20 +56,6 @@ void BackingStore::beginPaint(const QRegion ®ion)
|
|||
}
|
||||
}
|
||||
|
||||
static QRect scaledRect(const QRect &rect, qreal devicePixelRatio)
|
||||
{
|
||||
return QRect(rect.topLeft() * devicePixelRatio, rect.size() * 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()));
|
||||
}
|
||||
}
|
||||
|
||||
void BackingStore::flush(QWindow *window, const QRegion ®ion, const QPoint &offset)
|
||||
{
|
||||
Window *platformWindow = static_cast<Window *>(window->handle());
|
||||
|
@ -81,17 +64,15 @@ void BackingStore::flush(QWindow *window, const QRegion ®ion, const QPoint &o
|
|||
return;
|
||||
}
|
||||
|
||||
blitImage(m_backBuffer, m_frontBuffer, region);
|
||||
|
||||
QRegion bufferDamage;
|
||||
for (const QRect &rect : region) {
|
||||
bufferDamage |= QRect(std::floor(rect.x() * m_backBuffer.devicePixelRatio()),
|
||||
std::floor(rect.y() * m_backBuffer.devicePixelRatio()),
|
||||
std::ceil(rect.width() * m_backBuffer.devicePixelRatio()),
|
||||
std::ceil(rect.height() * m_backBuffer.devicePixelRatio()));
|
||||
bufferDamage |= QRect(std::floor(rect.x() * m_buffer.devicePixelRatio()),
|
||||
std::floor(rect.y() * m_buffer.devicePixelRatio()),
|
||||
std::ceil(rect.width() * m_buffer.devicePixelRatio()),
|
||||
std::ceil(rect.height() * m_buffer.devicePixelRatio()));
|
||||
}
|
||||
|
||||
internalWindow->present(m_frontBuffer, bufferDamage);
|
||||
internalWindow->present(m_buffer, bufferDamage);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,8 +30,7 @@ public:
|
|||
void beginPaint(const QRegion ®ion) override;
|
||||
|
||||
private:
|
||||
QImage m_backBuffer;
|
||||
QImage m_frontBuffer;
|
||||
QImage m_buffer;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue