diff options
author | Tor Arne Vestbø <torarnv@gmail.com> | 2019-05-09 14:08:23 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2019-05-10 09:41:41 +0000 |
commit | 3159845c9c6c72c3e4492c2359c8a020fdb6ce5d (patch) | |
tree | ffc94f0b3497bbdb7a60fcb22042c3d435faca57 | |
parent | 64a2dc3962eabd7e59fb408a0b1604891302df72 (diff) | |
download | qtbase-3159845c9c6c72c3e4492c2359c8a020fdb6ce5d.tar.gz |
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>
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoabackingstore.h | 1 | ||||
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoabackingstore.mm | 15 |
2 files changed, 16 insertions, 0 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoabackingstore.h b/src/plugins/platforms/cocoa/qcocoabackingstore.h index 470da63e3d..acddc3ecc8 100644 --- a/src/plugins/platforms/cocoa/qcocoabackingstore.h +++ b/src/plugins/platforms/cocoa/qcocoabackingstore.h @@ -81,6 +81,7 @@ public: QPlatformTextureList *textures, bool translucentBackground) override; #endif + QImage toImage() const override; QPlatformGraphicsBuffer *graphicsBuffer() const override; private: diff --git a/src/plugins/platforms/cocoa/qcocoabackingstore.mm b/src/plugins/platforms/cocoa/qcocoabackingstore.mm index e786ecb5a5..cff1f96615 100644 --- a/src/plugins/platforms/cocoa/qcocoabackingstore.mm +++ b/src/plugins/platforms/cocoa/qcocoabackingstore.mm @@ -534,6 +534,21 @@ void QCALayerBackingStore::composeAndFlush(QWindow *window, const QRegion ®io } #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(); |