From a8ec52d5e76bc769ed63be1ad543be8f687e5dac Mon Sep 17 00:00:00 2001 From: Andre de la Rocha Date: Fri, 20 Sep 2019 18:12:42 +0200 Subject: Windows QPA: Fix close button not working on Windows 7 A previous change modified hit testing in the non-client area of fixed-size windows, in order to prevent showing a resize cursor when the windows are not resizable (QTBUG-77220). The change assigned HTCAPTION for any point over the entire title bar, including the top bar buttons, which on Windows 7 classic or basic desktop caused these buttons to become unresponsive. The present fix changes this behavior to redefine only the outer sizing frame, while letting the rest of the title bar be handled by DefWindowProc(). Fixes: QTBUG-78262 Change-Id: Id6e821a805c8333a67988f87c3727bed0c93290e Reviewed-by: Volker Hilsheimer Reviewed-by: Friedemann Kleint --- src/plugins/platforms/windows/qwindowswindow.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp index 519a2daae9..1d8b252029 100644 --- a/src/plugins/platforms/windows/qwindowswindow.cpp +++ b/src/plugins/platforms/windows/qwindowswindow.cpp @@ -2645,10 +2645,16 @@ bool QWindowsWindow::handleNonClientHitTest(const QPoint &globalPos, LRESULT *re return true; } if (localPos.y() < 0) { - const int topResizeBarPos = -frameMargins().top(); - if (localPos.y() >= topResizeBarPos) + // We want to return HTCAPTION/true only over the outer sizing frame, not the entire title bar, + // otherwise the title bar buttons (close, etc.) become unresponsive on Windows 7 (QTBUG-78262). + // However, neither frameMargins() nor GetSystemMetrics(SM_CYSIZEFRAME), etc., give the correct + // sizing frame height in all Windows versions/scales. This empirical constant seems to work, though. + const int sizingHeight = 9; + const int topResizeBarPos = sizingHeight - frameMargins().top(); + if (localPos.y() < topResizeBarPos) { *result = HTCAPTION; // Extend caption over top resize bar, let's user move the window. - return true; + return true; + } } } if (fixedWidth && (localPos.x() < 0 || localPos.x() >= size.width())) { -- cgit v1.2.3 From 54d3059ccfe6df0a375d2addac4ad41333122b8d Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Wed, 28 Aug 2019 08:16:12 +0200 Subject: Move DialogButtonBoxLayout case to be before MouseDoubleClickDistance This amends 9be66cb282dee1ce4380602a2f3caf5abfd144cf so that the DialogButtonBoxLayout case is moved to be before the MouseDoubleClickDistance one in case the fallthrough is triggered. Change-Id: I843dad6b55ccffe6b6c275cd75587f04659e512f Reviewed-by: BogDan Vatra --- src/plugins/platforms/android/qandroidplatformtheme.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/android/qandroidplatformtheme.cpp b/src/plugins/platforms/android/qandroidplatformtheme.cpp index 7fc68c3d7c..d3a8a53241 100644 --- a/src/plugins/platforms/android/qandroidplatformtheme.cpp +++ b/src/plugins/platforms/android/qandroidplatformtheme.cpp @@ -465,7 +465,8 @@ QVariant QAndroidPlatformTheme::themeHint(ThemeHint hint) const return QStringList(QLatin1String("android")); } return QStringList(QLatin1String("fusion")); - + case DialogButtonBoxLayout: + return QVariant(QPlatformDialogHelper::AndroidLayout); case MouseDoubleClickDistance: { int minimumDistance = qEnvironmentVariableIntValue("QT_ANDROID_MINIMUM_MOUSE_DOUBLE_CLICK_DISTANCE"); @@ -489,8 +490,6 @@ QVariant QAndroidPlatformTheme::themeHint(ThemeHint hint) const Q_FALLTHROUGH(); } - case DialogButtonBoxLayout: - return QVariant(QPlatformDialogHelper::AndroidLayout); default: return QPlatformTheme::themeHint(hint); } -- cgit v1.2.3 From 0a8be8127b1ea52f604055421332b0dce273b899 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Thu, 26 Sep 2019 12:57:53 +0200 Subject: Fix robustness detection for windows Fixes detecting requested robustness for OpenGL < 4.0. Fixes: QTBUG-78781 Change-Id: I6a10f3ed925dd05d5caa7d6b6e12935e27eed3e9 Reviewed-by: Friedemann Kleint Reviewed-by: Laszlo Agocs --- .../platforms/windows/qwindowsglcontext.cpp | 62 +++++++++++----------- src/plugins/platforms/windows/qwindowsglcontext.h | 3 +- 2 files changed, 33 insertions(+), 32 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/windows/qwindowsglcontext.cpp b/src/plugins/platforms/windows/qwindowsglcontext.cpp index 1063432dcc..50f528e7fc 100644 --- a/src/plugins/platforms/windows/qwindowsglcontext.cpp +++ b/src/plugins/platforms/windows/qwindowsglcontext.cpp @@ -885,13 +885,6 @@ QWindowsOpenGLContextFormat QWindowsOpenGLContextFormat::current() result.profile = QSurfaceFormat::CoreProfile; else if (value & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT) result.profile = QSurfaceFormat::CompatibilityProfile; - if (result.version < 0x0400) - return result; - // v4.0 onwards - value = 0; - QOpenGLStaticContext::opengl32.glGetIntegerv(RESET_NOTIFICATION_STRATEGY_ARB, &value); - if (value == LOSE_CONTEXT_ON_RESET_ARB) - result.options |= QSurfaceFormat::ResetNotification; return result; } @@ -969,6 +962,7 @@ QOpenGLTemporaryContext::~QOpenGLTemporaryContext() */ #define SAMPLE_BUFFER_EXTENSION "GL_ARB_multisample" +#define ROBUSTNESS_EXTENSION "GL_ARB_robustness" QOpenGLStaticContext::QOpenGLStaticContext() : vendor(QOpenGLStaticContext::getGlString(GL_VENDOR)), @@ -989,9 +983,31 @@ QOpenGLStaticContext::QOpenGLStaticContext() : wglGetExtensionsStringARB(reinterpret_cast( reinterpret_cast(QOpenGLStaticContext::opengl32.wglGetProcAddress("wglGetExtensionsStringARB")))) { - if (extensionNames.startsWith(SAMPLE_BUFFER_EXTENSION " ") - || extensionNames.indexOf(" " SAMPLE_BUFFER_EXTENSION " ") != -1) - extensions |= SampleBuffers; + if (defaultFormat.version < 0x0300) { + if (extensionNames.startsWith(SAMPLE_BUFFER_EXTENSION " ") + || extensionNames.indexOf(" " SAMPLE_BUFFER_EXTENSION " ") != -1) + extensions |= SampleBuffers; + if (extensionNames.startsWith(ROBUSTNESS_EXTENSION " ") + || extensionNames.indexOf(" " ROBUSTNESS_EXTENSION " ") != -1) + extensions |= Robustness; + } else { + typedef const GLubyte * (APIENTRY *glGetStringi_t)(GLenum, GLuint); + auto glGetStringi = reinterpret_cast( + reinterpret_cast(QOpenGLStaticContext::opengl32.wglGetProcAddress("glGetStringi"))); + if (glGetStringi) { + GLint n = 0; + QOpenGLStaticContext::opengl32.glGetIntegerv(GL_NUM_EXTENSIONS, &n); + for (GLint i = 0; i < n; ++i) { + const char *p = reinterpret_cast(glGetStringi(GL_EXTENSIONS, i)); + if (p) { + if (!strcmp(p, SAMPLE_BUFFER_EXTENSION)) + extensions |= SampleBuffers; + else if (!strcmp(p, ROBUSTNESS_EXTENSION)) + extensions |= Robustness; + } + } + } + } } QByteArray QOpenGLStaticContext::getGlString(unsigned int which) @@ -1230,27 +1246,11 @@ bool QWindowsGLContext::updateObtainedParams(HDC hdc, int *obtainedSwapInterval) if (m_staticContext->wglGetSwapInternalExt && obtainedSwapInterval) *obtainedSwapInterval = m_staticContext->wglGetSwapInternalExt(); - bool hasRobustness = false; - if (m_obtainedFormat.majorVersion() < 3) { - const char *exts = reinterpret_cast(QOpenGLStaticContext::opengl32.glGetString(GL_EXTENSIONS)); - hasRobustness = exts && strstr(exts, "GL_ARB_robustness"); - } else { - typedef const GLubyte * (APIENTRY *glGetStringi_t)(GLenum, GLuint); - glGetStringi_t glGetStringi = reinterpret_cast( - reinterpret_cast(QOpenGLStaticContext::opengl32.wglGetProcAddress("glGetStringi"))); - if (glGetStringi) { - GLint n = 0; - QOpenGLStaticContext::opengl32.glGetIntegerv(GL_NUM_EXTENSIONS, &n); - for (GLint i = 0; i < n; ++i) { - const char *p = reinterpret_cast(glGetStringi(GL_EXTENSIONS, i)); - if (p && !strcmp(p, "GL_ARB_robustness")) { - hasRobustness = true; - break; - } - } - } - } - if (hasRobustness) { + if (testFlag(m_staticContext->extensions, QOpenGLStaticContext::Robustness)) { + GLint value = 0; + QOpenGLStaticContext::opengl32.glGetIntegerv(RESET_NOTIFICATION_STRATEGY_ARB, &value); + if (value == LOSE_CONTEXT_ON_RESET_ARB) + m_obtainedFormat.setOption(QSurfaceFormat::ResetNotification); m_getGraphicsResetStatus = reinterpret_cast( reinterpret_cast(QOpenGLStaticContext::opengl32.wglGetProcAddress("glGetGraphicsResetStatusARB"))); } diff --git a/src/plugins/platforms/windows/qwindowsglcontext.h b/src/plugins/platforms/windows/qwindowsglcontext.h index 199f8112e3..00e4d323a6 100644 --- a/src/plugins/platforms/windows/qwindowsglcontext.h +++ b/src/plugins/platforms/windows/qwindowsglcontext.h @@ -140,7 +140,8 @@ public: enum Extensions { SampleBuffers = 0x1, - sRGBCapableFramebuffer = 0x2 + sRGBCapableFramebuffer = 0x2, + Robustness = 0x4, }; typedef bool -- cgit v1.2.3 From 401e81063fd27639e0b3eaf4b4745faa186ceeb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 27 Sep 2019 12:29:59 +0200 Subject: Replace use of deprecated API in macOS event dispatchers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I077ba12b406f662ba22b2f2cddf0171963335739 Reviewed-by: Tor Arne Vestbø Reviewed-by: Timur Pocheptsov --- src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm index d3bb0711f0..e87fc39c42 100644 --- a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm +++ b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm @@ -881,7 +881,7 @@ void QCocoaEventDispatcherPrivate::processPostedEvents() return; } - int serial = serialNumber.load(); + int serial = serialNumber.loadRelaxed(); if (!threadData->canWait || (serial != lastSerial)) { lastSerial = serial; QCoreApplication::sendPostedEvents(); -- cgit v1.2.3 From 10780c7b8cd632087fb93005eaf03b6adf94a2b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 25 Sep 2019 17:29:40 +0200 Subject: macOS: Gather QNSView draw callbacks together MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I29881b379481287b4938e47fc06405c918aa39a3 Reviewed-by: Morten Johan Sørvig Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/cocoa/qnsview_drawing.mm | 90 +++++++++++++++----------- 1 file changed, 51 insertions(+), 39 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/cocoa/qnsview_drawing.mm b/src/plugins/platforms/cocoa/qnsview_drawing.mm index e72142466b..6f9c72513d 100644 --- a/src/plugins/platforms/cocoa/qnsview_drawing.mm +++ b/src/plugins/platforms/cocoa/qnsview_drawing.mm @@ -71,24 +71,6 @@ return YES; } -- (void)drawRect:(NSRect)dirtyRect -{ - Q_UNUSED(dirtyRect); - - if (!m_platformWindow) - return; - - QRegion exposedRegion; - const NSRect *dirtyRects; - NSInteger numDirtyRects; - [self getRectsBeingDrawn:&dirtyRects count:&numDirtyRects]; - for (int i = 0; i < numDirtyRects; ++i) - exposedRegion += QRectF::fromCGRect(dirtyRects[i]).toRect(); - - qCDebug(lcQpaDrawing) << "[QNSView drawRect:]" << m_platformWindow->window() << exposedRegion; - m_platformWindow->handleExposeEvent(exposedRegion); -} - - (BOOL)layerEnabledByMacOS { // AppKit has its own logic for this, but if we rely on that, our layers are created @@ -173,8 +155,59 @@ } #endif +- (void)viewDidChangeBackingProperties +{ + qCDebug(lcQpaDrawing) << "Backing properties changed for" << self; + + if (self.layer) + self.layer.contentsScale = self.window.backingScaleFactor; + + // Ideally we would plumb this situation through QPA in a way that lets + // clients invalidate their own caches, recreate QBackingStore, etc. + // For now we trigger an expose, and let QCocoaBackingStore deal with + // buffer invalidation internally. + [self setNeedsDisplay:YES]; +} + +// ----------------------- Draw callbacks ----------------------- + +/* + This method is called by AppKit for the non-layer case, where we are + drawing into the NSWindow's surface. +*/ +- (void)drawRect:(NSRect)dirtyRect +{ + Q_UNUSED(dirtyRect); + + Q_ASSERT_X(!self.layer, "QNSView", + "The drawRect code path should not be hit when we are layer backed"); + + if (!m_platformWindow) + return; + + QRegion exposedRegion; + const NSRect *dirtyRects; + NSInteger numDirtyRects; + [self getRectsBeingDrawn:&dirtyRects count:&numDirtyRects]; + for (int i = 0; i < numDirtyRects; ++i) + exposedRegion += QRectF::fromCGRect(dirtyRects[i]).toRect(); + + qCDebug(lcQpaDrawing) << "[QNSView drawRect:]" << m_platformWindow->window() << exposedRegion; + m_platformWindow->handleExposeEvent(exposedRegion); +} + +/* + This method is called by AppKit when we are layer-backed, where + we are drawing into the layer. +*/ - (void)displayLayer:(CALayer *)layer { + Q_ASSERT_X(self.layer && layer == self.layer, "QNSView", + "The displayLayer code path should only be hit for our own layer"); + + if (!m_platformWindow) + return; + if (!NSThread.isMainThread) { // Qt is calling AppKit APIs such as -[NSOpenGLContext setView:] on secondary threads, // which we shouldn't do. This may result in AppKit (wrongly) triggering a display on @@ -184,29 +217,8 @@ return; } - Q_ASSERT(layer == self.layer); - - if (!m_platformWindow) - return; - qCDebug(lcQpaDrawing) << "[QNSView displayLayer]" << m_platformWindow->window(); - - // FIXME: Find out if there's a way to resolve the dirty rect like in drawRect: m_platformWindow->handleExposeEvent(QRectF::fromCGRect(self.bounds).toRect()); } -- (void)viewDidChangeBackingProperties -{ - qCDebug(lcQpaDrawing) << "Backing properties changed for" << self; - - if (self.layer) - self.layer.contentsScale = self.window.backingScaleFactor; - - // Ideally we would plumb this situation through QPA in a way that lets - // clients invalidate their own caches, recreate QBackingStore, etc. - // For now we trigger an expose, and let QCocoaBackingStore deal with - // buffer invalidation internally. - [self setNeedsDisplay:YES]; -} - @end -- cgit v1.2.3 From ce8a9c1b0156f1562ece70cb5d78d446fde02378 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 25 Sep 2019 17:31:45 +0200 Subject: macOS: Propagate drawRect: dirty bounding rect as fallback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I333e2bfe4a25bfbfebef7b2ec30a600fd441c9a9 Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/cocoa/qnsview_drawing.mm | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/cocoa/qnsview_drawing.mm b/src/plugins/platforms/cocoa/qnsview_drawing.mm index 6f9c72513d..91c0a4dc07 100644 --- a/src/plugins/platforms/cocoa/qnsview_drawing.mm +++ b/src/plugins/platforms/cocoa/qnsview_drawing.mm @@ -175,10 +175,8 @@ This method is called by AppKit for the non-layer case, where we are drawing into the NSWindow's surface. */ -- (void)drawRect:(NSRect)dirtyRect +- (void)drawRect:(NSRect)dirtyBoundingRect { - Q_UNUSED(dirtyRect); - Q_ASSERT_X(!self.layer, "QNSView", "The drawRect code path should not be hit when we are layer backed"); @@ -192,6 +190,9 @@ for (int i = 0; i < numDirtyRects; ++i) exposedRegion += QRectF::fromCGRect(dirtyRects[i]).toRect(); + if (exposedRegion.isEmpty()) + exposedRegion = QRectF::fromCGRect(dirtyBoundingRect).toRect(); + qCDebug(lcQpaDrawing) << "[QNSView drawRect:]" << m_platformWindow->window() << exposedRegion; m_platformWindow->handleExposeEvent(exposedRegion); } -- cgit v1.2.3 From fd49d5e31596525595885393d24893c2173a8b2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 25 Sep 2019 17:37:17 +0200 Subject: macOS: Flesh out and clarify layer setup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I10d972254c02de8789e64c8503861d51764a1633 Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/cocoa/qnsview_drawing.mm | 68 +++++++++++++++++++------- 1 file changed, 50 insertions(+), 18 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/cocoa/qnsview_drawing.mm b/src/plugins/platforms/cocoa/qnsview_drawing.mm index 91c0a4dc07..17746e9e94 100644 --- a/src/plugins/platforms/cocoa/qnsview_drawing.mm +++ b/src/plugins/platforms/cocoa/qnsview_drawing.mm @@ -43,9 +43,7 @@ - (void)initDrawing { - self.wantsLayer = [self layerExplicitlyRequested] - || [self shouldUseMetalLayer] - || [self layerEnabledByMacOS]; + [self updateLayerBacking]; // Enable high-DPI OpenGL for retina displays. Enabling has the side // effect that Cocoa will start calling glViewport(0, 0, width, height), @@ -71,6 +69,15 @@ return YES; } +// ----------------------- Layer setup ----------------------- + +- (void)updateLayerBacking +{ + self.wantsLayer = [self layerEnabledByMacOS] + || [self layerExplicitlyRequested] + || [self shouldUseMetalLayer]; +} + - (BOOL)layerEnabledByMacOS { // AppKit has its own logic for this, but if we rely on that, our layers are created @@ -105,38 +112,63 @@ return surfaceType == QWindow::MetalSurface || surfaceType == QWindow::VulkanSurface; } +/* + This method is called by AppKit when layer-backing is requested by + setting wantsLayer too YES (via -[NSView _updateLayerBackedness]), + or in cases where AppKit itself decides that a view should be + layer-backed. + + Note however that some code paths in AppKit will not go via this + method for creating the backing layer, and will instead create the + layer manually, and just call setLayer. An example of this is when + an NSOpenGLContext is attached to a view, in which case AppKit will + create a new layer in NSOpenGLContextSetLayerOnViewIfNecessary. + + For this reason we leave the implementation of this override as + minimal as possible, only focusing on creating the appropriate + layer type, and then leave it up to setLayer to do the work of + making sure the layer is set up correctly. +*/ - (CALayer *)makeBackingLayer { if ([self shouldUseMetalLayer]) { // Check if Metal is supported. If it isn't then it's most likely // too late at this point and the QWindow will be non-functional, // but we can at least print a warning. - if (![MTLCreateSystemDefaultDevice() autorelease]) { - qWarning() << "QWindow initialization error: Metal is not supported"; - return [super makeBackingLayer]; + if ([MTLCreateSystemDefaultDevice() autorelease]) { + return [CAMetalLayer layer]; + } else { + qCWarning(lcQpaDrawing) << "Failed to create QWindow::MetalSurface." + << "Metal is not supported by any of the GPUs in this system."; } - - CAMetalLayer *layer = [CAMetalLayer layer]; - - // Set the contentsScale for the layer. This is normally done in - // viewDidChangeBackingProperties, however on startup that function - // is called before the layer is created here. The layer's drawableSize - // is updated from layoutSublayersOfLayer as usual. - layer.contentsScale = self.window.backingScaleFactor; - - return layer; } return [super makeBackingLayer]; } +/* + This method is called by AppKit whenever the view is asked to change + its layer, which can happen both as a result of enabling layer-backing, + or when a layer is set explicitly. The latter can happen both when a + view is layer-hosting, or when AppKit internals are switching out the + layer-backed view, as described above for makeBackingLayer. +*/ - (void)setLayer:(CALayer *)layer { - qCDebug(lcQpaDrawing) << "Making" << self << "layer-backed with" << layer - << "due to being" << ([self layerExplicitlyRequested] ? "explicitly requested" + qCDebug(lcQpaDrawing) << "Making" << self + << (self.wantsLayer ? "layer-backed" : "layer-hosted") + << "with" << layer << "due to being" << ([self layerExplicitlyRequested] ? "explicitly requested" : [self shouldUseMetalLayer] ? "needed by surface type" : "enabled by macOS"); + [super setLayer:layer]; layer.delegate = self; + + // When adding a view to a view hierarchy the backing properties will change + // which results in updating the contents scale, but in case of switching the + // layer on a view that's already in a view hierarchy we need to manually ensure + // the scale is up to date. + if (self.superview) + layer.contentsScale = self.window.backingScaleFactor; } - (NSViewLayerContentsRedrawPolicy)layerContentsRedrawPolicy -- cgit v1.2.3 From cefd214b1bf6bd87ba3780d42b4a86452dc9eb55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 25 Sep 2019 17:38:06 +0200 Subject: macOS: Improve layer delegate setup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We should detect the cases where there's already a delegate, and setting up the delegate before the layer is added makes sense. Change-Id: I67896cbc96d11ce9a3826fd8aa0e5e104a83a21c Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/cocoa/qnsview_drawing.mm | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/cocoa/qnsview_drawing.mm b/src/plugins/platforms/cocoa/qnsview_drawing.mm index 17746e9e94..7739be8319 100644 --- a/src/plugins/platforms/cocoa/qnsview_drawing.mm +++ b/src/plugins/platforms/cocoa/qnsview_drawing.mm @@ -160,8 +160,14 @@ << "with" << layer << "due to being" << ([self layerExplicitlyRequested] ? "explicitly requested" : [self shouldUseMetalLayer] ? "needed by surface type" : "enabled by macOS"); + if (layer.delegate && layer.delegate != self) { + qCWarning(lcQpaDrawing) << "Layer already has delegate" << layer.delegate + << "This delegate is responsible for all view updates for" << self; + } else { + layer.delegate = self; + } + [super setLayer:layer]; - layer.delegate = self; // When adding a view to a view hierarchy the backing properties will change // which results in updating the contents scale, but in case of switching the -- cgit v1.2.3 From 4fade3c3b8e68bf2c51771fc2895a32bf76365bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 26 Sep 2019 12:05:16 +0200 Subject: macOS: Resolve layer contents scale based on DPR MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I32de4610a2aebbc7e0adcad9bb3440683cae5906 Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/cocoa/qnsview_drawing.mm | 32 ++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/cocoa/qnsview_drawing.mm b/src/plugins/platforms/cocoa/qnsview_drawing.mm index 7739be8319..bbf7d30157 100644 --- a/src/plugins/platforms/cocoa/qnsview_drawing.mm +++ b/src/plugins/platforms/cocoa/qnsview_drawing.mm @@ -174,9 +174,11 @@ // layer on a view that's already in a view hierarchy we need to manually ensure // the scale is up to date. if (self.superview) - layer.contentsScale = self.window.backingScaleFactor; + [self updateLayerContentsScale]; } +// ----------------------- Layer updates ----------------------- + - (NSViewLayerContentsRedrawPolicy)layerContentsRedrawPolicy { // We need to set this explicitly since the super implementation @@ -198,7 +200,7 @@ qCDebug(lcQpaDrawing) << "Backing properties changed for" << self; if (self.layer) - self.layer.contentsScale = self.window.backingScaleFactor; + [self updateLayerContentsScale]; // Ideally we would plumb this situation through QPA in a way that lets // clients invalidate their own caches, recreate QBackingStore, etc. @@ -207,6 +209,32 @@ [self setNeedsDisplay:YES]; } +- (void)updateLayerContentsScale +{ + // We expect clients to fill the layer with retina aware content, + // based on the devicePixelRatio of the QWindow, so we set the + // layer's content scale to match that. By going via devicePixelRatio + // instead of applying the NSWindow's backingScaleFactor, we also take + // into account OpenGL views with wantsBestResolutionOpenGLSurface set + // to NO. In this case the window will have a backingScaleFactor of 2, + // but the QWindow will have a devicePixelRatio of 1. + auto devicePixelRatio = m_platformWindow->devicePixelRatio(); + qCDebug(lcQpaDrawing) << "Updating" << self.layer << "content scale to" << devicePixelRatio; + self.layer.contentsScale = devicePixelRatio; +} + +/* + This method is called by AppKit to determine whether it should update + the contentScale of the layer to match the window backing scale. + + We always return NO since we're updating the contents scale manually. +*/ +- (BOOL)layer:(CALayer *)layer shouldInheritContentsScale:(CGFloat)scale fromWindow:(NSWindow *)window +{ + Q_UNUSED(layer); Q_UNUSED(scale); Q_UNUSED(window); + return NO; +} + // ----------------------- Draw callbacks ----------------------- /* -- cgit v1.2.3 From 72dd9de283aded3097f5e97fa56dfc048a999c5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 26 Sep 2019 12:05:57 +0200 Subject: macOS: Avoid automatic resizing of layers by fixing them to top-left MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a layer is resized, e.g. during a window resize, the contents of the layer may lag behind if the client doesn't fill the layer in response to the window resize and corresponding expose event. The default behavior is for Core Animation to stretch the content to fill the layer, but this results in the content "jumping" back and forth when the content then picks up the new size and fills the layer. Instead we tell Core Animation to fix the content to the top left corner. If a layer is sized up without a corresponding layer contents update this will result in missing/transparent pixels in the bottom or right part of the layer, explicitly showing what the result of the missing paint is. During debugging we also highlight this area by adding a magenta background color to the layer. Conversely, if the layer is sized down we don't need to resize it, we can just keep the fixed top left position, and the content will stay in place during the resize. This allows for optimizations during window resizing, where we don't need to allocate new buffers if the old buffer is larger than the new one. Change-Id: I265b57e3a0ddff8bbcda3af5d670cd8c3b00b181 Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/cocoa/qnsview_drawing.mm | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/cocoa/qnsview_drawing.mm b/src/plugins/platforms/cocoa/qnsview_drawing.mm index bbf7d30157..ce5488ead0 100644 --- a/src/plugins/platforms/cocoa/qnsview_drawing.mm +++ b/src/plugins/platforms/cocoa/qnsview_drawing.mm @@ -175,6 +175,14 @@ // the scale is up to date. if (self.superview) [self updateLayerContentsScale]; + + if (self.opaque && lcQpaDrawing().isDebugEnabled()) { + // If the view claims to be opaque we expect it to fill the entire + // layer with content, in which case we want to detect any areas + // where it doesn't. + layer.backgroundColor = NSColor.magentaColor.CGColor; + } + } // ----------------------- Layer updates ----------------------- @@ -186,14 +194,14 @@ return NSViewLayerContentsRedrawDuringViewResize; } -#if 0 // Disabled until we enable lazy backingstore resizing - (NSViewLayerContentsPlacement)layerContentsPlacement { - // Always place the layer at top left without any automatic scaling, - // so that we can re-use larger layers when resizing a window down. + // Always place the layer at top left without any automatic scaling. + // This will highlight situations where we're missing content for the + // layer by not responding to the displayLayer: request synchronously. + // It also allows us to re-use larger layers when resizing a window down. return NSViewLayerContentsPlacementTopLeft; } -#endif - (void)viewDidChangeBackingProperties { -- cgit v1.2.3