diff --git a/src/platformsupport/graphics/qrasterbackingstore.cpp b/src/platformsupport/graphics/qrasterbackingstore.cpp index 58e811dff1..325c98b93d 100644 --- a/src/platformsupport/graphics/qrasterbackingstore.cpp +++ b/src/platformsupport/graphics/qrasterbackingstore.cpp @@ -62,13 +62,20 @@ void QRasterBackingStore::resize(const QSize &size, const QRegion &staticContent if (m_image.size() == effectiveBufferSize) return; - QImage::Format format = window()->format().hasAlpha() ? QImage::Format_ARGB32_Premultiplied : QImage::Format_RGB32; - m_image = QImage(effectiveBufferSize, format); + m_image = QImage(effectiveBufferSize, format()); m_image.setDevicePixelRatio(windowDevicePixelRatio); - if (format == QImage::Format_ARGB32_Premultiplied) + if (m_image.format() == QImage::Format_ARGB32_Premultiplied) m_image.fill(Qt::transparent); } +QImage::Format QRasterBackingStore::format() const +{ + if (window()->format().hasAlpha()) + return QImage::Format_ARGB32_Premultiplied; + else + return QImage::Format_RGB32; +} + QPaintDevice *QRasterBackingStore::paintDevice() { return &m_image; diff --git a/src/platformsupport/graphics/qrasterbackingstore_p.h b/src/platformsupport/graphics/qrasterbackingstore_p.h index de96c99b5a..55976d2ceb 100644 --- a/src/platformsupport/graphics/qrasterbackingstore_p.h +++ b/src/platformsupport/graphics/qrasterbackingstore_p.h @@ -62,13 +62,16 @@ public: QRasterBackingStore(QWindow *window); ~QRasterBackingStore(); - QPaintDevice *paintDevice() Q_DECL_OVERRIDE; - QImage toImage() const Q_DECL_OVERRIDE; - void resize (const QSize &size, const QRegion &) Q_DECL_OVERRIDE; + void resize(const QSize &size, const QRegion &staticContents) Q_DECL_OVERRIDE; bool scroll(const QRegion &area, int dx, int dy) Q_DECL_OVERRIDE; void beginPaint(const QRegion ®ion) Q_DECL_OVERRIDE; + QPaintDevice *paintDevice() Q_DECL_OVERRIDE; + QImage toImage() const Q_DECL_OVERRIDE; + protected: + virtual QImage::Format format() const; + QImage m_image; }; diff --git a/src/platformsupport/platformsupport.pro b/src/platformsupport/platformsupport.pro index 15bbaf94c9..19efa60f48 100644 --- a/src/platformsupport/platformsupport.pro +++ b/src/platformsupport/platformsupport.pro @@ -29,6 +29,6 @@ unix:!darwin:qtConfig(dbus) { include(dbusmenu/dbusmenu.pri) include(dbustray/dbustray.pri) } -uikit: include(graphics/graphics.pri) +darwin: include(graphics/graphics.pri) load(qt_module) diff --git a/src/plugins/platforms/cocoa/qcocoabackingstore.h b/src/plugins/platforms/cocoa/qcocoabackingstore.h index 52a3e756b9..562be2be8f 100644 --- a/src/plugins/platforms/cocoa/qcocoabackingstore.h +++ b/src/plugins/platforms/cocoa/qcocoabackingstore.h @@ -40,33 +40,20 @@ #ifndef QBACKINGSTORE_COCOA_H #define QBACKINGSTORE_COCOA_H -#include - -#include "qcocoawindow.h" -#include "qnsview.h" - -#include +#include QT_BEGIN_NAMESPACE -class QCocoaBackingStore : public QPlatformBackingStore +class QCocoaBackingStore : public QRasterBackingStore { public: QCocoaBackingStore(QWindow *window); ~QCocoaBackingStore(); - QPaintDevice *paintDevice() Q_DECL_OVERRIDE; - void flush(QWindow *widget, const QRegion ®ion, const QPoint &offset) Q_DECL_OVERRIDE; - QImage toImage() const Q_DECL_OVERRIDE; - - void resize (const QSize &size, const QRegion &) Q_DECL_OVERRIDE; - bool scroll(const QRegion &area, int dx, int dy) Q_DECL_OVERRIDE; - void beginPaint(const QRegion ®ion) Q_DECL_OVERRIDE; - qreal getBackingStoreDevicePixelRatio(); + void flush(QWindow *, const QRegion &, const QPoint &) Q_DECL_OVERRIDE; private: - QImage m_qImage; - QSize m_requestedSize; + QImage::Format format() const Q_DECL_OVERRIDE; }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/cocoa/qcocoabackingstore.mm b/src/plugins/platforms/cocoa/qcocoabackingstore.mm index 20233518b3..af5418315c 100644 --- a/src/plugins/platforms/cocoa/qcocoabackingstore.mm +++ b/src/plugins/platforms/cocoa/qcocoabackingstore.mm @@ -38,13 +38,13 @@ ****************************************************************************/ #include "qcocoabackingstore.h" -#include -#include "qcocoahelpers.h" + +#include "qcocoawindow.h" QT_BEGIN_NAMESPACE QCocoaBackingStore::QCocoaBackingStore(QWindow *window) - : QPlatformBackingStore(window) + : QRasterBackingStore(window) { } @@ -54,69 +54,21 @@ QCocoaBackingStore::~QCocoaBackingStore() [cocoaWindow->m_qtView clearBackingStore:this]; } -QPaintDevice *QCocoaBackingStore::paintDevice() +QImage::Format QCocoaBackingStore::format() const { - QCocoaWindow *cocoaWindow = static_cast(window()->handle()); - int windowDevicePixelRatio = int(cocoaWindow->devicePixelRatio()); + if (static_cast(window()->handle())->m_drawContentBorderGradient) + return QImage::Format_ARGB32_Premultiplied; - // Receate the backing store buffer if the effective buffer size has changed, - // either due to a window resize or devicePixelRatio change. - QSize effectiveBufferSize = m_requestedSize * windowDevicePixelRatio; - if (m_qImage.size() != effectiveBufferSize) { - QImage::Format format = (window()->format().hasAlpha() || cocoaWindow->m_drawContentBorderGradient) - ? QImage::Format_ARGB32_Premultiplied : QImage::Format_RGB32; - m_qImage = QImage(effectiveBufferSize, format); - m_qImage.setDevicePixelRatio(windowDevicePixelRatio); - if (format == QImage::Format_ARGB32_Premultiplied) - m_qImage.fill(Qt::transparent); - } - return &m_qImage; + return QRasterBackingStore::format(); } -void QCocoaBackingStore::flush(QWindow *win, const QRegion ®ion, const QPoint &offset) +void QCocoaBackingStore::flush(QWindow *window, const QRegion ®ion, const QPoint &offset) { - if (!m_qImage.isNull()) { - if (QCocoaWindow *cocoaWindow = static_cast(win->handle())) - [cocoaWindow->m_qtView flushBackingStore:this region:region offset:offset]; - } -} + if (m_image.isNull()) + return; -QImage QCocoaBackingStore::toImage() const -{ - return m_qImage; -} - -void QCocoaBackingStore::resize(const QSize &size, const QRegion &) -{ - m_requestedSize = size; -} - -bool QCocoaBackingStore::scroll(const QRegion &area, int dx, int dy) -{ - extern void qt_scrollRectInImage(QImage &img, const QRect &rect, const QPoint &offset); - const qreal devicePixelRatio = m_qImage.devicePixelRatio(); - QPoint qpoint(dx * devicePixelRatio, dy * devicePixelRatio); - for (const QRect &rect : area) { - const QRect qrect(rect.topLeft() * devicePixelRatio, rect.size() * devicePixelRatio); - qt_scrollRectInImage(m_qImage, qrect, qpoint); - } - return true; -} - -void QCocoaBackingStore::beginPaint(const QRegion ®ion) -{ - if (m_qImage.hasAlphaChannel()) { - QPainter p(&m_qImage); - p.setCompositionMode(QPainter::CompositionMode_Source); - const QColor blank = Qt::transparent; - for (const QRect &rect : region) - p.fillRect(rect, blank); - } -} - -qreal QCocoaBackingStore::getBackingStoreDevicePixelRatio() -{ - return m_qImage.devicePixelRatio(); + if (QCocoaWindow *cocoaWindow = static_cast(window->handle())) + [cocoaWindow->m_qtView flushBackingStore:this region:region offset:offset]; } QT_END_NAMESPACE diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm index 3d30aca7e7..22a32c7ceb 100644 --- a/src/plugins/platforms/cocoa/qnsview.mm +++ b/src/plugins/platforms/cocoa/qnsview.mm @@ -495,7 +495,7 @@ static bool _q_dontOverrideCtrlLMB = false; qCDebug(lcQpaCocoaWindow) << "[QNSView flushBackingStore:]" << m_window << region.rectCount() << region.boundingRect() << offset; m_backingStore = backingStore; - m_backingStoreOffset = offset * m_backingStore->getBackingStoreDevicePixelRatio(); + m_backingStoreOffset = offset * m_backingStore->paintDevice()->devicePixelRatio(); for (const QRect &rect : region) [self setNeedsDisplayInRect:NSMakeRect(rect.x(), rect.y(), rect.width(), rect.height())]; } @@ -577,7 +577,7 @@ static bool _q_dontOverrideCtrlLMB = false; // The backing store source rect will be larger on retina displays. // Scale dirtyRect by the device pixel ratio: - const qreal devicePixelRatio = m_backingStore->getBackingStoreDevicePixelRatio(); + const qreal devicePixelRatio = m_backingStore->paintDevice()->devicePixelRatio(); CGRect dirtyBackingRect = CGRectMake(dirtyRect.origin.x * devicePixelRatio, dirtyRect.origin.y * devicePixelRatio, dirtyRect.size.width * devicePixelRatio,