macOS: Implement QCALayerBackingStore::toImage()

It's not part of the QBackingStore API, but clients such as the Qt Quick
software renderer access it through the platform backingstore, to grab
the window.

Change-Id: I203484ce13a5f8fb6815d27ab07f874fa9d16b8c
Fixes: QTBUG-75467
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
Tor Arne Vestbø 2019-05-09 14:08:23 +02:00 committed by Tor Arne Vestbø
parent 64a2dc3962
commit 3159845c9c
2 changed files with 16 additions and 0 deletions

View File

@ -81,6 +81,7 @@ public:
QPlatformTextureList *textures, bool translucentBackground) override;
#endif
QImage toImage() const override;
QPlatformGraphicsBuffer *graphicsBuffer() const override;
private:

View File

@ -534,6 +534,21 @@ void QCALayerBackingStore::composeAndFlush(QWindow *window, const QRegion &regio
}
#endif
QImage QCALayerBackingStore::toImage() const
{
if (!const_cast<QCALayerBackingStore*>(this)->prepareForFlush())
return QImage();
// We need to make a copy here, as the returned image could be used just
// for reading, in which case it won't detach, and then the underlying
// image data might change under the feet of the client when we re-use
// the buffer at a later point.
m_buffers.back()->lock(QPlatformGraphicsBuffer::SWReadAccess);
QImage imageCopy = m_buffers.back()->asImage()->copy();
m_buffers.back()->unlock();
return imageCopy;
}
QPlatformGraphicsBuffer *QCALayerBackingStore::graphicsBuffer() const
{
return m_buffers.back().get();