From 80e7120feb5ddf9d5f0c9ed12bb8580898b18db8 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Thu, 1 Aug 2019 15:29:01 +0200 Subject: eglfs/kms: Re-enable drm/gbm format overrides in the config file Follow up to 091a386eaf91ad8932332a8aefc2df793de59f6c Defaulting to querying from the egl config is fine, but dropping support for the "format" key in the output list in the json config file is not ideal. Task-number: QTBUG-76748 Change-Id: I25dc99369d118c300cdef25b464426f6be85453b Reviewed-by: Johan Helsing --- .../eglfs_kms/qeglfskmsgbmscreen.cpp | 37 +++++++++++++++------- 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmscreen.cpp b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmscreen.cpp index 24f82e7843..3a2951efbd 100644 --- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmscreen.cpp +++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmscreen.cpp @@ -155,20 +155,33 @@ gbm_surface *QEglFSKmsGbmScreen::createSurface(EGLConfig eglConfig) qCDebug(qLcEglfsKmsDebug, "Creating gbm_surface for screen %s", qPrintable(name())); const auto gbmDevice = static_cast(device())->gbmDevice(); - EGLint native_format = -1; - EGLBoolean success = eglGetConfigAttrib(display(), eglConfig, EGL_NATIVE_VISUAL_ID, &native_format); - qCDebug(qLcEglfsKmsDebug) << "Got native format" << hex << native_format << dec << "from eglGetConfigAttrib() with return code" << bool(success); - - if (success) - m_gbm_surface = gbm_surface_create(gbmDevice, - rawGeometry().width(), - rawGeometry().height(), - native_format, - GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING); + // If there was no format override given in the config file, + // query the native (here, gbm) format from the EGL config. + const bool queryFromEgl = !m_output.drm_format_requested_by_user; + if (queryFromEgl) { + EGLint native_format = -1; + EGLBoolean success = eglGetConfigAttrib(display(), eglConfig, EGL_NATIVE_VISUAL_ID, &native_format); + qCDebug(qLcEglfsKmsDebug) << "Got native format" << hex << native_format << dec + << "from eglGetConfigAttrib() with return code" << bool(success); + + if (success) { + m_gbm_surface = gbm_surface_create(gbmDevice, + rawGeometry().width(), + rawGeometry().height(), + native_format, + GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING); + if (m_gbm_surface) + m_output.drm_format = gbmFormatToDrmFormat(native_format); + } + } - if (!m_gbm_surface) { // fallback for older drivers + // Fallback for older drivers, and when "format" is explicitly specified + // in the output config. (not guaranteed that the requested format works + // of course, but do what we are told to) + if (!m_gbm_surface) { uint32_t gbmFormat = drmFormatToGbmFormat(m_output.drm_format); - qCDebug(qLcEglfsKmsDebug, "Could not create surface with EGL_NATIVE_VISUAL_ID, falling back to format %x", gbmFormat); + if (queryFromEgl) + qCDebug(qLcEglfsKmsDebug, "Could not create surface with EGL_NATIVE_VISUAL_ID, falling back to format %x", gbmFormat); m_gbm_surface = gbm_surface_create(gbmDevice, rawGeometry().width(), rawGeometry().height(), -- cgit v1.2.3 From 88d1909871ce1a3016ff61edd8bc2062a79f35fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Klitzing?= Date: Wed, 14 Aug 2019 15:40:26 +0200 Subject: Fix macOS build with -no-feature-accessibility MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Id16b102feb7b57efcf1a36385a009774cb023f41 Reviewed-by: Jörg Bornemann --- src/plugins/platforms/cocoa/cocoa.pro | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/cocoa/cocoa.pro b/src/plugins/platforms/cocoa/cocoa.pro index 02e00039ae..f0dd013922 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 -- cgit v1.2.3 From fa7d7ae658e60a84a711401430cefbff4b6b0693 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Mon, 19 Aug 2019 15:13:13 +0200 Subject: Fix -no-feature-mimetype build Change-Id: I282f630d6e8a0b2b10fd1286d7a185a068abc9f1 Reviewed-by: Alexandru Croitor --- src/plugins/printsupport/cups/qppdprintdevice.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/printsupport/cups/qppdprintdevice.cpp b/src/plugins/printsupport/cups/qppdprintdevice.cpp index ea6336c4d1..8bfa239dbe 100644 --- a/src/plugins/printsupport/cups/qppdprintdevice.cpp +++ b/src/plugins/printsupport/cups/qppdprintdevice.cpp @@ -40,11 +40,11 @@ #include "qppdprintdevice.h" #include "qcupsprintersupport_p.h" +#include "private/qcups_p.h" // Only needed for PDPK_* +#if QT_CONFIG(mimetype) #include -#include - -#include "private/qcups_p.h" // Only needed for PDPK_* +#endif #ifndef QT_LINUXBASE // LSB merges everything into cups.h #include -- cgit v1.2.3 From fc049052812bfa0b63af1f3c5fcadf1eb582e775 Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Mon, 19 Aug 2019 15:04:42 +0200 Subject: macOS: Bail out early in case a popup is closed by a mouseDown MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It can happen that AppKit calls -mouseDown: on a popup's view, but we consider the click to be outside of popup's area (happens on the 1-pixel edge of a 'geometry', QRect::contains() returns false). If we send close event to essentially 'self', m_platformWindow is becoming nullptr. So we bail out early, no further processing is needed. Fixes: QTBUG-77348 Change-Id: I224943e6bcf4ae052412ef7dc7b23a94f999aa19 Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/cocoa/qnsview_mouse.mm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/cocoa/qnsview_mouse.mm b/src/plugins/platforms/cocoa/qnsview_mouse.mm index a887cb841d..3a5a074264 100644 --- a/src/plugins/platforms/cocoa/qnsview_mouse.mm +++ b/src/plugins/platforms/cocoa/qnsview_mouse.mm @@ -389,14 +389,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; } } -- cgit v1.2.3 From 626340d45882c7dcb9e56e7bdbae38f04a5b1cd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Tue, 20 Aug 2019 15:05:19 +0200 Subject: iOS: Fix NSUInteger vs NSInteger comparison warning Change-Id: I700132084c208f4ce63e0fc0516ebc3df7881ab0 Reviewed-by: Timur Pocheptsov --- src/plugins/platforms/ios/quiview_accessibility.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/ios/quiview_accessibility.mm b/src/plugins/platforms/ios/quiview_accessibility.mm index 458ddcc9b8..6612dc131e 100644 --- a/src/plugins/platforms/ios/quiview_accessibility.mm +++ b/src/plugins/platforms/ios/quiview_accessibility.mm @@ -101,7 +101,7 @@ - (id)accessibilityElementAtIndex:(NSInteger)index { [self initAccessibility]; - if (index >= [m_accessibleElements count]) + if (NSUInteger(index) >= [m_accessibleElements count]) return nil; return m_accessibleElements[index]; } -- cgit v1.2.3 From ee82f866152a27ef7a0d69f3aa41608d4a058610 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 21 Aug 2019 16:37:16 +0200 Subject: macOS: Don't ask for a NSWindow background unless we need one This allow halfway transparent windows, even with a border, which is a bit of a weird use-case, but matches what we do on other platforms. We don't need the explicit call to NSDrawWindowBackground in the QNSWindowBackingStore implementation, as the NSThemeFrame will draw this background on our behalf. Fixes: QTBUG-77637 Change-Id: I012d845fa957c40aa713adaecbb1601a848e3534 Reviewed-by: Timur Pocheptsov --- src/plugins/platforms/cocoa/qcocoabackingstore.mm | 3 --- src/plugins/platforms/cocoa/qnswindow.mm | 14 ++------------ 2 files changed, 2 insertions(+), 15 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/cocoa/qcocoabackingstore.mm b/src/plugins/platforms/cocoa/qcocoabackingstore.mm index af50aabe15..02f56b4516 100644 --- a/src/plugins/platforms/cocoa/qcocoabackingstore.mm +++ b/src/plugins/platforms/cocoa/qcocoabackingstore.mm @@ -212,9 +212,6 @@ void QNSWindowBackingStore::flush(QWindow *window, const QRegion ®ion, const CGRect viewRect = viewLocalRect.toCGRect(); - if (windowHasUnifiedToolbar()) - NSDrawWindowBackground(viewRect); - [backingStoreImage drawInRect:viewRect fromRect:backingStoreRect.toCGRect() operation:compositingOperation fraction:1.0 respectFlipped:YES hints:nil]; 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 -- cgit v1.2.3 From e688e28ee5e154baa03dbafdad06f8db69ef880c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 21 Aug 2019 12:36:21 +0200 Subject: macOS: Invalidate backingstore and trigger expose on color space changes Fixes: QTBUG-77749 Change-Id: I677a71152e4a218c08d8863d4f886d158a79e809 Reviewed-by: Volker Hilsheimer Reviewed-by: Timur Pocheptsov --- src/plugins/platforms/cocoa/qcocoabackingstore.h | 5 +++++ src/plugins/platforms/cocoa/qcocoabackingstore.mm | 22 ++++++++++++++++++++++ src/plugins/platforms/cocoa/qcocoawindow.h | 1 + src/plugins/platforms/cocoa/qcocoawindow.mm | 11 +++++++++++ 4 files changed, 39 insertions(+) (limited to 'src/plugins') 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 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> m_buffers; }; diff --git a/src/plugins/platforms/cocoa/qcocoabackingstore.mm b/src/plugins/platforms/cocoa/qcocoabackingstore.mm index 02f56b4516..5d5e406d8a 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(window->handle())->view(); + m_backingPropertiesObserver = QMacNotificationObserver(view.window, + NSWindowDidChangeBackingPropertiesNotification, [this]() { + qCDebug(lcQpaBackingStore) << "Backing properties for" + << this->window() << "did change"; + backingPropertiesChanged(); + }); } QCFType QCocoaBackingStore::colorSpace() const @@ -299,6 +310,11 @@ void QNSWindowBackingStore::redrawRoundedBottomCorners(CGRect windowRect) const #endif } +void QNSWindowBackingStore::backingPropertiesChanged() +{ + m_image = QImage(); +} + // ---------------------------------------------------------------------------- // https://stackoverflow.com/a/52722575/2761869 @@ -574,6 +590,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/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 d6f88b4f23..3008a056a2 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -1261,6 +1261,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() { -- cgit v1.2.3 From b1db1dd655788fb685949959c99c901515bfd8ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Klitzing?= Date: Tue, 23 Jul 2019 12:44:45 +0200 Subject: Fix build with -no-feature-printer on macOS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes: QTBUG-62675 Change-Id: I3bfcd6d78c3124769ff8662941472333c795fdbe Reviewed-by: Jörg Bornemann --- src/plugins/platforms/cocoa/cocoa.pro | 27 ++++++++++++---------- .../platforms/cocoa/qcocoanativeinterface.mm | 10 ++++---- src/plugins/platforms/cocoa/qpaintengine_mac.mm | 4 ++++ 3 files changed, 24 insertions(+), 17 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/cocoa/cocoa.pro b/src/plugins/platforms/cocoa/cocoa.pro index f0dd013922..4cf9e64447 100644 --- a/src/plugins/platforms/cocoa/cocoa.pro +++ b/src/plugins/platforms/cocoa/cocoa.pro @@ -103,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 @@ -130,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/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 -#ifndef QT_NO_WIDGETS +#if !defined(QT_NO_WIDGETS) && defined(QT_PRINTSUPPORT_LIB) #include "qcocoaprintersupport.h" #include "qprintengine_mac_p.h" #include @@ -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(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/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 #include #include #include #include +#if defined(QT_PRINTSUPPORT_LIB) #include +#endif #include #include #include -- cgit v1.2.3 From e1b0dfc1d406e132fd42ecebcc7bd260e9ef8f9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 31 Jul 2019 14:14:00 +0200 Subject: macOS: Choose appropriate NSWindow depth based on surface format Change-Id: I67e63412096ca11a8f056f5755525311756906ef Reviewed-by: Andy Nichols Reviewed-by: Timur Pocheptsov --- src/plugins/platforms/cocoa/qcocoabackingstore.mm | 31 +++++++++++++++++++++++ src/plugins/platforms/cocoa/qcocoawindow.mm | 15 ----------- 2 files changed, 31 insertions(+), 15 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/cocoa/qcocoabackingstore.mm b/src/plugins/platforms/cocoa/qcocoabackingstore.mm index 5d5e406d8a..cb453f7613 100644 --- a/src/plugins/platforms/cocoa/qcocoabackingstore.mm +++ b/src/plugins/platforms/cocoa/qcocoabackingstore.mm @@ -75,6 +75,37 @@ QCFType 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(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() diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index 3008a056a2..a3120f4ccc 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -1659,21 +1659,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; -- cgit v1.2.3 From c66732b979a4e9fb34bda062747f84e099a4fcee Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Fri, 30 Aug 2019 13:13:15 +0200 Subject: QSystemTrayIcon: on macOS, hide messages when the user clicks them MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is default behavior on macOS, and also the behavior on Windows. [ChangeLog][QtWidgets][QSystemTrayIcon] On macOS, clicking on the message will remove the notification. Change-Id: Ie30f7dacf478af76ccb53d16aea8f122869072c8 Fixes: QTBUG-77150 Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm b/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm index db64702b8d..b805fad0fe 100644 --- a/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm +++ b/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm @@ -434,8 +434,7 @@ QT_END_NAMESPACE } - (void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification { - Q_UNUSED(center); - Q_UNUSED(notification); + [center removeDeliveredNotification:notification]; emit systray->messageClicked(); } -- cgit v1.2.3 From 64ed4081cabf039e0132e9359649a6e5599f54cc Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Fri, 30 Aug 2019 12:05:01 +0200 Subject: QSystemTrayIcon on macOS: support the timeout hint in showMessage If set, schedule a call to remove the notification (NSTimeInterval is specified in seconds). The system might hide the notification balloon earlier, but the notification will still be removed from the message center after the specified interval. Task-number: QTBUG-77150 Change-Id: I510e412beb16e9de271290798f3e66310f44df4f Reviewed-by: Timur Pocheptsov --- src/plugins/platforms/cocoa/qcocoasystemtrayicon.h | 2 +- src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/cocoa/qcocoasystemtrayicon.h b/src/plugins/platforms/cocoa/qcocoasystemtrayicon.h index 6779bda491..738c40aba6 100644 --- a/src/plugins/platforms/cocoa/qcocoasystemtrayicon.h +++ b/src/plugins/platforms/cocoa/qcocoasystemtrayicon.h @@ -65,7 +65,7 @@ public: void updateMenu(QPlatformMenu *menu) override; QRect geometry() const override; void showMessage(const QString &title, const QString &msg, - const QIcon& icon, MessageIcon iconType, int secs) override; + const QIcon& icon, MessageIcon iconType, int msecs) override; bool isSystemTrayAvailable() const override; bool supportsMessages() const override; diff --git a/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm b/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm index b805fad0fe..1390ace632 100644 --- a/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm +++ b/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm @@ -264,7 +264,7 @@ bool QCocoaSystemTrayIcon::supportsMessages() const } void QCocoaSystemTrayIcon::showMessage(const QString &title, const QString &message, - const QIcon& icon, MessageIcon, int) + const QIcon& icon, MessageIcon, int msecs) { if (!m_sys) return; @@ -282,6 +282,10 @@ void QCocoaSystemTrayIcon::showMessage(const QString &title, const QString &mess NSUserNotificationCenter *center = NSUserNotificationCenter.defaultUserNotificationCenter; center.delegate = m_sys->item; [center deliverNotification:notification]; + if (msecs) { + NSTimeInterval timeout = msecs / 1000.0; + [center performSelector:@selector(removeDeliveredNotification:) withObject:notification afterDelay:timeout]; + } [notification release]; } QT_END_NAMESPACE -- cgit v1.2.3 From f6b34ce173830e470ae01597c7c1d66eaee58617 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 14 Aug 2019 12:25:41 +0200 Subject: Windows QPA: Update theme fonts when the primary screen changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Call into the theme to update the fonts on a change. This at least helps in the case of disabled High DPI scaling. Task-number: QTBUG-77144 Change-Id: I2c8fd85259403eaaeea56cd096f99116fc6bba9a Reviewed-by: André de la Rocha Reviewed-by: Oliver Wolff --- src/plugins/platforms/windows/qwindowsscreen.cpp | 6 ++++++ src/plugins/platforms/windows/qwindowstheme.h | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/windows/qwindowsscreen.cpp b/src/plugins/platforms/windows/qwindowsscreen.cpp index 4137a4bd9a..cecd06f5a4 100644 --- a/src/plugins/platforms/windows/qwindowsscreen.cpp +++ b/src/plugins/platforms/windows/qwindowsscreen.cpp @@ -42,6 +42,7 @@ #include "qwindowswindow.h" #include "qwindowsintegration.h" #include "qwindowscursor.h" +#include "qwindowstheme.h" #include @@ -547,10 +548,13 @@ bool QWindowsScreenManager::handleScreenChanges() // Look for changed monitors, add new ones const WindowsScreenDataList newDataList = monitorData(); const bool lockScreen = newDataList.size() == 1 && (newDataList.front().flags & QWindowsScreenData::LockScreen); + bool primaryScreenChanged = false; for (const QWindowsScreenData &newData : newDataList) { const int existingIndex = indexOfMonitor(m_screens, newData.name); if (existingIndex != -1) { m_screens.at(existingIndex)->handleChanges(newData); + if (existingIndex == 0) + primaryScreenChanged = true; } else { QWindowsScreen *newScreen = new QWindowsScreen(newData); m_screens.push_back(newScreen); @@ -567,6 +571,8 @@ bool QWindowsScreenManager::handleScreenChanges() removeScreen(i); } // for existing screens } // not lock screen + if (primaryScreenChanged) + QWindowsTheme::instance()->refreshFonts(); return true; } diff --git a/src/plugins/platforms/windows/qwindowstheme.h b/src/plugins/platforms/windows/qwindowstheme.h index c132f20167..28c69e4ec1 100644 --- a/src/plugins/platforms/windows/qwindowstheme.h +++ b/src/plugins/platforms/windows/qwindowstheme.h @@ -85,6 +85,8 @@ public: static bool useNativeMenus(); + void refreshFonts(); + static const char *name; private: @@ -92,7 +94,6 @@ private: void clearPalettes(); void refreshPalettes(); void clearFonts(); - void refreshFonts(); void refreshIconPixmapSizes(); static QWindowsTheme *m_instance; -- cgit v1.2.3 From 1c55a6caf1fc2b8a73a9a756bcf6894c5d4e4398 Mon Sep 17 00:00:00 2001 From: Andre de la Rocha Date: Fri, 30 Aug 2019 20:02:58 +0200 Subject: Windows QPA: Fix crash in UI Automation with Youdao Dictionary Unlike other accessibility classes, QAccessibleTree is returning a different instance, with a different ID, every time child()/childAt() are called for the same child elements. This causes ElementProviderFromPoint to return different IRawElementProviderSimple instances every time, for the same coordinates, which causes the NetEase Youdao Dictionary to call it in an infinite loop, allocating new QAccessibleTableCell instances, until the application crashes. The crash happened, for instance, just by using the mouse over Qt Creator's project tree while Youdao Dictionary was running. While the root cause seems to be QAccessibleTree not caching and reusing objects, this change adds a layer of safety to the UI Automation classes in the Windows QPA, to avoid causing a crash until QAccessibleTree, and possibly other accessibility classes, are fixed. Fixes: QTBUG-77974 Change-Id: I9b0c8174bc0fd9ef7f5626ee0b72c8a9626520ee Reviewed-by: Oliver Wolff --- .../uiautomation/qwindowsuiamainprovider.cpp | 30 ++++++++++++++-------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/windows/uiautomation/qwindowsuiamainprovider.cpp b/src/plugins/platforms/windows/uiautomation/qwindowsuiamainprovider.cpp index a427e553f0..5a05adbf81 100644 --- a/src/plugins/platforms/windows/uiautomation/qwindowsuiamainprovider.cpp +++ b/src/plugins/platforms/windows/uiautomation/qwindowsuiamainprovider.cpp @@ -670,18 +670,26 @@ HRESULT QWindowsUiaMainProvider::ElementProviderFromPoint(double x, double y, IR QPoint point; nativeUiaPointToPoint(uiaPoint, window, &point); - QAccessibleInterface *targetacc = accessible->childAt(point.x(), point.y()); - - if (targetacc) { - QAccessibleInterface *acc = targetacc; - // Controls can be embedded within grouping elements. By default returns the innermost control. - while (acc) { - targetacc = acc; - // For accessibility tools it may be better to return the text element instead of its subcomponents. - if (targetacc->textInterface()) break; - acc = acc->childAt(point.x(), point.y()); + if (auto targetacc = accessible->childAt(point.x(), point.y())) { + auto acc = accessible->childAt(point.x(), point.y()); + // Reject the cases where childAt() returns a different instance in each call for the same + // element (e.g., QAccessibleTree), as it causes an endless loop with Youdao Dictionary installed. + if (targetacc == acc) { + // Controls can be embedded within grouping elements. By default returns the innermost control. + while (acc) { + targetacc = acc; + // For accessibility tools it may be better to return the text element instead of its subcomponents. + if (targetacc->textInterface()) break; + acc = targetacc->childAt(point.x(), point.y()); + if (acc != targetacc->childAt(point.x(), point.y())) { + qCDebug(lcQpaUiAutomation) << "Non-unique childAt() for" << targetacc; + break; + } + } + *pRetVal = providerForAccessible(targetacc); + } else { + qCDebug(lcQpaUiAutomation) << "Non-unique childAt() for" << accessible; } - *pRetVal = providerForAccessible(targetacc); } return S_OK; } -- cgit v1.2.3 From 60e1c3b69853a1eaa40744836876f2dce6e0a142 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Mon, 2 Sep 2019 15:21:50 +0200 Subject: macOS: Remove use of deprecated QMatrix APIs in style Change-Id: If88a6a49b6289eb16b3cc6fca7fd340a93b72934 Reviewed-by: Timur Pocheptsov --- src/plugins/styles/mac/qmacstyle_mac.mm | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/styles/mac/qmacstyle_mac.mm b/src/plugins/styles/mac/qmacstyle_mac.mm index ec3bb91ebf..b2bcdb3e5b 100644 --- a/src/plugins/styles/mac/qmacstyle_mac.mm +++ b/src/plugins/styles/mac/qmacstyle_mac.mm @@ -555,10 +555,10 @@ QRect rotateTabPainter(QPainter *p, QTabBar::Shape shape, QRect tabRect) newRot = -90; } tabRect.setRect(0, 0, tabRect.height(), tabRect.width()); - QMatrix m; - m.translate(newX, newY); - m.rotate(newRot); - p->setMatrix(m, true); + QTransform transform; + transform.translate(newX, newY); + transform.rotate(newRot); + p->setTransform(transform, true); } return tabRect; } @@ -2951,24 +2951,24 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai } #endif - QMatrix matrix; - matrix.translate(opt->rect.center().x() + xOffset, opt->rect.center().y() + 2); + QTransform transform; + transform.translate(opt->rect.center().x() + xOffset, opt->rect.center().y() + 2); QPainterPath path; switch(pe) { default: case PE_IndicatorArrowDown: break; case PE_IndicatorArrowUp: - matrix.rotate(180); + transform.rotate(180); break; case PE_IndicatorArrowLeft: - matrix.rotate(90); + transform.rotate(90); break; case PE_IndicatorArrowRight: - matrix.rotate(-90); + transform.rotate(-90); break; } - p->setMatrix(matrix); + p->setTransform(transform); path.moveTo(-halfSize, -halfSize * 0.5); path.lineTo(0.0, halfSize * 0.5); -- cgit v1.2.3 From 43983b0b6fe2ca0d6f42edcec19115fb16753b75 Mon Sep 17 00:00:00 2001 From: Sona Kurazyan Date: Mon, 2 Sep 2019 16:45:00 +0200 Subject: Remove QOperatingSystemVersion::WindowsVista The minimum supported version is Windows 7. Remove QOperatingSystemVersion::WindowsVista added by b0cd007335853f283c47ffb0f5611d14e6dbe84b and replace with "true" wherever it was used. Change-Id: I08c0208467b655a921b6773f77d8bc099be69031 Reviewed-by: Friedemann Kleint Reviewed-by: Thiago Macieira --- src/plugins/styles/windowsvista/qwindowsvistastyle.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp b/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp index c4ada66ca9..feb2bc824b 100644 --- a/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp +++ b/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp @@ -84,8 +84,7 @@ static const int windowsRightBorder = 15; // right border on windows */ bool QWindowsVistaStylePrivate::useVista() { - return QOperatingSystemVersion::current() >= QOperatingSystemVersion::WindowsVista - && QWindowsVistaStylePrivate::useXP(); + return QWindowsVistaStylePrivate::useXP(); } /* \internal -- cgit v1.2.3 From 891b1f51b937ce3052de48dcf8416c875cf52326 Mon Sep 17 00:00:00 2001 From: BogDan Vatra Date: Wed, 28 Aug 2019 18:51:46 +0300 Subject: Android: Fix cmake generator Fixes: QTBUG-29859 Change-Id: Id0b5f9ab8b4866483361ba9f15cf51dc0d2627d0 Reviewed-by: Alexandru Croitor --- src/plugins/platforms/android/android.pro | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/android/android.pro b/src/plugins/platforms/android/android.pro index 78632a9bea..346df84038 100644 --- a/src/plugins/platforms/android/android.pro +++ b/src/plugins/platforms/android/android.pro @@ -93,7 +93,3 @@ qtConfig(vulkan) { PLUGIN_TYPE = platforms load(qt_plugin) - -#Non-standard install directory, QTBUG-29859 -DESTDIR = $$DESTDIR/android -target.path = $${target.path}/android -- cgit v1.2.3 From c2e32a29c3736c79cd6e7b669147d61764d0ff9e Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 4 Sep 2019 23:25:35 +0200 Subject: QWindowsUiaTextRangeProvider: replace ephemeral QList with QVLA MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QList is horribly inefficient™. Since the container only lives for the duration of the function call, use QVLA instead. Change-Id: I2d179caef37bb78efface5547ff8bfcdc8f9a6ac Reviewed-by: Edward Welbourne Reviewed-by: Mårten Nordheim --- .../platforms/windows/uiautomation/qwindowsuiatextrangeprovider.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/windows/uiautomation/qwindowsuiatextrangeprovider.cpp b/src/plugins/platforms/windows/uiautomation/qwindowsuiatextrangeprovider.cpp index 8e395669f8..d8b8f7281d 100644 --- a/src/plugins/platforms/windows/uiautomation/qwindowsuiatextrangeprovider.cpp +++ b/src/plugins/platforms/windows/uiautomation/qwindowsuiatextrangeprovider.cpp @@ -48,6 +48,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE @@ -227,7 +228,7 @@ HRESULT QWindowsUiaTextRangeProvider::GetBoundingRectangles(SAFEARRAY **pRetVal) return UIA_E_ELEMENTNOTAVAILABLE; int len = textInterface->characterCount(); - QList rectList; + QVarLengthArray rectList; if ((m_startOffset >= 0) && (m_endOffset <= len) && (m_startOffset < m_endOffset)) { int start, end; -- cgit v1.2.3 From 94902905ec203626abc050744d14898674dc2bbd Mon Sep 17 00:00:00 2001 From: Frank Richter Date: Sun, 11 Aug 2019 17:06:48 +0200 Subject: Windows QPA: Preferably use DXGI to obtain adapter info MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QWindowsOpenGLTester used Direct3D9 to determine GPU properties such as the vendor ID. Prefer the more modern DXGI, if available. Change-Id: Ie6b20dbe2d69bacb28d5d4e4e3459709ddc58537 Reviewed-by: André de la Rocha --- .../platforms/windows/qwindowsopengltester.cpp | 256 +++++++++++++++++++-- src/plugins/platforms/windows/windows.pri | 2 + 2 files changed, 235 insertions(+), 23 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/windows/qwindowsopengltester.cpp b/src/plugins/platforms/windows/qwindowsopengltester.cpp index afc1991e2c..63ecbfe0ea 100644 --- a/src/plugins/platforms/windows/qwindowsopengltester.cpp +++ b/src/plugins/platforms/windows/qwindowsopengltester.cpp @@ -47,6 +47,7 @@ #include #include #include +#include #include #include @@ -57,6 +58,8 @@ #include #include #include +#include +#include QT_BEGIN_NAMESPACE @@ -80,52 +83,259 @@ static GpuDescription adapterIdentifierToGpuDescription(const D3DADAPTER_IDENTIF return result; } -class QDirect3D9Handle +class QGraphicsAdapterInfo { public: - Q_DISABLE_COPY_MOVE(QDirect3D9Handle) + Q_DISABLE_COPY_MOVE(QGraphicsAdapterInfo) - QDirect3D9Handle(); - ~QDirect3D9Handle(); + QGraphicsAdapterInfo(); + ~QGraphicsAdapterInfo(); - bool isValid() const { return m_direct3D9 != nullptr; } + bool isValid() const; - UINT adapterCount() const { return m_direct3D9 ? m_direct3D9->GetAdapterCount() : 0u; } + UINT adapterCount() const; bool retrieveAdapterIdentifier(UINT n, D3DADAPTER_IDENTIFIER9 *adapterIdentifier) const; private: + QSystemLibrary m_dxgilib; + IDXGIFactory1 *m_dxgiFactory1 = nullptr; + QSystemLibrary m_d3d9lib; IDirect3D9 *m_direct3D9 = nullptr; + + /* This is a value from the DXGI_ADAPTER_FLAG enum. + * However, it's not available in dxgi.h from MinGW, + * so define it here in any case. */ + enum { DXGI_ADAPTER_FLAG_SOFTWARE = 2 }; + + UINT adapterCountDXGI() const; + bool retrieveAdapterIdentifierDXGI(UINT n, D3DADAPTER_IDENTIFIER9 *adapterIdentifier) const; + + UINT adapterCountD3D9() const; + bool retrieveAdapterIdentifierD3D9(UINT n, D3DADAPTER_IDENTIFIER9 *adapterIdentifier) const; }; -QDirect3D9Handle::QDirect3D9Handle() : +QGraphicsAdapterInfo::QGraphicsAdapterInfo() : + m_dxgilib(QStringLiteral("dxgi")), m_d3d9lib(QStringLiteral("d3d9")) { - using PtrDirect3DCreate9 = IDirect3D9 *(WINAPI *)(UINT); + using PtrCreateDXGIFactory1 = HRESULT (WINAPI *)(REFIID, void**); - if (m_d3d9lib.load()) { - if (auto direct3DCreate9 = (PtrDirect3DCreate9)m_d3d9lib.resolve("Direct3DCreate9")) - m_direct3D9 = direct3DCreate9(D3D_SDK_VERSION); + if (m_dxgilib.load()) { + if (auto createDXGIFactory1 = (PtrCreateDXGIFactory1)m_dxgilib.resolve("CreateDXGIFactory1")) + createDXGIFactory1(IID_PPV_ARGS(&m_dxgiFactory1)); + } + + if (!m_dxgiFactory1) { + using PtrDirect3DCreate9 = IDirect3D9 *(WINAPI *)(UINT); + + if (m_d3d9lib.load()) { + if (auto direct3DCreate9 = (PtrDirect3DCreate9)m_d3d9lib.resolve("Direct3DCreate9")) + m_direct3D9 = direct3DCreate9(D3D_SDK_VERSION); + } } } -QDirect3D9Handle::~QDirect3D9Handle() +QGraphicsAdapterInfo::~QGraphicsAdapterInfo() { + if (m_dxgiFactory1) + m_dxgiFactory1->Release(); if (m_direct3D9) m_direct3D9->Release(); } -bool QDirect3D9Handle::retrieveAdapterIdentifier(UINT n, D3DADAPTER_IDENTIFIER9 *adapterIdentifier) const +bool QGraphicsAdapterInfo::isValid() const +{ + return m_dxgiFactory1 != nullptr || m_direct3D9 != nullptr; +} + +UINT QGraphicsAdapterInfo::adapterCount() const +{ + if (m_dxgiFactory1) + return adapterCountDXGI(); + if (m_direct3D9) + return adapterCountD3D9(); + return 0; +} + +bool QGraphicsAdapterInfo::retrieveAdapterIdentifier(UINT n, D3DADAPTER_IDENTIFIER9 *adapterIdentifier) const +{ + if (m_dxgiFactory1) + return retrieveAdapterIdentifierDXGI(n, adapterIdentifier); + if (m_direct3D9) + return retrieveAdapterIdentifierD3D9(n, adapterIdentifier); + return false; +} + +UINT QGraphicsAdapterInfo::adapterCountDXGI() const +{ + /* DXGI doesn't have an adapterCount(), instead we have to call EnumAdapters1() + * until DXGI_ERROR_NOT_FOUND is returned. */ + UINT n = 0; + + IDXGIAdapter1 *adapter; + while (SUCCEEDED(m_dxgiFactory1->EnumAdapters1(n, &adapter))) { + adapter->Release(); + ++n; + } + + return n; +} + +// Detect whether we are running under 64-bit Windows. +static bool isWow64Process() +{ + typedef BOOL (WINAPI *IsWow64ProcessPtr)(HANDLE hProcess, PBOOL Wow64Process); + IsWow64ProcessPtr IsWow64Process = (IsWow64ProcessPtr)QLibrary::resolve( + QStringLiteral("kernel32.dll"), "IsWow64Process"); + + if (IsWow64Process) { + BOOL IsWow64 = FALSE; + if (IsWow64Process(GetCurrentProcess(), &IsWow64)) + return IsWow64; + } + return false; +} + +// Read a string value from registry +static QString regGetString(HKEY key, const wchar_t* valueName) +{ + QVarLengthArray buf (MAX_PATH); + LRESULT res; + DWORD bufSize = buf.size() * sizeof(wchar_t); + res = RegGetValue(key, nullptr, valueName, + RRF_RT_REG_SZ | RRF_RT_REG_MULTI_SZ, nullptr, + buf.data(), &bufSize); + if (res == ERROR_MORE_DATA) { + buf.resize(bufSize / sizeof(wchar_t)); + bufSize = buf.size() * sizeof(wchar_t); + res = RegGetValue(key, nullptr, valueName, + RRF_RT_REG_SZ | RRF_RT_REG_MULTI_SZ, nullptr, + buf.data(), &bufSize); + } + /* In case of REG_MULTI_SZ, this returns just the first string, + * but that is sufficient for our purposes. */ + if (res == ERROR_SUCCESS) + return QString::fromWCharArray(buf.data()); + return QString(); +} + +// Read driver name given a DeviceKey +static QString retrieveDriverName(const wchar_t *driverKey) +{ + /* Kernel-style prefix, maps to HKLM + * (see https://docs.microsoft.com/en-us/windows-hardware/drivers/kernel/registry-key-object-routines) */ + static const wchar_t prefixMappingHKLM[] = L"\\Registry\\Machine\\"; + const size_t prefixMappingHKLMLen = wcslen(prefixMappingHKLM); + if (wcsnicmp(driverKey, prefixMappingHKLM, prefixMappingHKLMLen) != 0) + return QString(); + + driverKey += prefixMappingHKLMLen; + QString driverPath; + HKEY key; + if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, driverKey, 0, KEY_READ | KEY_WOW64_64KEY, &key) == ERROR_SUCCESS) { + const wchar_t *valueName = + isWow64Process() ? L"UserModeDriverNameWow" : L"UserModeDriverName"; + driverPath = regGetString(key, valueName); + RegCloseKey(key); + } + if (!driverPath.isEmpty()) { + int fileNameSep = driverPath.lastIndexOf(QLatin1Char('\\')); + if (fileNameSep >= 0) + driverPath = driverPath.mid(fileNameSep + 1); + return driverPath; + } + return QString(); +} + +// Retrieve driver name for a display device from registry. +static QString driverNameForDevice(const wchar_t *displayDevice) +{ + QString driverName; + DISPLAY_DEVICE dd; + memset(&dd, 0, sizeof(dd)); + dd.cb = sizeof(dd); + for (int dev = 0; EnumDisplayDevices(nullptr, dev, &dd, 0); ++dev) { + if (wcsicmp(displayDevice, dd.DeviceName) == 0) { + // DeviceKey is documented as "internal", but it's a registry key in kernel format + driverName = retrieveDriverName(dd.DeviceKey); + break; + } + } + if (driverName.isEmpty()) { + /* Fall back to driver name from EnumDisplaySettings. + * This is only a fallback as on Windows 10 this just returns an device-independent + * name. OTOH, it's possible to recognize RDP connections from the driver name. */ + DEVMODE devMode; + if (EnumDisplaySettings(displayDevice, ENUM_CURRENT_SETTINGS, &devMode)) + driverName = QString::fromWCharArray(devMode.dmDeviceName); + } + return driverName; +} + +bool QGraphicsAdapterInfo::retrieveAdapterIdentifierDXGI(UINT n, D3DADAPTER_IDENTIFIER9 *adapterIdentifier) const +{ + IDXGIAdapter1 *adapter; + if (FAILED(m_dxgiFactory1->EnumAdapters1(n, &adapter))) + return false; + + bool result = false; + + DXGI_ADAPTER_DESC1 adapterDesc; + if (SUCCEEDED(adapter->GetDesc1(&adapterDesc))) { + if ((adapterDesc.VendorId != 0) && (adapterDesc.DeviceId != 0) // Don't use adapter description of Software Devices + && ((adapterDesc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) == 0)) { + memset(adapterIdentifier, 0, sizeof(*adapterIdentifier)); + WideCharToMultiByte(1252, 0, adapterDesc.Description, -1, + adapterIdentifier->Description, + sizeof(adapterIdentifier->Description), nullptr, nullptr); + adapterIdentifier->Description[sizeof(adapterIdentifier->Description) - 1] = 0; + adapterIdentifier->VendorId = adapterDesc.VendorId; + adapterIdentifier->DeviceId = adapterDesc.DeviceId; + adapterIdentifier->SubSysId = adapterDesc.SubSysId; + adapterIdentifier->Revision = adapterDesc.Revision; + + LARGE_INTEGER umdVersion; + if (SUCCEEDED(adapter->CheckInterfaceSupport(__uuidof(ID3D10Device), &umdVersion))) { + adapterIdentifier->DriverVersion = umdVersion; + result = true; + } + + /* DXGI doesn't expose the driver name, but we can get it from the registry. + * But we need a device name to follow. */ + IDXGIOutput *output = nullptr; + if (SUCCEEDED(adapter->EnumOutputs (0, &output))) { + DXGI_OUTPUT_DESC outputDesc; + if (SUCCEEDED(output->GetDesc (&outputDesc))) { + QString driverName = driverNameForDevice(outputDesc.DeviceName); + qstrncpy(adapterIdentifier->Driver, driverName.toLatin1().constData(), + sizeof(adapterIdentifier->Driver)); + } + output->Release(); + } + } + } + + adapter->Release(); + + return result; +} + +UINT QGraphicsAdapterInfo::adapterCountD3D9() const +{ + return m_direct3D9->GetAdapterCount(); +} + +bool QGraphicsAdapterInfo::retrieveAdapterIdentifierD3D9(UINT n, D3DADAPTER_IDENTIFIER9 *adapterIdentifier) const { - return m_direct3D9 - && SUCCEEDED(m_direct3D9->GetAdapterIdentifier(n, 0, adapterIdentifier)); + return SUCCEEDED(m_direct3D9->GetAdapterIdentifier(n, 0, adapterIdentifier)); } GpuDescription GpuDescription::detect() { GpuDescription result; - QDirect3D9Handle direct3D9; - if (!direct3D9.isValid()) + QGraphicsAdapterInfo adapterInfo; + if (!adapterInfo.isValid()) return result; D3DADAPTER_IDENTIFIER9 adapterIdentifier; @@ -136,7 +346,7 @@ GpuDescription GpuDescription::detect() // and D3D uses by default. Therefore querying any additional adapters is // futile and not useful for our purposes in general, except for // identifying a few special cases later on. - if (direct3D9.retrieveAdapterIdentifier(0, &adapterIdentifier)) { + if (adapterInfo.retrieveAdapterIdentifier(0, &adapterIdentifier)) { result = adapterIdentifierToGpuDescription(adapterIdentifier); isAMD = result.vendorId == VENDOR_ID_AMD; } @@ -145,9 +355,9 @@ GpuDescription GpuDescription::detect() // when starting apps on a screen connected to the Intel card) by looking // for a default AMD adapter and an additional non-AMD one. if (isAMD) { - const UINT adapterCount = direct3D9.adapterCount(); + const UINT adapterCount = adapterInfo.adapterCount(); for (UINT adp = 1; adp < adapterCount; ++adp) { - if (direct3D9.retrieveAdapterIdentifier(adp, &adapterIdentifier) + if (adapterInfo.retrieveAdapterIdentifier(adp, &adapterIdentifier) && adapterIdentifier.VendorId != VENDOR_ID_AMD) { // Bingo. Now figure out the display for the AMD card. DISPLAY_DEVICE dd; @@ -172,11 +382,11 @@ GpuDescription GpuDescription::detect() QVector GpuDescription::detectAll() { QVector result; - QDirect3D9Handle direct3D9; - if (const UINT adapterCount = direct3D9.adapterCount()) { + QGraphicsAdapterInfo adapterInfo; + if (const UINT adapterCount = adapterInfo.adapterCount()) { for (UINT adp = 0; adp < adapterCount; ++adp) { D3DADAPTER_IDENTIFIER9 adapterIdentifier; - if (direct3D9.retrieveAdapterIdentifier(adp, &adapterIdentifier)) + if (adapterInfo.retrieveAdapterIdentifier(adp, &adapterIdentifier)) result.append(adapterIdentifierToGpuDescription(adapterIdentifier)); } } diff --git a/src/plugins/platforms/windows/windows.pri b/src/plugins/platforms/windows/windows.pri index 95ba961df1..7de6369541 100644 --- a/src/plugins/platforms/windows/windows.pri +++ b/src/plugins/platforms/windows/windows.pri @@ -12,6 +12,8 @@ LIBS += -lshlwapi -lwtsapi32 QMAKE_USE_PRIVATE += \ advapi32 \ d3d9/nolink \ + d3d11/nolink \ + dxgi/nolink \ ole32 \ shell32 \ user32 \ -- cgit v1.2.3 From 82c6911d7d25489bd810fbef89441e5d8ee5cfac Mon Sep 17 00:00:00 2001 From: Frank Richter Date: Mon, 9 Sep 2019 09:32:40 +0200 Subject: Windows QPA: Fix pixel format looping in describeFormats() As per MSDN, pixel format indices are 1-based, not 0-based. Change-Id: I6083144d3a95626e45bea21b50096b5f5f811c67 Reviewed-by: Friedemann Kleint --- src/plugins/platforms/windows/qwindowsglcontext.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/windows/qwindowsglcontext.cpp b/src/plugins/platforms/windows/qwindowsglcontext.cpp index 101db75d0b..dcdf9a5622 100644 --- a/src/plugins/platforms/windows/qwindowsglcontext.cpp +++ b/src/plugins/platforms/windows/qwindowsglcontext.cpp @@ -323,7 +323,7 @@ static inline bool static void describeFormats(HDC hdc) { const int pfiMax = DescribePixelFormat(hdc, 0, 0, nullptr); - for (int i = 0; i < pfiMax; i++) { + for (int i = 1; i <= pfiMax; i++) { PIXELFORMATDESCRIPTOR pfd; initPixelFormatDescriptor(&pfd); DescribePixelFormat(hdc, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd); -- cgit v1.2.3 From e77877f2079a74918c139b8ea7f6dc927246c20f Mon Sep 17 00:00:00 2001 From: Frank Richter Date: Wed, 26 Jul 2017 11:27:30 +0200 Subject: Windows QPA: Also wrap DescribePixelFormat() GDI and the software rendering opengl32sw.dll may have very different pixel formats so use wglDescribePixelFormat() in that case. This mirrors the existing behavior for SetPixelFormat(). Change-Id: I55e658ab69bad84bb10cc5a042d62e84c005c0e6 Reviewed-by: Oliver Wolff --- src/plugins/platforms/windows/qwindowsglcontext.cpp | 12 +++++++++--- src/plugins/platforms/windows/qwindowsglcontext.h | 2 ++ 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/windows/qwindowsglcontext.cpp b/src/plugins/platforms/windows/qwindowsglcontext.cpp index 101db75d0b..64b83e2bc4 100644 --- a/src/plugins/platforms/windows/qwindowsglcontext.cpp +++ b/src/plugins/platforms/windows/qwindowsglcontext.cpp @@ -196,6 +196,7 @@ bool QWindowsOpengl32DLL::init(bool softwareRendering) wglShareLists = reinterpret_cast(resolve("wglShareLists")); wglSwapBuffers = reinterpret_cast(resolve("wglSwapBuffers")); wglSetPixelFormat = reinterpret_cast(resolve("wglSetPixelFormat")); + wglDescribePixelFormat = reinterpret_cast(resolve("wglDescribePixelFormat")); glGetError = reinterpret_cast(resolve("glGetError")); glGetIntegerv = reinterpret_cast(resolve("glGetIntegerv")); @@ -214,6 +215,11 @@ BOOL QWindowsOpengl32DLL::setPixelFormat(HDC dc, int pf, const PIXELFORMATDESCRI return moduleIsNotOpengl32() ? wglSetPixelFormat(dc, pf, pfd) : SetPixelFormat(dc, pf, pfd); } +int QWindowsOpengl32DLL::describePixelFormat(HDC dc, int pf, UINT size, PIXELFORMATDESCRIPTOR *pfd) +{ + return moduleIsNotOpengl32() ? wglDescribePixelFormat(dc, pf, size, pfd) : DescribePixelFormat(dc, pf, size, pfd); +} + QWindowsOpenGLContext *QOpenGLStaticContext::createContext(QOpenGLContext *context) { return new QWindowsGLContext(this, context); @@ -322,11 +328,11 @@ static inline bool static void describeFormats(HDC hdc) { - const int pfiMax = DescribePixelFormat(hdc, 0, 0, nullptr); + const int pfiMax = QOpenGLStaticContext::opengl32.describePixelFormat(hdc, 0, 0, nullptr); for (int i = 0; i < pfiMax; i++) { PIXELFORMATDESCRIPTOR pfd; initPixelFormatDescriptor(&pfd); - DescribePixelFormat(hdc, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd); + QOpenGLStaticContext::opengl32.describePixelFormat(hdc, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd); qCDebug(lcQpaGl) << '#' << i << '/' << pfiMax << ':' << pfd; } } @@ -617,7 +623,7 @@ static int choosePixelFormat(HDC hdc, // Verify if format is acceptable. Note that the returned // formats have been observed to not contain PFD_SUPPORT_OPENGL, ignore. initPixelFormatDescriptor(obtainedPfd); - DescribePixelFormat(hdc, pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), obtainedPfd); + QOpenGLStaticContext::opengl32.describePixelFormat(hdc, pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), obtainedPfd); if (!isAcceptableFormat(additional, *obtainedPfd, true)) { qCDebug(lcQpaGl) << __FUNCTION__ << " obtained px #" << pixelFormat << " not acceptable=" << *obtainedPfd; diff --git a/src/plugins/platforms/windows/qwindowsglcontext.h b/src/plugins/platforms/windows/qwindowsglcontext.h index 1abe2eb390..e962af39c2 100644 --- a/src/plugins/platforms/windows/qwindowsglcontext.h +++ b/src/plugins/platforms/windows/qwindowsglcontext.h @@ -107,6 +107,7 @@ struct QWindowsOpengl32DLL // Wrappers. Always use these instead of SwapBuffers/wglSwapBuffers/etc. BOOL swapBuffers(HDC dc); BOOL setPixelFormat(HDC dc, int pf, const PIXELFORMATDESCRIPTOR *pfd); + int describePixelFormat(HDC dc, int pf, UINT size, PIXELFORMATDESCRIPTOR *pfd); // WGL HGLRC (WINAPI * wglCreateContext)(HDC dc); @@ -130,6 +131,7 @@ private: // For Mesa llvmpipe shipped with a name other than opengl32.dll BOOL (WINAPI * wglSwapBuffers)(HDC dc); BOOL (WINAPI * wglSetPixelFormat)(HDC dc, int pf, const PIXELFORMATDESCRIPTOR *pfd); + int (WINAPI * wglDescribePixelFormat)(HDC dc, int pf, UINT size, PIXELFORMATDESCRIPTOR *pfd); }; class QOpenGLStaticContext : public QWindowsStaticOpenGLContext -- cgit v1.2.3 From b1698e9bc2ca0668f5b5f0e7af2274eb2a0cb7e0 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 4 Sep 2019 23:44:16 +0200 Subject: QWinRTUia*: remove anti-pattern passing new'ed QSharedPointer into lambdas MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QSharedPointer is made for passing around by value. It is unclear why in so many repeated cases a QSharedPointer is created on the stack, then a copy of it is new'ed up, passed into a lambda to be deleted inside it. First, it requires an additional heap allocation. Because it's passed as a raw pointer to QSharedPointer, however, there's also always the danger that it's leaked by seemingly-innocuous changes such as adding an early return from the lambda (and some of them could really use one, with the ifs nesting several levels deep). All this is not needed, though. It's perfectly ok to store a copy of a QSharedPointer, by value, in a lambda, and keep one copy outside it. Poor man's std::future, if you will. So, do away with all that, just pass the shared pointer by value into the lambda, and, as a drive-by, replace some ephemeral QLists with QVLAs. In one case, replace a QPair with a struct to make the code using that type more accessible ('first' and 'second' are really, really bad variable names if they, in fact, represent 'startOffset' and 'endOffset'). Also port directly to shared_ptr / make_shared. Saves one memory allocation each, due to the co-allocation of payload and control block, and even though there's QSharedPointer::create, which does this, too, std::shared_ptr is simply much lighter on the use of atomics (copying a QSP ups two ref counts, copying a std::shared_ptr just one). Since these variables live behind the API boundary, there's no reason not to prefer the more efficient alternative. Change-Id: I4b9fe30e56df5106fc2ab7a0b55b2b8316cca5fe Reviewed-by: Oliver Wolff Reviewed-by: Mårten Nordheim --- .../uiautomation/qwinrtuiagriditemprovider.cpp | 12 +++---- .../winrt/uiautomation/qwinrtuiagridprovider.cpp | 12 +++---- .../winrt/uiautomation/qwinrtuiamainprovider.cpp | 26 +++++++-------- .../winrt/uiautomation/qwinrtuiamainprovider.h | 2 +- .../qwinrtuiaselectionitemprovider.cpp | 10 +++--- .../uiautomation/qwinrtuiaselectionprovider.cpp | 18 +++++----- .../uiautomation/qwinrtuiatableitemprovider.cpp | 18 +++++----- .../winrt/uiautomation/qwinrtuiatableprovider.cpp | 18 +++++----- .../winrt/uiautomation/qwinrtuiatextprovider.cpp | 38 ++++++++++++---------- .../uiautomation/qwinrtuiatextrangeprovider.cpp | 21 ++++++------ 10 files changed, 85 insertions(+), 90 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiagriditemprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiagriditemprovider.cpp index 524000b618..355dbf7d20 100644 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiagriditemprovider.cpp +++ b/src/plugins/platforms/winrt/uiautomation/qwinrtuiagriditemprovider.cpp @@ -51,6 +51,8 @@ #include #include +#include + QT_BEGIN_NAMESPACE using namespace QWinRTUiAutomation; @@ -105,19 +107,17 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaGridItemProvider::get_ContainingGrid(IIRawEle *value = nullptr; auto accid = id(); - auto elementId = QSharedPointer(new QAccessible::Id(0)); - auto ptrElementId = new QSharedPointer(elementId); + auto elementId = std::make_shared(0); - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, ptrElementId]() { + if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, elementId]() { if (QAccessibleInterface *accessible = accessibleForId(accid)) { if (QAccessibleTableCellInterface *tableCellInterface = accessible->tableCellInterface()) { if (QAccessibleInterface *table = tableCellInterface->table()) { - **ptrElementId = idForAccessible(table); - QWinRTUiaMetadataCache::instance()->load(**ptrElementId); + *elementId = idForAccessible(table); + QWinRTUiaMetadataCache::instance()->load(*elementId); } } } - delete ptrElementId; return S_OK; }))) { return E_FAIL; diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiagridprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiagridprovider.cpp index e469991de2..3bd90f6850 100644 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiagridprovider.cpp +++ b/src/plugins/platforms/winrt/uiautomation/qwinrtuiagridprovider.cpp @@ -51,6 +51,8 @@ #include #include +#include + QT_BEGIN_NAMESPACE using namespace QWinRTUiAutomation; @@ -104,21 +106,19 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaGridProvider::GetItem(INT32 row, INT32 column *returnValue = nullptr; auto accid = id(); - auto elementId = QSharedPointer(new QAccessible::Id(0)); - auto ptrElementId = new QSharedPointer(elementId); + auto elementId = std::make_shared(0); - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, row, column, ptrElementId]() { + if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, row, column, elementId]() { if (QAccessibleInterface *accessible = accessibleForId(accid)) { if (QAccessibleTableInterface *tableInterface = accessible->tableInterface()) { if ((row >= 0) && (row < tableInterface->rowCount()) && (column >= 0) && (column < tableInterface->columnCount())) { if (QAccessibleInterface *cell = tableInterface->cellAt(row, column)) { - **ptrElementId = idForAccessible(cell); - QWinRTUiaMetadataCache::instance()->load(**ptrElementId); + *elementId = idForAccessible(cell); + QWinRTUiaMetadataCache::instance()->load(*elementId); } } } } - delete ptrElementId; return S_OK; }))) { return E_FAIL; diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiamainprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiamainprovider.cpp index 6f3ad6dcd2..0b1db306bd 100644 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiamainprovider.cpp +++ b/src/plugins/platforms/winrt/uiautomation/qwinrtuiamainprovider.cpp @@ -64,6 +64,8 @@ #include #include +#include + using namespace QWinRTUiAutomation; using namespace Microsoft::WRL; using namespace Microsoft::WRL::Wrappers; @@ -179,7 +181,7 @@ HRESULT QWinRTUiaMainProvider::rawProviderForAccessibleId(QAccessible::Id elemen } // Returns an array of IIRawElementProviderSimple instances for a list of accessible interface ids. -HRESULT QWinRTUiaMainProvider::rawProviderArrayForAccessibleIdList(const QList &elementIds, +HRESULT QWinRTUiaMainProvider::rawProviderArrayForAccessibleIdList(const QVarLengthArray &elementIds, UINT32 *returnValueSize, IIRawElementProviderSimple ***returnValue) { @@ -190,7 +192,7 @@ HRESULT QWinRTUiaMainProvider::rawProviderArrayForAccessibleIdList(const QList rawProviderList; - for (auto elementId : qAsConst(elementIds)) { + for (auto elementId : elementIds) { IIRawElementProviderSimple *rawProvider; if (SUCCEEDED(rawProviderForAccessibleId(elementId, &rawProvider))) rawProviderList.append(rawProvider); @@ -515,10 +517,9 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::GetChildrenCore(IVector>(new QList); - auto ptrChildren = new QSharedPointer>(children); + auto children = std::make_shared>(); - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, ptrChildren]() { + if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, children]() { if (QAccessibleInterface *accessible = accessibleForId(accid)) { int childCount = accessible->childCount(); for (int i = 0; i < childCount; ++i) { @@ -526,11 +527,10 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::GetChildrenCore(IVectorload(childId); if (!childAcc->state().invisible) - (*ptrChildren)->append(childId); + children->append(childId); } } } - delete ptrChildren; return S_OK; }))) { return E_FAIL; @@ -538,7 +538,7 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::GetChildrenCore(IVector> peerVector = Make(); - for (auto childId : qAsConst(*children)) { + for (auto childId : *children) { if (ComPtr provider = providerForAccessibleId(childId)) { IAutomationPeer *peer; if (SUCCEEDED(provider.CopyTo(&peer))) @@ -750,10 +750,9 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::GetPeerFromPointCore(ABI::Windo // Scale coordinates from High DPI screens? auto accid = id(); - auto elementId = QSharedPointer(new QAccessible::Id(0)); - auto ptrElementId = new QSharedPointer(elementId); + auto elementId = std::make_shared(0); - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, ptrElementId, point]() { + if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, elementId, point]() { // Controls can be embedded within grouping elements. By default returns the innermost control. QAccessibleInterface *target = accessibleForId(accid); while (QAccessibleInterface *tmpacc = target->childAt(point.X, point.Y)) { @@ -761,9 +760,8 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::GetPeerFromPointCore(ABI::Windo // For accessibility tools it may be better to return the text element instead of its subcomponents. if (target->textInterface()) break; } - **ptrElementId = idForAccessible(target); - QWinRTUiaMetadataCache::instance()->load(**ptrElementId); - delete ptrElementId; + *elementId = idForAccessible(target); + QWinRTUiaMetadataCache::instance()->load(*elementId); return S_OK; }))) { return E_FAIL; diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiamainprovider.h b/src/plugins/platforms/winrt/uiautomation/qwinrtuiamainprovider.h index 384a166cf7..23a6e56ae7 100644 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiamainprovider.h +++ b/src/plugins/platforms/winrt/uiautomation/qwinrtuiamainprovider.h @@ -69,7 +69,7 @@ public: virtual ~QWinRTUiaMainProvider(); static QWinRTUiaMainProvider *providerForAccessibleId(QAccessible::Id id); static HRESULT rawProviderForAccessibleId(QAccessible::Id elementId, ABI::Windows::UI::Xaml::Automation::Provider::IIRawElementProviderSimple **returnValue); - static HRESULT rawProviderArrayForAccessibleIdList(const QList &elementIds, UINT32 *returnValueSize, ABI::Windows::UI::Xaml::Automation::Provider::IIRawElementProviderSimple ***returnValue); + static HRESULT rawProviderArrayForAccessibleIdList(const QVarLengthArray &elementIds, UINT32 *returnValueSize, ABI::Windows::UI::Xaml::Automation::Provider::IIRawElementProviderSimple ***returnValue); static void notifyFocusChange(QAccessibleEvent *event); static void notifyVisibilityChange(QAccessibleEvent *event); static void notifyStateChange(QAccessibleStateChangeEvent *event); diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiaselectionitemprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiaselectionitemprovider.cpp index 9bc88272ba..2cb5aa685c 100644 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiaselectionitemprovider.cpp +++ b/src/plugins/platforms/winrt/uiautomation/qwinrtuiaselectionitemprovider.cpp @@ -51,6 +51,8 @@ #include #include +#include + QT_BEGIN_NAMESPACE using namespace QWinRTUiAutomation; @@ -94,21 +96,19 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaSelectionItemProvider::get_SelectionContainer *value = nullptr; auto accid = id(); - auto elementId = QSharedPointer(new QAccessible::Id(0)); - auto ptrElementId = new QSharedPointer(elementId); + auto elementId = std::make_shared(0); - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, ptrElementId]() { + if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, elementId]() { if (QAccessibleInterface *accessible = accessibleForId(accid)) { // Radio buttons do not require a container. if (accessible->role() == QAccessible::ListItem) { if (QAccessibleInterface *parent = accessible->parent()) { if (parent->role() == QAccessible::List) { - **ptrElementId = idForAccessible(parent); + *elementId = idForAccessible(parent); } } } } - delete ptrElementId; return S_OK; }))) { return E_FAIL; diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiaselectionprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiaselectionprovider.cpp index 9e61a8df61..4d825351c8 100644 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiaselectionprovider.cpp +++ b/src/plugins/platforms/winrt/uiautomation/qwinrtuiaselectionprovider.cpp @@ -51,6 +51,8 @@ #include #include +#include + QT_BEGIN_NAMESPACE using namespace QWinRTUiAutomation; @@ -89,10 +91,9 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaSelectionProvider::get_IsSelectionRequired(bo *value = false; auto accid = id(); - auto selectionRequired = QSharedPointer(new bool(false)); - auto ptrSelectionRequired = new QSharedPointer(selectionRequired); + auto selectionRequired = std::make_shared(false); - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, ptrSelectionRequired]() { + if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, selectionRequired]() { // Initially returns false if none are selected. After the first selection, it may be required. bool anySelected = false; if (QAccessibleInterface *accessible = accessibleForId(accid)) { @@ -105,9 +106,8 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaSelectionProvider::get_IsSelectionRequired(bo } } } - **ptrSelectionRequired = anySelected && !accessible->state().multiSelectable && !accessible->state().extSelectable; + *selectionRequired = anySelected && !accessible->state().multiSelectable && !accessible->state().extSelectable; } - delete ptrSelectionRequired; return S_OK; }))) { return E_FAIL; @@ -128,10 +128,9 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaSelectionProvider::GetSelection(UINT32 *retur *returnValue = nullptr; auto accid = id(); - auto elementIds = QSharedPointer>(new QList); - auto ptrElementIds = new QSharedPointer>(elementIds); + auto elementIds = std::make_shared>(); - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, ptrElementIds]() { + if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, elementIds]() { if (QAccessibleInterface *accessible = accessibleForId(accid)) { int childCount = accessible->childCount(); for (int i = 0; i < childCount; ++i) { @@ -139,12 +138,11 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaSelectionProvider::GetSelection(UINT32 *retur if (childAcc->state().selected) { QAccessible::Id childId = idForAccessible(childAcc); QWinRTUiaMetadataCache::instance()->load(childId); - (*ptrElementIds)->append(childId); + elementIds->append(childId); } } } } - delete ptrElementIds; return S_OK; }))) { return E_FAIL; diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatableitemprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiatableitemprovider.cpp index 1af74a8b72..7cd953de87 100644 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatableitemprovider.cpp +++ b/src/plugins/platforms/winrt/uiautomation/qwinrtuiatableitemprovider.cpp @@ -51,6 +51,8 @@ #include #include +#include + QT_BEGIN_NAMESPACE using namespace QWinRTUiAutomation; @@ -79,21 +81,19 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTableItemProvider::GetColumnHeaderItems(UINT3 *returnValue = nullptr; auto accid = id(); - auto elementIds = QSharedPointer>(new QList); - auto ptrElementIds = new QSharedPointer>(elementIds); + auto elementIds = std::make_shared>(); - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, ptrElementIds]() { + if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, elementIds]() { if (QAccessibleInterface *accessible = accessibleForId(accid)) { if (QAccessibleTableCellInterface *tableCellInterface = accessible->tableCellInterface()) { QList headers = tableCellInterface->columnHeaderCells(); for (auto header : qAsConst(headers)) { QAccessible::Id headerId = idForAccessible(header); QWinRTUiaMetadataCache::instance()->load(headerId); - (*ptrElementIds)->append(headerId); + elementIds->append(headerId); } } } - delete ptrElementIds; return S_OK; }))) { return E_FAIL; @@ -113,21 +113,19 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTableItemProvider::GetRowHeaderItems(UINT32 * *returnValue = nullptr; auto accid = id(); - auto elementIds = QSharedPointer>(new QList); - auto ptrElementIds = new QSharedPointer>(elementIds); + auto elementIds = std::make_shared>(); - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, ptrElementIds]() { + if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, elementIds]() { if (QAccessibleInterface *accessible = accessibleForId(accid)) { if (QAccessibleTableCellInterface *tableCellInterface = accessible->tableCellInterface()) { QList headers = tableCellInterface->rowHeaderCells(); for (auto header : qAsConst(headers)) { QAccessible::Id headerId = idForAccessible(header); QWinRTUiaMetadataCache::instance()->load(headerId); - (*ptrElementIds)->append(headerId); + elementIds->append(headerId); } } } - delete ptrElementIds; return S_OK; }))) { return E_FAIL; diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatableprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiatableprovider.cpp index e71ade3c1f..d763b320b1 100644 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatableprovider.cpp +++ b/src/plugins/platforms/winrt/uiautomation/qwinrtuiatableprovider.cpp @@ -51,6 +51,8 @@ #include #include +#include + QT_BEGIN_NAMESPACE using namespace QWinRTUiAutomation; @@ -91,10 +93,9 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTableProvider::GetColumnHeaders(UINT32 *retur *returnValue = nullptr; auto accid = id(); - auto elementIds = QSharedPointer>(new QList); - auto ptrElementIds = new QSharedPointer>(elementIds); + auto elementIds = std::make_shared>(); - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, ptrElementIds]() { + if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, elementIds]() { if (QAccessibleInterface *accessible = accessibleForId(accid)) { if (QAccessibleTableInterface *tableInterface = accessible->tableInterface()) { for (int i = 0; i < tableInterface->columnCount(); ++i) { @@ -105,14 +106,13 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTableProvider::GetColumnHeaders(UINT32 *retur for (auto header : qAsConst(headers)) { QAccessible::Id headerId = idForAccessible(header); QWinRTUiaMetadataCache::instance()->load(headerId); - (*ptrElementIds)->append(headerId); + elementIds->append(headerId); } } } } } } - delete ptrElementIds; return S_OK; }))) { return E_FAIL; @@ -132,10 +132,9 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTableProvider::GetRowHeaders(UINT32 *returnVa *returnValue = nullptr; auto accid = id(); - auto elementIds = QSharedPointer>(new QList); - auto ptrElementIds = new QSharedPointer>(elementIds); + auto elementIds = std::make_shared>(); - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, ptrElementIds]() { + if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, elementIds]() { if (QAccessibleInterface *accessible = accessibleForId(accid)) { if (QAccessibleTableInterface *tableInterface = accessible->tableInterface()) { for (int i = 0; i < tableInterface->rowCount(); ++i) { @@ -146,14 +145,13 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTableProvider::GetRowHeaders(UINT32 *returnVa for (auto header : qAsConst(headers)) { QAccessible::Id headerId = idForAccessible(header); QWinRTUiaMetadataCache::instance()->load(headerId); - (*ptrElementIds)->append(headerId); + elementIds->append(headerId); } } } } } } - delete ptrElementIds; return S_OK; }))) { return E_FAIL; diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatextprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiatextprovider.cpp index aa120377df..cd7420f360 100644 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatextprovider.cpp +++ b/src/plugins/platforms/winrt/uiautomation/qwinrtuiatextprovider.cpp @@ -51,6 +51,8 @@ #include #include +#include + QT_BEGIN_NAMESPACE using namespace QWinRTUiAutomation; @@ -104,26 +106,26 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTextProvider::GetSelection(UINT32 *returnValu *returnValueSize = 0; *returnValue = nullptr; + struct Selection { int startOffset, endOffset; }; + auto accid = id(); - auto selections = QSharedPointer>>(new QList>); - auto ptrSelections = new QSharedPointer>>(selections); + auto selections = std::make_shared>(); - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, ptrSelections]() { + if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, selections]() { if (QAccessibleInterface *accessible = accessibleForId(accid)) { if (QAccessibleTextInterface *textInterface = accessible->textInterface()) { for (int i = 0; i < textInterface->selectionCount(); ++i) { - QPair sel; - textInterface->selection(i, &sel.first, &sel.second); - (*ptrSelections)->append(sel); + int startOffset, endOffset; + textInterface->selection(i, &startOffset, &endOffset); + selections->append({startOffset, endOffset}); } - if ((*ptrSelections)->size() == 0) { + if (selections->size() == 0) { // If there is no selection, we return an array with a single degenerate (empty) text range at the cursor position. - QPair sel(textInterface->cursorPosition(), textInterface->cursorPosition()); - (*ptrSelections)->append(sel); + auto cur = textInterface->cursorPosition(); + selections->append({cur, cur}); } } } - delete ptrSelections; return S_OK; }))) { return E_FAIL; @@ -137,9 +139,11 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTextProvider::GetSelection(UINT32 *returnValu if (!providerArray) return E_OUTOFMEMORY; - for (int i = 0; i < selCount; ++i) { - ComPtr textRangeProvider = Make(id(), (*selections)[i].first, (*selections)[i].second); - textRangeProvider.CopyTo(&providerArray[i]); + auto dst = providerArray; + for (auto sel : *selections) { + ComPtr textRangeProvider + = Make(id(), sel.startOffset, sel.endOffset); + textRangeProvider.CopyTo(dst++); } *returnValueSize = selCount; *returnValue = providerArray; @@ -184,14 +188,12 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTextProvider::RangeFromPoint(ABI::Windows::Fo const QPoint pt(screenLocation.X, screenLocation.Y); auto accid = id(); - auto offset = QSharedPointer(new int); - auto ptrOffset = new QSharedPointer(offset); + auto offset = std::make_shared(); - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, pt, ptrOffset]() { + if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, pt, offset]() { if (QAccessibleInterface *accessible = accessibleForId(accid)) if (QAccessibleTextInterface *textInterface = accessible->textInterface()) - **ptrOffset = qBound(0, textInterface->offsetAtPoint(pt), textInterface->characterCount() - 1); - delete ptrOffset; + *offset = qBound(0, textInterface->offsetAtPoint(pt), textInterface->characterCount() - 1); return S_OK; }))) { return E_FAIL; diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatextrangeprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiatextrangeprovider.cpp index fc3778d652..ca15feaff9 100644 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatextrangeprovider.cpp +++ b/src/plugins/platforms/winrt/uiautomation/qwinrtuiatextrangeprovider.cpp @@ -51,6 +51,8 @@ #include #include +#include + QT_BEGIN_NAMESPACE using namespace QWinRTUiAutomation; @@ -212,10 +214,9 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTextRangeProvider::GetBoundingRectangles(UINT auto accid = id(); auto startOffset = m_startOffset; auto endOffset = m_endOffset; - auto rects = QSharedPointer>(new QList); - auto ptrRects = new QSharedPointer>(rects); + auto rects = std::make_shared>(); - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, startOffset, endOffset, ptrRects]() { + if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, startOffset, endOffset, rects]() { if (QAccessibleInterface *accessible = accessibleForId(accid)) { if (QAccessibleTextInterface *textInterface = accessible->textInterface()) { int len = textInterface->characterCount(); @@ -233,7 +234,7 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTextRangeProvider::GetBoundingRectangles(UINT qMin(startRect.y(), endRect.y()), qMax(startRect.x() + startRect.width(), endRect.x() + endRect.width()) - qMin(startRect.x(), endRect.x()), qMax(startRect.y() + startRect.height(), endRect.y() + endRect.height()) - qMin(startRect.y(), endRect.y())); - (*ptrRects)->append(lineRect); + rects->append(lineRect); } if (end >= len) break; textInterface->textAfterOffset(end + 1, QAccessible::LineBoundary, &start, &end); @@ -241,7 +242,6 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTextRangeProvider::GetBoundingRectangles(UINT } } } - delete ptrRects; return S_OK; }))) { return E_FAIL; @@ -251,11 +251,12 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTextRangeProvider::GetBoundingRectangles(UINT if (!doubleArray) return E_OUTOFMEMORY; - for (int i = 0; i < rects->size(); ++i) { - doubleArray[i*4] = (*rects)[i].left(); - doubleArray[i*4+1] = (*rects)[i].top(); - doubleArray[i*4+2] = (*rects)[i].width(); - doubleArray[i*4+3] = (*rects)[i].height(); + DOUBLE *dst = doubleArray; + for (auto rect : *rects) { + *dst++ = rect.left(); + *dst++ = rect.top(); + *dst++ = rect.width(); + *dst++ = rect.height(); } *returnValue = doubleArray; *returnValueSize = 4 * rects->size(); -- cgit v1.2.3 From bc34784d053ebf9b0d167e9398052fcc80d8af87 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Sun, 8 Sep 2019 10:27:47 +0200 Subject: Handle robustness with OpenGL < 4.0 We need to have the right idea of robustness, so check for extension. Fixes: QTBUG-78107 Change-Id: I26987269e5c50bee20e2e3cc6d75f91a6c9af25e Reviewed-by: Laszlo Agocs --- .../gl_integrations/xcb_glx/qglxintegration.cpp | 24 +++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp index 5e5fefca90..2b77062b16 100644 --- a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp +++ b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp @@ -63,6 +63,7 @@ QT_BEGIN_NAMESPACE typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*); +typedef const GLubyte *(*glGetStringiProc)(GLenum, GLuint); #ifndef GLX_CONTEXT_CORE_PROFILE_BIT_ARB #define GLX_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001 @@ -145,6 +146,27 @@ static inline QByteArray getGlString(GLenum param) return QByteArray(); } +static bool hasGlExtension(const QSurfaceFormat &format, const char *ext) +{ + if (format.majorVersion() < 3) { + auto exts = reinterpret_cast(glGetString(GL_EXTENSIONS)); + return exts && strstr(exts, ext); + } else { + auto glGetStringi = reinterpret_cast( + glXGetProcAddress(reinterpret_cast("glGetStringi"))); + if (glGetStringi) { + GLint n = 0; + 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, ext)) + return true; + } + } + return false; + } +} + static void updateFormatFromContext(QSurfaceFormat &format) { // Update the version, profile, and context bit of the format @@ -163,7 +185,7 @@ static void updateFormatFromContext(QSurfaceFormat &format) format.setOption(QSurfaceFormat::StereoBuffers); if (format.renderableType() == QSurfaceFormat::OpenGL) { - if (format.version() >= qMakePair(4, 0)) { + if (hasGlExtension(format, "GL_ARB_robustness")) { GLint value = 0; glGetIntegerv(GL_RESET_NOTIFICATION_STRATEGY_ARB, &value); if (value == GL_LOSE_CONTEXT_ON_RESET_ARB) -- cgit v1.2.3 From 137cbd1c7200809cc3945c6d4b6deee560cdc9fc Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Thu, 29 Aug 2019 23:58:58 +0200 Subject: Cocoa: Set the accepted action to be the one from the response MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit By setting the accepted action to be the one from the response it will enable the user to set the drop action in their code and this will be reflected at the platform level. Change-Id: I7b9459b228c00ef01d91649b3405316729713164 Fixes: QTBUG-77427 Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/cocoa/qnsview_dragging.mm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/cocoa/qnsview_dragging.mm b/src/plugins/platforms/cocoa/qnsview_dragging.mm index 37e972dba9..41b96b2df6 100644 --- a/src/plugins/platforms/cocoa/qnsview_dragging.mm +++ b/src/plugins/platforms/cocoa/qnsview_dragging.mm @@ -270,6 +270,7 @@ static QPoint mapWindowCoordinates(QWindow *source, QWindow *target, QPoint poin // The drag was started from within the application response = QWindowSystemInterface::handleDrop(target, nativeDrag->dragMimeData(), point, qtAllowed, buttons, modifiers); + nativeDrag->setAcceptedAction(response.acceptedAction()); } else { QCocoaDropData mimeData(sender.draggingPasteboard); response = QWindowSystemInterface::handleDrop(target, &mimeData, @@ -282,6 +283,7 @@ static QPoint mapWindowCoordinates(QWindow *source, QWindow *target, QPoint poin { Q_UNUSED(session); Q_UNUSED(screenPoint); + Q_UNUSED(operation); if (!m_platformWindow) return; @@ -290,8 +292,7 @@ static QPoint mapWindowCoordinates(QWindow *source, QWindow *target, QPoint poin if (!target) return; - QCocoaDrag* nativeDrag = QCocoaIntegration::instance()->drag(); - nativeDrag->setAcceptedAction(qt_mac_mapNSDragOperation(operation)); + QCocoaIntegration::instance()->drag(); // Qt starts drag-and-drop on a mouse button press event. Cococa in // this case won't send the matching release event, so we have to -- cgit v1.2.3 From 117175a2f2ecab990f65eefd32b42be22f9aa3ce Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Wed, 11 Sep 2019 17:56:14 +0200 Subject: macOS dark mode: set the link color MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes: QTBUG-71740 Change-Id: I49f49338c7f3a28845de63c2a6bf2dc8495dd108 Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/cocoa/qcocoasystemsettings.mm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/cocoa/qcocoasystemsettings.mm b/src/plugins/platforms/cocoa/qcocoasystemsettings.mm index 9b6dc94d33..cb25bd7d81 100644 --- a/src/plugins/platforms/cocoa/qcocoasystemsettings.mm +++ b/src/plugins/platforms/cocoa/qcocoasystemsettings.mm @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2019 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the plugins of the Qt Toolkit. @@ -52,6 +52,8 @@ @property (class, strong, readonly) NSColor *unemphasizedSelectedTextColor NS_AVAILABLE_MAC(10_14); @property (class, strong, readonly) NSColor *unemphasizedSelectedContentBackgroundColor NS_AVAILABLE_MAC(10_14); @property (class, strong, readonly) NSArray *alternatingContentBackgroundColors NS_AVAILABLE_MAC(10_14); +// Missing from non-Mojave SDKs, even if introduced in 10.10 +@property (class, strong, readonly) NSColor *linkColor NS_AVAILABLE_MAC(10_10); @end #endif @@ -111,6 +113,8 @@ QPalette * qt_mac_createSystemPalette() palette->setBrush(QPalette::ToolTipBase, qt_mac_toQBrush([NSColor controlColor])); + palette->setColor(QPalette::Normal, QPalette::Link, qt_mac_toQColor([NSColor linkColor])); + return palette; } -- cgit v1.2.3 From 6eaa1d07e1e86f1535b8294645f75972dc69184b Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 12 Sep 2019 09:24:29 +0200 Subject: Eliminate the last QList in QtBase production code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QList is horribly inefficient™ (on 32-bit platforms). Fix by using a QVector instead. Change-Id: Id85cb71404f329049c3e9997e51113035569e1b4 Reviewed-by: Friedemann Kleint --- src/plugins/platforms/eglfs/api/qeglfscursor_p.h | 4 +++- .../platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmcursor.h | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/eglfs/api/qeglfscursor_p.h b/src/plugins/platforms/eglfs/api/qeglfscursor_p.h index 89c2e89f58..8768f9dd8c 100644 --- a/src/plugins/platforms/eglfs/api/qeglfscursor_p.h +++ b/src/plugins/platforms/eglfs/api/qeglfscursor_p.h @@ -59,6 +59,8 @@ #include #include +#include + QT_BEGIN_NAMESPACE class QOpenGLShaderProgram; @@ -143,7 +145,7 @@ private: int cursorsPerRow; int width, height; // width and height of the atlas int cursorWidth, cursorHeight; // width and height of cursors inside the atlas - QList hotSpots; + QVector hotSpots; QImage image; // valid until it's uploaded } m_cursorAtlas; diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmcursor.h b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmcursor.h index c96dd585d3..d47b579238 100644 --- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmcursor.h +++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmcursor.h @@ -41,7 +41,7 @@ #define QEGLFSKMSGBMCURSOR_H #include -#include +#include #include #include @@ -110,7 +110,7 @@ private: int cursorsPerRow; int width, height; // width and height of the atlas int cursorWidth, cursorHeight; // width and height of cursors inside the atlas - QList hotSpots; + QVector hotSpots; QImage image; } m_cursorAtlas; }; -- cgit v1.2.3 From 29e40c1f6f630803747ca615f99d2813df57fc52 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 4 Sep 2019 23:49:09 +0200 Subject: QWinRTUiaValueProvider: optimize SetValue() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The code followed a pattern used elsewhere whereby a return value is transmitted out of a task executed on a separate thread by way of shared ownership of the value using QSharedPointer. In the present case, however, the pattern was applied to an argument of the task, not its return value, so remove all the sharing machinery and just copy the argument (a QString) into the task (a lambda). Change-Id: Ib997322ed70201781b6012c7e4f945b124b05868 Reviewed-by: Edward Welbourne Reviewed-by: Mårten Nordheim --- .../platforms/winrt/uiautomation/qwinrtuiavalueprovider.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiavalueprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiavalueprovider.cpp index 21389b74d2..255d8ee49e 100644 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiavalueprovider.cpp +++ b/src/plugins/platforms/winrt/uiautomation/qwinrtuiavalueprovider.cpp @@ -96,24 +96,22 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaValueProvider::SetValue(HSTRING value) qCDebug(lcQpaUiAutomation) << __FUNCTION__; auto accid = id(); - auto tmpValue = QSharedPointer(new QString); - auto ptrValue = new QSharedPointer(tmpValue); - *tmpValue = hStrToQStr(value); + QString tmpValue = hStrToQStr(value); - QEventDispatcherWinRT::runOnMainThread([accid, ptrValue]() { + QEventDispatcherWinRT::runOnMainThread([accid, tmpValue]() { if (QAccessibleInterface *accessible = accessibleForId(accid)) { // First sets the value as a text. - accessible->setText(QAccessible::Value, **ptrValue); + accessible->setText(QAccessible::Value, tmpValue); // Then, if the control supports the value interface (range value) // and the supplied text can be converted to a number, and that number // lies within the min/max limits, sets it as the control's current (numeric) value. if (QAccessibleValueInterface *valueInterface = accessible->valueInterface()) { bool ok = false; - double numval = (*ptrValue)->toDouble(&ok); + double numval = tmpValue.toDouble(&ok); if (ok) { double minimum = valueInterface->minimumValue().toDouble(); double maximum = valueInterface->maximumValue().toDouble(); @@ -124,7 +122,6 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaValueProvider::SetValue(HSTRING value) } } QWinRTUiaMetadataCache::instance()->load(accid); - delete ptrValue; return S_OK; }, 0); -- cgit v1.2.3 From 4534522ff0f189418d828fd29b9d417b5a1b5d27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 13 Sep 2019 18:37:00 +0200 Subject: macOS: Keep default NSWindow background unless window is frameless The logic was changed in ee82f8661 to only draw a window background when the window was textured, and otherwise ask for a clear window background. This has an unfortunate side-effect on macOS 10.15 that the window's title bar will be partially transparent and reflect the content under the window, with a blur effect. It also inadvertently broke the use-case of setting the NSWindow background color explicitly. With this patch we're back to the behavior before ee82f8661, and users who still want to have a non-borderless window with a clear background can still do this by setting the background color to the clear color manually. Task-number: QTBUG-77637 Change-Id: I8a11bc46e6393b29a37f002ea123a987048106b9 Reviewed-by: Timur Pocheptsov --- src/plugins/platforms/cocoa/qnswindow.mm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/cocoa/qnswindow.mm b/src/plugins/platforms/cocoa/qnswindow.mm index 68cb270457..6b4e110af2 100644 --- a/src/plugins/platforms/cocoa/qnswindow.mm +++ b/src/plugins/platforms/cocoa/qnswindow.mm @@ -255,8 +255,8 @@ static bool isMouseEvent(NSEvent *ev) - (NSColor *)backgroundColor { - return self.styleMask & NSWindowStyleMaskTexturedBackground ? - [super backgroundColor] : [NSColor clearColor]; + return self.styleMask == NSWindowStyleMaskBorderless ? + [NSColor clearColor] : [super backgroundColor]; } - (void)sendEvent:(NSEvent*)theEvent -- cgit v1.2.3 From e2431b619da5c53d34df0b46105deb4450ed0c1f Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sun, 15 Sep 2019 19:49:32 +0200 Subject: QPSQL: Fix crash when a prepared statement is deleted after the db was removed When a prepared statement is still alive after the database was removed with QSqlDatabase::removeDatabase(), the cleanup routine is trying to access the driver which is no longer alive which results in a crash. Fix it by checking if the driver is still alive similar to 5f66486cc254e1483f776d3058f96db493fd26e5. Fixes: QTBUG-43889 Change-Id: Ib466a76d014e32c055d203bda15b075ad3dff3d9 Reviewed-by: Andy Shaw Reviewed-by: Jesus Fernandez --- src/plugins/sqldrivers/psql/qsql_psql.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/sqldrivers/psql/qsql_psql.cpp b/src/plugins/sqldrivers/psql/qsql_psql.cpp index 0bae45382d..28be7bdc38 100644 --- a/src/plugins/sqldrivers/psql/qsql_psql.cpp +++ b/src/plugins/sqldrivers/psql/qsql_psql.cpp @@ -428,12 +428,14 @@ static QVariant::Type qDecodePSQLType(int t) void QPSQLResultPrivate::deallocatePreparedStmt() { - const QString stmt = QStringLiteral("DEALLOCATE ") + preparedStmtId; - PGresult *result = drv_d_func()->exec(stmt); + if (drv_d_func()) { + const QString stmt = QStringLiteral("DEALLOCATE ") + preparedStmtId; + PGresult *result = drv_d_func()->exec(stmt); - if (PQresultStatus(result) != PGRES_COMMAND_OK) - qWarning("Unable to free statement: %s", PQerrorMessage(drv_d_func()->connection)); - PQclear(result); + if (PQresultStatus(result) != PGRES_COMMAND_OK) + qWarning("Unable to free statement: %s", PQerrorMessage(drv_d_func()->connection)); + PQclear(result); + } preparedStmtId.clear(); } -- cgit v1.2.3 From 72522517688d68a25a543a1da2497a4b8f6b424b Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 12 Sep 2019 09:43:21 +0200 Subject: Brush up the Windows styles - use range-based for loops where possible - use nullptr - use member initialization - remove a lot of C-style casts - use override - fix some signedness warnings - add some missing break statements Task-number: QTBUG-76493 Change-Id: Ica6ed65ec29e958406e54d816b8a679ed81bd177 Reviewed-by: Oliver Wolff --- src/plugins/styles/windowsvista/main.cpp | 4 +- .../styles/windowsvista/qwindowsvistastyle.cpp | 110 +++++++------- .../styles/windowsvista/qwindowsvistastyle_p_p.h | 2 +- .../styles/windowsvista/qwindowsxpstyle.cpp | 158 ++++++++++----------- .../styles/windowsvista/qwindowsxpstyle_p_p.h | 61 ++++---- 5 files changed, 165 insertions(+), 170 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/styles/windowsvista/main.cpp b/src/plugins/styles/windowsvista/main.cpp index d5048e45b7..5e7bcf5e6e 100644 --- a/src/plugins/styles/windowsvista/main.cpp +++ b/src/plugins/styles/windowsvista/main.cpp @@ -48,7 +48,7 @@ class QWindowsVistaStylePlugin : public QStylePlugin Q_OBJECT Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QStyleFactoryInterface" FILE "windowsvistastyle.json") public: - QStyle *create(const QString &key); + QStyle *create(const QString &key) override; }; QStyle *QWindowsVistaStylePlugin::create(const QString &key) @@ -56,7 +56,7 @@ QStyle *QWindowsVistaStylePlugin::create(const QString &key) if (key.compare(QLatin1String("windowsvista"), Qt::CaseInsensitive) == 0) return new QWindowsVistaStyle(); - return 0; + return nullptr; } QT_END_NAMESPACE diff --git a/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp b/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp index feb2bc824b..e213d65946 100644 --- a/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp +++ b/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp @@ -44,7 +44,6 @@ #include #include #include -#include #include QT_BEGIN_NAMESPACE @@ -91,7 +90,7 @@ bool QWindowsVistaStylePrivate::useVista() Checks and returns the style object */ inline QObject *styleObject(const QStyleOption *option) { - return option ? option->styleObject : 0; + return option ? option->styleObject : nullptr; } /* \internal @@ -116,7 +115,7 @@ static inline QImage createAnimationBuffer(const QStyleOption *option, const QWi Used by animations to clone a styleoption and shift its offset */ QStyleOption *clonedAnimationStyleOption(const QStyleOption*option) { - QStyleOption *styleOption = 0; + QStyleOption *styleOption = nullptr; if (const QStyleOptionSlider *slider = qstyleoption_cast(option)) styleOption = new QStyleOptionSlider(*slider); else if (const QStyleOptionSpinBox *spinbox = qstyleoption_cast(option)) @@ -297,7 +296,7 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt int oldState = styleObject->property("_q_stylestate").toInt(); oldRect = styleObject->property("_q_stylerect").toRect(); newRect = option->rect; - styleObject->setProperty("_q_stylestate", (int)option->state); + styleObject->setProperty("_q_stylestate", int(option->state)); styleObject->setProperty("_q_stylerect", option->rect); bool doTransition = oldState && @@ -315,7 +314,7 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt if (doTransition) { QStyleOption *styleOption = clonedAnimationStyleOption(option); - styleOption->state = (QStyle::State)oldState; + styleOption->state = QStyle::State(oldState); QWindowsVistaAnimation *anim = qobject_cast(d->animation(styleObject)); QWindowsVistaTransition *t = new QWindowsVistaTransition(styleObject); @@ -340,7 +339,7 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt // The end state of the transition is simply the result we would have painted // if the style was not animated. - styleOption->styleObject = 0; + styleOption->styleObject = nullptr; styleOption->state = option->state; proxy()->drawPrimitive(element, styleOption, &endPainter, widget); @@ -355,7 +354,7 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt //translate state flags to UXTHEME states : if (element == PE_FrameLineEdit) { - theme = OpenThemeData(0, L"Edit"); + theme = OpenThemeData(nullptr, L"Edit"); partId = EP_EDITBORDER_NOSCROLL; if (oldState & State_MouseOver) @@ -373,7 +372,7 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt toState = ETS_NORMAL; } else { - theme = OpenThemeData(0, L"Button"); + theme = OpenThemeData(nullptr, L"Button"); if (element == PE_IndicatorRadioButton) partId = BP_RADIOBUTTON; else if (element == PE_IndicatorCheckBox) @@ -389,7 +388,7 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt if (theme && SUCCEEDED(GetThemeTransitionDuration(theme, partId, fromState, toState, TMT_TRANSITIONDURATIONS, &duration))) { - t->setDuration(duration); + t->setDuration(int(duration)); } t->setStartTime(QTime::currentTime()); @@ -534,7 +533,7 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt else if (state & State_MouseOver) stateId = EBS_HOT; - XPThemeData theme(0, painter, QWindowsXPStylePrivate::EditTheme, + XPThemeData theme(nullptr, painter, QWindowsXPStylePrivate::EditTheme, partId, stateId, rect); if (!theme.isValid()) { QWindowsStyle::drawPrimitive(element, option, painter, widget); @@ -581,27 +580,26 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt p->drawRect(option->rect.adjusted(0, 0, -1, -1)); p->setPen(oldPen); return; - } else { - int stateId = ETS_NORMAL; - if (!(state & State_Enabled)) - stateId = ETS_DISABLED; - else if (state & State_ReadOnly) - stateId = ETS_READONLY; - else if (state & State_MouseOver) - stateId = ETS_HOT; - else if (state & State_HasFocus) - stateId = ETS_SELECTED; - XPThemeData theme(widget, painter, - QWindowsXPStylePrivate::EditTheme, - EP_EDITBORDER_NOSCROLL, stateId, option->rect); - theme.noContent = true; - painter->save(); - QRegion clipRegion = option->rect; - clipRegion -= option->rect.adjusted(2, 2, -2, -2); - painter->setClipRegion(clipRegion); - d->drawBackground(theme); - painter->restore(); } + int stateId = ETS_NORMAL; + if (!(state & State_Enabled)) + stateId = ETS_DISABLED; + else if (state & State_ReadOnly) + stateId = ETS_READONLY; + else if (state & State_MouseOver) + stateId = ETS_HOT; + else if (state & State_HasFocus) + stateId = ETS_SELECTED; + XPThemeData theme(widget, painter, + QWindowsXPStylePrivate::EditTheme, + EP_EDITBORDER_NOSCROLL, stateId, option->rect); + theme.noContent = true; + painter->save(); + QRegion clipRegion = option->rect; + clipRegion -= option->rect.adjusted(2, 2, -2, -2); + painter->setClipRegion(clipRegion); + d->drawBackground(theme); + painter->restore(); } break; @@ -724,7 +722,7 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt d->drawBackground(theme); } else { QWindowsXPStyle::drawPrimitive(PE_PanelItemViewItem, option, painter, widget); - break;; + break; } QPixmapCache::insert(key, pixmap); } @@ -770,7 +768,7 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt case PE_Widget: { #if QT_CONFIG(dialogbuttonbox) - const QDialogButtonBox *buttonBox = 0; + const QDialogButtonBox *buttonBox = nullptr; if (qobject_cast (widget)) buttonBox = widget->findChild(QLatin1String("qt_msgbox_buttonbox")); @@ -844,7 +842,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption int oldState = styleObject->property("_q_stylestate").toInt(); oldRect = styleObject->property("_q_stylerect").toRect(); newRect = option->rect; - styleObject->setProperty("_q_stylestate", (int)option->state); + styleObject->setProperty("_q_stylestate", int(option->state)); styleObject->setProperty("_q_stylerect", option->rect); bool wasDefault = false; @@ -870,7 +868,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption QWindowsVistaTransition *t = new QWindowsVistaTransition(styleObject); QWindowsVistaAnimation *anim = qobject_cast(d->animation(styleObject)); QStyleOption *styleOption = clonedAnimationStyleOption(option); - styleOption->state = (QStyle::State)oldState; + styleOption->state = QStyle::State(oldState); QImage startImage = createAnimationBuffer(option, widget); QPainter startPainter(&startImage); @@ -892,12 +890,12 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption DWORD duration = 0; - const HTHEME theme = OpenThemeData(0, L"Button"); + const HTHEME theme = OpenThemeData(nullptr, L"Button"); int fromState = buttonStateId(oldState, BP_PUSHBUTTON); int toState = buttonStateId(option->state, BP_PUSHBUTTON); if (GetThemeTransitionDuration(theme, BP_PUSHBUTTON, fromState, toState, TMT_TRANSITIONDURATIONS, &duration) == S_OK) - t->setDuration(duration); + t->setDuration(int(duration)); else t->setDuration(0); t->setStartTime(QTime::currentTime()); @@ -983,7 +981,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption if (btn->features & QStyleOptionButton::HasMenu) { int mbiw = 0, mbih = 0; - XPThemeData theme(widget, 0, QWindowsXPStylePrivate::ToolBarTheme, + XPThemeData theme(widget, nullptr, QWindowsXPStylePrivate::ToolBarTheme, TP_DROPDOWNBUTTON); if (theme.isValid()) { const QSizeF size = theme.size() * QStyleHelper::dpiScaled(1, option); @@ -992,7 +990,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption mbih = qRound(size.height()); } } - QRect ir = subElementRect(SE_PushButtonContents, option, 0); + QRect ir = subElementRect(SE_PushButtonContents, option, nullptr); QStyleOptionButton newBtn = *btn; newBtn.rect = QStyle::visualRect(option->direction, option->rect, QRect(ir.right() - mbiw - 2, @@ -1137,7 +1135,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption QPalette::ColorRole textRole = disabled ? QPalette::Text : QPalette::ButtonText; QPixmap pix = mbi->icon.pixmap(proxy()->pixelMetric(PM_SmallIconSize, option, widget), QIcon::Normal); - uint alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine; + int alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine; if (!proxy()->styleHint(SH_UnderlineShortcut, mbi, widget)) alignment |= Qt::TextHideMnemonic; @@ -1177,7 +1175,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption int checkcol = qRound(qreal(25) * factor); const int gutterWidth = qRound(qreal(3) * factor); { - XPThemeData theme(widget, 0, QWindowsXPStylePrivate::MenuTheme, + XPThemeData theme(widget, nullptr, QWindowsXPStylePrivate::MenuTheme, MENU_POPUPCHECKBACKGROUND, MBI_HOT); XPThemeData themeSize = theme; themeSize.partId = MENU_POPUPCHECK; @@ -1394,7 +1392,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption int mw = proxy()->pixelMetric(QStyle::PM_DockWidgetTitleMargin, dwOpt, widget); int fw = proxy()->pixelMetric(PM_DockWidgetFrameWidth, dwOpt, widget); const QDockWidget *dw = qobject_cast(widget); - bool isFloating = dw != 0 && dw->isFloating(); + bool isFloating = dw && dw->isFloating(); QRect r = option->rect.adjusted(0, 2, -1, -3); QRect titleRect = r; @@ -1411,7 +1409,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption if (isFloating) { titleRect.adjust(0, -fw, 0, 0); - if (widget != 0 && widget->windowIcon().cacheKey() != QApplication::windowIcon().cacheKey()) + if (widget && widget->windowIcon().cacheKey() != QApplication::windowIcon().cacheKey()) titleRect.adjust(titleRect.height() + mw, 0, 0, 0); } else { titleRect.adjust(mw, 0, 0, 0); @@ -1517,8 +1515,8 @@ void QWindowsVistaStyle::drawComplexControl(ComplexControl control, const QStyle int oldActiveControls = styleObject->property("_q_stylecontrols").toInt(); QRect oldRect = styleObject->property("_q_stylerect").toRect(); - styleObject->setProperty("_q_stylestate", (int)option->state); - styleObject->setProperty("_q_stylecontrols", (int)option->activeSubControls); + styleObject->setProperty("_q_stylestate", int(option->state)); + styleObject->setProperty("_q_stylecontrols", int(option->activeSubControls)); styleObject->setProperty("_q_stylerect", option->rect); bool doTransition = ((state & State_Sunken) != (oldState & State_Sunken) || @@ -1562,8 +1560,8 @@ void QWindowsVistaStyle::drawComplexControl(ComplexControl control, const QStyle // Draw transition source if (!anim) { - styleOption->state = (QStyle::State)oldState; - styleOption->activeSubControls = (QStyle::SubControl)oldActiveControls; + styleOption->state = QStyle::State(oldState); + styleOption->activeSubControls = QStyle::SubControl(oldActiveControls); proxy()->drawComplexControl(control, styleOption, &startPainter, widget); } else { anim->paint(&startPainter, option); @@ -1814,7 +1812,7 @@ void QWindowsVistaStyle::drawComplexControl(ComplexControl control, const QStyle // That however breaks with QtQuickControls where this results in transparent // spinbox background, so if there's no "widget" passed (QtQuickControls case), // let ftheme.noContent be false, which fixes the spinbox rendering in QQC - ftheme.noContent = (widget != NULL); + ftheme.noContent = (widget != nullptr); d->drawBackground(ftheme); } if (sub & SC_SpinBoxUp) { @@ -1871,7 +1869,7 @@ QSize QWindowsVistaStyle::sizeFromContents(ContentsType type, const QStyleOption sz = QWindowsXPStyle::sizeFromContents(type, option, size, widget); int minimumHeight; { - XPThemeData theme(widget, 0, + XPThemeData theme(widget, nullptr, QWindowsXPStylePrivate::MenuTheme, MENU_POPUPCHECKBACKGROUND, MBI_HOT); XPThemeData themeSize = theme; @@ -1939,7 +1937,7 @@ QRect QWindowsVistaStyle::subElementRect(SubElement element, const QStyleOption case SE_PushButtonContents: if (const QStyleOptionButton *btn = qstyleoption_cast(option)) { MARGINS borderSize; - const HTHEME theme = OpenThemeData(widget ? QWindowsVistaStylePrivate::winId(widget) : 0, L"Button"); + const HTHEME theme = OpenThemeData(widget ? QWindowsVistaStylePrivate::winId(widget) : nullptr, L"Button"); if (theme) { int stateId = PBS_NORMAL; if (!(option->state & State_Enabled)) @@ -1954,7 +1952,7 @@ QRect QWindowsVistaStyle::subElementRect(SubElement element, const QStyleOption int border = proxy()->pixelMetric(PM_DefaultFrameWidth, btn, widget); rect = option->rect.adjusted(border, border, -border, -border); - if (SUCCEEDED(GetThemeMargins(theme, NULL, BP_PUSHBUTTON, stateId, TMT_CONTENTMARGINS, NULL, &borderSize))) { + if (SUCCEEDED(GetThemeMargins(theme, nullptr, BP_PUSHBUTTON, stateId, TMT_CONTENTMARGINS, nullptr, &borderSize))) { rect.adjust(borderSize.cxLeftWidth, borderSize.cyTopHeight, -borderSize.cxRightWidth, -borderSize.cyBottomHeight); rect = visualRect(option->direction, option->rect, rect); @@ -1972,7 +1970,7 @@ QRect QWindowsVistaStyle::subElementRect(SubElement element, const QStyleOption int y = option->rect.y(); int margin = proxy()->pixelMetric(QStyle::PM_HeaderMargin, option, widget); - XPThemeData theme(widget, 0, + XPThemeData theme(widget, nullptr, QWindowsXPStylePrivate::HeaderTheme, HP_HEADERSORTARROW, HSAS_SORTEDDOWN, option->rect); @@ -2045,7 +2043,7 @@ static bool buttonVisible(const QStyle::SubControl sc, const QStyleOptionTitleBa bool isMinimized = tb->titleBarState & Qt::WindowMinimized; bool isMaximized = tb->titleBarState & Qt::WindowMaximized; - const uint flags = tb->titleBarFlags; + const auto flags = tb->titleBarFlags; bool retVal = false; switch (sc) { case QStyle::SC_TitleBarContextHelpButton: @@ -2103,7 +2101,7 @@ int QWindowsVistaStyle::styleHint(StyleHint hint, const QStyleOption *option, co if (option) { if (QStyleHintReturnMask *mask = qstyleoption_cast(returnData)) { ret = true; - XPThemeData themeData(widget, 0, + XPThemeData themeData(widget, nullptr, QWindowsXPStylePrivate::ToolTipTheme, TTP_STANDARD, TTSS_NORMAL, option->rect); mask->region = d->region(themeData); @@ -2112,7 +2110,7 @@ int QWindowsVistaStyle::styleHint(StyleHint hint, const QStyleOption *option, co break; case SH_Table_GridLineColor: if (option) - ret = option->palette.color(QPalette::Base).darker(118).rgb(); + ret = int(option->palette.color(QPalette::Base).darker(118).rgb()); else ret = -1; break; @@ -2323,7 +2321,7 @@ void QWindowsVistaStyle::polish(QWidget *widget) //we do not have to care about unpolishing widget->setContentsMargins(3, 0, 4, 0); COLORREF bgRef; - HTHEME theme = OpenThemeData(widget ? QWindowsVistaStylePrivate::winId(widget) : 0, L"TOOLTIP"); + HTHEME theme = OpenThemeData(widget ? QWindowsVistaStylePrivate::winId(widget) : nullptr, L"TOOLTIP"); if (theme && SUCCEEDED(GetThemeColor(theme, TTP_STANDARD, TTSS_NORMAL, TMT_TEXTCOLOR, &bgRef))) { QColor textColor = QColor::fromRgb(bgRef); QPalette pal; @@ -2463,7 +2461,7 @@ QIcon QWindowsVistaStyle::standardIcon(StandardPixmap standardIcon, switch(standardIcon) { case SP_CommandLink: { - XPThemeData theme(0, 0, + XPThemeData theme(nullptr, nullptr, QWindowsXPStylePrivate::ButtonTheme, BP_COMMANDLINKGLYPH, CMDLGS_NORMAL); if (theme.isValid()) { diff --git a/src/plugins/styles/windowsvista/qwindowsvistastyle_p_p.h b/src/plugins/styles/windowsvista/qwindowsvistastyle_p_p.h index d66b17e9f8..8fef9f9927 100644 --- a/src/plugins/styles/windowsvista/qwindowsvistastyle_p_p.h +++ b/src/plugins/styles/windowsvista/qwindowsvistastyle_p_p.h @@ -162,7 +162,7 @@ class QWindowsVistaAnimation : public QBlendStyleAnimation public: QWindowsVistaAnimation(Type type, QObject *target) : QBlendStyleAnimation(type, target) { } - virtual bool isUpdateNeeded() const; + bool isUpdateNeeded() const override; void paint(QPainter *painter, const QStyleOption *option); }; diff --git a/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp b/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp index e2c5bdc924..bf80138b32 100644 --- a/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp +++ b/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp @@ -117,7 +117,7 @@ static inline QBackingStore *backingStoreForWidget(const QWidget *widget) if (const QWidget *topLevel = widget->nativeParentWidget()) if (QBackingStore *topLevelBackingStore = topLevel->backingStore()) return topLevelBackingStore; - return 0; + return nullptr; } static inline HDC hdcForWidgetBackingStore(const QWidget *widget) @@ -127,7 +127,7 @@ static inline HDC hdcForWidgetBackingStore(const QWidget *widget) if (nativeInterface) return static_cast(nativeInterface->nativeResourceForBackingStore(QByteArrayLiteral("getDC"), backingStore)); } - return 0; + return nullptr; } // Theme data helper ------------------------------------------------------------------------------ @@ -148,7 +148,7 @@ bool XPThemeData::isValid() HTHEME XPThemeData::handle() { if (!QWindowsXPStylePrivate::useXP()) - return 0; + return nullptr; if (!htheme) htheme = QWindowsXPStylePrivate::createTheme(theme, QWindowsXPStylePrivate::winId(widget)); @@ -175,10 +175,10 @@ RECT XPThemeData::toRECT(const QRect &qr) HRGN XPThemeData::mask(QWidget *widget) { if (!IsThemeBackgroundPartiallyTransparent(handle(), partId, stateId)) - return 0; + return nullptr; HRGN hrgn; - HDC dc = 0; + HDC dc = nullptr; if (widget) dc = hdcForWidgetBackingStore(widget); RECT nativeRect = toRECT(rect); @@ -188,7 +188,7 @@ HRGN XPThemeData::mask(QWidget *widget) // QWindowsXPStylePrivate ------------------------------------------------------------------------- // Static initializations -HWND QWindowsXPStylePrivate::m_vistaTreeViewHelper = 0; +HWND QWindowsXPStylePrivate::m_vistaTreeViewHelper = nullptr; HTHEME QWindowsXPStylePrivate::m_themes[NThemes]; bool QWindowsXPStylePrivate::use_xp = false; QBasicAtomicInt QWindowsXPStylePrivate::ref = Q_BASIC_ATOMIC_INITIALIZER(-1); // -1 based refcounting @@ -227,7 +227,7 @@ bool QWindowsXPStylePrivate::useXP(bool update) { if (!update) return use_xp; - return use_xp = IsThemeActive() && (IsAppThemed() || !QApplication::instance()); + return use_xp = IsThemeActive() && (IsAppThemed() || !QCoreApplication::instance()); } /* \internal @@ -241,7 +241,7 @@ void QWindowsXPStylePrivate::init(bool force) ref.ref(); useXP(true); - std::fill(m_themes, m_themes + NThemes, HTHEME(0)); + std::fill(m_themes, m_themes + NThemes, nullptr); } /* \internal @@ -253,12 +253,12 @@ void QWindowsXPStylePrivate::cleanup(bool force) if (bufferDC && nullBitmap) SelectObject(bufferDC, nullBitmap); DeleteObject(bufferBitmap); - bufferBitmap = 0; + bufferBitmap = nullptr; } if(bufferDC) DeleteDC(bufferDC); - bufferDC = 0; + bufferDC = nullptr; if (ref.deref() && !force) return; @@ -282,7 +282,7 @@ void QWindowsXPStylePrivate::cleanup(bool force) static inline HWND createTreeViewHelperWindow() { if (QPlatformNativeInterface *ni = QGuiApplication::platformNativeInterface()) { - void *hwnd = 0; + void *hwnd = nullptr; void *wndProc = reinterpret_cast(DefWindowProc); if (QMetaObject::invokeMethod(ni, "createMessageWindow", Qt::DirectConnection, Q_RETURN_ARG(void*, hwnd), @@ -292,7 +292,7 @@ static inline HWND createTreeViewHelperWindow() return reinterpret_cast(hwnd); } } - return 0; + return nullptr; } bool QWindowsXPStylePrivate::initVistaTreeViewTheming() @@ -305,7 +305,7 @@ bool QWindowsXPStylePrivate::initVistaTreeViewTheming() qWarning("Unable to create the treeview helper window."); return false; } - if (FAILED(SetWindowTheme(m_vistaTreeViewHelper, L"explorer", NULL))) { + if (FAILED(SetWindowTheme(m_vistaTreeViewHelper, L"explorer", nullptr))) { qErrnoWarning("SetWindowTheme() failed."); cleanupVistaTreeViewTheming(); return false; @@ -317,7 +317,7 @@ void QWindowsXPStylePrivate::cleanupVistaTreeViewTheming() { if (m_vistaTreeViewHelper) { DestroyWindow(m_vistaTreeViewHelper); - m_vistaTreeViewHelper = 0; + m_vistaTreeViewHelper = nullptr; } } @@ -328,11 +328,12 @@ void QWindowsXPStylePrivate::cleanupVistaTreeViewTheming() */ void QWindowsXPStylePrivate::cleanupHandleMap() { - for (int i = 0; i < NThemes; ++i) - if (m_themes[i]) { - CloseThemeData(m_themes[i]); - m_themes[i] = 0; + for (auto &theme : m_themes) { + if (theme) { + CloseThemeData(theme); + theme = nullptr; } + } QWindowsXPStylePrivate::cleanupVistaTreeViewTheming(); } @@ -340,7 +341,7 @@ HTHEME QWindowsXPStylePrivate::createTheme(int theme, HWND hwnd) { if (Q_UNLIKELY(theme < 0 || theme >= NThemes || !hwnd)) { qWarning("Invalid parameters #%d, %p", theme, hwnd); - return 0; + return nullptr; } if (!m_themes[theme]) { const wchar_t *name = themeNames[theme]; @@ -427,16 +428,16 @@ HBITMAP QWindowsXPStylePrivate::buffer(int w, int h) if (bufferDC && nullBitmap) SelectObject(bufferDC, nullBitmap); DeleteObject(bufferBitmap); - bufferBitmap = 0; + bufferBitmap = nullptr; } w = qMax(bufferW, w); h = qMax(bufferH, h); if (!bufferDC) { - HDC displayDC = GetDC(0); + HDC displayDC = GetDC(nullptr); bufferDC = CreateCompatibleDC(displayDC); - ReleaseDC(0, displayDC); + ReleaseDC(nullptr, displayDC); } // Define the header @@ -450,22 +451,22 @@ HBITMAP QWindowsXPStylePrivate::buffer(int w, int h) bmi.bmiHeader.biCompression = BI_RGB; // Create the pixmap - bufferPixels = 0; - bufferBitmap = CreateDIBSection(bufferDC, &bmi, DIB_RGB_COLORS, (void **) &bufferPixels, 0, 0); + bufferPixels = nullptr; + bufferBitmap = CreateDIBSection(bufferDC, &bmi, DIB_RGB_COLORS, reinterpret_cast(&bufferPixels), nullptr, 0); GdiFlush(); - nullBitmap = (HBITMAP)SelectObject(bufferDC, bufferBitmap); + nullBitmap = static_cast(SelectObject(bufferDC, bufferBitmap)); if (Q_UNLIKELY(!bufferBitmap)) { qErrnoWarning("QWindowsXPStylePrivate::buffer(%dx%d), CreateDIBSection() failed.", w, h); bufferW = 0; bufferH = 0; - return 0; + return nullptr; } if (Q_UNLIKELY(!bufferPixels)) { qErrnoWarning("QWindowsXPStylePrivate::buffer(%dx%d), CreateDIBSection() did not allocate pixel data.", w, h); bufferW = 0; bufferH = 0; - return 0; + return nullptr; } bufferW = w; bufferH = h; @@ -493,7 +494,7 @@ bool QWindowsXPStylePrivate::isTransparent(XPThemeData &themeData) */ QRegion QWindowsXPStylePrivate::region(XPThemeData &themeData) { - HRGN hRgn = 0; + HRGN hRgn = nullptr; const qreal factor = QWindowsStylePrivate::nativeMetricScaleFactor(themeData.widget); RECT rect = themeData.toRECT(QRect(themeData.rect.topLeft() / factor, themeData.rect.size() / factor)); if (!SUCCEEDED(GetThemeBackgroundRegion(themeData.handle(), bufferHDC(), themeData.partId, @@ -502,12 +503,12 @@ QRegion QWindowsXPStylePrivate::region(XPThemeData &themeData) } HRGN dest = CreateRectRgn(0, 0, 0, 0); - const bool success = CombineRgn(dest, hRgn, 0, RGN_COPY) != ERROR; + const bool success = CombineRgn(dest, hRgn, nullptr, RGN_COPY) != ERROR; QRegion region; if (success) { - int numBytes = GetRegionData(dest, 0, 0); + const auto numBytes = GetRegionData(dest, 0, nullptr); if (numBytes == 0) return QRegion(); @@ -551,7 +552,7 @@ bool QWindowsXPStylePrivate::hasAlphaChannel(const QRect &rect) int firstAlpha = -1; for (int y = startY; y < h/2; ++y) { - DWORD *buffer = (DWORD*)bufferPixels + (y * bufferW); + auto buffer = reinterpret_cast(bufferPixels) + (y * bufferW); for (int x = startX; x < w; ++x, ++buffer) { int alpha = (*buffer) >> 24; if (firstAlpha == -1) @@ -580,7 +581,7 @@ bool QWindowsXPStylePrivate::fixAlphaChannel(const QRect &rect) bool hasFixedAlphaValue = false; for (int y = startY; y < h; ++y) { - DWORD *buffer = (DWORD*)bufferPixels + (y * bufferW); + auto buffer = reinterpret_cast(bufferPixels) + (y * bufferW); for (int x = startX; x < w; ++x, ++buffer) { uint pixel = *buffer; int alpha = qAlpha(pixel); @@ -612,7 +613,7 @@ bool QWindowsXPStylePrivate::swapAlphaChannel(const QRect &rect, bool allPixels) // Flip the alphas, so that 255-alpha pixels are 0, and 0-alpha are 255. for (int y = startY; y < h; ++y) { - DWORD *buffer = (DWORD*)bufferPixels + (y * bufferW); + auto buffer = reinterpret_cast(bufferPixels) + (y * bufferW); for (int x = startX; x < w; ++x, ++buffer) { if (allPixels) { *buffer |= 0xFF000000; @@ -668,7 +669,7 @@ bool QWindowsXPStylePrivate::drawBackground(XPThemeData &themeData) return true; QPainter *painter = themeData.painter; - Q_ASSERT_X(painter != 0, "QWindowsXPStylePrivate::drawBackground()", "Trying to draw a theme part without a painter"); + Q_ASSERT_X(painter != nullptr, "QWindowsXPStylePrivate::drawBackground()", "Trying to draw a theme part without a painter"); if (!painter || !painter->isActive()) return false; @@ -706,7 +707,7 @@ bool QWindowsXPStylePrivate::drawBackground(XPThemeData &themeData) } } - const HDC dc = canDrawDirectly ? hdcForWidgetBackingStore(themeData.widget) : HDC(0); + const HDC dc = canDrawDirectly ? hdcForWidgetBackingStore(themeData.widget) : nullptr; const bool result = dc ? drawBackgroundDirectly(dc, themeData, aditionalDevicePixelRatio) : drawBackgroundThruNativeBuffer(themeData, aditionalDevicePixelRatio); @@ -740,7 +741,7 @@ bool QWindowsXPStylePrivate::drawBackgroundDirectly(HDC dc, XPThemeData &themeDa { QPainter *painter = themeData.painter; - const auto deviceTransform = painter->deviceTransform(); + const auto &deviceTransform = painter->deviceTransform(); const QPointF redirectionDelta(deviceTransform.dx(), deviceTransform.dy()); const QRect area = scaleRect(QRectF(themeData.rect), additionalDevicePixelRatio).translated(redirectionDelta).toRect(); @@ -771,7 +772,7 @@ bool QWindowsXPStylePrivate::drawBackgroundDirectly(HDC dc, XPThemeData &themeDa | (themeData.mirrorHorizontally ? DTBG_MIRRORDC : 0); const HRESULT result = DrawThemeBackgroundEx(themeData.handle(), dc, themeData.partId, themeData.stateId, &(drawRECT), &drawOptions); - SelectClipRgn(dc, 0); + SelectClipRgn(dc, nullptr); DeleteObject(hrgn); return SUCCEEDED(result); } @@ -1099,9 +1100,7 @@ QWindowsXPStyle::QWindowsXPStyle() /*! Destroys the style. */ -QWindowsXPStyle::~QWindowsXPStyle() -{ -} +QWindowsXPStyle::~QWindowsXPStyle() = default; /*! \reimp */ void QWindowsXPStyle::unpolish(QApplication *app) @@ -1157,7 +1156,7 @@ void QWindowsXPStyle::polish(QWidget *widget) if (!d->hasInitColors) { // Get text color for group box labels COLORREF cref; - XPThemeData theme(widget, 0, QWindowsXPStylePrivate::ButtonTheme, 0, 0); + XPThemeData theme(widget, nullptr, QWindowsXPStylePrivate::ButtonTheme, 0, 0); GetThemeColor(theme.handle(), BP_GROUPBOX, GBS_NORMAL, TMT_TEXTCOLOR, &cref); d->groupBoxTextColor = qRgb(GetRValue(cref), GetGValue(cref), GetBValue(cref)); GetThemeColor(theme.handle(), BP_GROUPBOX, GBS_DISABLED, TMT_TEXTCOLOR, &cref); @@ -1270,7 +1269,7 @@ QRect QWindowsXPStyle::subElementRect(SubElement sr, const QStyleOption *option, if (const QStyleOptionButton *btn = qstyleoption_cast(option)) { MARGINS borderSize; if (widget) { - XPThemeData buttontheme(widget, 0, QWindowsXPStylePrivate::ButtonTheme); + XPThemeData buttontheme(widget, nullptr, QWindowsXPStylePrivate::ButtonTheme); HTHEME theme = buttontheme.handle(); if (theme) { int stateId; @@ -1288,7 +1287,7 @@ QRect QWindowsXPStyle::subElementRect(SubElement sr, const QStyleOption *option, int border = proxy()->pixelMetric(PM_DefaultFrameWidth, btn, widget); rect = option->rect.adjusted(border, border, -border, -border); - if (SUCCEEDED(GetThemeMargins(theme, NULL, BP_PUSHBUTTON, stateId, TMT_CONTENTMARGINS, NULL, &borderSize))) { + if (SUCCEEDED(GetThemeMargins(theme, nullptr, BP_PUSHBUTTON, stateId, TMT_CONTENTMARGINS, nullptr, &borderSize))) { rect.adjust(borderSize.cxLeftWidth, borderSize.cyTopHeight, -borderSize.cxRightWidth, -borderSize.cyBottomHeight); rect = visualRect(option->direction, option->rect, rect); @@ -1468,7 +1467,7 @@ case PE_Frame: return; themeNumber = QWindowsXPStylePrivate::ListViewTheme; partId = LVP_LISTGROUP; - XPThemeData theme(widget, 0, themeNumber, partId, 0); + XPThemeData theme(widget, nullptr, themeNumber, partId); if (!(flags & State_Enabled)) stateId = ETS_DISABLED; @@ -1496,9 +1495,9 @@ case PE_Frame: p->drawRect(QRectF(option->rect).adjusted(0, 0, -topLevelAdjustment, -topLevelAdjustment)); p->setPen(oldPen); return; - } else if (fillType == BT_NONE) { - return; } + if (fillType == BT_NONE) + return; } break; } @@ -1514,7 +1513,8 @@ case PE_Frame: p->drawRect(option->rect.adjusted(0, 0, -1, -1)); p->setPen(oldPen); return; - } else if (qstyleoption_cast(option)) { + } + if (qstyleoption_cast(option)) { themeNumber = QWindowsXPStylePrivate::EditTheme; partId = EP_EDITTEXT; noContent = true; @@ -1538,7 +1538,7 @@ case PE_Frame: if (QWindowsXPStylePrivate::isLineEditBaseColorSet(option, widget)) { p->fillRect(panel->rect, panel->palette.brush(QPalette::Base)); } else { - XPThemeData theme(0, p, themeNumber, partId, stateId, rect); + XPThemeData theme(nullptr, p, themeNumber, partId, stateId, rect); if (!theme.isValid()) { QWindowsStyle::drawPrimitive(pe, option, p, widget); return; @@ -1587,9 +1587,9 @@ case PE_Frame: wchar_t themeFileName[maxlength]; wchar_t themeColor[maxlength]; // Due to a a scaling issue with the XP Silver theme, tab gradients are not used with it - if (GetCurrentThemeName(themeFileName, maxlength, themeColor, maxlength, NULL, 0) == S_OK) { - wchar_t *offset = 0; - if ((offset = wcsrchr(themeFileName, QChar(QLatin1Char('\\')).unicode())) != NULL) { + if (GetCurrentThemeName(themeFileName, maxlength, themeColor, maxlength, nullptr, 0) == S_OK) { + wchar_t *offset = nullptr; + if ((offset = wcsrchr(themeFileName, QChar(QLatin1Char('\\')).unicode())) != nullptr) { offset++; if (!lstrcmp(offset, L"Luna.msstyles") && !lstrcmp(offset, L"Metallic")) { useGradient = false; @@ -1820,7 +1820,7 @@ case PE_Frame: bef_v -= delta; aft_h += delta; aft_v += delta; - XPThemeData theme(0, p, QWindowsXPStylePrivate::XpTreeViewTheme); + XPThemeData theme(nullptr, p, QWindowsXPStylePrivate::XpTreeViewTheme); theme.rect = QRect(bef_h, bef_v, decoration_size, decoration_size); theme.partId = TVP_GLYPH; theme.stateId = flags & QStyle::State_Open ? GLPS_OPENED : GLPS_CLOSED; @@ -1912,7 +1912,7 @@ void QWindowsXPStyle::drawControl(ControlElement element, const QStyleOption *op { themeNumber = QWindowsXPStylePrivate::StatusTheme; partId = SP_GRIPPER; - XPThemeData theme(0, p, themeNumber, partId, 0); + XPThemeData theme(nullptr, p, themeNumber, partId); QSize size = (theme.size() * QWindowsStylePrivate::nativeMetricScaleFactor(widget)).toSize(); size.rheight()--; if (const QStyleOptionSizeGrip *sg = qstyleoption_cast(option)) { @@ -1980,7 +1980,7 @@ void QWindowsXPStyle::drawControl(ControlElement element, const QStyleOption *op if (btn->features & QStyleOptionButton::HasMenu) { int mbiw = 0, mbih = 0; - XPThemeData theme(widget, 0, + XPThemeData theme(widget, nullptr, QWindowsXPStylePrivate::ToolBarTheme, TP_SPLITBUTTONDROPDOWN); if (theme.isValid()) { @@ -2309,7 +2309,7 @@ void QWindowsXPStyle::drawControl(ControlElement element, const QStyleOption *op if (isFloating) { titleRect.adjust(0, -fw, 0, 0); - if (widget != 0 && widget->windowIcon().cacheKey() != QApplication::windowIcon().cacheKey()) + if (widget != nullptr && widget->windowIcon().cacheKey() != QApplication::windowIcon().cacheKey()) titleRect.adjust(titleRect.height() + mw, 0, 0, 0); } else { titleRect.adjust(mw, 0, 0, 0); @@ -2775,7 +2775,7 @@ void QWindowsXPStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCo break; v = nextInterval; } - if (lines.size() > 0) { + if (!lines.isEmpty()) { p->save(); p->translate(slrect.topLeft()); p->drawLines(lines.constData(), lines.size()); @@ -2923,7 +2923,7 @@ void QWindowsXPStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCo p->save(); p->setClipRect(menuarea); tool.rect = option->rect; - proxy()->drawPrimitive(PE_PanelButtonBevel, &tool, p, 0); + proxy()->drawPrimitive(PE_PanelButtonBevel, &tool, p, nullptr); p->restore(); } // Draw arrow @@ -3223,7 +3223,7 @@ void QWindowsXPStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCo } } -static inline Qt::Orientation progressBarOrientation(const QStyleOption *option = 0) +static inline Qt::Orientation progressBarOrientation(const QStyleOption *option = nullptr) { if (const QStyleOptionProgressBar *pb = qstyleoption_cast(option)) return pb->orientation; @@ -3234,27 +3234,27 @@ int QWindowsXPStylePrivate::pixelMetricFromSystemDp(QStyle::PixelMetric pm, cons { switch (pm) { case QStyle::PM_IndicatorWidth: - return XPThemeData::themeSize(widget, 0, QWindowsXPStylePrivate::ButtonTheme, BP_CHECKBOX, CBS_UNCHECKEDNORMAL).width(); + return XPThemeData::themeSize(widget, nullptr, QWindowsXPStylePrivate::ButtonTheme, BP_CHECKBOX, CBS_UNCHECKEDNORMAL).width(); case QStyle::PM_IndicatorHeight: - return XPThemeData::themeSize(widget, 0, QWindowsXPStylePrivate::ButtonTheme, BP_CHECKBOX, CBS_UNCHECKEDNORMAL).height(); + return XPThemeData::themeSize(widget, nullptr, QWindowsXPStylePrivate::ButtonTheme, BP_CHECKBOX, CBS_UNCHECKEDNORMAL).height(); case QStyle::PM_ExclusiveIndicatorWidth: - return XPThemeData::themeSize(widget, 0, QWindowsXPStylePrivate::ButtonTheme, BP_RADIOBUTTON, RBS_UNCHECKEDNORMAL).width(); + return XPThemeData::themeSize(widget, nullptr, QWindowsXPStylePrivate::ButtonTheme, BP_RADIOBUTTON, RBS_UNCHECKEDNORMAL).width(); case QStyle::PM_ExclusiveIndicatorHeight: - return XPThemeData::themeSize(widget, 0, QWindowsXPStylePrivate::ButtonTheme, BP_RADIOBUTTON, RBS_UNCHECKEDNORMAL).height(); + return XPThemeData::themeSize(widget, nullptr, QWindowsXPStylePrivate::ButtonTheme, BP_RADIOBUTTON, RBS_UNCHECKEDNORMAL).height(); case QStyle::PM_ProgressBarChunkWidth: return progressBarOrientation(option) == Qt::Horizontal - ? XPThemeData::themeSize(widget, 0, QWindowsXPStylePrivate::ProgressTheme, PP_CHUNK).width() - : XPThemeData::themeSize(widget, 0, QWindowsXPStylePrivate::ProgressTheme, PP_CHUNKVERT).height(); + ? XPThemeData::themeSize(widget, nullptr, QWindowsXPStylePrivate::ProgressTheme, PP_CHUNK).width() + : XPThemeData::themeSize(widget, nullptr, QWindowsXPStylePrivate::ProgressTheme, PP_CHUNKVERT).height(); case QStyle::PM_SliderThickness: - return XPThemeData::themeSize(widget, 0, QWindowsXPStylePrivate::TrackBarTheme, TKP_THUMB).height(); + return XPThemeData::themeSize(widget, nullptr, QWindowsXPStylePrivate::TrackBarTheme, TKP_THUMB).height(); case QStyle::PM_TitleBarHeight: return widget && (widget->windowType() == Qt::Tool) ? GetSystemMetrics(SM_CYSMCAPTION) + GetSystemMetrics(SM_CXSIZEFRAME) : GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CXSIZEFRAME); case QStyle::PM_MdiSubWindowFrameWidth: - return XPThemeData::themeSize(widget, 0, QWindowsXPStylePrivate::WindowTheme, WP_FRAMELEFT, FS_ACTIVE).width(); + return XPThemeData::themeSize(widget, nullptr, QWindowsXPStylePrivate::WindowTheme, WP_FRAMELEFT, FS_ACTIVE).width(); case QStyle::PM_DockWidgetFrameWidth: - return XPThemeData::themeSize(widget, 0, QWindowsXPStylePrivate::WindowTheme, WP_SMALLFRAMERIGHT, FS_ACTIVE).width(); + return XPThemeData::themeSize(widget, nullptr, QWindowsXPStylePrivate::WindowTheme, WP_SMALLFRAMERIGHT, FS_ACTIVE).width(); default: break; } @@ -3620,7 +3620,7 @@ QSize QWindowsXPStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt case CT_LineEdit: case CT_ComboBox: { - XPThemeData buttontheme(widget, 0, QWindowsXPStylePrivate::ButtonTheme, BP_PUSHBUTTON, PBS_NORMAL); + XPThemeData buttontheme(widget, nullptr, QWindowsXPStylePrivate::ButtonTheme, BP_PUSHBUTTON, PBS_NORMAL); if (buttontheme.isValid()) { const qreal factor = QWindowsXPStylePrivate::nativeMetricScaleFactor(widget); const QMarginsF borderSize = buttontheme.margins() * factor; @@ -3741,11 +3741,11 @@ int QWindowsXPStyle::styleHint(StyleHint hint, const QStyleOption *option, const titleBarRect.setHeight(tbHeight); XPThemeData themeData; if (titlebar->titleBarState & Qt::WindowMinimized) { - themeData = XPThemeData(widget, 0, + themeData = XPThemeData(widget, nullptr, QWindowsXPStylePrivate::WindowTheme, WP_MINCAPTION, CS_ACTIVE, titleBarRect); } else - themeData = XPThemeData(widget, 0, + themeData = XPThemeData(widget, nullptr, QWindowsXPStylePrivate::WindowTheme, WP_CAPTION, CS_ACTIVE, titleBarRect); mask->region = d->region(themeData) + @@ -3774,10 +3774,8 @@ int QWindowsXPStyle::styleHint(StyleHint hint, const QStyleOption *option, const /*! \reimp */ QPalette QWindowsXPStyle::standardPalette() const { - if (QWindowsXPStylePrivate::useXP() && QApplicationPrivate::sys_pal) - return *QApplicationPrivate::sys_pal; - else - return QWindowsStyle::standardPalette(); + return QWindowsXPStylePrivate::useXP() && QApplicationPrivate::sys_pal + ? *QApplicationPrivate::sys_pal : QWindowsStyle::standardPalette(); } /*! @@ -3795,7 +3793,7 @@ QPixmap QWindowsXPStyle::standardPixmap(StandardPixmap standardPixmap, const QSt if (qstyleoption_cast(option)) { if (widget && widget->isWindow()) { - XPThemeData theme(widget, 0, QWindowsXPStylePrivate::WindowTheme, WP_SMALLCLOSEBUTTON, CBS_NORMAL); + XPThemeData theme(widget, nullptr, QWindowsXPStylePrivate::WindowTheme, WP_SMALLCLOSEBUTTON, CBS_NORMAL); if (theme.isValid()) { const QSize size = (theme.size() * QWindowsStylePrivate::nativeMetricScaleFactor(widget)).toSize(); return QIcon(QWindowsStyle::standardPixmap(standardPixmap, option, widget)).pixmap(size); @@ -3826,9 +3824,9 @@ QIcon QWindowsXPStyle::standardIcon(StandardPixmap standardIcon, if (qstyleoption_cast(option)) { if (d->dockFloat.isNull()) { - XPThemeData themeSize(0, 0, QWindowsXPStylePrivate::WindowTheme, + XPThemeData themeSize(nullptr, nullptr, QWindowsXPStylePrivate::WindowTheme, WP_SMALLCLOSEBUTTON, CBS_NORMAL); - XPThemeData theme(0, 0, QWindowsXPStylePrivate::WindowTheme, + XPThemeData theme(nullptr, nullptr, QWindowsXPStylePrivate::WindowTheme, WP_MAXBUTTON, MAXBS_NORMAL); if (theme.isValid()) { const QSize size = (themeSize.size() * QWindowsStylePrivate::nativeMetricScaleFactor(widget)).toSize(); @@ -3862,7 +3860,7 @@ QIcon QWindowsXPStyle::standardIcon(StandardPixmap standardIcon, if (qstyleoption_cast(option)) { if (d->dockClose.isNull()) { - XPThemeData theme(0, 0, QWindowsXPStylePrivate::WindowTheme, + XPThemeData theme(nullptr, nullptr, QWindowsXPStylePrivate::WindowTheme, WP_SMALLCLOSEBUTTON, CBS_NORMAL); if (theme.isValid()) { const QSize size = (theme.size() * QWindowsStylePrivate::nativeMetricScaleFactor(widget)).toSize(); @@ -3896,9 +3894,9 @@ QIcon QWindowsXPStyle::standardIcon(StandardPixmap standardIcon, if (qstyleoption_cast(option)) { if (d->dockFloat.isNull()) { - XPThemeData themeSize(0, 0, QWindowsXPStylePrivate::WindowTheme, + XPThemeData themeSize(nullptr, nullptr, QWindowsXPStylePrivate::WindowTheme, WP_SMALLCLOSEBUTTON, CBS_NORMAL); - XPThemeData theme(0, 0, QWindowsXPStylePrivate::WindowTheme, + XPThemeData theme(nullptr, nullptr, QWindowsXPStylePrivate::WindowTheme, WP_RESTOREBUTTON, RBS_NORMAL); if (theme.isValid()) { const QSize size = (themeSize.size() * QWindowsStylePrivate::nativeMetricScaleFactor(widget)).toSize(); diff --git a/src/plugins/styles/windowsvista/qwindowsxpstyle_p_p.h b/src/plugins/styles/windowsvista/qwindowsxpstyle_p_p.h index 60f9d7e9b7..ad7754e3d4 100644 --- a/src/plugins/styles/windowsvista/qwindowsxpstyle_p_p.h +++ b/src/plugins/styles/windowsvista/qwindowsxpstyle_p_p.h @@ -100,11 +100,11 @@ class QDebug; class XPThemeData { public: - explicit XPThemeData(const QWidget *w = 0, QPainter *p = 0, int themeIn = -1, + explicit XPThemeData(const QWidget *w = nullptr, QPainter *p = nullptr, int themeIn = -1, int part = 0, int state = 0, const QRect &r = QRect()) - : widget(w), painter(p), theme(themeIn), htheme(0), partId(part), stateId(state), + : widget(w), painter(p), theme(themeIn), partId(part), stateId(state), mirrorHorizontally(false), mirrorVertically(false), noBorder(false), - noContent(false), rotate(0), rect(r) + noContent(false), rect(r) {} HRGN mask(QWidget *widget); @@ -117,17 +117,17 @@ public: QMarginsF margins(const QRect &rect, int propId = TMT_CONTENTMARGINS); QMarginsF margins(int propId = TMT_CONTENTMARGINS); - static QSizeF themeSize(const QWidget *w = 0, QPainter *p = 0, int themeIn = -1, int part = 0, int state = 0); - static QMarginsF themeMargins(const QRect &rect, const QWidget *w = 0, QPainter *p = 0, int themeIn = -1, + static QSizeF themeSize(const QWidget *w = nullptr, QPainter *p = nullptr, int themeIn = -1, int part = 0, int state = 0); + static QMarginsF themeMargins(const QRect &rect, const QWidget *w = nullptr, QPainter *p = nullptr, int themeIn = -1, int part = 0, int state = 0, int propId = TMT_CONTENTMARGINS); - static QMarginsF themeMargins(const QWidget *w = 0, QPainter *p = 0, int themeIn = -1, + static QMarginsF themeMargins(const QWidget *w = nullptr, QPainter *p = nullptr, int themeIn = -1, int part = 0, int state = 0, int propId = TMT_CONTENTMARGINS); const QWidget *widget; QPainter *painter; int theme; - HTHEME htheme; + HTHEME htheme = nullptr; int partId; int stateId; @@ -135,18 +135,18 @@ public: uint mirrorVertically : 1; uint noBorder : 1; uint noContent : 1; - uint rotate; + uint rotate = 0; QRect rect; }; struct ThemeMapKey { - int theme; - int partId; - int stateId; - bool noBorder; - bool noContent; + int theme = 0; + int partId = -1; + int stateId = -1; + bool noBorder = false; + bool noContent = false; - ThemeMapKey() : partId(-1), stateId(-1) {} + ThemeMapKey() = default; ThemeMapKey(const XPThemeData &data) : theme(data.theme), partId(data.partId), stateId(data.stateId), noBorder(data.noBorder), noContent(data.noContent) {} @@ -171,7 +171,7 @@ enum AlphaChannelType { }; struct ThemeMapData { - AlphaChannelType alphaType; // Which type of alpha on part & state + AlphaChannelType alphaType = UnknownAlpha; // Which type of alpha on part & state bool dataValid : 1; // Only used to detect if hash value is ok bool partIsTransparent : 1; @@ -217,15 +217,13 @@ public: }; QWindowsXPStylePrivate() - : QWindowsStylePrivate(), hasInitColors(false), bufferDC(0), bufferBitmap(0), nullBitmap(0), - bufferPixels(0), bufferW(0), bufferH(0) { init(); } ~QWindowsXPStylePrivate() { cleanup(); } - static int pixelMetricFromSystemDp(QStyle::PixelMetric pm, const QStyleOption *option = 0, const QWidget *widget = 0); - static int fixedPixelMetric(QStyle::PixelMetric pm, const QStyleOption *option = 0, const QWidget *widget = 0); + static int pixelMetricFromSystemDp(QStyle::PixelMetric pm, const QStyleOption *option = nullptr, const QWidget *widget = nullptr); + static int fixedPixelMetric(QStyle::PixelMetric pm, const QStyleOption *option = nullptr, const QWidget *widget = nullptr); static HWND winId(const QWidget *widget); @@ -251,10 +249,10 @@ public: bool fixAlphaChannel(const QRect &rect); bool swapAlphaChannel(const QRect &rect, bool allPixels = false); - QRgb groupBoxTextColor; - QRgb groupBoxTextColorDisabled; - QRgb sliderTickColor; - bool hasInitColors; + QRgb groupBoxTextColor = 0; + QRgb groupBoxTextColorDisabled = 0; + QRgb sliderTickColor = 0; + bool hasInitColors = false; static HTHEME createTheme(int theme, HWND hwnd); static QString themeName(int theme); @@ -277,11 +275,12 @@ private: static bool use_xp; QHash alphaCache; - HDC bufferDC; - HBITMAP bufferBitmap; - HBITMAP nullBitmap; - uchar *bufferPixels; - int bufferW, bufferH; + HDC bufferDC = nullptr; + HBITMAP bufferBitmap = nullptr; + HBITMAP nullBitmap = nullptr; + uchar *bufferPixels = nullptr; + int bufferW = 0; + int bufferH = 0; static HWND m_vistaTreeViewHelper; static HTHEME m_themes[NThemes]; @@ -292,7 +291,7 @@ inline QSizeF XPThemeData::size() QSizeF result(0, 0); if (isValid()) { SIZE size; - if (SUCCEEDED(GetThemePartSize(handle(), 0, partId, stateId, 0, TS_TRUE, &size))) + if (SUCCEEDED(GetThemePartSize(handle(), nullptr, partId, stateId, nullptr, TS_TRUE, &size))) result = QSize(size.cx, size.cy); } return result; @@ -304,7 +303,7 @@ inline QMarginsF XPThemeData::margins(const QRect &qRect, int propId) if (isValid()) { MARGINS margins; RECT rect = XPThemeData::toRECT(qRect); - if (SUCCEEDED(GetThemeMargins(handle(), 0, partId, stateId, propId, &rect, &margins))) + if (SUCCEEDED(GetThemeMargins(handle(), nullptr, partId, stateId, propId, &rect, &margins))) result = QMargins(margins.cxLeftWidth, margins.cyTopHeight, margins.cxRightWidth, margins.cyBottomHeight); } return result; @@ -315,7 +314,7 @@ inline QMarginsF XPThemeData::margins(int propId) QMarginsF result(0, 0, 0 ,0); if (isValid()) { MARGINS margins; - if (SUCCEEDED(GetThemeMargins(handle(), 0, partId, stateId, propId, NULL, &margins))) + if (SUCCEEDED(GetThemeMargins(handle(), nullptr, partId, stateId, propId, nullptr, &margins))) result = QMargins(margins.cxLeftWidth, margins.cyTopHeight, margins.cxRightWidth, margins.cyBottomHeight); } return result; -- cgit v1.2.3 From 2dd781df87b98697c815183e4abeb226577230ab Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 12 Sep 2019 08:54:58 +0200 Subject: Windows QPA: Fix missing resize when changing the scale factor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Do not suppress the resize event caused by the handling of WM_DPICHANGED unless the screen really changed. Fixes: QTBUG-76510 Change-Id: I8b9ae41ad7deb863c1633ec5901bc04304b2165c Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/windows/qwindowswindow.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp index 79681fd1fa..519a2daae9 100644 --- a/src/plugins/platforms/windows/qwindowswindow.cpp +++ b/src/plugins/platforms/windows/qwindowswindow.cpp @@ -1897,8 +1897,10 @@ void QWindowsWindow::handleGeometryChange() { const QRect previousGeometry = m_data.geometry; m_data.geometry = geometry_sys(); - if (testFlag(WithinDpiChanged)) - return; // QGuiApplication will send resize + if (testFlag(WithinDpiChanged) + && QWindowsContext::instance()->screenManager().screenForHwnd(m_data.hwnd) != screen()) { + return; // QGuiApplication will send resize when screen actually changes + } QWindowSystemInterface::handleGeometryChange(window(), m_data.geometry); // QTBUG-32121: OpenGL/normal windows (with exception of ANGLE) do not receive // expose events when shrinking, synthesize. -- cgit v1.2.3 From 3278eae5773f21f6b1cc059fa392609e28caa902 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Fri, 10 May 2019 12:04:52 +0200 Subject: wasm: recreate backing store texture with valid gl context The compositor context is not current during the resize() call, but will be during updateTexture(). Change-Id: I29c2e06aa251b564b5d622dc9380ec994e15aab0 Reviewed-by: Lorn Potter --- src/plugins/platforms/wasm/qwasmbackingstore.cpp | 9 ++++++--- src/plugins/platforms/wasm/qwasmbackingstore.h | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/wasm/qwasmbackingstore.cpp b/src/plugins/platforms/wasm/qwasmbackingstore.cpp index e8eda2605f..7e8a382512 100644 --- a/src/plugins/platforms/wasm/qwasmbackingstore.cpp +++ b/src/plugins/platforms/wasm/qwasmbackingstore.cpp @@ -81,6 +81,11 @@ void QWasmBackingStore::updateTexture() if (m_dirty.isNull()) return; + if (m_recreateTexture && m_texture->isCreated()) { + m_recreateTexture = false; + m_texture->destroy(); + } + if (!m_texture->isCreated()) { m_texture->setMinificationFilter(QOpenGLTexture::Nearest); m_texture->setMagnificationFilter(QOpenGLTexture::Nearest); @@ -146,9 +151,7 @@ void QWasmBackingStore::resize(const QSize &size, const QRegion &staticContents) m_image = QImage(size * window()->devicePixelRatio(), QImage::Format_RGB32); m_image.setDevicePixelRatio(window()->devicePixelRatio()); - - if (m_texture->isCreated()) - m_texture->destroy(); + m_recreateTexture = true; } QImage QWasmBackingStore::toImage() const diff --git a/src/plugins/platforms/wasm/qwasmbackingstore.h b/src/plugins/platforms/wasm/qwasmbackingstore.h index 4bca83c457..b93c96b483 100644 --- a/src/plugins/platforms/wasm/qwasmbackingstore.h +++ b/src/plugins/platforms/wasm/qwasmbackingstore.h @@ -64,6 +64,7 @@ private: QImage m_image; QScopedPointer m_texture; QRegion m_dirty; + bool m_recreateTexture = false; }; QT_END_NAMESPACE -- cgit v1.2.3 From cd92049a95e6c762dadf011fad93f5ca151375fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Thu, 5 Sep 2019 12:37:00 +0200 Subject: Prevent crash in QWasmScreen::resizeMaximizedWindows() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit screen() may return a null QScreen pointer during screen initialization. Fixes: QTBUG-78118 Change-Id: Ide26eb3f06861c38cd7ae56789dd010d4cd7e572 Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/wasm/qwasmscreen.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/plugins') diff --git a/src/plugins/platforms/wasm/qwasmscreen.cpp b/src/plugins/platforms/wasm/qwasmscreen.cpp index f2eabfa486..e536bc0ee3 100644 --- a/src/plugins/platforms/wasm/qwasmscreen.cpp +++ b/src/plugins/platforms/wasm/qwasmscreen.cpp @@ -139,6 +139,8 @@ QPlatformCursor *QWasmScreen::cursor() const void QWasmScreen::resizeMaximizedWindows() { + if (!screen()) + return; QPlatformScreen::resizeMaximizedWindows(); } -- cgit v1.2.3 From aa6d7dd7ee306c0adbcd42b013d1e749072205bb Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Wed, 18 Sep 2019 20:34:13 +0200 Subject: QSqlDriver: deprecate one-arg notification() signal QSqlDriver::notifcation() signal is available in two versions since Qt4 times. They are both emitted in the corresponding places which is useless. Therefore deprecate the one-arg version. [ChangeLog][QtSql][QSqlDriver] The one-arg version of QSqlDriver::notifcation() is now deprecated. Change-Id: Ie09aa0cc952f4d854c6fb617b37b9047a3194ee3 Reviewed-by: Andy Shaw --- src/plugins/sqldrivers/ibase/qsql_ibase.cpp | 5 +++++ src/plugins/sqldrivers/psql/qsql_psql.cpp | 5 +++++ src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp | 5 +++++ 3 files changed, 15 insertions(+) (limited to 'src/plugins') diff --git a/src/plugins/sqldrivers/ibase/qsql_ibase.cpp b/src/plugins/sqldrivers/ibase/qsql_ibase.cpp index ead08dbce8..b0b5375222 100644 --- a/src/plugins/sqldrivers/ibase/qsql_ibase.cpp +++ b/src/plugins/sqldrivers/ibase/qsql_ibase.cpp @@ -1914,7 +1914,12 @@ void QIBaseDriver::qHandleEventNotification(void *updatedResultBuffer) if (counts[0]) { if (eBuffer->subscriptionState == QIBaseEventBuffer::Subscribed) { +#if QT_DEPRECATED_SINCE(5, 15) +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED emit notification(i.key()); +QT_WARNING_POP +#endif emit notification(i.key(), QSqlDriver::UnknownSource, QVariant()); } else if (eBuffer->subscriptionState == QIBaseEventBuffer::Starting) diff --git a/src/plugins/sqldrivers/psql/qsql_psql.cpp b/src/plugins/sqldrivers/psql/qsql_psql.cpp index 28be7bdc38..5f325db81e 100644 --- a/src/plugins/sqldrivers/psql/qsql_psql.cpp +++ b/src/plugins/sqldrivers/psql/qsql_psql.cpp @@ -1692,7 +1692,12 @@ void QPSQLDriver::_q_handleNotification(int) if (notify->extra) payload = d->isUtf8 ? QString::fromUtf8(notify->extra) : QString::fromLatin1(notify->extra); #endif +#if QT_DEPRECATED_SINCE(5, 15) +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED emit notification(name); +QT_WARNING_POP +#endif QSqlDriver::NotificationSource source = (notify->be_pid == PQbackendPID(d->connection)) ? QSqlDriver::SelfSource : QSqlDriver::OtherSource; emit notification(name, source, payload); } diff --git a/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp b/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp index 001bd673fc..65d3f0a580 100644 --- a/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp +++ b/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp @@ -1044,7 +1044,12 @@ void QSQLiteDriver::handleNotification(const QString &tableName, qint64 rowid) { Q_D(const QSQLiteDriver); if (d->notificationid.contains(tableName)) { +#if QT_DEPRECATED_SINCE(5, 15) +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED emit notification(tableName); +QT_WARNING_POP +#endif emit notification(tableName, QSqlDriver::UnknownSource, QVariant(rowid)); } } -- cgit v1.2.3 From ec0e9f29dfd0b45edf5fd33e8ccf763e604612d7 Mon Sep 17 00:00:00 2001 From: BogDan Vatra Date: Tue, 17 Sep 2019 09:54:28 +0300 Subject: Android: Fix loading of plugins In 5bb178c479a247720fbc3fbb7f06a32b725193ac, the Android platform plugin was moved from platforms/android to platforms/. The unforeseen consequence of this was that the plugin loader for plugins/platforms would now find it, whereas before it would be ignored. It would therefore be detected as the appropriate plugin, but since it was intended to be loaded as a static plugin, loading it dynamically would fail. Instead of fixing the static plugin loading, we remove this hack. Fixes: QTBUG-78440 Change-Id: Idcb6c075fdebaf67644f32a59d7aaf0d1c0bbe20 Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/plugins/platforms/android/android.pro | 8 ++- src/plugins/platforms/android/androidjnimain.cpp | 2 - src/plugins/platforms/android/main.cpp | 63 ++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 7 deletions(-) create mode 100644 src/plugins/platforms/android/main.cpp (limited to 'src/plugins') diff --git a/src/plugins/platforms/android/android.pro b/src/plugins/platforms/android/android.pro index 346df84038..730247cd7f 100644 --- a/src/plugins/platforms/android/android.pro +++ b/src/plugins/platforms/android/android.pro @@ -1,9 +1,5 @@ TARGET = qtforandroid -# STATICPLUGIN needed because there's a Q_IMPORT_PLUGIN in androidjnimain.cpp -# Yes, the plugin imports itself statically -DEFINES += QT_STATICPLUGIN - LIBS += -ljnigraphics -landroid QT += \ @@ -19,7 +15,8 @@ INCLUDEPATH += \ $$PWD \ $$QT_SOURCE_TREE/src/3rdparty/android -SOURCES += $$PWD/androidplatformplugin.cpp \ +SOURCES += $$PWD/main.cpp \ + $$PWD/androidplatformplugin.cpp \ $$PWD/androidcontentfileengine.cpp \ $$PWD/androiddeadlockprotector.cpp \ $$PWD/androidjnimain.cpp \ @@ -92,4 +89,5 @@ qtConfig(vulkan) { } PLUGIN_TYPE = platforms +PLUGIN_CLASS_NAME = QAndroidIntegrationPlugin load(qt_plugin) diff --git a/src/plugins/platforms/android/androidjnimain.cpp b/src/plugins/platforms/android/androidjnimain.cpp index 915f7f0f5b..27eb337aaa 100644 --- a/src/plugins/platforms/android/androidjnimain.cpp +++ b/src/plugins/platforms/android/androidjnimain.cpp @@ -68,8 +68,6 @@ #include -Q_IMPORT_PLUGIN(QAndroidPlatformIntegrationPlugin) - QT_BEGIN_NAMESPACE static JavaVM *m_javaVM = nullptr; diff --git a/src/plugins/platforms/android/main.cpp b/src/plugins/platforms/android/main.cpp new file mode 100644 index 0000000000..c304fc8d69 --- /dev/null +++ b/src/plugins/platforms/android/main.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2019 BogDan Vatra +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include +#include "qandroidplatformintegration.h" + +QT_BEGIN_NAMESPACE + +class QAndroidIntegrationPlugin : public QPlatformIntegrationPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID QPlatformIntegrationFactoryInterface_iid FILE "android.json") + +public: + QPlatformIntegration *create(const QString& system, const QStringList& paramList) override; +}; + +QPlatformIntegration *QAndroidIntegrationPlugin::create(const QString& system, const QStringList& paramList) +{ + if (!system.compare(QLatin1String("android"), Qt::CaseInsensitive)) + return new QAndroidPlatformIntegration(paramList); + + return nullptr; +} + +QT_END_NAMESPACE -- cgit v1.2.3 From 04dcc902eb64d94653a12005f3aedf32be1011c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 19 Sep 2019 18:09:52 +0200 Subject: macOS: Handle backing property changes in a single place Change-Id: I70d57632a1756f74249f64d4d4c405cb3120a179 Reviewed-by: Timur Pocheptsov --- src/plugins/platforms/cocoa/qcocoawindow.h | 1 - src/plugins/platforms/cocoa/qcocoawindow.mm | 11 ----------- src/plugins/platforms/cocoa/qnsview_drawing.mm | 20 ++++++++++++-------- 3 files changed, 12 insertions(+), 20 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/cocoa/qcocoawindow.h b/src/plugins/platforms/cocoa/qcocoawindow.h index c6ce6e6819..fef72bc496 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.h +++ b/src/plugins/platforms/cocoa/qcocoawindow.h @@ -161,7 +161,6 @@ 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 db4bc12210..35b7162346 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -1262,17 +1262,6 @@ 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() { diff --git a/src/plugins/platforms/cocoa/qnsview_drawing.mm b/src/plugins/platforms/cocoa/qnsview_drawing.mm index d2e6f848a0..de93e03685 100644 --- a/src/plugins/platforms/cocoa/qnsview_drawing.mm +++ b/src/plugins/platforms/cocoa/qnsview_drawing.mm @@ -211,17 +211,21 @@ - (void)viewDidChangeBackingProperties { - CALayer *layer = self.layer; - if (!layer) - return; + qCDebug(lcQpaDrawing) << "Backing properties changed for" << self; - layer.contentsScale = self.window.backingScaleFactor; + if (CALayer *layer = self.layer) { + layer.contentsScale = self.window.backingScaleFactor; - // Metal layers must be manually updated on e.g. screen change - if ([layer isKindOfClass:CAMetalLayer.class]) { - [self updateMetalLayerDrawableSize:static_cast(layer)]; - [self setNeedsDisplay:YES]; + // Metal layers must be manually updated on e.g. screen change + if ([layer isKindOfClass:CAMetalLayer.class]) + [self updateMetalLayerDrawableSize:static_cast(layer)]; } + + // 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 0642ca3528b1020acf1deadf8bf6d374c0db05f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 19 Sep 2019 18:15:18 +0200 Subject: macOS: Don't update Metal layer's drawableSize automatically MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Like our other rendering code paths, the Metal path should allow the user to resize their surface when they see fit. This is the case today with e.g QBackingStore::resize() and QOpenGLPaintDevice::setSize(). [ChangeLog][macOS] The drawableSize of Metal layers is no longer updated automatically on window resize or screen change. Update the size manually in response to resizeEvent(), or at the start of each frame, as needed. Change-Id: I9ed6d4326d0e0a3f4e3c63984d3b193e8bb77cae Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/cocoa/qnsview_drawing.mm | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/cocoa/qnsview_drawing.mm b/src/plugins/platforms/cocoa/qnsview_drawing.mm index de93e03685..e72142466b 100644 --- a/src/plugins/platforms/cocoa/qnsview_drawing.mm +++ b/src/plugins/platforms/cocoa/qnsview_drawing.mm @@ -173,20 +173,6 @@ } #endif -- (void)updateMetalLayerDrawableSize:(CAMetalLayer *)layer -{ - CGSize drawableSize = layer.bounds.size; - drawableSize.width *= layer.contentsScale; - drawableSize.height *= layer.contentsScale; - layer.drawableSize = drawableSize; -} - -- (void)layoutSublayersOfLayer:(CALayer *)layer -{ - if ([layer isKindOfClass:CAMetalLayer.class]) - [self updateMetalLayerDrawableSize:static_cast(layer)]; -} - - (void)displayLayer:(CALayer *)layer { if (!NSThread.isMainThread) { @@ -213,13 +199,8 @@ { qCDebug(lcQpaDrawing) << "Backing properties changed for" << self; - if (CALayer *layer = self.layer) { - layer.contentsScale = self.window.backingScaleFactor; - - // Metal layers must be manually updated on e.g. screen change - if ([layer isKindOfClass:CAMetalLayer.class]) - [self updateMetalLayerDrawableSize:static_cast(layer)]; - } + 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. -- cgit v1.2.3 From 2dfeea921b8ac9fef92db8fab7b518f3f5994512 Mon Sep 17 00:00:00 2001 From: Liang Qi Date: Mon, 23 Sep 2019 13:48:30 +0200 Subject: Avoid unused parameter 'grab' warnings Android (5220042 based on r346389c) clang version 8.0.7: src/plugins/platforms/android/qandroidplatformwindow.h:68:35: error: unused parameter 'grab' [-Werror,-Wunused-parameter] bool setMouseGrabEnabled(bool grab) override { return false; } ^ src/plugins/platforms/android/qandroidplatformwindow.h:69:38: error: unused parameter 'grab' [-Werror,-Wunused-parameter] bool setKeyboardGrabEnabled(bool grab) override { return false; } ^ Change-Id: I4d8a18d5e3bfbc13c05b47f0cdfe10370673e359 Reviewed-by: Ville Voutilainen --- src/plugins/platforms/android/qandroidplatformwindow.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/android/qandroidplatformwindow.h b/src/plugins/platforms/android/qandroidplatformwindow.h index 5edd274759..d8eb6b7b7f 100644 --- a/src/plugins/platforms/android/qandroidplatformwindow.h +++ b/src/plugins/platforms/android/qandroidplatformwindow.h @@ -65,8 +65,8 @@ public: void setParent(const QPlatformWindow *window) override; WId winId() const override { return m_windowId; } - bool setMouseGrabEnabled(bool grab) override { return false; } - bool setKeyboardGrabEnabled(bool grab) override { return false; } + bool setMouseGrabEnabled(bool grab) override { Q_UNUSED(grab); return false; } + bool setKeyboardGrabEnabled(bool grab) override { Q_UNUSED(grab); return false; } QAndroidPlatformScreen *platformScreen() const; -- cgit v1.2.3 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') 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') 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') 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') 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') 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') 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') 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') 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') 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') 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 From 6b3de85f2b12a001a8f7a55da917a6f2fa004dcd Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Mon, 30 Sep 2019 13:35:44 +0000 Subject: Revert "Windows QPA: Preferably use DXGI to obtain adapter info" This reverts commit 94902905ec203626abc050744d14898674dc2bbd. The patch caused various test failures on Windows 7 in the CI system in qtdeclarative and qt3d. Without the patch we ended up using openglsw32.dll, with this patch we get qt.qpa.gl unknown - supportedRenderers GpuDescription(vendorId=0x0, deviceId=0x0, subSysId=0x0, revision=0, driver: \"\", version=, \"\"\"\") 0 renderer: QFlags(0x8|0x20) and then end up using ANGLE, which fails. Change-Id: I97c51f9c360461e1a05722d02d50c2450ca87b78 Task-number: QTBUG-78832 Reviewed-by: Alexandru Croitor --- .../platforms/windows/qwindowsopengltester.cpp | 256 ++------------------- src/plugins/platforms/windows/windows.pri | 2 - 2 files changed, 23 insertions(+), 235 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/windows/qwindowsopengltester.cpp b/src/plugins/platforms/windows/qwindowsopengltester.cpp index 63ecbfe0ea..afc1991e2c 100644 --- a/src/plugins/platforms/windows/qwindowsopengltester.cpp +++ b/src/plugins/platforms/windows/qwindowsopengltester.cpp @@ -47,7 +47,6 @@ #include #include #include -#include #include #include @@ -58,8 +57,6 @@ #include #include #include -#include -#include QT_BEGIN_NAMESPACE @@ -83,259 +80,52 @@ static GpuDescription adapterIdentifierToGpuDescription(const D3DADAPTER_IDENTIF return result; } -class QGraphicsAdapterInfo +class QDirect3D9Handle { public: - Q_DISABLE_COPY_MOVE(QGraphicsAdapterInfo) + Q_DISABLE_COPY_MOVE(QDirect3D9Handle) - QGraphicsAdapterInfo(); - ~QGraphicsAdapterInfo(); + QDirect3D9Handle(); + ~QDirect3D9Handle(); - bool isValid() const; + bool isValid() const { return m_direct3D9 != nullptr; } - UINT adapterCount() const; + UINT adapterCount() const { return m_direct3D9 ? m_direct3D9->GetAdapterCount() : 0u; } bool retrieveAdapterIdentifier(UINT n, D3DADAPTER_IDENTIFIER9 *adapterIdentifier) const; private: - QSystemLibrary m_dxgilib; - IDXGIFactory1 *m_dxgiFactory1 = nullptr; - QSystemLibrary m_d3d9lib; IDirect3D9 *m_direct3D9 = nullptr; - - /* This is a value from the DXGI_ADAPTER_FLAG enum. - * However, it's not available in dxgi.h from MinGW, - * so define it here in any case. */ - enum { DXGI_ADAPTER_FLAG_SOFTWARE = 2 }; - - UINT adapterCountDXGI() const; - bool retrieveAdapterIdentifierDXGI(UINT n, D3DADAPTER_IDENTIFIER9 *adapterIdentifier) const; - - UINT adapterCountD3D9() const; - bool retrieveAdapterIdentifierD3D9(UINT n, D3DADAPTER_IDENTIFIER9 *adapterIdentifier) const; }; -QGraphicsAdapterInfo::QGraphicsAdapterInfo() : - m_dxgilib(QStringLiteral("dxgi")), +QDirect3D9Handle::QDirect3D9Handle() : m_d3d9lib(QStringLiteral("d3d9")) { - using PtrCreateDXGIFactory1 = HRESULT (WINAPI *)(REFIID, void**); + using PtrDirect3DCreate9 = IDirect3D9 *(WINAPI *)(UINT); - if (m_dxgilib.load()) { - if (auto createDXGIFactory1 = (PtrCreateDXGIFactory1)m_dxgilib.resolve("CreateDXGIFactory1")) - createDXGIFactory1(IID_PPV_ARGS(&m_dxgiFactory1)); - } - - if (!m_dxgiFactory1) { - using PtrDirect3DCreate9 = IDirect3D9 *(WINAPI *)(UINT); - - if (m_d3d9lib.load()) { - if (auto direct3DCreate9 = (PtrDirect3DCreate9)m_d3d9lib.resolve("Direct3DCreate9")) - m_direct3D9 = direct3DCreate9(D3D_SDK_VERSION); - } + if (m_d3d9lib.load()) { + if (auto direct3DCreate9 = (PtrDirect3DCreate9)m_d3d9lib.resolve("Direct3DCreate9")) + m_direct3D9 = direct3DCreate9(D3D_SDK_VERSION); } } -QGraphicsAdapterInfo::~QGraphicsAdapterInfo() +QDirect3D9Handle::~QDirect3D9Handle() { - if (m_dxgiFactory1) - m_dxgiFactory1->Release(); if (m_direct3D9) m_direct3D9->Release(); } -bool QGraphicsAdapterInfo::isValid() const -{ - return m_dxgiFactory1 != nullptr || m_direct3D9 != nullptr; -} - -UINT QGraphicsAdapterInfo::adapterCount() const -{ - if (m_dxgiFactory1) - return adapterCountDXGI(); - if (m_direct3D9) - return adapterCountD3D9(); - return 0; -} - -bool QGraphicsAdapterInfo::retrieveAdapterIdentifier(UINT n, D3DADAPTER_IDENTIFIER9 *adapterIdentifier) const -{ - if (m_dxgiFactory1) - return retrieveAdapterIdentifierDXGI(n, adapterIdentifier); - if (m_direct3D9) - return retrieveAdapterIdentifierD3D9(n, adapterIdentifier); - return false; -} - -UINT QGraphicsAdapterInfo::adapterCountDXGI() const -{ - /* DXGI doesn't have an adapterCount(), instead we have to call EnumAdapters1() - * until DXGI_ERROR_NOT_FOUND is returned. */ - UINT n = 0; - - IDXGIAdapter1 *adapter; - while (SUCCEEDED(m_dxgiFactory1->EnumAdapters1(n, &adapter))) { - adapter->Release(); - ++n; - } - - return n; -} - -// Detect whether we are running under 64-bit Windows. -static bool isWow64Process() -{ - typedef BOOL (WINAPI *IsWow64ProcessPtr)(HANDLE hProcess, PBOOL Wow64Process); - IsWow64ProcessPtr IsWow64Process = (IsWow64ProcessPtr)QLibrary::resolve( - QStringLiteral("kernel32.dll"), "IsWow64Process"); - - if (IsWow64Process) { - BOOL IsWow64 = FALSE; - if (IsWow64Process(GetCurrentProcess(), &IsWow64)) - return IsWow64; - } - return false; -} - -// Read a string value from registry -static QString regGetString(HKEY key, const wchar_t* valueName) -{ - QVarLengthArray buf (MAX_PATH); - LRESULT res; - DWORD bufSize = buf.size() * sizeof(wchar_t); - res = RegGetValue(key, nullptr, valueName, - RRF_RT_REG_SZ | RRF_RT_REG_MULTI_SZ, nullptr, - buf.data(), &bufSize); - if (res == ERROR_MORE_DATA) { - buf.resize(bufSize / sizeof(wchar_t)); - bufSize = buf.size() * sizeof(wchar_t); - res = RegGetValue(key, nullptr, valueName, - RRF_RT_REG_SZ | RRF_RT_REG_MULTI_SZ, nullptr, - buf.data(), &bufSize); - } - /* In case of REG_MULTI_SZ, this returns just the first string, - * but that is sufficient for our purposes. */ - if (res == ERROR_SUCCESS) - return QString::fromWCharArray(buf.data()); - return QString(); -} - -// Read driver name given a DeviceKey -static QString retrieveDriverName(const wchar_t *driverKey) -{ - /* Kernel-style prefix, maps to HKLM - * (see https://docs.microsoft.com/en-us/windows-hardware/drivers/kernel/registry-key-object-routines) */ - static const wchar_t prefixMappingHKLM[] = L"\\Registry\\Machine\\"; - const size_t prefixMappingHKLMLen = wcslen(prefixMappingHKLM); - if (wcsnicmp(driverKey, prefixMappingHKLM, prefixMappingHKLMLen) != 0) - return QString(); - - driverKey += prefixMappingHKLMLen; - QString driverPath; - HKEY key; - if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, driverKey, 0, KEY_READ | KEY_WOW64_64KEY, &key) == ERROR_SUCCESS) { - const wchar_t *valueName = - isWow64Process() ? L"UserModeDriverNameWow" : L"UserModeDriverName"; - driverPath = regGetString(key, valueName); - RegCloseKey(key); - } - if (!driverPath.isEmpty()) { - int fileNameSep = driverPath.lastIndexOf(QLatin1Char('\\')); - if (fileNameSep >= 0) - driverPath = driverPath.mid(fileNameSep + 1); - return driverPath; - } - return QString(); -} - -// Retrieve driver name for a display device from registry. -static QString driverNameForDevice(const wchar_t *displayDevice) -{ - QString driverName; - DISPLAY_DEVICE dd; - memset(&dd, 0, sizeof(dd)); - dd.cb = sizeof(dd); - for (int dev = 0; EnumDisplayDevices(nullptr, dev, &dd, 0); ++dev) { - if (wcsicmp(displayDevice, dd.DeviceName) == 0) { - // DeviceKey is documented as "internal", but it's a registry key in kernel format - driverName = retrieveDriverName(dd.DeviceKey); - break; - } - } - if (driverName.isEmpty()) { - /* Fall back to driver name from EnumDisplaySettings. - * This is only a fallback as on Windows 10 this just returns an device-independent - * name. OTOH, it's possible to recognize RDP connections from the driver name. */ - DEVMODE devMode; - if (EnumDisplaySettings(displayDevice, ENUM_CURRENT_SETTINGS, &devMode)) - driverName = QString::fromWCharArray(devMode.dmDeviceName); - } - return driverName; -} - -bool QGraphicsAdapterInfo::retrieveAdapterIdentifierDXGI(UINT n, D3DADAPTER_IDENTIFIER9 *adapterIdentifier) const -{ - IDXGIAdapter1 *adapter; - if (FAILED(m_dxgiFactory1->EnumAdapters1(n, &adapter))) - return false; - - bool result = false; - - DXGI_ADAPTER_DESC1 adapterDesc; - if (SUCCEEDED(adapter->GetDesc1(&adapterDesc))) { - if ((adapterDesc.VendorId != 0) && (adapterDesc.DeviceId != 0) // Don't use adapter description of Software Devices - && ((adapterDesc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) == 0)) { - memset(adapterIdentifier, 0, sizeof(*adapterIdentifier)); - WideCharToMultiByte(1252, 0, adapterDesc.Description, -1, - adapterIdentifier->Description, - sizeof(adapterIdentifier->Description), nullptr, nullptr); - adapterIdentifier->Description[sizeof(adapterIdentifier->Description) - 1] = 0; - adapterIdentifier->VendorId = adapterDesc.VendorId; - adapterIdentifier->DeviceId = adapterDesc.DeviceId; - adapterIdentifier->SubSysId = adapterDesc.SubSysId; - adapterIdentifier->Revision = adapterDesc.Revision; - - LARGE_INTEGER umdVersion; - if (SUCCEEDED(adapter->CheckInterfaceSupport(__uuidof(ID3D10Device), &umdVersion))) { - adapterIdentifier->DriverVersion = umdVersion; - result = true; - } - - /* DXGI doesn't expose the driver name, but we can get it from the registry. - * But we need a device name to follow. */ - IDXGIOutput *output = nullptr; - if (SUCCEEDED(adapter->EnumOutputs (0, &output))) { - DXGI_OUTPUT_DESC outputDesc; - if (SUCCEEDED(output->GetDesc (&outputDesc))) { - QString driverName = driverNameForDevice(outputDesc.DeviceName); - qstrncpy(adapterIdentifier->Driver, driverName.toLatin1().constData(), - sizeof(adapterIdentifier->Driver)); - } - output->Release(); - } - } - } - - adapter->Release(); - - return result; -} - -UINT QGraphicsAdapterInfo::adapterCountD3D9() const -{ - return m_direct3D9->GetAdapterCount(); -} - -bool QGraphicsAdapterInfo::retrieveAdapterIdentifierD3D9(UINT n, D3DADAPTER_IDENTIFIER9 *adapterIdentifier) const +bool QDirect3D9Handle::retrieveAdapterIdentifier(UINT n, D3DADAPTER_IDENTIFIER9 *adapterIdentifier) const { - return SUCCEEDED(m_direct3D9->GetAdapterIdentifier(n, 0, adapterIdentifier)); + return m_direct3D9 + && SUCCEEDED(m_direct3D9->GetAdapterIdentifier(n, 0, adapterIdentifier)); } GpuDescription GpuDescription::detect() { GpuDescription result; - QGraphicsAdapterInfo adapterInfo; - if (!adapterInfo.isValid()) + QDirect3D9Handle direct3D9; + if (!direct3D9.isValid()) return result; D3DADAPTER_IDENTIFIER9 adapterIdentifier; @@ -346,7 +136,7 @@ GpuDescription GpuDescription::detect() // and D3D uses by default. Therefore querying any additional adapters is // futile and not useful for our purposes in general, except for // identifying a few special cases later on. - if (adapterInfo.retrieveAdapterIdentifier(0, &adapterIdentifier)) { + if (direct3D9.retrieveAdapterIdentifier(0, &adapterIdentifier)) { result = adapterIdentifierToGpuDescription(adapterIdentifier); isAMD = result.vendorId == VENDOR_ID_AMD; } @@ -355,9 +145,9 @@ GpuDescription GpuDescription::detect() // when starting apps on a screen connected to the Intel card) by looking // for a default AMD adapter and an additional non-AMD one. if (isAMD) { - const UINT adapterCount = adapterInfo.adapterCount(); + const UINT adapterCount = direct3D9.adapterCount(); for (UINT adp = 1; adp < adapterCount; ++adp) { - if (adapterInfo.retrieveAdapterIdentifier(adp, &adapterIdentifier) + if (direct3D9.retrieveAdapterIdentifier(adp, &adapterIdentifier) && adapterIdentifier.VendorId != VENDOR_ID_AMD) { // Bingo. Now figure out the display for the AMD card. DISPLAY_DEVICE dd; @@ -382,11 +172,11 @@ GpuDescription GpuDescription::detect() QVector GpuDescription::detectAll() { QVector result; - QGraphicsAdapterInfo adapterInfo; - if (const UINT adapterCount = adapterInfo.adapterCount()) { + QDirect3D9Handle direct3D9; + if (const UINT adapterCount = direct3D9.adapterCount()) { for (UINT adp = 0; adp < adapterCount; ++adp) { D3DADAPTER_IDENTIFIER9 adapterIdentifier; - if (adapterInfo.retrieveAdapterIdentifier(adp, &adapterIdentifier)) + if (direct3D9.retrieveAdapterIdentifier(adp, &adapterIdentifier)) result.append(adapterIdentifierToGpuDescription(adapterIdentifier)); } } diff --git a/src/plugins/platforms/windows/windows.pri b/src/plugins/platforms/windows/windows.pri index 7de6369541..95ba961df1 100644 --- a/src/plugins/platforms/windows/windows.pri +++ b/src/plugins/platforms/windows/windows.pri @@ -12,8 +12,6 @@ LIBS += -lshlwapi -lwtsapi32 QMAKE_USE_PRIVATE += \ advapi32 \ d3d9/nolink \ - d3d11/nolink \ - dxgi/nolink \ ole32 \ shell32 \ user32 \ -- cgit v1.2.3 From fb09a8bfcfb9caeb9066946a7340f60d1d6f169c Mon Sep 17 00:00:00 2001 From: BogDan Vatra Date: Tue, 17 Sep 2019 09:56:07 +0300 Subject: Android: rework assets support The new version fix QDirIterators and it lists all the files and dirs. Change-Id: I5a30eedb61ab2397a84365d00f308cda0c194de2 Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/plugins/platforms/android/androidjnimain.cpp | 11 +- src/plugins/platforms/android/androidjnimain.h | 1 + .../android/qandroidassetsfileenginehandler.cpp | 356 ++++++++++----------- .../android/qandroidassetsfileenginehandler.h | 8 - 4 files changed, 184 insertions(+), 192 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/android/androidjnimain.cpp b/src/plugins/platforms/android/androidjnimain.cpp index 27eb337aaa..13ea9468df 100644 --- a/src/plugins/platforms/android/androidjnimain.cpp +++ b/src/plugins/platforms/android/androidjnimain.cpp @@ -75,6 +75,7 @@ static jclass m_applicationClass = nullptr; static jobject m_classLoaderObject = nullptr; static jmethodID m_loadClassMethodID = nullptr; static AAssetManager *m_assetManager = nullptr; +static jobject m_assets = nullptr; static jobject m_resourcesObj = nullptr; static jobject m_activityObject = nullptr; static jmethodID m_createSurfaceMethodID = nullptr; @@ -439,6 +440,11 @@ namespace QtAndroid return block; } + jobject assets() + { + return m_assets; + } + } // namespace QtAndroid static jboolean startQtAndroidPlugin(JNIEnv *env, jobject /*object*/, jstring paramsString, jstring environmentString) @@ -588,6 +594,8 @@ static void terminateQt(JNIEnv *env, jclass /*clazz*/) env->DeleteGlobalRef(m_RGB_565_BitmapConfigValue); if (m_bitmapDrawableClass) env->DeleteGlobalRef(m_bitmapDrawableClass); + if (m_assets) + env->DeleteGlobalRef(m_assets); m_androidPlatformIntegration = nullptr; delete m_androidAssetsFileEngineHandler; m_androidAssetsFileEngineHandler = nullptr; @@ -840,7 +848,8 @@ static int registerNatives(JNIEnv *env) if (object) { FIND_AND_CHECK_CLASS("android/content/ContextWrapper"); GET_AND_CHECK_METHOD(methodID, clazz, "getAssets", "()Landroid/content/res/AssetManager;"); - m_assetManager = AAssetManager_fromJava(env, env->CallObjectMethod(object, methodID)); + m_assets = env->NewGlobalRef(env->CallObjectMethod(object, methodID)); + m_assetManager = AAssetManager_fromJava(env, m_assets); GET_AND_CHECK_METHOD(methodID, clazz, "getResources", "()Landroid/content/res/Resources;"); m_resourcesObj = env->NewGlobalRef(env->CallObjectMethod(object, methodID)); diff --git a/src/plugins/platforms/android/androidjnimain.h b/src/plugins/platforms/android/androidjnimain.h index 08f1d50fe3..17ae30a1be 100644 --- a/src/plugins/platforms/android/androidjnimain.h +++ b/src/plugins/platforms/android/androidjnimain.h @@ -82,6 +82,7 @@ namespace QtAndroid double scaledDensity(); double pixelDensity(); JavaVM *javaVM(); + jobject assets(); AAssetManager *assetManager(); jclass applicationClass(); jobject activity(); diff --git a/src/plugins/platforms/android/qandroidassetsfileenginehandler.cpp b/src/plugins/platforms/android/qandroidassetsfileenginehandler.cpp index e1dcebfa4c..26e72a480f 100644 --- a/src/plugins/platforms/android/qandroidassetsfileenginehandler.cpp +++ b/src/plugins/platforms/android/qandroidassetsfileenginehandler.cpp @@ -39,40 +39,139 @@ #include "qandroidassetsfileenginehandler.h" #include "androidjnimain.h" +#include #include #include +#include QT_BEGIN_NAMESPACE -typedef QVector FilesList; +static const QLatin1String assetsPrefix("assets:"); +const static int prefixSize = 7; -struct AndroidAssetDir +static inline QString cleanedAssetPath(QString file) { - AndroidAssetDir(AAssetDir* ad) + if (file.startsWith(assetsPrefix)) + file.remove(0, prefixSize); + file.replace(QLatin1String("//"), QLatin1String("/")); + if (file.startsWith(QLatin1Char('/'))) + file.remove(0, 1); + if (file.endsWith(QLatin1Char('/'))) + file.chop(1); + return file; +} + +static inline QString prefixedPath(QString path) +{ + path = assetsPrefix + QLatin1Char('/') + path; + path.replace(QLatin1String("//"), QLatin1String("/")); + return path; +} + +struct AssetItem { + enum class Type { + File, + Folder + }; + + AssetItem (const QString &rawName) + : name(rawName) + { + if (name.endsWith(QLatin1Char('/'))) { + type = Type::Folder; + name.chop(1); + } + } + Type type = Type::File; + QString name; +}; + +using AssetItemList = QVector; + +class FolderIterator : public AssetItemList +{ +public: + static QSharedPointer fromCache(const QString &path) { - if (ad) { - const char *fileName; - while ((fileName = AAssetDir_getNextFileName(ad))) - m_items.push_back(QString::fromUtf8(fileName)); - AAssetDir_close(ad); + QMutexLocker lock(&m_assetsCacheMutex); + QSharedPointer *folder = m_assetsCache.object(path); + if (!folder) { + folder = new QSharedPointer{new FolderIterator{path}}; + if (!m_assetsCache.insert(path, folder)) { + QSharedPointer res = *folder; + delete folder; + return res; + } } + return *folder; + } + + FolderIterator(const QString &path) + : m_path(path) + { + QJNIObjectPrivate files = QJNIObjectPrivate::callStaticObjectMethod(QtAndroid::applicationClass(), + "listAssetContent", + "(Landroid/content/res/AssetManager;Ljava/lang/String;)[Ljava/lang/String;", + QtAndroid::assets(), QJNIObjectPrivate::fromString(path).object()); + if (files.isValid()) { + QJNIEnvironmentPrivate env; + jobjectArray jFiles = static_cast(files.object()); + const jint nFiles = env->GetArrayLength(jFiles); + for (int i = 0; i < nFiles; ++i) + push_back({QJNIObjectPrivate(env->GetObjectArrayElement(jFiles, i)).toString()}); + } + m_path = assetsPrefix + QLatin1Char('/') + m_path + QLatin1Char('/'); + m_path.replace(QLatin1String("//"), QLatin1String("/")); + } + + QString currentFileName() const + { + if (m_index < 0 || m_index >= size()) + return {}; + return at(m_index).name; + } + QString currentFilePath() const + { + if (m_index < 0 || m_index >= size()) + return {}; + return m_path + at(m_index).name; + } + + bool hasNext() const + { + return !empty() && m_index + 1 < size(); + } + + std::optional> next() + { + if (!hasNext()) + return {}; + ++m_index; + return std::pair(currentFileName(), at(m_index)); } - FilesList m_items; + +private: + int m_index = -1; + QString m_path; + static QCache> m_assetsCache; + static QMutex m_assetsCacheMutex; }; +QCache> FolderIterator::m_assetsCache(std::max(50, qEnvironmentVariableIntValue("QT_ANDROID_MAX_ASSETS_CACHE_SIZE"))); +QMutex FolderIterator::m_assetsCacheMutex; + class AndroidAbstractFileEngineIterator: public QAbstractFileEngineIterator { public: AndroidAbstractFileEngineIterator(QDir::Filters filters, const QStringList &nameFilters, - QSharedPointer asset, const QString &path) : QAbstractFileEngineIterator(filters, nameFilters) { - m_items = asset->m_items; - m_index = -1; - m_path = path; + m_stack.push_back(FolderIterator::fromCache(cleanedAssetPath(path))); + if (m_stack.last()->empty()) + m_stack.pop_back(); } QFileInfo currentFileInfo() const override @@ -82,54 +181,59 @@ public: QString currentFileName() const override { - if (m_index < 0 || m_index >= m_items.size()) - return QString(); - QString fileName = m_items[m_index]; - if (fileName.endsWith(QLatin1Char('/'))) - fileName.chop(1); - return fileName; + if (!m_currentIterator) + return {}; + return m_currentIterator->currentFileName(); } virtual QString currentFilePath() const { - return m_path + currentFileName(); + if (!m_currentIterator) + return {}; + return m_currentIterator->currentFilePath(); } bool hasNext() const override { - return m_items.size() && (m_index < m_items.size() - 1); + if (m_stack.empty()) + return false; + if (!m_stack.last()->hasNext()) { + m_stack.pop_back(); + return hasNext(); + } + return true; } QString next() override { - if (!hasNext()) - return QString(); - m_index++; - return currentFileName(); + if (m_stack.empty()) { + m_currentIterator.reset(); + return {}; + } + m_currentIterator = m_stack.last(); + auto res = m_currentIterator->next(); + if (!res) + return {}; + if (res->second.type == AssetItem::Type::Folder) { + m_stack.push_back(FolderIterator::fromCache(cleanedAssetPath(currentFilePath()))); + if (m_stack.last()->empty()) + m_stack.pop_back(); + } + return res->first; } private: - QString m_path; - FilesList m_items; - int m_index; + mutable QSharedPointer m_currentIterator; + mutable QVector> m_stack; }; class AndroidAbstractFileEngine: public QAbstractFileEngine { public: - explicit AndroidAbstractFileEngine(AAsset *asset, const QString &fileName) - { - m_assetFile = asset; - m_fileName = fileName; - } - - explicit AndroidAbstractFileEngine(QSharedPointer asset, const QString &fileName) + explicit AndroidAbstractFileEngine(AAssetManager *assetManager, const QString &fileName) + : m_assetManager(assetManager) { - m_assetFile = 0; - m_assetDir = asset; - m_fileName = fileName; - if (!m_fileName.endsWith(QLatin1Char('/'))) - m_fileName += QLatin1Char('/'); + setFileName(fileName); } ~AndroidAbstractFileEngine() @@ -139,7 +243,11 @@ public: bool open(QIODevice::OpenMode openMode) override { - return m_assetFile != 0 && (openMode & QIODevice::WriteOnly) == 0; + if (m_isFolder || (openMode & QIODevice::WriteOnly)) + return false; + close(); + m_assetFile = AAssetManager_open(m_assetManager, m_fileName.toUtf8(), AASSET_MODE_BUFFER); + return m_assetFile; } bool close() override @@ -200,7 +308,7 @@ public: FileFlags flags(ReadOwnerPerm|ReadUserPerm|ReadGroupPerm|ReadOtherPerm|ExistsFlag); if (m_assetFile) flags |= FileType; - if (!m_assetDir.isNull()) + else if (m_isFolder) flags |= DirectoryType; return type & flags; @@ -213,19 +321,19 @@ public: case DefaultName: case AbsoluteName: case CanonicalName: - return m_fileName; + return prefixedPath(m_fileName); case BaseName: if ((pos = m_fileName.lastIndexOf(QChar(QLatin1Char('/')))) != -1) - return m_fileName.mid(pos); + return prefixedPath(m_fileName.mid(pos)); else - return m_fileName; + return prefixedPath(m_fileName); case PathName: case AbsolutePathName: case CanonicalPathName: if ((pos = m_fileName.lastIndexOf(QChar(QLatin1Char('/')))) != -1) - return m_fileName.left(pos); + return prefixedPath(m_fileName.left(pos)); else - return m_fileName; + return prefixedPath(m_fileName); default: return QString(); } @@ -233,164 +341,46 @@ public: void setFileName(const QString &file) override { - if (file == m_fileName) - return; - - m_fileName = file; - if (!m_fileName.endsWith(QLatin1Char('/'))) - m_fileName += QLatin1Char('/'); - close(); + m_fileName = cleanedAssetPath(file); + m_isFolder = !open(QIODevice::ReadOnly) && !FolderIterator::fromCache(m_fileName)->empty(); } Iterator *beginEntryList(QDir::Filters filters, const QStringList &filterNames) override { - if (!m_assetDir.isNull()) - return new AndroidAbstractFileEngineIterator(filters, filterNames, m_assetDir, m_fileName); - return 0; + if (m_isFolder) + return new AndroidAbstractFileEngineIterator(filters, filterNames, m_fileName); + return nullptr; } private: - AAsset *m_assetFile; - QSharedPointer m_assetDir; + AAsset *m_assetFile = nullptr; + AAssetManager *m_assetManager; QString m_fileName; + bool m_isFolder; }; AndroidAssetsFileEngineHandler::AndroidAssetsFileEngineHandler() - : m_assetsCache(std::max(5, qEnvironmentVariableIntValue("QT_ANDROID_MAX_ASSETS_CACHE_SIZE"))) - , m_hasPrepopulatedCache(false) - , m_hasTriedPrepopulatingCache(false) { m_assetManager = QtAndroid::assetManager(); } -AndroidAssetsFileEngineHandler::~AndroidAssetsFileEngineHandler() -{ -} - -void AndroidAssetsFileEngineHandler::prepopulateCache() const -{ - Q_ASSERT(!m_hasTriedPrepopulatingCache); - m_hasTriedPrepopulatingCache = true; - - Q_ASSERT(m_assetsCache.isEmpty()); - - // Failsafe: Don't read cache files that are larger than 1MB - static qint64 maxPrepopulatedCacheSize = qMax(1024LL * 1024LL, - qgetenv("QT_ANDROID_MAX_PREPOPULATED_ASSETS_CACHE_SIZE").toLongLong()); - - const char *fileName = "--Added-by-androiddeployqt--/qt_cache_pregenerated_file_list"; - AAsset *asset = AAssetManager_open(m_assetManager, fileName, AASSET_MODE_BUFFER); - if (asset) { - m_hasPrepopulatedCache = true; - AndroidAbstractFileEngine fileEngine(asset, QString::fromLatin1(fileName)); - if (fileEngine.open(QIODevice::ReadOnly)) { - qint64 size = fileEngine.size(); - - if (size <= maxPrepopulatedCacheSize) { - QByteArray bytes(size, Qt::Uninitialized); - qint64 read = fileEngine.read(bytes.data(), size); - if (read != size) { - qWarning("Failed to read prepopulated cache"); - return; - } - - QDataStream stream(&bytes, QIODevice::ReadOnly); - stream.setVersion(QDataStream::Qt_5_3); - if (stream.status() != QDataStream::Ok) { - qWarning("Failed to read prepopulated cache"); - return; - } - - while (!stream.atEnd()) { - QString directoryName; - stream >> directoryName; - - int fileCount; - stream >> fileCount; - - QVector fileList; - fileList.reserve(fileCount); - while (fileCount--) { - QString fileName; - stream >> fileName; - fileList.append(fileName); - } - - QSharedPointer *aad = new QSharedPointer(new AndroidAssetDir(0)); - (*aad)->m_items = fileList; - - // Cost = 0, because we should always cache everything if there's a prepopulated cache - QByteArray key = directoryName != QLatin1String("/") - ? QByteArray("assets:/") + directoryName.toUtf8() - : QByteArray("assets:"); - - bool ok = m_assetsCache.insert(key, aad, 0); - if (!ok) - qWarning("Failed to insert in cache: %s", qPrintable(directoryName)); - } - } else { - qWarning("Prepopulated cache is too large to read.\n" - "Use environment variable QT_ANDROID_MAX_PREPOPULATED_ASSETS_CACHE_SIZE to adjust size."); - } - } - } -} - QAbstractFileEngine * AndroidAssetsFileEngineHandler::create(const QString &fileName) const { if (fileName.isEmpty()) - return 0; + return nullptr; - static QLatin1String assetsPrefix("assets:"); if (!fileName.startsWith(assetsPrefix)) - return 0; - - static int prefixSize = assetsPrefix.size() + 1; - - QByteArray path; - if (!fileName.endsWith(QLatin1Char('/'))) { - path = fileName.toUtf8(); - if (path.size() > prefixSize) { - AAsset *asset = AAssetManager_open(m_assetManager, - path.constData() + prefixSize, - AASSET_MODE_BUFFER); - if (asset) - return new AndroidAbstractFileEngine(asset, fileName); - } - } - - if (!path.size()) - path = fileName.left(fileName.length() - 1).toUtf8(); - - - m_assetsCacheMutext.lock(); - if (!m_hasTriedPrepopulatingCache) - prepopulateCache(); - - QSharedPointer *aad = m_assetsCache.object(path); - m_assetsCacheMutext.unlock(); - if (!aad) { - if (!m_hasPrepopulatedCache && path.size() > prefixSize) { - AAssetDir *assetDir = AAssetManager_openDir(m_assetManager, path.constData() + prefixSize); - if (assetDir) { - if (AAssetDir_getNextFileName(assetDir)) { - AAssetDir_rewind(assetDir); - aad = new QSharedPointer(new AndroidAssetDir(assetDir)); - m_assetsCacheMutext.lock(); - m_assetsCache.insert(path, aad); - m_assetsCacheMutext.unlock(); - return new AndroidAbstractFileEngine(*aad, fileName); - } else { - AAssetDir_close(assetDir); - } - } - } - } else { - return new AndroidAbstractFileEngine(*aad, fileName); - } - return 0; + return nullptr; + + QString path = fileName.mid(prefixSize); + path.replace(QLatin1String("//"), QLatin1String("/")); + if (path.startsWith(QLatin1Char('/'))) + path.remove(0, 1); + if (path.endsWith(QLatin1Char('/'))) + path.chop(1); + return new AndroidAbstractFileEngine(m_assetManager, path); } QT_END_NAMESPACE diff --git a/src/plugins/platforms/android/qandroidassetsfileenginehandler.h b/src/plugins/platforms/android/qandroidassetsfileenginehandler.h index f99dc9a11a..51cc5b07a8 100644 --- a/src/plugins/platforms/android/qandroidassetsfileenginehandler.h +++ b/src/plugins/platforms/android/qandroidassetsfileenginehandler.h @@ -49,22 +49,14 @@ QT_BEGIN_NAMESPACE -struct AndroidAssetDir; class AndroidAssetsFileEngineHandler: public QAbstractFileEngineHandler { public: AndroidAssetsFileEngineHandler(); - virtual ~AndroidAssetsFileEngineHandler(); QAbstractFileEngine *create(const QString &fileName) const override; private: - void prepopulateCache() const; - AAssetManager *m_assetManager; - mutable QCache> m_assetsCache; - mutable QMutex m_assetsCacheMutext; - mutable bool m_hasPrepopulatedCache; - mutable bool m_hasTriedPrepopulatingCache; }; QT_END_NAMESPACE -- cgit v1.2.3 From c8b07f7da3ff55f92378a1e98522f318bbc43077 Mon Sep 17 00:00:00 2001 From: BogDan Vatra Date: Thu, 15 Aug 2019 08:25:30 +0300 Subject: Android: Do not extract QML assets data Instead to extract the assets QML file, we create a .rcc bundle file which is register by android qpa plugin before the it invokes the main function. Thsi way we avoid extracting the QML files from assets as they can be accessed directly from resources. [ChangeLog][Android] Instead of bundling QML resources in assets and extracting them on first start, Qt now creates an .rcc file and register it before invoking the main function. Change-Id: Icb2fda79d82c5af102cc9a0276ff26bb0d1599e8 Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/plugins/platforms/android/androidjnimain.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/plugins') diff --git a/src/plugins/platforms/android/androidjnimain.cpp b/src/plugins/platforms/android/androidjnimain.cpp index 13ea9468df..fd2644717e 100644 --- a/src/plugins/platforms/android/androidjnimain.cpp +++ b/src/plugins/platforms/android/androidjnimain.cpp @@ -60,6 +60,7 @@ #include "qandroideventdispatcher.h" #include +#include #include #include #include @@ -525,6 +526,10 @@ static jboolean startQtApplication(JNIEnv */*env*/, jclass /*clazz*/) vm->AttachCurrentThread(&env, &args); } + // Register resources if they are available + if (QFile{QStringLiteral("assets:/android_rcc_bundle.rcc")}.exists()) + QResource::registerResource(QStringLiteral("assets:/android_rcc_bundle.rcc")); + QVarLengthArray params(m_applicationParams.size()); for (int i = 0; i < m_applicationParams.size(); i++) params[i] = static_cast(m_applicationParams[i].constData()); -- cgit v1.2.3 From c9478e90ff7abef1f019805f0846e651c484ebc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Tue, 24 Sep 2019 17:25:57 +0200 Subject: Export lcEventDispatcher in private namespace MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The category is used outside of QtCore, and needs to be exported for shared library builds. Change-Id: I9bba477d37b823146eaec4e1e53197651f09c013 Reviewed-by: Timur Pocheptsov Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/ios/qioseventdispatcher.mm | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/plugins') diff --git a/src/plugins/platforms/ios/qioseventdispatcher.mm b/src/plugins/platforms/ios/qioseventdispatcher.mm index 776343c5aa..c5856051de 100644 --- a/src/plugins/platforms/ios/qioseventdispatcher.mm +++ b/src/plugins/platforms/ios/qioseventdispatcher.mm @@ -211,6 +211,8 @@ namespace } logActivity; } +using namespace QT_PREPEND_NAMESPACE(QtPrivate); + extern "C" int qt_main_wrapper(int argc, char *argv[]) { @autoreleasepool { -- cgit v1.2.3 From dabc33bf9543e552d8627eda4977e82d340e9bcf Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Mon, 30 Sep 2019 22:25:33 +0200 Subject: QPainter: don't print deprecated warnings for HighQualityAntialiasing Add pragmas to not print warnings about the usage of the deprecated warnings inside QtCore. Change-Id: I2cd9f111cdf13cddff527ab3bac7fa80417d1445 Reviewed-by: Allan Sandfeld Jensen --- src/plugins/platforms/direct2d/qwindowsdirect2dpaintengine.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/plugins') diff --git a/src/plugins/platforms/direct2d/qwindowsdirect2dpaintengine.cpp b/src/plugins/platforms/direct2d/qwindowsdirect2dpaintengine.cpp index d7aba66b2f..03be44e095 100644 --- a/src/plugins/platforms/direct2d/qwindowsdirect2dpaintengine.cpp +++ b/src/plugins/platforms/direct2d/qwindowsdirect2dpaintengine.cpp @@ -941,6 +941,8 @@ public: { Q_Q(QWindowsDirect2DPaintEngine); +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED // Default path (no optimization) if (!(path.shape() == QVectorPath::LinesHint || path.shape() == QVectorPath::PolygonHint) || !pen.dashBrush @@ -948,6 +950,7 @@ public: || q->state()->renderHints.testFlag(QPainter::HighQualityAntialiasing) #endif || q->state()->renderHints.testFlag(QPainter::Antialiasing)) { +QT_WARNING_POP ComPtr geometry = vectorPathToID2D1PathGeometry(path); if (!geometry) { qWarning("%s: Could not convert path to d2d geometry", __FUNCTION__); -- cgit v1.2.3 From a978d21dac57697ae9557b99062bc804b005b9d4 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sun, 29 Sep 2019 21:28:52 +0200 Subject: PSQL: don't recreate QSqlField in loop in QPSQLResult::record() Move out the QSqlField variable out of the loop to avoid useless (de)allocations of QSqlField. Change-Id: I2c9e4c84f75e994d5eb1438839d502f6da531841 Reviewed-by: Robert Szefner Reviewed-by: Andy Shaw --- src/plugins/sqldrivers/psql/qsql_psql.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/plugins') diff --git a/src/plugins/sqldrivers/psql/qsql_psql.cpp b/src/plugins/sqldrivers/psql/qsql_psql.cpp index 28be7bdc38..3803f05b9f 100644 --- a/src/plugins/sqldrivers/psql/qsql_psql.cpp +++ b/src/plugins/sqldrivers/psql/qsql_psql.cpp @@ -812,8 +812,8 @@ QSqlRecord QPSQLResult::record() const return info; int count = PQnfields(d->result); + QSqlField f; for (int i = 0; i < count; ++i) { - QSqlField f; if (d->drv_d_func()->isUtf8) f.setName(QString::fromUtf8(PQfname(d->result, i))); else @@ -833,6 +833,8 @@ QSqlRecord QPSQLResult::record() const } } f.setTableName(tableName); + } else { + f.setTableName(QString()); } int ptype = PQftype(d->result, i); f.setType(qDecodePSQLType(ptype)); -- cgit v1.2.3 From 85f9fa7fab7b9a2d987be44a2a7a9d5ba57d6680 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Wed, 2 Oct 2019 22:28:06 +0200 Subject: Stop using QTime as a timer in QIBaseDriver::close() This is probably still the wrong thing to do here, though. Change-Id: I4ff76393dde0b9ad9eb4a5e0d35fb6125d141901 Reviewed-by: Edward Welbourne --- src/plugins/sqldrivers/ibase/qsql_ibase.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/sqldrivers/ibase/qsql_ibase.cpp b/src/plugins/sqldrivers/ibase/qsql_ibase.cpp index ead08dbce8..0f39f6aa0d 100644 --- a/src/plugins/sqldrivers/ibase/qsql_ibase.cpp +++ b/src/plugins/sqldrivers/ibase/qsql_ibase.cpp @@ -40,6 +40,7 @@ #include "qsql_ibase_p.h" #include #include +#include #include #include #include @@ -1570,10 +1571,9 @@ void QIBaseDriver::close() d->eventBuffers.clear(); #if defined(FB_API_VER) - // Workaround for Firebird crash - QTime timer; - timer.start(); - while (timer.elapsed() < 500) + // TODO check whether this workaround for Firebird crash is still needed + QDeadlineTimer timer(500); + while (!timer.hasExpired()) QCoreApplication::processEvents(); #endif } -- cgit v1.2.3 From bb65ac80977c277b6cba1abee423ccfd5f1b1f4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 4 Oct 2019 13:59:06 +0200 Subject: Modernize QWindowSystemInterface::handleCloseEvent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The base WindowSystemEvent has had an eventAccepted flag since 2014. Change-Id: Ia0aa795083cd98ece83a4c1cc010d3a25e2489fd Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/cocoa/qcocoawindow.mm | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index 35b7162346..a744a86695 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -1275,14 +1275,11 @@ void QCocoaWindow::windowWillClose() bool QCocoaWindow::windowShouldClose() { qCDebug(lcQpaWindow) << "QCocoaWindow::windowShouldClose" << window(); - // This callback should technically only determine if the window - // should (be allowed to) close, but since our QPA API to determine - // that also involves actually closing the window we do both at the - // same time, instead of doing the latter in windowWillClose. - bool accepted = false; - QWindowSystemInterface::handleCloseEvent(window(), &accepted); - QWindowSystemInterface::flushWindowSystemEvents(); - return accepted; + // This callback should technically only determine if the window + // should (be allowed to) close, but since our QPA API to determine + // that also involves actually closing the window we do both at the + // same time, instead of doing the latter in windowWillClose. + return QWindowSystemInterface::handleCloseEvent(window()); } // ----------------------------- QPA forwarding ----------------------------- -- cgit v1.2.3 From 425c59783c960e9f568b6c5e8920774ada9b87e5 Mon Sep 17 00:00:00 2001 From: Kirill Burtsev Date: Mon, 1 Jul 2019 18:44:39 +0200 Subject: Xcb: fix rounding error in reporting screen refresh rate Screen refresh rate might not be just integer but with decimal part like, for example, 59.97 Hz. Fix calculation from raw xcb data and its store type as it is qreal already for QScreen::refreshRate API. Task-number: QTBUG-73911 Change-Id: Ia0494e953176c2854f0ed42c4498a29cfef16106 Reviewed-by: Shawn Rutledge --- src/plugins/platforms/xcb/qxcbscreen.cpp | 2 +- src/plugins/platforms/xcb/qxcbscreen.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/xcb/qxcbscreen.cpp b/src/plugins/platforms/xcb/qxcbscreen.cpp index a5a2aeb9aa..0cf0942dab 100644 --- a/src/plugins/platforms/xcb/qxcbscreen.cpp +++ b/src/plugins/platforms/xcb/qxcbscreen.cpp @@ -790,7 +790,7 @@ void QXcbScreen::updateRefreshRate(xcb_randr_mode_t mode) xcb_randr_mode_info_t *modeInfo = modesIter.data; if (modeInfo->id == mode) { const uint32_t dotCount = modeInfo->htotal * modeInfo->vtotal; - m_refreshRate = (dotCount != 0) ? modeInfo->dot_clock / dotCount : 0; + m_refreshRate = (dotCount != 0) ? modeInfo->dot_clock / qreal(dotCount) : 0; m_mode = mode; break; } diff --git a/src/plugins/platforms/xcb/qxcbscreen.h b/src/plugins/platforms/xcb/qxcbscreen.h index ec3b07bfb7..914ce6307d 100644 --- a/src/plugins/platforms/xcb/qxcbscreen.h +++ b/src/plugins/platforms/xcb/qxcbscreen.h @@ -226,7 +226,7 @@ private: QRect m_availableGeometry; Qt::ScreenOrientation m_orientation = Qt::PrimaryOrientation; QXcbCursor *m_cursor; - int m_refreshRate = 60; + qreal m_refreshRate = 60.0; int m_pixelDensity = 1; QEdidParser m_edid; }; -- cgit v1.2.3 From 56029e1e98b8f019b344ae0c9a01d12a47d29866 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Br=C3=BCning?= Date: Mon, 7 Oct 2019 10:22:01 +0200 Subject: Blacklist Desktop GL for Mobile Intel 4 Series Express Chipset Using desktop GL with this graphics card causes crashes e.g. when using Qt WebEngine. Fixes: QTBUG-58772 Change-Id: I90e12aab4475c17be262e391ff0989cebf0b3ec4 Reviewed-by: Laszlo Agocs --- .../platforms/windows/openglblacklists/default.json | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/windows/openglblacklists/default.json b/src/plugins/platforms/windows/openglblacklists/default.json index 3cfa7e3856..e37351f9e0 100644 --- a/src/plugins/platforms/windows/openglblacklists/default.json +++ b/src/plugins/platforms/windows/openglblacklists/default.json @@ -152,6 +152,18 @@ "features": [ "disable_program_cache" ] - } + }, + { + "id": 13, + "description": "Disable DesktopGL on Windows with Mobile Intel(R) 4 Series Express Chipset Family graphics card (QTBUG-58772)", + "vendor_id": "0x8086", + "device_id": [ "0x2A42" ], + "os": { + "type": "win" + }, + "features": [ + "disable_desktopgl" + ] + } ] } -- cgit v1.2.3 From 38cf346bd70de6aaabfbf66ba159919591ce9098 Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Mon, 7 Oct 2019 11:19:01 +0200 Subject: QMacStyle::drawControl - lift the pool declaration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit out of switch/case - can help in case some NSControl is using autorelease and an application is calling drawControl too often. Fixes: QTBUG-78761 Change-Id: I2b55d533f52db16703dcc965920f4316fdf76734 Reviewed-by: Tor Arne Vestbø --- src/plugins/styles/mac/qmacstyle_mac.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/plugins') diff --git a/src/plugins/styles/mac/qmacstyle_mac.mm b/src/plugins/styles/mac/qmacstyle_mac.mm index b2bcdb3e5b..0a216e540d 100644 --- a/src/plugins/styles/mac/qmacstyle_mac.mm +++ b/src/plugins/styles/mac/qmacstyle_mac.mm @@ -3462,6 +3462,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter { Q_D(const QMacStyle); const AppearanceSync sync; + const QMacAutoReleasePool pool; QMacCGContext cg(p); QWindow *window = w && w->window() ? w->window()->windowHandle() : nullptr; d->resolveCurrentNSView(window); @@ -4326,7 +4327,6 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter break; case CE_ProgressBarContents: if (const QStyleOptionProgressBar *pb = qstyleoption_cast(opt)) { - QMacAutoReleasePool pool; const bool isIndeterminate = (pb->minimum == 0 && pb->maximum == 0); const bool vertical = pb->orientation == Qt::Vertical; const bool inverted = pb->invertedAppearance; -- cgit v1.2.3 From 6906b0647a2e1389a9eeeef0dd0f6354c9dd4206 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Sat, 5 Oct 2019 13:28:55 +0200 Subject: macOS: Pass required parameters to NSOpenSavePanelDelegate callbacks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I0e0322734a077e4ee948128f3ba6c074514ccbb9 Reviewed-by: Volker Hilsheimer Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm index 5f32400af0..03677ef0bc 100644 --- a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm +++ b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm @@ -214,7 +214,7 @@ static QString strippedText(QString s) NSString *filepath = info.filePath().toNSString(); NSURL *url = [NSURL fileURLWithPath:filepath isDirectory:info.isDir()]; bool selectable = (mOptions->acceptMode() == QFileDialogOptions::AcceptSave) - || [self panel:nil shouldEnableURL:url]; + || [self panel:mOpenPanel shouldEnableURL:url]; [self updateProperties]; [mSavePanel setNameFieldStringValue:selectable ? info.fileName().toNSString() : @""]; @@ -233,7 +233,7 @@ static QString strippedText(QString s) NSString *filepath = info.filePath().toNSString(); NSURL *url = [NSURL fileURLWithPath:filepath isDirectory:info.isDir()]; bool selectable = (mOptions->acceptMode() == QFileDialogOptions::AcceptSave) - || [self panel:nil shouldEnableURL:url]; + || [self panel:mSavePanel shouldEnableURL:url]; [mSavePanel setDirectoryURL: [NSURL fileURLWithPath:mCurrentDir]]; [mSavePanel setNameFieldStringValue:selectable ? info.fileName().toNSString() : @""]; @@ -263,7 +263,7 @@ static QString strippedText(QString s) NSString *filepath = info.filePath().toNSString(); NSURL *url = [NSURL fileURLWithPath:filepath isDirectory:info.isDir()]; bool selectable = (mOptions->acceptMode() == QFileDialogOptions::AcceptSave) - || [self panel:nil shouldEnableURL:url]; + || [self panel:mSavePanel shouldEnableURL:url]; [self updateProperties]; [mSavePanel setDirectoryURL: [NSURL fileURLWithPath:mCurrentDir]]; -- cgit v1.2.3 From 0e12c8b020d8bb54d214ecbab284429cc702e2d0 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Wed, 9 Oct 2019 12:40:10 +0200 Subject: Remove deprecated PE_IndicatorViewItemCheck and PE_FrameStatusBar They have been marked as deprecated since 5.13, and can be removed from Qt 6 codebase, which silences the respective compiler warnings. Change-Id: I3443c7bfa8db148b0b48957e2adc5eb131197faf Reviewed-by: Timur Pocheptsov --- src/plugins/styles/android/qandroidstyle.cpp | 2 +- src/plugins/styles/mac/qmacstyle_mac.mm | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/styles/android/qandroidstyle.cpp b/src/plugins/styles/android/qandroidstyle.cpp index 086df92322..1d0838daec 100644 --- a/src/plugins/styles/android/qandroidstyle.cpp +++ b/src/plugins/styles/android/qandroidstyle.cpp @@ -248,7 +248,7 @@ QAndroidStyle::ItemType QAndroidStyle::qtControl(QStyle::PrimitiveElement primit case QStyle::PE_FrameLineEdit: return QC_EditText; - case QStyle::PE_IndicatorViewItemCheck: + case QStyle::PE_IndicatorItemViewItemCheck: case QStyle::PE_IndicatorCheckBox: return QC_Checkbox; diff --git a/src/plugins/styles/mac/qmacstyle_mac.mm b/src/plugins/styles/mac/qmacstyle_mac.mm index b2bcdb3e5b..a2a24c529e 100644 --- a/src/plugins/styles/mac/qmacstyle_mac.mm +++ b/src/plugins/styles/mac/qmacstyle_mac.mm @@ -3211,7 +3211,7 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai CGContextRestoreGState(cg); break; } - case PE_IndicatorViewItemCheck: + case PE_IndicatorItemViewItemCheck: case PE_IndicatorRadioButton: case PE_IndicatorCheckBox: { const bool isEnabled = opt->state & State_Enabled; -- cgit v1.2.3 From ae7b21898273a83b4b2669b9d30a7f9777a7af99 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 7 Oct 2019 12:28:39 +0200 Subject: Windows QPA: Improve reliability of clipboard retrieval MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Clipboard retrieval sometimes fails due to the other application having the clipboard locked. Retry opening the clipboard. The choice of parameters is empirical, they have been observed to prevent failures for MS Office applications at least. Fixes: QTBUG-53979 Change-Id: Icbcaee149f0d377f33b222cdafbb2a21a7f1cf9d Reviewed-by: André de la Rocha Reviewed-by: Oliver Wolff --- src/plugins/platforms/windows/qwindowsclipboard.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/windows/qwindowsclipboard.cpp b/src/plugins/platforms/windows/qwindowsclipboard.cpp index b87e43f3f7..4e6d3306e1 100644 --- a/src/plugins/platforms/windows/qwindowsclipboard.cpp +++ b/src/plugins/platforms/windows/qwindowsclipboard.cpp @@ -115,12 +115,21 @@ static QDebug operator<<(QDebug d, const QMimeData *mimeData) IDataObject *QWindowsClipboardRetrievalMimeData::retrieveDataObject() const { + enum : int { attempts = 3 }; IDataObject * pDataObj = nullptr; - if (OleGetClipboard(&pDataObj) == S_OK) { - if (QWindowsContext::verbose > 1) - qCDebug(lcQpaMime) << __FUNCTION__ << pDataObj; - return pDataObj; + // QTBUG-53979, retry in case the other application has clipboard locked + for (int i = 1; i <= attempts; ++i) { + if (SUCCEEDED(OleGetClipboard(&pDataObj))) { + if (QWindowsContext::verbose > 1) + qCDebug(lcQpaMime) << __FUNCTION__ << pDataObj; + return pDataObj; + } + qCWarning(lcQpaMime, i == attempts + ? "Unable to obtain clipboard." + : "Retrying to obtain clipboard."); + QThread::msleep(50); } + return nullptr; } -- cgit v1.2.3 From aa3540b7be3dd0f5a96de1df5c4771d789127204 Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Wed, 9 Oct 2019 11:28:54 +0200 Subject: QMacStyle - fix the background color for tool button MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit when it's in 'ON' state ("inverted" color in 'Dark' appearance). Number are rather arbitrary and extracted with 'Digital Color Meter' app to make it look similar to the native panel (to be honest, this tool button on a toolbar not to be found in many native apps, they use different buttons anyway). Fixes: QTBUG-71526 Change-Id: Ie61e60b77f097f04550006612e4aab6f11bb954b Reviewed-by: Tor Arne Vestbø --- src/plugins/styles/mac/qmacstyle_mac.mm | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/styles/mac/qmacstyle_mac.mm b/src/plugins/styles/mac/qmacstyle_mac.mm index 0a216e540d..63dc49fd18 100644 --- a/src/plugins/styles/mac/qmacstyle_mac.mm +++ b/src/plugins/styles/mac/qmacstyle_mac.mm @@ -328,6 +328,20 @@ static const int closeButtonSize = 14; static const qreal closeButtonCornerRadius = 2.0; #endif // QT_CONFIG(tabbar) +#ifndef QT_NO_ACCESSIBILITY // This ifdef to avoid "unused function" warning. +QBrush brushForToolButton(bool isOnKeyWindow) +{ + // When a toolbutton in a toolbar is in the 'ON' state, we draw a + // partially transparent background. The colors must be different + // for 'Aqua' and 'DarkAqua' appearances though. + if (isDarkMode()) + return isOnKeyWindow ? QColor(73, 73, 73, 100) : QColor(56, 56, 56, 100); + + return isOnKeyWindow ? QColor(0, 0, 0, 28) : QColor(0, 0, 0, 21); +} +#endif // QT_NO_ACCESSIBILITY + + static const int headerSectionArrowHeight = 6; static const int headerSectionSeparatorInset = 2; @@ -5603,8 +5617,7 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex if (view) isKey = [view.window isKeyWindow]; - QBrush brush(isKey ? QColor(0, 0, 0, 28) - : QColor(0, 0, 0, 21)); + QBrush brush(brushForToolButton(isKey)); QPainterPath path; path.addRoundedRect(QRectF(tb->rect.x(), tb->rect.y(), tb->rect.width(), tb->rect.height() + 4), 4, 4); p->setRenderHint(QPainter::Antialiasing); -- cgit v1.2.3 From e4e3be75014dcd34f480811c9d423b1d2123a395 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 4 Oct 2019 15:54:03 +0200 Subject: macOS: Simplify reflection delegate handling in QCocoaApplicationDelegate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sending a message to a nil object returns nil, so there's no reason to check the delegate before calling respondsToSelector, and we can use the implicit _cmd argument to pass along the selector for the method we're in. For applicationShouldTerminate, if there's a reflection delegate but it doesn't answer to applicationShouldTerminate it makes no sense to skip our own logic. Change-Id: Iafcd883a5c8cec1b35d2f95238de55eff060d71f Reviewed-by: Morten Johan Sørvig Reviewed-by: Volker Hilsheimer --- .../platforms/cocoa/qcocoaapplicationdelegate.mm | 35 +++++++--------------- 1 file changed, 10 insertions(+), 25 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm index 2cf6672da9..da80c6a0e4 100644 --- a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm +++ b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm @@ -171,12 +171,8 @@ QT_USE_NAMESPACE // This function will only be called when NSApp is actually running. - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender { - // The reflection delegate gets precedence - if (reflectionDelegate) { - if ([reflectionDelegate respondsToSelector:@selector(applicationShouldTerminate:)]) - return [reflectionDelegate applicationShouldTerminate:sender]; - return NSTerminateNow; - } + if ([reflectionDelegate respondsToSelector:_cmd]) + return [reflectionDelegate applicationShouldTerminate:sender]; if ([self canQuit]) { if (!startedQuit) { @@ -282,26 +278,22 @@ QT_USE_NAMESPACE QWindowSystemInterface::handleFileOpenEvent(qtFileName); } - if (reflectionDelegate && - [reflectionDelegate respondsToSelector:@selector(application:openFiles:)]) + if ([reflectionDelegate respondsToSelector:_cmd]) [reflectionDelegate application:sender openFiles:filenames]; } - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender { - // If we have a reflection delegate, that will get to call the shots. - if (reflectionDelegate - && [reflectionDelegate respondsToSelector: - @selector(applicationShouldTerminateAfterLastWindowClosed:)]) + if ([reflectionDelegate respondsToSelector:_cmd]) return [reflectionDelegate applicationShouldTerminateAfterLastWindowClosed:sender]; + return NO; // Someday qApp->quitOnLastWindowClosed(); when QApp and NSApp work closer together. } - (void)applicationDidBecomeActive:(NSNotification *)notification { - if (reflectionDelegate - && [reflectionDelegate respondsToSelector:@selector(applicationDidBecomeActive:)]) + if ([reflectionDelegate respondsToSelector:_cmd]) [reflectionDelegate applicationDidBecomeActive:notification]; QWindowSystemInterface::handleApplicationStateChanged(Qt::ApplicationActive); @@ -309,8 +301,7 @@ QT_USE_NAMESPACE - (void)applicationDidResignActive:(NSNotification *)notification { - if (reflectionDelegate - && [reflectionDelegate respondsToSelector:@selector(applicationDidResignActive:)]) + if ([reflectionDelegate respondsToSelector:_cmd]) [reflectionDelegate applicationDidResignActive:notification]; QWindowSystemInterface::handleApplicationStateChanged(Qt::ApplicationInactive); @@ -318,10 +309,7 @@ QT_USE_NAMESPACE - (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag { - Q_UNUSED(theApplication); - Q_UNUSED(flag); - if (reflectionDelegate - && [reflectionDelegate respondsToSelector:@selector(applicationShouldHandleReopen:hasVisibleWindows:)]) + if ([reflectionDelegate respondsToSelector:_cmd]) return [reflectionDelegate applicationShouldHandleReopen:theApplication hasVisibleWindows:flag]; /* @@ -354,16 +342,13 @@ QT_USE_NAMESPACE - (BOOL)respondsToSelector:(SEL)aSelector { - BOOL result = [super respondsToSelector:aSelector]; - if (!result && reflectionDelegate) - result = [reflectionDelegate respondsToSelector:aSelector]; - return result; + return [super respondsToSelector:aSelector] || [reflectionDelegate respondsToSelector:aSelector]; } - (void)forwardInvocation:(NSInvocation *)invocation { SEL invocationSelector = [invocation selector]; - if (reflectionDelegate && [reflectionDelegate respondsToSelector:invocationSelector]) + if ([reflectionDelegate respondsToSelector:invocationSelector]) [invocation invokeWithTarget:reflectionDelegate]; else [self doesNotRecognizeSelector:invocationSelector]; -- cgit v1.2.3 From 35713ef3fffeb7476a8a72490caeffbda81c4f09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 4 Oct 2019 15:14:56 +0200 Subject: macOS: Don't override event handler for kAEQuitApplication MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The implementation of the default handler, [NSApp _handleAEQuit], does a lot more than just terminating the application, including sending NSWorkspaceWillPowerOffNotification if appropriate, and deals appropriately with state restoration. Change-Id: If725838fc0f40d09a0b8885eb3e7239499d8fea0 Fixes: QTBUG-18624 Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm index da80c6a0e4..2df85c791b 100644 --- a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm +++ b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm @@ -223,10 +223,6 @@ QT_USE_NAMESPACE application depends on. */ NSAppleEventManager *eventManager = [NSAppleEventManager sharedAppleEventManager]; - [eventManager setEventHandler:self - andSelector:@selector(appleEventQuit:withReplyEvent:) - forEventClass:kCoreEventClass - andEventID:kAEQuitApplication]; [eventManager setEventHandler:self andSelector:@selector(getUrl:withReplyEvent:) forEventClass:kInternetEventClass @@ -237,7 +233,6 @@ QT_USE_NAMESPACE - (void)removeAppleEventHandlers { NSAppleEventManager *eventManager = [NSAppleEventManager sharedAppleEventManager]; - [eventManager removeEventHandlerForEventClass:kCoreEventClass andEventID:kAEQuitApplication]; [eventManager removeEventHandlerForEventClass:kInternetEventClass andEventID:kAEGetURL]; } @@ -360,14 +355,6 @@ QT_USE_NAMESPACE NSString *urlString = [[event paramDescriptorForKeyword:keyDirectObject] stringValue]; QWindowSystemInterface::handleFileOpenEvent(QUrl(QString::fromNSString(urlString))); } - -- (void)appleEventQuit:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent -{ - Q_UNUSED(event); - Q_UNUSED(replyEvent); - [NSApp terminate:self]; -} - @end @implementation QCocoaApplicationDelegate (Menus) -- cgit v1.2.3 From eaf4911db29a82b3d94826a8ff09afe075a2b636 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 12 Sep 2019 13:29:25 +0200 Subject: macOS: Optionally flush sub-layers via sub-image copies of the backingstore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When we're flushing the backingstore to sub-views with their own layers we don't want to pay the cost of uploading the whole backingstore to the GPU in the case where we're dealing with a discrete GPU. To work around this we make a copy of the appropriate part of the surfcace. This results in additional copies of the data, and will need further investigation to limit these. Task-number: QTBUG-77447 Change-Id: I318ae80e433dd7b0a55fd5a598b19f114d8bd28e Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/cocoa/qcocoabackingstore.mm | 29 +++++++++++++++-------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/cocoa/qcocoabackingstore.mm b/src/plugins/platforms/cocoa/qcocoabackingstore.mm index eb316c53a8..b17302a640 100644 --- a/src/plugins/platforms/cocoa/qcocoabackingstore.mm +++ b/src/plugins/platforms/cocoa/qcocoabackingstore.mm @@ -560,17 +560,26 @@ void QCALayerBackingStore::flush(QWindow *flushedWindow, const QRegion ®ion, flushedView.layer.contents = nil; } - qCInfo(lcQpaBackingStore) << "Flushing" << backBufferSurface - << "to" << flushedView.layer << "of" << flushedView; - - flushedView.layer.contents = backBufferSurface; + if (flushedView == backingStoreView) { + qCInfo(lcQpaBackingStore) << "Flushing" << backBufferSurface + << "to" << flushedView.layer << "of" << flushedView; + flushedView.layer.contents = backBufferSurface; + } else { + auto subviewRect = [flushedView convertRect:flushedView.bounds toView:backingStoreView]; + auto scale = flushedView.layer.contentsScale; + subviewRect = CGRectApplyAffineTransform(subviewRect, CGAffineTransformMakeScale(scale, scale)); + + // We make a copy of the image data up front, which means we don't + // need to mark the IOSurface as being in use. FIXME: Investigate + // if there's a cheaper way to get sub-image data to a layer. + m_buffers.back()->lock(QPlatformGraphicsBuffer::SWReadAccess); + QImage subImage = m_buffers.back()->asImage()->copy(QRectF::fromCGRect(subviewRect).toRect()); + m_buffers.back()->unlock(); - if (flushedView != backingStoreView) { - const CGSize backingStoreSize = backingStoreView.bounds.size; - flushedView.layer.contentsRect = CGRectApplyAffineTransform( - [flushedView convertRect:flushedView.bounds toView:backingStoreView], - // The contentsRect is in unit coordinate system - CGAffineTransformMakeScale(1.0 / backingStoreSize.width, 1.0 / backingStoreSize.height)); + qCInfo(lcQpaBackingStore) << "Flushing" << subImage + << "to" << flushedView.layer << "of subview" << flushedView; + QCFType cgImage = subImage.toCGImage(); + flushedView.layer.contents = (__bridge id)static_cast(cgImage); } // Since we may receive multiple flushes before a new frame is started, we do not -- cgit v1.2.3 From 58c4fa1061d07d35805bbb5cc8af7b36129d4509 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Thu, 10 Oct 2019 16:07:55 +0200 Subject: JPEG image handler: drop a use of "volatile" The reading code protects a local variable with volatile. In this case the only possible reason to apply volatile seems to be protecting the variable across the subsequent setjmp/longjmp. However, the variable is never accessed after the longjmp (the function returns). So, drop the volatile. Change-Id: Ibecb11a9edcc6027b2fd52b555287ad53375a5d0 Reviewed-by: Allan Sandfeld Jensen Reviewed-by: Edward Welbourne --- src/plugins/imageformats/jpeg/qjpeghandler.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/imageformats/jpeg/qjpeghandler.cpp b/src/plugins/imageformats/jpeg/qjpeghandler.cpp index 1f1675e490..a09e6dfd5a 100644 --- a/src/plugins/imageformats/jpeg/qjpeghandler.cpp +++ b/src/plugins/imageformats/jpeg/qjpeghandler.cpp @@ -248,13 +248,12 @@ static bool ensureValidImage(QImage *dest, struct jpeg_decompress_struct *info, static bool read_jpeg_image(QImage *outImage, QSize scaledSize, QRect scaledClipRect, - QRect clipRect, volatile int inQuality, + QRect clipRect, int quality, Rgb888ToRgb32Converter converter, j_decompress_ptr info, struct my_error_mgr* err ) { if (!setjmp(err->setjmp_buffer)) { // -1 means default quality. - int quality = inQuality; if (quality < 0) quality = 75; -- cgit v1.2.3 From 8aa3329a7186b087163f68ef880c8ffdd47d01bf Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Thu, 10 Oct 2019 12:20:05 +0200 Subject: JPEG image handler: remove undefined behavior from setjmp/longjmp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The JPEG writing code features a setjmp/longjmp pair to deal with error handling. In doing so, it creates UB by touching local objects after the setjmp and then after the corresponding longjmp. The rules on what we can do are quite strict: objects that are 1) local to the function calling setjmp; 2) not qualified with volatile; 3) written into after the setjmp; have indeterminate state after the corresponding longjmp call (man 3 longjmp, C 2x draft N2346 §7.13.2.1.2). Not making any assumptions on any compiler used: let's just say that using them in any way is UB. Luckily, no compiler exploits this (yet), and the code works just fine. But we know the drill -- never play this game against compilers, because you will lose. So: we have a couple of those objects around in the writing routine (cinfo, row_pointer), that violate the rules above. Unfortunately we can't simply mark them as volatile: libjpeg's API expects them not to be volatile. Casting volatileness away and then touching an object in any way is undefined behavior out of the bat (C 2x draft N2346 §6.7.3.7, C++ [dcl.type.cv]). Given the code needs to do 3), and we can't work around 2), then work around 1): define them to be non-local to the function doing the setjmp. Introduce a small helper that declares such objects and then calls the function doing the actual work, with the setjmp/longjmp. An overall alternative would be of course stop using setjmp/longjmp, but libjpeg's API doesn't really seem to allow this -- when the library calls user's error handler, that error handler is expected not to return to the library (so a longjmp or an exit/abort are mandatory). Side note: all the code using libjpeg I've researched to debug this has this very same strange issue: * GDK-pixbuf's [1] * ImageMagick's [2] * and even libjpeg's [3] and libjpeg-turbo's [4] own examples. [1] https://github.com/GNOME/gdk-pixbuf/blob/master/gdk-pixbuf/io-jpeg.c#L581 [2] https://github.com/ImageMagick/ImageMagick/blob/master/coders/jpeg.c#L2338 [3] https://www.ijg.org/ [4] https://github.com/libjpeg-turbo/libjpeg-turbo/blob/master/example.txt#L331 Change-Id: I34a810db468f73423478cd3ac71b888f4b11cb28 Reviewed-by: Allan Sandfeld Jensen Reviewed-by: Edward Welbourne --- src/plugins/imageformats/jpeg/qjpeghandler.cpp | 34 ++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/imageformats/jpeg/qjpeghandler.cpp b/src/plugins/imageformats/jpeg/qjpeghandler.cpp index a09e6dfd5a..dd01138722 100644 --- a/src/plugins/imageformats/jpeg/qjpeghandler.cpp +++ b/src/plugins/imageformats/jpeg/qjpeghandler.cpp @@ -528,7 +528,14 @@ static inline void write_icc_profile(const QImage &image, j_compress_ptr cinfo) } } -static bool write_jpeg_image(const QImage &image, QIODevice *device, volatile int sourceQuality, const QString &description, bool optimize, bool progressive) +static bool do_write_jpeg_image(struct jpeg_compress_struct &cinfo, + JSAMPROW *row_pointer, + const QImage &image, + QIODevice *device, + int sourceQuality, + const QString &description, + bool optimize, + bool progressive) { bool success = false; const QVector cmap = image.colorTable(); @@ -536,10 +543,6 @@ static bool write_jpeg_image(const QImage &image, QIODevice *device, volatile in if (image.format() == QImage::Format_Invalid || image.format() == QImage::Format_Alpha8) return false; - struct jpeg_compress_struct cinfo; - JSAMPROW row_pointer[1]; - row_pointer[0] = 0; - struct my_jpeg_destination_mgr *iod_dest = new my_jpeg_destination_mgr(device); struct my_error_mgr jerr; @@ -712,6 +715,27 @@ static bool write_jpeg_image(const QImage &image, QIODevice *device, volatile in } delete iod_dest; + return success; +} + +static bool write_jpeg_image(const QImage &image, + QIODevice *device, + int sourceQuality, + const QString &description, + bool optimize, + bool progressive) +{ + // protect these objects from the setjmp/longjmp pair inside + // do_write_jpeg_image (by making them non-local). + struct jpeg_compress_struct cinfo; + JSAMPROW row_pointer[1]; + row_pointer[0] = 0; + + const bool success = do_write_jpeg_image(cinfo, row_pointer, + image, device, + sourceQuality, description, + optimize, progressive); + delete [] row_pointer[0]; return success; } -- cgit v1.2.3 From b43f5ed2da868eab17881872b165ae048d8a1d88 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sun, 6 Oct 2019 18:53:29 +0200 Subject: QMYSQL: remove support for MySql 4.x MySql 5.0 was released 2005 so it's time to remove support for MySql 4.x 14 years later. [ChangeLog][QtSql][QMYSQL] Removed support for MySql < 5.0 since 5.0 was released 14 years ago. Change-Id: I45005accdffefbd9338ac0e710512a4c7ea8e09e Reviewed-by: Andy Shaw --- src/plugins/sqldrivers/mysql/qsql_mysql.cpp | 156 +++++----------------------- 1 file changed, 26 insertions(+), 130 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/sqldrivers/mysql/qsql_mysql.cpp b/src/plugins/sqldrivers/mysql/qsql_mysql.cpp index febbe58506..0e195cfdb4 100644 --- a/src/plugins/sqldrivers/mysql/qsql_mysql.cpp +++ b/src/plugins/sqldrivers/mysql/qsql_mysql.cpp @@ -65,16 +65,7 @@ Q_DECLARE_METATYPE(MYSQL_RES*) Q_DECLARE_METATYPE(MYSQL*) - -#if MYSQL_VERSION_ID >= 40108 Q_DECLARE_METATYPE(MYSQL_STMT*) -#endif - -#if MYSQL_VERSION_ID >= 40100 -# define Q_CLIENT_MULTI_STATEMENTS CLIENT_MULTI_STATEMENTS -#else -# define Q_CLIENT_MULTI_STATEMENTS 0 -#endif // MySQL above version 8 removed my_bool typedef while MariaDB kept it, // by redefining it we can regain source compatibility. @@ -199,10 +190,8 @@ protected: bool nextResult() override; void detachFromResultSet() override; -#if MYSQL_VERSION_ID >= 40108 bool prepare(const QString &stmt) override; bool exec() override; -#endif }; class QMYSQLResultPrivate: public QSqlResultPrivate @@ -217,9 +206,7 @@ public: result(0), rowsAffected(0), hasBlobs(false) -#if MYSQL_VERSION_ID >= 40108 , stmt(0), meta(0), inBinds(0), outBinds(0) -#endif , preparedQuery(false) { } @@ -247,13 +234,11 @@ public: QVector fields; -#if MYSQL_VERSION_ID >= 40108 MYSQL_STMT* stmt; MYSQL_RES* meta; MYSQL_BIND *inBinds; MYSQL_BIND *outBinds; -#endif bool preparedQuery; }; @@ -261,11 +246,9 @@ public: #if QT_CONFIG(textcodec) static QTextCodec* codec(MYSQL* mysql) { -#if MYSQL_VERSION_ID >= 32321 QTextCodec* heuristicCodec = QTextCodec::codecForName(mysql_character_set_name(mysql)); if (heuristicCodec) return heuristicCodec; -#endif return QTextCodec::codecForLocale(); } #endif // textcodec @@ -350,8 +333,6 @@ static QSqlField qToField(MYSQL_FIELD *field, QTextCodec *tc) return f; } -#if MYSQL_VERSION_ID >= 40108 - static QSqlError qMakeStmtError(const QString& err, QSqlError::ErrorType type, MYSQL_STMT* stmt) { @@ -445,7 +426,6 @@ bool QMYSQLResultPrivate::bindInValues() } return true; } -#endif QMYSQLResult::QMYSQLResult(const QMYSQLDriver* db) : QSqlResult(*new QMYSQLResultPrivate(this, db)) @@ -460,11 +440,9 @@ QMYSQLResult::~QMYSQLResult() QVariant QMYSQLResult::handle() const { Q_D(const QMYSQLResult); -#if MYSQL_VERSION_ID >= 40108 if(d->preparedQuery) return d->meta ? QVariant::fromValue(d->meta) : QVariant::fromValue(d->stmt); else -#endif return QVariant::fromValue(d->result); } @@ -476,15 +454,12 @@ void QMYSQLResult::cleanup() // must iterate trough leftover result sets from multi-selects or stored procedures // if this isn't done subsequent queries will fail with "Commands out of sync" -#if MYSQL_VERSION_ID >= 40100 while (driver() && d->drv_d_func()->mysql && mysql_next_result(d->drv_d_func()->mysql) == 0) { MYSQL_RES *res = mysql_store_result(d->drv_d_func()->mysql); if (res) mysql_free_result(res); } -#endif -#if MYSQL_VERSION_ID >= 40108 if (d->stmt) { if (mysql_stmt_close(d->stmt)) qWarning("QMYSQLResult::cleanup: unable to free statement handle"); @@ -509,7 +484,6 @@ void QMYSQLResult::cleanup() delete[] d->inBinds; d->inBinds = 0; } -#endif d->hasBlobs = false; d->fields.clear(); @@ -536,7 +510,6 @@ bool QMYSQLResult::fetch(int i) if (at() == i) return true; if (d->preparedQuery) { -#if MYSQL_VERSION_ID >= 40108 mysql_stmt_data_seek(d->stmt, i); int nRC = mysql_stmt_fetch(d->stmt); @@ -550,9 +523,6 @@ bool QMYSQLResult::fetch(int i) "Unable to fetch data"), QSqlError::StatementError, d->stmt)); return false; } -#else - return false; -#endif } else { mysql_data_seek(d->result, i); d->row = mysql_fetch_row(d->result); @@ -570,7 +540,6 @@ bool QMYSQLResult::fetchNext() if (!driver()) return false; if (d->preparedQuery) { -#if MYSQL_VERSION_ID >= 40108 int nRC = mysql_stmt_fetch(d->stmt); if (nRC) { #ifdef MYSQL_DATA_TRUNCATED @@ -582,9 +551,6 @@ bool QMYSQLResult::fetchNext() "Unable to fetch data"), QSqlError::StatementError, d->stmt)); return false; } -#else - return false; -#endif } else { d->row = mysql_fetch_row(d->result); if (!d->row) @@ -607,11 +573,7 @@ bool QMYSQLResult::fetchLast() my_ulonglong numRows; if (d->preparedQuery) { -#if MYSQL_VERSION_ID >= 40108 numRows = mysql_stmt_num_rows(d->stmt); -#else - numRows = 0; -#endif } else { numRows = mysql_num_rows(d->result); } @@ -788,11 +750,7 @@ int QMYSQLResult::size() Q_D(const QMYSQLResult); if (driver() && isSelect()) if (d->preparedQuery) -#if MYSQL_VERSION_ID >= 40108 return mysql_stmt_num_rows(d->stmt); -#else - return -1; -#endif else return int(mysql_num_rows(d->result)); else @@ -821,11 +779,9 @@ QVariant QMYSQLResult::lastInsertId() const return QVariant(); if (d->preparedQuery) { -#if MYSQL_VERSION_ID >= 40108 quint64 id = mysql_stmt_insert_id(d->stmt); if (id) return QVariant(id); -#endif } else { quint64 id = mysql_insert_id(d->drv_d_func()->mysql); if (id) @@ -842,11 +798,7 @@ QSqlRecord QMYSQLResult::record() const if (!isActive() || !isSelect() || !driver()) return info; -#if MYSQL_VERSION_ID >= 40108 res = d->preparedQuery ? d->meta : d->result; -#else - res = d->result; -#endif if (!mysql_errno(d->drv_d_func()->mysql)) { mysql_field_seek(res, 0); @@ -865,7 +817,7 @@ bool QMYSQLResult::nextResult() Q_D(QMYSQLResult); if (!driver()) return false; -#if MYSQL_VERSION_ID >= 40100 + setAt(-1); setActive(false); @@ -908,9 +860,6 @@ bool QMYSQLResult::nextResult() setActive(true); return true; -#else - return false; -#endif } void QMYSQLResult::virtual_hook(int id, void *data) @@ -918,9 +867,6 @@ void QMYSQLResult::virtual_hook(int id, void *data) QSqlResult::virtual_hook(id, data); } - -#if MYSQL_VERSION_ID >= 40108 - static MYSQL_TIME *toMySqlDate(QDate date, QTime time, QVariant::Type type) { Q_ASSERT(type == QVariant::Time || type == QVariant::Date @@ -949,7 +895,7 @@ bool QMYSQLResult::prepare(const QString& query) Q_D(QMYSQLResult); if (!driver()) return false; -#if MYSQL_VERSION_ID >= 40108 + cleanup(); if (!d->drv_d_func()->preparedQuerysEnabled) return QSqlResult::prepare(query); @@ -983,9 +929,6 @@ bool QMYSQLResult::prepare(const QString& query) setSelect(d->bindInValues()); d->preparedQuery = true; return true; -#else - return false; -#endif } bool QMYSQLResult::exec() @@ -1155,7 +1098,7 @@ bool QMYSQLResult::exec() setActive(true); return true; } -#endif + ///////////////////////////////////////////////////////// static int qMySqlConnectionCount = 0; @@ -1164,18 +1107,16 @@ static bool qMySqlInitHandledByUser = false; static void qLibraryInit() { #ifndef Q_NO_MYSQL_EMBEDDED -# if MYSQL_VERSION_ID >= 40000 if (qMySqlInitHandledByUser || qMySqlConnectionCount > 1) return; -# if (MYSQL_VERSION_ID >= 40110 && MYSQL_VERSION_ID < 50000) || MYSQL_VERSION_ID >= 50003 +# if MYSQL_VERSION_ID >= 50003 if (mysql_library_init(0, 0, 0)) { # else if (mysql_server_init(0, 0, 0)) { # endif qWarning("QMYSQLDriver::qServerInit: unable to start server."); } -# endif // MYSQL_VERSION_ID #endif // Q_NO_MYSQL_EMBEDDED #if defined(MARIADB_BASE_VERSION) || defined(MARIADB_VERSION_ID) @@ -1187,12 +1128,10 @@ static void qLibraryEnd() { #if !defined(MARIADB_BASE_VERSION) && !defined(MARIADB_VERSION_ID) # if !defined(Q_NO_MYSQL_EMBEDDED) -# if MYSQL_VERSION_ID > 40000 -# if (MYSQL_VERSION_ID >= 40110 && MYSQL_VERSION_ID < 50000) || MYSQL_VERSION_ID >= 50003 - mysql_library_end(); -# else - mysql_server_end(); -# endif +# if MYSQL_VERSION_ID >= 50003 + mysql_library_end(); +# else + mysql_server_end(); # endif # endif #endif @@ -1271,17 +1210,9 @@ bool QMYSQLDriver::hasFeature(DriverFeature f) const return true; case PreparedQueries: case PositionalPlaceholders: -#if MYSQL_VERSION_ID >= 40108 return d->preparedQuerysEnabled; -#else - return false; -#endif case MultipleResultSets: -#if MYSQL_VERSION_ID >= 40100 return true; -#else - return false; -#endif } return false; } @@ -1322,7 +1253,7 @@ bool QMYSQLDriver::open(const QString& db, we have to enable CLIEN_MULTI_STATEMENTS here, otherwise _any_ stored procedure call will fail. */ - unsigned int optionFlags = Q_CLIENT_MULTI_STATEMENTS; + unsigned int optionFlags = CLIENT_MULTI_STATEMENTS; const QStringList opts(connOpts.split(QLatin1Char(';'), QString::SkipEmptyParts)); QString unixSocket; QString sslCert; @@ -1330,12 +1261,10 @@ bool QMYSQLDriver::open(const QString& db, QString sslKey; QString sslCAPath; QString sslCipher; -#if MYSQL_VERSION_ID >= 50000 my_bool reconnect=false; uint connectTimeout = 0; uint readTimeout = 0; uint writeTimeout = 0; -#endif // extract the real options from the string for (int i = 0; i < opts.count(); ++i) { @@ -1346,18 +1275,15 @@ bool QMYSQLDriver::open(const QString& db, QString opt = tmp.left(idx).simplified(); if (opt == QLatin1String("UNIX_SOCKET")) unixSocket = val; -#if MYSQL_VERSION_ID >= 50000 else if (opt == QLatin1String("MYSQL_OPT_RECONNECT")) { if (val == QLatin1String("TRUE") || val == QLatin1String("1") || val.isEmpty()) reconnect = true; - } else if (opt == QLatin1String("MYSQL_OPT_CONNECT_TIMEOUT")) { + } else if (opt == QLatin1String("MYSQL_OPT_CONNECT_TIMEOUT")) connectTimeout = val.toInt(); - } else if (opt == QLatin1String("MYSQL_OPT_READ_TIMEOUT")) { + else if (opt == QLatin1String("MYSQL_OPT_READ_TIMEOUT")) readTimeout = val.toInt(); - } else if (opt == QLatin1String("MYSQL_OPT_WRITE_TIMEOUT")) { + else if (opt == QLatin1String("MYSQL_OPT_WRITE_TIMEOUT")) writeTimeout = val.toInt(); - } -#endif else if (opt == QLatin1String("SSL_KEY")) sslKey = val; else if (opt == QLatin1String("SSL_CERT")) @@ -1442,7 +1368,7 @@ bool QMYSQLDriver::open(const QString& db, return false; } -#if (MYSQL_VERSION_ID >= 40113 && MYSQL_VERSION_ID < 50000) || MYSQL_VERSION_ID >= 50007 +#if MYSQL_VERSION_ID >= 50007 if (mysql_get_client_version() >= 50503 && mysql_get_server_version(d->mysql) >= 50503) { // force the communication to be utf8mb4 (only utf8mb4 supports 4-byte characters) mysql_set_character_set(d->mysql, "utf8mb4"); @@ -1457,20 +1383,15 @@ bool QMYSQLDriver::open(const QString& db, d->tc = codec(d->mysql); #endif } -#endif +#endif // MYSQL_VERSION_ID >= 50007 -#if MYSQL_VERSION_ID >= 40108 d->preparedQuerysEnabled = mysql_get_client_version() >= 40108 && mysql_get_server_version(d->mysql) >= 40100; -#else - d->preparedQuerysEnabled = false; -#endif #if QT_CONFIG(thread) mysql_thread_init(); #endif - setOpen(true); setOpenError(false); return true; @@ -1499,46 +1420,21 @@ QStringList QMYSQLDriver::tables(QSql::TableType type) const { Q_D(const QMYSQLDriver); QStringList tl; -#if MYSQL_VERSION_ID >= 40100 - if( mysql_get_server_version(d->mysql) < 50000) - { -#endif - if (!isOpen()) - return tl; - if (!(type & QSql::Tables)) - return tl; - - MYSQL_RES* tableRes = mysql_list_tables(d->mysql, NULL); - MYSQL_ROW row; - int i = 0; - while (tableRes) { - mysql_data_seek(tableRes, i); - row = mysql_fetch_row(tableRes); - if (!row) - break; - tl.append(toUnicode(d->tc, row[0])); - i++; - } - mysql_free_result(tableRes); -#if MYSQL_VERSION_ID >= 40100 - } else { - QSqlQuery q(createResult()); - if(type & QSql::Tables) { - QString sql = QLatin1String("select table_name from information_schema.tables where table_schema = '") + QLatin1String(d->mysql->db) + QLatin1String("' and table_type = 'BASE TABLE'"); - q.exec(sql); + QSqlQuery q(createResult()); + if (type & QSql::Tables) { + QString sql = QLatin1String("select table_name from information_schema.tables where table_schema = '") + QLatin1String(d->mysql->db) + QLatin1String("' and table_type = 'BASE TABLE'"); + q.exec(sql); - while(q.next()) - tl.append(q.value(0).toString()); - } - if(type & QSql::Views) { - QString sql = QLatin1String("select table_name from information_schema.tables where table_schema = '") + QLatin1String(d->mysql->db) + QLatin1String("' and table_type = 'VIEW'"); - q.exec(sql); + while (q.next()) + tl.append(q.value(0).toString()); + } + if (type & QSql::Views) { + QString sql = QLatin1String("select table_name from information_schema.tables where table_schema = '") + QLatin1String(d->mysql->db) + QLatin1String("' and table_type = 'VIEW'"); + q.exec(sql); - while(q.next()) - tl.append(q.value(0).toString()); - } + while (q.next()) + tl.append(q.value(0).toString()); } -#endif return tl; } -- cgit v1.2.3