summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/platforms/cocoa')
-rw-r--r--src/plugins/platforms/cocoa/cocoa.pro41
-rw-r--r--src/plugins/platforms/cocoa/qcocoabackingstore.h5
-rw-r--r--src/plugins/platforms/cocoa/qcocoabackingstore.mm56
-rw-r--r--src/plugins/platforms/cocoa/qcocoanativeinterface.mm10
-rw-r--r--src/plugins/platforms/cocoa/qcocoawindow.h1
-rw-r--r--src/plugins/platforms/cocoa/qcocoawindow.mm26
-rw-r--r--src/plugins/platforms/cocoa/qnsview_mouse.mm4
-rw-r--r--src/plugins/platforms/cocoa/qnswindow.mm14
-rw-r--r--src/plugins/platforms/cocoa/qpaintengine_mac.mm4
9 files changed, 108 insertions, 53 deletions
diff --git a/src/plugins/platforms/cocoa/cocoa.pro b/src/plugins/platforms/cocoa/cocoa.pro
index 02e00039ae..4cf9e64447 100644
--- a/src/plugins/platforms/cocoa/cocoa.pro
+++ b/src/plugins/platforms/cocoa/cocoa.pro
@@ -21,8 +21,6 @@ SOURCES += main.mm \
qcocoamenuloader.mm \
qcocoahelpers.mm \
qmultitouch_mac.mm \
- qcocoaaccessibilityelement.mm \
- qcocoaaccessibility.mm \
qcocoacursor.mm \
qcocoaclipboard.mm \
qcocoadrag.mm \
@@ -57,8 +55,6 @@ HEADERS += qcocoaintegration.h \
qcocoamenuloader.h \
qcocoahelpers.h \
qmultitouch_mac_p.h \
- qcocoaaccessibilityelement.h \
- qcocoaaccessibility.h \
qcocoacursor.h \
qcocoaclipboard.h \
qcocoadrag.h \
@@ -83,13 +79,21 @@ qtConfig(vulkan) {
HEADERS += qcocoavulkaninstance.h
}
+qtConfig(accessibility) {
+ QT += accessibility_support-private
+ SOURCES += qcocoaaccessibilityelement.mm \
+ qcocoaaccessibility.mm
+ HEADERS += qcocoaaccessibilityelement.h \
+ qcocoaaccessibility.h
+}
+
RESOURCES += qcocoaresources.qrc
LIBS += -framework AppKit -framework CoreServices -framework Carbon -framework IOKit -framework QuartzCore -framework CoreVideo -framework Metal -framework IOSurface -lcups
QT += \
core-private gui-private \
- accessibility_support-private clipboard_support-private theme_support-private \
+ clipboard_support-private theme_support-private \
fontdatabase_support-private graphics_support-private
qtConfig(vulkan): QT += vulkan_support-private
@@ -99,17 +103,20 @@ CONFIG += no_app_extension_api_only
qtHaveModule(widgets) {
QT_FOR_CONFIG += widgets
- SOURCES += \
- qpaintengine_mac.mm \
- qprintengine_mac.mm \
- qcocoaprintersupport.mm \
- qcocoaprintdevice.mm \
-
- HEADERS += \
- qpaintengine_mac_p.h \
- qprintengine_mac_p.h \
- qcocoaprintersupport.h \
- qcocoaprintdevice.h \
+ SOURCES += qpaintengine_mac.mm
+ HEADERS += qpaintengine_mac_p.h
+
+ qtHaveModule(printsupport) {
+ QT += printsupport-private
+ SOURCES += \
+ qprintengine_mac.mm \
+ qcocoaprintersupport.mm \
+ qcocoaprintdevice.mm
+ HEADERS += \
+ qcocoaprintersupport.h \
+ qcocoaprintdevice.h \
+ qprintengine_mac_p.h
+ }
qtConfig(colordialog) {
SOURCES += qcocoacolordialoghelper.mm
@@ -126,7 +133,7 @@ qtHaveModule(widgets) {
HEADERS += qcocoafontdialoghelper.h
}
- QT += widgets-private printsupport-private
+ QT += widgets-private
}
OTHER_FILES += cocoa.json
diff --git a/src/plugins/platforms/cocoa/qcocoabackingstore.h b/src/plugins/platforms/cocoa/qcocoabackingstore.h
index 9be6814ae7..a874936ce6 100644
--- a/src/plugins/platforms/cocoa/qcocoabackingstore.h
+++ b/src/plugins/platforms/cocoa/qcocoabackingstore.h
@@ -54,6 +54,8 @@ class QCocoaBackingStore : public QRasterBackingStore
protected:
QCocoaBackingStore(QWindow *window);
QCFType<CGColorSpaceRef> colorSpace() const;
+ QMacNotificationObserver m_backingPropertiesObserver;
+ virtual void backingPropertiesChanged() = 0;
};
class QNSWindowBackingStore : public QCocoaBackingStore
@@ -69,6 +71,7 @@ private:
bool windowHasUnifiedToolbar() const;
QImage::Format format() const override;
void redrawRoundedBottomCorners(CGRect) const;
+ void backingPropertiesChanged() override;
};
class QCALayerBackingStore : public QCocoaBackingStore
@@ -115,6 +118,8 @@ private:
bool recreateBackBufferIfNeeded();
bool prepareForFlush();
+ void backingPropertiesChanged() override;
+
std::list<std::unique_ptr<GraphicsBuffer>> m_buffers;
};
diff --git a/src/plugins/platforms/cocoa/qcocoabackingstore.mm b/src/plugins/platforms/cocoa/qcocoabackingstore.mm
index 15e0236107..eb316c53a8 100644
--- a/src/plugins/platforms/cocoa/qcocoabackingstore.mm
+++ b/src/plugins/platforms/cocoa/qcocoabackingstore.mm
@@ -51,6 +51,17 @@ QT_BEGIN_NAMESPACE
QCocoaBackingStore::QCocoaBackingStore(QWindow *window)
: QRasterBackingStore(window)
{
+ // Ideally this would be plumbed from the platform layer to QtGui, and
+ // the QBackingStore would be recreated, but we don't have that code yet,
+ // so at least make sure we invalidate our backingstore when the backing
+ // properties (color space e.g.) are changed.
+ NSView *view = static_cast<QCocoaWindow *>(window->handle())->view();
+ m_backingPropertiesObserver = QMacNotificationObserver(view.window,
+ NSWindowDidChangeBackingPropertiesNotification, [this]() {
+ qCDebug(lcQpaBackingStore) << "Backing properties for"
+ << this->window() << "did change";
+ backingPropertiesChanged();
+ });
}
QCFType<CGColorSpaceRef> QCocoaBackingStore::colorSpace() const
@@ -64,6 +75,37 @@ QCFType<CGColorSpaceRef> QCocoaBackingStore::colorSpace() const
QNSWindowBackingStore::QNSWindowBackingStore(QWindow *window)
: QCocoaBackingStore(window)
{
+ // Choose an appropriate window depth based on the requested surface format.
+ // On deep color displays the default bit depth is 16-bit, so unless we need
+ // that level of precision we opt out of it (and the expensive RGB32 -> RGB64
+ // conversions that come with it if our backingstore depth does not match).
+
+ NSWindow *nsWindow = static_cast<QCocoaWindow *>(window->handle())->view().window;
+ auto colorSpaceName = NSColorSpaceFromDepth(nsWindow.depthLimit);
+
+ static const int kDefaultBitDepth = 8;
+ auto surfaceFormat = window->requestedFormat();
+ auto bitsPerSample = qMax(kDefaultBitDepth, qMax(surfaceFormat.redBufferSize(),
+ qMax(surfaceFormat.greenBufferSize(), surfaceFormat.blueBufferSize())));
+
+ // NSBestDepth does not seem to guarantee a window depth deep enough for the
+ // given bits per sample, even if documented as such. For example, requesting
+ // 10 bits per sample will not give us a 16-bit format, even if that's what's
+ // available. Work around this by manually bumping the bit depth.
+ bitsPerSample = !(bitsPerSample & (bitsPerSample - 1))
+ ? bitsPerSample : qNextPowerOfTwo(bitsPerSample);
+
+ auto bestDepth = NSBestDepth(colorSpaceName, bitsPerSample, 0, NO, nullptr);
+
+ // Disable dynamic depth limit, otherwise our depth limit will be overwritten
+ // by AppKit if the window moves to a screen with a different depth. We call
+ // this before setting the depth limit, as the call will reset the depth to 0.
+ [nsWindow setDynamicDepthLimit:NO];
+
+ qCDebug(lcQpaBackingStore) << "Using" << NSBitsPerSampleFromDepth(bestDepth)
+ << "bit window depth for" << nsWindow;
+
+ nsWindow.depthLimit = bestDepth;
}
QNSWindowBackingStore::~QNSWindowBackingStore()
@@ -212,9 +254,6 @@ void QNSWindowBackingStore::flush(QWindow *window, const QRegion &region, const
CGRect viewRect = viewLocalRect.toCGRect();
- if (windowHasUnifiedToolbar())
- NSDrawWindowBackground(viewRect);
-
[backingStoreImage drawInRect:viewRect fromRect:backingStoreRect.toCGRect()
operation:compositingOperation fraction:1.0 respectFlipped:YES hints:nil];
@@ -302,6 +341,11 @@ void QNSWindowBackingStore::redrawRoundedBottomCorners(CGRect windowRect) const
#endif
}
+void QNSWindowBackingStore::backingPropertiesChanged()
+{
+ m_image = QImage();
+}
+
// ----------------------------------------------------------------------------
QCALayerBackingStore::QCALayerBackingStore(QWindow *window)
@@ -565,6 +609,12 @@ QImage QCALayerBackingStore::toImage() const
return imageCopy;
}
+void QCALayerBackingStore::backingPropertiesChanged()
+{
+ m_buffers.clear();
+ m_buffers.resize(1);
+}
+
QPlatformGraphicsBuffer *QCALayerBackingStore::graphicsBuffer() const
{
return m_buffers.back().get();
diff --git a/src/plugins/platforms/cocoa/qcocoanativeinterface.mm b/src/plugins/platforms/cocoa/qcocoanativeinterface.mm
index 9bd19dd07c..d0e69bdca5 100644
--- a/src/plugins/platforms/cocoa/qcocoanativeinterface.mm
+++ b/src/plugins/platforms/cocoa/qcocoanativeinterface.mm
@@ -59,7 +59,7 @@
#include "qguiapplication.h"
#include <qdebug.h>
-#ifndef QT_NO_WIDGETS
+#if !defined(QT_NO_WIDGETS) && defined(QT_PRINTSUPPORT_LIB)
#include "qcocoaprintersupport.h"
#include "qprintengine_mac_p.h"
#include <qpa/qplatformprintersupport.h>
@@ -153,24 +153,24 @@ QPlatformNativeInterface::NativeResourceForIntegrationFunction QCocoaNativeInter
QPlatformPrinterSupport *QCocoaNativeInterface::createPlatformPrinterSupport()
{
-#if !defined(QT_NO_WIDGETS) && !defined(QT_NO_PRINTER)
+#if !defined(QT_NO_WIDGETS) && !defined(QT_NO_PRINTER) && defined(QT_PRINTSUPPORT_LIB)
return new QCocoaPrinterSupport();
#else
- qFatal("Printing is not supported when Qt is configured with -no-widgets");
+ qFatal("Printing is not supported when Qt is configured with -no-widgets or -no-feature-printer");
return nullptr;
#endif
}
void *QCocoaNativeInterface::NSPrintInfoForPrintEngine(QPrintEngine *printEngine)
{
-#if !defined(QT_NO_WIDGETS) && !defined(QT_NO_PRINTER)
+#if !defined(QT_NO_WIDGETS) && !defined(QT_NO_PRINTER) && defined(QT_PRINTSUPPORT_LIB)
QMacPrintEnginePrivate *macPrintEnginePriv = static_cast<QMacPrintEngine *>(printEngine)->d_func();
if (macPrintEnginePriv->state == QPrinter::Idle && !macPrintEnginePriv->isPrintSessionInitialized())
macPrintEnginePriv->initialize();
return macPrintEnginePriv->printInfo;
#else
Q_UNUSED(printEngine);
- qFatal("Printing is not supported when Qt is configured with -no-widgets");
+ qFatal("Printing is not supported when Qt is configured with -no-widgets or -no-feature-printer");
return nullptr;
#endif
}
diff --git a/src/plugins/platforms/cocoa/qcocoawindow.h b/src/plugins/platforms/cocoa/qcocoawindow.h
index fef72bc496..c6ce6e6819 100644
--- a/src/plugins/platforms/cocoa/qcocoawindow.h
+++ b/src/plugins/platforms/cocoa/qcocoawindow.h
@@ -161,6 +161,7 @@ public:
Q_NOTIFICATION_HANDLER(NSWindowDidOrderOffScreenNotification) void windowDidOrderOffScreen();
Q_NOTIFICATION_HANDLER(NSWindowDidChangeOcclusionStateNotification) void windowDidChangeOcclusionState();
Q_NOTIFICATION_HANDLER(NSWindowDidChangeScreenNotification) void windowDidChangeScreen();
+ Q_NOTIFICATION_HANDLER(NSWindowDidChangeBackingPropertiesNotification) void windowDidChangeBackingProperties();
Q_NOTIFICATION_HANDLER(NSWindowWillCloseNotification) void windowWillClose();
bool windowShouldClose();
diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm
index 0c7ec7f736..db4bc12210 100644
--- a/src/plugins/platforms/cocoa/qcocoawindow.mm
+++ b/src/plugins/platforms/cocoa/qcocoawindow.mm
@@ -1262,6 +1262,17 @@ void QCocoaWindow::windowDidChangeScreen()
currentScreen->requestUpdate();
}
}
+/*
+ The window's backing scale factor or color space has changed.
+*/
+void QCocoaWindow::windowDidChangeBackingProperties()
+{
+ // Ideally we would plumb this thought QPA in a way that lets clients
+ // invalidate their own caches, and recreate QBackingStore. For now we
+ // trigger an expose, and let QCocoaBackingStore deal with its own
+ // buffer invalidation.
+ [m_view setNeedsDisplay:YES];
+}
void QCocoaWindow::windowWillClose()
{
@@ -1649,21 +1660,6 @@ QCocoaNSWindow *QCocoaWindow::createNSWindow(bool shouldBePanel)
applyContentBorderThickness(nsWindow);
- // Prevent CoreGraphics RGB32 -> RGB64 backing store conversions on deep color
- // displays by forcing 8-bit components, unless a deep color format has been
- // requested. This conversion uses significant CPU time.
- QSurface::SurfaceType surfaceType = QPlatformWindow::window()->surfaceType();
- bool usesCoreGraphics = surfaceType == QSurface::RasterSurface || surfaceType == QSurface::RasterGLSurface;
- QSurfaceFormat surfaceFormat = QPlatformWindow::window()->format();
- bool usesDeepColor = surfaceFormat.redBufferSize() > 8 ||
- surfaceFormat.greenBufferSize() > 8 ||
- surfaceFormat.blueBufferSize() > 8;
- bool usesLayer = view().layer;
- if (usesCoreGraphics && !usesDeepColor && !usesLayer) {
- [nsWindow setDynamicDepthLimit:NO];
- [nsWindow setDepthLimit:NSWindowDepthTwentyfourBitRGB];
- }
-
if (format().colorSpace() == QSurfaceFormat::sRGBColorSpace)
nsWindow.colorSpace = NSColorSpace.sRGBColorSpace;
diff --git a/src/plugins/platforms/cocoa/qnsview_mouse.mm b/src/plugins/platforms/cocoa/qnsview_mouse.mm
index 7c566442f0..30613eca32 100644
--- a/src/plugins/platforms/cocoa/qnsview_mouse.mm
+++ b/src/plugins/platforms/cocoa/qnsview_mouse.mm
@@ -394,14 +394,16 @@
}
// Close the popups if the click was outside.
if (!inside) {
+ bool selfClosed = false;
Qt::WindowType type = QCocoaIntegration::instance()->activePopupWindow()->window()->type();
while (QCocoaWindow *popup = QCocoaIntegration::instance()->popPopupWindow()) {
+ selfClosed = self == popup->view();
QWindowSystemInterface::handleCloseEvent(popup->window());
QWindowSystemInterface::flushWindowSystemEvents();
}
// Consume the mouse event when closing the popup, except for tool tips
// were it's expected that the event is processed normally.
- if (type != Qt::ToolTip)
+ if (type != Qt::ToolTip || selfClosed)
return;
}
}
diff --git a/src/plugins/platforms/cocoa/qnswindow.mm b/src/plugins/platforms/cocoa/qnswindow.mm
index 52f765eb31..68cb270457 100644
--- a/src/plugins/platforms/cocoa/qnswindow.mm
+++ b/src/plugins/platforms/cocoa/qnswindow.mm
@@ -253,20 +253,10 @@ static bool isMouseEvent(NSEvent *ev)
return m_platformWindow ? m_platformWindow->isOpaque() : [super isOpaque];
}
-/*!
- Borderless windows need a transparent background
-
- Technically windows with NSWindowStyleMaskTexturedBackground
- (such as windows with unified toolbars) need to draw the textured
- background of the NSWindow, and can't have a transparent
- background, but as NSWindowStyleMaskBorderless is 0, you can't
- have a window with NSWindowStyleMaskTexturedBackground that is
- also borderless.
-*/
- (NSColor *)backgroundColor
{
- return self.styleMask == NSWindowStyleMaskBorderless
- ? [NSColor clearColor] : [super backgroundColor];
+ return self.styleMask & NSWindowStyleMaskTexturedBackground ?
+ [super backgroundColor] : [NSColor clearColor];
}
- (void)sendEvent:(NSEvent*)theEvent
diff --git a/src/plugins/platforms/cocoa/qpaintengine_mac.mm b/src/plugins/platforms/cocoa/qpaintengine_mac.mm
index 3677877538..00b2267f0d 100644
--- a/src/plugins/platforms/cocoa/qpaintengine_mac.mm
+++ b/src/plugins/platforms/cocoa/qpaintengine_mac.mm
@@ -38,14 +38,18 @@
****************************************************************************/
#include "qpaintengine_mac_p.h"
+#if defined(QT_PRINTSUPPORT_LIB)
#include "qprintengine_mac_p.h"
+#endif
#include <qbitmap.h>
#include <qpaintdevice.h>
#include <qpainterpath.h>
#include <qpixmapcache.h>
#include <private/qpaintengine_raster_p.h>
+#if defined(QT_PRINTSUPPORT_LIB)
#include <qprinter.h>
+#endif
#include <qstack.h>
#include <qwidget.h>
#include <qvarlengtharray.h>