From 811465032b226d41fc5dd6971bed590b8af3a0a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Fri, 9 Aug 2019 12:25:05 +0200 Subject: =?UTF-8?q?macOS:=20Don=E2=80=99t=20show=20hidden=20windows=20whil?= =?UTF-8?q?e=20z-ordering?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Calling [NSWindow orderBack] will make the window visible again, and will e.g. bring back closed menus on application modality changes. Fixes: QTBUG-77281 Change-Id: I2f89b852ea9f8ab34c709cec96d93fe305984fb9 Reviewed-by: Timur Pocheptsov Reviewed-by: Tor Arne Vestbø (cherry picked from commit 3729695cc9d550e831567772441ad55bd767ab1a) --- src/plugins/platforms/cocoa/qcocoawindowmanager.mm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/plugins/platforms/cocoa/qcocoawindowmanager.mm b/src/plugins/platforms/cocoa/qcocoawindowmanager.mm index 879bfaa546..9c45d8c7fc 100644 --- a/src/plugins/platforms/cocoa/qcocoawindowmanager.mm +++ b/src/plugins/platforms/cocoa/qcocoawindowmanager.mm @@ -92,7 +92,8 @@ void QCocoaWindowManager::modalSessionChanged() if (NSApp.modalWindow) { // Lower window to that of the modal windows, but no less nativeWindow.level = NSModalPanelWindowLevel; - [nativeWindow orderBack:nil]; + if ([nativeWindow isVisible]) + [nativeWindow orderBack:nil]; } else { // Restore window's natural window level, whatever that was nativeWindow.level = naturalWindowLevel; -- cgit v1.2.3 From a9b9a881344239781e5894f2dd3d0af90ffbb4ba Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Tue, 6 Aug 2019 13:15:35 +0200 Subject: eglfs: Fix raster windows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also sanitize the initial WebAssembly hack. Both eglfs and wasm lack the concept of true raster windows. A QWindow with RasterSurface is rendered with OpenGL no matter what. The two platforms took two different approaches to work around the rest of the machinery: - wasm disabled the QOpenGLContext warning for non-OpenGL QWindows, - eglfs forced the QWindow surfaceType to OpenGLSurface whenever it was originally set to RasterSurface. Now, the latter breaks since c4e9eabc309a275efc222f4127f31ba4677259b7, leaving all raster window applications failing on eglfs, because flush in the backingstore is now checking the surface type and disallows OpenGLSurface windows. (just like how QOpenGLContext disallows RasterSurface windows) To solve all this correctly, introduce a new platform capability, OpenGLOnRasterSurface, and remove the special handling in the platform plugins. Change-Id: I7785dfb1c955577bbdccdc14ebaaac5babdec57c Fixes: QTBUG-77100 Reviewed-by: Tor Arne Vestbø (cherry picked from commit 53a6f7b7836ef5084106ed63f6745c20d663affa) Reviewed-by: Jukka Jokiniva --- src/gui/kernel/qopenglcontext.cpp | 3 --- src/gui/kernel/qplatformintegration.cpp | 3 +++ src/gui/kernel/qplatformintegration.h | 3 ++- src/gui/kernel/qsurface.cpp | 6 ++++++ src/plugins/platforms/eglfs/api/qeglfsintegration.cpp | 1 + src/plugins/platforms/eglfs/api/qeglfswindow.cpp | 9 ++------- src/plugins/platforms/eglfs/api/qeglfswindow_p.h | 1 - src/plugins/platforms/wasm/qwasmintegration.cpp | 1 + 8 files changed, 15 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/gui/kernel/qopenglcontext.cpp b/src/gui/kernel/qopenglcontext.cpp index b677afc526..3d9f1309c9 100644 --- a/src/gui/kernel/qopenglcontext.cpp +++ b/src/gui/kernel/qopenglcontext.cpp @@ -976,11 +976,8 @@ bool QOpenGLContext::makeCurrent(QSurface *surface) if (!surface->surfaceHandle()) return false; if (!surface->supportsOpenGL()) { -#ifndef Q_OS_WASM // ### work around the WASM platform plugin using QOpenGLContext with raster surfaces. - // see QTBUG-70076 qWarning() << "QOpenGLContext::makeCurrent() called with non-opengl surface" << surface; return false; -#endif } if (!d->platformGLContext->makeCurrent(surface->surfaceHandle())) diff --git a/src/gui/kernel/qplatformintegration.cpp b/src/gui/kernel/qplatformintegration.cpp index 490cfc6178..b3d3db0751 100644 --- a/src/gui/kernel/qplatformintegration.cpp +++ b/src/gui/kernel/qplatformintegration.cpp @@ -244,6 +244,9 @@ QPlatformServices *QPlatformIntegration::services() const \value TopStackedNativeChildWindows The platform supports native child windows via QWindowContainer without having to punch a transparent hole in the backingstore. (since 5.10) + + \value OpenGLOnRasterSurface The platform supports making a QOpenGLContext current + in combination with a QWindow of type RasterSurface. */ /*! diff --git a/src/gui/kernel/qplatformintegration.h b/src/gui/kernel/qplatformintegration.h index 389b35dbc0..a3594042ce 100644 --- a/src/gui/kernel/qplatformintegration.h +++ b/src/gui/kernel/qplatformintegration.h @@ -105,7 +105,8 @@ public: AllGLFunctionsQueryable, ApplicationIcon, SwitchableWidgetComposition, - TopStackedNativeChildWindows + TopStackedNativeChildWindows, + OpenGLOnRasterSurface }; virtual ~QPlatformIntegration() { } diff --git a/src/gui/kernel/qsurface.cpp b/src/gui/kernel/qsurface.cpp index 415e64b39c..709f28d431 100644 --- a/src/gui/kernel/qsurface.cpp +++ b/src/gui/kernel/qsurface.cpp @@ -39,6 +39,8 @@ #include "qsurface.h" #include "qopenglcontext.h" +#include +#include QT_BEGIN_NAMESPACE @@ -103,6 +105,10 @@ QT_BEGIN_NAMESPACE bool QSurface::supportsOpenGL() const { SurfaceType type = surfaceType(); + if (type == RasterSurface) { + QPlatformIntegration *integ = QGuiApplicationPrivate::instance()->platformIntegration(); + return integ->hasCapability(QPlatformIntegration::OpenGLOnRasterSurface); + } return type == OpenGLSurface || type == RasterGLSurface; } diff --git a/src/plugins/platforms/eglfs/api/qeglfsintegration.cpp b/src/plugins/platforms/eglfs/api/qeglfsintegration.cpp index c8a1ddf9b9..674f579b4f 100644 --- a/src/plugins/platforms/eglfs/api/qeglfsintegration.cpp +++ b/src/plugins/platforms/eglfs/api/qeglfsintegration.cpp @@ -265,6 +265,7 @@ bool QEglFSIntegration::hasCapability(QPlatformIntegration::Capability cap) cons case RasterGLSurface: return false; #endif case WindowManagement: return false; + case OpenGLOnRasterSurface: return true; default: return QPlatformIntegration::hasCapability(cap); } } diff --git a/src/plugins/platforms/eglfs/api/qeglfswindow.cpp b/src/plugins/platforms/eglfs/api/qeglfswindow.cpp index c1d5af47aa..1fed182882 100644 --- a/src/plugins/platforms/eglfs/api/qeglfswindow.cpp +++ b/src/plugins/platforms/eglfs/api/qeglfswindow.cpp @@ -64,7 +64,6 @@ QEglFSWindow::QEglFSWindow(QWindow *w) m_backingStore(0), m_rasterCompositingContext(0), #endif - m_raster(false), m_winId(0), m_surface(EGL_NO_SURFACE), m_window(0), @@ -94,11 +93,6 @@ void QEglFSWindow::create() m_winId = newWId(); - // Save the original surface type before changing to OpenGLSurface. - m_raster = (window()->surfaceType() == QSurface::RasterSurface); - if (m_raster) // change to OpenGL, but not for RasterGLSurface - window()->setSurfaceType(QSurface::OpenGLSurface); - if (window()->type() == Qt::Desktop) { QRect fullscreenRect(QPoint(), screen()->availableGeometry().size()); QWindowSystemInterface::handleGeometryChange(window(), fullscreenRect); @@ -329,7 +323,8 @@ QEglFSScreen *QEglFSWindow::screen() const bool QEglFSWindow::isRaster() const { - return m_raster || window()->surfaceType() == QSurface::RasterGLSurface; + const QWindow::SurfaceType type = window()->surfaceType(); + return type == QSurface::RasterSurface || type == QSurface::RasterGLSurface; } #ifndef QT_NO_OPENGL diff --git a/src/plugins/platforms/eglfs/api/qeglfswindow_p.h b/src/plugins/platforms/eglfs/api/qeglfswindow_p.h index b0091e2a62..be2a0630d3 100644 --- a/src/plugins/platforms/eglfs/api/qeglfswindow_p.h +++ b/src/plugins/platforms/eglfs/api/qeglfswindow_p.h @@ -118,7 +118,6 @@ protected: QOpenGLCompositorBackingStore *m_backingStore; QOpenGLContext *m_rasterCompositingContext; #endif - bool m_raster; WId m_winId; EGLSurface m_surface; diff --git a/src/plugins/platforms/wasm/qwasmintegration.cpp b/src/plugins/platforms/wasm/qwasmintegration.cpp index 116612c286..1e9f68027c 100644 --- a/src/plugins/platforms/wasm/qwasmintegration.cpp +++ b/src/plugins/platforms/wasm/qwasmintegration.cpp @@ -168,6 +168,7 @@ bool QWasmIntegration::hasCapability(QPlatformIntegration::Capability cap) const case RasterGLSurface: return false; // to enable this you need to fix qopenglwidget and quickwidget for wasm case MultipleWindows: return true; case WindowManagement: return true; + case OpenGLOnRasterSurface: return true; default: return QPlatformIntegration::hasCapability(cap); } } -- cgit v1.2.3 From 7d0fff91ddadd03ff900b6d9a046a92ce6bf5a63 Mon Sep 17 00:00:00 2001 From: Oliver Wolff Date: Tue, 20 Aug 2019 10:30:44 +0200 Subject: Revert "Disable debug plugin check for MinGW" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch caused an error when loading applications built in debug mode with MinGW and thus has to be reverted. This reverts commit bba44746f9f2cfca785a309deb056033ae0bea6e. Fixes: QTBUG-77431 Change-Id: I3134878a742b304d10176cc8b0ed5ce06d4de53f Reviewed-by: Jani Heikkinen Reviewed-by: Jörg Bornemann --- src/corelib/plugin/qlibrary.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/corelib/plugin/qlibrary.cpp b/src/corelib/plugin/qlibrary.cpp index 3aadd1a73b..0e32776c71 100644 --- a/src/corelib/plugin/qlibrary.cpp +++ b/src/corelib/plugin/qlibrary.cpp @@ -74,7 +74,7 @@ QT_BEGIN_NAMESPACE # define QLIBRARY_AS_DEBUG true #endif -#if defined(Q_OS_UNIX) || defined(Q_CC_MINGW) +#if defined(Q_OS_UNIX) // We don't use separate debug and release libs on UNIX, so we want // to allow loading plugins, regardless of how they were built. # define QT_NO_DEBUG_PLUGIN_CHECK -- cgit v1.2.3 From 1232205e32464d90e871f39eb1e14fcf9b78a163 Mon Sep 17 00:00:00 2001 From: Rainer Keller Date: Tue, 27 Aug 2019 14:44:48 +0200 Subject: Fix crash when text contains too many directional chars In case a text to be layouted contains more than 128 directional characters it causes the application to crash The function initScriptAnalysisAndIsolatePairs() collects information of RTL/LTR chaaracters into vector "isolatePairs". The size of the vector is capped to 128. Later the function generateDirectionalRuns() iterates the text again and tries to access items from the previously capped vector above the upper bound. Task-number: QTBUG-77819 Change-Id: Ibb7bf12c12b1db22f43ff46236518da3fdeed26a Reviewed-by: Simon Hausmann --- src/gui/text/qtextengine.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp index 2da13289bf..a7834587b1 100644 --- a/src/gui/text/qtextengine.cpp +++ b/src/gui/text/qtextengine.cpp @@ -399,6 +399,7 @@ struct QBidiAlgorithm { analysis[i].bidiDirection = (level & 1) ? QChar::DirR : QChar::DirL; runHasContent = true; lastRunWithContent = -1; + ++isolatePairPosition; } int runBeforeIsolate = runs.size(); ushort newLevel = isRtl ? ((stack.top().level + 1) | 1) : ((stack.top().level + 2) & ~1); @@ -440,21 +441,19 @@ struct QBidiAlgorithm { doEmbed(true, true, false); break; case QChar::DirLRI: - Q_ASSERT(isolatePairs.at(isolatePairPosition).start == i); doEmbed(false, false, true); - ++isolatePairPosition; break; case QChar::DirRLI: - Q_ASSERT(isolatePairs.at(isolatePairPosition).start == i); doEmbed(true, false, true); - ++isolatePairPosition; break; case QChar::DirFSI: { - const auto &pair = isolatePairs.at(isolatePairPosition); - Q_ASSERT(pair.start == i); - bool isRtl = QStringView(text + pair.start + 1, pair.end - pair.start - 1).isRightToLeft(); + bool isRtl = false; + if (isolatePairPosition < isolatePairs.size()) { + const auto &pair = isolatePairs.at(isolatePairPosition); + Q_ASSERT(pair.start == i); + isRtl = QStringView(text + pair.start + 1, pair.end - pair.start - 1).isRightToLeft(); + } doEmbed(isRtl, false, true); - ++isolatePairPosition; break; } -- cgit v1.2.3 From af6ac444c97ed2dc234f93fe457440c9da5482ea Mon Sep 17 00:00:00 2001 From: Rainer Keller Date: Tue, 27 Aug 2019 14:44:48 +0200 Subject: Fix crash when text contains too many directional chars In case a text to be layouted contains more than 128 directional characters it causes the application to crash The function initScriptAnalysisAndIsolatePairs() collects information of RTL/LTR chaaracters into vector "isolatePairs". The size of the vector is capped to 128. Later the function generateDirectionalRuns() iterates the text again and tries to access items from the previously capped vector above the upper bound. Task-number: QTBUG-77819 Change-Id: Ibb7bf12c12b1db22f43ff46236518da3fdeed26a Reviewed-by: Simon Hausmann (cherry picked from commit 1232205e32464d90e871f39eb1e14fcf9b78a163) Reviewed-by: Jukka Jokiniva Reviewed-by: Volker Hilsheimer --- src/gui/text/qtextengine.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp index 2da13289bf..a7834587b1 100644 --- a/src/gui/text/qtextengine.cpp +++ b/src/gui/text/qtextengine.cpp @@ -399,6 +399,7 @@ struct QBidiAlgorithm { analysis[i].bidiDirection = (level & 1) ? QChar::DirR : QChar::DirL; runHasContent = true; lastRunWithContent = -1; + ++isolatePairPosition; } int runBeforeIsolate = runs.size(); ushort newLevel = isRtl ? ((stack.top().level + 1) | 1) : ((stack.top().level + 2) & ~1); @@ -440,21 +441,19 @@ struct QBidiAlgorithm { doEmbed(true, true, false); break; case QChar::DirLRI: - Q_ASSERT(isolatePairs.at(isolatePairPosition).start == i); doEmbed(false, false, true); - ++isolatePairPosition; break; case QChar::DirRLI: - Q_ASSERT(isolatePairs.at(isolatePairPosition).start == i); doEmbed(true, false, true); - ++isolatePairPosition; break; case QChar::DirFSI: { - const auto &pair = isolatePairs.at(isolatePairPosition); - Q_ASSERT(pair.start == i); - bool isRtl = QStringView(text + pair.start + 1, pair.end - pair.start - 1).isRightToLeft(); + bool isRtl = false; + if (isolatePairPosition < isolatePairs.size()) { + const auto &pair = isolatePairs.at(isolatePairPosition); + Q_ASSERT(pair.start == i); + isRtl = QStringView(text + pair.start + 1, pair.end - pair.start - 1).isRightToLeft(); + } doEmbed(isRtl, false, true); - ++isolatePairPosition; break; } -- 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') 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 dbfa374a8610948f6e03ea1b3f3bc2905ce05be0 Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Mon, 2 Sep 2019 10:43:29 +0200 Subject: QHttpNetworkConnectionChannel - avoid re-connecting on 'disconnected' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The _q_error slot has a special case for RemoteHostClosedError, where the current channel's state is 'idle' and no request/reply is in progress. The comment states that: "Not actually an error, it is normal for Keep-Alive connections to close after some time if no request is sent on them. No need to error the other replies below. Just bail out here. The _q_disconnected will handle the possibly pipelined replies." _q_disconnected, indeed, takes care about pipelined replies ... calling 'ensureConnected' even if we have 0 replies in pipeline, which makes zero sense to me and results in QNAM endlessly trying to re-connect to the server. Fixes: QTBUG-77852 Change-Id: I6dcb43b36a6d432bc940246a08f65e1ee903fd24 Reviewed-by: Volker Hilsheimer Reviewed-by: Mårten Nordheim Reviewed-by: Timur Pocheptsov --- src/network/access/qhttpnetworkconnectionchannel.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/network/access/qhttpnetworkconnectionchannel.cpp b/src/network/access/qhttpnetworkconnectionchannel.cpp index 38adca2633..e7af7b648e 100644 --- a/src/network/access/qhttpnetworkconnectionchannel.cpp +++ b/src/network/access/qhttpnetworkconnectionchannel.cpp @@ -849,8 +849,11 @@ void QHttpNetworkConnectionChannel::_q_disconnected() QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); } state = QHttpNetworkConnectionChannel::IdleState; - - requeueCurrentlyPipelinedRequests(); + if (alreadyPipelinedRequests.length()) { + // If nothing was in a pipeline, no need in calling + // _q_startNextRequest (which it does): + requeueCurrentlyPipelinedRequests(); + } pendingEncrypt = false; } -- cgit v1.2.3 From 98c5f22161e25c0f6867c0bf7db7aa8d6fcf6074 Mon Sep 17 00:00:00 2001 From: Alexander Volkov Date: Fri, 30 Aug 2019 19:51:19 +0300 Subject: Avoid invalid memory access in QIconCacheGtkReader::lookup() If name argument is empty, e.g. an icon is created by QIcon::fromTheme(""), then icon_name_hash() will access a byte at index 1, which is outside of the string. Change-Id: I109c476718939d7dd252007ebac48c3dbbeceb72 Reviewed-by: Eirik Aavitsland --- src/gui/image/qiconloader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/gui/image/qiconloader.cpp b/src/gui/image/qiconloader.cpp index 1d0c93f26f..27c82bc09f 100644 --- a/src/gui/image/qiconloader.cpp +++ b/src/gui/image/qiconloader.cpp @@ -281,7 +281,7 @@ static quint32 icon_name_hash(const char *p) QVector QIconCacheGtkReader::lookup(const QStringRef &name) { QVector ret; - if (!isValid()) + if (!isValid() || name.isEmpty()) return ret; QByteArray nameUtf8 = name.toUtf8(); -- cgit v1.2.3 From 1b0c45f683cef20aacc8f40273aa89200e9924e4 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Fri, 23 Aug 2019 08:47:30 +0200 Subject: Deliver stationary touchpoints that have changed pressure As a rule, we don't deliver touch events containing only stationary touchpoints. To fix QTBUG-52510 we added an exception in 1bd0ab7050304d9e8989cde77e486947c56b9696 : if the velocity changed, deliver it anyway. Now we need to do the same if the pressure changed. Also, on the customer's hardware, pressure is indicated via ABS_MT_PRESSURE. Change-Id: If7f7088df055d686cdd86967b999e38024f8170f Fixes: QTBUG-77142 Reviewed-by: Laszlo Agocs --- src/gui/kernel/qguiapplication.cpp | 10 +++++++--- src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 359d182dd9..51cde72fa1 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -2695,7 +2695,7 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To QWindow *window = e->window.data(); typedef QPair > StatesAndTouchPoints; QHash windowsNeedingEvents; - bool stationaryTouchPointChangedVelocity = false; + bool stationaryTouchPointChangedProperty = false; for (int i = 0; i < e->points.count(); ++i) { QTouchEvent::TouchPoint touchPoint = e->points.at(i); @@ -2775,7 +2775,11 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To if (touchPoint.state() == Qt::TouchPointStationary) { if (touchInfo.touchPoint.velocity() != touchPoint.velocity()) { touchInfo.touchPoint.setVelocity(touchPoint.velocity()); - stationaryTouchPointChangedVelocity = true; + stationaryTouchPointChangedProperty = true; + } + if (!qFuzzyCompare(touchInfo.touchPoint.pressure(), touchPoint.pressure())) { + touchInfo.touchPoint.setPressure(touchPoint.pressure()); + stationaryTouchPointChangedProperty = true; } } else { touchInfo.touchPoint = touchPoint; @@ -2816,7 +2820,7 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To break; case Qt::TouchPointStationary: // don't send the event if nothing changed - if (!stationaryTouchPointChangedVelocity) + if (!stationaryTouchPointChangedProperty) continue; Q_FALLTHROUGH(); default: diff --git a/src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp b/src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp index f3cc160b3e..b5bd2dcff4 100644 --- a/src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp +++ b/src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp @@ -532,7 +532,7 @@ void QEvdevTouchScreenData::processInputEvent(input_event *data) m_currentData.state = Qt::TouchPointReleased; if (m_typeB) m_contacts[m_currentSlot].maj = m_currentData.maj; - } else if (data->code == ABS_PRESSURE) { + } else if (data->code == ABS_PRESSURE || data->code == ABS_MT_PRESSURE) { m_currentData.pressure = qBound(hw_pressure_min, data->value, hw_pressure_max); if (m_typeB || m_singleTouch) m_contacts[m_currentSlot].pressure = m_currentData.pressure; -- cgit v1.2.3 From 15edba41014690332f4753f932fa7d928096cb73 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 3 Sep 2019 07:49:32 -0700 Subject: qFatal: make it so you cannot disable the message Solves a few recursion problems in Qt, since then we won't try to inspect the logging registry while creating the logging registry. Fixes: QTBUG-78007 Change-Id: I44cc9ee732f54d2380bafffd15c0f51c7140682e Reviewed-by: Eskil Abrahamsen Blomfeldt Reviewed-by: Friedemann Kleint --- src/corelib/global/qlogging.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp index bf9c2ed2be..3c82097cfe 100644 --- a/src/corelib/global/qlogging.cpp +++ b/src/corelib/global/qlogging.cpp @@ -1814,8 +1814,8 @@ static void qt_message_print(QtMsgType msgType, const QMessageLogContext &contex #ifndef QT_BOOTSTRAPPED Q_TRACE(qt_message_print, msgType, context.category, context.function, context.file, context.line, message); - // qDebug, qWarning, ... macros do not check whether category is enabled - if (isDefaultCategory(context.category)) { + // qDebug, qWarning, ... macros do not check whether category is enabledgc + if (msgType != QtFatalMsg && isDefaultCategory(context.category)) { if (QLoggingCategory *defaultCategory = QLoggingCategory::defaultCategory()) { if (!defaultCategory->isEnabled(msgType)) return; -- 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/corelib/global/qoperatingsystemversion.cpp | 8 -------- src/corelib/global/qoperatingsystemversion.h | 1 - src/network/ssl/qsslsocket_openssl11.cpp | 5 ++--- src/plugins/styles/windowsvista/qwindowsvistastyle.cpp | 3 +-- 4 files changed, 3 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/corelib/global/qoperatingsystemversion.cpp b/src/corelib/global/qoperatingsystemversion.cpp index ded86cbc4e..33793ca168 100644 --- a/src/corelib/global/qoperatingsystemversion.cpp +++ b/src/corelib/global/qoperatingsystemversion.cpp @@ -355,14 +355,6 @@ bool QOperatingSystemVersion::isAnyOfType(std::initializer_list types) c return false; } -/*! - \variable QOperatingSystemVersion::WindowsVista - \brief a version corresponding to Windows Vista (version 6.0). - \since 6.0 - */ -const QOperatingSystemVersion QOperatingSystemVersion::WindowsVista = - QOperatingSystemVersion(QOperatingSystemVersion::Windows, 6, 0); - /*! \variable QOperatingSystemVersion::Windows7 \brief a version corresponding to Windows 7 (version 6.1). diff --git a/src/corelib/global/qoperatingsystemversion.h b/src/corelib/global/qoperatingsystemversion.h index 879bd379b0..f22878de89 100644 --- a/src/corelib/global/qoperatingsystemversion.h +++ b/src/corelib/global/qoperatingsystemversion.h @@ -60,7 +60,6 @@ public: Android }; - static const QOperatingSystemVersion WindowsVista; static const QOperatingSystemVersion Windows7; static const QOperatingSystemVersion Windows8; static const QOperatingSystemVersion Windows8_1; diff --git a/src/network/ssl/qsslsocket_openssl11.cpp b/src/network/ssl/qsslsocket_openssl11.cpp index 28be4f2e79..1d935c5217 100644 --- a/src/network/ssl/qsslsocket_openssl11.cpp +++ b/src/network/ssl/qsslsocket_openssl11.cpp @@ -143,13 +143,12 @@ void QSslSocketPrivate::ensureCiphersAndCertsLoaded() if (!s_loadRootCertsOnDemand) setDefaultCaCertificates(systemCaCertificates()); #ifdef Q_OS_WIN - //Enabled for fetching additional root certs from windows update on windows 6+ + //Enabled for fetching additional root certs from windows update on windows. //This flag is set false by setDefaultCaCertificates() indicating the app uses //its own cert bundle rather than the system one. //Same logic that disables the unix on demand cert loading. //Unlike unix, we do preload the certificates from the cert store. - if (QOperatingSystemVersion::current() >= QOperatingSystemVersion::WindowsVista) - s_loadRootCertsOnDemand = true; + s_loadRootCertsOnDemand = true; #endif } 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 63145bc705c014d99322de5e78b1ec19c69a8c11 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Thu, 29 Aug 2019 12:10:58 +0200 Subject: Refine QCalendar::hasYearZero()'s documentation Change-Id: I06697485c6be1c31998d0da54b357f3f5c8701e7 Reviewed-by: Paul Wicking --- src/corelib/time/qcalendar.cpp | 46 +++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/corelib/time/qcalendar.cpp b/src/corelib/time/qcalendar.cpp index d31eee6632..2044b37cea 100644 --- a/src/corelib/time/qcalendar.cpp +++ b/src/corelib/time/qcalendar.cpp @@ -837,29 +837,29 @@ bool QCalendar::isProleptic() const } /*! - Returns \c true if this calendar has a year zero. - - A non-proleptic calendar with no year zero represents years from its first - year onwards but provides no way to describe years before its first; such a - calendar has no year zero and is not proleptic. - - A calendar which represents years before its first may number these years - simply by following the usual integer counting, so that the year before the - first is year zero, with negative-numbered years preceding this; such a - calendar is proleptic and has a year zero. A calendar might also have a year - zero (for example, the year of some great event, with subsequent years being - the first year after that event, the second year after, and so on) without - describing years before its year zero. Such a calendar would have a year zero - without being proleptic. - - Some calendars, however, represent years before their first by an alternate - numbering; for example, the proleptic Gregorian calendar's first year is 1 CE - and the year before it is 1 BCE, preceded by 2 BCE and so on. In this case, - we use negative year numbers, with year -1 as the year before year 1, year -2 - as the year before year -1 and so on. Such a calendar is proleptic but has no - year zero. - - \sa isProleptic() + Returns \c true if this calendar has a year zero. + + A calendar may represent years from its first year onwards but provide no + way to describe years before its first; such a calendar has no year zero and + is not proleptic. + + A calendar which represents years before its first may number these years + simply by following the usual integer counting, so that the year before the + first is year zero, with negative-numbered years preceding this; such a + calendar is proleptic and has a year zero. A calendar might also have a year + zero (for example, the year of some great event, with subsequent years being + the first year after that event, the second year after, and so on) without + describing years before its year zero. Such a calendar would have a year + zero without being proleptic. + + Some calendars, however, represent years before their first by an alternate + numbering; for example, the proleptic Gregorian calendar's first year is 1 + CE and the year before it is 1 BCE, preceded by 2 BCE and so on. In this + case, we use negative year numbers for this alternate numbering, with year + -1 as the year before year 1, year -2 as the year before year -1 and so + on. Such a calendar is proleptic but has no year zero. + + \sa isProleptic() */ bool QCalendar::hasYearZero() const { -- cgit v1.2.3 From 42011c03613b38d2bf9c7770edf1392c5f5598f2 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Mon, 26 Aug 2019 19:38:39 +0200 Subject: QGraphicsView: mark obsolete flag DontClipPainter as deprecated The enum OptimizationFlag::DontClipPainter is deprecated and not used in the code since Qt4 times. Therefore also mark it as deprecated so it can be removed with Qt6 Change-Id: I318a55cf42e7a233d13d4ec0144e1977251f5c92 Reviewed-by: Oliver Wolff --- src/widgets/graphicsview/qgraphicsview.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/widgets/graphicsview/qgraphicsview.h b/src/widgets/graphicsview/qgraphicsview.h index e02fba69c9..1389796c3f 100644 --- a/src/widgets/graphicsview/qgraphicsview.h +++ b/src/widgets/graphicsview/qgraphicsview.h @@ -107,7 +107,9 @@ public: Q_ENUM(ViewportUpdateMode) enum OptimizationFlag { - DontClipPainter = 0x1, // obsolete +#if QT_DEPRECATED_SINCE(5, 14) + DontClipPainter Q_DECL_ENUMERATOR_DEPRECATED_X("This flag is unused") = 0x1, // obsolete +#endif DontSavePainterState = 0x2, DontAdjustForAntialiasing = 0x4, IndirectPainting = 0x8 -- cgit v1.2.3 From 236d4637b2258def1e678e515b42632943eb888d Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 4 Sep 2019 19:30:08 +0200 Subject: Optimize QEventDispatcherWinRT::runOnMainThread() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - use std::make_shared instead of QSharedPointer - two memory allocations saved - co-locate semaphore and HRESULT object in a single State object - one more memory allocation saved - pass the shared_ptr by value into the runnable - two more memory allocations saved Not only is the new code much faster, it's also much more readable. Also use QSemaphoreReleaser, just in case the delegate should throw. Change-Id: Ib99b9da86984d440d10b72e3071aa88099e24a1f Reviewed-by: Mårten Nordheim --- src/corelib/kernel/qeventdispatcher_winrt.cpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/corelib/kernel/qeventdispatcher_winrt.cpp b/src/corelib/kernel/qeventdispatcher_winrt.cpp index 600c6c38fd..f7a1f969a8 100644 --- a/src/corelib/kernel/qeventdispatcher_winrt.cpp +++ b/src/corelib/kernel/qeventdispatcher_winrt.cpp @@ -44,12 +44,13 @@ #include #include #include -#include #include #include #include #include +#include + #include #include #include @@ -300,19 +301,19 @@ HRESULT QEventDispatcherWinRT::runOnMainThread(const std::function &d if (QThread::currentThread() == QCoreApplication::instance()->thread()) return delegate(); - auto semaphore = QSharedPointer(new QSemaphore); - auto ptrSemaphore = new QSharedPointer(semaphore); - auto result = QSharedPointer(new HRESULT); - auto ptrResult = new QSharedPointer(result); + struct State { + QSemaphore semaphore; + HRESULT result; + }; + + const auto state = std::make_shared(); - QMetaObject::invokeMethod(QCoreApplication::instance(), [delegate, ptrSemaphore, ptrResult]() { - **ptrResult = delegate(); - delete ptrResult; - (*ptrSemaphore)->release(); - delete ptrSemaphore; + QMetaObject::invokeMethod(QCoreApplication::instance(), [delegate, state]() { + const QSemaphoreReleaser releaser{state->semaphore}; + state->result = delegate(); }, nullptr); - return semaphore->tryAcquire(1, timeout) ? *result : E_FAIL; + return state->semaphore.tryAcquire(1, timeout) ? state->result : E_FAIL; } bool QEventDispatcherWinRT::processEvents(QEventLoop::ProcessEventsFlags flags) -- cgit v1.2.3 From f92d8fd64ebbb0405363c745dbd3c084946ed039 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Fri, 5 Jul 2019 12:49:04 +0200 Subject: Combine BGR30_to_RGB30 and BGR888_to_RGB888 And let the meat of the function be shared with the rbSwap routine. Change-Id: I0ea18b30c26ff050c17dcb3ad4d654bfbb8c6221 Reviewed-by: Eirik Aavitsland --- src/gui/image/qimage.cpp | 2 +- src/gui/image/qimage_conversions.cpp | 218 ++++++++++++--------------------- src/gui/painting/qdrawhelper.cpp | 6 +- src/gui/painting/qdrawhelper_ssse3.cpp | 45 ++++++- 4 files changed, 125 insertions(+), 146 deletions(-) (limited to 'src') diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index 86130132a4..dda407181a 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -3370,7 +3370,7 @@ void QImage::mirrored_inplace(bool horizontal, bool vertical) \sa {QImage#Image Transformations}{Image Transformations} */ -inline void rgbSwapped_generic(int width, int height, const QImage *src, QImage *dst, const QPixelLayout* layout) +static inline void rgbSwapped_generic(int width, int height, const QImage *src, QImage *dst, const QPixelLayout* layout) { const RbSwapFunc func = layout->rbSwap; if (!func) { diff --git a/src/gui/image/qimage_conversions.cpp b/src/gui/image/qimage_conversions.cpp index 539bac222a..9e1df7058c 100644 --- a/src/gui/image/qimage_conversions.cpp +++ b/src/gui/image/qimage_conversions.cpp @@ -564,6 +564,67 @@ static bool convert_RGBA_to_ARGB_inplace(QImageData *data, Qt::ImageConversionFl return true; } +static void convert_rgbswap_generic(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags) +{ + Q_ASSERT(src->width == dest->width); + Q_ASSERT(src->height == dest->height); + + const RbSwapFunc func = qPixelLayouts[src->format].rbSwap; + Q_ASSERT(func); + + const qsizetype sbpl = src->bytes_per_line; + const qsizetype dbpl = dest->bytes_per_line; + const uchar *src_data = src->data; + uchar *dest_data = dest->data; + + for (int i = 0; i < src->height; ++i) { + func(dest_data, src_data, src->width); + + src_data += sbpl; + dest_data += dbpl; + } +} + +static bool convert_rgbswap_generic_inplace(QImageData *data, Qt::ImageConversionFlags) +{ + const RbSwapFunc func = qPixelLayouts[data->format].rbSwap; + Q_ASSERT(func); + + const qsizetype bpl = data->bytes_per_line; + uchar *line_data = data->data; + + for (int i = 0; i < data->height; ++i) { + func(line_data, line_data, data->width); + line_data += bpl; + } + + switch (data->format) { + case QImage::Format_RGB888: + data->format = QImage::Format_BGR888; + break; + case QImage::Format_BGR888: + data->format = QImage::Format_RGB888; + break; + case QImage::Format_BGR30: + data->format = QImage::Format_RGB30; + break; + case QImage::Format_A2BGR30_Premultiplied: + data->format = QImage::Format_A2RGB30_Premultiplied; + break; + case QImage::Format_RGB30: + data->format = QImage::Format_BGR30; + break; + case QImage::Format_A2RGB30_Premultiplied: + data->format = QImage::Format_A2BGR30_Premultiplied; + break; + default: + Q_UNREACHABLE(); + data->format = QImage::Format_Invalid; + return false; + } + return true; +} + template static void convert_RGB_to_RGB30(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags) { @@ -693,74 +754,10 @@ static bool convert_A2RGB30_PM_to_RGB30_inplace(QImageData *data, Qt::ImageConve return true; } -static void convert_BGR30_to_RGB30(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags) -{ - Q_ASSERT(src->format == QImage::Format_RGB30 || src->format == QImage::Format_BGR30 || - src->format == QImage::Format_A2RGB30_Premultiplied || src->format == QImage::Format_A2BGR30_Premultiplied); - Q_ASSERT(dest->format == QImage::Format_RGB30 || dest->format == QImage::Format_BGR30 || - dest->format == QImage::Format_A2RGB30_Premultiplied || dest->format == QImage::Format_A2BGR30_Premultiplied); - Q_ASSERT(src->width == dest->width); - Q_ASSERT(src->height == dest->height); - - const int src_pad = (src->bytes_per_line >> 2) - src->width; - const int dest_pad = (dest->bytes_per_line >> 2) - dest->width; - const quint32 *src_data = (quint32 *) src->data; - quint32 *dest_data = (quint32 *) dest->data; - - for (int i = 0; i < src->height; ++i) { - const quint32 *end = src_data + src->width; - while (src_data < end) { - *dest_data = qRgbSwapRgb30(*src_data); - ++src_data; - ++dest_data; - } - src_data += src_pad; - dest_data += dest_pad; - } -} - -static bool convert_BGR30_to_RGB30_inplace(QImageData *data, Qt::ImageConversionFlags) -{ - Q_ASSERT(data->format == QImage::Format_RGB30 || data->format == QImage::Format_BGR30 || - data->format == QImage::Format_A2RGB30_Premultiplied || data->format == QImage::Format_A2BGR30_Premultiplied); - - const int pad = (data->bytes_per_line >> 2) - data->width; - uint *rgb_data = (uint *) data->data; - - for (int i = 0; i < data->height; ++i) { - const uint *end = rgb_data + data->width; - while (rgb_data < end) { - *rgb_data = qRgbSwapRgb30(*rgb_data); - ++rgb_data; - } - rgb_data += pad; - } - - switch (data->format) { - case QImage::Format_BGR30: - data->format = QImage::Format_RGB30; - break; - case QImage::Format_A2BGR30_Premultiplied: - data->format = QImage::Format_A2RGB30_Premultiplied; - break; - case QImage::Format_RGB30: - data->format = QImage::Format_BGR30; - break; - case QImage::Format_A2RGB30_Premultiplied: - data->format = QImage::Format_A2BGR30_Premultiplied; - break; - default: - Q_UNREACHABLE(); - data->format = QImage::Format_Invalid; - return false; - } - return true; -} - static bool convert_BGR30_to_A2RGB30_inplace(QImageData *data, Qt::ImageConversionFlags flags) { Q_ASSERT(data->format == QImage::Format_RGB30 || data->format == QImage::Format_BGR30); - if (!convert_BGR30_to_RGB30_inplace(data, flags)) + if (!convert_rgbswap_generic_inplace(data, flags)) return false; if (data->format == QImage::Format_RGB30) @@ -1421,69 +1418,6 @@ static void convert_RGBA64_to_gray16(QImageData *dest, const QImageData *src, Qt } } -static void convert_RGB888_to_BGR888(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags) -{ - Q_ASSERT(src->format == QImage::Format_RGB888 || src->format == QImage::Format_BGR888); - Q_ASSERT(dest->format == QImage::Format_RGB888 || dest->format == QImage::Format_BGR888); - Q_ASSERT(src->width == dest->width); - Q_ASSERT(src->height == dest->height); - - const qsizetype sbpl = src->bytes_per_line; - const qsizetype dbpl = dest->bytes_per_line; - const uchar *src_data = src->data; - uchar *dest_data = dest->data; - - for (int i = 0; i < src->height; ++i) { - int pixel = 0; - // Handle 4 pixels (12 bytes) at a time - for (; pixel + 3 < src->width; pixel += 4) { - const uchar *src = src_data + pixel * 3; - quint32 *dest_packed = (quint32 *) (dest_data + pixel * 3); - dest_packed[0] = (src[5] << 24) | (src[0] << 16) | (src[1] << 8) | (src[2] << 0); - dest_packed[1] = (src[7] << 24) | (src[8] << 16) | (src[3] << 8) | (src[4] << 0); - dest_packed[2] = (src[9] << 24) | (src[10] << 16) | (src[11] << 8) | (src[6] << 0); - } - - // epilog: handle left over pixels - for (; pixel < src->width; ++pixel) { - dest_data[pixel * 3 + 0] = src_data[pixel * 3 + 2]; - dest_data[pixel * 3 + 1] = src_data[pixel * 3 + 1]; - dest_data[pixel * 3 + 2] = src_data[pixel * 3 + 0]; - } - - src_data += sbpl; - dest_data += dbpl; - } -} - -static bool convert_RGB888_to_BGR888_inplace(QImageData *data, Qt::ImageConversionFlags) -{ - Q_ASSERT(data->format == QImage::Format_RGB888 || data->format == QImage::Format_BGR888); - - const qsizetype bpl = data->bytes_per_line; - uchar *line_data = data->data; - - for (int i = 0; i < data->height; ++i) { - for (int j = 0; j < data->width; ++j) - qSwap(line_data[j * 3 + 0], line_data[j * 3 + 2]); - line_data += bpl; - } - - switch (data->format) { - case QImage::Format_RGB888: - data->format = QImage::Format_BGR888; - break; - case QImage::Format_BGR888: - data->format = QImage::Format_RGB888; - break; - default: - Q_UNREACHABLE(); - data->format = QImage::Format_Invalid; - return false; - } - return true; -} - static QVector fix_color_table(const QVector &ctbl, QImage::Format format) { QVector colorTable = ctbl; @@ -2635,7 +2569,7 @@ Image_Converter qimage_converter_map[QImage::NImageFormats][QImage::NImageFormat convert_RGB888_to_RGB, convert_RGB888_to_RGB, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - convert_RGB888_to_BGR888, + convert_rgbswap_generic, }, // Format_RGB888 { @@ -2781,8 +2715,8 @@ Image_Converter qimage_converter_map[QImage::NImageFormats][QImage::NImageFormat 0, 0, convert_passthrough, - convert_BGR30_to_RGB30, - convert_BGR30_to_RGB30, + convert_rgbswap_generic, + convert_rgbswap_generic, 0, 0, 0, 0, 0, 0, 0 }, // Format_BGR30 @@ -2809,7 +2743,7 @@ Image_Converter qimage_converter_map[QImage::NImageFormats][QImage::NImageFormat convert_A2RGB30_PM_to_RGB30, 0, convert_A2RGB30_PM_to_RGB30, - convert_BGR30_to_RGB30, + convert_rgbswap_generic, 0, 0, 0, 0, 0, 0, 0 }, // Format_A2BGR30_Premultiplied @@ -2833,8 +2767,8 @@ Image_Converter qimage_converter_map[QImage::NImageFormats][QImage::NImageFormat 0, 0, 0, - convert_BGR30_to_RGB30, - convert_BGR30_to_RGB30, + convert_rgbswap_generic, + convert_rgbswap_generic, 0, convert_passthrough, 0, 0, 0, 0, 0, 0, 0 @@ -2860,7 +2794,7 @@ Image_Converter qimage_converter_map[QImage::NImageFormats][QImage::NImageFormat convert_A2RGB30_PM_to_ARGB, 0, convert_A2RGB30_PM_to_RGB30, - convert_BGR30_to_RGB30, + convert_rgbswap_generic, convert_A2RGB30_PM_to_RGB30, 0, 0, 0, @@ -3013,7 +2947,7 @@ Image_Converter qimage_converter_map[QImage::NImageFormats][QImage::NImageFormat 0, 0, 0, - convert_RGB888_to_BGR888, + convert_rgbswap_generic, 0, 0, #if Q_BYTE_ORDER == Q_LITTLE_ENDIAN @@ -3161,7 +3095,7 @@ InPlace_Image_Converter qimage_inplace_converter_map[QImage::NImageFormats][QIma }, // Format_ARGB8555_Premultiplied { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - convert_RGB888_to_BGR888_inplace + convert_rgbswap_generic_inplace }, // Format_RGB888 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 @@ -3267,7 +3201,7 @@ InPlace_Image_Converter qimage_inplace_converter_map[QImage::NImageFormats][QIma 0, 0, // self convert_passthrough_inplace, - convert_BGR30_to_RGB30_inplace, + convert_rgbswap_generic_inplace, convert_BGR30_to_A2RGB30_inplace, 0, 0, 0, 0, 0, 0, 0 @@ -3295,7 +3229,7 @@ InPlace_Image_Converter qimage_inplace_converter_map[QImage::NImageFormats][QIma convert_A2RGB30_PM_to_RGB30_inplace, 0, // self convert_A2RGB30_PM_to_RGB30_inplace, - convert_BGR30_to_RGB30_inplace, + convert_rgbswap_generic_inplace, 0, 0, 0, 0, 0, 0, 0 }, // Format_A2BGR30_Premultiplied { @@ -3318,7 +3252,7 @@ InPlace_Image_Converter qimage_inplace_converter_map[QImage::NImageFormats][QIma 0, 0, 0, - convert_BGR30_to_RGB30_inplace, + convert_rgbswap_generic_inplace, convert_BGR30_to_A2RGB30_inplace, 0, // self convert_passthrough_inplace, @@ -3345,7 +3279,7 @@ InPlace_Image_Converter qimage_inplace_converter_map[QImage::NImageFormats][QIma convert_A2RGB30_PM_to_ARGB_inplace, 0, convert_A2RGB30_PM_to_RGB30_inplace, - convert_BGR30_to_RGB30_inplace, + convert_rgbswap_generic_inplace, convert_A2RGB30_PM_to_RGB30_inplace, 0, // self 0, 0, @@ -3427,7 +3361,7 @@ InPlace_Image_Converter qimage_inplace_converter_map[QImage::NImageFormats][QIma }, // Format_Grayscale16 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - convert_RGB888_to_BGR888_inplace, + convert_rgbswap_generic_inplace, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // Format_BGR888 }; diff --git a/src/gui/painting/qdrawhelper.cpp b/src/gui/painting/qdrawhelper.cpp index c17bf2ddfd..edb363ac69 100644 --- a/src/gui/painting/qdrawhelper.cpp +++ b/src/gui/painting/qdrawhelper.cpp @@ -669,8 +669,7 @@ static void QT_FASTCALL rbSwap_rgb30(uchar *d, const uchar *s, int count) { const uint *src = reinterpret_cast(s); uint *dest = reinterpret_cast(d); - for (int i = 0; i < count; ++i) - dest[i] = qRgbSwapRgb30(src[i]); + UNALIASED_CONVERSION_LOOP(dest, src, count, qRgbSwapRgb30); } template Q_DECL_CONSTEXPR static inline QPixelLayout pixelLayoutRGB() @@ -6774,6 +6773,9 @@ static void qInitDrawhelperFunctions() qBlendFunctions[QImage::Format_RGBX8888][QImage::Format_RGBA8888_Premultiplied] = qt_blend_argb32_on_argb32_ssse3; qBlendFunctions[QImage::Format_RGBA8888_Premultiplied][QImage::Format_RGBA8888_Premultiplied] = qt_blend_argb32_on_argb32_ssse3; sourceFetchUntransformed[QImage::Format_RGB888] = qt_fetchUntransformed_888_ssse3; + extern void QT_FASTCALL rbSwap_888_ssse3(uchar *dst, const uchar *src, int count); + qPixelLayouts[QImage::Format_RGB888].rbSwap = rbSwap_888_ssse3; + qPixelLayouts[QImage::Format_BGR888].rbSwap = rbSwap_888_ssse3; } #endif // SSSE3 diff --git a/src/gui/painting/qdrawhelper_ssse3.cpp b/src/gui/painting/qdrawhelper_ssse3.cpp index 35d61c3e6c..14d7047bb6 100644 --- a/src/gui/painting/qdrawhelper_ssse3.cpp +++ b/src/gui/painting/qdrawhelper_ssse3.cpp @@ -40,7 +40,7 @@ #include -#ifdef QT_COMPILER_SUPPORTS_SSSE3 +#if defined(QT_COMPILER_SUPPORTS_SSSE3) #include @@ -254,6 +254,49 @@ void qt_memfill24_ssse3(quint24 *dest, quint24 color, qsizetype count) } } +void QT_FASTCALL rbSwap_888_ssse3(uchar *dst, const uchar *src, int count) +{ + int i = 0; + + const static __m128i shuffleMask1 = _mm_setr_epi8(2, 1, 0, 5, 4, 3, 8, 7, 6, 11, 10, 9, 14, 13, 12, /*!!*/15); + const static __m128i shuffleMask2 = _mm_setr_epi8(0, /*!!*/1, 4, 3, 2, 7, 6, 5, 10, 9, 8, 13, 12, 11, /*!!*/14, 15); + const static __m128i shuffleMask3 = _mm_setr_epi8(/*!!*/0, 3, 2, 1, 6, 5, 4, 9, 8, 7, 12, 11, 10, 15, 14, 13); + + for (; i + 15 < count; i += 16) { + __m128i s1 = _mm_loadu_si128((const __m128i *)src); + __m128i s2 = _mm_loadu_si128((const __m128i *)(src + 16)); + __m128i s3 = _mm_loadu_si128((const __m128i *)(src + 32)); + s1 = _mm_shuffle_epi8(s1, shuffleMask1); + s2 = _mm_shuffle_epi8(s2, shuffleMask2); + s3 = _mm_shuffle_epi8(s3, shuffleMask3); + _mm_storeu_si128((__m128i *)dst, s1); + _mm_storeu_si128((__m128i *)(dst + 16), s2); + _mm_storeu_si128((__m128i *)(dst + 32), s3); + + // Now fix the last four misplaced values + std::swap(dst[15], dst[17]); + std::swap(dst[30], dst[32]); + + src += 48; + dst += 48; + } + + if (src != dst) { + SIMD_EPILOGUE(i, count, 15) { + dst[0] = src[2]; + dst[1] = src[1]; + dst[2] = src[0]; + dst += 3; + src += 3; + } + } else { + SIMD_EPILOGUE(i, count, 15) { + std::swap(dst[0], dst[2]); + dst += 3; + } + } +} + QT_END_NAMESPACE #endif // QT_COMPILER_SUPPORTS_SSSE3 -- cgit v1.2.3 From e21fa577dde32849fdaa744f30ad3b23d63b7214 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Thu, 5 Sep 2019 09:40:09 +0200 Subject: Schannel: retain extra data after renegotiation is requested I realized this is a potential scenario where we will have leftover data, but it wasn't covered. Change-Id: Ibaf1015bf2aee120e4a4d98888925b88ecb6ddfd Reviewed-by: Jesus Fernandez Reviewed-by: Timur Pocheptsov --- src/network/ssl/qsslsocket_schannel.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src') diff --git a/src/network/ssl/qsslsocket_schannel.cpp b/src/network/ssl/qsslsocket_schannel.cpp index c5ba823832..88f66ac4ea 100644 --- a/src/network/ssl/qsslsocket_schannel.cpp +++ b/src/network/ssl/qsslsocket_schannel.cpp @@ -1360,6 +1360,18 @@ void QSslSocketBackendPrivate::transmit() #endif schannelState = SchannelState::Renegotiate; renegotiating = true; + + if (dataBuffer[3].BufferType == SECBUFFER_EXTRA) { + // https://docs.microsoft.com/en-us/windows/desktop/secauthn/extra-buffers-returned-by-schannel + // dataBuffer[3].cbBuffer indicates the amount of bytes _NOT_ processed, + // the rest need to be stored. +#ifdef QSSLSOCKET_DEBUG + qCDebug(lcSsl) << "We've got excess data, moving it to the intermediate buffer:" + << dataBuffer[3].cbBuffer << "bytes"; +#endif + intermediateBuffer = ciphertext.right(int(dataBuffer[3].cbBuffer)); + } + // We need to call 'continueHandshake' or else there's no guarantee it ever gets called continueHandshake(); break; -- cgit v1.2.3 From d49daa3f2737be5c5cbdae3e6b1b2651489a0686 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Wed, 28 Aug 2019 15:39:56 +0200 Subject: Clarify documentation of daysInMonth() Change-Id: I86258512c33cabec8d11ff3c794934f40850e413 Reviewed-by: Paul Wicking --- src/corelib/time/qcalendar.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/corelib/time/qcalendar.cpp b/src/corelib/time/qcalendar.cpp index 2044b37cea..4d3f1627b5 100644 --- a/src/corelib/time/qcalendar.cpp +++ b/src/corelib/time/qcalendar.cpp @@ -221,8 +221,8 @@ QString QCalendar::name() const Calendars with intercallary days may represent these as extra days of the preceding month, or as short months separate from the usual ones. In the former case, daysInMonth(month, year) should be the number of ordinary days - in the month, although \c{isDateValid(year, month, day)} might return \c true for - some larger values of \c day. + in the month, although \c{isDateValid(year, month, day)} might return \c true + for some larger values of \c day. \sa daysInYear(), monthsInYear(), minimumDaysInMonth(), maximumDaysInMonth() */ @@ -725,7 +725,8 @@ QCalendar::QCalendar(QStringView name) Returns the number of days in the given \a month of the given \a year. Months are numbered consecutively, starting with 1 for the first month of each - year. + year. If \a year is \c Unspecified (its default, if not passed), the month's + length in a normal year is returned. \sa maximumDaysInMonth(), minimumDaysInMonth() */ -- cgit v1.2.3 From 543769666f18f79bd6ebd6119a39834aafc2b0df Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Wed, 4 Sep 2019 15:00:31 +0200 Subject: A follow-up to a recent fix in QHttpNetworkConnectionChannel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit While working with HTTP/2, we are not re-sending failed requests. In case we receive a GOAWAY frame, we properly handle it by processing some active streams if possible, and aborting streams that will not proceed further with ContentResendError. But it's possible that some server failed to send us GOAWAY (for example, it died) or closed the connection not finishing the streams that were still active and valid (ID <= value from GOAWAY frame). Now that we will not re-connect, there is no reason to be quiet about us not progressing - emit RemoteHostClosedError on any remaining active stream/request we cannot process further. Fixes: QTBUG-77852 Change-Id: I4cd68a1c8c103b1fbe36c20a1cc406ab2e20dd12 Reviewed-by: Mårten Nordheim Reviewed-by: Timur Pocheptsov --- src/network/access/qhttp2protocolhandler.cpp | 25 ++++++++++++++++++++++ src/network/access/qhttp2protocolhandler_p.h | 2 ++ .../access/qhttpnetworkconnectionchannel.cpp | 13 ++++++++++- 3 files changed, 39 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/network/access/qhttp2protocolhandler.cpp b/src/network/access/qhttp2protocolhandler.cpp index c1053882af..9bf5547f15 100644 --- a/src/network/access/qhttp2protocolhandler.cpp +++ b/src/network/access/qhttp2protocolhandler.cpp @@ -58,6 +58,8 @@ #include #endif +#include + #include #include @@ -195,6 +197,29 @@ QHttp2ProtocolHandler::QHttp2ProtocolHandler(QHttpNetworkConnectionChannel *chan } } +void QHttp2ProtocolHandler::handleConnectionClosure() +{ + // The channel has just received RemoteHostClosedError and since it will + // not try (for HTTP/2) to re-connect, it's time to finish all replies + // with error. + + // Maybe we still have some data to read and can successfully finish + // a stream/request? + _q_receiveReply(); + + // Finish all still active streams. If we previously had GOAWAY frame, + // we probably already closed some (or all) streams with ContentReSend + // error, but for those still active, not having any data to finish, + // we now report RemoteHostClosedError. + const auto errorString = QCoreApplication::translate("QHttp", "Connection closed"); + for (auto it = activeStreams.begin(), eIt = activeStreams.end(); it != eIt; ++it) + finishStreamWithError(it.value(), QNetworkReply::RemoteHostClosedError, errorString); + + // Make sure we'll never try to read anything later: + activeStreams.clear(); + goingAway = true; +} + void QHttp2ProtocolHandler::_q_uploadDataReadyRead() { if (!sender()) // QueuedConnection, firing after sender (byte device) was deleted. diff --git a/src/network/access/qhttp2protocolhandler_p.h b/src/network/access/qhttp2protocolhandler_p.h index 1943827e23..43fdb136cd 100644 --- a/src/network/access/qhttp2protocolhandler_p.h +++ b/src/network/access/qhttp2protocolhandler_p.h @@ -92,6 +92,8 @@ public: QHttp2ProtocolHandler &operator = (const QHttp2ProtocolHandler &rhs) = delete; QHttp2ProtocolHandler &operator = (QHttp2ProtocolHandler &&rhs) = delete; + Q_INVOKABLE void handleConnectionClosure(); + private slots: void _q_uploadDataReadyRead(); void _q_replyDestroyed(QObject* reply); diff --git a/src/network/access/qhttpnetworkconnectionchannel.cpp b/src/network/access/qhttpnetworkconnectionchannel.cpp index 716ea6c8b2..6ff2c47eb4 100644 --- a/src/network/access/qhttpnetworkconnectionchannel.cpp +++ b/src/network/access/qhttpnetworkconnectionchannel.cpp @@ -977,7 +977,18 @@ void QHttpNetworkConnectionChannel::_q_error(QAbstractSocket::SocketError socket if (!reply && state == QHttpNetworkConnectionChannel::IdleState) { // Not actually an error, it is normal for Keep-Alive connections to close after some time if no request // is sent on them. No need to error the other replies below. Just bail out here. - // The _q_disconnected will handle the possibly pipelined replies + // The _q_disconnected will handle the possibly pipelined replies. HTTP/2 is special for now, + // we do not resend, but must report errors if any request is in progress (note, while + // not in its sendRequest(), protocol handler switches the channel to IdleState, thus + // this check is under this condition in 'if'): + if (protocolHandler.data()) { + if (connection->connectionType() == QHttpNetworkConnection::ConnectionTypeHTTP2Direct + || connection->connectionType() == QHttpNetworkConnection::ConnectionTypeHTTP2) { + auto h2Handler = static_cast(protocolHandler.data()); + h2Handler->handleConnectionClosure(); + protocolHandler.reset(); + } + } return; } else if (state != QHttpNetworkConnectionChannel::IdleState && state != QHttpNetworkConnectionChannel::ReadingState) { // Try to reconnect/resend before sending an error. -- cgit v1.2.3 From a42a4513398a159e4f6749fbcb1309c4a42b4841 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Fri, 30 Aug 2019 22:06:17 +0200 Subject: QShortcut: call base class implementation in event() QShortcut::event() did not call the base class implementation QObject::event() which caused that e.g. QEvent::DeferredDelete was not handled. Fix it by calling QObject::event() when the event was not handled. Fixes: QTBUG-66809 Change-Id: Ideebc980bc658f8f2b9ec4417e738bccda5eeab5 Reviewed-by: Volker Hilsheimer --- src/widgets/kernel/qshortcut.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/widgets/kernel/qshortcut.cpp b/src/widgets/kernel/qshortcut.cpp index b7857e2b74..db06dce042 100644 --- a/src/widgets/kernel/qshortcut.cpp +++ b/src/widgets/kernel/qshortcut.cpp @@ -665,24 +665,22 @@ int QShortcut::id() const bool QShortcut::event(QEvent *e) { Q_D(QShortcut); - bool handled = false; if (d->sc_enabled && e->type() == QEvent::Shortcut) { QShortcutEvent *se = static_cast(e); if (se->shortcutId() == d->sc_id && se->key() == d->sc_sequence){ #if QT_CONFIG(whatsthis) if (QWhatsThis::inWhatsThisMode()) { QWhatsThis::showText(QCursor::pos(), d->sc_whatsthis); - handled = true; } else #endif if (se->isAmbiguous()) emit activatedAmbiguously(); else emit activated(); - handled = true; + return true; } } - return handled; + return QObject::event(e); } #endif // QT_NO_SHORTCUT -- cgit v1.2.3 From d1a22bd29856807805fa56608d2953c072df0cf1 Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Wed, 4 Sep 2019 15:00:31 +0200 Subject: A follow-up to a recent fix in QHttpNetworkConnectionChannel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit While working with HTTP/2, we are not re-sending failed requests. In case we receive a GOAWAY frame, we properly handle it by processing some active streams if possible, and aborting streams that will not proceed further with ContentResendError. But it's possible that some server failed to send us GOAWAY (for example, it died) or closed the connection not finishing the streams that were still active and valid (ID <= value from GOAWAY frame). Now that we will not re-connect, there is no reason to be quiet about us not progressing - emit RemoteHostClosedError on any remaining active stream/request we cannot process further. Fixes: QTBUG-77852 Change-Id: I4cd68a1c8c103b1fbe36c20a1cc406ab2e20dd12 Reviewed-by: Mårten Nordheim Reviewed-by: Timur Pocheptsov (cherry picked from commit 543769666f18f79bd6ebd6119a39834aafc2b0df) --- src/network/access/qhttp2protocolhandler.cpp | 25 ++++++++++++++++++++++ src/network/access/qhttp2protocolhandler_p.h | 2 ++ .../access/qhttpnetworkconnectionchannel.cpp | 13 ++++++++++- 3 files changed, 39 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/network/access/qhttp2protocolhandler.cpp b/src/network/access/qhttp2protocolhandler.cpp index 5d7fc7506e..6609aa0594 100644 --- a/src/network/access/qhttp2protocolhandler.cpp +++ b/src/network/access/qhttp2protocolhandler.cpp @@ -55,6 +55,8 @@ #include #endif +#include + #include #include @@ -211,6 +213,29 @@ QHttp2ProtocolHandler::QHttp2ProtocolHandler(QHttpNetworkConnectionChannel *chan } } +void QHttp2ProtocolHandler::handleConnectionClosure() +{ + // The channel has just received RemoteHostClosedError and since it will + // not try (for HTTP/2) to re-connect, it's time to finish all replies + // with error. + + // Maybe we still have some data to read and can successfully finish + // a stream/request? + _q_receiveReply(); + + // Finish all still active streams. If we previously had GOAWAY frame, + // we probably already closed some (or all) streams with ContentReSend + // error, but for those still active, not having any data to finish, + // we now report RemoteHostClosedError. + const auto errorString = QCoreApplication::translate("QHttp", "Connection closed"); + for (auto it = activeStreams.begin(), eIt = activeStreams.end(); it != eIt; ++it) + finishStreamWithError(it.value(), QNetworkReply::RemoteHostClosedError, errorString); + + // Make sure we'll never try to read anything later: + activeStreams.clear(); + goingAway = true; +} + void QHttp2ProtocolHandler::_q_uploadDataReadyRead() { if (!sender()) // QueuedConnection, firing after sender (byte device) was deleted. diff --git a/src/network/access/qhttp2protocolhandler_p.h b/src/network/access/qhttp2protocolhandler_p.h index 9165808302..d91853f613 100644 --- a/src/network/access/qhttp2protocolhandler_p.h +++ b/src/network/access/qhttp2protocolhandler_p.h @@ -90,6 +90,8 @@ public: QHttp2ProtocolHandler &operator = (const QHttp2ProtocolHandler &rhs) = delete; QHttp2ProtocolHandler &operator = (QHttp2ProtocolHandler &&rhs) = delete; + Q_INVOKABLE void handleConnectionClosure(); + private slots: void _q_uploadDataReadyRead(); void _q_replyDestroyed(QObject* reply); diff --git a/src/network/access/qhttpnetworkconnectionchannel.cpp b/src/network/access/qhttpnetworkconnectionchannel.cpp index e7af7b648e..1fac24ab49 100644 --- a/src/network/access/qhttpnetworkconnectionchannel.cpp +++ b/src/network/access/qhttpnetworkconnectionchannel.cpp @@ -967,7 +967,18 @@ void QHttpNetworkConnectionChannel::_q_error(QAbstractSocket::SocketError socket if (!reply && state == QHttpNetworkConnectionChannel::IdleState) { // Not actually an error, it is normal for Keep-Alive connections to close after some time if no request // is sent on them. No need to error the other replies below. Just bail out here. - // The _q_disconnected will handle the possibly pipelined replies + // The _q_disconnected will handle the possibly pipelined replies. HTTP/2 is special for now, + // we do not resend, but must report errors if any request is in progress (note, while + // not in its sendRequest(), protocol handler switches the channel to IdleState, thus + // this check is under this condition in 'if'): + if (protocolHandler.data()) { + if (connection->connectionType() == QHttpNetworkConnection::ConnectionTypeHTTP2Direct + || connection->connectionType() == QHttpNetworkConnection::ConnectionTypeHTTP2) { + auto h2Handler = static_cast(protocolHandler.data()); + h2Handler->handleConnectionClosure(); + protocolHandler.reset(); + } + } return; } else if (state != QHttpNetworkConnectionChannel::IdleState && state != QHttpNetworkConnectionChannel::ReadingState) { // Try to reconnect/resend before sending an error. -- cgit v1.2.3 From 6de5cf2df82e5025bd9f02e9f38922f8c7c4b3b5 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Mon, 2 Sep 2019 13:08:34 +0200 Subject: rhi: metal: Avoid upsetting validation in viewport and scissor When running with the threaded render loop of Qt Quick, it could be that the drawable changes size while the render thread prepares the command buffer with setViewport and setScissor. Those have no chance to see such changes, which is normally not a big problem because the resize will get processed eventually. However, in debug builds running in XCode, Metal validation checks the viewport and scissor rects against the (more or less) actual drawable size, and so would abort Qt Quick apps from time to time when resizing the window interactively. To solve this, we just query the drawable size in setViewport/setScissor to keep validation happy. Change-Id: I451f398bd1f88e3f49ea4624fc45bbb4b70e7f07 Reviewed-by: Andy Nichols --- src/gui/rhi/qrhimetal.mm | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/gui/rhi/qrhimetal.mm b/src/gui/rhi/qrhimetal.mm index 07753c985c..dfa79edb00 100644 --- a/src/gui/rhi/qrhimetal.mm +++ b/src/gui/rhi/qrhimetal.mm @@ -997,11 +997,44 @@ void QRhiMetal::setVertexInput(QRhiCommandBuffer *cb, } } +QSize safeOutputSize(QRhiMetal *rhiD, QMetalCommandBuffer *cbD) +{ + QSize size = cbD->currentTarget->pixelSize(); + + // So now we have the issue that the texture (drawable) size may have + // changed again since swapchain buildOrResize() was called. This can + // happen for example when interactively resizing the window a lot in one + // go, and command buffer building happens on a dedicated thread (f.ex. + // using the threaded render loop of Qt Quick). + // + // This is only an issue when running in debug mode with XCode because Metal + // validation will fail when setting viewport or scissor with the real size + // being smaller than what we think it is. So query the drawable size right + // here, in debug mode at least. + // + // In addition, we have to take the smaller of the two widths and heights + // to be safe, apparently. In some cases validation seems to think that the + // "render pass width" (or height) is the old(?) value. + +#ifdef QT_DEBUG + if (cbD->currentTarget->resourceType() == QRhiResource::RenderTarget) { + Q_ASSERT(rhiD->currentSwapChain); + const QSize otherSize = rhiD->currentSwapChain->surfacePixelSize(); + size.setWidth(qMin(size.width(), otherSize.width())); + size.setHeight(qMin(size.height(), otherSize.height())); + } +#else + Q_UNUSED(rhiD); +#endif + + return size; +} + void QRhiMetal::setViewport(QRhiCommandBuffer *cb, const QRhiViewport &viewport) { QMetalCommandBuffer *cbD = QRHI_RES(QMetalCommandBuffer, cb); Q_ASSERT(cbD->recordingPass == QMetalCommandBuffer::RenderPass); - const QSize outputSize = cbD->currentTarget->pixelSize(); + const QSize outputSize = safeOutputSize(this, cbD); // x,y is top-left in MTLViewportRect but bottom-left in QRhiViewport float x, y, w, h; @@ -1033,7 +1066,7 @@ void QRhiMetal::setScissor(QRhiCommandBuffer *cb, const QRhiScissor &scissor) QMetalCommandBuffer *cbD = QRHI_RES(QMetalCommandBuffer, cb); Q_ASSERT(cbD->recordingPass == QMetalCommandBuffer::RenderPass); Q_ASSERT(QRHI_RES(QMetalGraphicsPipeline, cbD->currentGraphicsPipeline)->m_flags.testFlag(QRhiGraphicsPipeline::UsesScissor)); - const QSize outputSize = cbD->currentTarget->pixelSize(); + const QSize outputSize = safeOutputSize(this, cbD); // x,y is top-left in MTLScissorRect but bottom-left in QRhiScissor int x, y, w, h; -- cgit v1.2.3 From 228f0c1d2e1e4a4b160172dbf254935bb8fa2460 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Mon, 2 Sep 2019 15:30:02 +0200 Subject: Allow render-to-texture widgets to tell if they want premul blending Instead of assuming they do not (like in >= 5.12.3) or they do (like in < 5.12.3). QOpenGLWidget and QQuickWidget will likely want the opposite. So allow specifying this with a QPlatformTextureList flag, similarly to how we do it for sRGB for QOpenGLWidget. Task-number: QTBUG-77471 Change-Id: I594ca919c8eca190fa70c6aa84f46f456fcd80e1 Reviewed-by: Paul Olav Tvete --- src/gui/painting/qplatformbackingstore.cpp | 20 ++++++++++++++------ src/gui/painting/qplatformbackingstore.h | 3 ++- 2 files changed, 16 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/gui/painting/qplatformbackingstore.cpp b/src/gui/painting/qplatformbackingstore.cpp index c71d82546a..601dc97be1 100644 --- a/src/gui/painting/qplatformbackingstore.cpp +++ b/src/gui/painting/qplatformbackingstore.cpp @@ -446,14 +446,22 @@ void QPlatformBackingStore::composeAndFlush(QWindow *window, const QRegion ®i d_ptr->blitter->setRedBlueSwizzle(false); } - // There is no way to tell if the OpenGL-rendered content is premultiplied or not. - // For compatibility, assume that it is not, and use normal alpha blend always. - if (d_ptr->premultiplied) - funcs->glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE); - // Textures for renderToTexture widgets that have WA_AlwaysStackOnTop set. + bool blendIsPremultiplied = d_ptr->premultiplied; for (int i = 0; i < textures->count(); ++i) { - if (textures->flags(i).testFlag(QPlatformTextureList::StacksOnTop)) + const QPlatformTextureList::Flags flags = textures->flags(i); + if (flags.testFlag(QPlatformTextureList::NeedsPremultipliedAlphaBlending)) { + if (!blendIsPremultiplied) { + funcs->glBlendFuncSeparate(GL_ONE, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE); + blendIsPremultiplied = true; + } + } else { + if (blendIsPremultiplied) { + funcs->glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE); + blendIsPremultiplied = false; + } + } + if (flags.testFlag(QPlatformTextureList::StacksOnTop)) blitTextureForWidget(textures, i, window, deviceWindowRect, d_ptr->blitter, offset, canUseSrgb); } diff --git a/src/gui/painting/qplatformbackingstore.h b/src/gui/painting/qplatformbackingstore.h index 414d2bf0de..4f08b0092f 100644 --- a/src/gui/painting/qplatformbackingstore.h +++ b/src/gui/painting/qplatformbackingstore.h @@ -81,7 +81,8 @@ class Q_GUI_EXPORT QPlatformTextureList : public QObject public: enum Flag { StacksOnTop = 0x01, - TextureIsSrgb = 0x02 + TextureIsSrgb = 0x02, + NeedsPremultipliedAlphaBlending = 0x04 }; Q_DECLARE_FLAGS(Flags, Flag) -- 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/corelib/corelib.pro | 2 +- src/plugins/platforms/android/android.pro | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) (limited to 'src') diff --git a/src/corelib/corelib.pro b/src/corelib/corelib.pro index 121db51eb5..ba5f5adf8d 100644 --- a/src/corelib/corelib.pro +++ b/src/corelib/corelib.pro @@ -21,7 +21,7 @@ CONFIG += simd optimize_full QMAKE_DOCS = $$PWD/doc/qtcore.qdocconf ANDROID_LIB_DEPENDENCIES = \ - plugins/platforms/android/libqtforandroid.so + plugins/platforms/libqtforandroid.so ANDROID_BUNDLED_JAR_DEPENDENCIES = \ jar/QtAndroid.jar ANDROID_PERMISSIONS = \ 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 9a0ef07f154676cfc3b54b2b1042233b27fe8de9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Thu, 5 Sep 2019 12:34:34 +0200 Subject: qrhid3d11: Remove unused variable blockDim Clang emits a warning Change-Id: Ie2bf77248df2b2ecf23e24429688563f9725dd0d Reviewed-by: Laszlo Agocs --- src/gui/rhi/qrhid3d11.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src') diff --git a/src/gui/rhi/qrhid3d11.cpp b/src/gui/rhi/qrhid3d11.cpp index 3e136cdb80..9e8533be23 100644 --- a/src/gui/rhi/qrhid3d11.cpp +++ b/src/gui/rhi/qrhid3d11.cpp @@ -1220,7 +1220,6 @@ void QRhiD3D11::enqueueSubresUpload(QD3D11Texture *texD, QD3D11CommandBuffer *cb const QSize size = subresDesc.sourceSize().isEmpty() ? q->sizeForMipLevel(level, texD->m_pixelSize) : subresDesc.sourceSize(); quint32 bpl = 0; - QSize blockDim; textureFormatInfo(texD->m_format, size, &bpl, nullptr); box.left = dp.x(); box.top = dp.y(); -- cgit v1.2.3 From 4ac872639ed0dd3ae6627e05bdda821f7d128500 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Thu, 9 Nov 2017 18:00:46 +0100 Subject: Make Qt relocatable [ChangeLog][QtCore] Qt installations on the host system can now be relocated, i.e. moved to other directories. Add a new feature 'relocatable' that's by default enabled for non-static builds - on platforms where libdl is available, - on macOS when configured with -framework, - on Windows. If the feature is enabled, the directory where plugins, translations and other assets are loaded from is determined by the location of libQt5Core.so and the lib dir (bin dir on Windows) relative to the prefix. For static builds, the feature 'relocatable' is off by default. It can be turned on manually by passing -feature-relocatable to configure. In that case, QLibraryInfo::location(QLibraryInfo::TranslationsPaths) and friends will return paths rooted in the user application's directory. The installed and relocated qmake determines properties like QT_INSTALL_PREFIX and QT_HOST_PREFIX from the location of the qmake executable and the host bin dir relative to the host prefix. This is now always done, independent of the 'relocatable' feature. Note that qmake is currently only relocatable within an environment that has the same layout as the original build machine due to absolute paths to the original prefix in .prl, .pc and .la files. This will be addressed in a separate patch. Task-number: QTBUG-15234 Change-Id: I7319e2856d8fe17f277082d71216442f52580633 Reviewed-by: Alexandru Croitor --- src/corelib/configure.json | 20 ---- src/corelib/global/qlibraryinfo.cpp | 208 ++++++++++++++++++++++++++++++------ 2 files changed, 175 insertions(+), 53 deletions(-) (limited to 'src') diff --git a/src/corelib/configure.json b/src/corelib/configure.json index f7b6d41534..ae360239c6 100644 --- a/src/corelib/configure.json +++ b/src/corelib/configure.json @@ -158,21 +158,6 @@ "-latomic" ] }, - "libdl": { - "label": "dlopen()", - "test": { - "main": [ - "dlclose(dlopen(0, 0));", - "dlsym(RTLD_DEFAULT, 0);", - "dlerror();" - ] - }, - "headers": "dlfcn.h", - "sources": [ - "", - "-ldl" - ] - }, "librt": { "label": "clock_gettime()", "test": { @@ -612,11 +597,6 @@ "condition": "features.clock-gettime && tests.clock-monotonic", "output": [ "feature" ] }, - "dlopen": { - "label": "dlopen()", - "condition": "config.unix && libs.libdl", - "output": [ "privateFeature" ] - }, "doubleconversion": { "label": "DoubleConversion", "output": [ "privateFeature", "feature" ] diff --git a/src/corelib/global/qlibraryinfo.cpp b/src/corelib/global/qlibraryinfo.cpp index 4c1b04f05e..c7357f9d13 100644 --- a/src/corelib/global/qlibraryinfo.cpp +++ b/src/corelib/global/qlibraryinfo.cpp @@ -55,15 +55,24 @@ QT_END_NAMESPACE # include "qcoreapplication.h" #endif +#ifndef QT_BUILD_QMAKE_BOOTSTRAP +# include "private/qglobal_p.h" +# include "qconfig.cpp" +#endif + #ifdef Q_OS_DARWIN # include "private/qcore_mac_p.h" -#endif +#endif // Q_OS_DARWIN -#ifndef QT_BUILD_QMAKE_BOOTSTRAP -# include "qconfig.cpp" +#include "archdetect.cpp" + +#if !defined(QT_BUILD_QMAKE) && QT_CONFIG(relocatable) && QT_CONFIG(dlopen) && !QT_CONFIG(framework) +# include #endif -#include "archdetect.cpp" +#if !defined(QT_BUILD_QMAKE) && QT_CONFIG(relocatable) && defined(Q_OS_WIN) +# include +#endif QT_BEGIN_NAMESPACE @@ -453,6 +462,160 @@ void QLibraryInfo::sysrootify(QString *path) } #endif // QT_BUILD_QMAKE +#ifndef QT_BUILD_QMAKE +static QString prefixFromAppDirHelper() +{ + QString appDir; + + if (QCoreApplication::instance()) { +#ifdef Q_OS_DARWIN + CFBundleRef bundleRef = CFBundleGetMainBundle(); + if (bundleRef) { + QCFType urlRef = CFBundleCopyBundleURL(bundleRef); + if (urlRef) { + QCFString path = CFURLCopyFileSystemPath(urlRef, kCFURLPOSIXPathStyle); +#ifdef Q_OS_MACOS + QString bundleContentsDir = QString(path) + QLatin1String("/Contents/"); + if (QDir(bundleContentsDir).exists()) + return QDir::cleanPath(bundleContentsDir); +#else + return QDir::cleanPath(QString(path)); // iOS +#endif // Q_OS_MACOS + } + } +#endif // Q_OS_DARWIN + // We make the prefix path absolute to the executable's directory. + appDir = QCoreApplication::applicationDirPath(); + } else { + appDir = QDir::currentPath(); + } + + return appDir; +} +#endif + +#if !defined(QT_BUILD_QMAKE) && QT_CONFIG(relocatable) +static QString prefixFromQtCoreLibraryHelper(const QString &qtCoreLibraryPath) +{ + const QString qtCoreLibrary = QDir::fromNativeSeparators(qtCoreLibraryPath); + const QString libDir = QFileInfo(qtCoreLibrary).absolutePath(); + const QString prefixDir = libDir + QLatin1Char('/') + + QLatin1String(QT_CONFIGURE_LIBLOCATION_TO_PREFIX_PATH); + return QDir::cleanPath(prefixDir); +} + +#if defined(Q_OS_WIN) +#if defined(Q_OS_WINRT) +EXTERN_C IMAGE_DOS_HEADER __ImageBase; +static HMODULE getWindowsModuleHandle() +{ + return reinterpret_cast(&__ImageBase); +} +#else // Q_OS_WINRT +static HMODULE getWindowsModuleHandle() +{ + HMODULE hModule = NULL; + GetModuleHandleEx( + GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, + (LPCTSTR)&QLibraryInfo::isDebugBuild, &hModule); + return hModule; +} +#endif // !Q_OS_WINRT +#endif // Q_OS_WIN + +static QString getRelocatablePrefix() +{ + QString prefixPath; + + // For static builds, the prefix will be the app directory. + // For regular builds, the prefix will be relative to the location of the QtCore shared library. +#if defined(QT_STATIC) + prefixPath = prefixFromAppDirHelper(); +#elif defined(Q_OS_DARWIN) && QT_CONFIG(framework) + CFBundleRef qtCoreBundle = CFBundleGetBundleWithIdentifier( + CFSTR("org.qt-project.QtCore")); + Q_ASSERT(qtCoreBundle); + + QCFType qtCorePath = CFBundleCopyBundleURL(qtCoreBundle); + Q_ASSERT(qtCorePath); + + QCFType qtCorePathAbsolute = CFURLCopyAbsoluteURL(qtCorePath); + Q_ASSERT(qtCorePathAbsolute); + + QCFType libDirCFPath = CFURLCreateCopyDeletingLastPathComponent(NULL, qtCorePathAbsolute); + + const QCFString libDirCFString = CFURLCopyFileSystemPath(libDirCFPath, kCFURLPOSIXPathStyle); + + const QString prefixDir = QString(libDirCFString) + QLatin1Char('/') + + QLatin1String(QT_CONFIGURE_LIBLOCATION_TO_PREFIX_PATH); + + prefixPath = QDir::cleanPath(prefixDir); +#elif QT_CONFIG(dlopen) + Dl_info info; + int result = dladdr(reinterpret_cast(&QLibraryInfo::isDebugBuild), &info); + if (result > 0 && info.dli_fname) + prefixPath = prefixFromQtCoreLibraryHelper(QString::fromLatin1(info.dli_fname)); +#elif defined(Q_OS_WIN) + HMODULE hModule = getWindowsModuleHandle(); + const int kBufferSize = 4096; + wchar_t buffer[kBufferSize]; + const int pathSize = GetModuleFileName(hModule, buffer, kBufferSize); + if (pathSize > 0) + prefixPath = prefixFromQtCoreLibraryHelper(QString::fromWCharArray(buffer, pathSize)); +#else +#error "The chosen platform / config does not support querying for a dynamic prefix." +#endif + + Q_ASSERT_X(!prefixPath.isEmpty(), "getRelocatablePrefix", + "Failed to find the Qt prefix path."); + return prefixPath; +} +#endif + +#if defined(QT_BUILD_QMAKE) && !defined(QT_BUILD_QMAKE_BOOTSTRAP) +QString qmake_abslocation(); + +static QString getPrefixFromHostBinDir(const char *hostBinDirToPrefixPath) +{ + const QFileInfo qmfi = QFileInfo(qmake_abslocation()).canonicalFilePath(); + return QDir::cleanPath(qmfi.absolutePath() + QLatin1Char('/') + + QLatin1String(hostBinDirToPrefixPath)); +} + +static QString getExtPrefixFromHostBinDir() +{ + return getPrefixFromHostBinDir(QT_CONFIGURE_HOSTBINDIR_TO_EXTPREFIX_PATH); +} + +static QString getHostPrefixFromHostBinDir() +{ + return getPrefixFromHostBinDir(QT_CONFIGURE_HOSTBINDIR_TO_HOSTPREFIX_PATH); +} +#endif + +#ifndef QT_BUILD_QMAKE_BOOTSTRAP +static const char *getPrefix( +#ifdef QT_BUILD_QMAKE + QLibraryInfo::PathGroup group +#endif + ) +{ +#if defined(QT_BUILD_QMAKE) +# if QT_CONFIGURE_CROSSBUILD + if (group == QLibraryInfo::DevicePaths) + return QT_CONFIGURE_PREFIX_PATH; +# endif + static QByteArray extPrefixPath = getExtPrefixFromHostBinDir().toLatin1(); + return extPrefixPath.constData(); +#elif QT_CONFIG(relocatable) + static QByteArray prefixPath = getRelocatablePrefix().toLatin1(); + return prefixPath.constData(); +#else + return QT_CONFIGURE_PREFIX_PATH; +#endif +} +#endif // QT_BUILD_QMAKE_BOOTSTRAP + /*! Returns the location specified by \a loc. */ @@ -564,12 +727,11 @@ QLibraryInfo::rawLocation(LibraryLocation loc, PathGroup group) if (!fromConf) { const char * volatile path = 0; if (loc == PrefixPath) { - path = -# ifdef QT_BUILD_QMAKE - (group != DevicePaths) ? - QT_CONFIGURE_EXT_PREFIX_PATH : -# endif - QT_CONFIGURE_PREFIX_PATH; + path = getPrefix( +#ifdef QT_BUILD_QMAKE + group +#endif + ); } else if (unsigned(loc) <= sizeof(qt_configure_str_offsets)/sizeof(qt_configure_str_offsets[0])) { path = qt_configure_strs + qt_configure_str_offsets[loc - 1]; #ifndef Q_OS_WIN // On Windows we use the registry @@ -578,7 +740,8 @@ QLibraryInfo::rawLocation(LibraryLocation loc, PathGroup group) #endif # ifdef QT_BUILD_QMAKE } else if (loc == HostPrefixPath) { - path = QT_CONFIGURE_HOST_PREFIX_PATH; + static const QByteArray hostPrefixPath = getHostPrefixFromHostBinDir().toLatin1(); + path = hostPrefixPath.constData(); # endif } @@ -612,28 +775,7 @@ QLibraryInfo::rawLocation(LibraryLocation loc, PathGroup group) } #else if (loc == PrefixPath) { - if (QCoreApplication::instance()) { -#ifdef Q_OS_DARWIN - CFBundleRef bundleRef = CFBundleGetMainBundle(); - if (bundleRef) { - QCFType urlRef = CFBundleCopyBundleURL(bundleRef); - if (urlRef) { - QCFString path = CFURLCopyFileSystemPath(urlRef, kCFURLPOSIXPathStyle); -#ifdef Q_OS_OSX - QString bundleContentsDir = QString(path) + QLatin1String("/Contents/"); - if (QDir(bundleContentsDir).exists()) - return QDir::cleanPath(bundleContentsDir + ret); -#else - return QDir::cleanPath(QString(path) + QLatin1Char('/') + ret); // iOS -#endif // Q_OS_OSX - } - } -#endif // Q_OS_DARWIN - // We make the prefix path absolute to the executable's directory. - baseDir = QCoreApplication::applicationDirPath(); - } else { - baseDir = QDir::currentPath(); - } + baseDir = prefixFromAppDirHelper(); } else { // we make any other path absolute to the prefix directory baseDir = location(PrefixPath); -- 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') 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 89d0a03c067b42155b1a2d310f8514f595abfd61 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Sun, 8 Sep 2019 15:38:56 +0200 Subject: Remove BT.2020 support from QColorSpace MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BT.2020 is an HDR color space and its luminance range doesn't match that of the rest of the currently available color spaces. Without support for white-point luminance in 5.14, there would be a behavior change when luminance support is later introduced, so it is better to remove it now, and reintroduce it when the necessary handling of different luminance levels is available. Change-Id: Ie29e4dd757faae3ac91d4252e1206acce42801dc Reviewed-by: Tor Arne Vestbø --- src/gui/painting/qcolormatrix_p.h | 6 ------ src/gui/painting/qcolorspace.cpp | 31 +---------------------------- src/gui/painting/qcolorspace.h | 9 +++------ src/gui/painting/qcolortransferfunction_p.h | 4 ---- src/gui/painting/qicc.cpp | 3 --- 5 files changed, 4 insertions(+), 49 deletions(-) (limited to 'src') diff --git a/src/gui/painting/qcolormatrix_p.h b/src/gui/painting/qcolormatrix_p.h index 66db95df7e..70d2137119 100644 --- a/src/gui/painting/qcolormatrix_p.h +++ b/src/gui/painting/qcolormatrix_p.h @@ -226,12 +226,6 @@ public: { 0.1351922452f, 0.7118769884f, 0.0000000000f }, { 0.0313525312f, 0.0000856627f, 0.8251883388f } }; } - static QColorMatrix toXyzFromBt2020() - { - return QColorMatrix { { 0.6506130099f, 0.2695676684f, -0.0018652577f }, - { 0.1865101457f, 0.6840794086f, 0.0172256753f }, - { 0.1270887405f, 0.0463530831f, 0.8098278046f } }; - } }; inline bool operator==(const QColorMatrix &m1, const QColorMatrix &m2) diff --git a/src/gui/painting/qcolorspace.cpp b/src/gui/painting/qcolorspace.cpp index 39ab358879..720c531e3f 100644 --- a/src/gui/painting/qcolorspace.cpp +++ b/src/gui/painting/qcolorspace.cpp @@ -70,12 +70,6 @@ QColorSpacePrimaries::QColorSpacePrimaries(QColorSpace::Primaries primaries) bluePoint = QPointF(0.150, 0.060); whitePoint = QColorVector::D65Chromaticity(); break; - case QColorSpace::Primaries::Bt2020: - redPoint = QPointF(0.708, 0.292); - greenPoint = QPointF(0.190, 0.797); - bluePoint = QPointF(0.131, 0.046); - whitePoint = QColorVector::D65Chromaticity(); - break; case QColorSpace::Primaries::AdobeRgb: redPoint = QPointF(0.640, 0.330); greenPoint = QPointF(0.210, 0.710); @@ -191,11 +185,6 @@ QColorSpacePrivate::QColorSpacePrivate(QColorSpace::NamedColorSpace namedColorSp transferFunction = QColorSpace::TransferFunction::ProPhotoRgb; description = QStringLiteral("ProPhoto RGB"); break; - case QColorSpace::Bt2020: - primaries = QColorSpace::Primaries::Bt2020; - transferFunction = QColorSpace::TransferFunction::Bt2020; - description = QStringLiteral("BT.2020"); - break; default: Q_UNREACHABLE(); } @@ -277,14 +266,6 @@ void QColorSpacePrivate::identifyColorSpace() } } break; - case QColorSpace::Primaries::Bt2020: - if (transferFunction == QColorSpace::TransferFunction::Bt2020) { - namedColorSpace = QColorSpace::Bt2020; - if (description.isEmpty()) - description = QStringLiteral("BT.2020"); - return; - } - break; default: break; } @@ -335,12 +316,6 @@ void QColorSpacePrivate::setTransferFunction() if (qFuzzyIsNull(gamma)) gamma = 1.8f; break; - case QColorSpace::TransferFunction::Bt2020: - trc[0].m_type = QColorTrc::Type::Function; - trc[0].m_fun = QColorTransferFunction::fromBt2020(); - if (qFuzzyIsNull(gamma)) - gamma = 1.961f; - break; case QColorSpace::TransferFunction::Custom: break; default: @@ -415,8 +390,6 @@ QColorTransform QColorSpacePrivate::transformationToColorSpace(const QColorSpace \l{http://www.color.org/chardata/rgb/DCIP3.xalter}{ICC registration of DCI-P3} \value ProPhotoRgb The Pro Photo RGB color space, also known as ROMM RGB is a very wide gamut color space. \l{http://www.color.org/chardata/rgb/rommrgb.xalter}{ICC registration of ROMM RGB} - \value Bt2020 BT.2020 also known as Rec.2020 is the color space of HDR TVs. - \l{http://www.color.org/chardata/rgb/BT2020.xalter}{ICC registration of BT.2020} */ /*! @@ -429,7 +402,6 @@ QColorTransform QColorSpacePrivate::transformationToColorSpace(const QColorSpace \value AdobeRgb The Adobe RGB primaries \value DciP3D65 The DCI-P3 primaries with the D65 whitepoint \value ProPhotoRgb The ProPhoto RGB primaries with the D50 whitepoint - \value Bt2020 The BT.2020 primaries */ /*! @@ -442,7 +414,6 @@ QColorTransform QColorSpacePrivate::transformationToColorSpace(const QColorSpace \value Gamma A transfer function that is a real gamma curve based on the value of gamma() \value SRgb The sRGB transfer function, composed of linear and gamma parts \value ProPhotoRgb The ProPhoto RGB transfer function, composed of linear and gamma parts - \value Bt2020 The BT.2020 transfer function, composed of linear and gamma parts */ /*! @@ -457,7 +428,7 @@ QColorSpace::QColorSpace() */ QColorSpace::QColorSpace(NamedColorSpace namedColorSpace) { - static QColorSpacePrivate *predefinedColorspacePrivates[QColorSpace::Bt2020 + 1]; + static QColorSpacePrivate *predefinedColorspacePrivates[QColorSpace::ProPhotoRgb + 1]; if (!predefinedColorspacePrivates[namedColorSpace]) { predefinedColorspacePrivates[namedColorSpace] = new QColorSpacePrivate(namedColorSpace); predefinedColorspacePrivates[namedColorSpace]->ref.ref(); diff --git a/src/gui/painting/qcolorspace.h b/src/gui/painting/qcolorspace.h index 11987b9a37..e6bc62d58a 100644 --- a/src/gui/painting/qcolorspace.h +++ b/src/gui/painting/qcolorspace.h @@ -59,8 +59,7 @@ public: SRgbLinear, AdobeRgb, DisplayP3, - ProPhotoRgb, - Bt2020, + ProPhotoRgb }; Q_ENUM(NamedColorSpace) enum class Primaries { @@ -68,8 +67,7 @@ public: SRgb, AdobeRgb, DciP3D65, - ProPhotoRgb, - Bt2020, + ProPhotoRgb }; Q_ENUM(Primaries) enum class TransferFunction { @@ -77,8 +75,7 @@ public: Linear, Gamma, SRgb, - ProPhotoRgb, - Bt2020, + ProPhotoRgb }; Q_ENUM(TransferFunction) diff --git a/src/gui/painting/qcolortransferfunction_p.h b/src/gui/painting/qcolortransferfunction_p.h index fd7cfa2b2b..0575dbd888 100644 --- a/src/gui/painting/qcolortransferfunction_p.h +++ b/src/gui/painting/qcolortransferfunction_p.h @@ -130,10 +130,6 @@ public: { return QColorTransferFunction(1.0f / 1.055f, 0.055f / 1.055f, 1.0f / 12.92f, 0.04045f, 0.0f, 0.0f, 2.4f); } - static QColorTransferFunction fromBt2020() - { - return QColorTransferFunction(1.0f / 1.0993f, 0.0993f / 1.0993f, 1.0f / 4.5f, 0.08145f, 0.0f, 0.0f, 2.2f); - } static QColorTransferFunction fromProPhotoRgb() { return QColorTransferFunction(1.0f, 0.0f, 1.0f / 16.0f, 16.0f / 512.0f, 0.0f, 0.0f, 1.8f); diff --git a/src/gui/painting/qicc.cpp b/src/gui/painting/qicc.cpp index 45b64de960..18f212f8e9 100644 --- a/src/gui/painting/qicc.cpp +++ b/src/gui/painting/qicc.cpp @@ -687,9 +687,6 @@ bool fromIccProfile(const QByteArray &data, QColorSpace *colorSpace) } else if (colorspaceDPtr->toXyz == QColorMatrix::toXyzFromDciP3D65()) { qCDebug(lcIcc) << "fromIccProfile: DCI-P3 D65 primaries detected"; colorspaceDPtr->primaries = QColorSpace::Primaries::DciP3D65; - } else if (colorspaceDPtr->toXyz == QColorMatrix::toXyzFromBt2020()) { - qCDebug(lcIcc) << "fromIccProfile: BT.2020 primaries detected"; - colorspaceDPtr->primaries = QColorSpace::Primaries::Bt2020; } if (colorspaceDPtr->toXyz == QColorMatrix::toXyzFromProPhotoRgb()) { qCDebug(lcIcc) << "fromIccProfile: ProPhoto RGB primaries detected"; -- cgit v1.2.3 From 5cea83a8a2fc3384bb07a7265c8d907171cb1ea4 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 13 Aug 2019 21:32:44 -0700 Subject: QRandom: retry the use of RDRAND instruction as recommended by manuals MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Intel whitepaper[1] recommends retrying RDRAND some 10 times even after it fails, since the hardware has a fairness algorithm and reseeds itself quite quickly. [1] https://software.intel.com/en-us/articles/intel-digital-random-number-generator-drng-software-implementation-guide Change-Id: I907a43cd9a714da288a2fffd15baafd88242d8b6 Reviewed-by: André Hartmann --- src/corelib/global/qrandom.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/corelib/global/qrandom.cpp b/src/corelib/global/qrandom.cpp index bf01b7ae2a..fa26d54afa 100644 --- a/src/corelib/global/qrandom.cpp +++ b/src/corelib/global/qrandom.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 Intel Corporation. +** Copyright (C) 2019 Intel Corporation. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. @@ -103,17 +103,22 @@ static QT_FUNCTION_TARGET(RDRND) qsizetype qt_random_cpu(void *buffer, qsizetype { unsigned *ptr = reinterpret_cast(buffer); unsigned *end = ptr + count; + int retries = 10; while (ptr + sizeof(qregisteruint)/sizeof(*ptr) <= end) { - if (_rdrandXX_step(reinterpret_cast(ptr)) == 0) + if (_rdrandXX_step(reinterpret_cast(ptr))) + ptr += sizeof(qregisteruint)/sizeof(*ptr); + else if (--retries == 0) goto out; - ptr += sizeof(qregisteruint)/sizeof(*ptr); } - if (sizeof(*ptr) != sizeof(qregisteruint) && ptr != end) { - if (_rdrand32_step(ptr)) - goto out; - ++ptr; + while (sizeof(*ptr) != sizeof(qregisteruint) && ptr != end) { + bool ok = _rdrand32_step(ptr); + if (!ok && --retries) + continue; + if (ok) + ++ptr; + break; } out: -- 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') 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 7af6649e884f4ba9fa3fde0333090b93f62a13c0 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Tue, 3 Sep 2019 11:59:24 +0200 Subject: rhi: gl, metal, d3d: Reuse shader objects when source is the same MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now that Qt Quick's batch renderer misses one level of shader source caching due to the nature of pipeline state objects, it can be useful to keep and reuse shader objects when the hash of the source code matches. The goal here is to allow Qt Quick to be on par with what the direct OpenGL path has when it comes to caching shader sources and compilation results. The program binary disk cache is not in scope in this patch. Also adds QRhi::releaseCachedResources(), similarly to what the scenegraph has. This can be called to clear caches such as the shader object cache we keep here. Change-Id: Ie3d81d823f61fa65ec814439e882c498f7774d43 Reviewed-by: Christian Strømme --- src/gui/rhi/qrhi.cpp | 17 ++++ src/gui/rhi/qrhi_p.h | 2 + src/gui/rhi/qrhi_p_p.h | 3 + src/gui/rhi/qrhid3d11.cpp | 116 ++++++++++++++++------ src/gui/rhi/qrhid3d11_p_p.h | 10 ++ src/gui/rhi/qrhigles2.cpp | 63 ++++++++---- src/gui/rhi/qrhigles2_p_p.h | 3 + src/gui/rhi/qrhimetal.mm | 229 ++++++++++++++++++++++++++----------------- src/gui/rhi/qrhimetal_p_p.h | 1 + src/gui/rhi/qrhinull.cpp | 5 + src/gui/rhi/qrhinull_p_p.h | 1 + src/gui/rhi/qrhivulkan.cpp | 5 + src/gui/rhi/qrhivulkan_p_p.h | 1 + 13 files changed, 315 insertions(+), 141 deletions(-) (limited to 'src') diff --git a/src/gui/rhi/qrhi.cpp b/src/gui/rhi/qrhi.cpp index 4414b61d55..88d2f73541 100644 --- a/src/gui/rhi/qrhi.cpp +++ b/src/gui/rhi/qrhi.cpp @@ -5019,6 +5019,23 @@ QRhiProfiler *QRhi::profiler() return &d->profiler; } +/*! + Attempts to release resources in the backend's caches. This can include both + CPU and GPU resources. Only memory and resources that can be recreated + automatically are in scope. As an example, if the backend's + QRhiGraphicsPipeline implementation maintains a cache of shader compilation + results, calling this function leads to emptying that cache, thus + potentially freeing up memory and graphics resources. + + Calling this function makes sense in resource constrained environments, + where at a certain point there is a need to ensure minimal resource usage, + at the expense of performance. + */ +void QRhi::releaseCachedResources() +{ + d->releaseCachedResources(); +} + /*! \return a new graphics pipeline resource. diff --git a/src/gui/rhi/qrhi_p.h b/src/gui/rhi/qrhi_p.h index 2d36c19e99..928d1f8fa7 100644 --- a/src/gui/rhi/qrhi_p.h +++ b/src/gui/rhi/qrhi_p.h @@ -1420,6 +1420,8 @@ public: static const int MAX_LAYERS = 6; // cubemaps only static const int MAX_LEVELS = 16; // a width and/or height of 65536 should be enough for everyone + void releaseCachedResources(); + protected: QRhi(); diff --git a/src/gui/rhi/qrhi_p_p.h b/src/gui/rhi/qrhi_p_p.h index 0914cf268b..b69757ae6d 100644 --- a/src/gui/rhi/qrhi_p_p.h +++ b/src/gui/rhi/qrhi_p_p.h @@ -157,6 +157,7 @@ public: virtual const QRhiNativeHandles *nativeHandles() = 0; virtual void sendVMemStatsToProfiler() = 0; virtual void makeThreadLocalNativeContextCurrent() = 0; + virtual void releaseCachedResources() = 0; bool isCompressedFormat(QRhiTexture::Format format) const; void compressedFormatInfo(QRhiTexture::Format format, const QSize &size, @@ -205,6 +206,8 @@ public: QRhi *q; + static const int MAX_SHADER_CACHE_ENTRIES = 128; + protected: bool debugMarkers = false; int currentFrameSlot = 0; // for vk, mtl, and similar. unused by gl and d3d11. diff --git a/src/gui/rhi/qrhid3d11.cpp b/src/gui/rhi/qrhid3d11.cpp index 9e8533be23..93eadc047d 100644 --- a/src/gui/rhi/qrhid3d11.cpp +++ b/src/gui/rhi/qrhid3d11.cpp @@ -267,10 +267,20 @@ bool QRhiD3D11::create(QRhi::Flags flags) return true; } +void QRhiD3D11::clearShaderCache() +{ + for (Shader &s : m_shaderCache) + s.s->Release(); + + m_shaderCache.clear(); +} + void QRhiD3D11::destroy() { finishActiveReadbacks(); + clearShaderCache(); + if (annotations) { annotations->Release(); annotations = nullptr; @@ -461,6 +471,11 @@ void QRhiD3D11::makeThreadLocalNativeContextCurrent() // nothing to do here } +void QRhiD3D11::releaseCachedResources() +{ + clearShaderCache(); +} + QRhiRenderBuffer *QRhiD3D11::createRenderBuffer(QRhiRenderBuffer::Type type, const QSize &pixelSize, int sampleCount, QRhiRenderBuffer::Flags flags) { @@ -3408,30 +3423,57 @@ bool QD3D11GraphicsPipeline::build() QByteArray vsByteCode; for (const QRhiShaderStage &shaderStage : qAsConst(m_shaderStages)) { - QString error; - QByteArray bytecode = compileHlslShaderSource(shaderStage.shader(), shaderStage.shaderVariant(), &error); - if (bytecode.isEmpty()) { - qWarning("HLSL shader compilation failed: %s", qPrintable(error)); - return false; - } - switch (shaderStage.type()) { - case QRhiShaderStage::Vertex: - hr = rhiD->dev->CreateVertexShader(bytecode.constData(), bytecode.size(), nullptr, &vs); - if (FAILED(hr)) { - qWarning("Failed to create vertex shader: %s", qPrintable(comErrorMessage(hr))); - return false; + auto cacheIt = rhiD->m_shaderCache.constFind(shaderStage); + if (cacheIt != rhiD->m_shaderCache.constEnd()) { + switch (shaderStage.type()) { + case QRhiShaderStage::Vertex: + vs = static_cast(cacheIt->s); + vs->AddRef(); + vsByteCode = cacheIt->bytecode; + break; + case QRhiShaderStage::Fragment: + fs = static_cast(cacheIt->s); + fs->AddRef(); + break; + default: + break; } - vsByteCode = bytecode; - break; - case QRhiShaderStage::Fragment: - hr = rhiD->dev->CreatePixelShader(bytecode.constData(), bytecode.size(), nullptr, &fs); - if (FAILED(hr)) { - qWarning("Failed to create pixel shader: %s", qPrintable(comErrorMessage(hr))); + } else { + QString error; + const QByteArray bytecode = compileHlslShaderSource(shaderStage.shader(), shaderStage.shaderVariant(), &error); + if (bytecode.isEmpty()) { + qWarning("HLSL shader compilation failed: %s", qPrintable(error)); return false; } - break; - default: - break; + + if (rhiD->m_shaderCache.count() >= QRhiD3D11::MAX_SHADER_CACHE_ENTRIES) { + // Use the simplest strategy: too many cached shaders -> drop them all. + rhiD->clearShaderCache(); + } + + switch (shaderStage.type()) { + case QRhiShaderStage::Vertex: + hr = rhiD->dev->CreateVertexShader(bytecode.constData(), bytecode.size(), nullptr, &vs); + if (FAILED(hr)) { + qWarning("Failed to create vertex shader: %s", qPrintable(comErrorMessage(hr))); + return false; + } + vsByteCode = bytecode; + rhiD->m_shaderCache.insert(shaderStage, QRhiD3D11::Shader(vs, bytecode)); + vs->AddRef(); + break; + case QRhiShaderStage::Fragment: + hr = rhiD->dev->CreatePixelShader(bytecode.constData(), bytecode.size(), nullptr, &fs); + if (FAILED(hr)) { + qWarning("Failed to create pixel shader: %s", qPrintable(comErrorMessage(hr))); + return false; + } + rhiD->m_shaderCache.insert(shaderStage, QRhiD3D11::Shader(fs, bytecode)); + fs->AddRef(); + break; + default: + break; + } } } @@ -3501,19 +3543,31 @@ bool QD3D11ComputePipeline::build() QRHI_RES_RHI(QRhiD3D11); - QString error; - QByteArray bytecode = compileHlslShaderSource(m_shaderStage.shader(), m_shaderStage.shaderVariant(), &error); - if (bytecode.isEmpty()) { - qWarning("HLSL compute shader compilation failed: %s", qPrintable(error)); - return false; - } + auto cacheIt = rhiD->m_shaderCache.constFind(m_shaderStage); + if (cacheIt != rhiD->m_shaderCache.constEnd()) { + cs = static_cast(cacheIt->s); + } else { + QString error; + const QByteArray bytecode = compileHlslShaderSource(m_shaderStage.shader(), m_shaderStage.shaderVariant(), &error); + if (bytecode.isEmpty()) { + qWarning("HLSL compute shader compilation failed: %s", qPrintable(error)); + return false; + } - HRESULT hr = rhiD->dev->CreateComputeShader(bytecode.constData(), bytecode.size(), nullptr, &cs); - if (FAILED(hr)) { - qWarning("Failed to create compute shader: %s", qPrintable(comErrorMessage(hr))); - return false; + HRESULT hr = rhiD->dev->CreateComputeShader(bytecode.constData(), bytecode.size(), nullptr, &cs); + if (FAILED(hr)) { + qWarning("Failed to create compute shader: %s", qPrintable(comErrorMessage(hr))); + return false; + } + + if (rhiD->m_shaderCache.count() >= QRhiD3D11::MAX_SHADER_CACHE_ENTRIES) + rhiD->clearShaderCache(); + + rhiD->m_shaderCache.insert(m_shaderStage, QRhiD3D11::Shader(cs, bytecode)); } + cs->AddRef(); + generation += 1; rhiD->registerResource(this); return true; diff --git a/src/gui/rhi/qrhid3d11_p_p.h b/src/gui/rhi/qrhid3d11_p_p.h index 582146315d..cd44519aaa 100644 --- a/src/gui/rhi/qrhid3d11_p_p.h +++ b/src/gui/rhi/qrhid3d11_p_p.h @@ -632,6 +632,7 @@ public: const QRhiNativeHandles *nativeHandles() override; void sendVMemStatsToProfiler() override; void makeThreadLocalNativeContextCurrent() override; + void releaseCachedResources() override; void enqueueSubresUpload(QD3D11Texture *texD, QD3D11CommandBuffer *cbD, int layer, int level, const QRhiTextureSubresourceUploadDescription &subresDesc); @@ -646,6 +647,7 @@ public: DXGI_SAMPLE_DESC effectiveSampleCount(int sampleCount) const; void finishActiveReadbacks(); void reportLiveObjects(ID3D11Device *device); + void clearShaderCache(); bool debugLayer = false; bool importedDevice = false; @@ -684,6 +686,14 @@ public: QRhiTexture::Format format; }; QVector activeReadbacks; + + struct Shader { + Shader() = default; + Shader(IUnknown *s, const QByteArray &bytecode) : s(s), bytecode(bytecode) { } + IUnknown *s; + QByteArray bytecode; + }; + QHash m_shaderCache; }; Q_DECLARE_TYPEINFO(QRhiD3D11::ActiveReadback, Q_MOVABLE_TYPE); diff --git a/src/gui/rhi/qrhigles2.cpp b/src/gui/rhi/qrhigles2.cpp index f4e711e33e..9ad591a17a 100644 --- a/src/gui/rhi/qrhigles2.cpp +++ b/src/gui/rhi/qrhigles2.cpp @@ -502,6 +502,10 @@ void QRhiGles2::destroy() ensureContext(); executeDeferredReleases(); + for (uint shader : m_shaderCache) + f->glDeleteShader(shader); + m_shaderCache.clear(); + if (!importedContext) { delete ctx; ctx = nullptr; @@ -757,6 +761,17 @@ void QRhiGles2::makeThreadLocalNativeContextCurrent() ensureContext(); } +void QRhiGles2::releaseCachedResources() +{ + if (!ensureContext()) + return; + + for (uint shader : m_shaderCache) + f->glDeleteShader(shader); + + m_shaderCache.clear(); +} + QRhiRenderBuffer *QRhiGles2::createRenderBuffer(QRhiRenderBuffer::Type type, const QSize &pixelSize, int sampleCount, QRhiRenderBuffer::Flags flags) { @@ -2673,7 +2688,6 @@ static inline GLenum toGlShaderType(QRhiShaderStage::Type type) bool QRhiGles2::compileShader(GLuint program, const QRhiShaderStage &shaderStage, QShaderDescription *desc, int *glslVersionUsed) { - GLuint shader = f->glCreateShader(toGlShaderType(shaderStage.type())); const QShader bakedShader = shaderStage.shader(); QVector versionsToTry; QByteArray source; @@ -2733,27 +2747,40 @@ bool QRhiGles2::compileShader(GLuint program, const QRhiShaderStage &shaderStage return false; } - const char *srcStr = source.constData(); - const GLint srcLength = source.count(); - f->glShaderSource(shader, 1, &srcStr, &srcLength); - f->glCompileShader(shader); - GLint compiled = 0; - f->glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled); - if (!compiled) { - GLint infoLogLength = 0; - f->glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength); - QByteArray log; - if (infoLogLength > 1) { - GLsizei length = 0; - log.resize(infoLogLength); - f->glGetShaderInfoLog(shader, infoLogLength, &length, log.data()); + GLuint shader; + auto cacheIt = m_shaderCache.constFind(shaderStage); + if (cacheIt != m_shaderCache.constEnd()) { + shader = *cacheIt; + } else { + shader = f->glCreateShader(toGlShaderType(shaderStage.type())); + const char *srcStr = source.constData(); + const GLint srcLength = source.count(); + f->glShaderSource(shader, 1, &srcStr, &srcLength); + f->glCompileShader(shader); + GLint compiled = 0; + f->glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled); + if (!compiled) { + GLint infoLogLength = 0; + f->glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength); + QByteArray log; + if (infoLogLength > 1) { + GLsizei length = 0; + log.resize(infoLogLength); + f->glGetShaderInfoLog(shader, infoLogLength, &length, log.data()); + } + qWarning("Failed to compile shader: %s\nSource was:\n%s", log.constData(), source.constData()); + return false; } - qWarning("Failed to compile shader: %s\nSource was:\n%s", log.constData(), source.constData()); - return false; + if (m_shaderCache.count() >= MAX_SHADER_CACHE_ENTRIES) { + // Use the simplest strategy: too many cached shaders -> drop them all. + for (uint shader : m_shaderCache) + f->glDeleteShader(shader); // does not actually get released yet when attached to a not-yet-released program + m_shaderCache.clear(); + } + m_shaderCache.insert(shaderStage, shader); } f->glAttachShader(program, shader); - f->glDeleteShader(shader); *desc = bakedShader.description(); return true; diff --git a/src/gui/rhi/qrhigles2_p_p.h b/src/gui/rhi/qrhigles2_p_p.h index 6da529be92..877eb88d27 100644 --- a/src/gui/rhi/qrhigles2_p_p.h +++ b/src/gui/rhi/qrhigles2_p_p.h @@ -665,6 +665,7 @@ public: const QRhiNativeHandles *nativeHandles() override; void sendVMemStatsToProfiler() override; void makeThreadLocalNativeContextCurrent() override; + void releaseCachedResources() override; bool ensureContext(QSurface *surface = nullptr) const; void executeDeferredReleases(); @@ -804,6 +805,8 @@ public: bool active = false; QGles2CommandBuffer cbWrapper; } ofr; + + QHash m_shaderCache; }; Q_DECLARE_TYPEINFO(QRhiGles2::DeferredReleaseEntry, Q_MOVABLE_TYPE); diff --git a/src/gui/rhi/qrhimetal.mm b/src/gui/rhi/qrhimetal.mm index dfa79edb00..a14ffa7173 100644 --- a/src/gui/rhi/qrhimetal.mm +++ b/src/gui/rhi/qrhimetal.mm @@ -138,6 +138,20 @@ QT_BEGIN_NAMESPACE \l{QRhiCommandBuffer::endPass()}. */ +struct QMetalShader +{ + id lib = nil; + id func = nil; + std::array localSize; + + void release() { + [lib release]; + lib = nil; + [func release]; + func = nil; + } +}; + struct QRhiMetalData { QRhiMetalData(QRhiImplementation *rhi) : ofr(rhi) { } @@ -206,6 +220,8 @@ struct QRhiMetalData API_AVAILABLE(macos(10.13), ios(11.0)) id captureScope = nil; static const int TEXBUF_ALIGN = 256; // probably not accurate + + QHash shaderCache; }; Q_DECLARE_TYPEINFO(QRhiMetalData::DeferredReleaseEntry, Q_MOVABLE_TYPE); @@ -289,17 +305,14 @@ struct QMetalGraphicsPipelineData MTLPrimitiveType primitiveType; MTLWinding winding; MTLCullMode cullMode; - id vsLib = nil; - id vsFunc = nil; - id fsLib = nil; - id fsFunc = nil; + QMetalShader vs; + QMetalShader fs; }; struct QMetalComputePipelineData { id ps = nil; - id csLib = nil; - id csFunc = nil; + QMetalShader cs; MTLSize localSize; }; @@ -404,6 +417,10 @@ void QRhiMetal::destroy() executeDeferredReleases(true); finishActiveReadbacks(true); + for (QMetalShader &s : d->shaderCache) + s.release(); + d->shaderCache.clear(); + if (@available(macOS 10.13, iOS 11.0, *)) { [d->captureScope release]; d->captureScope = nil; @@ -570,6 +587,14 @@ void QRhiMetal::makeThreadLocalNativeContextCurrent() // nothing to do here } +void QRhiMetal::releaseCachedResources() +{ + for (QMetalShader &s : d->shaderCache) + s.release(); + + d->shaderCache.clear(); +} + QRhiRenderBuffer *QRhiMetal::createRenderBuffer(QRhiRenderBuffer::Type type, const QSize &pixelSize, int sampleCount, QRhiRenderBuffer::Flags flags) { @@ -2843,36 +2868,17 @@ void QMetalGraphicsPipeline::release() { QRHI_RES_RHI(QRhiMetal); - if (!d->ps) - return; - - if (d->ps) { - [d->ps release]; - d->ps = nil; - } + d->vs.release(); + d->fs.release(); - if (d->ds) { - [d->ds release]; - d->ds = nil; - } + [d->ds release]; + d->ds = nil; - if (d->vsFunc) { - [d->vsFunc release]; - d->vsFunc = nil; - } - if (d->vsLib) { - [d->vsLib release]; - d->vsLib = nil; - } + if (!d->ps) + return; - if (d->fsFunc) { - [d->fsFunc release]; - d->fsFunc = nil; - } - if (d->fsLib) { - [d->fsLib release]; - d->fsLib = nil; - } + [d->ps release]; + d->ps = nil; rhiD->unregisterResource(this); } @@ -3159,34 +3165,66 @@ bool QMetalGraphicsPipeline::build() // buffers not just the resource binding layout) so leave it at the default for (const QRhiShaderStage &shaderStage : qAsConst(m_shaderStages)) { - QString error; - QByteArray entryPoint; - id lib = rhiD->d->createMetalLib(shaderStage.shader(), shaderStage.shaderVariant(), &error, &entryPoint); - if (!lib) { - qWarning("MSL shader compilation failed: %s", qPrintable(error)); - return false; - } - id func = rhiD->d->createMSLShaderFunction(lib, entryPoint); - if (!func) { - qWarning("MSL function for entry point %s not found", entryPoint.constData()); - [lib release]; - return false; - } - switch (shaderStage.type()) { - case QRhiShaderStage::Vertex: - rpDesc.vertexFunction = func; - d->vsLib = lib; - d->vsFunc = func; - break; - case QRhiShaderStage::Fragment: - rpDesc.fragmentFunction = func; - d->fsLib = lib; - d->fsFunc = func; - break; - default: - [func release]; - [lib release]; - break; + auto cacheIt = rhiD->d->shaderCache.constFind(shaderStage); + if (cacheIt != rhiD->d->shaderCache.constEnd()) { + switch (shaderStage.type()) { + case QRhiShaderStage::Vertex: + d->vs = *cacheIt; + [d->vs.lib retain]; + [d->vs.func retain]; + rpDesc.vertexFunction = d->vs.func; + break; + case QRhiShaderStage::Fragment: + d->fs = *cacheIt; + [d->fs.lib retain]; + [d->fs.func retain]; + rpDesc.fragmentFunction = d->fs.func; + break; + default: + break; + } + } else { + QString error; + QByteArray entryPoint; + id lib = rhiD->d->createMetalLib(shaderStage.shader(), shaderStage.shaderVariant(), &error, &entryPoint); + if (!lib) { + qWarning("MSL shader compilation failed: %s", qPrintable(error)); + return false; + } + id func = rhiD->d->createMSLShaderFunction(lib, entryPoint); + if (!func) { + qWarning("MSL function for entry point %s not found", entryPoint.constData()); + [lib release]; + return false; + } + if (rhiD->d->shaderCache.count() >= QRhiMetal::MAX_SHADER_CACHE_ENTRIES) { + // Use the simplest strategy: too many cached shaders -> drop them all. + for (QMetalShader &s : rhiD->d->shaderCache) + s.release(); + rhiD->d->shaderCache.clear(); + } + switch (shaderStage.type()) { + case QRhiShaderStage::Vertex: + d->vs.lib = lib; + d->vs.func = func; + rhiD->d->shaderCache.insert(shaderStage, d->vs); + [d->vs.lib retain]; + [d->vs.func retain]; + rpDesc.vertexFunction = func; + break; + case QRhiShaderStage::Fragment: + d->fs.lib = lib; + d->fs.func = func; + rhiD->d->shaderCache.insert(shaderStage, d->fs); + [d->fs.lib retain]; + [d->fs.func retain]; + rpDesc.fragmentFunction = func; + break; + default: + [func release]; + [lib release]; + break; + } } } @@ -3286,22 +3324,13 @@ void QMetalComputePipeline::release() { QRHI_RES_RHI(QRhiMetal); - if (d->csFunc) { - [d->csFunc release]; - d->csFunc = nil; - } - if (d->csLib) { - [d->csLib release]; - d->csLib = nil; - } + d->cs.release(); if (!d->ps) return; - if (d->ps) { - [d->ps release]; - d->ps = nil; - } + [d->ps release]; + d->ps = nil; rhiD->unregisterResource(this); } @@ -3313,28 +3342,44 @@ bool QMetalComputePipeline::build() QRHI_RES_RHI(QRhiMetal); - const QShader shader = m_shaderStage.shader(); - QString error; - QByteArray entryPoint; - id lib = rhiD->d->createMetalLib(shader, m_shaderStage.shaderVariant(), - &error, &entryPoint); - if (!lib) { - qWarning("MSL shader compilation failed: %s", qPrintable(error)); - return false; - } - id func = rhiD->d->createMSLShaderFunction(lib, entryPoint); - if (!func) { - qWarning("MSL function for entry point %s not found", entryPoint.constData()); - [lib release]; - return false; + auto cacheIt = rhiD->d->shaderCache.constFind(m_shaderStage); + if (cacheIt != rhiD->d->shaderCache.constEnd()) { + d->cs = *cacheIt; + } else { + const QShader shader = m_shaderStage.shader(); + QString error; + QByteArray entryPoint; + id lib = rhiD->d->createMetalLib(shader, m_shaderStage.shaderVariant(), + &error, &entryPoint); + if (!lib) { + qWarning("MSL shader compilation failed: %s", qPrintable(error)); + return false; + } + id func = rhiD->d->createMSLShaderFunction(lib, entryPoint); + if (!func) { + qWarning("MSL function for entry point %s not found", entryPoint.constData()); + [lib release]; + return false; + } + d->cs.lib = lib; + d->cs.func = func; + d->cs.localSize = shader.description().computeShaderLocalSize(); + + if (rhiD->d->shaderCache.count() >= QRhiMetal::MAX_SHADER_CACHE_ENTRIES) { + for (QMetalShader &s : rhiD->d->shaderCache) + s.release(); + rhiD->d->shaderCache.clear(); + } + rhiD->d->shaderCache.insert(m_shaderStage, d->cs); } - d->csLib = lib; - d->csFunc = func; - std::array localSize = shader.description().computeShaderLocalSize(); - d->localSize = MTLSizeMake(localSize[0], localSize[1], localSize[2]); + + [d->cs.lib retain]; + [d->cs.func retain]; + + d->localSize = MTLSizeMake(d->cs.localSize[0], d->cs.localSize[1], d->cs.localSize[2]); NSError *err = nil; - d->ps = [rhiD->d->dev newComputePipelineStateWithFunction: d->csFunc error: &err]; + d->ps = [rhiD->d->dev newComputePipelineStateWithFunction: d->cs.func error: &err]; if (!d->ps) { const QString msg = QString::fromNSString(err.localizedDescription); qWarning("Failed to create render pipeline state: %s", qPrintable(msg)); diff --git a/src/gui/rhi/qrhimetal_p_p.h b/src/gui/rhi/qrhimetal_p_p.h index c448865f4d..01b0bf4f56 100644 --- a/src/gui/rhi/qrhimetal_p_p.h +++ b/src/gui/rhi/qrhimetal_p_p.h @@ -417,6 +417,7 @@ public: const QRhiNativeHandles *nativeHandles() override; void sendVMemStatsToProfiler() override; void makeThreadLocalNativeContextCurrent() override; + void releaseCachedResources() override; void executeDeferredReleases(bool forced = false); void finishActiveReadbacks(bool forced = false); diff --git a/src/gui/rhi/qrhinull.cpp b/src/gui/rhi/qrhinull.cpp index dff6e05268..29a3968bfc 100644 --- a/src/gui/rhi/qrhinull.cpp +++ b/src/gui/rhi/qrhinull.cpp @@ -174,6 +174,11 @@ void QRhiNull::makeThreadLocalNativeContextCurrent() // nothing to do here } +void QRhiNull::releaseCachedResources() +{ + // nothing to do here +} + QRhiRenderBuffer *QRhiNull::createRenderBuffer(QRhiRenderBuffer::Type type, const QSize &pixelSize, int sampleCount, QRhiRenderBuffer::Flags flags) { diff --git a/src/gui/rhi/qrhinull_p_p.h b/src/gui/rhi/qrhinull_p_p.h index bdf0d59724..b43f830d5e 100644 --- a/src/gui/rhi/qrhinull_p_p.h +++ b/src/gui/rhi/qrhinull_p_p.h @@ -283,6 +283,7 @@ public: const QRhiNativeHandles *nativeHandles() override; void sendVMemStatsToProfiler() override; void makeThreadLocalNativeContextCurrent() override; + void releaseCachedResources() override; QRhiNullNativeHandles nativeHandlesStruct; QRhiSwapChain *currentSwapChain = nullptr; diff --git a/src/gui/rhi/qrhivulkan.cpp b/src/gui/rhi/qrhivulkan.cpp index dfc85fb853..4f550c6a90 100644 --- a/src/gui/rhi/qrhivulkan.cpp +++ b/src/gui/rhi/qrhivulkan.cpp @@ -3744,6 +3744,11 @@ void QRhiVulkan::makeThreadLocalNativeContextCurrent() // nothing to do here } +void QRhiVulkan::releaseCachedResources() +{ + // nothing to do here +} + QRhiRenderBuffer *QRhiVulkan::createRenderBuffer(QRhiRenderBuffer::Type type, const QSize &pixelSize, int sampleCount, QRhiRenderBuffer::Flags flags) { diff --git a/src/gui/rhi/qrhivulkan_p_p.h b/src/gui/rhi/qrhivulkan_p_p.h index 962a1b8eb7..23cc80b814 100644 --- a/src/gui/rhi/qrhivulkan_p_p.h +++ b/src/gui/rhi/qrhivulkan_p_p.h @@ -712,6 +712,7 @@ public: const QRhiNativeHandles *nativeHandles() override; void sendVMemStatsToProfiler() override; void makeThreadLocalNativeContextCurrent() override; + void releaseCachedResources() override; VkResult createDescriptorPool(VkDescriptorPool *pool); bool allocateDescriptorSet(VkDescriptorSetAllocateInfo *allocInfo, VkDescriptorSet *result, int *resultPoolIndex); -- cgit v1.2.3 From 5f570aa64d13bf21677990f3e0deb8c4bb5f7b5d Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sun, 8 Sep 2019 21:08:35 +0200 Subject: QComboBox: add documentation for textHighlighted/textActivated The documentation for textHighlighted/textActivated was not added within bdf1c4f671c706832cea84269e91995e85eb9f07 so add it now. Change-Id: Ifa7ad72af4490d4ce1d6de00d0963c0e76013f42 Reviewed-by: Friedemann Kleint --- src/widgets/widgets/qcombobox.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp index e73c63f657..a53c278aea 100644 --- a/src/widgets/widgets/qcombobox.cpp +++ b/src/widgets/widgets/qcombobox.cpp @@ -862,6 +862,16 @@ QStyleOptionComboBox QComboBoxPrivateContainer::comboStyleOption() const when the choice is not changed. If you need to know when the choice actually changes, use signal currentIndexChanged(). + \obsolete Use QComboBox::textActivated() instead +*/ +/*! + \fn void QComboBox::textActivated(const QString &text) + \since 5.14 + + This signal is sent when the user chooses an item in the combobox. + The item's \a text is passed. Note that this signal is sent even + when the choice is not changed. If you need to know when the + choice actually changes, use signal currentIndexChanged(). */ /*! @@ -876,6 +886,15 @@ QStyleOptionComboBox QComboBoxPrivateContainer::comboStyleOption() const This signal is sent when an item in the combobox popup list is highlighted by the user. The item's \a text is passed. + + \obsolete Use textHighlighted() instead +*/ +/*! + \fn void QComboBox::textHighlighted(const QString &text) + \since 5.14 + + This signal is sent when an item in the combobox popup list is + highlighted by the user. The item's \a text is passed. */ /*! @@ -888,7 +907,6 @@ QStyleOptionComboBox QComboBoxPrivateContainer::comboStyleOption() const currentIndex was reset. */ -#if QT_DEPRECATED_SINCE(5, 13) /*! \fn void QComboBox::currentIndexChanged(const QString &text) \since 4.1 @@ -897,7 +915,6 @@ QStyleOptionComboBox QComboBoxPrivateContainer::comboStyleOption() const changes either through user interaction or programmatically. The item's \a text is passed. */ -#endif /*! \fn void QComboBox::currentTextChanged(const QString &text) -- cgit v1.2.3 From e018d11600bffc6e54cddd3857822516f3f501a0 Mon Sep 17 00:00:00 2001 From: David Faure Date: Sat, 7 Sep 2019 22:32:35 +0200 Subject: Dpi settings: QT_SCREEN_SCALE_FACTORS enables scaling again MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit commit 900f2cb6f7070 removed this from the condition, which breaks the (common) case of having QT_AUTO_SCREEN_SCALE_FACTOR=0 and QT_SCREEN_SCALE_FACTORS set. This used to obey the screen scale factors, so it should still do so (despite the deprecation warning). This is what the Plasma `kcmshell5 kscreen` module actually sets (via startkde). Change-Id: I5f4efed11b937498049ebf1b107954721cf54147 Reviewed-by: Friedemann Kleint Reviewed-by: Morten Johan Sørvig --- src/gui/kernel/qhighdpiscaling.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/gui/kernel/qhighdpiscaling.cpp b/src/gui/kernel/qhighdpiscaling.cpp index ec4feeba8b..dcbae4f5c0 100644 --- a/src/gui/kernel/qhighdpiscaling.cpp +++ b/src/gui/kernel/qhighdpiscaling.cpp @@ -538,7 +538,7 @@ void QHighDpiScaling::updateHighDpiScaling() ++i; } } - m_active = m_globalScalingActive || m_usePixelDensity; + m_active = m_globalScalingActive || m_screenFactorSet || m_usePixelDensity; } /* -- cgit v1.2.3 From 97b9af1519ad3809a7900f0ac1f5710a439c87c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Fri, 6 Sep 2019 13:51:37 +0200 Subject: Schannel: unbreak renegotiation (and likely gracious shutdown) The reason it wasn't working before was a couple of things: 1. Due to an extra 'else' it would not process the SEC_I_RENEGOTIATE or SEC_I_CONTEXT_EXPIRED branch. 2. The peerCertVerified boolean was not only wrong, but also broke renegotiation even if the 'else' wasn't there. My previous attempt to fix it ended up being a noop, so: Reverts e21fa577dde32849fdaa744f30ad3b23d63b7214 Change-Id: Ifbad55d4bb066b7566bb88cead48e329cbd574f9 Reviewed-by: Timur Pocheptsov --- src/network/ssl/qsslsocket_schannel.cpp | 19 ++++--------------- src/network/ssl/qsslsocket_schannel_p.h | 1 - 2 files changed, 4 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/network/ssl/qsslsocket_schannel.cpp b/src/network/ssl/qsslsocket_schannel.cpp index 88f66ac4ea..37705b03a1 100644 --- a/src/network/ssl/qsslsocket_schannel.cpp +++ b/src/network/ssl/qsslsocket_schannel.cpp @@ -1069,7 +1069,6 @@ bool QSslSocketBackendPrivate::verifyHandshake() } schannelState = SchannelState::Done; - peerCertVerified = true; return true; } @@ -1152,7 +1151,6 @@ void QSslSocketBackendPrivate::reset() connectionEncrypted = false; shutdown = false; - peerCertVerified = false; renegotiating = false; } @@ -1315,7 +1313,9 @@ void QSslSocketBackendPrivate::transmit() #endif intermediateBuffer = ciphertext.right(int(dataBuffer[3].cbBuffer)); } - } else if (status == SEC_E_INCOMPLETE_MESSAGE) { + } + + if (status == SEC_E_INCOMPLETE_MESSAGE) { // Need more data before we can decrypt.. to the buffer it goes! #ifdef QSSLSOCKET_DEBUG qCDebug(lcSsl, "We didn't have enough data to decrypt anything, will try again!"); @@ -1361,17 +1361,6 @@ void QSslSocketBackendPrivate::transmit() schannelState = SchannelState::Renegotiate; renegotiating = true; - if (dataBuffer[3].BufferType == SECBUFFER_EXTRA) { - // https://docs.microsoft.com/en-us/windows/desktop/secauthn/extra-buffers-returned-by-schannel - // dataBuffer[3].cbBuffer indicates the amount of bytes _NOT_ processed, - // the rest need to be stored. -#ifdef QSSLSOCKET_DEBUG - qCDebug(lcSsl) << "We've got excess data, moving it to the intermediate buffer:" - << dataBuffer[3].cbBuffer << "bytes"; -#endif - intermediateBuffer = ciphertext.right(int(dataBuffer[3].cbBuffer)); - } - // We need to call 'continueHandshake' or else there's no guarantee it ever gets called continueHandshake(); break; @@ -1537,7 +1526,7 @@ void QSslSocketBackendPrivate::continueHandshake() case SchannelState::VerifyHandshake: // if we're in shutdown or renegotiating then we might not need to verify // (since we already did) - if (!peerCertVerified && !verifyHandshake()) { + if (!verifyHandshake()) { shutdown = true; // Skip sending shutdown alert q->abort(); // We don't want to send buffered data disconnectFromHost(); diff --git a/src/network/ssl/qsslsocket_schannel_p.h b/src/network/ssl/qsslsocket_schannel_p.h index 9879e2fc60..6ab200e1f9 100644 --- a/src/network/ssl/qsslsocket_schannel_p.h +++ b/src/network/ssl/qsslsocket_schannel_p.h @@ -147,7 +147,6 @@ private: ULONG contextAttributes = 0; bool renegotiating = false; - bool peerCertVerified = false; }; QT_END_NAMESPACE -- cgit v1.2.3 From e5e8f1d67ce5f74ccb345086667933266543fd51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Fri, 6 Sep 2019 13:01:43 +0200 Subject: Schannel: handle SEC_E_INCOMPLETE_DATA in acceptContext It's not a failure state, we just need more data. It is handled properly in other functions. Change-Id: I9450a78c71a3f4fe9506a7a79de6efa2db08697c Reviewed-by: Timur Pocheptsov --- src/network/ssl/qsslsocket_schannel.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/network/ssl/qsslsocket_schannel.cpp b/src/network/ssl/qsslsocket_schannel.cpp index 37705b03a1..339ecf4da2 100644 --- a/src/network/ssl/qsslsocket_schannel.cpp +++ b/src/network/ssl/qsslsocket_schannel.cpp @@ -828,12 +828,17 @@ bool QSslSocketBackendPrivate::acceptContext() &expiry // ptsTimeStamp ); + if (status == SEC_E_INCOMPLETE_MESSAGE) { + // Need more data + return true; + } + if (inBuffers[1].BufferType == SECBUFFER_EXTRA) { // https://docs.microsoft.com/en-us/windows/desktop/secauthn/extra-buffers-returned-by-schannel // inBuffers[1].cbBuffer indicates the amount of bytes _NOT_ processed, the rest need to // be stored. intermediateBuffer = intermediateBuffer.right(int(inBuffers[1].cbBuffer)); - } else if (status != SEC_E_INCOMPLETE_MESSAGE) { + } else { /* No 'extra' data, message not incomplete */ intermediateBuffer.clear(); } -- cgit v1.2.3 From 648dac1ceb40a346adf2081997f5c6166c3ad503 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Thu, 5 Sep 2019 17:01:23 +0200 Subject: QMenu::popup(): don't change the menu's screen if called from exec() Since b3fc5e1ea3eb4fe838ac716aaca4efaa5de5a814, topData()->initialScreenIndex has always been short-lived: it only remembers the screen in case the widget parent is a QDesktopScreenWidget (gotten from QDesktopWidget::screen()), only until the window is created. Then it is reset. In the case of exec() we need to avoid calling setScreen() twice, because that would set the screen once, then forget which screen it was supposed to be on, then set the screen again when exec() calls popup(). This is achieved by using the stored eventLoop pointer to detect that popup() is being called from exec(), and avoid calling setScreen() a second time in popup(), because exec() already needed to call createWinId() before it created the event loop. Amends 82da8306bc1313b85632eee0faf858239261a092 Task-number: QTBUG-76162 Change-Id: I70da517b9d530630e59d103cb2a1ce11c897b2c8 Reviewed-by: Friedemann Kleint Reviewed-by: Joni Poikelin --- src/widgets/widgets/qmenu.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp index e38490dabd..51b458f03a 100644 --- a/src/widgets/widgets/qmenu.cpp +++ b/src/widgets/widgets/qmenu.cpp @@ -2332,14 +2332,17 @@ void QMenu::popup(const QPoint &p, QAction *atAction) // However if the QMenu was constructed with a QDesktopScreenWidget as its parent, // then initialScreenIndex was set, so we should respect that for the lifetime of this menu. // Use d->popupScreen to remember, because initialScreenIndex will be reset after the first showing. - const int screenIndex = d->topData()->initialScreenIndex; - if (screenIndex >= 0) - d->popupScreen = screenIndex; - if (auto s = QGuiApplication::screens().value(d->popupScreen)) { - if (d->setScreen(s)) + // However if eventLoop exists, then exec() already did this by calling createWinId(); so leave it alone. (QTBUG-76162) + if (!d->eventLoop) { + const int screenIndex = d->topData()->initialScreenIndex; + if (screenIndex >= 0) + d->popupScreen = screenIndex; + if (auto s = QGuiApplication::screens().value(d->popupScreen)) { + if (d->setScreen(s)) + d->itemsDirty = true; + } else if (d->setScreenForPoint(p)) { d->itemsDirty = true; - } else if (d->setScreenForPoint(p)) { - d->itemsDirty = true; + } } const bool contextMenu = d->isContextMenu(); -- 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') 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 49362d064fffe350600f5324fb510b381578d04a Mon Sep 17 00:00:00 2001 From: Sona Kurazyan Date: Wed, 4 Sep 2019 17:26:33 +0200 Subject: Add a QSplashScreen constructor taking a QScreen MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The constructor taking a QWidget is needed for specifying the screen where the splash screen should be displayed. Add a new constructor for specifying the target screen for the splash screen directly, instead of "extracting" the screen information from a widget. This removes the need for using the deprecated QDesktopWidget. Deprecate the constructor taking a QWidget. Task-number: QTBUG-76491 Change-Id: I1dde242ff5f7b53e52af308bb685f492d6266d33 Reviewed-by: Tor Arne Vestbø --- src/widgets/doc/snippets/qsplashscreen/main.cpp | 7 +++++ src/widgets/widgets/qsplashscreen.cpp | 38 +++++++++++++++++++++++-- src/widgets/widgets/qsplashscreen.h | 4 +++ 3 files changed, 46 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/widgets/doc/snippets/qsplashscreen/main.cpp b/src/widgets/doc/snippets/qsplashscreen/main.cpp index 843932ca83..2512035879 100644 --- a/src/widgets/doc/snippets/qsplashscreen/main.cpp +++ b/src/widgets/doc/snippets/qsplashscreen/main.cpp @@ -71,3 +71,10 @@ int main(int argc, char *argv[]) return app.exec(); } //! [1] + +//! [2] +QScreen *screen = QGuiApplication::screens().at(1); +QPixmap pixmap(":/splash.png"); +QSplashScreen splash(screen, pixmap); +splash.show(); +//! [2] diff --git a/src/widgets/widgets/qsplashscreen.cpp b/src/widgets/widgets/qsplashscreen.cpp index e39ef6d1cd..b7c3426e08 100644 --- a/src/widgets/widgets/qsplashscreen.cpp +++ b/src/widgets/widgets/qsplashscreen.cpp @@ -123,6 +123,11 @@ public: wish to do your own drawing you can get a pointer to the pixmap used in the splash screen with pixmap(). Alternatively, you can subclass QSplashScreen and reimplement drawContents(). + + In case of having multiple screens, it is also possible to show the + splash screen on a different screen than the primary one. For example: + + \snippet qsplashscreen/main.cpp 2 */ /*! @@ -139,6 +144,23 @@ QSplashScreen::QSplashScreen(const QPixmap &pixmap, Qt::WindowFlags f) /*! \overload + \since 5.15 + + This function allows you to specify the screen for your splashscreen. The + typical use for this constructor is if you have multiple screens and + prefer to have the splash screen on a different screen than your primary + one. In that case pass the proper \a screen. +*/ +QSplashScreen::QSplashScreen(QScreen *screen, const QPixmap &pixmap, Qt::WindowFlags f) + : QWidget(*(new QSplashScreenPrivate()), nullptr, Qt::SplashScreen | Qt::FramelessWindowHint | f) +{ + d_func()->setPixmap(pixmap, screen); +} + +#if QT_DEPRECATED_SINCE(5, 15) +/*! + \overload + \obsolete This function allows you to specify a parent for your splashscreen. The typical use for this constructor is if you have a multiple screens and @@ -152,6 +174,7 @@ QSplashScreen::QSplashScreen(QWidget *parent, const QPixmap &pixmap, Qt::WindowF // is still 0 here due to QWidget's special handling. d_func()->setPixmap(pixmap, QSplashScreenPrivate::screenFor(parent)); } +#endif /*! Destructor. @@ -286,26 +309,35 @@ void QSplashScreen::setPixmap(const QPixmap &pixmap) } // In setPixmap(), resize and try to position on a screen according to: -// 1) If a QDesktopScreenWidget is found in the parent hierarchy, use that (see docs on +// 1) If the screen for the given widget is available, use that +// 2) If a QDesktopScreenWidget is found in the parent hierarchy, use that (see docs on // QSplashScreen(QWidget *, QPixmap). -// 2) If a widget with associated QWindow is found, use that -// 3) When nothing can be found, try to center it over the cursor +// 3) If a widget with associated QWindow is found, use that +// 4) When nothing can be found, try to center it over the cursor +#if QT_DEPRECATED_SINCE(5, 15) static inline int screenNumberOf(const QDesktopScreenWidget *dsw) { auto desktopWidgetPrivate = static_cast(qt_widget_private(QApplication::desktop())); return desktopWidgetPrivate->screens.indexOf(const_cast(dsw)); } +#endif const QScreen *QSplashScreenPrivate::screenFor(const QWidget *w) { + if (w && w->screen()) + return w->screen(); + for (const QWidget *p = w; p !=nullptr ; p = p->parentWidget()) { +#if QT_DEPRECATED_SINCE(5, 15) if (auto dsw = qobject_cast(p)) return QGuiApplication::screens().value(screenNumberOf(dsw)); +#endif if (QWindow *window = p->windowHandle()) return window->screen(); } + #if QT_CONFIG(cursor) // Note: We could rely on QPlatformWindow::initialGeometry() to center it // over the cursor, but not all platforms (namely Android) use that. diff --git a/src/widgets/widgets/qsplashscreen.h b/src/widgets/widgets/qsplashscreen.h index 8bdf4e7749..1877493fcf 100644 --- a/src/widgets/widgets/qsplashscreen.h +++ b/src/widgets/widgets/qsplashscreen.h @@ -55,7 +55,11 @@ class Q_WIDGETS_EXPORT QSplashScreen : public QWidget Q_OBJECT public: explicit QSplashScreen(const QPixmap &pixmap = QPixmap(), Qt::WindowFlags f = Qt::WindowFlags()); + QSplashScreen(QScreen *screen, const QPixmap &pixmap = QPixmap(), Qt::WindowFlags f = Qt::WindowFlags()); +#if QT_DEPRECATED_SINCE(5, 15) + QT_DEPRECATED_VERSION_X_5_15("Use the constructor taking a QScreen *") QSplashScreen(QWidget *parent, const QPixmap &pixmap = QPixmap(), Qt::WindowFlags f = Qt::WindowFlags()); +#endif virtual ~QSplashScreen(); void setPixmap(const QPixmap &pixmap); -- cgit v1.2.3 From c0b3c06a7d4f6a2f90742e8dc81c898082a70416 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 5 Sep 2019 09:52:05 +0200 Subject: QFileDialog: Fix volume name display on Windows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The volume names displayed did not match those of Windows Explorer; for example "New Volume (X:)" would be displayed for mapped network drives. Replace GetVolumeInformation() and manual formatting by the normal display name of IShellItem. Fixes: QTBUG-78043 Change-Id: Ia742b7733e8ddc31e9506f15d90d065b985a111d Reviewed-by: André de la Rocha --- src/widgets/dialogs/qfilesystemmodel.cpp | 39 +++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/widgets/dialogs/qfilesystemmodel.cpp b/src/widgets/dialogs/qfilesystemmodel.cpp index e9e49e0c33..a04189513a 100644 --- a/src/widgets/dialogs/qfilesystemmodel.cpp +++ b/src/widgets/dialogs/qfilesystemmodel.cpp @@ -57,6 +57,9 @@ #ifdef Q_OS_WIN # include # include +# ifndef Q_OS_WINRT +# include +# endif #endif QT_BEGIN_NAMESPACE @@ -837,8 +840,8 @@ QString QFileSystemModelPrivate::displayName(const QModelIndex &index) const { #if defined(Q_OS_WIN) QFileSystemNode *dirNode = node(index); - if (!dirNode->volumeName.isNull()) - return dirNode->volumeName + QLatin1String(" (") + name(index) + QLatin1Char(')'); + if (!dirNode->volumeName.isEmpty()) + return dirNode->volumeName; #endif return name(index); } @@ -1773,6 +1776,27 @@ void QFileSystemModelPrivate::_q_directoryChanged(const QString &directory, cons removeNode(parentNode, toRemove[i]); } +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) +static QString volumeName(const QString &path) +{ + IShellItem *item = nullptr; + const QString native = QDir::toNativeSeparators(path); + HRESULT hr = SHCreateItemFromParsingName(reinterpret_cast(native.utf16()), + nullptr, IID_IShellItem, + reinterpret_cast(&item)); + if (FAILED(hr)) + return QString(); + LPWSTR name = nullptr; + hr = item->GetDisplayName(SIGDN_NORMALDISPLAY, &name); + if (FAILED(hr)) + return QString(); + QString result = QString::fromWCharArray(name); + CoTaskMemFree(name); + item->Release(); + return result; +} +#endif // Q_OS_WIN && !Q_OS_WINRT + /*! \internal @@ -1791,15 +1815,8 @@ QFileSystemModelPrivate::QFileSystemNode* QFileSystemModelPrivate::addNode(QFile #endif #if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) //The parentNode is "" so we are listing the drives - if (parentNode->fileName.isEmpty()) { - wchar_t name[MAX_PATH + 1]; - //GetVolumeInformation requires to add trailing backslash - const QString nodeName = fileName + QLatin1String("\\"); - BOOL success = ::GetVolumeInformation((wchar_t *)(nodeName.utf16()), - name, MAX_PATH + 1, NULL, 0, NULL, NULL, 0); - if (success && name[0]) - node->volumeName = QString::fromWCharArray(name); - } + if (parentNode->fileName.isEmpty()) + node->volumeName = volumeName(fileName); #endif Q_ASSERT(!parentNode->children.contains(fileName)); parentNode->children.insert(fileName, node); -- 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') 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 66a4001fa28de5d3eac03c2662556d2d5511b0a3 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 9 Sep 2019 17:09:45 +0200 Subject: Fix qdoc warnings src/corelib/global/qnamespace.qdoc:3279: (qdoc) warning: Can't link to 'QGuiApplication::setHighDdpiScaleFactorRoundingPolicy()' src/corelib/time/qislamiccivilcalendar.cpp:49: (qdoc) warning: Can't link to 'QJijriCalendar' src/network/ssl/qsslsocket.cpp:1510: (qdoc) warning: Can't link to 'QSslConfiguration::defaultCaCertificates()' src/network/access/qhttp2configuration.cpp:49: (qdoc) warning: '\brief' statement does not end with a full stop. src/gui/text/qtextformat.cpp:532: (qdoc) warning: Undocumented enum item 'TableBorderCollapse' in QTextFormat::Property src/gui/text/qtextdocument.cpp:2066: (qdoc) warning: Undocumented enum item 'UnknownResource' in QTextDocument::ResourceType src/gui/kernel/qguiapplication.cpp:3500: (qdoc) warning: Undocumented parameter 'policy' in QGuiApplication::setHighDpiScaleFactorRoundingPolicy() Change-Id: I3573ef98cf9b58d16525c356270fe009fdffcf45 Reviewed-by: Shawn Rutledge --- src/corelib/global/qnamespace.qdoc | 2 +- src/corelib/time/qhijricalendar.cpp | 1 + src/corelib/time/qislamiccivilcalendar.cpp | 3 ++- src/gui/kernel/qguiapplication.cpp | 2 +- src/gui/text/qtextdocument.cpp | 5 +++-- src/gui/text/qtextformat.cpp | 1 + src/network/access/qhttp2configuration.cpp | 2 +- src/network/ssl/qsslsocket.cpp | 2 +- src/widgets/styles/qstyleoption.cpp | 2 +- 9 files changed, 12 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/corelib/global/qnamespace.qdoc b/src/corelib/global/qnamespace.qdoc index 886aedb4f3..cce88782e9 100644 --- a/src/corelib/global/qnamespace.qdoc +++ b/src/corelib/global/qnamespace.qdoc @@ -3287,7 +3287,7 @@ the application object is created, or by setting the QT_SCALE_FACTOR_ROUNDING_POLICY environment variable. - \sa QGuiApplication::setHighDdpiScaleFactorRoundingPolicy() + \sa QGuiApplication::setHighDpiScaleFactorRoundingPolicy() \sa AA_EnableHighDpiScaling. \omitvalue Unset diff --git a/src/corelib/time/qhijricalendar.cpp b/src/corelib/time/qhijricalendar.cpp index 9aabe46570..a0e6905e91 100644 --- a/src/corelib/time/qhijricalendar.cpp +++ b/src/corelib/time/qhijricalendar.cpp @@ -45,6 +45,7 @@ QT_BEGIN_NAMESPACE /*! \since 5.14 + \internal \class QHijriCalendar \inmodule QtCore diff --git a/src/corelib/time/qislamiccivilcalendar.cpp b/src/corelib/time/qislamiccivilcalendar.cpp index 27c93f5c00..84562849cc 100644 --- a/src/corelib/time/qislamiccivilcalendar.cpp +++ b/src/corelib/time/qislamiccivilcalendar.cpp @@ -48,6 +48,7 @@ using namespace QRoundingDown; /*! \since 5.14 + \internal \class QIslamicCivilCalendar \inmodule QtCore @@ -67,7 +68,7 @@ using namespace QRoundingDown; long. Its determination of leap years follows a 30-year cycle, in each of which the years 2, 5, 7, 10, 13, 16, 18, 21, 24, 26 and 29 are leap years. - \sa QJijriCalendar, QCalendar + \sa QHijriCalendar, QCalendar */ QIslamicCivilCalendar::QIslamicCivilCalendar() diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index fa9d5d5f4d..47bd5727a9 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -3505,7 +3505,7 @@ Qt::ApplicationState QGuiApplication::applicationState() \since 5.14 Sets the high-DPI scale factor rounding policy for the application. The - policy decides how non-integer scale factors (such as Windows 150%) are + \a policy decides how non-integer scale factors (such as Windows 150%) are handled, for applications that have AA_EnableHighDpiScaling enabled. The two principal options are whether fractional scale factors should diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp index c80617f929..3652a180a8 100644 --- a/src/gui/text/qtextdocument.cpp +++ b/src/gui/text/qtextdocument.cpp @@ -2067,8 +2067,9 @@ void QTextDocument::print(QPagedPaintDevice *printer) const \enum QTextDocument::ResourceType This enum describes the types of resources that can be loaded by - QTextDocument's loadResource() function. + QTextDocument's loadResource() function or by QTextBrowser::setSource(). + \value UnknownResource No resource is loaded, or the resource type is not known. \value HtmlResource The resource contains HTML. \value ImageResource The resource contains image data. Currently supported data types are QVariant::Pixmap and @@ -2082,7 +2083,7 @@ void QTextDocument::print(QPagedPaintDevice *printer) const \value UserResource The first available value for user defined resource types. - \sa loadResource() + \sa loadResource(), QTextBrowser::sourceType() */ /*! diff --git a/src/gui/text/qtextformat.cpp b/src/gui/text/qtextformat.cpp index 47a38db3ad..e3bd49a15e 100644 --- a/src/gui/text/qtextformat.cpp +++ b/src/gui/text/qtextformat.cpp @@ -650,6 +650,7 @@ Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QTextFormat &fmt) \value TableColumns \value TableColumnWidthConstraints \value TableHeaderRowCount + \value TableBorderCollapse Specifies the \l QTextTableFormat::borderCollapse property. Table cell properties diff --git a/src/network/access/qhttp2configuration.cpp b/src/network/access/qhttp2configuration.cpp index a32bccfd09..bd4318d4e9 100644 --- a/src/network/access/qhttp2configuration.cpp +++ b/src/network/access/qhttp2configuration.cpp @@ -48,7 +48,7 @@ QT_BEGIN_NAMESPACE /*! \class QHttp2Configuration - \brief The QHttp2Configuration class controls HTTP/2 parameters and settings + \brief The QHttp2Configuration class controls HTTP/2 parameters and settings. \since 5.14 \reentrant diff --git a/src/network/ssl/qsslsocket.cpp b/src/network/ssl/qsslsocket.cpp index ca6c58117d..e302aa1761 100644 --- a/src/network/ssl/qsslsocket.cpp +++ b/src/network/ssl/qsslsocket.cpp @@ -1512,7 +1512,7 @@ bool QSslSocket::addDefaultCaCertificates(const QString &path, QSsl::EncodingFor SSL socket's CA certificate database is initialized to the default CA certificate database. - \sa QSslConfiguration::defaultCaCertificates(), addCaCertificates() + \sa QSslConfiguration::caCertificates(), addCaCertificates() */ void QSslSocket::addDefaultCaCertificate(const QSslCertificate &certificate) { diff --git a/src/widgets/styles/qstyleoption.cpp b/src/widgets/styles/qstyleoption.cpp index 5b3efd598f..01cadd9a86 100644 --- a/src/widgets/styles/qstyleoption.cpp +++ b/src/widgets/styles/qstyleoption.cpp @@ -1760,7 +1760,7 @@ QStyleOptionMenuItem::QStyleOptionMenuItem(int version) \value Exclusive The item is an exclusive check item (like a radio button). \value NonExclusive The item is a non-exclusive check item (like a check box). - \sa checkType, QAction::checkable, QAction::checked, QActionGroup::exclusive + \sa checkType, QAction::checkable, QAction::checked, QActionGroup::exclusionPolicy */ /*! -- cgit v1.2.3 From 0fd6595d5e63fe1db429a0f242c7e98c6d2855f7 Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Tue, 10 Sep 2019 09:39:59 +0200 Subject: Add a missing ConnectionTypeHttp2Direct in several if statements MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Found while preparing SPDY retirement. Change-Id: I30f923fdeb0f6f0b5e808a3e7b7d81ddb9c4ef12 Reviewed-by: Mårten Nordheim Reviewed-by: Edward Welbourne --- src/network/access/qhttpnetworkconnection.cpp | 3 ++- src/network/access/qhttpnetworkconnectionchannel.cpp | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/network/access/qhttpnetworkconnection.cpp b/src/network/access/qhttpnetworkconnection.cpp index 9b1e63520d..294273d751 100644 --- a/src/network/access/qhttpnetworkconnection.cpp +++ b/src/network/access/qhttpnetworkconnection.cpp @@ -1232,7 +1232,8 @@ void QHttpNetworkConnectionPrivate::_q_hostLookupFinished(const QHostInfo &info) emitReplyError(channels[0].socket, channels[0].reply, QNetworkReply::HostNotFoundError); networkLayerState = QHttpNetworkConnectionPrivate::Unknown; } else if (connectionType == QHttpNetworkConnection::ConnectionTypeSPDY - || connectionType == QHttpNetworkConnection::ConnectionTypeHTTP2) { + || connectionType == QHttpNetworkConnection::ConnectionTypeHTTP2 + || connectionType == QHttpNetworkConnection::ConnectionTypeHTTP2Direct) { for (const HttpMessagePair &spdyPair : qAsConst(channels[0].spdyRequestsToSend)) { // emit error for all replies QHttpNetworkReply *currentReply = spdyPair.second; diff --git a/src/network/access/qhttpnetworkconnectionchannel.cpp b/src/network/access/qhttpnetworkconnectionchannel.cpp index d91fd8d2e6..8f94cef32b 100644 --- a/src/network/access/qhttpnetworkconnectionchannel.cpp +++ b/src/network/access/qhttpnetworkconnectionchannel.cpp @@ -1096,6 +1096,7 @@ void QHttpNetworkConnectionChannel::_q_error(QAbstractSocket::SocketError socket || !connection->d_func()->lowPriorityQueue.isEmpty()); if (connection->connectionType() == QHttpNetworkConnection::ConnectionTypeHTTP2 + || connection->connectionType() == QHttpNetworkConnection::ConnectionTypeHTTP2Direct #ifndef QT_NO_SSL || connection->connectionType() == QHttpNetworkConnection::ConnectionTypeSPDY #endif -- cgit v1.2.3 From 78437ef0d2d662663bbc827befc849cad5886b63 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Wed, 11 Sep 2019 09:29:40 +0200 Subject: Add qt.core.filesystemwatcher logging category QFileSystemWatcher has open bugs, so users should be able to help troubleshoot. Change-Id: I6b703e25f294944469d20fd36012b6a55133732a Reviewed-by: Friedemann Kleint --- src/corelib/io/qfilesystemwatcher.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/corelib/io/qfilesystemwatcher.cpp b/src/corelib/io/qfilesystemwatcher.cpp index 64c422c55a..a4705136a2 100644 --- a/src/corelib/io/qfilesystemwatcher.cpp +++ b/src/corelib/io/qfilesystemwatcher.cpp @@ -41,9 +41,9 @@ #include "qfilesystemwatcher_p.h" #include -#include #include #include +#include #include #include @@ -67,6 +67,8 @@ QT_BEGIN_NAMESPACE +Q_LOGGING_CATEGORY(lcWatcher, "qt.core.filesystemwatcher") + QFileSystemWatcherEngine *QFileSystemWatcherPrivate::createNativeEngine(QObject *parent) { #if defined(Q_OS_WIN) @@ -137,6 +139,7 @@ void QFileSystemWatcherPrivate::initPollerEngine() void QFileSystemWatcherPrivate::_q_fileChanged(const QString &path, bool removed) { Q_Q(QFileSystemWatcher); + qCDebug(lcWatcher) << "file changed" << path << "removed?" << removed << "watching?" << files.contains(path); if (!files.contains(path)) { // the path was removed after a change was detected, but before we delivered the signal return; @@ -149,6 +152,7 @@ void QFileSystemWatcherPrivate::_q_fileChanged(const QString &path, bool removed void QFileSystemWatcherPrivate::_q_directoryChanged(const QString &path, bool removed) { Q_Q(QFileSystemWatcher); + qCDebug(lcWatcher) << "directory changed" << path << "removed?" << removed << "watching?" << directories.contains(path); if (!directories.contains(path)) { // perhaps the path was removed after a change was detected, but before we delivered the signal return; @@ -355,7 +359,7 @@ QStringList QFileSystemWatcher::addPaths(const QStringList &paths) qWarning("QFileSystemWatcher::addPaths: list is empty"); return p; } - + qCDebug(lcWatcher) << "adding" << paths; const auto selectEngine = [this, d]() -> QFileSystemWatcherEngine* { #ifdef QT_BUILD_INTERNAL const QString on = objectName(); @@ -364,11 +368,11 @@ QStringList QFileSystemWatcher::addPaths(const QStringList &paths) // Autotest override case - use the explicitly selected engine only const QStringRef forceName = on.midRef(26); if (forceName == QLatin1String("poller")) { - qDebug("QFileSystemWatcher: skipping native engine, using only polling engine"); + qCDebug(lcWatcher, "QFileSystemWatcher: skipping native engine, using only polling engine"); d_func()->initPollerEngine(); return d->poller; } else if (forceName == QLatin1String("native")) { - qDebug("QFileSystemWatcher: skipping polling engine, using only native engine"); + qCDebug(lcWatcher, "QFileSystemWatcher: skipping polling engine, using only native engine"); return d->native; } return nullptr; @@ -431,6 +435,7 @@ QStringList QFileSystemWatcher::removePaths(const QStringList &paths) qWarning("QFileSystemWatcher::removePaths: list is empty"); return p; } + qCDebug(lcWatcher) << "removing" << paths; if (d->native) p = d->native->removePaths(p, &d->files, &d->directories); -- 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') 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') 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 e8bca8e7639942d245cea8a184bc2f4c72694a12 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 9 Sep 2019 12:14:26 +0200 Subject: QtGui: replace some QMutexLockers with (new) qt_{scoped,unique}_lock() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In QImageReader, also replace a QMutex with a QBasicMutex, making the code similar to the corresponding code in QPicture. Change-Id: Ia1cd546eccd3662837762e506235e350b7a08647 Reviewed-by: Mårten Nordheim --- src/gui/image/qimagereader.cpp | 6 +++--- src/gui/image/qpicture.cpp | 3 ++- src/gui/kernel/qguiapplication.cpp | 7 ++++--- src/gui/kernel/qopenglcontext.cpp | 11 ++++++----- src/gui/kernel/qtouchdevice.cpp | 10 +++++----- 5 files changed, 20 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/gui/image/qimagereader.cpp b/src/gui/image/qimagereader.cpp index 6a0763e696..dff24b449a 100644 --- a/src/gui/image/qimagereader.cpp +++ b/src/gui/image/qimagereader.cpp @@ -150,7 +150,7 @@ // factory loader #include #include -#include +#include // for qt_getImageText #include @@ -186,8 +186,8 @@ static QImageIOHandler *createReadHandlerHelper(QIODevice *device, QByteArray suffix; #ifndef QT_NO_IMAGEFORMATPLUGIN - static QMutex mutex; - QMutexLocker locker(&mutex); + static QBasicMutex mutex; + const auto locker = qt_scoped_lock(mutex); typedef QMultiMap PluginKeyMap; diff --git a/src/gui/image/qpicture.cpp b/src/gui/image/qpicture.cpp index 8548f1857e..978a07b9f9 100644 --- a/src/gui/image/qpicture.cpp +++ b/src/gui/image/qpicture.cpp @@ -57,6 +57,7 @@ #include "qregexp.h" #include "qregion.h" #include "qdebug.h" +#include #include @@ -1427,7 +1428,7 @@ void qt_init_picture_plugins() typedef PluginKeyMap::const_iterator PluginKeyMapConstIterator; static QBasicMutex mutex; - QMutexLocker locker(&mutex); + const auto locker = qt_scoped_lock(mutex); static QFactoryLoader loader(QPictureFormatInterface_iid, QStringLiteral("/pictureformats")); diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 47bd5727a9..a3ef3b2314 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -58,6 +58,7 @@ #include #include #include +#include #include #include #include @@ -3305,7 +3306,7 @@ void QGuiApplicationPrivate::applyWindowGeometrySpecificationTo(QWindow *window) QFont QGuiApplication::font() { Q_ASSERT_X(QGuiApplicationPrivate::self, "QGuiApplication::font()", "no QGuiApplication instance"); - QMutexLocker locker(&applicationFontMutex); + const auto locker = qt_scoped_lock(applicationFontMutex); initFontUnlocked(); return *QGuiApplicationPrivate::app_font; } @@ -3317,7 +3318,7 @@ QFont QGuiApplication::font() */ void QGuiApplication::setFont(const QFont &font) { - QMutexLocker locker(&applicationFontMutex); + auto locker = qt_unique_lock(applicationFontMutex); const bool emitChange = !QGuiApplicationPrivate::app_font || (*QGuiApplicationPrivate::app_font != font); if (!QGuiApplicationPrivate::app_font) @@ -4081,7 +4082,7 @@ void QGuiApplicationPrivate::notifyThemeChanged() sendApplicationPaletteChange(); } if (!(applicationResourceFlags & ApplicationFontExplicitlySet)) { - QMutexLocker locker(&applicationFontMutex); + const auto locker = qt_scoped_lock(applicationFontMutex); clearFontUnlocked(); initFontUnlocked(); } diff --git a/src/gui/kernel/qopenglcontext.cpp b/src/gui/kernel/qopenglcontext.cpp index 6f51fe3095..638eb1d12f 100644 --- a/src/gui/kernel/qopenglcontext.cpp +++ b/src/gui/kernel/qopenglcontext.cpp @@ -45,6 +45,7 @@ #include #include +#include #include #include @@ -1442,7 +1443,7 @@ QOpenGLContextGroup *QOpenGLContextGroup::currentContextGroup() void QOpenGLContextGroupPrivate::addContext(QOpenGLContext *ctx) { - QMutexLocker locker(&m_mutex); + const auto locker = qt_scoped_lock(m_mutex); m_refs.ref(); m_shares << ctx; } @@ -1454,7 +1455,7 @@ void QOpenGLContextGroupPrivate::removeContext(QOpenGLContext *ctx) bool deleteObject = false; { - QMutexLocker locker(&m_mutex); + const auto locker = qt_scoped_lock(m_mutex); m_shares.removeOne(ctx); if (ctx == m_context && !m_shares.isEmpty()) @@ -1502,7 +1503,7 @@ void QOpenGLContextGroupPrivate::cleanup() void QOpenGLContextGroupPrivate::deletePendingResources(QOpenGLContext *ctx) { - QMutexLocker locker(&m_mutex); + const auto locker = qt_scoped_lock(m_mutex); const QList pending = m_pendingDeletion; m_pendingDeletion.clear(); @@ -1543,7 +1544,7 @@ void QOpenGLContextGroupPrivate::deletePendingResources(QOpenGLContext *ctx) QOpenGLSharedResource::QOpenGLSharedResource(QOpenGLContextGroup *group) : m_group(group) { - QMutexLocker locker(&m_group->d_func()->m_mutex); + const auto locker = qt_scoped_lock(m_group->d_func()->m_mutex); m_group->d_func()->m_sharedResources << this; } @@ -1559,7 +1560,7 @@ void QOpenGLSharedResource::free() return; } - QMutexLocker locker(&m_group->d_func()->m_mutex); + const auto locker = qt_scoped_lock(m_group->d_func()->m_mutex); m_group->d_func()->m_sharedResources.removeOne(this); m_group->d_func()->m_pendingDeletion << this; diff --git a/src/gui/kernel/qtouchdevice.cpp b/src/gui/kernel/qtouchdevice.cpp index ea187f54aa..8293fddc59 100644 --- a/src/gui/kernel/qtouchdevice.cpp +++ b/src/gui/kernel/qtouchdevice.cpp @@ -228,7 +228,7 @@ TouchDevices::TouchDevices() */ QList QTouchDevice::devices() { - QMutexLocker lock(&devicesMutex); + const auto locker = qt_scoped_lock(devicesMutex); return deviceList->list; } @@ -237,13 +237,13 @@ QList QTouchDevice::devices() */ bool QTouchDevicePrivate::isRegistered(const QTouchDevice *dev) { - QMutexLocker locker(&devicesMutex); + const auto locker = qt_scoped_lock(devicesMutex); return deviceList->list.contains(dev); } const QTouchDevice *QTouchDevicePrivate::deviceById(quint8 id) { - QMutexLocker locker(&devicesMutex); + const auto locker = qt_scoped_lock(devicesMutex); for (const QTouchDevice *dev : qAsConst(deviceList->list)) if (QTouchDevicePrivate::get(const_cast(dev))->id == id) return dev; @@ -255,7 +255,7 @@ const QTouchDevice *QTouchDevicePrivate::deviceById(quint8 id) */ void QTouchDevicePrivate::registerDevice(const QTouchDevice *dev) { - QMutexLocker lock(&devicesMutex); + const auto locker = qt_scoped_lock(devicesMutex); deviceList->list.append(dev); } @@ -264,7 +264,7 @@ void QTouchDevicePrivate::registerDevice(const QTouchDevice *dev) */ void QTouchDevicePrivate::unregisterDevice(const QTouchDevice *dev) { - QMutexLocker lock(&devicesMutex); + const auto locker = qt_scoped_lock(devicesMutex); deviceList->list.removeOne(dev); } -- cgit v1.2.3 From 0f219d20549030d56f1951a9bd72b25f7a64bbe7 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 9 Sep 2019 16:37:11 +0200 Subject: QReadWriteLock: use NSDMI to simplify the Private ctor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I7267dedb152186ad8c74cbf2eddd863c3bc0845f Reviewed-by: Olivier Goffart (Woboq GmbH) Reviewed-by: Mårten Nordheim --- src/corelib/thread/qreadwritelock_p.h | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/corelib/thread/qreadwritelock_p.h b/src/corelib/thread/qreadwritelock_p.h index 31da2401c0..a4d002b7f2 100644 --- a/src/corelib/thread/qreadwritelock_p.h +++ b/src/corelib/thread/qreadwritelock_p.h @@ -63,17 +63,16 @@ QT_BEGIN_NAMESPACE class QReadWriteLockPrivate { public: - QReadWriteLockPrivate(bool isRecursive = false) - : readerCount(0), writerCount(0), waitingReaders(0), waitingWriters(0), - recursive(isRecursive), id(0), currentWriter(nullptr) {} + explicit QReadWriteLockPrivate(bool isRecursive = false) + : recursive(isRecursive) {} QMutex mutex; QWaitCondition writerCond; QWaitCondition readerCond; - int readerCount; - int writerCount; - int waitingReaders; - int waitingWriters; + int readerCount = 0; + int writerCount = 0; + int waitingReaders = 0; + int waitingWriters = 0; const bool recursive; //Called with the mutex locked @@ -82,19 +81,18 @@ public: void unlock(); //memory management - int id; + int id = 0; void release(); static QReadWriteLockPrivate *allocate(); // Recusive mutex handling - Qt::HANDLE currentWriter; + Qt::HANDLE currentWriter = {}; QHash currentReaders; // called with the mutex unlocked bool recursiveLockForWrite(int timeout); bool recursiveLockForRead(int timeout); void recursiveUnlock(); - }; QT_END_NAMESPACE -- cgit v1.2.3 From 08ad96404b4c915eece1a547bf12e91664e7cdff Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 21 Aug 2019 22:14:16 +0200 Subject: QCoreApplication: work towards replacing a QRecursiveMutex with a QMutex At first glance, libraryPathMutex is only recursive because setLibraryPaths(), addLibraryPath() and removeLibraryPath(), all of which lock libraryPathMutex, may call libraryPaths(), which does, too. This is easily fixed by splitting libraryPaths() into public libraryPaths() and private libraryPathsLocked(), the latter expecting to be called with the libraryPathMutex already held. And this is what this patch does. However, on second glance, the building of the initial app_libpaths calls a monstrous amount of code, incl. QLibraryInfo, and some of that code probably re-enters one of the library-path functions. So while this patch is a step towards making libraryPathMutex non-recursive, it's probably not the end. Change-Id: I3ed83272ace6966980cf8e1db877f24c89789da3 Reviewed-by: Ulf Hermann Reviewed-by: Edward Welbourne Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/corelib/kernel/qcoreapplication.cpp | 13 ++++++++++--- src/corelib/kernel/qcoreapplication.h | 3 +++ 2 files changed, 13 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index 6647ea99f5..c537e8f51b 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -2693,7 +2693,14 @@ Q_GLOBAL_STATIC(QRecursiveMutex, libraryPathMutex) QStringList QCoreApplication::libraryPaths() { QMutexLocker locker(libraryPathMutex()); + return libraryPathsLocked(); +} +/*! + \internal +*/ +QStringList QCoreApplication::libraryPathsLocked() +{ if (coreappdata()->manual_libpaths) return *(coreappdata()->manual_libpaths); @@ -2769,7 +2776,7 @@ void QCoreApplication::setLibraryPaths(const QStringList &paths) // When the application is constructed it should still amend the paths. So we keep the originals // around, and even create them if they don't exist, yet. if (!coreappdata()->app_libpaths) - libraryPaths(); + libraryPathsLocked(); if (coreappdata()->manual_libpaths) *(coreappdata()->manual_libpaths) = paths; @@ -2812,7 +2819,7 @@ void QCoreApplication::addLibraryPath(const QString &path) return; } else { // make sure that library paths are initialized - libraryPaths(); + libraryPathsLocked(); QStringList *app_libpaths = coreappdata()->app_libpaths.data(); if (app_libpaths->contains(canonicalPath)) return; @@ -2851,7 +2858,7 @@ void QCoreApplication::removeLibraryPath(const QString &path) return; } else { // make sure that library paths is initialized - libraryPaths(); + libraryPathsLocked(); QStringList *app_libpaths = coreappdata()->app_libpaths.data(); if (!app_libpaths->contains(canonicalPath)) return; diff --git a/src/corelib/kernel/qcoreapplication.h b/src/corelib/kernel/qcoreapplication.h index b7df004736..71ea124fbe 100644 --- a/src/corelib/kernel/qcoreapplication.h +++ b/src/corelib/kernel/qcoreapplication.h @@ -208,6 +208,9 @@ private: static bool notifyInternal2(QObject *receiver, QEvent *); static bool forwardEvent(QObject *receiver, QEvent *event, QEvent *originatingEvent = nullptr); #endif +#if QT_CONFIG(library) + static QStringList libraryPathsLocked(); +#endif static QCoreApplication *self; -- cgit v1.2.3 From 447ee95d5e050c5db1636c5d3bd0edbf59f26108 Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Wed, 11 Sep 2019 09:25:51 +0200 Subject: QHttpThreadDelegate - remove unneeded code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Found while cleaning up SPDY remains: I've noticed that for H2 case I never check if incomingSslConfiguration is nullptr or not, but the code several lines below - does it, which looks kind of moronic. This configuration is initialized when the delegate is created, so no need to have this if-statement. Instead, assert, making this behavior a requirement. Change-Id: I90fb84337be925a3288252aa2491b4c23d6c6cbb Reviewed-by: Mårten Nordheim --- src/network/access/qhttpthreaddelegate.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/network/access/qhttpthreaddelegate.cpp b/src/network/access/qhttpthreaddelegate.cpp index 3d1849010b..46a6615f4d 100644 --- a/src/network/access/qhttpthreaddelegate.cpp +++ b/src/network/access/qhttpthreaddelegate.cpp @@ -297,6 +297,11 @@ void QHttpThreadDelegate::startRequest() connectionType = QHttpNetworkConnection::ConnectionTypeHTTP2Direct; } +#if QT_CONFIG(ssl) + // See qnetworkreplyhttpimpl, delegate's initialization code. + Q_ASSERT(!ssl || incomingSslConfiguration.data()); +#endif // QT_CONFIG(ssl) + const bool isH2 = httpRequest.isHTTP2Allowed() || httpRequest.isHTTP2Direct(); if (isH2) { #if QT_CONFIG(ssl) @@ -316,9 +321,6 @@ void QHttpThreadDelegate::startRequest() } #ifndef QT_NO_SSL - if (ssl && !incomingSslConfiguration.data()) - incomingSslConfiguration.reset(new QSslConfiguration); - if (!isH2 && httpRequest.isSPDYAllowed() && ssl) { connectionType = QHttpNetworkConnection::ConnectionTypeSPDY; urlCopy.setScheme(QStringLiteral("spdy")); // to differentiate SPDY requests from HTTPS requests -- cgit v1.2.3 From f567129bb514b5856c7d1320cdc4dd5a84a5b6e3 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Sat, 7 Sep 2019 19:23:09 +0200 Subject: rhi: d3d11: Add the device lost testing machinery MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The device can be lost when physically removing the graphics adapter, disabling the driver (Device Manager), upgrading/uninstalling the graphics driver, and when it is reset due to an error. Some of these can (and should) be tested manually, but the last one has a convenient, programmatic way of triggering: by triggering the timeout detection and recovery (TDR) of WDDM. A compute shader with an infinite loop should trigger this after 2 seconds by default. All tests in tests/manual/rhi can now be started with a --curse argument where specifies the number of frames to render before breaking the device. Qt Quick will get an environment variable with similar semantics in a separate patch. Change-Id: I4b6f8d977a15b5b89d686b3973965df6435810ae Reviewed-by: Christian Strømme --- src/gui/rhi/cs_tdr.h | 209 ++++++++++++++++++++++++++++++++++++++++++++ src/gui/rhi/qrhid3d11.cpp | 57 +++++++++++- src/gui/rhi/qrhid3d11_p.h | 3 + src/gui/rhi/qrhid3d11_p_p.h | 13 +++ src/gui/rhi/tdr.hlsl | 9 ++ 5 files changed, 290 insertions(+), 1 deletion(-) create mode 100644 src/gui/rhi/cs_tdr.h create mode 100644 src/gui/rhi/tdr.hlsl (limited to 'src') diff --git a/src/gui/rhi/cs_tdr.h b/src/gui/rhi/cs_tdr.h new file mode 100644 index 0000000000..f80cb3a498 --- /dev/null +++ b/src/gui/rhi/cs_tdr.h @@ -0,0 +1,209 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Gui module +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#ifdef Q_OS_WIN + +#include + +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 10.1 +// +// +// Buffer Definitions: +// +// cbuffer ConstantBuffer +// { +// +// uint zero; // Offset: 0 Size: 4 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim HLSL Bind Count +// ------------------------------ ---------- ------- ----------- -------------- ------ +// uav UAV uint buf u0 1 +// ConstantBuffer cbuffer NA NA cb0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// no Input +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// no Output +cs_5_0 +dcl_globalFlags refactoringAllowed +dcl_constantbuffer CB0[1], immediateIndexed +dcl_uav_typed_buffer (uint,uint,uint,uint) u0 +dcl_input vThreadID.x +dcl_thread_group 256, 1, 1 +loop + breakc_nz cb0[0].x + store_uav_typed u0.xyzw, vThreadID.xxxx, cb0[0].xxxx +endloop +ret +// Approximately 5 instruction slots used +#endif + +const BYTE g_killDeviceByTimingOut[] = +{ + 68, 88, 66, 67, 217, 62, + 220, 38, 136, 51, 86, 245, + 161, 96, 18, 35, 141, 17, + 26, 13, 1, 0, 0, 0, + 164, 2, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 100, 1, 0, 0, 116, 1, + 0, 0, 132, 1, 0, 0, + 8, 2, 0, 0, 82, 68, + 69, 70, 40, 1, 0, 0, + 1, 0, 0, 0, 144, 0, + 0, 0, 2, 0, 0, 0, + 60, 0, 0, 0, 0, 5, + 83, 67, 0, 1, 0, 0, + 0, 1, 0, 0, 82, 68, + 49, 49, 60, 0, 0, 0, + 24, 0, 0, 0, 32, 0, + 0, 0, 40, 0, 0, 0, + 36, 0, 0, 0, 12, 0, + 0, 0, 0, 0, 0, 0, + 124, 0, 0, 0, 4, 0, + 0, 0, 4, 0, 0, 0, + 1, 0, 0, 0, 255, 255, + 255, 255, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 128, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 117, 97, + 118, 0, 67, 111, 110, 115, + 116, 97, 110, 116, 66, 117, + 102, 102, 101, 114, 0, 171, + 128, 0, 0, 0, 1, 0, + 0, 0, 168, 0, 0, 0, + 16, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 208, 0, 0, 0, 0, 0, + 0, 0, 4, 0, 0, 0, + 2, 0, 0, 0, 220, 0, + 0, 0, 0, 0, 0, 0, + 255, 255, 255, 255, 0, 0, + 0, 0, 255, 255, 255, 255, + 0, 0, 0, 0, 122, 101, + 114, 111, 0, 100, 119, 111, + 114, 100, 0, 171, 0, 0, + 19, 0, 1, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 213, 0, 0, 0, 77, 105, + 99, 114, 111, 115, 111, 102, + 116, 32, 40, 82, 41, 32, + 72, 76, 83, 76, 32, 83, + 104, 97, 100, 101, 114, 32, + 67, 111, 109, 112, 105, 108, + 101, 114, 32, 49, 48, 46, + 49, 0, 73, 83, 71, 78, + 8, 0, 0, 0, 0, 0, + 0, 0, 8, 0, 0, 0, + 79, 83, 71, 78, 8, 0, + 0, 0, 0, 0, 0, 0, + 8, 0, 0, 0, 83, 72, + 69, 88, 124, 0, 0, 0, + 80, 0, 5, 0, 31, 0, + 0, 0, 106, 8, 0, 1, + 89, 0, 0, 4, 70, 142, + 32, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 156, 8, + 0, 4, 0, 224, 17, 0, + 0, 0, 0, 0, 68, 68, + 0, 0, 95, 0, 0, 2, + 18, 0, 2, 0, 155, 0, + 0, 4, 0, 1, 0, 0, + 1, 0, 0, 0, 1, 0, + 0, 0, 48, 0, 0, 1, + 3, 0, 4, 4, 10, 128, + 32, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 164, 0, + 0, 7, 242, 224, 17, 0, + 0, 0, 0, 0, 6, 0, + 2, 0, 6, 128, 32, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 22, 0, 0, 1, + 62, 0, 0, 1, 83, 84, + 65, 84, 148, 0, 0, 0, + 5, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0 +}; + +#endif // Q_OS_WIN diff --git a/src/gui/rhi/qrhid3d11.cpp b/src/gui/rhi/qrhid3d11.cpp index 93eadc047d..f12e376b58 100644 --- a/src/gui/rhi/qrhid3d11.cpp +++ b/src/gui/rhi/qrhid3d11.cpp @@ -36,6 +36,7 @@ #include "qrhid3d11_p_p.h" #include "qshader_p.h" +#include "cs_tdr.h" #include #include #include @@ -119,9 +120,14 @@ QT_BEGIN_NAMESPACE */ QRhiD3D11::QRhiD3D11(QRhiD3D11InitParams *params, QRhiD3D11NativeHandles *importDevice) - : ofr(this) + : ofr(this), + deviceCurse(this) { debugLayer = params->enableDebugLayer; + + deviceCurse.framesToActivate = params->framesUntilKillingDeviceViaTdr; + deviceCurse.permanent = params->repeatDeviceKill; + importedDevice = importDevice != nullptr; if (importedDevice) { dev = reinterpret_cast(importDevice->dev); @@ -264,6 +270,9 @@ bool QRhiD3D11::create(QRhi::Flags flags) nativeHandlesStruct.dev = dev; nativeHandlesStruct.context = context; + if (deviceCurse.framesToActivate > 0) + deviceCurse.initResources(); + return true; } @@ -281,6 +290,8 @@ void QRhiD3D11::destroy() clearShaderCache(); + deviceCurse.releaseResources(); + if (annotations) { annotations->Release(); annotations = nullptr; @@ -1003,6 +1014,20 @@ QRhi::FrameOpResult QRhiD3D11::endFrame(QRhiSwapChain *swapChain, QRhi::EndFrame swapChainD->frameCount += 1; contextState.currentSwapChain = nullptr; + + if (deviceCurse.framesToActivate > 0) { + deviceCurse.framesLeft -= 1; + if (deviceCurse.framesLeft == 0) { + deviceCurse.framesLeft = deviceCurse.framesToActivate; + if (!deviceCurse.permanent) + deviceCurse.framesToActivate = -1; + + deviceCurse.activate(); + } else if (deviceCurse.framesLeft % 100 == 0) { + qDebug("Impending doom: %d frames left", deviceCurse.framesLeft); + } + } + return QRhi::FrameOpSuccess; } @@ -3914,4 +3939,34 @@ bool QD3D11SwapChain::buildOrResize() return true; } +void QRhiD3D11::DeviceCurse::initResources() +{ + framesLeft = framesToActivate; + + HRESULT hr = q->dev->CreateComputeShader(g_killDeviceByTimingOut, sizeof(g_killDeviceByTimingOut), nullptr, &cs); + if (FAILED(hr)) { + qWarning("Failed to create compute shader: %s", qPrintable(comErrorMessage(hr))); + return; + } +} + +void QRhiD3D11::DeviceCurse::releaseResources() +{ + if (cs) { + cs->Release(); + cs = nullptr; + } +} + +void QRhiD3D11::DeviceCurse::activate() +{ + if (!cs) + return; + + qDebug("Activating Curse. Goodbye Cruel World."); + + q->context->CSSetShader(cs, nullptr, 0); + q->context->Dispatch(256, 1, 1); +} + QT_END_NAMESPACE diff --git a/src/gui/rhi/qrhid3d11_p.h b/src/gui/rhi/qrhid3d11_p.h index 3e2e492d9c..5df1843b1e 100644 --- a/src/gui/rhi/qrhid3d11_p.h +++ b/src/gui/rhi/qrhid3d11_p.h @@ -58,6 +58,9 @@ QT_BEGIN_NAMESPACE struct Q_GUI_EXPORT QRhiD3D11InitParams : public QRhiInitParams { bool enableDebugLayer = false; + + int framesUntilKillingDeviceViaTdr = -1; + bool repeatDeviceKill = false; }; struct Q_GUI_EXPORT QRhiD3D11NativeHandles : public QRhiNativeHandles diff --git a/src/gui/rhi/qrhid3d11_p_p.h b/src/gui/rhi/qrhid3d11_p_p.h index cd44519aaa..cc4e095d10 100644 --- a/src/gui/rhi/qrhid3d11_p_p.h +++ b/src/gui/rhi/qrhid3d11_p_p.h @@ -694,6 +694,19 @@ public: QByteArray bytecode; }; QHash m_shaderCache; + + struct DeviceCurse { + DeviceCurse(QRhiD3D11 *impl) : q(impl) { } + QRhiD3D11 *q; + int framesToActivate = -1; + bool permanent = false; + int framesLeft = 0; + ID3D11ComputeShader *cs = nullptr; + + void initResources(); + void releaseResources(); + void activate(); + } deviceCurse; }; Q_DECLARE_TYPEINFO(QRhiD3D11::ActiveReadback, Q_MOVABLE_TYPE); diff --git a/src/gui/rhi/tdr.hlsl b/src/gui/rhi/tdr.hlsl new file mode 100644 index 0000000000..f79de91c4a --- /dev/null +++ b/src/gui/rhi/tdr.hlsl @@ -0,0 +1,9 @@ +RWBuffer uav; +cbuffer ConstantBuffer { uint zero; } + +[numthreads(256, 1, 1)] +void killDeviceByTimingOut(uint3 id: SV_DispatchThreadID) +{ + while (zero == 0) + uav[id.x] = zero; +} -- cgit v1.2.3 From d1486e2982df9373a7e5816609eff066cac6eb52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 4 Sep 2019 12:50:37 +0200 Subject: Simplify QColorSpacePrivate initialization QColorVector and QColorMatrix are default-constructed following the Qt philosophy of types always being well-defined. The corner-case where we need uninitialized versions of these types for performance reasons is handled explicitly. Change-Id: I629334d1ffc63563ec9fd1298c623946e0799d1d Reviewed-by: Paul Olav Tvete Reviewed-by: Simon Hausmann --- src/gui/painting/qcolormatrix_p.h | 16 +++++----------- src/gui/painting/qcolorspace.cpp | 8 +------- src/gui/painting/qcolorspace_p.h | 6 +++--- src/gui/painting/qcolortransform.cpp | 12 +++++++++++- 4 files changed, 20 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/gui/painting/qcolormatrix_p.h b/src/gui/painting/qcolormatrix_p.h index 70d2137119..edb2d32258 100644 --- a/src/gui/painting/qcolormatrix_p.h +++ b/src/gui/painting/qcolormatrix_p.h @@ -62,17 +62,16 @@ class QColorVector { public: QColorVector() = default; - Q_DECL_CONSTEXPR QColorVector(float x, float y, float z) : x(x), y(y), z(z), _unused(0.0f) { } + Q_DECL_CONSTEXPR QColorVector(float x, float y, float z) : x(x), y(y), z(z) { } explicit Q_DECL_CONSTEXPR QColorVector(const QPointF &chr) // from XY chromaticity : x(chr.x() / chr.y()) , y(1.0f) , z((1.0 - chr.x() - chr.y()) / chr.y()) - , _unused(0.0f) { } - float x; // X, x or red - float y; // Y, y or green - float z; // Z, Y or blue - float _unused; + float x = 0.0f; // X, x or red + float y = 0.0f; // Y, y or green + float z = 0.0f; // Z, Y or blue + float _unused = 0.0f; friend inline bool operator==(const QColorVector &v1, const QColorVector &v2); friend inline bool operator!=(const QColorVector &v1, const QColorVector &v2); @@ -81,7 +80,6 @@ public: return !x && !y && !z; } - static Q_DECL_CONSTEXPR QColorVector null() { return QColorVector(0.0f, 0.0f, 0.0f); } static bool isValidChromaticity(const QPointF &chr) { if (chr.x() < qreal(0.0) || chr.x() > qreal(1.0)) @@ -187,10 +185,6 @@ public: { r.z, g.z, b.z } }; } - static QColorMatrix null() - { - return { QColorVector::null(), QColorVector::null(), QColorVector::null() }; - } static QColorMatrix identity() { return { { 1.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, { 0.0f, 0.0f, 1.0f } }; diff --git a/src/gui/painting/qcolorspace.cpp b/src/gui/painting/qcolorspace.cpp index 720c531e3f..937bb505c9 100644 --- a/src/gui/painting/qcolorspace.cpp +++ b/src/gui/painting/qcolorspace.cpp @@ -146,17 +146,11 @@ QColorMatrix QColorSpacePrimaries::toXyzMatrix() const } QColorSpacePrivate::QColorSpacePrivate() - : primaries(QColorSpace::Primaries::Custom) - , transferFunction(QColorSpace::TransferFunction::Custom) - , gamma(0.0f) - , whitePoint(QColorVector::null()) - , toXyz(QColorMatrix::null()) { } QColorSpacePrivate::QColorSpacePrivate(QColorSpace::NamedColorSpace namedColorSpace) : namedColorSpace(namedColorSpace) - , gamma(0.0f) { switch (namedColorSpace) { case QColorSpace::SRgb: @@ -282,7 +276,7 @@ void QColorSpacePrivate::initialize() void QColorSpacePrivate::setToXyzMatrix() { if (primaries == QColorSpace::Primaries::Custom) { - toXyz = QColorMatrix::null(); + toXyz = QColorMatrix(); whitePoint = QColorVector::D50(); return; } diff --git a/src/gui/painting/qcolorspace_p.h b/src/gui/painting/qcolorspace_p.h index c06681df6b..e7add19ed3 100644 --- a/src/gui/painting/qcolorspace_p.h +++ b/src/gui/painting/qcolorspace_p.h @@ -124,9 +124,9 @@ public: static constexpr QColorSpace::NamedColorSpace Unknown = QColorSpace::NamedColorSpace(0); QColorSpace::NamedColorSpace namedColorSpace = Unknown; - QColorSpace::Primaries primaries; - QColorSpace::TransferFunction transferFunction; - float gamma; + QColorSpace::Primaries primaries = QColorSpace::Primaries::Custom; + QColorSpace::TransferFunction transferFunction = QColorSpace::TransferFunction::Custom; + float gamma = 0.0f; QColorVector whitePoint; QColorTrc trc[3]; diff --git a/src/gui/painting/qcolortransform.cpp b/src/gui/painting/qcolortransform.cpp index 53fd1dfbaa..10ccefed74 100644 --- a/src/gui/painting/qcolortransform.cpp +++ b/src/gui/painting/qcolortransform.cpp @@ -612,6 +612,15 @@ static void storeOpaque(QRgba64 *dst, const QRgba64 *src, const QColorVector *bu static constexpr qsizetype WorkBlockSize = 256; +template +class QUninitialized +{ +public: + operator T*() { return reinterpret_cast(this); } +private: + alignas(T) char data[sizeof(T) * Count]; +}; + template void QColorTransformPrivate::apply(T *dst, const T *src, qsizetype count, TransformFlags flags) const { @@ -623,7 +632,8 @@ void QColorTransformPrivate::apply(T *dst, const T *src, qsizetype count, Transf bool doApplyMatrix = (colorMatrix != QColorMatrix::identity()); - QColorVector buffer[WorkBlockSize]; + QUninitialized buffer; + qsizetype i = 0; while (i < count) { const qsizetype len = qMin(count - i, WorkBlockSize); -- cgit v1.2.3 From 1c63605c102c52efbc3b620bb3221e167da39570 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Mon, 9 Sep 2019 17:00:27 +0200 Subject: rhi: Make the clang code model happy as much as we can MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When interfacing with reality (i.e. native platform APIs provided in C, ObjC, or COM), each of the APIs has its own idea of what types it likes to use for sizes, points, rects, etc. Out of the hundreds of warnings Qt Creator throws at us with the default clang check level when opening one of the rhi backends not a single one is useful. Regardless, let's try getting rid of what we can. This mostly involves throwing in int/uint conversions in order to get the signedness change warnings to shut up. The things that are either unacceptable to change or are beyond our control are left untouched. Change-Id: I6e4cb7cd373bf48dc990eaf83344242bbf30bd66 Reviewed-by: Christian Strømme --- src/gui/rhi/qrhi.cpp | 25 ++-- src/gui/rhi/qrhid3d11.cpp | 269 +++++++++++++++++++------------------- src/gui/rhi/qrhigles2.cpp | 121 ++++++++--------- src/gui/rhi/qrhimetal.mm | 214 ++++++++++++++++--------------- src/gui/rhi/qrhiprofiler.cpp | 14 +- src/gui/rhi/qrhiprofiler_p_p.h | 6 +- src/gui/rhi/qrhivulkan.cpp | 285 +++++++++++++++++++++-------------------- 7 files changed, 470 insertions(+), 464 deletions(-) (limited to 'src') diff --git a/src/gui/rhi/qrhi.cpp b/src/gui/rhi/qrhi.cpp index 88d2f73541..65cfaf5123 100644 --- a/src/gui/rhi/qrhi.cpp +++ b/src/gui/rhi/qrhi.cpp @@ -673,7 +673,7 @@ bool operator!=(const QRhiDepthStencilClearValue &a, const QRhiDepthStencilClear */ uint qHash(const QRhiDepthStencilClearValue &v, uint seed) Q_DECL_NOTHROW { - return seed * (qFloor(v.depthClearValue() * 100) + v.stencilClearValue()); + return seed * (uint(qFloor(qreal(v.depthClearValue()) * 100)) + v.stencilClearValue()); } #ifndef QT_NO_DEBUG_STREAM @@ -768,7 +768,8 @@ bool operator!=(const QRhiViewport &a, const QRhiViewport &b) Q_DECL_NOTHROW uint qHash(const QRhiViewport &v, uint seed) Q_DECL_NOTHROW { const std::array r = v.viewport(); - return seed + r[0] + r[1] + r[2] + r[3] + qFloor(v.minDepth() * 100) + qFloor(v.maxDepth() * 100); + return seed + uint(r[0]) + uint(r[1]) + uint(r[2]) + uint(r[3]) + + uint(qFloor(qreal(v.minDepth()) * 100)) + uint(qFloor(qreal(v.maxDepth()) * 100)); } #ifndef QT_NO_DEBUG_STREAM @@ -850,7 +851,7 @@ bool operator!=(const QRhiScissor &a, const QRhiScissor &b) Q_DECL_NOTHROW uint qHash(const QRhiScissor &v, uint seed) Q_DECL_NOTHROW { const std::array r = v.scissor(); - return seed + r[0] + r[1] + r[2] + r[3]; + return seed + uint(r[0]) + uint(r[1]) + uint(r[2]) + uint(r[3]); } #ifndef QT_NO_DEBUG_STREAM @@ -1136,7 +1137,7 @@ bool operator!=(const QRhiVertexInputAttribute &a, const QRhiVertexInputAttribut */ uint qHash(const QRhiVertexInputAttribute &v, uint seed) Q_DECL_NOTHROW { - return seed + v.binding() + v.location() + v.format() + v.offset(); + return seed + uint(v.binding()) + uint(v.location()) + uint(v.format()) + v.offset(); } #ifndef QT_NO_DEBUG_STREAM @@ -3001,7 +3002,7 @@ bool operator!=(const QRhiShaderResourceBinding &a, const QRhiShaderResourceBind uint qHash(const QRhiShaderResourceBinding &b, uint seed) Q_DECL_NOTHROW { const char *u = reinterpret_cast(&b.d->u); - return seed + b.d->binding + 10 * b.d->stage + 100 * b.d->type + return seed + uint(b.d->binding) + 10 * uint(b.d->stage) + 100 * uint(b.d->type) + qHash(QByteArray::fromRawData(u, sizeof(b.d->u)), seed); } @@ -3823,8 +3824,8 @@ void QRhiImplementation::compressedFormatInfo(QRhiTexture::Format format, const break; } - const quint32 wblocks = (size.width() + xdim - 1) / xdim; - const quint32 hblocks = (size.height() + ydim - 1) / ydim; + const quint32 wblocks = uint((size.width() + xdim - 1) / xdim); + const quint32 hblocks = uint((size.height() + ydim - 1) / ydim); if (bpl) *bpl = wblocks * blockSize; @@ -3880,9 +3881,9 @@ void QRhiImplementation::textureFormatInfo(QRhiTexture::Format format, const QSi } if (bpl) - *bpl = size.width() * bpc; + *bpl = uint(size.width()) * bpc; if (byteSize) - *byteSize = size.width() * size.height() * bpc; + *byteSize = uint(size.width() * size.height()) * bpc; } // Approximate because it excludes subresource alignment or multisampling. @@ -3892,12 +3893,12 @@ quint32 QRhiImplementation::approxByteSizeForTexture(QRhiTexture::Format format, quint32 approxSize = 0; for (int level = 0; level < mipCount; ++level) { quint32 byteSize = 0; - const QSize size(qFloor(float(qMax(1, baseSize.width() >> level))), - qFloor(float(qMax(1, baseSize.height() >> level)))); + const QSize size(qFloor(qreal(qMax(1, baseSize.width() >> level))), + qFloor(qreal(qMax(1, baseSize.height() >> level)))); textureFormatInfo(format, size, nullptr, &byteSize); approxSize += byteSize; } - approxSize *= layerCount; + approxSize *= uint(layerCount); return approxSize; } diff --git a/src/gui/rhi/qrhid3d11.cpp b/src/gui/rhi/qrhid3d11.cpp index f12e376b58..2828256a90 100644 --- a/src/gui/rhi/qrhid3d11.cpp +++ b/src/gui/rhi/qrhid3d11.cpp @@ -161,7 +161,7 @@ static QString comErrorMessage(HRESULT hr) } template -static inline Int aligned(Int v, Int byteAlign) +inline Int aligned(Int v, Int byteAlign) { return (v + byteAlign - 1) & ~(byteAlign - 1); } @@ -172,7 +172,7 @@ static IDXGIFactory1 *createDXGIFactory2() if (QOperatingSystemVersion::current() > QOperatingSystemVersion::Windows7) { using PtrCreateDXGIFactory2 = HRESULT (WINAPI *)(UINT, REFIID, void **); QSystemLibrary dxgilib(QStringLiteral("dxgi")); - if (auto createDXGIFactory2 = (PtrCreateDXGIFactory2)dxgilib.resolve("CreateDXGIFactory2")) { + if (auto createDXGIFactory2 = reinterpret_cast(dxgilib.resolve("CreateDXGIFactory2"))) { const HRESULT hr = createDXGIFactory2(0, IID_IDXGIFactory2, reinterpret_cast(&result)); if (FAILED(hr)) { qWarning("CreateDXGIFactory2() failed to create DXGI factory: %s", qPrintable(comErrorMessage(hr))); @@ -227,10 +227,10 @@ bool QRhiD3D11::create(QRhi::Flags flags) int requestedAdapterIndex = -1; if (qEnvironmentVariableIsSet("QT_D3D_ADAPTER_INDEX")) requestedAdapterIndex = qEnvironmentVariableIntValue("QT_D3D_ADAPTER_INDEX"); - for (int adapterIndex = 0; dxgiFactory->EnumAdapters1(adapterIndex, &adapter) != DXGI_ERROR_NOT_FOUND; ++adapterIndex) { + for (int adapterIndex = 0; dxgiFactory->EnumAdapters1(UINT(adapterIndex), &adapter) != DXGI_ERROR_NOT_FOUND; ++adapterIndex) { DXGI_ADAPTER_DESC1 desc; adapter->GetDesc1(&desc); - const QString name = QString::fromUtf16((char16_t *) desc.Description); + const QString name = QString::fromUtf16(reinterpret_cast(desc.Description)); qCDebug(QRHI_LOG_INFO, "Adapter %d: '%s' (flags 0x%x)", adapterIndex, qPrintable(name), desc.Flags); if (!adapterToUse && (requestedAdapterIndex < 0 || requestedAdapterIndex == adapterIndex)) { adapterToUse = adapter; @@ -343,9 +343,9 @@ DXGI_SAMPLE_DESC QRhiD3D11::effectiveSampleCount(int sampleCount) const return desc; } - desc.Count = s; + desc.Count = UINT(s); if (s > 1) - desc.Quality = D3D11_STANDARD_MULTISAMPLE_PATTERN; + desc.Quality = UINT(D3D11_STANDARD_MULTISAMPLE_PATTERN); else desc.Quality = 0; @@ -666,7 +666,7 @@ void QRhiD3D11::setShaderResources(QRhiCommandBuffer *cb, QRhiShaderResourceBind uint *p = cmd.args.bindShaderResources.dynamicOffsetPairs; for (int i = 0; i < dynamicOffsetCount; ++i) { const QRhiCommandBuffer::DynamicOffset &dynOfs(dynamicOffsets[i]); - const uint binding = dynOfs.first; + const uint binding = uint(dynOfs.first); Q_ASSERT(aligned(dynOfs.second, quint32(256)) == dynOfs.second); const uint offsetInConstants = dynOfs.second / 16; *p++ = binding; @@ -802,10 +802,10 @@ void QRhiD3D11::setBlendConstants(QRhiCommandBuffer *cb, const QColor &c) QD3D11CommandBuffer::Command cmd; cmd.cmd = QD3D11CommandBuffer::Command::BlendConstants; cmd.args.blendConstants.ps = QRHI_RES(QD3D11GraphicsPipeline, cbD->currentGraphicsPipeline); - cmd.args.blendConstants.c[0] = c.redF(); - cmd.args.blendConstants.c[1] = c.greenF(); - cmd.args.blendConstants.c[2] = c.blueF(); - cmd.args.blendConstants.c[3] = c.alphaF(); + cmd.args.blendConstants.c[0] = float(c.redF()); + cmd.args.blendConstants.c[1] = float(c.greenF()); + cmd.args.blendConstants.c[2] = float(c.blueF()); + cmd.args.blendConstants.c[3] = float(c.alphaF()); cbD->commands.append(cmd); } @@ -1201,7 +1201,7 @@ QRhi::FrameOpResult QRhiD3D11::finish() void QRhiD3D11::enqueueSubresUpload(QD3D11Texture *texD, QD3D11CommandBuffer *cbD, int layer, int level, const QRhiTextureSubresourceUploadDescription &subresDesc) { - UINT subres = D3D11CalcSubresource(level, layer, texD->mipLevelCount); + UINT subres = D3D11CalcSubresource(UINT(level), UINT(layer), texD->mipLevelCount); const QPoint dp = subresDesc.destinationTopLeft(); D3D11_BOX box; box.front = 0; @@ -1232,13 +1232,13 @@ void QRhiD3D11::enqueueSubresUpload(QD3D11Texture *texD, QD3D11CommandBuffer *cb } else { cmd.args.updateSubRes.src = cbD->retainImage(img); } - box.left = dp.x(); - box.top = dp.y(); - box.right = dp.x() + size.width(); - box.bottom = dp.y() + size.height(); + box.left = UINT(dp.x()); + box.top = UINT(dp.y()); + box.right = UINT(dp.x() + size.width()); + box.bottom = UINT(dp.y() + size.height()); cmd.args.updateSubRes.hasDstBox = true; cmd.args.updateSubRes.dstBox = box; - cmd.args.updateSubRes.srcRowPitch = bpl; + cmd.args.updateSubRes.srcRowPitch = UINT(bpl); } else if (!subresDesc.data().isEmpty() && isCompressedFormat(texD->m_format)) { const QSize size = subresDesc.sourceSize().isEmpty() ? q->sizeForMipLevel(level, texD->m_pixelSize) : subresDesc.sourceSize(); @@ -1248,10 +1248,10 @@ void QRhiD3D11::enqueueSubresUpload(QD3D11Texture *texD, QD3D11CommandBuffer *cb // Everything must be a multiple of the block width and // height, so e.g. a mip level of size 2x2 will be 4x4 when it // comes to the actual data. - box.left = aligned(dp.x(), blockDim.width()); - box.top = aligned(dp.y(), blockDim.height()); - box.right = aligned(dp.x() + size.width(), blockDim.width()); - box.bottom = aligned(dp.y() + size.height(), blockDim.height()); + box.left = UINT(aligned(dp.x(), blockDim.width())); + box.top = UINT(aligned(dp.y(), blockDim.height())); + box.right = UINT(aligned(dp.x() + size.width(), blockDim.width())); + box.bottom = UINT(aligned(dp.y() + size.height(), blockDim.height())); cmd.args.updateSubRes.hasDstBox = true; cmd.args.updateSubRes.dstBox = box; cmd.args.updateSubRes.src = cbD->retainData(subresDesc.data()); @@ -1261,10 +1261,10 @@ void QRhiD3D11::enqueueSubresUpload(QD3D11Texture *texD, QD3D11CommandBuffer *cb : subresDesc.sourceSize(); quint32 bpl = 0; textureFormatInfo(texD->m_format, size, &bpl, nullptr); - box.left = dp.x(); - box.top = dp.y(); - box.right = dp.x() + size.width(); - box.bottom = dp.y() + size.height(); + box.left = UINT(dp.x()); + box.top = UINT(dp.y()); + box.right = UINT(dp.x() + size.width()); + box.bottom = UINT(dp.y() + size.height()); cmd.args.updateSubRes.hasDstBox = true; cmd.args.updateSubRes.dstBox = box; cmd.args.updateSubRes.src = cbD->retainData(subresDesc.data()); @@ -1286,7 +1286,7 @@ void QRhiD3D11::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate for (const QRhiResourceUpdateBatchPrivate::DynamicBufferUpdate &u : ud->dynamicBufferUpdates) { QD3D11Buffer *bufD = QRHI_RES(QD3D11Buffer, u.buf); Q_ASSERT(bufD->m_type == QRhiBuffer::Dynamic); - memcpy(bufD->dynBuf.data() + u.offset, u.data.constData(), u.data.size()); + memcpy(bufD->dynBuf.data() + u.offset, u.data.constData(), size_t(u.data.size())); bufD->hasPendingDynamicUpdates = true; } @@ -1304,10 +1304,10 @@ void QRhiD3D11::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate // since the ID3D11Buffer's size is rounded up to be a multiple of 256 // while the data we have has the original size. D3D11_BOX box; - box.left = u.offset; + box.left = UINT(u.offset); box.top = box.front = 0; box.back = box.bottom = 1; - box.right = u.offset + u.data.size(); // no -1: right, bottom, back are exclusive, see D3D11_BOX doc + box.right = UINT(u.offset + u.data.size()); // no -1: right, bottom, back are exclusive, see D3D11_BOX doc cmd.args.updateSubRes.hasDstBox = true; cmd.args.updateSubRes.dstBox = box; cbD->commands.append(cmd); @@ -1326,25 +1326,25 @@ void QRhiD3D11::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate Q_ASSERT(u.copy.src && u.copy.dst); QD3D11Texture *srcD = QRHI_RES(QD3D11Texture, u.copy.src); QD3D11Texture *dstD = QRHI_RES(QD3D11Texture, u.copy.dst); - UINT srcSubRes = D3D11CalcSubresource(u.copy.desc.sourceLevel(), u.copy.desc.sourceLayer(), srcD->mipLevelCount); - UINT dstSubRes = D3D11CalcSubresource(u.copy.desc.destinationLevel(), u.copy.desc.destinationLayer(), dstD->mipLevelCount); + UINT srcSubRes = D3D11CalcSubresource(UINT(u.copy.desc.sourceLevel()), UINT(u.copy.desc.sourceLayer()), srcD->mipLevelCount); + UINT dstSubRes = D3D11CalcSubresource(UINT(u.copy.desc.destinationLevel()), UINT(u.copy.desc.destinationLayer()), dstD->mipLevelCount); const QPoint dp = u.copy.desc.destinationTopLeft(); const QSize size = u.copy.desc.pixelSize().isEmpty() ? srcD->m_pixelSize : u.copy.desc.pixelSize(); const QPoint sp = u.copy.desc.sourceTopLeft(); D3D11_BOX srcBox; - srcBox.left = sp.x(); - srcBox.top = sp.y(); + srcBox.left = UINT(sp.x()); + srcBox.top = UINT(sp.y()); srcBox.front = 0; // back, right, bottom are exclusive - srcBox.right = srcBox.left + size.width(); - srcBox.bottom = srcBox.top + size.height(); + srcBox.right = srcBox.left + UINT(size.width()); + srcBox.bottom = srcBox.top + UINT(size.height()); srcBox.back = 1; QD3D11CommandBuffer::Command cmd; cmd.cmd = QD3D11CommandBuffer::Command::CopySubRes; cmd.args.copySubRes.dst = dstD->tex; cmd.args.copySubRes.dstSubRes = dstSubRes; - cmd.args.copySubRes.dstX = dp.x(); - cmd.args.copySubRes.dstY = dp.y(); + cmd.args.copySubRes.dstX = UINT(dp.x()); + cmd.args.copySubRes.dstY = UINT(dp.y()); cmd.args.copySubRes.src = srcD->tex; cmd.args.copySubRes.srcSubRes = srcSubRes; cmd.args.copySubRes.hasSrcBox = true; @@ -1372,7 +1372,7 @@ void QRhiD3D11::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate dxgiFormat = texD->dxgiFormat; pixelSize = u.read.rb.level() > 0 ? q->sizeForMipLevel(u.read.rb.level(), texD->m_pixelSize) : texD->m_pixelSize; format = texD->m_format; - subres = D3D11CalcSubresource(u.read.rb.level(), u.read.rb.layer(), texD->mipLevelCount); + subres = D3D11CalcSubresource(UINT(u.read.rb.level()), UINT(u.read.rb.layer()), texD->mipLevelCount); } else { Q_ASSERT(contextState.currentSwapChain); swapChainD = QRHI_RES(QD3D11SwapChain, contextState.currentSwapChain); @@ -1401,8 +1401,8 @@ void QRhiD3D11::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate D3D11_TEXTURE2D_DESC desc; memset(&desc, 0, sizeof(desc)); - desc.Width = pixelSize.width(); - desc.Height = pixelSize.height(); + desc.Width = UINT(pixelSize.width()); + desc.Height = UINT(pixelSize.height()); desc.MipLevels = 1; desc.ArraySize = 1; desc.Format = dxgiFormat; @@ -1415,7 +1415,7 @@ void QRhiD3D11::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate qWarning("Failed to create readback staging texture: %s", qPrintable(comErrorMessage(hr))); return; } - QRHI_PROF_F(newReadbackBuffer(quint64(quintptr(stagingTex)), + QRHI_PROF_F(newReadbackBuffer(qint64(qintptr(stagingTex)), texD ? static_cast(texD) : static_cast(swapChainD), bufSize)); @@ -1458,7 +1458,7 @@ void QRhiD3D11::finishActiveReadbacks() const QRhiD3D11::ActiveReadback &aRb(activeReadbacks[i]); aRb.result->format = aRb.format; aRb.result->pixelSize = aRb.pixelSize; - aRb.result->data.resize(aRb.bufSize); + aRb.result->data.resize(int(aRb.bufSize)); D3D11_MAPPED_SUBRESOURCE mp; HRESULT hr = context->Map(aRb.stagingTex, 0, D3D11_MAP_READ, 0, &mp); @@ -1479,7 +1479,7 @@ void QRhiD3D11::finishActiveReadbacks() context->Unmap(aRb.stagingTex, 0); aRb.stagingTex->Release(); - QRHI_PROF_F(releaseReadbackBuffer(quint64(quintptr(aRb.stagingTex)))); + QRHI_PROF_F(releaseReadbackBuffer(qint64(qintptr(aRb.stagingTex)))); if (aRb.result->completed) completedCallbacks.append(aRb.result->completed); @@ -1548,10 +1548,10 @@ void QRhiD3D11::beginPass(QRhiCommandBuffer *cb, if (rtD->dsAttCount && wantsDsClear) clearCmd.args.clear.mask |= QD3D11CommandBuffer::Command::Depth | QD3D11CommandBuffer::Command::Stencil; - clearCmd.args.clear.c[0] = colorClearValue.redF(); - clearCmd.args.clear.c[1] = colorClearValue.greenF(); - clearCmd.args.clear.c[2] = colorClearValue.blueF(); - clearCmd.args.clear.c[3] = colorClearValue.alphaF(); + clearCmd.args.clear.c[0] = float(colorClearValue.redF()); + clearCmd.args.clear.c[1] = float(colorClearValue.greenF()); + clearCmd.args.clear.c[2] = float(colorClearValue.blueF()); + clearCmd.args.clear.c[3] = float(colorClearValue.alphaF()); clearCmd.args.clear.d = depthStencilClearValue.depthClearValue(); clearCmd.args.clear.s = depthStencilClearValue.stencilClearValue(); cbD->commands.append(clearCmd); @@ -1582,8 +1582,8 @@ void QRhiD3D11::endPass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resource QD3D11CommandBuffer::Command cmd; cmd.cmd = QD3D11CommandBuffer::Command::ResolveSubRes; cmd.args.resolveSubRes.dst = dstTexD->tex; - cmd.args.resolveSubRes.dstSubRes = D3D11CalcSubresource(colorAtt.resolveLevel(), - colorAtt.resolveLayer(), + cmd.args.resolveSubRes.dstSubRes = D3D11CalcSubresource(UINT(colorAtt.resolveLevel()), + UINT(colorAtt.resolveLayer()), dstTexD->mipLevelCount); if (srcTexD) { cmd.args.resolveSubRes.src = srcTexD->tex; @@ -1610,7 +1610,7 @@ void QRhiD3D11::endPass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resource continue; } } - cmd.args.resolveSubRes.srcSubRes = D3D11CalcSubresource(0, colorAtt.layer(), 1); + cmd.args.resolveSubRes.srcSubRes = D3D11CalcSubresource(0, UINT(colorAtt.layer()), 1); cmd.args.resolveSubRes.format = dstTexD->dxgiFormat; cbD->commands.append(cmd); } @@ -1677,9 +1677,9 @@ void QRhiD3D11::dispatch(QRhiCommandBuffer *cb, int x, int y, int z) QD3D11CommandBuffer::Command cmd; cmd.cmd = QD3D11CommandBuffer::Command::Dispatch; - cmd.args.dispatch.x = x; - cmd.args.dispatch.y = y; - cmd.args.dispatch.z = z; + cmd.args.dispatch.x = UINT(x); + cmd.args.dispatch.y = UINT(y); + cmd.args.dispatch.z = UINT(z); cbD->commands.append(cmd); } @@ -1721,11 +1721,11 @@ void QRhiD3D11::updateShaderResourceBindings(QD3D11ShaderResourceBindings *srbD) // dynamic ubuf offsets are not considered here, those are baked in // at a later stage, which is good as vsubufoffsets and friends are // per-srb, not per-setShaderResources call - const uint offsetInConstants = b->u.ubuf.offset / 16; + const uint offsetInConstants = uint(b->u.ubuf.offset) / 16; // size must be 16 mult. (in constants, i.e. multiple of 256 bytes). // We can round up if needed since the buffers's actual size // (ByteWidth) is always a multiple of 256. - const uint sizeInConstants = aligned(b->u.ubuf.maybeSize ? b->u.ubuf.maybeSize : bufD->m_size, 256) / 16; + const uint sizeInConstants = uint(aligned(b->u.ubuf.maybeSize ? b->u.ubuf.maybeSize : bufD->m_size, 256) / 16); if (b->stage.testFlag(QRhiShaderResourceBinding::VertexStage)) { srbD->vsubufs.feed(b->binding, bufD->buffer); srbD->vsubufoffsets.feed(b->binding, offsetInConstants); @@ -1843,7 +1843,7 @@ void QRhiD3D11::executeBufferHostWritesForCurrentFrame(QD3D11Buffer *bufD) D3D11_MAPPED_SUBRESOURCE mp; HRESULT hr = context->Map(bufD->buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mp); if (SUCCEEDED(hr)) { - memcpy(mp.pData, bufD->dynBuf.constData(), bufD->dynBuf.size()); + memcpy(mp.pData, bufD->dynBuf.constData(), size_t(bufD->dynBuf.size())); context->Unmap(bufD->buffer, 0); } else { qWarning("Failed to map buffer: %s", qPrintable(comErrorMessage(hr))); @@ -1856,13 +1856,13 @@ static void applyDynamicOffsets(QVarLengthArray *offsets, QRhiBatchedBindings *ubufoffsets, const uint *dynOfsPairs, int dynOfsPairCount) { - const UINT count = ubufs->batches[batchIndex].resources.count(); + const int count = ubufs->batches[batchIndex].resources.count(); const UINT startBinding = ubufs->batches[batchIndex].startBinding; *offsets = ubufoffsets->batches[batchIndex].resources; - for (UINT b = 0; b < count; ++b) { + for (int b = 0; b < count; ++b) { for (int di = 0; di < dynOfsPairCount; ++di) { const uint binding = dynOfsPairs[2 * di]; - if (binding == startBinding + b) { + if (binding == startBinding + UINT(b)) { const uint offsetInConstants = dynOfsPairs[2 * di + 1]; (*offsets)[b] = offsetInConstants; break; @@ -1877,37 +1877,37 @@ void QRhiD3D11::bindShaderResources(QD3D11ShaderResourceBindings *srbD, { if (!offsetOnlyChange) { for (const auto &batch : srbD->vssamplers.batches) - context->VSSetSamplers(batch.startBinding, batch.resources.count(), batch.resources.constData()); + context->VSSetSamplers(batch.startBinding, UINT(batch.resources.count()), batch.resources.constData()); for (const auto &batch : srbD->vsshaderresources.batches) { - context->VSSetShaderResources(batch.startBinding, batch.resources.count(), batch.resources.constData()); + context->VSSetShaderResources(batch.startBinding, UINT(batch.resources.count()), batch.resources.constData()); contextState.vsHighestActiveSrvBinding = qMax(contextState.vsHighestActiveSrvBinding, - batch.startBinding + batch.resources.count() - 1); + int(batch.startBinding) + batch.resources.count() - 1); } for (const auto &batch : srbD->fssamplers.batches) - context->PSSetSamplers(batch.startBinding, batch.resources.count(), batch.resources.constData()); + context->PSSetSamplers(batch.startBinding, UINT(batch.resources.count()), batch.resources.constData()); for (const auto &batch : srbD->fsshaderresources.batches) { - context->PSSetShaderResources(batch.startBinding, batch.resources.count(), batch.resources.constData()); + context->PSSetShaderResources(batch.startBinding, UINT(batch.resources.count()), batch.resources.constData()); contextState.fsHighestActiveSrvBinding = qMax(contextState.fsHighestActiveSrvBinding, - batch.startBinding + batch.resources.count() - 1); + int(batch.startBinding) + batch.resources.count() - 1); } for (const auto &batch : srbD->cssamplers.batches) - context->CSSetSamplers(batch.startBinding, batch.resources.count(), batch.resources.constData()); + context->CSSetSamplers(batch.startBinding, UINT(batch.resources.count()), batch.resources.constData()); for (const auto &batch : srbD->csshaderresources.batches) { - context->CSSetShaderResources(batch.startBinding, batch.resources.count(), batch.resources.constData()); + context->CSSetShaderResources(batch.startBinding, UINT(batch.resources.count()), batch.resources.constData()); contextState.csHighestActiveSrvBinding = qMax(contextState.csHighestActiveSrvBinding, - batch.startBinding + batch.resources.count() - 1); + int(batch.startBinding) + batch.resources.count() - 1); } } for (int i = 0, ie = srbD->vsubufs.batches.count(); i != ie; ++i) { if (!dynOfsPairCount) { context->VSSetConstantBuffers1(srbD->vsubufs.batches[i].startBinding, - srbD->vsubufs.batches[i].resources.count(), + UINT(srbD->vsubufs.batches[i].resources.count()), srbD->vsubufs.batches[i].resources.constData(), srbD->vsubufoffsets.batches[i].resources.constData(), srbD->vsubufsizes.batches[i].resources.constData()); @@ -1915,7 +1915,7 @@ void QRhiD3D11::bindShaderResources(QD3D11ShaderResourceBindings *srbD, QVarLengthArray offsets; applyDynamicOffsets(&offsets, i, &srbD->vsubufs, &srbD->vsubufoffsets, dynOfsPairs, dynOfsPairCount); context->VSSetConstantBuffers1(srbD->vsubufs.batches[i].startBinding, - srbD->vsubufs.batches[i].resources.count(), + UINT(srbD->vsubufs.batches[i].resources.count()), srbD->vsubufs.batches[i].resources.constData(), offsets.constData(), srbD->vsubufsizes.batches[i].resources.constData()); @@ -1925,7 +1925,7 @@ void QRhiD3D11::bindShaderResources(QD3D11ShaderResourceBindings *srbD, for (int i = 0, ie = srbD->fsubufs.batches.count(); i != ie; ++i) { if (!dynOfsPairCount) { context->PSSetConstantBuffers1(srbD->fsubufs.batches[i].startBinding, - srbD->fsubufs.batches[i].resources.count(), + UINT(srbD->fsubufs.batches[i].resources.count()), srbD->fsubufs.batches[i].resources.constData(), srbD->fsubufoffsets.batches[i].resources.constData(), srbD->fsubufsizes.batches[i].resources.constData()); @@ -1933,7 +1933,7 @@ void QRhiD3D11::bindShaderResources(QD3D11ShaderResourceBindings *srbD, QVarLengthArray offsets; applyDynamicOffsets(&offsets, i, &srbD->fsubufs, &srbD->fsubufoffsets, dynOfsPairs, dynOfsPairCount); context->PSSetConstantBuffers1(srbD->fsubufs.batches[i].startBinding, - srbD->fsubufs.batches[i].resources.count(), + UINT(srbD->fsubufs.batches[i].resources.count()), srbD->fsubufs.batches[i].resources.constData(), offsets.constData(), srbD->fsubufsizes.batches[i].resources.constData()); @@ -1943,7 +1943,7 @@ void QRhiD3D11::bindShaderResources(QD3D11ShaderResourceBindings *srbD, for (int i = 0, ie = srbD->csubufs.batches.count(); i != ie; ++i) { if (!dynOfsPairCount) { context->CSSetConstantBuffers1(srbD->csubufs.batches[i].startBinding, - srbD->csubufs.batches[i].resources.count(), + UINT(srbD->csubufs.batches[i].resources.count()), srbD->csubufs.batches[i].resources.constData(), srbD->csubufoffsets.batches[i].resources.constData(), srbD->csubufsizes.batches[i].resources.constData()); @@ -1951,7 +1951,7 @@ void QRhiD3D11::bindShaderResources(QD3D11ShaderResourceBindings *srbD, QVarLengthArray offsets; applyDynamicOffsets(&offsets, i, &srbD->csubufs, &srbD->csubufoffsets, dynOfsPairs, dynOfsPairCount); context->CSSetConstantBuffers1(srbD->csubufs.batches[i].startBinding, - srbD->csubufs.batches[i].resources.count(), + UINT(srbD->csubufs.batches[i].resources.count()), srbD->csubufs.batches[i].resources.constData(), offsets.constData(), srbD->csubufsizes.batches[i].resources.constData()); @@ -1960,13 +1960,13 @@ void QRhiD3D11::bindShaderResources(QD3D11ShaderResourceBindings *srbD, for (int i = 0, ie = srbD->csUAVs.batches.count(); i != ie; ++i) { const uint startBinding = srbD->csUAVs.batches[i].startBinding; - const uint count = srbD->csUAVs.batches[i].resources.count(); + const uint count = uint(srbD->csUAVs.batches[i].resources.count()); context->CSSetUnorderedAccessViews(startBinding, count, srbD->csUAVs.batches[i].resources.constData(), nullptr); contextState.csHighestActiveUavBinding = qMax(contextState.csHighestActiveUavBinding, - startBinding + count - 1); + int(startBinding + count - 1)); } } @@ -1990,7 +1990,7 @@ void QRhiD3D11::resetShaderResources() QVarLengthArray nulloffsets(count); for (int i = 0; i < count; ++i) nulloffsets[i] = 0; - context->IASetVertexBuffers(0, count, nullbufs.constData(), nullstrides.constData(), nulloffsets.constData()); + context->IASetVertexBuffers(0, UINT(count), nullbufs.constData(), nullstrides.constData(), nulloffsets.constData()); contextState.vsHighestActiveVertexBufferBinding = -1; } @@ -2003,15 +2003,15 @@ void QRhiD3D11::resetShaderResources() for (int i = 0; i < nullsrvs.count(); ++i) nullsrvs[i] = nullptr; if (contextState.vsHighestActiveSrvBinding >= 0) { - context->VSSetShaderResources(0, contextState.vsHighestActiveSrvBinding + 1, nullsrvs.constData()); + context->VSSetShaderResources(0, UINT(contextState.vsHighestActiveSrvBinding + 1), nullsrvs.constData()); contextState.vsHighestActiveSrvBinding = -1; } if (contextState.fsHighestActiveSrvBinding >= 0) { - context->PSSetShaderResources(0, contextState.fsHighestActiveSrvBinding + 1, nullsrvs.constData()); + context->PSSetShaderResources(0, UINT(contextState.fsHighestActiveSrvBinding + 1), nullsrvs.constData()); contextState.fsHighestActiveSrvBinding = -1; } if (contextState.csHighestActiveSrvBinding >= 0) { - context->CSSetShaderResources(0, contextState.csHighestActiveSrvBinding + 1, nullsrvs.constData()); + context->CSSetShaderResources(0, UINT(contextState.csHighestActiveSrvBinding + 1), nullsrvs.constData()); contextState.csHighestActiveSrvBinding = -1; } } @@ -2022,7 +2022,7 @@ void QRhiD3D11::resetShaderResources() D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT> nulluavs(nulluavCount); for (int i = 0; i < nulluavCount; ++i) nulluavs[i] = nullptr; - context->CSSetUnorderedAccessViews(0, nulluavCount, nulluavs.constData(), nullptr); + context->CSSetUnorderedAccessViews(0, UINT(nulluavCount), nulluavs.constData(), nullptr); contextState.csHighestActiveUavBinding = -1; } } @@ -2044,7 +2044,7 @@ void QRhiD3D11::executeCommandBuffer(QD3D11CommandBuffer *cbD, QD3D11SwapChain * // writing the first timestamp only afterwards. context->Begin(tsDisjoint); QD3D11RenderTargetData *rtD = rtData(×tampSwapChain->rt); - context->OMSetRenderTargets(rtD->colorAttCount, rtD->colorAttCount ? rtD->rtv : nullptr, rtD->dsv); + context->OMSetRenderTargets(UINT(rtD->colorAttCount), rtD->colorAttCount ? rtD->rtv : nullptr, rtD->dsv); context->End(tsStart); // just record a timestamp, no Begin needed } } @@ -2057,7 +2057,7 @@ void QRhiD3D11::executeCommandBuffer(QD3D11CommandBuffer *cbD, QD3D11SwapChain * case QD3D11CommandBuffer::Command::SetRenderTarget: { QD3D11RenderTargetData *rtD = rtData(cmd.args.setRenderTarget.rt); - context->OMSetRenderTargets(rtD->colorAttCount, rtD->colorAttCount ? rtD->rtv : nullptr, rtD->dsv); + context->OMSetRenderTargets(UINT(rtD->colorAttCount), rtD->colorAttCount ? rtD->rtv : nullptr, rtD->dsv); } break; case QD3D11CommandBuffer::Command::Clear: @@ -2073,7 +2073,7 @@ void QRhiD3D11::executeCommandBuffer(QD3D11CommandBuffer *cbD, QD3D11SwapChain * if (cmd.args.clear.mask & QD3D11CommandBuffer::Command::Stencil) ds |= D3D11_CLEAR_STENCIL; if (ds) - context->ClearDepthStencilView(rtD->dsv, ds, cmd.args.clear.d, cmd.args.clear.s); + context->ClearDepthStencilView(rtD->dsv, ds, cmd.args.clear.d, UINT8(cmd.args.clear.s)); } break; case QD3D11CommandBuffer::Command::Viewport: @@ -2103,8 +2103,8 @@ void QRhiD3D11::executeCommandBuffer(QD3D11CommandBuffer *cbD, QD3D11SwapChain * contextState.vsHighestActiveVertexBufferBinding = qMax( contextState.vsHighestActiveVertexBufferBinding, cmd.args.bindVertexBuffers.startSlot + cmd.args.bindVertexBuffers.slotCount - 1); - context->IASetVertexBuffers(cmd.args.bindVertexBuffers.startSlot, - cmd.args.bindVertexBuffers.slotCount, + context->IASetVertexBuffers(UINT(cmd.args.bindVertexBuffers.startSlot), + UINT(cmd.args.bindVertexBuffers.slotCount), cmd.args.bindVertexBuffers.buffers, cmd.args.bindVertexBuffers.strides, cmd.args.bindVertexBuffers.offsets); @@ -2247,7 +2247,7 @@ static inline uint toD3DBufferUsage(QRhiBuffer::UsageFlags usage) u |= D3D11_BIND_CONSTANT_BUFFER; if (usage.testFlag(QRhiBuffer::StorageBuffer)) u |= D3D11_BIND_UNORDERED_ACCESS; - return u; + return uint(u); } bool QD3D11Buffer::build() @@ -2270,7 +2270,7 @@ bool QD3D11Buffer::build() D3D11_BUFFER_DESC desc; memset(&desc, 0, sizeof(desc)); - desc.ByteWidth = roundedSize; + desc.ByteWidth = UINT(roundedSize); desc.Usage = m_type == Dynamic ? D3D11_USAGE_DYNAMIC : D3D11_USAGE_DEFAULT; desc.BindFlags = toD3DBufferUsage(m_usage); desc.CPUAccessFlags = m_type == Dynamic ? D3D11_CPU_ACCESS_WRITE : 0; @@ -2289,10 +2289,10 @@ bool QD3D11Buffer::build() } if (!m_objectName.isEmpty()) - buffer->SetPrivateData(WKPDID_D3DDebugObjectName, m_objectName.size(), m_objectName.constData()); + buffer->SetPrivateData(WKPDID_D3DDebugObjectName, UINT(m_objectName.size()), m_objectName.constData()); QRHI_PROF; - QRHI_PROF_F(newBuffer(this, roundedSize, m_type == Dynamic ? 2 : 1, m_type == Dynamic ? 1 : 0)); + QRHI_PROF_F(newBuffer(this, quint32(roundedSize), m_type == Dynamic ? 2 : 1, m_type == Dynamic ? 1 : 0)); generation += 1; rhiD->registerResource(this); @@ -2310,7 +2310,7 @@ ID3D11UnorderedAccessView *QD3D11Buffer::unorderedAccessView() desc.Format = DXGI_FORMAT_R32_TYPELESS; desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER; desc.Buffer.FirstElement = 0; - desc.Buffer.NumElements = aligned(m_size, 4) / 4; + desc.Buffer.NumElements = UINT(aligned(m_size, 4) / 4); desc.Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW; QRHI_RES_RHI(QRhiD3D11); @@ -2371,8 +2371,8 @@ bool QD3D11RenderBuffer::build() D3D11_TEXTURE2D_DESC desc; memset(&desc, 0, sizeof(desc)); - desc.Width = m_pixelSize.width(); - desc.Height = m_pixelSize.height(); + desc.Width = UINT(m_pixelSize.width()); + desc.Height = UINT(m_pixelSize.height()); desc.MipLevels = 1; desc.ArraySize = 1; desc.SampleDesc = sampleDesc; @@ -2421,10 +2421,10 @@ bool QD3D11RenderBuffer::build() } if (!m_objectName.isEmpty()) - tex->SetPrivateData(WKPDID_D3DDebugObjectName, m_objectName.size(), m_objectName.constData()); + tex->SetPrivateData(WKPDID_D3DDebugObjectName, UINT(m_objectName.size()), m_objectName.constData()); QRHI_PROF; - QRHI_PROF_F(newRenderBuffer(this, false, false, sampleDesc.Count)); + QRHI_PROF_F(newRenderBuffer(this, false, false, int(sampleDesc.Count))); rhiD->registerResource(this); return true; @@ -2514,7 +2514,7 @@ bool QD3D11Texture::prepareBuild(QSize *adjustedSize) QRHI_RES_RHI(QRhiD3D11); dxgiFormat = toD3DTextureFormat(m_format, m_flags); - mipLevelCount = hasMipMaps ? rhiD->q->mipLevelsForSize(size) : 1; + mipLevelCount = uint(hasMipMaps ? rhiD->q->mipLevelsForSize(size) : 1); sampleDesc = rhiD->effectiveSampleCount(m_sampleCount); if (sampleDesc.Count > 1) { if (isCube) { @@ -2600,8 +2600,8 @@ bool QD3D11Texture::build() D3D11_TEXTURE2D_DESC desc; memset(&desc, 0, sizeof(desc)); - desc.Width = size.width(); - desc.Height = size.height(); + desc.Width = UINT(size.width()); + desc.Height = UINT(size.height()); desc.MipLevels = mipLevelCount; desc.ArraySize = isCube ? 6 : 1; desc.Format = dxgiFormat; @@ -2621,10 +2621,10 @@ bool QD3D11Texture::build() return false; if (!m_objectName.isEmpty()) - tex->SetPrivateData(WKPDID_D3DDebugObjectName, m_objectName.size(), m_objectName.constData()); + tex->SetPrivateData(WKPDID_D3DDebugObjectName, UINT(m_objectName.size()), m_objectName.constData()); QRHI_PROF; - QRHI_PROF_F(newTexture(this, true, mipLevelCount, isCube ? 6 : 1, sampleDesc.Count)); + QRHI_PROF_F(newTexture(this, true, int(mipLevelCount), isCube ? 6 : 1, int(sampleDesc.Count))); owns = true; rhiD->registerResource(this); @@ -2646,7 +2646,7 @@ bool QD3D11Texture::buildFrom(const QRhiNativeHandles *src) return false; QRHI_PROF; - QRHI_PROF_F(newTexture(this, false, mipLevelCount, m_flags.testFlag(CubeMap) ? 6 : 1, sampleDesc.Count)); + QRHI_PROF_F(newTexture(this, false, int(mipLevelCount), m_flags.testFlag(CubeMap) ? 6 : 1, int(sampleDesc.Count))); owns = false; QRHI_RES_RHI(QRhiD3D11); @@ -2670,12 +2670,12 @@ ID3D11UnorderedAccessView *QD3D11Texture::unorderedAccessViewForLevel(int level) desc.Format = dxgiFormat; if (isCube) { desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2DARRAY; - desc.Texture2DArray.MipSlice = level; + desc.Texture2DArray.MipSlice = UINT(level); desc.Texture2DArray.FirstArraySlice = 0; desc.Texture2DArray.ArraySize = 6; } else { desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D; - desc.Texture2D.MipSlice = level; + desc.Texture2D.MipSlice = UINT(level); } QRHI_RES_RHI(QRhiD3D11); @@ -2935,15 +2935,15 @@ bool QD3D11TextureRenderTarget::build() rtvDesc.Format = toD3DTextureFormat(texD->format(), texD->flags()); if (texD->flags().testFlag(QRhiTexture::CubeMap)) { rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY; - rtvDesc.Texture2DArray.MipSlice = colorAttachments[i].level(); - rtvDesc.Texture2DArray.FirstArraySlice = colorAttachments[i].layer(); + rtvDesc.Texture2DArray.MipSlice = UINT(colorAttachments[i].level()); + rtvDesc.Texture2DArray.FirstArraySlice = UINT(colorAttachments[i].layer()); rtvDesc.Texture2DArray.ArraySize = 1; } else { if (texD->sampleDesc.Count > 1) { rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMS; } else { rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D; - rtvDesc.Texture2D.MipSlice = colorAttachments[i].level(); + rtvDesc.Texture2D.MipSlice = UINT(colorAttachments[i].level()); } } HRESULT hr = rhiD->dev->CreateRenderTargetView(texD->tex, &rtvDesc, &rtv[i]); @@ -2954,7 +2954,7 @@ bool QD3D11TextureRenderTarget::build() ownsRtv[i] = true; if (i == 0) { d.pixelSize = texD->pixelSize(); - d.sampleCount = texD->sampleDesc.Count; + d.sampleCount = int(texD->sampleDesc.Count); } } else if (rb) { QD3D11RenderBuffer *rbD = QRHI_RES(QD3D11RenderBuffer, rb); @@ -2962,7 +2962,7 @@ bool QD3D11TextureRenderTarget::build() rtv[i] = rbD->rtv; if (i == 0) { d.pixelSize = rbD->pixelSize(); - d.sampleCount = rbD->sampleDesc.Count; + d.sampleCount = int(rbD->sampleDesc.Count); } } } @@ -2984,7 +2984,7 @@ bool QD3D11TextureRenderTarget::build() } if (d.colorAttCount == 0) { d.pixelSize = depthTexD->pixelSize(); - d.sampleCount = depthTexD->sampleDesc.Count; + d.sampleCount = int(depthTexD->sampleDesc.Count); } } else { ownsDsv = false; @@ -2992,7 +2992,7 @@ bool QD3D11TextureRenderTarget::build() dsv = depthRbD->dsv; if (d.colorAttCount == 0) { d.pixelSize = m_desc.depthStencilBuffer()->pixelSize(); - d.sampleCount = depthRbD->sampleDesc.Count; + d.sampleCount = int(depthRbD->sampleDesc.Count); } } d.dsAttCount = 1; @@ -3216,9 +3216,9 @@ static inline D3D11_PRIMITIVE_TOPOLOGY toD3DTopology(QRhiGraphicsPipeline::Topol } } -static inline uint toD3DColorWriteMask(QRhiGraphicsPipeline::ColorMask c) +static inline UINT8 toD3DColorWriteMask(QRhiGraphicsPipeline::ColorMask c) { - uint f = 0; + UINT8 f = 0; if (c.testFlag(QRhiGraphicsPipeline::R)) f |= D3D11_COLOR_WRITE_ENABLE_RED; if (c.testFlag(QRhiGraphicsPipeline::G)) @@ -3353,22 +3353,22 @@ static QByteArray compileHlslShaderSource(const QShader &shader, QShader::Varian ID3DBlob *bytecode = nullptr; ID3DBlob *errors = nullptr; - HRESULT hr = d3dCompile(hlslSource.shader().constData(), hlslSource.shader().size(), + HRESULT hr = d3dCompile(hlslSource.shader().constData(), SIZE_T(hlslSource.shader().size()), nullptr, nullptr, nullptr, hlslSource.entryPoint().constData(), target, 0, 0, &bytecode, &errors); if (FAILED(hr) || !bytecode) { qWarning("HLSL shader compilation failed: 0x%x", uint(hr)); if (errors) { *error = QString::fromUtf8(static_cast(errors->GetBufferPointer()), - errors->GetBufferSize()); + int(errors->GetBufferSize())); errors->Release(); } return QByteArray(); } QByteArray result; - result.resize(bytecode->GetBufferSize()); - memcpy(result.data(), bytecode->GetBufferPointer(), result.size()); + result.resize(int(bytecode->GetBufferSize())); + memcpy(result.data(), bytecode->GetBufferPointer(), size_t(result.size())); bytecode->Release(); return result; } @@ -3400,8 +3400,8 @@ bool QD3D11GraphicsPipeline::build() dsDesc.DepthFunc = toD3DCompareOp(m_depthOp); dsDesc.StencilEnable = m_stencilTest; if (m_stencilTest) { - dsDesc.StencilReadMask = m_stencilReadMask; - dsDesc.StencilWriteMask = m_stencilWriteMask; + dsDesc.StencilReadMask = UINT8(m_stencilReadMask); + dsDesc.StencilWriteMask = UINT8(m_stencilWriteMask); dsDesc.FrontFace.StencilFailOp = toD3DStencilOp(m_stencilFront.failOp); dsDesc.FrontFace.StencilDepthFailOp = toD3DStencilOp(m_stencilFront.depthFailOp); dsDesc.FrontFace.StencilPassOp = toD3DStencilOp(m_stencilFront.passOp); @@ -3478,7 +3478,7 @@ bool QD3D11GraphicsPipeline::build() switch (shaderStage.type()) { case QRhiShaderStage::Vertex: - hr = rhiD->dev->CreateVertexShader(bytecode.constData(), bytecode.size(), nullptr, &vs); + hr = rhiD->dev->CreateVertexShader(bytecode.constData(), SIZE_T(bytecode.size()), nullptr, &vs); if (FAILED(hr)) { qWarning("Failed to create vertex shader: %s", qPrintable(comErrorMessage(hr))); return false; @@ -3488,7 +3488,7 @@ bool QD3D11GraphicsPipeline::build() vs->AddRef(); break; case QRhiShaderStage::Fragment: - hr = rhiD->dev->CreatePixelShader(bytecode.constData(), bytecode.size(), nullptr, &fs); + hr = rhiD->dev->CreatePixelShader(bytecode.constData(), SIZE_T(bytecode.size()), nullptr, &fs); if (FAILED(hr)) { qWarning("Failed to create pixel shader: %s", qPrintable(comErrorMessage(hr))); return false; @@ -3513,20 +3513,21 @@ bool QD3D11GraphicsPipeline::build() memset(&desc, 0, sizeof(desc)); // the output from SPIRV-Cross uses TEXCOORD as the semantic desc.SemanticName = "TEXCOORD"; - desc.SemanticIndex = attribute.location(); + desc.SemanticIndex = UINT(attribute.location()); desc.Format = toD3DAttributeFormat(attribute.format()); - desc.InputSlot = attribute.binding(); + desc.InputSlot = UINT(attribute.binding()); desc.AlignedByteOffset = attribute.offset(); const QRhiVertexInputBinding &binding(bindings[attribute.binding()]); if (binding.classification() == QRhiVertexInputBinding::PerInstance) { desc.InputSlotClass = D3D11_INPUT_PER_INSTANCE_DATA; - desc.InstanceDataStepRate = binding.instanceStepRate(); + desc.InstanceDataStepRate = UINT(binding.instanceStepRate()); } else { desc.InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; } inputDescs.append(desc); } - hr = rhiD->dev->CreateInputLayout(inputDescs.constData(), inputDescs.count(), vsByteCode, vsByteCode.size(), &inputLayout); + hr = rhiD->dev->CreateInputLayout(inputDescs.constData(), UINT(inputDescs.count()), + vsByteCode, SIZE_T(vsByteCode.size()), &inputLayout); if (FAILED(hr)) { qWarning("Failed to create input layout: %s", qPrintable(comErrorMessage(hr))); return false; @@ -3579,7 +3580,7 @@ bool QD3D11ComputePipeline::build() return false; } - HRESULT hr = rhiD->dev->CreateComputeShader(bytecode.constData(), bytecode.size(), nullptr, &cs); + HRESULT hr = rhiD->dev->CreateComputeShader(bytecode.constData(), SIZE_T(bytecode.size()), nullptr, &cs); if (FAILED(hr)) { qWarning("Failed to create compute shader: %s", qPrintable(comErrorMessage(hr))); return false; @@ -3715,8 +3716,8 @@ bool QD3D11SwapChain::newColorBuffer(const QSize &size, DXGI_FORMAT format, DXGI { D3D11_TEXTURE2D_DESC desc; memset(&desc, 0, sizeof(desc)); - desc.Width = size.width(); - desc.Height = size.height(); + desc.Width = UINT(size.width()); + desc.Height = UINT(size.height()); desc.MipLevels = 1; desc.ArraySize = 1; desc.Format = format; @@ -3787,8 +3788,8 @@ bool QD3D11SwapChain::buildOrResize() DXGI_SWAP_CHAIN_DESC1 desc; memset(&desc, 0, sizeof(desc)); - desc.Width = pixelSize.width(); - desc.Height = pixelSize.height(); + desc.Width = UINT(pixelSize.width()); + desc.Height = UINT(pixelSize.height()); desc.Format = colorFormat; desc.SampleDesc.Count = 1; desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; @@ -3813,8 +3814,8 @@ bool QD3D11SwapChain::buildOrResize() DXGI_SWAP_CHAIN_DESC desc; memset(&desc, 0, sizeof(desc)); - desc.BufferDesc.Width = pixelSize.width(); - desc.BufferDesc.Height = pixelSize.height(); + desc.BufferDesc.Width = UINT(pixelSize.width()); + desc.BufferDesc.Height = UINT(pixelSize.height()); desc.BufferDesc.RefreshRate.Numerator = 60; desc.BufferDesc.RefreshRate.Denominator = 1; desc.BufferDesc.Format = colorFormat; @@ -3836,7 +3837,7 @@ bool QD3D11SwapChain::buildOrResize() } else { releaseBuffers(); const UINT count = useFlipDiscard ? BUFFER_COUNT : 1; - HRESULT hr = swapChain->ResizeBuffers(count, pixelSize.width(), pixelSize.height(), + HRESULT hr = swapChain->ResizeBuffers(count, UINT(pixelSize.width()), UINT(pixelSize.height()), colorFormat, swapChainFlags); if (FAILED(hr)) { qWarning("Failed to resize D3D11 swapchain: %s", qPrintable(comErrorMessage(hr))); @@ -3899,13 +3900,13 @@ bool QD3D11SwapChain::buildOrResize() QD3D11ReferenceRenderTarget *rtD = QRHI_RES(QD3D11ReferenceRenderTarget, &rt); rtD->d.rp = QRHI_RES(QD3D11RenderPassDescriptor, m_renderPassDesc); rtD->d.pixelSize = pixelSize; - rtD->d.dpr = window->devicePixelRatio(); - rtD->d.sampleCount = sampleDesc.Count; + rtD->d.dpr = float(window->devicePixelRatio()); + rtD->d.sampleCount = int(sampleDesc.Count); rtD->d.colorAttCount = 1; rtD->d.dsAttCount = m_depthStencil ? 1 : 0; QRHI_PROF; - QRHI_PROF_F(resizeSwapChain(this, BUFFER_COUNT, sampleDesc.Count > 1 ? BUFFER_COUNT : 0, sampleDesc.Count)); + QRHI_PROF_F(resizeSwapChain(this, BUFFER_COUNT, sampleDesc.Count > 1 ? BUFFER_COUNT : 0, int(sampleDesc.Count))); if (rhiP) { D3D11_QUERY_DESC queryDesc; memset(&queryDesc, 0, sizeof(queryDesc)); diff --git a/src/gui/rhi/qrhigles2.cpp b/src/gui/rhi/qrhigles2.cpp index 9ad591a17a..0329acd350 100644 --- a/src/gui/rhi/qrhigles2.cpp +++ b/src/gui/rhi/qrhigles2.cpp @@ -654,7 +654,7 @@ static inline GLenum toGlCompressedTextureFormat(QRhiTexture::Format format, QRh bool QRhiGles2::isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture::Flags flags) const { if (isCompressedFormat(format)) - return supportedCompressedFormats.contains(toGlCompressedTextureFormat(format, flags)); + return supportedCompressedFormats.contains(GLint(toGlCompressedTextureFormat(format, flags))); switch (format) { case QRhiTexture::D16: @@ -930,7 +930,7 @@ void QRhiGles2::setShaderResources(QRhiCommandBuffer *cb, QRhiShaderResourceBind uint *p = cmd.args.bindShaderResources.dynamicOffsetPairs; for (int i = 0; i < dynamicOffsetCount; ++i) { const QRhiCommandBuffer::DynamicOffset &dynOfs(dynamicOffsets[i]); - *p++ = dynOfs.first; + *p++ = uint(dynOfs.first); *p++ = dynOfs.second; } } else { @@ -1023,10 +1023,10 @@ void QRhiGles2::setBlendConstants(QRhiCommandBuffer *cb, const QColor &c) QGles2CommandBuffer::Command cmd; cmd.cmd = QGles2CommandBuffer::Command::BlendConstants; - cmd.args.blendConstants.r = c.redF(); - cmd.args.blendConstants.g = c.greenF(); - cmd.args.blendConstants.b = c.blueF(); - cmd.args.blendConstants.a = c.alphaF(); + cmd.args.blendConstants.r = float(c.redF()); + cmd.args.blendConstants.g = float(c.greenF()); + cmd.args.blendConstants.b = float(c.blueF()); + cmd.args.blendConstants.a = float(c.alphaF()); cbD->commands.append(cmd); } @@ -1314,7 +1314,7 @@ void QRhiGles2::enqueueSubresUpload(QGles2Texture *texD, QGles2CommandBuffer *cb } cmd.args.subImage.target = texD->target; cmd.args.subImage.texture = texD->texture; - cmd.args.subImage.faceTarget = faceTargetBase + layer; + cmd.args.subImage.faceTarget = faceTargetBase + uint(layer); cmd.args.subImage.level = level; cmd.args.subImage.dx = dp.x(); cmd.args.subImage.dy = dp.y(); @@ -1333,7 +1333,7 @@ void QRhiGles2::enqueueSubresUpload(QGles2Texture *texD, QGles2CommandBuffer *cb cmd.cmd = QGles2CommandBuffer::Command::CompressedSubImage; cmd.args.compressedSubImage.target = texD->target; cmd.args.compressedSubImage.texture = texD->texture; - cmd.args.compressedSubImage.faceTarget = faceTargetBase + layer; + cmd.args.compressedSubImage.faceTarget = faceTargetBase + uint(layer); cmd.args.compressedSubImage.level = level; cmd.args.compressedSubImage.dx = dp.x(); cmd.args.compressedSubImage.dy = dp.y(); @@ -1348,7 +1348,7 @@ void QRhiGles2::enqueueSubresUpload(QGles2Texture *texD, QGles2CommandBuffer *cb cmd.cmd = QGles2CommandBuffer::Command::CompressedImage; cmd.args.compressedImage.target = texD->target; cmd.args.compressedImage.texture = texD->texture; - cmd.args.compressedImage.faceTarget = faceTargetBase + layer; + cmd.args.compressedImage.faceTarget = faceTargetBase + uint(layer); cmd.args.compressedImage.level = level; cmd.args.compressedImage.glintformat = texD->glintformat; cmd.args.compressedImage.w = size.width(); @@ -1366,7 +1366,7 @@ void QRhiGles2::enqueueSubresUpload(QGles2Texture *texD, QGles2CommandBuffer *cb cmd.cmd = QGles2CommandBuffer::Command::SubImage; cmd.args.subImage.target = texD->target; cmd.args.subImage.texture = texD->texture; - cmd.args.subImage.faceTarget = faceTargetBase + layer; + cmd.args.subImage.faceTarget = faceTargetBase + uint(layer); cmd.args.subImage.level = level; cmd.args.subImage.dx = dp.x(); cmd.args.subImage.dy = dp.y(); @@ -1394,7 +1394,7 @@ void QRhiGles2::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate QGles2Buffer *bufD = QRHI_RES(QGles2Buffer, u.buf); Q_ASSERT(bufD->m_type == QRhiBuffer::Dynamic); if (bufD->m_usage.testFlag(QRhiBuffer::UniformBuffer)) { - memcpy(bufD->ubuf.data() + u.offset, u.data.constData(), u.data.size()); + memcpy(bufD->ubuf.data() + u.offset, u.data.constData(), size_t(u.data.size())); } else { trackedBufferBarrier(cbD, bufD, QGles2Buffer::AccessUpdate); QGles2CommandBuffer::Command cmd; @@ -1413,7 +1413,7 @@ void QRhiGles2::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate Q_ASSERT(bufD->m_type != QRhiBuffer::Dynamic); Q_ASSERT(u.offset + u.data.size() <= bufD->m_size); if (bufD->m_usage.testFlag(QRhiBuffer::UniformBuffer)) { - memcpy(bufD->ubuf.data() + u.offset, u.data.constData(), u.data.size()); + memcpy(bufD->ubuf.data() + u.offset, u.data.constData(), size_t(u.data.size())); } else { trackedBufferBarrier(cbD, bufD, QGles2Buffer::AccessUpdate); QGles2CommandBuffer::Command cmd; @@ -1458,7 +1458,7 @@ void QRhiGles2::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate QGles2CommandBuffer::Command cmd; cmd.cmd = QGles2CommandBuffer::Command::CopyTex; - cmd.args.copyTex.srcFaceTarget = srcFaceTargetBase + u.copy.desc.sourceLayer(); + cmd.args.copyTex.srcFaceTarget = srcFaceTargetBase + uint(u.copy.desc.sourceLayer()); cmd.args.copyTex.srcTexture = srcD->texture; cmd.args.copyTex.srcLevel = u.copy.desc.sourceLevel(); cmd.args.copyTex.srcX = sp.x(); @@ -1466,7 +1466,7 @@ void QRhiGles2::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate cmd.args.copyTex.dstTarget = dstD->target; cmd.args.copyTex.dstTexture = dstD->texture; - cmd.args.copyTex.dstFaceTarget = dstFaceTargetBase + u.copy.desc.destinationLayer(); + cmd.args.copyTex.dstFaceTarget = dstFaceTargetBase + uint(u.copy.desc.destinationLayer()); cmd.args.copyTex.dstLevel = u.copy.desc.destinationLevel(); cmd.args.copyTex.dstX = dp.x(); cmd.args.copyTex.dstY = dp.y(); @@ -1488,7 +1488,7 @@ void QRhiGles2::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate cmd.args.readPixels.format = texD->m_format; const GLenum faceTargetBase = texD->m_flags.testFlag(QRhiTexture::CubeMap) ? GL_TEXTURE_CUBE_MAP_POSITIVE_X : texD->target; - cmd.args.readPixels.readTarget = faceTargetBase + u.read.rb.layer(); + cmd.args.readPixels.readTarget = faceTargetBase + uint(u.read.rb.layer()); cmd.args.readPixels.level = u.read.rb.level(); } cbD->commands.append(cmd); @@ -1848,7 +1848,7 @@ void QRhiGles2::executeCommandBuffer(QRhiCommandBuffer *cb) f->glBindVertexArray(0); break; case QGles2CommandBuffer::Command::Viewport: - f->glViewport(cmd.args.viewport.x, cmd.args.viewport.y, cmd.args.viewport.w, cmd.args.viewport.h); + f->glViewport(GLint(cmd.args.viewport.x), GLint(cmd.args.viewport.y), GLsizei(cmd.args.viewport.w), GLsizei(cmd.args.viewport.h)); f->glDepthRangef(cmd.args.viewport.d0, cmd.args.viewport.d1); break; case QGles2CommandBuffer::Command::Scissor: @@ -1861,8 +1861,8 @@ void QRhiGles2::executeCommandBuffer(QRhiCommandBuffer *cb) { QGles2GraphicsPipeline *psD = QRHI_RES(QGles2GraphicsPipeline, cmd.args.stencilRef.ps); if (psD) { - f->glStencilFuncSeparate(GL_FRONT, toGlCompareOp(psD->m_stencilFront.compareOp), cmd.args.stencilRef.ref, psD->m_stencilReadMask); - f->glStencilFuncSeparate(GL_BACK, toGlCompareOp(psD->m_stencilBack.compareOp), cmd.args.stencilRef.ref, psD->m_stencilReadMask); + f->glStencilFuncSeparate(GL_FRONT, toGlCompareOp(psD->m_stencilFront.compareOp), GLint(cmd.args.stencilRef.ref), psD->m_stencilReadMask); + f->glStencilFuncSeparate(GL_BACK, toGlCompareOp(psD->m_stencilBack.compareOp), GLint(cmd.args.stencilRef.ref), psD->m_stencilReadMask); } else { qWarning("No graphics pipeline active for setStencilRef; ignored"); } @@ -1882,7 +1882,7 @@ void QRhiGles2::executeCommandBuffer(QRhiCommandBuffer *cb) // we do not support more than one vertex buffer f->glBindBuffer(GL_ARRAY_BUFFER, cmd.args.bindVertexBuffer.buffer); - const int stride = bindings[bindingIdx].stride(); + const int stride = int(bindings[bindingIdx].stride()); int size = 1; GLenum type = GL_FLOAT; bool normalize = false; @@ -1924,13 +1924,13 @@ void QRhiGles2::executeCommandBuffer(QRhiCommandBuffer *cb) const int locationIdx = a.location(); quint32 ofs = a.offset() + cmd.args.bindVertexBuffer.offset; - f->glVertexAttribPointer(locationIdx, size, type, normalize, stride, + f->glVertexAttribPointer(GLuint(locationIdx), size, type, normalize, stride, reinterpret_cast(quintptr(ofs))); - f->glEnableVertexAttribArray(locationIdx); + f->glEnableVertexAttribArray(GLuint(locationIdx)); if (bindings[bindingIdx].classification() == QRhiVertexInputBinding::PerInstance && caps.instancing) { - f->glVertexAttribDivisor(locationIdx, bindings[bindingIdx].instanceStepRate()); + f->glVertexAttribDivisor(GLuint(locationIdx), GLuint(bindings[bindingIdx].instanceStepRate())); } } } else { @@ -1949,10 +1949,10 @@ void QRhiGles2::executeCommandBuffer(QRhiCommandBuffer *cb) QGles2GraphicsPipeline *psD = QRHI_RES(QGles2GraphicsPipeline, cmd.args.draw.ps); if (psD) { if (cmd.args.draw.instanceCount == 1 || !caps.instancing) { - f->glDrawArrays(psD->drawMode, cmd.args.draw.firstVertex, cmd.args.draw.vertexCount); + f->glDrawArrays(psD->drawMode, GLint(cmd.args.draw.firstVertex), GLsizei(cmd.args.draw.vertexCount)); } else { - f->glDrawArraysInstanced(psD->drawMode, cmd.args.draw.firstVertex, cmd.args.draw.vertexCount, - cmd.args.draw.instanceCount); + f->glDrawArraysInstanced(psD->drawMode, GLint(cmd.args.draw.firstVertex), GLsizei(cmd.args.draw.vertexCount), + GLsizei(cmd.args.draw.instanceCount)); } } else { qWarning("No graphics pipeline active for draw; ignored"); @@ -1968,30 +1968,30 @@ void QRhiGles2::executeCommandBuffer(QRhiCommandBuffer *cb) if (cmd.args.drawIndexed.instanceCount == 1 || !caps.instancing) { if (cmd.args.drawIndexed.baseVertex != 0 && caps.baseVertex) { f->glDrawElementsBaseVertex(psD->drawMode, - cmd.args.drawIndexed.indexCount, + GLsizei(cmd.args.drawIndexed.indexCount), indexType, ofs, cmd.args.drawIndexed.baseVertex); } else { f->glDrawElements(psD->drawMode, - cmd.args.drawIndexed.indexCount, + GLsizei(cmd.args.drawIndexed.indexCount), indexType, ofs); } } else { if (cmd.args.drawIndexed.baseVertex != 0 && caps.baseVertex) { f->glDrawElementsInstancedBaseVertex(psD->drawMode, - cmd.args.drawIndexed.indexCount, + GLsizei(cmd.args.drawIndexed.indexCount), indexType, ofs, - cmd.args.drawIndexed.instanceCount, + GLsizei(cmd.args.drawIndexed.instanceCount), cmd.args.drawIndexed.baseVertex); } else { f->glDrawElementsInstanced(psD->drawMode, - cmd.args.drawIndexed.indexCount, + GLsizei(cmd.args.drawIndexed.indexCount), indexType, ofs, - cmd.args.drawIndexed.instanceCount); + GLsizei(cmd.args.drawIndexed.instanceCount)); } } } else { @@ -2016,7 +2016,7 @@ void QRhiGles2::executeCommandBuffer(QRhiCommandBuffer *cb) const int colorAttCount = cmd.args.bindFramebuffer.colorAttCount; QVarLengthArray bufs; for (int i = 0; i < colorAttCount; ++i) - bufs.append(GL_COLOR_ATTACHMENT0 + i); + bufs.append(GL_COLOR_ATTACHMENT0 + uint(i)); f->glDrawBuffers(colorAttCount, bufs.constData()); } } else { @@ -2044,7 +2044,7 @@ void QRhiGles2::executeCommandBuffer(QRhiCommandBuffer *cb) f->glClearDepthf(cmd.args.clear.d); } if (cmd.args.clear.mask & GL_STENCIL_BUFFER_BIT) - f->glClearStencil(cmd.args.clear.s); + f->glClearStencil(GLint(cmd.args.clear.s)); f->glClear(cmd.args.clear.mask); break; case QGles2CommandBuffer::Command::BufferSubData: @@ -2288,7 +2288,7 @@ void QRhiGles2::bindShaderResources(QRhiGraphicsPipeline *maybeGraphicsPs, QRhiC if (dynOfsCount) { for (int j = 0; j < dynOfsCount; ++j) { if (dynOfsPairs[2 * j] == uint(b->binding)) { - viewOffset = dynOfsPairs[2 * j + 1]; + viewOffset = int(dynOfsPairs[2 * j + 1]); break; } } @@ -2379,20 +2379,20 @@ void QRhiGles2::bindShaderResources(QRhiGraphicsPipeline *maybeGraphicsPs, QRhiC for (QGles2SamplerDescription &sampler : samplers) { if (sampler.binding == b->binding) { - f->glActiveTexture(GL_TEXTURE0 + texUnit); + f->glActiveTexture(GL_TEXTURE0 + uint(texUnit)); f->glBindTexture(texD->target, texD->texture); if (texD->samplerState != samplerD->d) { - f->glTexParameteri(texD->target, GL_TEXTURE_MIN_FILTER, samplerD->d.glminfilter); - f->glTexParameteri(texD->target, GL_TEXTURE_MAG_FILTER, samplerD->d.glmagfilter); - f->glTexParameteri(texD->target, GL_TEXTURE_WRAP_S, samplerD->d.glwraps); - f->glTexParameteri(texD->target, GL_TEXTURE_WRAP_T, samplerD->d.glwrapt); + f->glTexParameteri(texD->target, GL_TEXTURE_MIN_FILTER, GLint(samplerD->d.glminfilter)); + f->glTexParameteri(texD->target, GL_TEXTURE_MAG_FILTER, GLint(samplerD->d.glmagfilter)); + f->glTexParameteri(texD->target, GL_TEXTURE_WRAP_S, GLint(samplerD->d.glwraps)); + f->glTexParameteri(texD->target, GL_TEXTURE_WRAP_T, GLint(samplerD->d.glwrapt)); // 3D textures not supported by GLES 2.0 or by us atm... //f->glTexParameteri(texD->target, GL_TEXTURE_WRAP_R, samplerD->d.glwrapr); if (caps.textureCompareMode) { if (samplerD->d.gltexcomparefunc != GL_NEVER) { f->glTexParameteri(texD->target, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE); - f->glTexParameteri(texD->target, GL_TEXTURE_COMPARE_FUNC, samplerD->d.gltexcomparefunc); + f->glTexParameteri(texD->target, GL_TEXTURE_COMPARE_FUNC, GLint(samplerD->d.gltexcomparefunc)); } else { f->glTexParameteri(texD->target, GL_TEXTURE_COMPARE_MODE, GL_NONE); } @@ -2419,7 +2419,7 @@ void QRhiGles2::bindShaderResources(QRhiGraphicsPipeline *maybeGraphicsPs, QRhiC access = GL_READ_ONLY; else if (b->type == QRhiShaderResourceBinding::ImageStore) access = GL_WRITE_ONLY; - f->glBindImageTexture(b->binding, texD->texture, + f->glBindImageTexture(GLuint(b->binding), texD->texture, b->u.simage.level, layered, 0, access, texD->glsizedintformat); } @@ -2432,9 +2432,9 @@ void QRhiGles2::bindShaderResources(QRhiGraphicsPipeline *maybeGraphicsPs, QRhiC { QGles2Buffer *bufD = QRHI_RES(QGles2Buffer, b->u.sbuf.buf); if (b->u.sbuf.offset == 0 && b->u.sbuf.maybeSize == 0) - f->glBindBufferBase(GL_SHADER_STORAGE_BUFFER, b->binding, bufD->buffer); + f->glBindBufferBase(GL_SHADER_STORAGE_BUFFER, GLuint(b->binding), bufD->buffer); else - f->glBindBufferRange(GL_SHADER_STORAGE_BUFFER, b->binding, bufD->buffer, + f->glBindBufferRange(GL_SHADER_STORAGE_BUFFER, GLuint(b->binding), bufD->buffer, b->u.sbuf.offset, b->u.sbuf.maybeSize ? b->u.sbuf.maybeSize : bufD->m_size); } break; @@ -2556,10 +2556,10 @@ void QRhiGles2::beginPass(QRhiCommandBuffer *cb, clearCmd.args.clear.mask |= GL_COLOR_BUFFER_BIT; if (rtD->dsAttCount && wantsDsClear) clearCmd.args.clear.mask |= GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT; - clearCmd.args.clear.c[0] = colorClearValue.redF(); - clearCmd.args.clear.c[1] = colorClearValue.greenF(); - clearCmd.args.clear.c[2] = colorClearValue.blueF(); - clearCmd.args.clear.c[3] = colorClearValue.alphaF(); + clearCmd.args.clear.c[0] = float(colorClearValue.redF()); + clearCmd.args.clear.c[1] = float(colorClearValue.greenF()); + clearCmd.args.clear.c[2] = float(colorClearValue.blueF()); + clearCmd.args.clear.c[3] = float(colorClearValue.alphaF()); clearCmd.args.clear.d = depthStencilClearValue.depthClearValue(); clearCmd.args.clear.s = depthStencilClearValue.stencilClearValue(); cbD->commands.append(clearCmd); @@ -2597,7 +2597,7 @@ void QRhiGles2::endPass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resource QGles2Texture *colorTexD = QRHI_RES(QGles2Texture, colorAtt.resolveTexture()); const GLenum faceTargetBase = colorTexD->m_flags.testFlag(QRhiTexture::CubeMap) ? GL_TEXTURE_CUBE_MAP_POSITIVE_X : colorTexD->target; - cmd.args.blitFromRb.target = faceTargetBase + colorAtt.resolveLayer(); + cmd.args.blitFromRb.target = faceTargetBase + uint(colorAtt.resolveLayer()); cmd.args.blitFromRb.texture = colorTexD->texture; cmd.args.blitFromRb.dstLevel = colorAtt.resolveLevel(); cbD->commands.append(cmd); @@ -2664,9 +2664,9 @@ void QRhiGles2::dispatch(QRhiCommandBuffer *cb, int x, int y, int z) QGles2CommandBuffer::Command cmd; cmd.cmd = QGles2CommandBuffer::Command::Dispatch; - cmd.args.dispatch.x = x; - cmd.args.dispatch.y = y; - cmd.args.dispatch.z = z; + cmd.args.dispatch.x = GLuint(x); + cmd.args.dispatch.y = GLuint(y); + cmd.args.dispatch.z = GLuint(z); cbD->commands.append(cmd); } @@ -2818,7 +2818,7 @@ void QRhiGles2::gatherUniforms(GLuint program, const QShaderDescription::Uniform uniform.glslLocation = f->glGetUniformLocation(program, name.constData()); if (uniform.glslLocation >= 0) { uniform.binding = ub.binding; - uniform.offset = blockMember.offset; + uniform.offset = uint(blockMember.offset); uniform.size = blockMember.size; dst->append(uniform); } @@ -2882,7 +2882,7 @@ bool QGles2Buffer::build() return false; } ubuf.resize(nonZeroSize); - QRHI_PROF_F(newBuffer(this, nonZeroSize, 0, 1)); + QRHI_PROF_F(newBuffer(this, uint(nonZeroSize), 0, 1)); return true; } @@ -2901,7 +2901,7 @@ bool QGles2Buffer::build() usageState.access = AccessNone; - QRHI_PROF_F(newBuffer(this, nonZeroSize, 1, 0)); + QRHI_PROF_F(newBuffer(this, uint(nonZeroSize), 1, 0)); rhiD->registerResource(this); return true; } @@ -3172,13 +3172,13 @@ bool QGles2Texture::build() for (int layer = 0, layerCount = isCube ? 6 : 1; layer != layerCount; ++layer) { for (int level = 0; level != mipLevelCount; ++level) { const QSize mipSize = rhiD->q->sizeForMipLevel(level, size); - rhiD->f->glTexImage2D(faceTargetBase + layer, level, glintformat, + rhiD->f->glTexImage2D(faceTargetBase + uint(layer), level, GLint(glintformat), mipSize.width(), mipSize.height(), 0, glformat, gltype, nullptr); } } } else { - rhiD->f->glTexImage2D(target, 0, glintformat, size.width(), size.height(), + rhiD->f->glTexImage2D(target, 0, GLint(glintformat), size.width(), size.height(), 0, glformat, gltype, nullptr); } } else { @@ -3381,14 +3381,15 @@ bool QGles2TextureRenderTarget::build() QGles2Texture *texD = QRHI_RES(QGles2Texture, texture); Q_ASSERT(texD->texture && texD->specified); const GLenum faceTargetBase = texD->flags().testFlag(QRhiTexture::CubeMap) ? GL_TEXTURE_CUBE_MAP_POSITIVE_X : texD->target; - rhiD->f->glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, faceTargetBase + colorAtt.layer(), texD->texture, colorAtt.level()); + rhiD->f->glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uint(i), faceTargetBase + uint(colorAtt.layer()), + texD->texture, colorAtt.level()); if (i == 0) { d.pixelSize = texD->pixelSize(); d.sampleCount = 1; } } else if (renderBuffer) { QGles2RenderBuffer *rbD = QRHI_RES(QGles2RenderBuffer, renderBuffer); - rhiD->f->glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_RENDERBUFFER, rbD->renderbuffer); + rhiD->f->glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uint(i), GL_RENDERBUFFER, rbD->renderbuffer); if (i == 0) { d.pixelSize = rbD->pixelSize(); d.sampleCount = rbD->samples; @@ -3538,7 +3539,7 @@ bool QGles2GraphicsPipeline::build() for (auto inVar : vsDesc.inputVariables()) { const QByteArray name = inVar.name.toUtf8(); - rhiD->f->glBindAttribLocation(program, inVar.location, name.constData()); + rhiD->f->glBindAttribLocation(program, GLuint(inVar.location), name.constData()); } if (!rhiD->linkProgram(program)) @@ -3684,7 +3685,7 @@ bool QGles2SwapChain::buildOrResize() rt.d.rp = QRHI_RES(QGles2RenderPassDescriptor, m_renderPassDesc); rt.d.pixelSize = pixelSize; - rt.d.dpr = m_window->devicePixelRatio(); + rt.d.dpr = float(m_window->devicePixelRatio()); rt.d.sampleCount = qBound(1, m_sampleCount, 64); rt.d.colorAttCount = 1; rt.d.dsAttCount = m_depthStencil ? 1 : 0; diff --git a/src/gui/rhi/qrhimetal.mm b/src/gui/rhi/qrhimetal.mm index a14ffa7173..3bf95ad676 100644 --- a/src/gui/rhi/qrhimetal.mm +++ b/src/gui/rhi/qrhimetal.mm @@ -352,7 +352,8 @@ QRhiMetal::~QRhiMetal() delete d; } -static inline uint aligned(uint v, uint byteAlign) +template +inline Int aligned(Int v, Int byteAlign) { return (v + byteAlign - 1) & ~(byteAlign - 1); } @@ -655,7 +656,7 @@ void QRhiMetal::enqueueShaderResourceBindings(QMetalShaderResourceBindings *srbD { QMetalBuffer *bufD = QRHI_RES(QMetalBuffer, b->u.ubuf.buf); id mtlbuf = bufD->d->buf[bufD->d->slotted ? currentFrameSlot : 0]; - uint offset = b->u.ubuf.offset; + uint offset = uint(b->u.ubuf.offset); for (int i = 0; i < dynamicOffsetCount; ++i) { const QRhiCommandBuffer::DynamicOffset &dynOfs(dynamicOffsets[i]); if (dynOfs.first == b->binding) { @@ -719,7 +720,7 @@ void QRhiMetal::enqueueShaderResourceBindings(QMetalShaderResourceBindings *srbD { QMetalBuffer *bufD = QRHI_RES(QMetalBuffer, b->u.sbuf.buf); id mtlbuf = bufD->d->buf[0]; - uint offset = b->u.sbuf.offset; + uint offset = uint(b->u.sbuf.offset); if (b->stage.testFlag(QRhiShaderResourceBinding::VertexStage)) { res[0].buffers.feed(b->binding, mtlbuf); res[0].bufferOffsets.feed(b->binding, offset); @@ -751,17 +752,17 @@ void QRhiMetal::enqueueShaderResourceBindings(QMetalShaderResourceBindings *srbD case 0: [cbD->d->currentRenderPassEncoder setVertexBuffers: bufferBatch.resources.constData() offsets: offsetBatch.resources.constData() - withRange: NSMakeRange(bufferBatch.startBinding, bufferBatch.resources.count())]; + withRange: NSMakeRange(bufferBatch.startBinding, NSUInteger(bufferBatch.resources.count()))]; break; case 1: [cbD->d->currentRenderPassEncoder setFragmentBuffers: bufferBatch.resources.constData() offsets: offsetBatch.resources.constData() - withRange: NSMakeRange(bufferBatch.startBinding, bufferBatch.resources.count())]; + withRange: NSMakeRange(bufferBatch.startBinding, NSUInteger(bufferBatch.resources.count()))]; break; case 2: [cbD->d->currentComputePassEncoder setBuffers: bufferBatch.resources.constData() offsets: offsetBatch.resources.constData() - withRange: NSMakeRange(bufferBatch.startBinding, bufferBatch.resources.count())]; + withRange: NSMakeRange(bufferBatch.startBinding, NSUInteger(bufferBatch.resources.count()))]; break; default: Q_UNREACHABLE(); @@ -780,15 +781,15 @@ void QRhiMetal::enqueueShaderResourceBindings(QMetalShaderResourceBindings *srbD switch (idx) { case 0: [cbD->d->currentRenderPassEncoder setVertexTextures: batch.resources.constData() - withRange: NSMakeRange(batch.startBinding, batch.resources.count())]; + withRange: NSMakeRange(batch.startBinding, NSUInteger(batch.resources.count()))]; break; case 1: [cbD->d->currentRenderPassEncoder setFragmentTextures: batch.resources.constData() - withRange: NSMakeRange(batch.startBinding, batch.resources.count())]; + withRange: NSMakeRange(batch.startBinding, NSUInteger(batch.resources.count()))]; break; case 2: [cbD->d->currentComputePassEncoder setTextures: batch.resources.constData() - withRange: NSMakeRange(batch.startBinding, batch.resources.count())]; + withRange: NSMakeRange(batch.startBinding, NSUInteger(batch.resources.count()))]; break; default: Q_UNREACHABLE(); @@ -800,15 +801,15 @@ void QRhiMetal::enqueueShaderResourceBindings(QMetalShaderResourceBindings *srbD switch (idx) { case 0: [cbD->d->currentRenderPassEncoder setVertexSamplerStates: batch.resources.constData() - withRange: NSMakeRange(batch.startBinding, batch.resources.count())]; + withRange: NSMakeRange(batch.startBinding, NSUInteger(batch.resources.count()))]; break; case 1: [cbD->d->currentRenderPassEncoder setFragmentSamplerStates: batch.resources.constData() - withRange: NSMakeRange(batch.startBinding, batch.resources.count())]; + withRange: NSMakeRange(batch.startBinding, NSUInteger(batch.resources.count()))]; break; case 2: [cbD->d->currentComputePassEncoder setSamplerStates: batch.resources.constData() - withRange: NSMakeRange(batch.startBinding, batch.resources.count())]; + withRange: NSMakeRange(batch.startBinding, NSUInteger(batch.resources.count()))]; break; default: Q_UNREACHABLE(); @@ -1006,7 +1007,7 @@ void QRhiMetal::setVertexInput(QRhiCommandBuffer *cb, [cbD->d->currentRenderPassEncoder setVertexBuffers: bufferBatch.resources.constData() offsets: offsetBatch.resources.constData() - withRange: NSMakeRange(firstVertexBinding + bufferBatch.startBinding, bufferBatch.resources.count())]; + withRange: NSMakeRange(uint(firstVertexBinding) + bufferBatch.startBinding, NSUInteger(bufferBatch.resources.count()))]; } } @@ -1067,21 +1068,21 @@ void QRhiMetal::setViewport(QRhiCommandBuffer *cb, const QRhiViewport &viewport) return; MTLViewport vp; - vp.originX = x; - vp.originY = y; - vp.width = w; - vp.height = h; - vp.znear = viewport.minDepth(); - vp.zfar = viewport.maxDepth(); + vp.originX = double(x); + vp.originY = double(y); + vp.width = double(w); + vp.height = double(h); + vp.znear = double(viewport.minDepth()); + vp.zfar = double(viewport.maxDepth()); [cbD->d->currentRenderPassEncoder setViewport: vp]; if (!QRHI_RES(QMetalGraphicsPipeline, cbD->currentGraphicsPipeline)->m_flags.testFlag(QRhiGraphicsPipeline::UsesScissor)) { MTLScissorRect s; - s.x = x; - s.y = y; - s.width = w; - s.height = h; + s.x = NSUInteger(x); + s.y = NSUInteger(y); + s.width = NSUInteger(w); + s.height = NSUInteger(h); [cbD->d->currentRenderPassEncoder setScissorRect: s]; } } @@ -1099,10 +1100,10 @@ void QRhiMetal::setScissor(QRhiCommandBuffer *cb, const QRhiScissor &scissor) return; MTLScissorRect s; - s.x = x; - s.y = y; - s.width = w; - s.height = h; + s.x = NSUInteger(x); + s.y = NSUInteger(y); + s.width = NSUInteger(w); + s.height = NSUInteger(h); [cbD->d->currentRenderPassEncoder setScissorRect: s]; } @@ -1112,7 +1113,8 @@ void QRhiMetal::setBlendConstants(QRhiCommandBuffer *cb, const QColor &c) QMetalCommandBuffer *cbD = QRHI_RES(QMetalCommandBuffer, cb); Q_ASSERT(cbD->recordingPass == QMetalCommandBuffer::RenderPass); - [cbD->d->currentRenderPassEncoder setBlendColorRed: c.redF() green: c.greenF() blue: c.blueF() alpha: c.alphaF()]; + [cbD->d->currentRenderPassEncoder setBlendColorRed: float(c.redF()) + green: float(c.greenF()) blue: float(c.blueF()) alpha: float(c.alphaF())]; } void QRhiMetal::setStencilRef(QRhiCommandBuffer *cb, quint32 refValue) @@ -1144,7 +1146,7 @@ void QRhiMetal::drawIndexed(QRhiCommandBuffer *cb, quint32 indexCount, return; const quint32 indexOffset = cbD->currentIndexOffset + firstIndex * (cbD->currentIndexFormat == QRhiCommandBuffer::IndexUInt16 ? 2 : 4); - Q_ASSERT(indexOffset == aligned(indexOffset, 4)); + Q_ASSERT(indexOffset == aligned(indexOffset, 4)); QMetalBuffer *ibufD = QRHI_RES(QMetalBuffer, cbD->currentIndexBuffer); id mtlbuf = ibufD->d->buf[ibufD->d->slotted ? currentFrameSlot : 0]; @@ -1402,7 +1404,7 @@ MTLRenderPassDescriptor *QRhiMetalData::createDefaultRenderPass(bool hasDepthSte MTLClearColor c = MTLClearColorMake(colorClearValue.redF(), colorClearValue.greenF(), colorClearValue.blueF(), colorClearValue.alphaF()); - for (int i = 0; i < colorAttCount; ++i) { + for (uint i = 0; i < uint(colorAttCount); ++i) { rp.colorAttachments[i].loadAction = MTLLoadActionClear; rp.colorAttachments[i].storeAction = MTLStoreActionStore; rp.colorAttachments[i].clearColor = c; @@ -1413,7 +1415,7 @@ MTLRenderPassDescriptor *QRhiMetalData::createDefaultRenderPass(bool hasDepthSte rp.depthAttachment.storeAction = MTLStoreActionDontCare; rp.stencilAttachment.loadAction = MTLLoadActionClear; rp.stencilAttachment.storeAction = MTLStoreActionDontCare; - rp.depthAttachment.clearDepth = depthStencilClearValue.depthClearValue(); + rp.depthAttachment.clearDepth = double(depthStencilClearValue.depthClearValue()); rp.stencilAttachment.clearStencil = depthStencilClearValue.stencilClearValue(); } @@ -1426,7 +1428,7 @@ qsizetype QRhiMetal::subresUploadByteSize(const QRhiTextureSubresourceUploadDesc const qsizetype imageSizeBytes = subresDesc.image().isNull() ? subresDesc.data().size() : subresDesc.image().sizeInBytes(); if (imageSizeBytes > 0) - size += aligned(imageSizeBytes, QRhiMetalData::TEXBUF_ALIGN); + size += aligned(imageSizeBytes, QRhiMetalData::TEXBUF_ALIGN); return size; } @@ -1454,31 +1456,31 @@ void QRhiMetal::enqueueSubresUpload(QMetalTexture *texD, void *mp, void *blitEnc h = subresDesc.sourceSize().height(); } if (img.depth() == 32) { - memcpy(reinterpret_cast(mp) + *curOfs, img.constBits(), fullImageSizeBytes); + memcpy(reinterpret_cast(mp) + *curOfs, img.constBits(), size_t(fullImageSizeBytes)); srcOffset = sy * bpl + sx * 4; // bpl remains set to the original image's row stride } else { img = img.copy(sx, sy, w, h); bpl = img.bytesPerLine(); Q_ASSERT(img.sizeInBytes() <= fullImageSizeBytes); - memcpy(reinterpret_cast(mp) + *curOfs, img.constBits(), img.sizeInBytes()); + memcpy(reinterpret_cast(mp) + *curOfs, img.constBits(), size_t(img.sizeInBytes())); } } else { - memcpy(reinterpret_cast(mp) + *curOfs, img.constBits(), fullImageSizeBytes); + memcpy(reinterpret_cast(mp) + *curOfs, img.constBits(), size_t(fullImageSizeBytes)); } [blitEnc copyFromBuffer: texD->d->stagingBuf[currentFrameSlot] - sourceOffset: *curOfs + srcOffset - sourceBytesPerRow: bpl + sourceOffset: NSUInteger(*curOfs + srcOffset) + sourceBytesPerRow: NSUInteger(bpl) sourceBytesPerImage: 0 - sourceSize: MTLSizeMake(w, h, 1) + sourceSize: MTLSizeMake(NSUInteger(w), NSUInteger(h), 1) toTexture: texD->d->tex - destinationSlice: layer - destinationLevel: level - destinationOrigin: MTLOriginMake(dp.x(), dp.y(), 0) + destinationSlice: NSUInteger(layer) + destinationLevel: NSUInteger(level) + destinationOrigin: MTLOriginMake(NSUInteger(dp.x()), NSUInteger(dp.y()), 0) options: MTLBlitOptionNone]; - *curOfs += aligned(fullImageSizeBytes, QRhiMetalData::TEXBUF_ALIGN); + *curOfs += aligned(fullImageSizeBytes, QRhiMetalData::TEXBUF_ALIGN); } else if (!rawData.isEmpty() && isCompressedFormat(texD->m_format)) { const QSize subresSize = q->sizeForMipLevel(level, texD->m_pixelSize); const int subresw = subresSize.width(); @@ -1503,17 +1505,17 @@ void QRhiMetal::enqueueSubresUpload(QMetalTexture *texD, void *mp, void *blitEnc if (dy + h != subresh) h = aligned(h, blockDim.height()); - memcpy(reinterpret_cast(mp) + *curOfs, rawData.constData(), rawData.size()); + memcpy(reinterpret_cast(mp) + *curOfs, rawData.constData(), size_t(rawData.size())); [blitEnc copyFromBuffer: texD->d->stagingBuf[currentFrameSlot] - sourceOffset: *curOfs + sourceOffset: NSUInteger(*curOfs) sourceBytesPerRow: bpl sourceBytesPerImage: 0 - sourceSize: MTLSizeMake(w, h, 1) + sourceSize: MTLSizeMake(NSUInteger(w), NSUInteger(h), 1) toTexture: texD->d->tex - destinationSlice: layer - destinationLevel: level - destinationOrigin: MTLOriginMake(dx, dy, 0) + destinationSlice: NSUInteger(layer) + destinationLevel: NSUInteger(level) + destinationOrigin: MTLOriginMake(NSUInteger(dx), NSUInteger(dy), 0) options: MTLBlitOptionNone]; *curOfs += aligned(rawData.size(), QRhiMetalData::TEXBUF_ALIGN); @@ -1532,17 +1534,17 @@ void QRhiMetal::enqueueSubresUpload(QMetalTexture *texD, void *mp, void *blitEnc quint32 bpl = 0; textureFormatInfo(texD->m_format, QSize(w, h), &bpl, nullptr); - memcpy(reinterpret_cast(mp) + *curOfs, rawData.constData(), rawData.size()); + memcpy(reinterpret_cast(mp) + *curOfs, rawData.constData(), size_t(rawData.size())); [blitEnc copyFromBuffer: texD->d->stagingBuf[currentFrameSlot] - sourceOffset: *curOfs + sourceOffset: NSUInteger(*curOfs) sourceBytesPerRow: bpl sourceBytesPerImage: 0 - sourceSize: MTLSizeMake(w, h, 1) + sourceSize: MTLSizeMake(NSUInteger(w), NSUInteger(h), 1) toTexture: texD->d->tex - destinationSlice: layer - destinationLevel: level - destinationOrigin: MTLOriginMake(dp.x(), dp.y(), 0) + destinationSlice: NSUInteger(layer) + destinationLevel: NSUInteger(level) + destinationOrigin: MTLOriginMake(NSUInteger(dp.x()), NSUInteger(dp.y()), 0) options: MTLBlitOptionNone]; *curOfs += aligned(rawData.size(), QRhiMetalData::TEXBUF_ALIGN); @@ -1596,9 +1598,9 @@ void QRhiMetal::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate ensureBlit(); Q_ASSERT(!utexD->d->stagingBuf[currentFrameSlot]); - utexD->d->stagingBuf[currentFrameSlot] = [d->dev newBufferWithLength: stagingSize + utexD->d->stagingBuf[currentFrameSlot] = [d->dev newBufferWithLength: NSUInteger(stagingSize) options: MTLResourceStorageModeShared]; - QRHI_PROF_F(newTextureStagingArea(utexD, currentFrameSlot, stagingSize)); + QRHI_PROF_F(newTextureStagingArea(utexD, currentFrameSlot, quint32(stagingSize))); void *mp = [utexD->d->stagingBuf[currentFrameSlot] contents]; qsizetype curOfs = 0; @@ -1628,14 +1630,14 @@ void QRhiMetal::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate ensureBlit(); [blitEnc copyFromTexture: srcD->d->tex - sourceSlice: u.copy.desc.sourceLayer() - sourceLevel: u.copy.desc.sourceLevel() - sourceOrigin: MTLOriginMake(sp.x(), sp.y(), 0) - sourceSize: MTLSizeMake(size.width(), size.height(), 1) + sourceSlice: NSUInteger(u.copy.desc.sourceLayer()) + sourceLevel: NSUInteger(u.copy.desc.sourceLevel()) + sourceOrigin: MTLOriginMake(NSUInteger(sp.x()), NSUInteger(sp.y()), 0) + sourceSize: MTLSizeMake(NSUInteger(size.width()), NSUInteger(size.height()), 1) toTexture: dstD->d->tex - destinationSlice: u.copy.desc.destinationLayer() - destinationLevel: u.copy.desc.destinationLevel() - destinationOrigin: MTLOriginMake(dp.x(), dp.y(), 0)]; + destinationSlice: NSUInteger(u.copy.desc.destinationLayer()) + destinationLevel: NSUInteger(u.copy.desc.destinationLevel()) + destinationOrigin: MTLOriginMake(NSUInteger(dp.x()), NSUInteger(dp.y()), 0)]; srcD->lastActiveFrameSlot = dstD->lastActiveFrameSlot = currentFrameSlot; } else if (u.type == QRhiResourceUpdateBatchPrivate::TextureOp::Read) { @@ -1675,16 +1677,16 @@ void QRhiMetal::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate textureFormatInfo(aRb.format, aRb.pixelSize, &bpl, &aRb.bufSize); aRb.buf = [d->dev newBufferWithLength: aRb.bufSize options: MTLResourceStorageModeShared]; - QRHI_PROF_F(newReadbackBuffer(quint64(quintptr(aRb.buf)), + QRHI_PROF_F(newReadbackBuffer(qint64(qintptr(aRb.buf)), texD ? static_cast(texD) : static_cast(swapChainD), aRb.bufSize)); ensureBlit(); [blitEnc copyFromTexture: src - sourceSlice: u.read.rb.layer() - sourceLevel: u.read.rb.level() + sourceSlice: NSUInteger(u.read.rb.layer()) + sourceLevel: NSUInteger(u.read.rb.level()) sourceOrigin: MTLOriginMake(0, 0, 0) - sourceSize: MTLSizeMake(srcSize.width(), srcSize.height(), 1) + sourceSize: MTLSizeMake(NSUInteger(srcSize.width()), NSUInteger(srcSize.height()), 1) toBuffer: aRb.buf destinationOffset: 0 destinationBytesPerRow: bpl @@ -1722,14 +1724,14 @@ void QRhiMetal::executeBufferHostWritesForCurrentFrame(QMetalBuffer *bufD) int changeEnd = -1; for (const QRhiResourceUpdateBatchPrivate::DynamicBufferUpdate &u : updates) { Q_ASSERT(bufD == QRHI_RES(QMetalBuffer, u.buf)); - memcpy(static_cast(p) + u.offset, u.data.constData(), u.data.size()); + memcpy(static_cast(p) + u.offset, u.data.constData(), size_t(u.data.size())); if (changeBegin == -1 || u.offset < changeBegin) changeBegin = u.offset; if (changeEnd == -1 || u.offset + u.data.size() > changeEnd) changeEnd = u.offset + u.data.size(); } if (changeBegin >= 0 && bufD->d->managed) - [bufD->d->buf[idx] didModifyRange: NSMakeRange(changeBegin, changeEnd - changeBegin)]; + [bufD->d->buf[idx] didModifyRange: NSMakeRange(NSUInteger(changeBegin), NSUInteger(changeEnd - changeBegin))]; updates.clear(); } @@ -1786,7 +1788,7 @@ void QRhiMetal::beginPass(QRhiCommandBuffer *cb, rtD = rtTex->d; cbD->d->currentPassRpDesc = d->createDefaultRenderPass(rtD->dsAttCount, colorClearValue, depthStencilClearValue, rtD->colorAttCount); if (rtTex->m_flags.testFlag(QRhiTextureRenderTarget::PreserveColorContents)) { - for (int i = 0; i < rtD->colorAttCount; ++i) + for (uint i = 0; i < uint(rtD->colorAttCount); ++i) cbD->d->currentPassRpDesc.colorAttachments[i].loadAction = MTLLoadActionLoad; } if (rtD->dsAttCount && rtTex->m_flags.testFlag(QRhiTextureRenderTarget::PreserveDepthStencilContents)) { @@ -1813,15 +1815,15 @@ void QRhiMetal::beginPass(QRhiCommandBuffer *cb, break; } - for (int i = 0; i < rtD->colorAttCount; ++i) { + for (uint i = 0; i < uint(rtD->colorAttCount); ++i) { cbD->d->currentPassRpDesc.colorAttachments[i].texture = rtD->fb.colorAtt[i].tex; - cbD->d->currentPassRpDesc.colorAttachments[i].slice = rtD->fb.colorAtt[i].layer; - cbD->d->currentPassRpDesc.colorAttachments[i].level = rtD->fb.colorAtt[i].level; + cbD->d->currentPassRpDesc.colorAttachments[i].slice = NSUInteger(rtD->fb.colorAtt[i].layer); + cbD->d->currentPassRpDesc.colorAttachments[i].level = NSUInteger(rtD->fb.colorAtt[i].level); if (rtD->fb.colorAtt[i].resolveTex) { cbD->d->currentPassRpDesc.colorAttachments[i].storeAction = MTLStoreActionMultisampleResolve; cbD->d->currentPassRpDesc.colorAttachments[i].resolveTexture = rtD->fb.colorAtt[i].resolveTex; - cbD->d->currentPassRpDesc.colorAttachments[i].resolveSlice = rtD->fb.colorAtt[i].resolveLayer; - cbD->d->currentPassRpDesc.colorAttachments[i].resolveLevel = rtD->fb.colorAtt[i].resolveLevel; + cbD->d->currentPassRpDesc.colorAttachments[i].resolveSlice = NSUInteger(rtD->fb.colorAtt[i].resolveLayer); + cbD->d->currentPassRpDesc.colorAttachments[i].resolveLevel = NSUInteger(rtD->fb.colorAtt[i].resolveLevel); } } @@ -1903,7 +1905,7 @@ void QRhiMetal::dispatch(QRhiCommandBuffer *cb, int x, int y, int z) Q_ASSERT(cbD->recordingPass == QMetalCommandBuffer::ComputePass); QMetalComputePipeline *psD = QRHI_RES(QMetalComputePipeline, cbD->currentComputePipeline); - [cbD->d->currentComputePassEncoder dispatchThreadgroups: MTLSizeMake(x, y, z) + [cbD->d->currentComputePassEncoder dispatchThreadgroups: MTLSizeMake(NSUInteger(x), NSUInteger(y), NSUInteger(z)) threadsPerThreadgroup: psD->d->localSize]; } @@ -1971,12 +1973,12 @@ void QRhiMetal::finishActiveReadbacks(bool forced) if (forced || currentFrameSlot == aRb.activeFrameSlot || aRb.activeFrameSlot < 0) { aRb.result->format = aRb.format; aRb.result->pixelSize = aRb.pixelSize; - aRb.result->data.resize(aRb.bufSize); + aRb.result->data.resize(int(aRb.bufSize)); void *p = [aRb.buf contents]; memcpy(aRb.result->data.data(), p, aRb.bufSize); [aRb.buf release]; - QRHI_PROF_F(releaseReadbackBuffer(quint64(quintptr(aRb.buf)))); + QRHI_PROF_F(releaseReadbackBuffer(qint64(qintptr(aRb.buf)))); if (aRb.result->completed) completedCallbacks.append(aRb.result->completed); @@ -2035,8 +2037,8 @@ bool QMetalBuffer::build() return false; } - const int nonZeroSize = m_size <= 0 ? 256 : m_size; - const int roundedSize = m_usage.testFlag(QRhiBuffer::UniformBuffer) ? aligned(nonZeroSize, 256) : nonZeroSize; + const uint nonZeroSize = m_size <= 0 ? 256 : uint(m_size); + const uint roundedSize = m_usage.testFlag(QRhiBuffer::UniformBuffer) ? aligned(nonZeroSize, 256) : nonZeroSize; d->managed = false; MTLResourceOptions opts = MTLResourceStorageModeShared; @@ -2123,10 +2125,10 @@ bool QMetalRenderBuffer::build() MTLTextureDescriptor *desc = [[MTLTextureDescriptor alloc] init]; desc.textureType = samples > 1 ? MTLTextureType2DMultisample : MTLTextureType2D; - desc.width = m_pixelSize.width(); - desc.height = m_pixelSize.height(); + desc.width = NSUInteger(m_pixelSize.width()); + desc.height = NSUInteger(m_pixelSize.height()); if (samples > 1) - desc.sampleCount = samples; + desc.sampleCount = NSUInteger(samples); desc.resourceOptions = MTLResourceStorageModePrivate; desc.usage = MTLTextureUsageRenderTarget; @@ -2393,11 +2395,11 @@ bool QMetalTexture::build() else desc.textureType = samples > 1 ? MTLTextureType2DMultisample : MTLTextureType2D; desc.pixelFormat = d->format; - desc.width = size.width(); - desc.height = size.height(); - desc.mipmapLevelCount = mipLevelCount; + desc.width = NSUInteger(size.width()); + desc.height = NSUInteger(size.height()); + desc.mipmapLevelCount = NSUInteger(mipLevelCount); if (samples > 1) - desc.sampleCount = samples; + desc.sampleCount = NSUInteger(samples); desc.resourceOptions = MTLResourceStorageModePrivate; desc.storageMode = MTLStorageModePrivate; desc.usage = MTLTextureUsageShaderRead; @@ -2463,7 +2465,7 @@ id QMetalTextureData::viewForLevel(int level) const MTLTextureType type = [tex textureType]; const bool isCube = q->m_flags.testFlag(QRhiTexture::CubeMap); id view = [tex newTextureViewWithPixelFormat: format textureType: type - levels: NSMakeRange(level, 1) slices: NSMakeRange(0, isCube ? 6 : 1)]; + levels: NSMakeRange(NSUInteger(level), 1) slices: NSMakeRange(0, isCube ? 6 : 1)]; perLevelViews[level] = view; return view; @@ -2673,13 +2675,13 @@ QRhiRenderPassDescriptor *QMetalTextureRenderTarget::newCompatibleRenderPassDesc for (int i = 0, ie = colorAttachments.count(); i != ie; ++i) { QMetalTexture *texD = QRHI_RES(QMetalTexture, colorAttachments[i].texture()); QMetalRenderBuffer *rbD = QRHI_RES(QMetalRenderBuffer, colorAttachments[i].renderBuffer()); - rpD->colorFormat[i] = texD ? texD->d->format : rbD->d->format; + rpD->colorFormat[i] = int(texD ? texD->d->format : rbD->d->format); } if (m_desc.depthTexture()) - rpD->dsFormat = QRHI_RES(QMetalTexture, m_desc.depthTexture())->d->format; + rpD->dsFormat = int(QRHI_RES(QMetalTexture, m_desc.depthTexture())->d->format); else if (m_desc.depthStencilBuffer()) - rpD->dsFormat = QRHI_RES(QMetalRenderBuffer, m_desc.depthStencilBuffer())->d->format; + rpD->dsFormat = int(QRHI_RES(QMetalRenderBuffer, m_desc.depthStencilBuffer())->d->format); return rpD; } @@ -3079,7 +3081,7 @@ id QRhiMetalData::createMetalLib(const QShader &shader, QShader::Var QShaderCode mtllib = shader.shader({ QShader::MetalLibShader, 12, shaderVariant }); if (!mtllib.shader().isEmpty()) { dispatch_data_t data = dispatch_data_create(mtllib.shader().constData(), - mtllib.shader().size(), + size_t(mtllib.shader().size()), dispatch_get_global_queue(0, 0), DISPATCH_DATA_DESTRUCTOR_DEFAULT); NSError *err = nil; @@ -3139,19 +3141,19 @@ bool QMetalGraphicsPipeline::build() MTLVertexDescriptor *inputLayout = [MTLVertexDescriptor vertexDescriptor]; const QVector attributes = m_vertexInputLayout.attributes(); for (const QRhiVertexInputAttribute &attribute : attributes) { - const int loc = attribute.location(); + const uint loc = uint(attribute.location()); inputLayout.attributes[loc].format = toMetalAttributeFormat(attribute.format()); - inputLayout.attributes[loc].offset = attribute.offset(); - inputLayout.attributes[loc].bufferIndex = firstVertexBinding + attribute.binding(); + inputLayout.attributes[loc].offset = NSUInteger(attribute.offset()); + inputLayout.attributes[loc].bufferIndex = NSUInteger(firstVertexBinding + attribute.binding()); } const QVector bindings = m_vertexInputLayout.bindings(); for (int i = 0, ie = bindings.count(); i != ie; ++i) { const QRhiVertexInputBinding &binding(bindings[i]); - const int layoutIdx = firstVertexBinding + i; + const uint layoutIdx = uint(firstVertexBinding + i); inputLayout.layouts[layoutIdx].stepFunction = binding.classification() == QRhiVertexInputBinding::PerInstance ? MTLVertexStepFunctionPerInstance : MTLVertexStepFunctionPerVertex; - inputLayout.layouts[layoutIdx].stepRate = binding.instanceStepRate(); + inputLayout.layouts[layoutIdx].stepRate = NSUInteger(binding.instanceStepRate()); inputLayout.layouts[layoutIdx].stride = binding.stride(); } @@ -3239,8 +3241,8 @@ bool QMetalGraphicsPipeline::build() Q_ASSERT(m_targetBlends.count() == rpD->colorAttachmentCount || (m_targetBlends.isEmpty() && rpD->colorAttachmentCount == 1)); - for (int i = 0, ie = m_targetBlends.count(); i != ie; ++i) { - const QRhiGraphicsPipeline::TargetBlend &b(m_targetBlends[i]); + for (uint i = 0, ie = uint(m_targetBlends.count()); i != ie; ++i) { + const QRhiGraphicsPipeline::TargetBlend &b(m_targetBlends[int(i)]); rpDesc.colorAttachments[i].pixelFormat = MTLPixelFormat(rpD->colorFormat[i]); rpDesc.colorAttachments[i].blendingEnabled = b.enable; rpDesc.colorAttachments[i].sourceRGBBlendFactor = toMetalBlendFactor(b.srcColor); @@ -3262,7 +3264,7 @@ bool QMetalGraphicsPipeline::build() rpDesc.stencilAttachmentPixelFormat = fmt; } - rpDesc.sampleCount = rhiD->effectiveSampleCount(m_sampleCount); + rpDesc.sampleCount = NSUInteger(rhiD->effectiveSampleCount(m_sampleCount)); NSError *err = nil; d->ps = [rhiD->d->dev newRenderPipelineStateWithDescriptor: rpDesc error: &err]; @@ -3517,7 +3519,7 @@ QSize QMetalSwapChain::surfacePixelSize() CAMetalLayer *layer = (CAMetalLayer *) [v layer]; if (layer) { CGSize size = [layer drawableSize]; - return QSize(size.width, size.height); + return QSize(int(size.width), int(size.height)); } } return QSize(); @@ -3532,7 +3534,7 @@ QRhiRenderPassDescriptor *QMetalSwapChain::newCompatibleRenderPassDescriptor() rpD->colorAttachmentCount = 1; rpD->hasDepthStencil = m_depthStencil != nullptr; - rpD->colorFormat[0] = d->colorFormat; + rpD->colorFormat[0] = int(d->colorFormat); // m_depthStencil may not be built yet so cannot rely on computed fields in it rpD->dsFormat = rhiD->d->dev.depth24Stencil8PixelFormatSupported @@ -3616,7 +3618,7 @@ bool QMetalSwapChain::buildOrResize() } rtWrapper.d->pixelSize = pixelSize; - rtWrapper.d->dpr = window->devicePixelRatio(); + rtWrapper.d->dpr = float(window->devicePixelRatio()); rtWrapper.d->sampleCount = samples; rtWrapper.d->colorAttCount = 1; rtWrapper.d->dsAttCount = ds ? 1 : 0; @@ -3627,9 +3629,9 @@ bool QMetalSwapChain::buildOrResize() MTLTextureDescriptor *desc = [[MTLTextureDescriptor alloc] init]; desc.textureType = MTLTextureType2DMultisample; desc.pixelFormat = d->colorFormat; - desc.width = pixelSize.width(); - desc.height = pixelSize.height(); - desc.sampleCount = samples; + desc.width = NSUInteger(pixelSize.width()); + desc.height = NSUInteger(pixelSize.height()); + desc.sampleCount = NSUInteger(samples); desc.resourceOptions = MTLResourceStorageModePrivate; desc.storageMode = MTLStorageModePrivate; desc.usage = MTLTextureUsageRenderTarget; diff --git a/src/gui/rhi/qrhiprofiler.cpp b/src/gui/rhi/qrhiprofiler.cpp index e74e446a1c..1521c0f36e 100644 --- a/src/gui/rhi/qrhiprofiler.cpp +++ b/src/gui/rhi/qrhiprofiler.cpp @@ -319,7 +319,7 @@ void QRhiProfilerPrivate::writeFloat(const char *key, float f) Q_ASSERT(key[0] == 'F'); buf.append(key); buf.append(','); - buf.append(QByteArray::number(f)); + buf.append(QByteArray::number(double(f))); buf.append(','); } @@ -385,7 +385,7 @@ void QRhiProfilerPrivate::newRenderBuffer(QRhiRenderBuffer *rb, bool transientBa const QRhiTexture::Format assumedFormat = type == QRhiRenderBuffer::DepthStencil ? QRhiTexture::D32F : QRhiTexture::RGBA8; quint32 byteSize = rhiDWhenEnabled->approxByteSizeForTexture(assumedFormat, sz, 1, 1); if (sampleCount > 1) - byteSize *= sampleCount; + byteSize *= uint(sampleCount); startEntry(QRhiProfiler::NewRenderBuffer, ts.elapsed(), rb); writeInt("type", type); @@ -416,7 +416,7 @@ void QRhiProfilerPrivate::newTexture(QRhiTexture *tex, bool owns, int mipCount, const QSize sz = tex->pixelSize(); quint32 byteSize = rhiDWhenEnabled->approxByteSizeForTexture(format, sz, mipCount, layerCount); if (sampleCount > 1) - byteSize *= sampleCount; + byteSize *= uint(sampleCount); startEntry(QRhiProfiler::NewTexture, ts.elapsed(), tex); writeInt("width", sz.width()); @@ -467,7 +467,7 @@ void QRhiProfilerPrivate::resizeSwapChain(QRhiSwapChain *sc, int bufferCount, in const QSize sz = sc->currentPixelSize(); quint32 byteSize = rhiDWhenEnabled->approxByteSizeForTexture(QRhiTexture::BGRA8, sz, 1, 1); - byteSize = byteSize * bufferCount + byteSize * msaaBufferCount * sampleCount; + byteSize = byteSize * uint(bufferCount) + byteSize * uint(msaaBufferCount) * uint(sampleCount); startEntry(QRhiProfiler::ResizeSwapChain, ts.elapsed(), sc); writeInt("width", sz.width()); @@ -569,7 +569,7 @@ void QRhiProfilerPrivate::swapChainFrameGpuTime(QRhiSwapChain *sc, float gpuTime } } -void QRhiProfilerPrivate::newReadbackBuffer(quint64 id, QRhiResource *src, quint32 size) +void QRhiProfilerPrivate::newReadbackBuffer(qint64 id, QRhiResource *src, quint32 size) { if (!outputDevice) return; @@ -580,7 +580,7 @@ void QRhiProfilerPrivate::newReadbackBuffer(quint64 id, QRhiResource *src, quint endEntry(); } -void QRhiProfilerPrivate::releaseReadbackBuffer(quint64 id) +void QRhiProfilerPrivate::releaseReadbackBuffer(qint64 id) { if (!outputDevice) return; @@ -590,7 +590,7 @@ void QRhiProfilerPrivate::releaseReadbackBuffer(quint64 id) endEntry(); } -void QRhiProfilerPrivate::vmemStat(int realAllocCount, int subAllocCount, quint32 totalSize, quint32 unusedSize) +void QRhiProfilerPrivate::vmemStat(uint realAllocCount, uint subAllocCount, quint32 totalSize, quint32 unusedSize) { if (!outputDevice) return; diff --git a/src/gui/rhi/qrhiprofiler_p_p.h b/src/gui/rhi/qrhiprofiler_p_p.h index 49c6bd78ed..7d0f183fb1 100644 --- a/src/gui/rhi/qrhiprofiler_p_p.h +++ b/src/gui/rhi/qrhiprofiler_p_p.h @@ -79,10 +79,10 @@ public: void endSwapChainFrame(QRhiSwapChain *sc, int frameCount); void swapChainFrameGpuTime(QRhiSwapChain *sc, float gpuTimeMs); - void newReadbackBuffer(quint64 id, QRhiResource *src, quint32 size); - void releaseReadbackBuffer(quint64 id); + void newReadbackBuffer(qint64 id, QRhiResource *src, quint32 size); + void releaseReadbackBuffer(qint64 id); - void vmemStat(int realAllocCount, int subAllocCount, quint32 totalSize, quint32 unusedSize); + void vmemStat(uint realAllocCount, uint subAllocCount, quint32 totalSize, quint32 unusedSize); void startEntry(QRhiProfiler::StreamOp op, qint64 timestamp, QRhiResource *res); void writeInt(const char *key, qint64 v); diff --git a/src/gui/rhi/qrhivulkan.cpp b/src/gui/rhi/qrhivulkan.cpp index 4f550c6a90..c4f298dafb 100644 --- a/src/gui/rhi/qrhivulkan.cpp +++ b/src/gui/rhi/qrhivulkan.cpp @@ -211,7 +211,8 @@ QT_BEGIN_NAMESPACE \brief Holds the Vulkan render pass object backing a QRhiRenderPassDescriptor. */ -static inline VkDeviceSize aligned(VkDeviceSize v, VkDeviceSize byteAlign) +template +inline Int aligned(Int v, Int byteAlign) { return (v + byteAlign - 1) & ~(byteAlign - 1); } @@ -370,7 +371,7 @@ bool QRhiVulkan::create(QRhi::Flags flags) auto queryQueueFamilyProps = [this, &queueFamilyProps] { uint32_t queueCount = 0; f->vkGetPhysicalDeviceQueueFamilyProperties(physDev, &queueCount, nullptr); - queueFamilyProps.resize(queueCount); + queueFamilyProps.resize(int(queueCount)); f->vkGetPhysicalDeviceQueueFamilyProperties(physDev, &queueCount, queueFamilyProps.data()); }; @@ -391,7 +392,7 @@ bool QRhiVulkan::create(QRhi::Flags flags) int requestedPhysDevIndex = -1; if (qEnvironmentVariableIsSet("QT_VK_PHYSICAL_DEVICE_INDEX")) requestedPhysDevIndex = qEnvironmentVariableIntValue("QT_VK_PHYSICAL_DEVICE_INDEX"); - for (uint32_t i = 0; i < physDevCount; ++i) { + for (int i = 0; i < int(physDevCount); ++i) { f->vkGetPhysicalDeviceProperties(physDevs[i], &physDevProperties); qCDebug(QRHI_LOG_INFO, "Physical device %d: '%s' %d.%d.%d", i, physDevProperties.deviceName, @@ -423,7 +424,7 @@ bool QRhiVulkan::create(QRhi::Flags flags) i, queueFamilyProps[i].queueFlags, queueFamilyProps[i].queueCount); if (gfxQueueFamilyIdx == -1 && (queueFamilyProps[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) - && (!maybeWindow || inst->supportsPresent(physDev, i, maybeWindow))) + && (!maybeWindow || inst->supportsPresent(physDev, uint32_t(i), maybeWindow))) { if (queueFamilyProps[i].queueFlags & VK_QUEUE_COMPUTE_BIT) gfxQueueFamilyIdx = i; @@ -444,7 +445,7 @@ bool QRhiVulkan::create(QRhi::Flags flags) const float prio[] = { 0 }; memset(queueInfo, 0, sizeof(queueInfo)); queueInfo[0].sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; - queueInfo[0].queueFamilyIndex = gfxQueueFamilyIdx; + queueInfo[0].queueFamilyIndex = uint32_t(gfxQueueFamilyIdx); queueInfo[0].queueCount = 1; queueInfo[0].pQueuePriorities = prio; @@ -480,9 +481,9 @@ bool QRhiVulkan::create(QRhi::Flags flags) devInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; devInfo.queueCreateInfoCount = 1; devInfo.pQueueCreateInfos = queueInfo; - devInfo.enabledLayerCount = devLayers.count(); + devInfo.enabledLayerCount = uint32_t(devLayers.count()); devInfo.ppEnabledLayerNames = devLayers.constData(); - devInfo.enabledExtensionCount = requestedDevExts.count(); + devInfo.enabledExtensionCount = uint32_t(requestedDevExts.count()); devInfo.ppEnabledExtensionNames = requestedDevExts.constData(); err = f->vkCreateDevice(physDev, &devInfo, nullptr, &dev); @@ -498,7 +499,7 @@ bool QRhiVulkan::create(QRhi::Flags flags) VkCommandPoolCreateInfo poolInfo; memset(&poolInfo, 0, sizeof(poolInfo)); poolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; - poolInfo.queueFamilyIndex = gfxQueueFamilyIdx; + poolInfo.queueFamilyIndex = uint32_t(gfxQueueFamilyIdx); VkResult err = df->vkCreateCommandPool(dev, &poolInfo, nullptr, &cmdPool); if (err != VK_SUCCESS) { qWarning("Failed to create command pool: %d", err); @@ -508,7 +509,7 @@ bool QRhiVulkan::create(QRhi::Flags flags) if (gfxQueueFamilyIdx != -1) { if (!gfxQueue) - df->vkGetDeviceQueue(dev, gfxQueueFamilyIdx, 0, &gfxQueue); + df->vkGetDeviceQueue(dev, uint32_t(gfxQueueFamilyIdx), 0, &gfxQueue); if (queueFamilyProps.isEmpty()) queryQueueFamilyProps(); @@ -691,7 +692,7 @@ bool QRhiVulkan::allocateDescriptorSet(VkDescriptorSetAllocateInfo *allocInfo, V df->vkResetDescriptorPool(dev, descriptorPools[i].pool, 0); descriptorPools[i].allocedDescSets = 0; } - if (descriptorPools[i].allocedDescSets + allocInfo->descriptorSetCount <= QVK_DESC_SETS_PER_POOL) { + if (descriptorPools[i].allocedDescSets + int(allocInfo->descriptorSetCount) <= QVK_DESC_SETS_PER_POOL) { VkResult err = tryAllocate(i); if (err == VK_SUCCESS) { descriptorPools[i].allocedDescSets += allocInfo->descriptorSetCount; @@ -901,8 +902,8 @@ bool QRhiVulkan::createTransientImage(VkFormat format, imgInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; imgInfo.imageType = VK_IMAGE_TYPE_2D; imgInfo.format = format; - imgInfo.extent.width = pixelSize.width(); - imgInfo.extent.height = pixelSize.height(); + imgInfo.extent.width = uint32_t(pixelSize.width()); + imgInfo.extent.height = uint32_t(pixelSize.height()); imgInfo.extent.depth = 1; imgInfo.mipLevels = imgInfo.arrayLayers = 1; imgInfo.samples = samples; @@ -925,7 +926,7 @@ bool QRhiVulkan::createTransientImage(VkFormat format, VkMemoryAllocateInfo memInfo; memset(&memInfo, 0, sizeof(memInfo)); memInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; - memInfo.allocationSize = aligned(memReq.size, memReq.alignment) * count; + memInfo.allocationSize = aligned(memReq.size, memReq.alignment) * VkDeviceSize(count); uint32_t startIndex = 0; do { @@ -1175,7 +1176,7 @@ bool QRhiVulkan::createOffscreenRenderPass(VkRenderPass *rp, VkSubpassDescription subpassDesc; memset(&subpassDesc, 0, sizeof(subpassDesc)); subpassDesc.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; - subpassDesc.colorAttachmentCount = colorRefs.count(); + subpassDesc.colorAttachmentCount = uint32_t(colorRefs.count()); Q_ASSERT(colorRefs.count() == resolveRefs.count()); subpassDesc.pColorAttachments = !colorRefs.isEmpty() ? colorRefs.constData() : nullptr; subpassDesc.pDepthStencilAttachment = hasDepthStencil ? &dsRef : nullptr; @@ -1184,7 +1185,7 @@ bool QRhiVulkan::createOffscreenRenderPass(VkRenderPass *rp, VkRenderPassCreateInfo rpInfo; memset(&rpInfo, 0, sizeof(rpInfo)); rpInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; - rpInfo.attachmentCount = attDescs.count(); + rpInfo.attachmentCount = uint32_t(attDescs.count()); rpInfo.pAttachments = attDescs.constData(); rpInfo.subpassCount = 1; rpInfo.pSubpasses = &subpassDesc; @@ -1325,7 +1326,7 @@ bool QRhiVulkan::recreateSwapChain(QRhiSwapChain *swapChain) } if (actualSwapChainBufferCount != reqBufferCount) qCDebug(QRHI_LOG_INFO, "Actual swapchain buffer count is %u", actualSwapChainBufferCount); - swapChainD->bufferCount = actualSwapChainBufferCount; + swapChainD->bufferCount = int(actualSwapChainBufferCount); VkImage swapChainImages[QVkSwapChain::MAX_BUFFER_COUNT]; err = vkGetSwapchainImagesKHR(dev, swapChainD->sc, &actualSwapChainBufferCount, swapChainImages); @@ -1540,12 +1541,12 @@ QRhi::FrameOpResult QRhiVulkan::beginFrame(QRhiSwapChain *swapChain, QRhi::Begin // will make B wait for A's frame 0 commands, so if a resource is written // in B's frame or when B checks for pending resource releases, that won't // mess up A's in-flight commands (as they are not in flight anymore). - waitCommandCompletion(swapChainD->currentFrameSlot); + waitCommandCompletion(int(swapChainD->currentFrameSlot)); // Now is the time to read the timestamps for the previous frame for this slot. if (frame.timestampQueryIndex >= 0) { quint64 timestamp[2] = { 0, 0 }; - VkResult err = df->vkGetQueryPoolResults(dev, timestampQueryPool, frame.timestampQueryIndex, 2, + VkResult err = df->vkGetQueryPoolResults(dev, timestampQueryPool, uint32_t(frame.timestampQueryIndex), 2, 2 * sizeof(quint64), timestamp, sizeof(quint64), VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WAIT_BIT); timestampQueryPoolMap.clearBit(frame.timestampQueryIndex / 2); @@ -1585,10 +1586,10 @@ QRhi::FrameOpResult QRhiVulkan::beginFrame(QRhiSwapChain *swapChain, QRhi::Begin } } if (timestampQueryIdx >= 0) { - df->vkCmdResetQueryPool(frame.cmdBuf, timestampQueryPool, timestampQueryIdx, 2); + df->vkCmdResetQueryPool(frame.cmdBuf, timestampQueryPool, uint32_t(timestampQueryIdx), 2); // record timestamp at the start of the command buffer df->vkCmdWriteTimestamp(frame.cmdBuf, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, - timestampQueryPool, timestampQueryIdx); + timestampQueryPool, uint32_t(timestampQueryIdx)); frame.timestampQueryIndex = timestampQueryIdx; } @@ -1598,7 +1599,7 @@ QRhi::FrameOpResult QRhiVulkan::beginFrame(QRhiSwapChain *swapChain, QRhi::Begin QVkSwapChain::ImageResources &image(swapChainD->imageRes[swapChainD->currentImageIndex]); swapChainD->rtWrapper.d.fb = image.fb; - currentFrameSlot = swapChainD->currentFrameSlot; + currentFrameSlot = int(swapChainD->currentFrameSlot); currentSwapChain = swapChainD; if (swapChainD->ds) swapChainD->ds->lastActiveFrameSlot = currentFrameSlot; @@ -1653,7 +1654,7 @@ QRhi::FrameOpResult QRhiVulkan::endFrame(QRhiSwapChain *swapChain, QRhi::EndFram // record another timestamp, when enabled if (frame.timestampQueryIndex >= 0) { df->vkCmdWriteTimestamp(frame.cmdBuf, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, - timestampQueryPool, frame.timestampQueryIndex + 1); + timestampQueryPool, uint32_t(frame.timestampQueryIndex + 1)); } // stop recording and submit to the queue @@ -1932,8 +1933,8 @@ static inline QRhiPassResourceTracker::UsageState toPassTrackerUsageState(const { QRhiPassResourceTracker::UsageState u; u.layout = 0; // unused with buffers - u.access = bufUsage.access; - u.stage = bufUsage.stage; + u.access = int(bufUsage.access); + u.stage = int(bufUsage.stage); return u; } @@ -1941,8 +1942,8 @@ static inline QRhiPassResourceTracker::UsageState toPassTrackerUsageState(const { QRhiPassResourceTracker::UsageState u; u.layout = texUsage.layout; - u.access = texUsage.access; - u.stage = texUsage.stage; + u.access = int(texUsage.access); + u.stage = int(texUsage.stage); return u; } @@ -2106,8 +2107,8 @@ void QRhiVulkan::beginPass(QRhiCommandBuffer *cb, rpBeginInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; rpBeginInfo.renderPass = rtD->rp->rp; rpBeginInfo.framebuffer = rtD->fb; - rpBeginInfo.renderArea.extent.width = rtD->pixelSize.width(); - rpBeginInfo.renderArea.extent.height = rtD->pixelSize.height(); + rpBeginInfo.renderArea.extent.width = uint32_t(rtD->pixelSize.width()); + rpBeginInfo.renderArea.extent.height = uint32_t(rtD->pixelSize.height()); QVarLengthArray cvs; for (int i = 0; i < rtD->colorAttCount; ++i) { @@ -2127,7 +2128,7 @@ void QRhiVulkan::beginPass(QRhiCommandBuffer *cb, float(colorClearValue.alphaF()) } }; cvs.append(cv); } - rpBeginInfo.clearValueCount = cvs.count(); + rpBeginInfo.clearValueCount = uint32_t(cvs.count()); QVkCommandBuffer::Command cmd; cmd.cmd = QVkCommandBuffer::Command::BeginRenderPass; @@ -2229,7 +2230,7 @@ void QRhiVulkan::dispatch(QRhiCommandBuffer *cb, int x, int y, int z) Q_ASSERT(cbD->recordingPass == QVkCommandBuffer::ComputePass); if (cbD->useSecondaryCb) { - df->vkCmdDispatch(cbD->secondaryCbs.last(), x, y, z); + df->vkCmdDispatch(cbD->secondaryCbs.last(), uint32_t(x), uint32_t(y), uint32_t(z)); } else { QVkCommandBuffer::Command cmd; cmd.cmd = QVkCommandBuffer::Command::Dispatch; @@ -2245,7 +2246,7 @@ VkShaderModule QRhiVulkan::createShader(const QByteArray &spirv) VkShaderModuleCreateInfo shaderInfo; memset(&shaderInfo, 0, sizeof(shaderInfo)); shaderInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; - shaderInfo.codeSize = spirv.size(); + shaderInfo.codeSize = size_t(spirv.size()); shaderInfo.pCode = reinterpret_cast(spirv.constData()); VkShaderModule shaderModule; VkResult err = df->vkCreateShaderModule(dev, &shaderInfo, nullptr, &shaderModule); @@ -2292,7 +2293,7 @@ void QRhiVulkan::updateShaderResourceBindings(QRhiShaderResourceBindings *srb, i memset(&writeInfo, 0, sizeof(writeInfo)); writeInfo.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; writeInfo.dstSet = srbD->descSets[frameSlot]; - writeInfo.dstBinding = b->binding; + writeInfo.dstBinding = uint32_t(b->binding); writeInfo.descriptorCount = 1; switch (b->type) { @@ -2306,8 +2307,8 @@ void QRhiVulkan::updateShaderResourceBindings(QRhiShaderResourceBindings *srb, i bd.ubuf.generation = bufD->generation; VkDescriptorBufferInfo bufInfo; bufInfo.buffer = bufD->m_type == QRhiBuffer::Dynamic ? bufD->buffers[frameSlot] : bufD->buffers[0]; - bufInfo.offset = b->u.ubuf.offset; - bufInfo.range = b->u.ubuf.maybeSize ? b->u.ubuf.maybeSize : bufD->m_size; + bufInfo.offset = VkDeviceSize(b->u.ubuf.offset); + bufInfo.range = VkDeviceSize(b->u.ubuf.maybeSize ? b->u.ubuf.maybeSize : bufD->m_size); // be nice and assert when we know the vulkan device would die a horrible death due to non-aligned reads Q_ASSERT(aligned(bufInfo.offset, ubufAlign) == bufInfo.offset); bufferInfos.append(bufInfo); @@ -2364,8 +2365,8 @@ void QRhiVulkan::updateShaderResourceBindings(QRhiShaderResourceBindings *srb, i bd.sbuf.generation = bufD->generation; VkDescriptorBufferInfo bufInfo; bufInfo.buffer = bufD->m_type == QRhiBuffer::Dynamic ? bufD->buffers[frameSlot] : bufD->buffers[0]; - bufInfo.offset = b->u.ubuf.offset; - bufInfo.range = b->u.ubuf.maybeSize ? b->u.ubuf.maybeSize : bufD->m_size; + bufInfo.offset = VkDeviceSize(b->u.ubuf.offset); + bufInfo.range = VkDeviceSize(b->u.ubuf.maybeSize ? b->u.ubuf.maybeSize : bufD->m_size); bufferInfos.append(bufInfo); writeInfo.pBufferInfo = &bufferInfos.last(); } @@ -2379,7 +2380,7 @@ void QRhiVulkan::updateShaderResourceBindings(QRhiShaderResourceBindings *srb, i ++frameSlot; } - df->vkUpdateDescriptorSets(dev, writeInfos.count(), writeInfos.constData(), 0, nullptr); + df->vkUpdateDescriptorSets(dev, uint32_t(writeInfos.count()), writeInfos.constData(), 0, nullptr); } static inline bool accessIsWrite(VkAccessFlags access) @@ -2487,10 +2488,10 @@ void QRhiVulkan::subresourceBarrier(QVkCommandBuffer *cbD, VkImage image, memset(&barrier, 0, sizeof(barrier)); barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; - barrier.subresourceRange.baseMipLevel = startLevel; - barrier.subresourceRange.levelCount = levelCount; - barrier.subresourceRange.baseArrayLayer = startLayer; - barrier.subresourceRange.layerCount = layerCount; + barrier.subresourceRange.baseMipLevel = uint32_t(startLevel); + barrier.subresourceRange.levelCount = uint32_t(levelCount); + barrier.subresourceRange.baseArrayLayer = uint32_t(startLayer); + barrier.subresourceRange.layerCount = uint32_t(layerCount); barrier.oldLayout = oldLayout; barrier.newLayout = newLayout; barrier.srcAccessMask = srcAccess; @@ -2511,7 +2512,7 @@ VkDeviceSize QRhiVulkan::subresUploadByteSize(const QRhiTextureSubresourceUpload const qsizetype imageSizeBytes = subresDesc.image().isNull() ? subresDesc.data().size() : subresDesc.image().sizeInBytes(); if (imageSizeBytes > 0) - size += aligned(imageSizeBytes, texbufAlign); + size += aligned(VkDeviceSize(imageSizeBytes), texbufAlign); return size; } @@ -2528,8 +2529,8 @@ void QRhiVulkan::prepareUploadSubres(QVkTexture *texD, int layer, int level, memset(©Info, 0, sizeof(copyInfo)); copyInfo.bufferOffset = *curOfs; copyInfo.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; - copyInfo.imageSubresource.mipLevel = level; - copyInfo.imageSubresource.baseArrayLayer = layer; + copyInfo.imageSubresource.mipLevel = uint32_t(level); + copyInfo.imageSubresource.baseArrayLayer = uint32_t(layer); copyInfo.imageSubresource.layerCount = 1; copyInfo.imageExtent.depth = 1; @@ -2544,7 +2545,7 @@ void QRhiVulkan::prepareUploadSubres(QVkTexture *texD, int layer, int level, // be taken into account for bufferRowLength. int bpc = qMax(1, image.depth() / 8); // this is in pixels, not bytes, to make it more complicated... - copyInfo.bufferRowLength = image.bytesPerLine() / bpc; + copyInfo.bufferRowLength = uint32_t(image.bytesPerLine() / bpc); if (!subresDesc.sourceSize().isEmpty() || !subresDesc.sourceTopLeft().isNull()) { const int sx = subresDesc.sourceTopLeft().x(); const int sy = subresDesc.sourceTopLeft().y(); @@ -2554,7 +2555,7 @@ void QRhiVulkan::prepareUploadSubres(QVkTexture *texD, int layer, int level, // The staging buffer will get the full image // regardless, just adjust the vk // buffer-to-image copy start offset. - copyInfo.bufferOffset += sy * image.bytesPerLine() + sx * 4; + copyInfo.bufferOffset += VkDeviceSize(sy * image.bytesPerLine() + sx * 4); // bufferRowLength remains set to the original image's width } else { image = image.copy(sx, sy, size.width(), size.height()); @@ -2563,13 +2564,13 @@ void QRhiVulkan::prepareUploadSubres(QVkTexture *texD, int layer, int level, // space reserved for this mip will be unused. copySizeBytes = image.sizeInBytes(); bpc = qMax(1, image.depth() / 8); - copyInfo.bufferRowLength = image.bytesPerLine() / bpc; + copyInfo.bufferRowLength = uint32_t(image.bytesPerLine() / bpc); } } copyInfo.imageOffset.x = dp.x(); copyInfo.imageOffset.y = dp.y(); - copyInfo.imageExtent.width = size.width(); - copyInfo.imageExtent.height = size.height(); + copyInfo.imageExtent.width = uint32_t(size.width()); + copyInfo.imageExtent.height = uint32_t(size.height()); copyInfos->append(copyInfo); } else if (!rawData.isEmpty() && isCompressedFormat(texD->m_format)) { copySizeBytes = imageSizeBytes = rawData.size(); @@ -2588,8 +2589,8 @@ void QRhiVulkan::prepareUploadSubres(QVkTexture *texD, int layer, int level, copyInfo.imageOffset.y = aligned(dp.y(), blockDim.height()); // width and height must be multiples of the block width and height // or x + width and y + height must equal the subresource width and height - copyInfo.imageExtent.width = dp.x() + w == subresw ? w : aligned(w, blockDim.width()); - copyInfo.imageExtent.height = dp.y() + h == subresh ? h : aligned(h, blockDim.height()); + copyInfo.imageExtent.width = uint32_t(dp.x() + w == subresw ? w : aligned(w, blockDim.width())); + copyInfo.imageExtent.height = uint32_t(dp.y() + h == subresh ? h : aligned(h, blockDim.height())); copyInfos->append(copyInfo); } else if (!rawData.isEmpty()) { copySizeBytes = imageSizeBytes = rawData.size(); @@ -2599,15 +2600,15 @@ void QRhiVulkan::prepareUploadSubres(QVkTexture *texD, int layer, int level, size = subresDesc.sourceSize(); copyInfo.imageOffset.x = dp.x(); copyInfo.imageOffset.y = dp.y(); - copyInfo.imageExtent.width = size.width(); - copyInfo.imageExtent.height = size.height(); + copyInfo.imageExtent.width = uint32_t(size.width()); + copyInfo.imageExtent.height = uint32_t(size.height()); copyInfos->append(copyInfo); } else { qWarning("Invalid texture upload for %p layer=%d mip=%d", texD, layer, level); } - memcpy(reinterpret_cast(mp) + *curOfs, src, copySizeBytes); - *curOfs += aligned(imageSizeBytes, texbufAlign); + memcpy(reinterpret_cast(mp) + *curOfs, src, size_t(copySizeBytes)); + *curOfs += aligned(VkDeviceSize(imageSizeBytes), texbufAlign); } void QRhiVulkan::enqueueResourceUpdates(QVkCommandBuffer *cbD, QRhiResourceUpdateBatch *resourceUpdates) @@ -2633,7 +2634,7 @@ void QRhiVulkan::enqueueResourceUpdates(QVkCommandBuffer *cbD, QRhiResourceUpdat bufferInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; // must cover the entire buffer - this way multiple, partial updates per frame // are supported even when the staging buffer is reused (Static) - bufferInfo.size = bufD->m_size; + bufferInfo.size = VkDeviceSize(bufD->m_size); bufferInfo.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT; VmaAllocationCreateInfo allocInfo; @@ -2645,7 +2646,7 @@ void QRhiVulkan::enqueueResourceUpdates(QVkCommandBuffer *cbD, QRhiResourceUpdat &bufD->stagingBuffers[currentFrameSlot], &allocation, nullptr); if (err == VK_SUCCESS) { bufD->stagingAllocations[currentFrameSlot] = allocation; - QRHI_PROF_F(newBufferStagingArea(bufD, currentFrameSlot, bufD->m_size)); + QRHI_PROF_F(newBufferStagingArea(bufD, currentFrameSlot, quint32(bufD->m_size))); } else { qWarning("Failed to create staging buffer of size %d: %d", bufD->m_size, err); continue; @@ -2659,18 +2660,18 @@ void QRhiVulkan::enqueueResourceUpdates(QVkCommandBuffer *cbD, QRhiResourceUpdat qWarning("Failed to map buffer: %d", err); continue; } - memcpy(static_cast(p) + u.offset, u.data.constData(), u.data.size()); + memcpy(static_cast(p) + u.offset, u.data.constData(), size_t(u.data.size())); vmaUnmapMemory(toVmaAllocator(allocator), a); - vmaFlushAllocation(toVmaAllocator(allocator), a, u.offset, u.data.size()); + vmaFlushAllocation(toVmaAllocator(allocator), a, VkDeviceSize(u.offset), VkDeviceSize(u.data.size())); trackedBufferBarrier(cbD, bufD, 0, VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT); VkBufferCopy copyInfo; memset(©Info, 0, sizeof(copyInfo)); - copyInfo.srcOffset = u.offset; - copyInfo.dstOffset = u.offset; - copyInfo.size = u.data.size(); + copyInfo.srcOffset = VkDeviceSize(u.offset); + copyInfo.dstOffset = VkDeviceSize(u.offset); + copyInfo.size = VkDeviceSize(u.data.size()); QVkCommandBuffer::Command cmd; cmd.cmd = QVkCommandBuffer::Command::CopyBuffer; @@ -2732,7 +2733,7 @@ void QRhiVulkan::enqueueResourceUpdates(QVkCommandBuffer *cbD, QRhiResourceUpdat continue; } utexD->stagingAllocations[currentFrameSlot] = allocation; - QRHI_PROF_F(newTextureStagingArea(utexD, currentFrameSlot, stagingSize)); + QRHI_PROF_F(newTextureStagingArea(utexD, currentFrameSlot, quint32(stagingSize))); BufferImageCopyList copyInfos; size_t curOfs = 0; @@ -2799,24 +2800,24 @@ void QRhiVulkan::enqueueResourceUpdates(QVkCommandBuffer *cbD, QRhiResourceUpdat memset(®ion, 0, sizeof(region)); region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; - region.srcSubresource.mipLevel = u.copy.desc.sourceLevel(); - region.srcSubresource.baseArrayLayer = u.copy.desc.sourceLayer(); + region.srcSubresource.mipLevel = uint32_t(u.copy.desc.sourceLevel()); + region.srcSubresource.baseArrayLayer = uint32_t(u.copy.desc.sourceLayer()); region.srcSubresource.layerCount = 1; region.srcOffset.x = u.copy.desc.sourceTopLeft().x(); region.srcOffset.y = u.copy.desc.sourceTopLeft().y(); region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; - region.dstSubresource.mipLevel = u.copy.desc.destinationLevel(); - region.dstSubresource.baseArrayLayer = u.copy.desc.destinationLayer(); + region.dstSubresource.mipLevel = uint32_t(u.copy.desc.destinationLevel()); + region.dstSubresource.baseArrayLayer = uint32_t(u.copy.desc.destinationLayer()); region.dstSubresource.layerCount = 1; region.dstOffset.x = u.copy.desc.destinationTopLeft().x(); region.dstOffset.y = u.copy.desc.destinationTopLeft().y(); const QSize size = u.copy.desc.pixelSize().isEmpty() ? srcD->m_pixelSize : u.copy.desc.pixelSize(); - region.extent.width = size.width(); - region.extent.height = size.height(); + region.extent.width = uint32_t(size.width()); + region.extent.height = uint32_t(size.height()); region.extent.depth = 1; trackedImageBarrier(cbD, srcD, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, @@ -2883,7 +2884,7 @@ void QRhiVulkan::enqueueResourceUpdates(QVkCommandBuffer *cbD, QRhiResourceUpdat VkResult err = vmaCreateBuffer(toVmaAllocator(allocator), &bufferInfo, &allocInfo, &aRb.buf, &allocation, nullptr); if (err == VK_SUCCESS) { aRb.bufAlloc = allocation; - QRHI_PROF_F(newReadbackBuffer(quint64(aRb.buf), + QRHI_PROF_F(newReadbackBuffer(qint64(aRb.buf), texD ? static_cast(texD) : static_cast(swapChainD), aRb.bufSize)); } else { @@ -2896,11 +2897,11 @@ void QRhiVulkan::enqueueResourceUpdates(QVkCommandBuffer *cbD, QRhiResourceUpdat memset(©Desc, 0, sizeof(copyDesc)); copyDesc.bufferOffset = 0; copyDesc.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; - copyDesc.imageSubresource.mipLevel = u.read.rb.level(); - copyDesc.imageSubresource.baseArrayLayer = u.read.rb.layer(); + copyDesc.imageSubresource.mipLevel = uint32_t(u.read.rb.level()); + copyDesc.imageSubresource.baseArrayLayer = uint32_t(u.read.rb.layer()); copyDesc.imageSubresource.layerCount = 1; - copyDesc.imageExtent.width = aRb.pixelSize.width(); - copyDesc.imageExtent.height = aRb.pixelSize.height(); + copyDesc.imageExtent.width = uint32_t(aRb.pixelSize.width()); + copyDesc.imageExtent.height = uint32_t(aRb.pixelSize.height()); copyDesc.imageExtent.depth = 1; if (texD) { @@ -2953,7 +2954,7 @@ void QRhiVulkan::enqueueResourceUpdates(QVkCommandBuffer *cbD, QRhiResourceUpdat if (!origStage) origStage = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; - for (uint level = 1; level < utexD->mipLevelCount; ++level) { + for (int level = 1; level < int(utexD->mipLevelCount); ++level) { if (level == 1) { subresourceBarrier(cbD, utexD->image, origLayout, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, @@ -2981,8 +2982,8 @@ void QRhiVulkan::enqueueResourceUpdates(QVkCommandBuffer *cbD, QRhiResourceUpdat memset(®ion, 0, sizeof(region)); region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; - region.srcSubresource.mipLevel = level - 1; - region.srcSubresource.baseArrayLayer = u.mipgen.layer; + region.srcSubresource.mipLevel = uint32_t(level) - 1; + region.srcSubresource.baseArrayLayer = uint32_t(u.mipgen.layer); region.srcSubresource.layerCount = 1; region.srcOffsets[1].x = qMax(1, w); @@ -2990,8 +2991,8 @@ void QRhiVulkan::enqueueResourceUpdates(QVkCommandBuffer *cbD, QRhiResourceUpdat region.srcOffsets[1].z = 1; region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; - region.dstSubresource.mipLevel = level; - region.dstSubresource.baseArrayLayer = u.mipgen.layer; + region.dstSubresource.mipLevel = uint32_t(level); + region.dstSubresource.baseArrayLayer = uint32_t(u.mipgen.layer); region.dstSubresource.layerCount = 1; region.dstOffsets[1].x = qMax(1, w >> 1); @@ -3018,13 +3019,13 @@ void QRhiVulkan::enqueueResourceUpdates(QVkCommandBuffer *cbD, QRhiResourceUpdat VK_ACCESS_TRANSFER_READ_BIT, origAccess, VK_PIPELINE_STAGE_TRANSFER_BIT, origStage, u.mipgen.layer, 1, - 0, utexD->mipLevelCount - 1); + 0, int(utexD->mipLevelCount) - 1); subresourceBarrier(cbD, utexD->image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, origLayout, VK_ACCESS_TRANSFER_WRITE_BIT, origAccess, VK_PIPELINE_STAGE_TRANSFER_BIT, origStage, u.mipgen.layer, 1, - utexD->mipLevelCount - 1, 1); + int(utexD->mipLevelCount) - 1, 1); } utexD->lastActiveFrameSlot = currentFrameSlot; @@ -3055,7 +3056,7 @@ void QRhiVulkan::executeBufferHostWritesForCurrentFrame(QVkBuffer *bufD) int changeEnd = -1; for (const QRhiResourceUpdateBatchPrivate::DynamicBufferUpdate &u : updates) { Q_ASSERT(bufD == QRHI_RES(QVkBuffer, u.buf)); - memcpy(static_cast(p) + u.offset, u.data.constData(), u.data.size()); + memcpy(static_cast(p) + u.offset, u.data.constData(), size_t(u.data.size())); if (changeBegin == -1 || u.offset < changeBegin) changeBegin = u.offset; if (changeEnd == -1 || u.offset + u.data.size() > changeEnd) @@ -3063,7 +3064,7 @@ void QRhiVulkan::executeBufferHostWritesForCurrentFrame(QVkBuffer *bufD) } vmaUnmapMemory(toVmaAllocator(allocator), a); if (changeBegin >= 0) - vmaFlushAllocation(toVmaAllocator(allocator), a, changeBegin, changeEnd - changeBegin); + vmaFlushAllocation(toVmaAllocator(allocator), a, VkDeviceSize(changeBegin), VkDeviceSize(changeEnd - changeBegin)); updates.clear(); } @@ -3164,7 +3165,7 @@ void QRhiVulkan::finishActiveReadbacks(bool forced) if (forced || currentFrameSlot == aRb.activeFrameSlot || aRb.activeFrameSlot < 0) { aRb.result->format = aRb.format; aRb.result->pixelSize = aRb.pixelSize; - aRb.result->data.resize(aRb.bufSize); + aRb.result->data.resize(int(aRb.bufSize)); void *p = nullptr; VmaAllocation a = toVmaAllocation(aRb.bufAlloc); VkResult err = vmaMapMemory(toVmaAllocator(allocator), a, &p); @@ -3176,7 +3177,7 @@ void QRhiVulkan::finishActiveReadbacks(bool forced) vmaUnmapMemory(toVmaAllocator(allocator), a); vmaDestroyBuffer(toVmaAllocator(allocator), aRb.buf, a); - QRHI_PROF_F(releaseReadbackBuffer(quint64(aRb.buf))); + QRHI_PROF_F(releaseReadbackBuffer(qint64(aRb.buf))); if (aRb.result->completed) completedCallbacks.append(aRb.result->completed); @@ -3266,7 +3267,7 @@ void QRhiVulkan::recordPrimaryCommandBuffer(QVkCommandBuffer *cbD) case QVkCommandBuffer::Command::CopyBufferToImage: df->vkCmdCopyBufferToImage(cbD->cb, cmd.args.copyBufferToImage.src, cmd.args.copyBufferToImage.dst, cmd.args.copyBufferToImage.dstLayout, - cmd.args.copyBufferToImage.count, + uint32_t(cmd.args.copyBufferToImage.count), cbD->pools.bufferImageCopy.constData() + cmd.args.copyBufferToImage.bufferImageCopyIndex); break; case QVkCommandBuffer::Command::CopyImage: @@ -3315,13 +3316,13 @@ void QRhiVulkan::recordPrimaryCommandBuffer(QVkCommandBuffer *cbD) df->vkCmdBindDescriptorSets(cbD->cb, cmd.args.bindDescriptorSet.bindPoint, cmd.args.bindDescriptorSet.pipelineLayout, 0, 1, &cmd.args.bindDescriptorSet.descSet, - cmd.args.bindDescriptorSet.dynamicOffsetCount, + uint32_t(cmd.args.bindDescriptorSet.dynamicOffsetCount), offsets); } break; case QVkCommandBuffer::Command::BindVertexBuffer: - df->vkCmdBindVertexBuffers(cbD->cb, cmd.args.bindVertexBuffer.startBinding, - cmd.args.bindVertexBuffer.count, + df->vkCmdBindVertexBuffers(cbD->cb, uint32_t(cmd.args.bindVertexBuffer.startBinding), + uint32_t(cmd.args.bindVertexBuffer.count), cbD->pools.vertexBuffer.constData() + cmd.args.bindVertexBuffer.vertexBufferIndex, cbD->pools.vertexBufferOffset.constData() + cmd.args.bindVertexBuffer.vertexBufferOffsetIndex); break; @@ -3367,7 +3368,7 @@ void QRhiVulkan::recordPrimaryCommandBuffer(QVkCommandBuffer *cbD) recordTransitionPassResources(cbD, cbD->passResTrackers[cmd.args.transitionResources.trackerIndex]); break; case QVkCommandBuffer::Command::Dispatch: - df->vkCmdDispatch(cbD->cb, cmd.args.dispatch.x, cmd.args.dispatch.y, cmd.args.dispatch.z); + df->vkCmdDispatch(cbD->cb, uint32_t(cmd.args.dispatch.x), uint32_t(cmd.args.dispatch.y), uint32_t(cmd.args.dispatch.z)); break; case QVkCommandBuffer::Command::ExecuteSecondary: df->vkCmdExecuteCommands(cbD->cb, 1, &cmd.args.executeSecondary.cb); @@ -3421,8 +3422,8 @@ static inline VkPipelineStageFlags toVkPipelineStage(QRhiPassResourceTracker::Bu static inline QVkBuffer::UsageState toVkBufferUsageState(QRhiPassResourceTracker::UsageState usage) { QVkBuffer::UsageState u; - u.access = usage.access; - u.stage = usage.stage; + u.access = VkAccessFlags(usage.access); + u.stage = VkPipelineStageFlags(usage.stage); return u; } @@ -3494,8 +3495,8 @@ static inline QVkTexture::UsageState toVkTextureUsageState(QRhiPassResourceTrack { QVkTexture::UsageState u; u.layout = VkImageLayout(usage.layout); - u.access = usage.access; - u.stage = usage.stage; + u.access = VkAccessFlags(usage.access); + u.stage = VkPipelineStageFlags(usage.stage); return u; } @@ -3603,7 +3604,7 @@ QRhiBuffer *QRhiVulkan::createBuffer(QRhiBuffer::Type type, QRhiBuffer::UsageFla int QRhiVulkan::ubufAlignment() const { - return ubufAlign; // typically 256 (bytes) + return int(ubufAlign); // typically 256 (bytes) } bool QRhiVulkan::isYUpInFramebuffer() const @@ -3711,9 +3712,9 @@ int QRhiVulkan::resourceLimit(QRhi::ResourceLimit limit) const case QRhi::TextureSizeMin: return 1; case QRhi::TextureSizeMax: - return physDevProperties.limits.maxImageDimension2D; + return int(physDevProperties.limits.maxImageDimension2D); case QRhi::MaxColorAttachments: - return physDevProperties.limits.maxColorAttachments; + return int(physDevProperties.limits.maxColorAttachments); case QRhi::FramesInFlight: return QVK_FRAMES_IN_FLIGHT; default: @@ -3736,7 +3737,7 @@ void QRhiVulkan::sendVMemStatsToProfiler() VmaStats stats; vmaCalculateStats(toVmaAllocator(allocator), &stats); QRHI_PROF_F(vmemStat(stats.total.blockCount, stats.total.allocationCount, - stats.total.usedBytes, stats.total.unusedBytes)); + quint32(stats.total.usedBytes), quint32(stats.total.unusedBytes))); } void QRhiVulkan::makeThreadLocalNativeContextCurrent() @@ -4008,7 +4009,7 @@ void QRhiVulkan::setShaderResources(QRhiCommandBuffer *cb, QRhiShaderResourceBin gfxPsD ? VK_PIPELINE_BIND_POINT_GRAPHICS : VK_PIPELINE_BIND_POINT_COMPUTE, gfxPsD ? gfxPsD->layout : compPsD->layout, 0, 1, &srbD->descSets[descSetIdx], - dynOfs.count(), + uint32_t(dynOfs.count()), dynOfs.count() ? dynOfs.constData() : nullptr); } else { QVkCommandBuffer::Command cmd; @@ -4078,8 +4079,8 @@ void QRhiVulkan::setVertexInput(QRhiCommandBuffer *cb, } if (cbD->useSecondaryCb) { - df->vkCmdBindVertexBuffers(cbD->secondaryCbs.last(), startBinding, - bufs.count(), bufs.constData(), ofs.constData()); + df->vkCmdBindVertexBuffers(cbD->secondaryCbs.last(), uint32_t(startBinding), + uint32_t(bufs.count()), bufs.constData(), ofs.constData()); } else { QVkCommandBuffer::Command cmd; cmd.cmd = QVkCommandBuffer::Command::BindVertexBuffer; @@ -4160,10 +4161,10 @@ void QRhiVulkan::setViewport(QRhiCommandBuffer *cb, const QRhiViewport &viewport if (!QRHI_RES(QVkGraphicsPipeline, cbD->currentGraphicsPipeline)->m_flags.testFlag(QRhiGraphicsPipeline::UsesScissor)) { VkRect2D *s = &cmd.args.setScissor.scissor; - s->offset.x = x; - s->offset.y = y; - s->extent.width = w; - s->extent.height = h; + s->offset.x = int32_t(x); + s->offset.y = int32_t(y); + s->extent.width = uint32_t(w); + s->extent.height = uint32_t(h); if (cbD->useSecondaryCb) { df->vkCmdSetScissor(cbD->secondaryCbs.last(), 0, 1, s); } else { @@ -4189,8 +4190,8 @@ void QRhiVulkan::setScissor(QRhiCommandBuffer *cb, const QRhiScissor &scissor) VkRect2D *s = &cmd.args.setScissor.scissor; s->offset.x = x; s->offset.y = y; - s->extent.width = w; - s->extent.height = h; + s->extent.width = uint32_t(w); + s->extent.height = uint32_t(h); if (cbD->useSecondaryCb) { df->vkCmdSetScissor(cbD->secondaryCbs.last(), 0, 1, s); @@ -4211,10 +4212,10 @@ void QRhiVulkan::setBlendConstants(QRhiCommandBuffer *cb, const QColor &c) } else { QVkCommandBuffer::Command cmd; cmd.cmd = QVkCommandBuffer::Command::SetBlendConstants; - cmd.args.setBlendConstants.c[0] = c.redF(); - cmd.args.setBlendConstants.c[1] = c.greenF(); - cmd.args.setBlendConstants.c[2] = c.blueF(); - cmd.args.setBlendConstants.c[3] = c.alphaF(); + cmd.args.setBlendConstants.c[0] = float(c.redF()); + cmd.args.setBlendConstants.c[1] = float(c.greenF()); + cmd.args.setBlendConstants.c[2] = float(c.blueF()); + cmd.args.setBlendConstants.c[3] = float(c.alphaF()); cbD->commands.append(cmd); } } @@ -4843,7 +4844,7 @@ bool QVkBuffer::build() VkBufferCreateInfo bufferInfo; memset(&bufferInfo, 0, sizeof(bufferInfo)); bufferInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; - bufferInfo.size = nonZeroSize; + bufferInfo.size = uint32_t(nonZeroSize); bufferInfo.usage = toVkBufferUsage(m_usage); VmaAllocationCreateInfo allocInfo; @@ -4890,7 +4891,7 @@ bool QVkBuffer::build() } QRHI_PROF; - QRHI_PROF_F(newBuffer(this, nonZeroSize, m_type != Dynamic ? 1 : QVK_FRAMES_IN_FLIGHT, 0)); + QRHI_PROF_F(newBuffer(this, uint(nonZeroSize), m_type != Dynamic ? 1 : QVK_FRAMES_IN_FLIGHT, 0)); lastActiveFrameSlot = -1; generation += 1; @@ -5081,7 +5082,7 @@ bool QVkTexture::prepareBuild(QSize *adjustedSize) const bool isCube = m_flags.testFlag(CubeMap); const bool hasMipMaps = m_flags.testFlag(MipMapped); - mipLevelCount = hasMipMaps ? rhiD->q->mipLevelsForSize(size) : 1; + mipLevelCount = uint(hasMipMaps ? rhiD->q->mipLevelsForSize(size) : 1); const int maxLevels = QRhi::MAX_LEVELS; if (mipLevelCount > maxLevels) { qWarning("Too many mip levels (%d, max is %d), truncating mip chain", mipLevelCount, maxLevels); @@ -5160,8 +5161,8 @@ bool QVkTexture::build() imageInfo.flags = isCube ? VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT : 0; imageInfo.imageType = VK_IMAGE_TYPE_2D; imageInfo.format = vkformat; - imageInfo.extent.width = size.width(); - imageInfo.extent.height = size.height(); + imageInfo.extent.width = uint32_t(size.width()); + imageInfo.extent.height = uint32_t(size.height()); imageInfo.extent.depth = 1; imageInfo.mipLevels = mipLevelCount; imageInfo.arrayLayers = isCube ? 6 : 1; @@ -5202,7 +5203,7 @@ bool QVkTexture::build() rhiD->setObjectName(uint64_t(image), VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, m_objectName); QRHI_PROF; - QRHI_PROF_F(newTexture(this, true, mipLevelCount, isCube ? 6 : 1, samples)); + QRHI_PROF_F(newTexture(this, true, int(mipLevelCount), isCube ? 6 : 1, samples)); owns = true; rhiD->registerResource(this); @@ -5224,7 +5225,7 @@ bool QVkTexture::buildFrom(const QRhiNativeHandles *src) return false; QRHI_PROF; - QRHI_PROF_F(newTexture(this, false, mipLevelCount, m_flags.testFlag(CubeMap) ? 6 : 1, samples)); + QRHI_PROF_F(newTexture(this, false, int(mipLevelCount), m_flags.testFlag(CubeMap) ? 6 : 1, samples)); usageState.layout = h->layout; @@ -5260,7 +5261,7 @@ VkImageView QVkTexture::imageViewForLevel(int level) viewInfo.components.b = VK_COMPONENT_SWIZZLE_B; viewInfo.components.a = VK_COMPONENT_SWIZZLE_A; viewInfo.subresourceRange.aspectMask = isDepth ? VK_IMAGE_ASPECT_DEPTH_BIT : VK_IMAGE_ASPECT_COLOR_BIT; - viewInfo.subresourceRange.baseMipLevel = level; + viewInfo.subresourceRange.baseMipLevel = uint32_t(level); viewInfo.subresourceRange.levelCount = 1; viewInfo.subresourceRange.baseArrayLayer = 0; viewInfo.subresourceRange.layerCount = isCube ? 6 : 1; @@ -5501,9 +5502,9 @@ bool QVkTextureRenderTarget::build() viewInfo.components.b = VK_COMPONENT_SWIZZLE_B; viewInfo.components.a = VK_COMPONENT_SWIZZLE_A; viewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; - viewInfo.subresourceRange.baseMipLevel = colorAttachments[i].level(); + viewInfo.subresourceRange.baseMipLevel = uint32_t(colorAttachments[i].level()); viewInfo.subresourceRange.levelCount = 1; - viewInfo.subresourceRange.baseArrayLayer = colorAttachments[i].layer(); + viewInfo.subresourceRange.baseArrayLayer = uint32_t(colorAttachments[i].layer()); viewInfo.subresourceRange.layerCount = 1; VkResult err = rhiD->df->vkCreateImageView(rhiD->dev, &viewInfo, nullptr, &rtv[i]); if (err != VK_SUCCESS) { @@ -5565,9 +5566,9 @@ bool QVkTextureRenderTarget::build() viewInfo.components.b = VK_COMPONENT_SWIZZLE_B; viewInfo.components.a = VK_COMPONENT_SWIZZLE_A; viewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; - viewInfo.subresourceRange.baseMipLevel = colorAttachments[i].resolveLevel(); + viewInfo.subresourceRange.baseMipLevel = uint32_t(colorAttachments[i].resolveLevel()); viewInfo.subresourceRange.levelCount = 1; - viewInfo.subresourceRange.baseArrayLayer = colorAttachments[i].resolveLayer(); + viewInfo.subresourceRange.baseArrayLayer = uint32_t(colorAttachments[i].resolveLayer()); viewInfo.subresourceRange.layerCount = 1; VkResult err = rhiD->df->vkCreateImageView(rhiD->dev, &viewInfo, nullptr, &resrtv[i]); if (err != VK_SUCCESS) { @@ -5588,10 +5589,10 @@ bool QVkTextureRenderTarget::build() memset(&fbInfo, 0, sizeof(fbInfo)); fbInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; fbInfo.renderPass = d.rp->rp; - fbInfo.attachmentCount = d.colorAttCount + d.dsAttCount + d.resolveAttCount; + fbInfo.attachmentCount = uint32_t(d.colorAttCount + d.dsAttCount + d.resolveAttCount); fbInfo.pAttachments = views.constData(); - fbInfo.width = d.pixelSize.width(); - fbInfo.height = d.pixelSize.height(); + fbInfo.width = uint32_t(d.pixelSize.width()); + fbInfo.height = uint32_t(d.pixelSize.height()); fbInfo.layers = 1; VkResult err = rhiD->df->vkCreateFramebuffer(rhiD->dev, &fbInfo, nullptr, &d.fb); @@ -5675,7 +5676,7 @@ bool QVkShaderResourceBindings::build() const QRhiShaderResourceBindingPrivate *b = QRhiShaderResourceBindingPrivate::get(&binding); VkDescriptorSetLayoutBinding vkbinding; memset(&vkbinding, 0, sizeof(vkbinding)); - vkbinding.binding = b->binding; + vkbinding.binding = uint32_t(b->binding); vkbinding.descriptorType = toVkDescriptorType(b); vkbinding.descriptorCount = 1; // no array support yet vkbinding.stageFlags = toVkShaderStageFlags(b->stage); @@ -5792,7 +5793,7 @@ bool QVkGraphicsPipeline::build() shaderStageCreateInfos.append(shaderInfo); } } - pipelineInfo.stageCount = shaderStageCreateInfos.count(); + pipelineInfo.stageCount = uint32_t(shaderStageCreateInfos.count()); pipelineInfo.pStages = shaderStageCreateInfos.constData(); const QVector bindings = m_vertexInputLayout.bindings(); @@ -5833,15 +5834,15 @@ bool QVkGraphicsPipeline::build() VkPipelineVertexInputStateCreateInfo vertexInputInfo; memset(&vertexInputInfo, 0, sizeof(vertexInputInfo)); vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; - vertexInputInfo.vertexBindingDescriptionCount = vertexBindings.count(); + vertexInputInfo.vertexBindingDescriptionCount = uint32_t(vertexBindings.count()); vertexInputInfo.pVertexBindingDescriptions = vertexBindings.constData(); - vertexInputInfo.vertexAttributeDescriptionCount = vertexAttributes.count(); + vertexInputInfo.vertexAttributeDescriptionCount = uint32_t(vertexAttributes.count()); vertexInputInfo.pVertexAttributeDescriptions = vertexAttributes.constData(); VkPipelineVertexInputDivisorStateCreateInfoEXT divisorInfo; if (!nonOneStepRates.isEmpty()) { memset(&divisorInfo, 0, sizeof(divisorInfo)); divisorInfo.sType = VkStructureType(1000190001); // VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_DIVISOR_STATE_CREATE_INFO_EXT - divisorInfo.vertexBindingDivisorCount = nonOneStepRates.count(); + divisorInfo.vertexBindingDivisorCount = uint32_t(nonOneStepRates.count()); divisorInfo.pVertexBindingDivisors = nonOneStepRates.constData(); vertexInputInfo.pNext = &divisorInfo; } @@ -5858,7 +5859,7 @@ bool QVkGraphicsPipeline::build() VkPipelineDynamicStateCreateInfo dynamicInfo; memset(&dynamicInfo, 0, sizeof(dynamicInfo)); dynamicInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; - dynamicInfo.dynamicStateCount = dynEnable.count(); + dynamicInfo.dynamicStateCount = uint32_t(dynEnable.count()); dynamicInfo.pDynamicStates = dynEnable.constData(); pipelineInfo.pDynamicState = &dynamicInfo; @@ -5930,7 +5931,7 @@ bool QVkGraphicsPipeline::build() | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; vktargetBlends.append(blend); } - blendInfo.attachmentCount = vktargetBlends.count(); + blendInfo.attachmentCount = uint32_t(vktargetBlends.count()); blendInfo.pAttachments = vktargetBlends.constData(); pipelineInfo.pColorBlendState = &blendInfo; @@ -6131,11 +6132,11 @@ QSize QVkSwapChain::surfacePixelSize() QRHI_RES_RHI(QRhiVulkan); rhiD->vkGetPhysicalDeviceSurfaceCapabilitiesKHR(rhiD->physDev, surface, &surfaceCaps); VkExtent2D bufferSize = surfaceCaps.currentExtent; - if (bufferSize.width == quint32(-1)) { - Q_ASSERT(bufferSize.height == quint32(-1)); + if (bufferSize.width == uint32_t(-1)) { + Q_ASSERT(bufferSize.height == uint32_t(-1)); return m_window->size() * m_window->devicePixelRatio(); } - return QSize(bufferSize.width, bufferSize.height); + return QSize(int(bufferSize.width), int(bufferSize.height)); } QRhiRenderPassDescriptor *QVkSwapChain::newCompatibleRenderPassDescriptor() @@ -6203,7 +6204,7 @@ bool QVkSwapChain::ensureSurface() QRHI_RES_RHI(QRhiVulkan); if (rhiD->gfxQueueFamilyIdx != -1) { - if (!rhiD->inst->supportsPresent(rhiD->physDev, rhiD->gfxQueueFamilyIdx, m_window)) { + if (!rhiD->inst->supportsPresent(rhiD->physDev, uint32_t(rhiD->gfxQueueFamilyIdx), m_window)) { qWarning("Presenting not supported on this window"); return false; } @@ -6232,7 +6233,7 @@ bool QVkSwapChain::ensureSurface() rhiD->vkGetPhysicalDeviceSurfaceFormatsKHR(rhiD->physDev, surface, &formatCount, formats.data()); const bool srgbRequested = m_flags.testFlag(sRGB); - for (quint32 i = 0; i < formatCount; ++i) { + for (int i = 0; i < int(formatCount); ++i) { if (formats[i].format != VK_FORMAT_UNDEFINED && srgbRequested == isSrgbFormat(formats[i].format)) { colorFormat = formats[i].format; colorSpace = formats[i].colorSpace; @@ -6293,7 +6294,7 @@ bool QVkSwapChain::buildOrResize() Q_ASSERT(rtWrapper.d.rp && rtWrapper.d.rp->rp); rtWrapper.d.pixelSize = pixelSize; - rtWrapper.d.dpr = window->devicePixelRatio(); + rtWrapper.d.dpr = float(window->devicePixelRatio()); rtWrapper.d.sampleCount = samples; rtWrapper.d.colorAttCount = 1; if (m_depthStencil) { @@ -6320,10 +6321,10 @@ bool QVkSwapChain::buildOrResize() memset(&fbInfo, 0, sizeof(fbInfo)); fbInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; fbInfo.renderPass = rtWrapper.d.rp->rp; - fbInfo.attachmentCount = rtWrapper.d.colorAttCount + rtWrapper.d.dsAttCount + rtWrapper.d.resolveAttCount; + fbInfo.attachmentCount = uint32_t(rtWrapper.d.colorAttCount + rtWrapper.d.dsAttCount + rtWrapper.d.resolveAttCount); fbInfo.pAttachments = views; - fbInfo.width = pixelSize.width(); - fbInfo.height = pixelSize.height(); + fbInfo.width = uint32_t(pixelSize.width()); + fbInfo.height = uint32_t(pixelSize.height()); fbInfo.layers = 1; VkResult err = rhiD->df->vkCreateFramebuffer(rhiD->dev, &fbInfo, nullptr, &image.fb); -- cgit v1.2.3 From 1fbe3c23160120ab2d392ff841aa57d58a2e0063 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Mon, 9 Sep 2019 16:14:55 +0200 Subject: rhi: d3d11: Fix enabling alpha compositing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task-number: QTBUG-78089 Change-Id: I4e33665947debe007abcb976641e515224fa8451 Reviewed-by: Christian Strømme --- src/gui/rhi/qrhid3d11.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/gui/rhi/qrhid3d11.cpp b/src/gui/rhi/qrhid3d11.cpp index 2828256a90..119234035a 100644 --- a/src/gui/rhi/qrhid3d11.cpp +++ b/src/gui/rhi/qrhid3d11.cpp @@ -3773,11 +3773,23 @@ bool QD3D11SwapChain::buildOrResize() const UINT swapChainFlags = 0; QRHI_RES_RHI(QRhiD3D11); - const bool useFlipDiscard = rhiD->hasDxgi2 && rhiD->supportsFlipDiscardSwapchain; + bool useFlipDiscard = rhiD->hasDxgi2 && rhiD->supportsFlipDiscardSwapchain; if (!swapChain) { HWND hwnd = reinterpret_cast(window->winId()); sampleDesc = rhiD->effectiveSampleCount(m_sampleCount); + // Take a shortcut for alpha: our QWindow is OpenGLSurface so whatever + // the platform plugin does to enable transparency for OpenGL window + // will be sufficient for us too on the legacy (DISCARD) path. For + // FLIP_DISCARD we'd need to use DirectComposition (create a + // IDCompositionDevice/Target/Visual), avoid that for now. + if (m_flags.testFlag(SurfaceHasPreMulAlpha) || m_flags.testFlag(SurfaceHasNonPreMulAlpha)) { + useFlipDiscard = false; + if (window->requestedFormat().alphaBufferSize() <= 0) + qWarning("Swapchain says surface has alpha but the window has no alphaBufferSize set. " + "This may lead to problems."); + } + HRESULT hr; if (useFlipDiscard) { // We use FLIP_DISCARD which implies a buffer count of 2 (as opposed to the @@ -3796,10 +3808,9 @@ bool QD3D11SwapChain::buildOrResize() desc.BufferCount = BUFFER_COUNT; desc.Scaling = DXGI_SCALING_STRETCH; desc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD; - if (m_flags.testFlag(SurfaceHasPreMulAlpha)) - desc.AlphaMode = DXGI_ALPHA_MODE_PREMULTIPLIED; - else if (m_flags.testFlag(SurfaceHasNonPreMulAlpha)) - desc.AlphaMode = DXGI_ALPHA_MODE_STRAIGHT; + // Do not bother with AlphaMode, if won't work unless we go through + // DirectComposition. Instead, we just take the other (DISCARD) + // path for now when alpha is requested. desc.Flags = swapChainFlags; IDXGISwapChain1 *sc1; -- cgit v1.2.3 From 6f592ea300dfc69343aef1e79c7df5579909d3e9 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Tue, 10 Sep 2019 16:22:15 +0200 Subject: rhi: gl: Avoid crash when reading back the swapchain backbuffer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I9a632c06d8b9e666d99d0f135d3396d2de03f92a Reviewed-by: Christian Strømme --- src/gui/rhi/qrhigles2.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/gui/rhi/qrhigles2.cpp b/src/gui/rhi/qrhigles2.cpp index 0329acd350..4d91ac45bd 100644 --- a/src/gui/rhi/qrhigles2.cpp +++ b/src/gui/rhi/qrhigles2.cpp @@ -1480,7 +1480,8 @@ void QRhiGles2::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate cmd.cmd = QGles2CommandBuffer::Command::ReadPixels; cmd.args.readPixels.result = u.read.result; QGles2Texture *texD = QRHI_RES(QGles2Texture, u.read.rb.texture()); - trackedImageBarrier(cbD, texD, QGles2Texture::AccessRead); + if (texD) + trackedImageBarrier(cbD, texD, QGles2Texture::AccessRead); cmd.args.readPixels.texture = texD ? texD->texture : 0; if (texD) { cmd.args.readPixels.w = texD->m_pixelSize.width(); -- cgit v1.2.3 From d39d1a9e67affb3fd44fdd9ec71a50282a6fed1f Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Wed, 11 Sep 2019 09:50:57 +0200 Subject: rhi: Clarify the swapchain alpha flag docs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Iff0edf0ae40b830af0209403d899def922e6088c Reviewed-by: Christian Strømme --- src/gui/rhi/qrhi.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/gui/rhi/qrhi.cpp b/src/gui/rhi/qrhi.cpp index 65cfaf5123..5ad433cf23 100644 --- a/src/gui/rhi/qrhi.cpp +++ b/src/gui/rhi/qrhi.cpp @@ -3458,10 +3458,18 @@ QRhiResource::Type QRhiGraphicsPipeline::resourceType() const Flag values to describe swapchain properties \value SurfaceHasPreMulAlpha Indicates that the target surface has - transparency with premultiplied alpha. + transparency with premultiplied alpha. For example, this is what Qt Quick + uses when the alpha channel is enabled on the target QWindow, because the + scenegraph rendrerer always outputs fragments with alpha multiplied into + the red, green, and blue values. To ensure identical behavior across + platforms, always set QSurfaceFormat::alphaBufferSize() to a non-zero value + on the target QWindow whenever this flag is set on the swapchain. \value SurfaceHasNonPreMulAlpha Indicates the target surface has - transparencyt with non-premultiplied alpha. + transparency with non-premultiplied alpha. Be aware that this may not be + supported on some systems, if the system compositor always expects content + with premultiplied alpha. In that case the behavior with this flag set is + expected to be equivalent to SurfaceHasPreMulAlpha. \value sRGB Requests to pick an sRGB format for the swapchain and/or its render target views, where applicable. Note that this implies that sRGB -- cgit v1.2.3 From 0616e14de0bf867bc2730b2b07005fbcbb234bb4 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Tue, 10 Sep 2019 14:09:41 +0200 Subject: rhi: Better handling of device loss MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Starting with D3D11. The other backends will follow later. Change-Id: I4f165c9f1743df0fb00bdce1e898917575bf5f6e Reviewed-by: Christian Strømme --- src/gui/rhi/qrhi.cpp | 43 ++++++++++++++++++++++++++++++++++++++++++- src/gui/rhi/qrhi_p.h | 2 ++ src/gui/rhi/qrhi_p_p.h | 1 + src/gui/rhi/qrhid3d11.cpp | 21 +++++++++++++++++++-- src/gui/rhi/qrhid3d11_p_p.h | 2 ++ src/gui/rhi/qrhigles2.cpp | 5 +++++ src/gui/rhi/qrhigles2_p_p.h | 1 + src/gui/rhi/qrhimetal.mm | 5 +++++ src/gui/rhi/qrhimetal_p_p.h | 1 + src/gui/rhi/qrhinull.cpp | 5 +++++ src/gui/rhi/qrhinull_p_p.h | 1 + src/gui/rhi/qrhivulkan.cpp | 5 +++++ src/gui/rhi/qrhivulkan_p_p.h | 1 + 13 files changed, 90 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/gui/rhi/qrhi.cpp b/src/gui/rhi/qrhi.cpp index 5ad433cf23..fbdc90bd1b 100644 --- a/src/gui/rhi/qrhi.cpp +++ b/src/gui/rhi/qrhi.cpp @@ -455,7 +455,7 @@ Q_LOGGING_CATEGORY(QRHI_LOG_INFO, "qt.rhi.general") \value FrameOpDeviceLost The graphics device was lost. This can be recoverable by attempting to repeat the operation (such as, beginFrame()) - and releasing and reinitializing all objects backed by native graphics + after releasing and reinitializing all objects backed by native graphics resources. */ @@ -5045,6 +5045,47 @@ void QRhi::releaseCachedResources() d->releaseCachedResources(); } +/*! + \return true if the graphics device was lost. + + The loss of the device is typically detected in beginFrame(), endFrame() or + QRhiSwapChain::buildOrResize(), depending on the backend and the underlying + native APIs. The most common is endFrame() because that is where presenting + happens. With some backends QRhiSwapChain::buildOrResize() can also fail + due to a device loss. Therefore this function is provided as a generic way + to check if a device loss was detected by a previous operation. + + When the device is lost, no further operations should be done via the QRhi. + Rather, all QRhi resources should be released, followed by destroying the + QRhi. A new QRhi can then be attempted to be created. If successful, all + graphics resources must be reinitialized. If not, try again later, + repeatedly. + + While simple applications may decide to not care about device loss, + on the commonly used desktop platforms a device loss can happen + due to a variety of reasons, including physically disconnecting the + graphics adapter, disabling the device or driver, uninstalling or upgrading + the graphics driver, or due to errors that lead to a graphics device reset. + Some of these can happen under perfectly normal circumstances as well, for + example the upgrade of the graphics driver to a newer version is a common + task that can happen at any time while a Qt application is running. Users + may very well expect applications to be able to survive this, even when the + application is actively using an API like OpenGL or Direct3D. + + Qt's own frameworks built on top of QRhi, such as, Qt Quick, can be + expected to handle and take appropriate measures when a device loss occurs. + If the data for graphics resources, such as textures and buffers, are still + available on the CPU side, such an event may not be noticeable on the + application level at all since graphics resources can seamlessly be + reinitialized then. However, applications and libraries working directly + with QRhi are expected to be prepared to check and handle device loss + situations themselves. + */ +bool QRhi::isDeviceLost() const +{ + return d->isDeviceLost(); +} + /*! \return a new graphics pipeline resource. diff --git a/src/gui/rhi/qrhi_p.h b/src/gui/rhi/qrhi_p.h index 928d1f8fa7..51e70af18e 100644 --- a/src/gui/rhi/qrhi_p.h +++ b/src/gui/rhi/qrhi_p.h @@ -1422,6 +1422,8 @@ public: void releaseCachedResources(); + bool isDeviceLost() const; + protected: QRhi(); diff --git a/src/gui/rhi/qrhi_p_p.h b/src/gui/rhi/qrhi_p_p.h index b69757ae6d..7c0b000c33 100644 --- a/src/gui/rhi/qrhi_p_p.h +++ b/src/gui/rhi/qrhi_p_p.h @@ -158,6 +158,7 @@ public: virtual void sendVMemStatsToProfiler() = 0; virtual void makeThreadLocalNativeContextCurrent() = 0; virtual void releaseCachedResources() = 0; + virtual bool isDeviceLost() const = 0; bool isCompressedFormat(QRhiTexture::Format format) const; void compressedFormatInfo(QRhiTexture::Format format, const QSize &size, diff --git a/src/gui/rhi/qrhid3d11.cpp b/src/gui/rhi/qrhid3d11.cpp index 119234035a..2350691dc0 100644 --- a/src/gui/rhi/qrhid3d11.cpp +++ b/src/gui/rhi/qrhid3d11.cpp @@ -267,6 +267,8 @@ bool QRhiD3D11::create(QRhi::Flags flags) if (FAILED(context->QueryInterface(IID_ID3DUserDefinedAnnotation, reinterpret_cast(&annotations)))) annotations = nullptr; + deviceLost = false; + nativeHandlesStruct.dev = dev; nativeHandlesStruct.context = context; @@ -487,6 +489,11 @@ void QRhiD3D11::releaseCachedResources() clearShaderCache(); } +bool QRhiD3D11::isDeviceLost() const +{ + return deviceLost; +} + QRhiRenderBuffer *QRhiD3D11::createRenderBuffer(QRhiRenderBuffer::Type type, const QSize &pixelSize, int sampleCount, QRhiRenderBuffer::Flags flags) { @@ -1003,8 +1010,14 @@ QRhi::FrameOpResult QRhiD3D11::endFrame(QRhiSwapChain *swapChain, QRhi::EndFrame if (!flags.testFlag(QRhi::SkipPresent)) { const UINT presentFlags = 0; HRESULT hr = swapChainD->swapChain->Present(swapChainD->swapInterval, presentFlags); - if (FAILED(hr)) + if (hr == DXGI_ERROR_DEVICE_REMOVED || hr == DXGI_ERROR_DEVICE_RESET) { + qWarning("Device loss detected in Present()"); + deviceLost = true; + return QRhi::FrameOpDeviceLost; + } else if (FAILED(hr)) { qWarning("Failed to present: %s", qPrintable(comErrorMessage(hr))); + return QRhi::FrameOpError; + } // move on to the next buffer swapChainD->currentFrameSlot = (swapChainD->currentFrameSlot + 1) % QD3D11SwapChain::BUFFER_COUNT; @@ -3850,7 +3863,11 @@ bool QD3D11SwapChain::buildOrResize() const UINT count = useFlipDiscard ? BUFFER_COUNT : 1; HRESULT hr = swapChain->ResizeBuffers(count, UINT(pixelSize.width()), UINT(pixelSize.height()), colorFormat, swapChainFlags); - if (FAILED(hr)) { + if (hr == DXGI_ERROR_DEVICE_REMOVED || hr == DXGI_ERROR_DEVICE_RESET) { + qWarning("Device loss detected in ResizeBuffers()"); + rhiD->deviceLost = true; + return false; + } else if (FAILED(hr)) { qWarning("Failed to resize D3D11 swapchain: %s", qPrintable(comErrorMessage(hr))); return false; } diff --git a/src/gui/rhi/qrhid3d11_p_p.h b/src/gui/rhi/qrhid3d11_p_p.h index cc4e095d10..da7fe84b1a 100644 --- a/src/gui/rhi/qrhid3d11_p_p.h +++ b/src/gui/rhi/qrhid3d11_p_p.h @@ -633,6 +633,7 @@ public: void sendVMemStatsToProfiler() override; void makeThreadLocalNativeContextCurrent() override; void releaseCachedResources() override; + bool isDeviceLost() const override; void enqueueSubresUpload(QD3D11Texture *texD, QD3D11CommandBuffer *cbD, int layer, int level, const QRhiTextureSubresourceUploadDescription &subresDesc); @@ -658,6 +659,7 @@ public: IDXGIFactory1 *dxgiFactory = nullptr; bool hasDxgi2 = false; bool supportsFlipDiscardSwapchain = false; + bool deviceLost = false; QRhiD3D11NativeHandles nativeHandlesStruct; struct { diff --git a/src/gui/rhi/qrhigles2.cpp b/src/gui/rhi/qrhigles2.cpp index 4d91ac45bd..d408490b34 100644 --- a/src/gui/rhi/qrhigles2.cpp +++ b/src/gui/rhi/qrhigles2.cpp @@ -772,6 +772,11 @@ void QRhiGles2::releaseCachedResources() m_shaderCache.clear(); } +bool QRhiGles2::isDeviceLost() const +{ + return false; +} + QRhiRenderBuffer *QRhiGles2::createRenderBuffer(QRhiRenderBuffer::Type type, const QSize &pixelSize, int sampleCount, QRhiRenderBuffer::Flags flags) { diff --git a/src/gui/rhi/qrhigles2_p_p.h b/src/gui/rhi/qrhigles2_p_p.h index 877eb88d27..3664e7162b 100644 --- a/src/gui/rhi/qrhigles2_p_p.h +++ b/src/gui/rhi/qrhigles2_p_p.h @@ -666,6 +666,7 @@ public: void sendVMemStatsToProfiler() override; void makeThreadLocalNativeContextCurrent() override; void releaseCachedResources() override; + bool isDeviceLost() const override; bool ensureContext(QSurface *surface = nullptr) const; void executeDeferredReleases(); diff --git a/src/gui/rhi/qrhimetal.mm b/src/gui/rhi/qrhimetal.mm index 3bf95ad676..770786db98 100644 --- a/src/gui/rhi/qrhimetal.mm +++ b/src/gui/rhi/qrhimetal.mm @@ -596,6 +596,11 @@ void QRhiMetal::releaseCachedResources() d->shaderCache.clear(); } +bool QRhiMetal::isDeviceLost() const +{ + return false; +} + QRhiRenderBuffer *QRhiMetal::createRenderBuffer(QRhiRenderBuffer::Type type, const QSize &pixelSize, int sampleCount, QRhiRenderBuffer::Flags flags) { diff --git a/src/gui/rhi/qrhimetal_p_p.h b/src/gui/rhi/qrhimetal_p_p.h index 01b0bf4f56..633e9b8de4 100644 --- a/src/gui/rhi/qrhimetal_p_p.h +++ b/src/gui/rhi/qrhimetal_p_p.h @@ -418,6 +418,7 @@ public: void sendVMemStatsToProfiler() override; void makeThreadLocalNativeContextCurrent() override; void releaseCachedResources() override; + bool isDeviceLost() const override; void executeDeferredReleases(bool forced = false); void finishActiveReadbacks(bool forced = false); diff --git a/src/gui/rhi/qrhinull.cpp b/src/gui/rhi/qrhinull.cpp index 29a3968bfc..b58d9f5c56 100644 --- a/src/gui/rhi/qrhinull.cpp +++ b/src/gui/rhi/qrhinull.cpp @@ -179,6 +179,11 @@ void QRhiNull::releaseCachedResources() // nothing to do here } +bool QRhiNull::isDeviceLost() const +{ + return false; +} + QRhiRenderBuffer *QRhiNull::createRenderBuffer(QRhiRenderBuffer::Type type, const QSize &pixelSize, int sampleCount, QRhiRenderBuffer::Flags flags) { diff --git a/src/gui/rhi/qrhinull_p_p.h b/src/gui/rhi/qrhinull_p_p.h index b43f830d5e..d6dbdbdc75 100644 --- a/src/gui/rhi/qrhinull_p_p.h +++ b/src/gui/rhi/qrhinull_p_p.h @@ -284,6 +284,7 @@ public: void sendVMemStatsToProfiler() override; void makeThreadLocalNativeContextCurrent() override; void releaseCachedResources() override; + bool isDeviceLost() const override; QRhiNullNativeHandles nativeHandlesStruct; QRhiSwapChain *currentSwapChain = nullptr; diff --git a/src/gui/rhi/qrhivulkan.cpp b/src/gui/rhi/qrhivulkan.cpp index c4f298dafb..5dd4b12329 100644 --- a/src/gui/rhi/qrhivulkan.cpp +++ b/src/gui/rhi/qrhivulkan.cpp @@ -3750,6 +3750,11 @@ void QRhiVulkan::releaseCachedResources() // nothing to do here } +bool QRhiVulkan::isDeviceLost() const +{ + return false; +} + QRhiRenderBuffer *QRhiVulkan::createRenderBuffer(QRhiRenderBuffer::Type type, const QSize &pixelSize, int sampleCount, QRhiRenderBuffer::Flags flags) { diff --git a/src/gui/rhi/qrhivulkan_p_p.h b/src/gui/rhi/qrhivulkan_p_p.h index 23cc80b814..0f16c54779 100644 --- a/src/gui/rhi/qrhivulkan_p_p.h +++ b/src/gui/rhi/qrhivulkan_p_p.h @@ -713,6 +713,7 @@ public: void sendVMemStatsToProfiler() override; void makeThreadLocalNativeContextCurrent() override; void releaseCachedResources() override; + bool isDeviceLost() const override; VkResult createDescriptorPool(VkDescriptorPool *pool); bool allocateDescriptorSet(VkDescriptorSetAllocateInfo *allocInfo, VkDescriptorSet *result, int *resultPoolIndex); -- cgit v1.2.3 From 8fef0ffc16ec9a88169349adfa8aafc9f375e94b Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Tue, 10 Sep 2019 16:49:58 +0200 Subject: rhi: vulkan: Report device lost MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Typically caught in vkQueueSubmit(). The WaitIdles that can be hit upon cleanup must be guarded by !deviceLost because they inexplicably cause an infinite blocking wait when the device was already reported as lost. (with NVIDIA at least) Change-Id: I7142e2461e1aed9ee3068b2b963cdf2c678ca4e0 Reviewed-by: Christian Strømme --- src/gui/rhi/qrhivulkan.cpp | 67 ++++++++++++++++++++++++-------------------- src/gui/rhi/qrhivulkan_p_p.h | 1 + 2 files changed, 38 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/gui/rhi/qrhivulkan.cpp b/src/gui/rhi/qrhivulkan.cpp index 5dd4b12329..1ed3ffc206 100644 --- a/src/gui/rhi/qrhivulkan.cpp +++ b/src/gui/rhi/qrhivulkan.cpp @@ -589,6 +589,8 @@ bool QRhiVulkan::create(QRhi::Flags flags) vkDebugMarkerSetObjectName = reinterpret_cast(f->vkGetDeviceProcAddr(dev, "vkDebugMarkerSetObjectNameEXT")); } + deviceLost = false; + nativeHandlesStruct.physDev = physDev; nativeHandlesStruct.dev = dev; nativeHandlesStruct.gfxQueueFamilyIdx = gfxQueueFamilyIdx; @@ -604,7 +606,8 @@ void QRhiVulkan::destroy() if (!df) return; - df->vkDeviceWaitIdle(dev); + if (!deviceLost) + df->vkDeviceWaitIdle(dev); executeDeferredReleases(true); finishActiveReadbacks(true); @@ -1425,7 +1428,8 @@ void QRhiVulkan::releaseSwapChainResources(QRhiSwapChain *swapChain) if (swapChainD->sc == VK_NULL_HANDLE) return; - df->vkDeviceWaitIdle(dev); + if (!deviceLost) + df->vkDeviceWaitIdle(dev); for (int i = 0; i < QVK_FRAMES_IN_FLIGHT; ++i) { QVkSwapChain::FrameResources &frame(swapChainD->frameRes[i]); @@ -1488,15 +1492,6 @@ void QRhiVulkan::releaseSwapChainResources(QRhiSwapChain *swapChain) // NB! surface and similar must remain intact } -static inline bool checkDeviceLost(VkResult err) -{ - if (err == VK_ERROR_DEVICE_LOST) { - qWarning("Device lost"); - return true; - } - return false; -} - QRhi::FrameOpResult QRhiVulkan::beginFrame(QRhiSwapChain *swapChain, QRhi::BeginFrameFlags flags) { QVkSwapChain *swapChainD = QRHI_RES(QVkSwapChain, swapChain); @@ -1523,10 +1518,12 @@ QRhi::FrameOpResult QRhiVulkan::beginFrame(QRhiSwapChain *swapChain, QRhi::Begin } else if (err == VK_ERROR_OUT_OF_DATE_KHR) { return QRhi::FrameOpSwapChainOutOfDate; } else { - if (checkDeviceLost(err)) + if (err == VK_ERROR_DEVICE_LOST) { + qWarning("Device loss detected in vkAcquireNextImageKHR()"); + deviceLost = true; return QRhi::FrameOpDeviceLost; - else - qWarning("Failed to acquire next swapchain image: %d", err); + } + qWarning("Failed to acquire next swapchain image: %d", err); return QRhi::FrameOpError; } } @@ -1690,10 +1687,12 @@ QRhi::FrameOpResult QRhiVulkan::endFrame(QRhiSwapChain *swapChain, QRhi::EndFram if (err == VK_ERROR_OUT_OF_DATE_KHR) { return QRhi::FrameOpSwapChainOutOfDate; } else if (err != VK_SUBOPTIMAL_KHR) { - if (checkDeviceLost(err)) + if (err == VK_ERROR_DEVICE_LOST) { + qWarning("Device loss detected in vkQueuePresentKHR()"); + deviceLost = true; return QRhi::FrameOpDeviceLost; - else - qWarning("Failed to present: %d", err); + } + qWarning("Failed to present: %d", err); return QRhi::FrameOpError; } } @@ -1750,10 +1749,12 @@ QRhi::FrameOpResult QRhiVulkan::startPrimaryCommandBuffer(VkCommandBuffer *cb) VkResult err = df->vkAllocateCommandBuffers(dev, &cmdBufInfo, cb); if (err != VK_SUCCESS) { - if (checkDeviceLost(err)) + if (err == VK_ERROR_DEVICE_LOST) { + qWarning("Device loss detected in vkAllocateCommandBuffers()"); + deviceLost = true; return QRhi::FrameOpDeviceLost; - else - qWarning("Failed to allocate frame command buffer: %d", err); + } + qWarning("Failed to allocate frame command buffer: %d", err); return QRhi::FrameOpError; } @@ -1763,10 +1764,12 @@ QRhi::FrameOpResult QRhiVulkan::startPrimaryCommandBuffer(VkCommandBuffer *cb) err = df->vkBeginCommandBuffer(*cb, &cmdBufBeginInfo); if (err != VK_SUCCESS) { - if (checkDeviceLost(err)) + if (err == VK_ERROR_DEVICE_LOST) { + qWarning("Device loss detected in vkBeginCommandBuffer()"); + deviceLost = true; return QRhi::FrameOpDeviceLost; - else - qWarning("Failed to begin frame command buffer: %d", err); + } + qWarning("Failed to begin frame command buffer: %d", err); return QRhi::FrameOpError; } @@ -1778,10 +1781,12 @@ QRhi::FrameOpResult QRhiVulkan::endAndSubmitPrimaryCommandBuffer(VkCommandBuffer { VkResult err = df->vkEndCommandBuffer(cb); if (err != VK_SUCCESS) { - if (checkDeviceLost(err)) + if (err == VK_ERROR_DEVICE_LOST) { + qWarning("Device loss detected in vkEndCommandBuffer()"); + deviceLost = true; return QRhi::FrameOpDeviceLost; - else - qWarning("Failed to end frame command buffer: %d", err); + } + qWarning("Failed to end frame command buffer: %d", err); return QRhi::FrameOpError; } @@ -1803,10 +1808,12 @@ QRhi::FrameOpResult QRhiVulkan::endAndSubmitPrimaryCommandBuffer(VkCommandBuffer err = df->vkQueueSubmit(gfxQueue, 1, &submitInfo, cmdFence); if (err != VK_SUCCESS) { - if (checkDeviceLost(err)) + if (err == VK_ERROR_DEVICE_LOST) { + qWarning("Device loss detected in vkQueueSubmit()"); + deviceLost = true; return QRhi::FrameOpDeviceLost; - else - qWarning("Failed to submit to graphics queue: %d", err); + } + qWarning("Failed to submit to graphics queue: %d", err); return QRhi::FrameOpError; } @@ -3752,7 +3759,7 @@ void QRhiVulkan::releaseCachedResources() bool QRhiVulkan::isDeviceLost() const { - return false; + return deviceLost; } QRhiRenderBuffer *QRhiVulkan::createRenderBuffer(QRhiRenderBuffer::Type type, const QSize &pixelSize, diff --git a/src/gui/rhi/qrhivulkan_p_p.h b/src/gui/rhi/qrhivulkan_p_p.h index 0f16c54779..a53b3b88fb 100644 --- a/src/gui/rhi/qrhivulkan_p_p.h +++ b/src/gui/rhi/qrhivulkan_p_p.h @@ -805,6 +805,7 @@ public: VkDeviceSize ubufAlign; VkDeviceSize texbufAlign; bool hasWideLines = false; + bool deviceLost = false; bool debugMarkersAvailable = false; bool vertexAttribDivisorAvailable = false; -- cgit v1.2.3 From f59f67287fa17e8d4edf6a231c010f768d1b76e8 Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Wed, 11 Sep 2019 11:39:18 +0200 Subject: QNetworkRequest: deprecate SPDY-related attributes for 5.15 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As they will be removed in Qt 6. Also, two H2-related attributes will be replaced by the new ones with their names corrected. Docs updated. Change-Id: I14eeb5fc077a101ca5d177c9369a088bdcb8297e Task-number: QTBUG-78255 Reviewed-by: Paul Wicking Reviewed-by: Edward Welbourne Reviewed-by: Mårten Nordheim --- src/network/access/qnetworkrequest.cpp | 13 ++++++++++--- src/network/access/qnetworkrequest.h | 12 +++++++++--- 2 files changed, 19 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/network/access/qnetworkrequest.cpp b/src/network/access/qnetworkrequest.cpp index 118fb6b1fb..cedb1597de 100644 --- a/src/network/access/qnetworkrequest.cpp +++ b/src/network/access/qnetworkrequest.cpp @@ -277,23 +277,30 @@ QT_BEGIN_NAMESPACE Indicates whether the QNetworkAccessManager code is allowed to use SPDY with this request. This applies only to SSL requests, and depends on the server supporting SPDY. + Obsolete, use Http2 instead of Spdy. \value SpdyWasUsedAttribute Replies only, type: QMetaType::Bool Indicates whether SPDY was used for receiving - this reply. + this reply. Obsolete, use Http2 instead of Spdy. - \value HTTP2AllowedAttribute + \value Http2AllowedAttribute Requests only, type: QMetaType::Bool (default: false) Indicates whether the QNetworkAccessManager code is allowed to use HTTP/2 with this request. This applies to SSL requests or 'cleartext' HTTP/2. - \value HTTP2WasUsedAttribute + \value Http2WasUsedAttribute Replies only, type: QMetaType::Bool (default: false) Indicates whether HTTP/2 was used for receiving this reply. (This value was introduced in 5.9.) + \value HTTP2AllowedAttribute + Obsolete alias for Http2AllowedAttribute. + + \value HTTP2WasUsedAttribute + Obsolete alias for Http2WasUsedAttribute. + \value EmitAllUploadProgressSignalsAttribute Requests only, type: QMetaType::Bool (default: false) Indicates whether all upload signals should be emitted. diff --git a/src/network/access/qnetworkrequest.h b/src/network/access/qnetworkrequest.h index e09ff8aaae..72a6555d91 100644 --- a/src/network/access/qnetworkrequest.h +++ b/src/network/access/qnetworkrequest.h @@ -89,12 +89,18 @@ public: DownloadBufferAttribute, // internal SynchronousRequestAttribute, // internal BackgroundRequestAttribute, +#if QT_DEPRECATED_SINCE(5, 15) SpdyAllowedAttribute, SpdyWasUsedAttribute, - EmitAllUploadProgressSignalsAttribute, +#endif // QT_DEPRECATED_SINCE(5, 15) + EmitAllUploadProgressSignalsAttribute = BackgroundRequestAttribute + 3, FollowRedirectsAttribute, - HTTP2AllowedAttribute, - HTTP2WasUsedAttribute, + Http2AllowedAttribute, + Http2WasUsedAttribute, +#if QT_DEPRECATED_SINCE(5, 15) + HTTP2AllowedAttribute Q_DECL_ENUMERATOR_DEPRECATED_X("Use Http2AllowedAttribute") = Http2AllowedAttribute, + HTTP2WasUsedAttribute Q_DECL_ENUMERATOR_DEPRECATED_X("Use Http2WasUsedAttribute"), +#endif // QT_DEPRECATED_SINCE(5, 15) OriginalContentLengthAttribute, RedirectPolicyAttribute, Http2DirectAttribute, -- cgit v1.2.3 From ef78a2e8f9bade867e43c75892353e38d48c595c Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Wed, 11 Sep 2019 11:09:05 +0200 Subject: rhi: Add a flag to indicate preferring a software adapter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ...if there is one and the concept is applicable in the first place. Change-Id: Iab202c1c1cdd229f4910159de4cae7ce30805ea9 Reviewed-by: Christian Strømme --- src/gui/rhi/qrhi.cpp | 12 ++++++++++++ src/gui/rhi/qrhi_p.h | 3 ++- src/gui/rhi/qrhid3d11.cpp | 25 ++++++++++++++++++++++++- src/gui/rhi/qrhivulkan.cpp | 24 ++++++++++++++++++++++-- 4 files changed, 60 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/gui/rhi/qrhi.cpp b/src/gui/rhi/qrhi.cpp index fbdc90bd1b..585dc8a8fa 100644 --- a/src/gui/rhi/qrhi.cpp +++ b/src/gui/rhi/qrhi.cpp @@ -439,6 +439,18 @@ Q_LOGGING_CATEGORY(QRHI_LOG_INFO, "qt.rhi.general") visible in external GPU debugging tools will not be available and functions like QRhiCommandBuffer::debugMarkBegin() will become a no-op. Avoid enabling in production builds as it may involve a performance penalty. + + \value PreferSoftwareRenderer Indicates that backends should prefer + choosing an adapter or physical device that renders in software on the CPU. + For example, with Direct3D there is typically a "Basic Render Driver" + adapter available with \c{DXGI_ADAPTER_FLAG_SOFTWARE}. Setting this flag + requests the backend to choose that adapter over any other, as long as no + specific adapter was forced by other backend-specific means. With Vulkan + this maps to preferring physical devices with + \c{VK_PHYSICAL_DEVICE_TYPE_CPU}. When not available, or when it is not + possible to decide if an adapter/device is software-based, this flag is + ignored. It may also be ignored with graphics APIs that have no concept and + means of enumerating adapters/devices. */ /*! diff --git a/src/gui/rhi/qrhi_p.h b/src/gui/rhi/qrhi_p.h index 51e70af18e..6f0b8e0b04 100644 --- a/src/gui/rhi/qrhi_p.h +++ b/src/gui/rhi/qrhi_p.h @@ -1294,7 +1294,8 @@ public: enum Flag { EnableProfiling = 1 << 0, - EnableDebugMarkers = 1 << 1 + EnableDebugMarkers = 1 << 1, + PreferSoftwareRenderer = 1 << 2 }; Q_DECLARE_FLAGS(Flags, Flag) diff --git a/src/gui/rhi/qrhid3d11.cpp b/src/gui/rhi/qrhid3d11.cpp index 2350691dc0..0977a3042d 100644 --- a/src/gui/rhi/qrhid3d11.cpp +++ b/src/gui/rhi/qrhid3d11.cpp @@ -119,6 +119,11 @@ QT_BEGIN_NAMESPACE \c{ID3D11Texture2D *}. */ +// help mingw with its ancient sdk headers +#ifndef DXGI_ADAPTER_FLAG_SOFTWARE +#define DXGI_ADAPTER_FLAG_SOFTWARE 2 +#endif + QRhiD3D11::QRhiD3D11(QRhiD3D11InitParams *params, QRhiD3D11NativeHandles *importDevice) : ofr(this), deviceCurse(this) @@ -227,11 +232,29 @@ bool QRhiD3D11::create(QRhi::Flags flags) int requestedAdapterIndex = -1; if (qEnvironmentVariableIsSet("QT_D3D_ADAPTER_INDEX")) requestedAdapterIndex = qEnvironmentVariableIntValue("QT_D3D_ADAPTER_INDEX"); + + if (requestedAdapterIndex < 0 && flags.testFlag(QRhi::PreferSoftwareRenderer)) { + for (int adapterIndex = 0; dxgiFactory->EnumAdapters1(UINT(adapterIndex), &adapter) != DXGI_ERROR_NOT_FOUND; ++adapterIndex) { + DXGI_ADAPTER_DESC1 desc; + adapter->GetDesc1(&desc); + adapter->Release(); + if (desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) { + requestedAdapterIndex = adapterIndex; + break; + } + } + } + for (int adapterIndex = 0; dxgiFactory->EnumAdapters1(UINT(adapterIndex), &adapter) != DXGI_ERROR_NOT_FOUND; ++adapterIndex) { DXGI_ADAPTER_DESC1 desc; adapter->GetDesc1(&desc); const QString name = QString::fromUtf16(reinterpret_cast(desc.Description)); - qCDebug(QRHI_LOG_INFO, "Adapter %d: '%s' (flags 0x%x)", adapterIndex, qPrintable(name), desc.Flags); + qCDebug(QRHI_LOG_INFO, "Adapter %d: '%s' (vendor 0x%X device 0x%X flags 0x%X)", + adapterIndex, + qPrintable(name), + desc.VendorId, + desc.DeviceId, + desc.Flags); if (!adapterToUse && (requestedAdapterIndex < 0 || requestedAdapterIndex == adapterIndex)) { adapterToUse = adapter; qCDebug(QRHI_LOG_INFO, " using this adapter"); diff --git a/src/gui/rhi/qrhivulkan.cpp b/src/gui/rhi/qrhivulkan.cpp index 1ed3ffc206..64fea37292 100644 --- a/src/gui/rhi/qrhivulkan.cpp +++ b/src/gui/rhi/qrhivulkan.cpp @@ -388,22 +388,42 @@ bool QRhiVulkan::create(QRhi::Flags flags) qWarning("Failed to enumerate physical devices: %d", err); return false; } + int physDevIndex = -1; int requestedPhysDevIndex = -1; if (qEnvironmentVariableIsSet("QT_VK_PHYSICAL_DEVICE_INDEX")) requestedPhysDevIndex = qEnvironmentVariableIntValue("QT_VK_PHYSICAL_DEVICE_INDEX"); + + if (requestedPhysDevIndex < 0 && flags.testFlag(QRhi::PreferSoftwareRenderer)) { + for (int i = 0; i < int(physDevCount); ++i) { + f->vkGetPhysicalDeviceProperties(physDevs[i], &physDevProperties); + if (physDevProperties.deviceType == VK_PHYSICAL_DEVICE_TYPE_CPU) { + requestedPhysDevIndex = i; + break; + } + } + } + for (int i = 0; i < int(physDevCount); ++i) { f->vkGetPhysicalDeviceProperties(physDevs[i], &physDevProperties); - qCDebug(QRHI_LOG_INFO, "Physical device %d: '%s' %d.%d.%d", i, + qCDebug(QRHI_LOG_INFO, "Physical device %d: '%s' %d.%d.%d (api %d.%d.%d vendor 0x%X device 0x%X type %d)", + i, physDevProperties.deviceName, VK_VERSION_MAJOR(physDevProperties.driverVersion), VK_VERSION_MINOR(physDevProperties.driverVersion), - VK_VERSION_PATCH(physDevProperties.driverVersion)); + VK_VERSION_PATCH(physDevProperties.driverVersion), + VK_VERSION_MAJOR(physDevProperties.apiVersion), + VK_VERSION_MINOR(physDevProperties.apiVersion), + VK_VERSION_PATCH(physDevProperties.apiVersion), + physDevProperties.vendorID, + physDevProperties.deviceID, + physDevProperties.deviceType); if (physDevIndex < 0 && (requestedPhysDevIndex < 0 || requestedPhysDevIndex == int(i))) { physDevIndex = i; qCDebug(QRHI_LOG_INFO, " using this physical device"); } } + if (physDevIndex < 0) { qWarning("No matching physical device"); return false; -- cgit v1.2.3 From 3d7207414b07104c1ea03ef341301a7390d7b0ad Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Mon, 9 Sep 2019 15:48:09 +0200 Subject: rhi: metal: Configure the layer's opaque property as appropriate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task-number: QTBUG-78089 Change-Id: I6cd95e24d38562cf1931c107bb6b719e340583a8 Reviewed-by: Christian Strømme --- src/gui/rhi/qrhimetal.mm | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src') diff --git a/src/gui/rhi/qrhimetal.mm b/src/gui/rhi/qrhimetal.mm index 770786db98..2d85c86bf0 100644 --- a/src/gui/rhi/qrhimetal.mm +++ b/src/gui/rhi/qrhimetal.mm @@ -3596,6 +3596,18 @@ bool QMetalSwapChain::buildOrResize() } #endif + if (m_flags.testFlag(SurfaceHasPreMulAlpha)) { + d->layer.opaque = NO; + } else if (m_flags.testFlag(SurfaceHasNonPreMulAlpha)) { + // The CoreAnimation compositor is said to expect premultiplied alpha, + // so this is then wrong when it comes to the blending operations but + // there's nothing we can do. Fortunately Qt Quick always outputs + // premultiplied alpha so it is not a problem there. + d->layer.opaque = NO; + } else { + d->layer.opaque = YES; + } + m_currentPixelSize = surfacePixelSize(); pixelSize = m_currentPixelSize; -- cgit v1.2.3 From 16da0b2cf8b6b344ae9dc37f46acec643c72fc28 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Wed, 11 Sep 2019 19:41:49 +0200 Subject: QTranslator doc: use QCoreApplication::installTranslator() The example snippet was using app.installTranslator() even installTranslator() is a static function. And since app is a QApplication instead a QCoreApplication this could lead to the assumption that a QTranslator can only be used for gui applications. Therefore use the correct static invocation QCoreApplication::installTranslator(). Change-Id: Ia3ce00f25230c2fe2bdc159ec14c88c961924651 Reviewed-by: Paul Wicking Reviewed-by: Friedemann Kleint --- src/corelib/doc/snippets/hellotrmain.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/corelib/doc/snippets/hellotrmain.cpp b/src/corelib/doc/snippets/hellotrmain.cpp index 2fab919a47..721a83240b 100644 --- a/src/corelib/doc/snippets/hellotrmain.cpp +++ b/src/corelib/doc/snippets/hellotrmain.cpp @@ -56,13 +56,13 @@ int main(int argc, char *argv[]) QTranslator translator; // look up e.g. :/translations/myapp_de.qm if (translator.load(QLocale(), QLatin1String("myapp"), QLatin1String("_"), QLatin1String(":/translations"))) - app.installTranslator(&translator); + QCoreApplication::installTranslator(&translator); QPushButton hello(QCoreApplication::translate("main", "Hello world!")); hello.resize(100, 30); hello.show(); - return app.exec(); + return QCoreApplication::exec(); } //! [0] -- 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') 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 351c738fc4586bf354c9363fb78e190bdfca4617 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 12 Sep 2019 11:07:31 +0200 Subject: QPointer: some simplifications - don't write explicit meta functions, use std::conditional - = default the default ctor The class is already not trivially-copyable, so making the default ctor trivial doesn't change the ABI. Change-Id: I8e35bbbb35973c9ff8fc48dfbfc10061de4bfd30 Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/corelib/kernel/qpointer.h | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/corelib/kernel/qpointer.h b/src/corelib/kernel/qpointer.h index 7052bcf0d4..5efdb0b395 100644 --- a/src/corelib/kernel/qpointer.h +++ b/src/corelib/kernel/qpointer.h @@ -54,20 +54,11 @@ class QPointer { Q_STATIC_ASSERT_X(!std::is_pointer::value, "QPointer's template type must not be a pointer type"); - template - struct TypeSelector - { - typedef QObject Type; - }; - template - struct TypeSelector - { - typedef const QObject Type; - }; - typedef typename TypeSelector::Type QObjectType; + using QObjectType = + typename std::conditional::value, const QObject, QObject>::type; QWeakPointer wp; public: - inline QPointer() { } + QPointer() = default; inline QPointer(T *p) : wp(p, true) { } // compiler-generated copy/move ctor/assignment operators are fine! // compiler-generated dtor is fine! -- cgit v1.2.3 From 68b30a23a8ee66de4da62dcddfe2072c01945c24 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 10 Sep 2019 19:27:43 +0200 Subject: Port QReadWriteLock from QMutexLocker to qt_unique_lock MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Most of these are unique_locks because they call QWaitCondition::wait() and it doesn't feel right to use qt_scoped_lock if the lock is dropped within the scope. Change-Id: I506eede63008dad135c21112e578da4f7684e528 Reviewed-by: Mårten Nordheim --- src/corelib/thread/qreadwritelock.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/corelib/thread/qreadwritelock.cpp b/src/corelib/thread/qreadwritelock.cpp index 30e9b95a52..14654986a0 100644 --- a/src/corelib/thread/qreadwritelock.cpp +++ b/src/corelib/thread/qreadwritelock.cpp @@ -48,6 +48,7 @@ #include "qreadwritelock_p.h" #include "qelapsedtimer.h" #include "private/qfreelist_p.h" +#include "private/qlocking_p.h" QT_BEGIN_NAMESPACE @@ -262,7 +263,7 @@ bool QReadWriteLock::tryLockForRead(int timeout) if (d->recursive) return d->recursiveLockForRead(timeout); - QMutexLocker lock(&d->mutex); + auto lock = qt_unique_lock(d->mutex); if (d != d_ptr.loadRelaxed()) { // d_ptr has changed: this QReadWriteLock was unlocked before we had // time to lock d->mutex. @@ -369,7 +370,7 @@ bool QReadWriteLock::tryLockForWrite(int timeout) if (d->recursive) return d->recursiveLockForWrite(timeout); - QMutexLocker lock(&d->mutex); + auto lock = qt_unique_lock(d->mutex); if (d != d_ptr.loadRelaxed()) { // The mutex was unlocked before we had time to lock the mutex. // We are holding to a mutex within a QReadWriteLockPrivate that is already released @@ -418,7 +419,7 @@ void QReadWriteLock::unlock() return; } - QMutexLocker locker(&d->mutex); + const auto lock = qt_scoped_lock(d->mutex); if (d->writerCount) { Q_ASSERT(d->writerCount == 1); Q_ASSERT(d->readerCount == 0); @@ -536,7 +537,7 @@ void QReadWriteLockPrivate::unlock() bool QReadWriteLockPrivate::recursiveLockForRead(int timeout) { Q_ASSERT(recursive); - QMutexLocker lock(&mutex); + auto lock = qt_unique_lock(mutex); Qt::HANDLE self = QThread::currentThreadId(); @@ -556,7 +557,7 @@ bool QReadWriteLockPrivate::recursiveLockForRead(int timeout) bool QReadWriteLockPrivate::recursiveLockForWrite(int timeout) { Q_ASSERT(recursive); - QMutexLocker lock(&mutex); + auto lock = qt_unique_lock(mutex); Qt::HANDLE self = QThread::currentThreadId(); if (currentWriter == self) { @@ -574,7 +575,7 @@ bool QReadWriteLockPrivate::recursiveLockForWrite(int timeout) void QReadWriteLockPrivate::recursiveUnlock() { Q_ASSERT(recursive); - QMutexLocker lock(&mutex); + auto lock = qt_unique_lock(mutex); Qt::HANDLE self = QThread::currentThreadId(); if (self == currentWriter) { -- cgit v1.2.3 From 319c4786036b5f45fc95c683cef5cf5ba2ce2a6d Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 23 Aug 2019 15:05:32 +0200 Subject: QReadWriteLock: replace (QWaitCondition, QMutex) with std::(condition_variable, mutex) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It turns out that QWaitCondition is a std::condition_variable_any. The _any variant works with any mutex type, but requires a native mutex for the native condition variable. So, QWaitCondition and std::condition_variable_any both require two different mutexes: the one the user passes in, and an internal one. std::condition_variable, however, only works with std::mutex, and since both are backed by the native API, condition_variable can use the mutex passed in by the user instead of having to use an internal one. So, port from 2 × QWaitCondition + QMutex (2 × native cond + 2 × native mutex + Qt mutex) to std::condition_variable + std::mutex (2 × native cond + native mutex), shaving the overhead of two additional mutexes (one Qt, one native) as well as the memory allocation performed by QWaitCondition (for its Private). Speeds up the writeOnly case by ~1/8th: PASS : tst_QReadWriteLock::writeOnly(QReadWriteLock) RESULT : tst_QReadWriteLock::writeOnly():"QReadWriteLock": - 39,703 msecs per iteration (total: 39,703, iterations: 1) + 34,950 msecs per iteration (total: 34,950, iterations: 1) Change-Id: I196cb13a27242fc1cb99723dfab5b2e5f8522143 Reviewed-by: Edward Welbourne Reviewed-by: Mårten Nordheim Reviewed-by: Olivier Goffart (Woboq GmbH) Reviewed-by: Volker Hilsheimer --- src/corelib/thread/qreadwritelock.cpp | 37 ++++++++++++++++++++--------------- src/corelib/thread/qreadwritelock_p.h | 14 +++++++------ 2 files changed, 29 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/corelib/thread/qreadwritelock.cpp b/src/corelib/thread/qreadwritelock.cpp index 14654986a0..5aba05c1b9 100644 --- a/src/corelib/thread/qreadwritelock.cpp +++ b/src/corelib/thread/qreadwritelock.cpp @@ -50,6 +50,8 @@ #include "private/qfreelist_p.h" #include "private/qlocking_p.h" +#include + QT_BEGIN_NAMESPACE /* @@ -65,6 +67,9 @@ QT_BEGIN_NAMESPACE */ namespace { + +using ms = std::chrono::milliseconds; + enum { StateMask = 0x3, StateLockedForRead = 0x1, @@ -274,7 +279,7 @@ bool QReadWriteLock::tryLockForRead(int timeout) d = d_ptr.loadAcquire(); continue; } - return d->lockForRead(timeout); + return d->lockForRead(lock, timeout); } } @@ -378,7 +383,7 @@ bool QReadWriteLock::tryLockForWrite(int timeout) d = d_ptr.loadAcquire(); continue; } - return d->lockForWrite(timeout); + return d->lockForWrite(lock, timeout); } } @@ -461,9 +466,9 @@ QReadWriteLock::StateForWaitCondition QReadWriteLock::stateForWaitCondition() co } -bool QReadWriteLockPrivate::lockForRead(int timeout) +bool QReadWriteLockPrivate::lockForRead(std::unique_lock &lock, int timeout) { - Q_ASSERT(!mutex.tryLock()); // mutex must be locked when entering this function + Q_ASSERT(!mutex.try_lock()); // mutex must be locked when entering this function QElapsedTimer t; if (timeout > 0) @@ -477,10 +482,10 @@ bool QReadWriteLockPrivate::lockForRead(int timeout) if (elapsed > timeout) return false; waitingReaders++; - readerCond.wait(&mutex, timeout - elapsed); + readerCond.wait_for(lock, ms{timeout - elapsed}); } else { waitingReaders++; - readerCond.wait(&mutex); + readerCond.wait(lock); } waitingReaders--; } @@ -489,9 +494,9 @@ bool QReadWriteLockPrivate::lockForRead(int timeout) return true; } -bool QReadWriteLockPrivate::lockForWrite(int timeout) +bool QReadWriteLockPrivate::lockForWrite(std::unique_lock &lock, int timeout) { - Q_ASSERT(!mutex.tryLock()); // mutex must be locked when entering this function + Q_ASSERT(!mutex.try_lock()); // mutex must be locked when entering this function QElapsedTimer t; if (timeout > 0) @@ -506,15 +511,15 @@ bool QReadWriteLockPrivate::lockForWrite(int timeout) if (waitingReaders && !waitingWriters && !writerCount) { // We timed out and now there is no more writers or waiting writers, but some // readers were queueud (probably because of us). Wake the waiting readers. - readerCond.wakeAll(); + readerCond.notify_all(); } return false; } waitingWriters++; - writerCond.wait(&mutex, timeout - elapsed); + writerCond.wait_for(lock, ms{timeout - elapsed}); } else { waitingWriters++; - writerCond.wait(&mutex); + writerCond.wait(lock); } waitingWriters--; } @@ -527,11 +532,11 @@ bool QReadWriteLockPrivate::lockForWrite(int timeout) void QReadWriteLockPrivate::unlock() { - Q_ASSERT(!mutex.tryLock()); // mutex must be locked when entering this function + Q_ASSERT(!mutex.try_lock()); // mutex must be locked when entering this function if (waitingWriters) - writerCond.wakeOne(); + writerCond.notify_one(); else if (waitingReaders) - readerCond.wakeAll(); + readerCond.notify_all(); } bool QReadWriteLockPrivate::recursiveLockForRead(int timeout) @@ -547,7 +552,7 @@ bool QReadWriteLockPrivate::recursiveLockForRead(int timeout) return true; } - if (!lockForRead(timeout)) + if (!lockForRead(lock, timeout)) return false; currentReaders.insert(self, 1); @@ -565,7 +570,7 @@ bool QReadWriteLockPrivate::recursiveLockForWrite(int timeout) return true; } - if (!lockForWrite(timeout)) + if (!lockForWrite(lock, timeout)) return false; currentWriter = self; diff --git a/src/corelib/thread/qreadwritelock_p.h b/src/corelib/thread/qreadwritelock_p.h index a4d002b7f2..b2e782f9ee 100644 --- a/src/corelib/thread/qreadwritelock_p.h +++ b/src/corelib/thread/qreadwritelock_p.h @@ -54,7 +54,9 @@ #include #include -#include + +#include +#include QT_REQUIRE_CONFIG(thread); @@ -66,9 +68,9 @@ public: explicit QReadWriteLockPrivate(bool isRecursive = false) : recursive(isRecursive) {} - QMutex mutex; - QWaitCondition writerCond; - QWaitCondition readerCond; + std::mutex mutex; + std::condition_variable writerCond; + std::condition_variable readerCond; int readerCount = 0; int writerCount = 0; int waitingReaders = 0; @@ -76,8 +78,8 @@ public: const bool recursive; //Called with the mutex locked - bool lockForWrite(int timeout); - bool lockForRead(int timeout); + bool lockForWrite(std::unique_lock &lock, int timeout); + bool lockForRead(std::unique_lock &lock, int timeout); void unlock(); //memory management -- 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') 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') 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 af1c3bf884c896e42fd2a8b7847ae86743b2c4ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Thu, 5 Sep 2019 12:22:13 +0200 Subject: qnetconmonitor_win: Mark destructors virtual After these two classes were no longer marked final clang started complaining because their dtor is not marked virtual. Amends 9dc594b2bf3572aa5df3ec3ad2b9842c96e8290d Change-Id: I42b78c0b444935d3e0cb4d476d3881fd5fb5c3cb Reviewed-by: Timur Pocheptsov Reviewed-by: Friedemann Kleint --- src/network/kernel/qnetconmonitor_win.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/network/kernel/qnetconmonitor_win.cpp b/src/network/kernel/qnetconmonitor_win.cpp index a010df8e3a..1566e7f914 100644 --- a/src/network/kernel/qnetconmonitor_win.cpp +++ b/src/network/kernel/qnetconmonitor_win.cpp @@ -103,7 +103,7 @@ class QNetworkConnectionEvents : public INetworkConnectionEvents { public: QNetworkConnectionEvents(QNetworkConnectionMonitorPrivate *monitor); - ~QNetworkConnectionEvents(); + virtual ~QNetworkConnectionEvents(); HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject) override; @@ -471,7 +471,7 @@ class QNetworkListManagerEvents : public INetworkListManagerEvents { public: QNetworkListManagerEvents(QNetworkStatusMonitorPrivate *monitor); - ~QNetworkListManagerEvents(); + virtual ~QNetworkListManagerEvents(); HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject) override; -- cgit v1.2.3 From 39b0a6f152d70eff50fde978c074a6a0860e6394 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Thu, 12 Sep 2019 16:09:36 +0200 Subject: rhi: gl: Pick up context loss MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ...and change the return value of makeThreadLocalNativeContextCurrent() to a bool since we expect this to mirror QOpenGLContext::makeCurrent(). Change-Id: I339507152e461fe28fcf7fe777165e6d0072f055 Reviewed-by: Christian Strømme --- src/gui/rhi/qrhi.cpp | 43 ++++++++++++++++++++++++++++++++++++++----- src/gui/rhi/qrhi_p.h | 2 +- src/gui/rhi/qrhi_p_p.h | 2 +- src/gui/rhi/qrhid3d11.cpp | 5 +++-- src/gui/rhi/qrhid3d11_p_p.h | 2 +- src/gui/rhi/qrhigles2.cpp | 29 ++++++++++++++++++----------- src/gui/rhi/qrhigles2_p_p.h | 3 ++- src/gui/rhi/qrhimetal.mm | 5 +++-- src/gui/rhi/qrhimetal_p_p.h | 2 +- src/gui/rhi/qrhinull.cpp | 5 +++-- src/gui/rhi/qrhinull_p_p.h | 2 +- src/gui/rhi/qrhivulkan.cpp | 5 +++-- src/gui/rhi/qrhivulkan_p_p.h | 2 +- 13 files changed, 76 insertions(+), 31 deletions(-) (limited to 'src') diff --git a/src/gui/rhi/qrhi.cpp b/src/gui/rhi/qrhi.cpp index 585dc8a8fa..858be0159b 100644 --- a/src/gui/rhi/qrhi.cpp +++ b/src/gui/rhi/qrhi.cpp @@ -468,7 +468,7 @@ Q_LOGGING_CATEGORY(QRHI_LOG_INFO, "qt.rhi.general") \value FrameOpDeviceLost The graphics device was lost. This can be recoverable by attempting to repeat the operation (such as, beginFrame()) after releasing and reinitializing all objects backed by native graphics - resources. + resources. See isDeviceLost(). */ /*! @@ -5022,10 +5022,17 @@ const QRhiNativeHandles *QRhi::nativeHandles() has to ensure external OpenGL code provided by the application can still run like it did before with direct usage of OpenGL, as long as the QRhi is using the OpenGL backend. + + \return false when failed, similarly to QOpenGLContext::makeCurrent(). When + the operation failed, isDeviceLost() can be called to determine if there + was a loss of context situation. Such a check is equivalent to checking via + QOpenGLContext::isValid(). + + \sa QOpenGLContext::makeCurrent(), QOpenGLContext::isValid() */ -void QRhi::makeThreadLocalNativeContextCurrent() +bool QRhi::makeThreadLocalNativeContextCurrent() { - d->makeThreadLocalNativeContextCurrent(); + return d->makeThreadLocalNativeContextCurrent(); } /*! @@ -5092,6 +5099,12 @@ void QRhi::releaseCachedResources() reinitialized then. However, applications and libraries working directly with QRhi are expected to be prepared to check and handle device loss situations themselves. + + \note With OpenGL, applications may need to opt-in to context reset + notifications by setting QSurfaceFormat::ResetNotification on the + QOpenGLContext. This is typically done by enabling the flag in + QRhiGles2InitParams::format. Keep in mind however that some systems may + generate context resets situations even when this flag is not set. */ bool QRhi::isDeviceLost() const { @@ -5259,7 +5272,17 @@ QRhiSwapChain *QRhi::newSwapChain() \endlist - \sa endFrame(), beginOffscreenFrame() + \return QRhi::FrameOpSuccess on success, or another QRhi::FrameOpResult + value on failure. Some of these should be treated as soft, "try again + later" type of errors: When QRhi::FrameOpSwapChainOutOfDate is returned, + the swapchain is to be resized or updated by calling + QRhiSwapChain::buildOrResize(). The application should then attempt to + generate a new frame. QRhi::FrameOpDeviceLost means the graphics device is + lost but this may also be recoverable by releasing all resources, including + the QRhi itself, and then recreating all resources. See isDeviceLost() for + further discussion. + + \sa endFrame(), beginOffscreenFrame(), isDeviceLost() */ QRhi::FrameOpResult QRhi::beginFrame(QRhiSwapChain *swapChain, BeginFrameFlags flags) { @@ -5284,7 +5307,17 @@ QRhi::FrameOpResult QRhi::beginFrame(QRhiSwapChain *swapChain, BeginFrameFlags f Passing QRhi::SkipPresent skips queuing the Present command or calling swapBuffers. - \sa beginFrame() + \return QRhi::FrameOpSuccess on success, or another QRhi::FrameOpResult + value on failure. Some of these should be treated as soft, "try again + later" type of errors: When QRhi::FrameOpSwapChainOutOfDate is returned, + the swapchain is to be resized or updated by calling + QRhiSwapChain::buildOrResize(). The application should then attempt to + generate a new frame. QRhi::FrameOpDeviceLost means the graphics device is + lost but this may also be recoverable by releasing all resources, including + the QRhi itself, and then recreating all resources. See isDeviceLost() for + further discussion. + + \sa beginFrame(), isDeviceLost() */ QRhi::FrameOpResult QRhi::endFrame(QRhiSwapChain *swapChain, EndFrameFlags flags) { diff --git a/src/gui/rhi/qrhi_p.h b/src/gui/rhi/qrhi_p.h index 6f0b8e0b04..c73f03cf72 100644 --- a/src/gui/rhi/qrhi_p.h +++ b/src/gui/rhi/qrhi_p.h @@ -1414,7 +1414,7 @@ public: int resourceLimit(ResourceLimit limit) const; const QRhiNativeHandles *nativeHandles(); - void makeThreadLocalNativeContextCurrent(); + bool makeThreadLocalNativeContextCurrent(); QRhiProfiler *profiler(); diff --git a/src/gui/rhi/qrhi_p_p.h b/src/gui/rhi/qrhi_p_p.h index 7c0b000c33..63f27b6de4 100644 --- a/src/gui/rhi/qrhi_p_p.h +++ b/src/gui/rhi/qrhi_p_p.h @@ -156,7 +156,7 @@ public: virtual int resourceLimit(QRhi::ResourceLimit limit) const = 0; virtual const QRhiNativeHandles *nativeHandles() = 0; virtual void sendVMemStatsToProfiler() = 0; - virtual void makeThreadLocalNativeContextCurrent() = 0; + virtual bool makeThreadLocalNativeContextCurrent() = 0; virtual void releaseCachedResources() = 0; virtual bool isDeviceLost() const = 0; diff --git a/src/gui/rhi/qrhid3d11.cpp b/src/gui/rhi/qrhid3d11.cpp index 0977a3042d..1d2f3cfa80 100644 --- a/src/gui/rhi/qrhid3d11.cpp +++ b/src/gui/rhi/qrhid3d11.cpp @@ -502,9 +502,10 @@ void QRhiD3D11::sendVMemStatsToProfiler() // nothing to do here } -void QRhiD3D11::makeThreadLocalNativeContextCurrent() +bool QRhiD3D11::makeThreadLocalNativeContextCurrent() { - // nothing to do here + // not applicable + return false; } void QRhiD3D11::releaseCachedResources() diff --git a/src/gui/rhi/qrhid3d11_p_p.h b/src/gui/rhi/qrhid3d11_p_p.h index da7fe84b1a..cf4808510c 100644 --- a/src/gui/rhi/qrhid3d11_p_p.h +++ b/src/gui/rhi/qrhid3d11_p_p.h @@ -631,7 +631,7 @@ public: int resourceLimit(QRhi::ResourceLimit limit) const override; const QRhiNativeHandles *nativeHandles() override; void sendVMemStatsToProfiler() override; - void makeThreadLocalNativeContextCurrent() override; + bool makeThreadLocalNativeContextCurrent() override; void releaseCachedResources() override; bool isDeviceLost() const override; diff --git a/src/gui/rhi/qrhigles2.cpp b/src/gui/rhi/qrhigles2.cpp index d408490b34..2d51d892e3 100644 --- a/src/gui/rhi/qrhigles2.cpp +++ b/src/gui/rhi/qrhigles2.cpp @@ -371,7 +371,12 @@ bool QRhiGles2::ensureContext(QSurface *surface) const return true; if (!ctx->makeCurrent(surface)) { - qWarning("QRhiGles2: Failed to make context current. Expect bad things to happen."); + if (ctx->isValid()) { + qWarning("QRhiGles2: Failed to make context current. Expect bad things to happen."); + } else { + qWarning("QRhiGles2: Context is lost."); + contextLost = true; + } return false; } @@ -491,6 +496,8 @@ bool QRhiGles2::create(QRhi::Flags flags) nativeHandlesStruct.context = ctx; + contextLost = false; + return true; } @@ -753,12 +760,12 @@ void QRhiGles2::sendVMemStatsToProfiler() // nothing to do here } -void QRhiGles2::makeThreadLocalNativeContextCurrent() +bool QRhiGles2::makeThreadLocalNativeContextCurrent() { if (inFrame && !ofr.active) - ensureContext(currentSwapChain->surface); + return ensureContext(currentSwapChain->surface); else - ensureContext(); + return ensureContext(); } void QRhiGles2::releaseCachedResources() @@ -774,7 +781,7 @@ void QRhiGles2::releaseCachedResources() bool QRhiGles2::isDeviceLost() const { - return false; + return contextLost; } QRhiRenderBuffer *QRhiGles2::createRenderBuffer(QRhiRenderBuffer::Type type, const QSize &pixelSize, @@ -1161,7 +1168,7 @@ QRhi::FrameOpResult QRhiGles2::beginFrame(QRhiSwapChain *swapChain, QRhi::BeginF QGles2SwapChain *swapChainD = QRHI_RES(QGles2SwapChain, swapChain); if (!ensureContext(swapChainD->surface)) - return QRhi::FrameOpError; + return contextLost ? QRhi::FrameOpDeviceLost : QRhi::FrameOpError; currentSwapChain = swapChainD; @@ -1184,7 +1191,7 @@ QRhi::FrameOpResult QRhiGles2::endFrame(QRhiSwapChain *swapChain, QRhi::EndFrame addBoundaryCommand(&swapChainD->cb, QGles2CommandBuffer::Command::EndFrame); if (!ensureContext(swapChainD->surface)) - return QRhi::FrameOpError; + return contextLost ? QRhi::FrameOpDeviceLost : QRhi::FrameOpError; executeCommandBuffer(&swapChainD->cb); @@ -1208,7 +1215,7 @@ QRhi::FrameOpResult QRhiGles2::beginOffscreenFrame(QRhiCommandBuffer **cb, QRhi: { Q_UNUSED(flags); if (!ensureContext()) - return QRhi::FrameOpError; + return contextLost ? QRhi::FrameOpDeviceLost : QRhi::FrameOpError; ofr.active = true; @@ -1230,7 +1237,7 @@ QRhi::FrameOpResult QRhiGles2::endOffscreenFrame(QRhi::EndFrameFlags flags) addBoundaryCommand(&ofr.cbWrapper, QGles2CommandBuffer::Command::EndFrame); if (!ensureContext()) - return QRhi::FrameOpError; + return contextLost ? QRhi::FrameOpDeviceLost : QRhi::FrameOpError; executeCommandBuffer(&ofr.cbWrapper); @@ -1244,14 +1251,14 @@ QRhi::FrameOpResult QRhiGles2::finish() Q_ASSERT(!currentSwapChain); Q_ASSERT(ofr.cbWrapper.recordingPass == QGles2CommandBuffer::NoPass); if (!ensureContext()) - return QRhi::FrameOpError; + return contextLost ? QRhi::FrameOpDeviceLost : QRhi::FrameOpError; executeCommandBuffer(&ofr.cbWrapper); ofr.cbWrapper.resetCommands(); } else { Q_ASSERT(currentSwapChain); Q_ASSERT(currentSwapChain->cb.recordingPass == QGles2CommandBuffer::NoPass); if (!ensureContext(currentSwapChain->surface)) - return QRhi::FrameOpError; + return contextLost ? QRhi::FrameOpDeviceLost : QRhi::FrameOpError; executeCommandBuffer(¤tSwapChain->cb); currentSwapChain->cb.resetCommands(); } diff --git a/src/gui/rhi/qrhigles2_p_p.h b/src/gui/rhi/qrhigles2_p_p.h index 3664e7162b..e7bcb626b6 100644 --- a/src/gui/rhi/qrhigles2_p_p.h +++ b/src/gui/rhi/qrhigles2_p_p.h @@ -664,7 +664,7 @@ public: int resourceLimit(QRhi::ResourceLimit limit) const override; const QRhiNativeHandles *nativeHandles() override; void sendVMemStatsToProfiler() override; - void makeThreadLocalNativeContextCurrent() override; + bool makeThreadLocalNativeContextCurrent() override; void releaseCachedResources() override; bool isDeviceLost() const override; @@ -770,6 +770,7 @@ public: QVector supportedCompressedFormats; mutable QVector supportedSampleCountList; QRhiGles2NativeHandles nativeHandlesStruct; + mutable bool contextLost = false; struct DeferredReleaseEntry { enum Type { diff --git a/src/gui/rhi/qrhimetal.mm b/src/gui/rhi/qrhimetal.mm index 2d85c86bf0..0b1ab72c2c 100644 --- a/src/gui/rhi/qrhimetal.mm +++ b/src/gui/rhi/qrhimetal.mm @@ -583,9 +583,10 @@ void QRhiMetal::sendVMemStatsToProfiler() // nothing to do here } -void QRhiMetal::makeThreadLocalNativeContextCurrent() +bool QRhiMetal::makeThreadLocalNativeContextCurrent() { - // nothing to do here + // not applicable + return false; } void QRhiMetal::releaseCachedResources() diff --git a/src/gui/rhi/qrhimetal_p_p.h b/src/gui/rhi/qrhimetal_p_p.h index 633e9b8de4..a08f56072a 100644 --- a/src/gui/rhi/qrhimetal_p_p.h +++ b/src/gui/rhi/qrhimetal_p_p.h @@ -416,7 +416,7 @@ public: int resourceLimit(QRhi::ResourceLimit limit) const override; const QRhiNativeHandles *nativeHandles() override; void sendVMemStatsToProfiler() override; - void makeThreadLocalNativeContextCurrent() override; + bool makeThreadLocalNativeContextCurrent() override; void releaseCachedResources() override; bool isDeviceLost() const override; diff --git a/src/gui/rhi/qrhinull.cpp b/src/gui/rhi/qrhinull.cpp index b58d9f5c56..60d620813b 100644 --- a/src/gui/rhi/qrhinull.cpp +++ b/src/gui/rhi/qrhinull.cpp @@ -169,9 +169,10 @@ void QRhiNull::sendVMemStatsToProfiler() // nothing to do here } -void QRhiNull::makeThreadLocalNativeContextCurrent() +bool QRhiNull::makeThreadLocalNativeContextCurrent() { - // nothing to do here + // not applicable + return false; } void QRhiNull::releaseCachedResources() diff --git a/src/gui/rhi/qrhinull_p_p.h b/src/gui/rhi/qrhinull_p_p.h index d6dbdbdc75..ee301d247b 100644 --- a/src/gui/rhi/qrhinull_p_p.h +++ b/src/gui/rhi/qrhinull_p_p.h @@ -282,7 +282,7 @@ public: int resourceLimit(QRhi::ResourceLimit limit) const override; const QRhiNativeHandles *nativeHandles() override; void sendVMemStatsToProfiler() override; - void makeThreadLocalNativeContextCurrent() override; + bool makeThreadLocalNativeContextCurrent() override; void releaseCachedResources() override; bool isDeviceLost() const override; diff --git a/src/gui/rhi/qrhivulkan.cpp b/src/gui/rhi/qrhivulkan.cpp index 64fea37292..444c91dd75 100644 --- a/src/gui/rhi/qrhivulkan.cpp +++ b/src/gui/rhi/qrhivulkan.cpp @@ -3767,9 +3767,10 @@ void QRhiVulkan::sendVMemStatsToProfiler() quint32(stats.total.usedBytes), quint32(stats.total.unusedBytes))); } -void QRhiVulkan::makeThreadLocalNativeContextCurrent() +bool QRhiVulkan::makeThreadLocalNativeContextCurrent() { - // nothing to do here + // not applicable + return false; } void QRhiVulkan::releaseCachedResources() diff --git a/src/gui/rhi/qrhivulkan_p_p.h b/src/gui/rhi/qrhivulkan_p_p.h index a53b3b88fb..a390bc3707 100644 --- a/src/gui/rhi/qrhivulkan_p_p.h +++ b/src/gui/rhi/qrhivulkan_p_p.h @@ -711,7 +711,7 @@ public: int resourceLimit(QRhi::ResourceLimit limit) const override; const QRhiNativeHandles *nativeHandles() override; void sendVMemStatsToProfiler() override; - void makeThreadLocalNativeContextCurrent() override; + bool makeThreadLocalNativeContextCurrent() override; void releaseCachedResources() override; bool isDeviceLost() const override; -- cgit v1.2.3 From 8286daba038d3c90d2bc06785ffcf9c0c603cb83 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Thu, 5 Sep 2019 17:18:56 +0200 Subject: MS TZ data: avoid calculating a date in year 0 There is no year 0 in the proleptic Gregorian calendar, so QDate() won't be happy if asked for a date in it. Tweak scanning of the data we get from MS-Win so as to avoid a date calculation that could otherwise happen in year 0 when constructing QDateTime(QDate(1, 1, 1), QTime(0, 0, 0), QTimeZone("Australia/Sydney")). Added a test for this case, which Oliver Wolff has kindly verified does reproduce the assertion failure. However, Coin is unable to reproduce, as all its MS builds are configured with -release, so Q_ASSERT() does nothing. (The relevant code then skips over year 0, albeit for the wrong reasons, and gets the right results, albeit inefficiently, leaving no other symptom by which to detect the problem.) Fixes: QTBUG-78051 Change-Id: Ife8a7470e5bd450bc421e89b3f1e1211756fc889 Reviewed-by: Qt CI Bot Reviewed-by: Oliver Wolff Reviewed-by: Volker Hilsheimer --- src/corelib/time/qtimezoneprivate_win.cpp | 42 +++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/corelib/time/qtimezoneprivate_win.cpp b/src/corelib/time/qtimezoneprivate_win.cpp index 1bf2366748..5a480222e0 100644 --- a/src/corelib/time/qtimezoneprivate_win.cpp +++ b/src/corelib/time/qtimezoneprivate_win.cpp @@ -371,6 +371,7 @@ QDate calculateTransitionLocalDate(const SYSTEMTIME &rule, int year) // Otherwise, the rule date is annual and relative: const int dayOfWeek = rule.wDayOfWeek == 0 ? 7 : rule.wDayOfWeek; QDate date(year, rule.wMonth, 1); + Q_ASSERT(date.isValid()); // How many days before was last dayOfWeek before target month ? int adjust = dayOfWeek - date.dayOfWeek(); // -6 <= adjust < 7 if (adjust >= 0) // Ensure -7 <= adjust < 0: @@ -401,6 +402,7 @@ qint64 calculateTransitionForYear(const SYSTEMTIME &rule, int year, int bias) { // TODO Consider caching the calculated values - i.e. replace SYSTEMTIME in // WinTransitionRule; do this in init() once and store the results. + Q_ASSERT(year); const QDate date = calculateTransitionLocalDate(rule, year); const QTime time = QTime(rule.wHour, rule.wMinute, rule.wSecond); if (date.isValid() && time.isValid()) @@ -479,6 +481,7 @@ struct TransitionTimePair int yearEndOffset(const QWinTimeZonePrivate::QWinTransitionRule &rule, int year) { + Q_ASSERT(year); int offset = rule.standardTimeBias; // Only needed to help another TransitionTimePair work out year + 1's start // offset; and the oldYearOffset we use only affects an alleged transition @@ -743,11 +746,12 @@ QTimeZonePrivate::Data QWinTimeZonePrivate::data(qint64 forMSecsSinceEpoch) cons const QWinTransitionRule &rule = m_tranRules.at(ruleIndex); // Does this rule's period include any transition at all ? if (rule.standardTimeRule.wMonth > 0 || rule.daylightTimeRule.wMonth > 0) { - const int endYear = qMax(rule.startYear, year - 1); + int prior = year == 1 ? -1 : year - 1; // No year 0. + const int endYear = qMax(rule.startYear, prior); while (year >= endYear) { const int newYearOffset = (year <= rule.startYear && ruleIndex > 0) - ? yearEndOffset(m_tranRules.at(ruleIndex - 1), year - 1) - : yearEndOffset(rule, year - 1); + ? yearEndOffset(m_tranRules.at(ruleIndex - 1), prior) + : yearEndOffset(rule, prior); const TransitionTimePair pair(rule, year, newYearOffset); bool isDst = false; if (pair.std != invalidMSecs() && pair.std <= forMSecsSinceEpoch) { @@ -755,7 +759,8 @@ QTimeZonePrivate::Data QWinTimeZonePrivate::data(qint64 forMSecsSinceEpoch) cons } else if (pair.dst != invalidMSecs() && pair.dst <= forMSecsSinceEpoch) { isDst = true; } else { - --year; // Try an earlier year for this rule (once). + year = prior; // Try an earlier year for this rule (once). + prior = year == 1 ? -1 : year - 1; // No year 0. continue; } return ruleToData(rule, forMSecsSinceEpoch, @@ -767,8 +772,11 @@ QTimeZonePrivate::Data QWinTimeZonePrivate::data(qint64 forMSecsSinceEpoch) cons // No transition, no DST, use the year's standard time. return ruleToData(rule, forMSecsSinceEpoch, QTimeZone::StandardTime); } - if (year >= rule.startYear) + if (year >= rule.startYear) { year = rule.startYear - 1; // Seek last transition in new rule. + if (!year) + --year; + } } // We don't have relevant data :-( return invalidData(); @@ -795,9 +803,10 @@ QTimeZonePrivate::Data QWinTimeZonePrivate::nextTransition(qint64 afterMSecsSinc year = rule.startYear; // Seek first transition in this rule. const int endYear = ruleIndex + 1 < m_tranRules.count() ? qMin(m_tranRules.at(ruleIndex + 1).startYear, year + 2) : (year + 2); + int prior = year == 1 ? -1 : year - 1; // No year 0. int newYearOffset = (year <= rule.startYear && ruleIndex > 0) - ? yearEndOffset(m_tranRules.at(ruleIndex - 1), year - 1) - : yearEndOffset(rule, year - 1); + ? yearEndOffset(m_tranRules.at(ruleIndex - 1), prior) + : yearEndOffset(rule, prior); while (year < endYear) { const TransitionTimePair pair(rule, year, newYearOffset); bool isDst = false; @@ -810,7 +819,9 @@ QTimeZonePrivate::Data QWinTimeZonePrivate::nextTransition(qint64 afterMSecsSinc newYearOffset = rule.standardTimeBias; if (pair.dst > pair.std) newYearOffset += rule.daylightTimeBias; - ++year; // Try a later year for this rule (once). + // Try a later year for this rule (once). + prior = year; + year = year == -1 ? 1 : year + 1; // No year 0 continue; } @@ -837,11 +848,12 @@ QTimeZonePrivate::Data QWinTimeZonePrivate::previousTransition(qint64 beforeMSec const QWinTransitionRule &rule = m_tranRules.at(ruleIndex); // Does this rule's period include any transition at all ? if (rule.standardTimeRule.wMonth > 0 || rule.daylightTimeRule.wMonth > 0) { - const int endYear = qMax(rule.startYear, year - 1); + int prior = year == 1 ? -1 : year - 1; // No year 0. + const int endYear = qMax(rule.startYear, prior); while (year >= endYear) { const int newYearOffset = (year <= rule.startYear && ruleIndex > 0) - ? yearEndOffset(m_tranRules.at(ruleIndex - 1), year - 1) - : yearEndOffset(rule, year - 1); + ? yearEndOffset(m_tranRules.at(ruleIndex - 1), prior) + : yearEndOffset(rule, prior); const TransitionTimePair pair(rule, year, newYearOffset); bool isDst = false; if (pair.std != invalidMSecs() && pair.std < beforeMSecsSinceEpoch) { @@ -849,7 +861,8 @@ QTimeZonePrivate::Data QWinTimeZonePrivate::previousTransition(qint64 beforeMSec } else if (pair.dst != invalidMSecs() && pair.dst < beforeMSecsSinceEpoch) { isDst = true; } else { - --year; // Try an earlier year for this rule (once). + year = prior; // Try an earlier year for this rule (once). + prior = year == 1 ? -1 : year - 1; // No year 0. continue; } if (isDst) @@ -863,8 +876,11 @@ QTimeZonePrivate::Data QWinTimeZonePrivate::previousTransition(qint64 beforeMSec // rule: return ruleToData(rule, startOfTime, QTimeZone::StandardTime, false); } // else: no transition during rule's period - if (year >= rule.startYear) + if (year >= rule.startYear) { year = rule.startYear - 1; // Seek last transition in new rule + if (!year) + --year; + } } // Apparently no transition before the given time: return invalidData(); -- cgit v1.2.3 From c6bde29e143b1fadac97f656ba6c3059135d4a11 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 9 Sep 2019 16:20:47 +0200 Subject: Doc-fix: correct some misinformation about QDateTime's handling of DST Tidy up QDateTime::offsetFromUtc's doc, in the process. We don't take DST into account for dates before the epoch; that should be mentioned when saying we take DST into account. Also, referring to *this as the "current" time begs to be misunderstood. The \class comment also misleadingly claimed that we don't take into account any changes to time-zone before DST; where, in fact, we only ignore DST changes before 1970, not changes to standard offset. Change-Id: I090e668edf0338c825f5afcc67f894579a129c46 Reviewed-by: Paul Wicking --- src/corelib/time/qdatetime.cpp | 53 ++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/corelib/time/qdatetime.cpp b/src/corelib/time/qdatetime.cpp index 8b1665e7dd..13a54c1210 100644 --- a/src/corelib/time/qdatetime.cpp +++ b/src/corelib/time/qdatetime.cpp @@ -3432,15 +3432,15 @@ inline qint64 QDateTimePrivate::zoneMSecsToEpochMSecs(qint64 zoneMSecs, const QT datetime by adding a number of seconds, days, months, or years. QDateTime can describe datetimes with respect to \l{Qt::LocalTime}{local - time}, to \l{Qt::UTC}{UTC}, to a specified \l{Qt::OffsetFromUTC}{offset - from UTC} or to a specified \l{Qt::TimeZone}{time zone}, in conjunction - with the QTimeZone class. For example, a time zone of "Europe/Berlin" will - apply the daylight-saving rules as used in Germany since 1970. In contrast, - an offset from UTC of +3600 seconds is one hour ahead of UTC (usually - written in ISO standard notation as "UTC+01:00"), with no daylight-saving - offset or changes. When using either local time or a specified time zone, - time-zone transitions such as the starts and ends of daylight-saving time - (DST) are taken into account. The choice of system used to represent a + time}, to \l{Qt::UTC}{UTC}, to a specified \l{Qt::OffsetFromUTC}{offset from + UTC} or to a specified \l{Qt::TimeZone}{time zone}, in conjunction with the + QTimeZone class. For example, a time zone of "Europe/Berlin" will apply the + daylight-saving rules as used in Germany since 1970. In contrast, an offset + from UTC of +3600 seconds is one hour ahead of UTC (usually written in ISO + standard notation as "UTC+01:00"), with no daylight-saving offset or + changes. When using either local time or a specified time zone, time-zone + transitions such as the starts and ends of daylight-saving time (DST; but + see below) are taken into account. The choice of system used to represent a datetime is described as its "timespec". A QDateTime object is typically created either by giving a date and time @@ -3528,11 +3528,13 @@ inline qint64 QDateTimePrivate::zoneMSecsToEpochMSecs(qint64 zoneMSecs, const QT The range of valid dates taking DST into account is 1970-01-01 to the present, and rules are in place for handling DST correctly until 2037-12-31, - but these could change. For dates falling outside that range, QDateTime - makes a \e{best guess} using the rules for year 1970 or 2037, but we can't - guarantee accuracy. This means QDateTime doesn't take into account changes - in a time zone before 1970, even if the system's time zone database provides - that information. + but these could change. For dates after 2037, QDateTime makes a \e{best + guess} using the rules for year 2037, but we can't guarantee accuracy; + indeed, for \e{any} future date, the time-zone may change its rules before + that date comes around. For dates before 1970, QDateTime doesn't take DST + changes into account, even if the system's time zone database provides that + information, although it does take into account changes to the time-zone's + standard offset, where this information is available. \section2 Offsets From UTC @@ -3797,17 +3799,22 @@ QTimeZone QDateTime::timeZone() const /*! \since 5.2 - Returns the current Offset From UTC in seconds. + Returns this date-time's Offset From UTC in seconds. - If the timeSpec() is Qt::OffsetFromUTC this will be the value originally set. - - If the timeSpec() is Qt::TimeZone this will be the offset effective in the - Time Zone including any Daylight-Saving Offset. - - If the timeSpec() is Qt::LocalTime this will be the difference between the - Local Time and UTC including any Daylight-Saving Offset. + The result depends on timeSpec(): + \list + \li \c Qt::UTC The offset is 0. + \li \c Qt::OffsetFromUTC The offset is the value originally set. + \li \c Qt::LocalTime The local time's offset from UTC is returned. + \li \c Qt::TimeZone The offset used by the time-zone is returned. + \endlist - If the timeSpec() is Qt::UTC this will be 0. + For the last two, the offset at this date and time will be returned, taking + account of Daylight-Saving Offset unless the date precedes the start of + 1970. The offset is the difference between the local time or time in the + given time-zone and UTC time; it is positive in time-zones ahead of UTC + (East of The Prime Meridian), negative for those behind UTC (West of The + Prime Meridian). \sa setOffsetFromUtc() */ -- cgit v1.2.3 From 00d0a530358d40d577578cb1bcb75a978549bd8d Mon Sep 17 00:00:00 2001 From: David Faure Date: Sat, 7 Sep 2019 23:14:19 +0200 Subject: QDpi: divide the forced DPI by the scaling factor, as Qt 5.13 did MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When setting a DPI in xrdb, it should have the same effect on apps that enable scaling and apps that don't (including Qt4 and GTK applications). That's what happened in Qt 5.13, while the recent changes removed that division, and as a result the fonts were huge in Qt5 apps compared to Qt4/GTK/kwin/plasmashell/krunner (which don't scale, but do honor the font DPI). Change-Id: Icd7be2d15a9b50982ae624e41bd9e546f315d58b Reviewed-by: Friedemann Kleint Reviewed-by: Morten Johan Sørvig --- src/gui/kernel/qhighdpiscaling.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/gui/kernel/qhighdpiscaling.cpp b/src/gui/kernel/qhighdpiscaling.cpp index dcbae4f5c0..ee54fd4fa1 100644 --- a/src/gui/kernel/qhighdpiscaling.cpp +++ b/src/gui/kernel/qhighdpiscaling.cpp @@ -680,8 +680,11 @@ QDpi QHighDpiScaling::logicalDpi(const QScreen *screen) if (!screen || !screen->handle()) return QDpi(96, 96); - if (!m_usePixelDensity) - return QPlatformScreen::overrideDpi(screen->handle()->logicalDpi()); + if (!m_usePixelDensity) { + const qreal screenScaleFactor = screenSubfactor(screen->handle()); + const QDpi dpi = QPlatformScreen::overrideDpi(screen->handle()->logicalDpi()); + return QDpi{ dpi.first / screenScaleFactor, dpi.second / screenScaleFactor }; + } const qreal scaleFactor = rawScaleFactor(screen->handle()); const qreal roundedScaleFactor = roundScaleFactor(scaleFactor); -- 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') 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 02e43e6fa6f47eaedc1dd72956569aa939d90981 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 28 Aug 2019 16:56:18 +0200 Subject: widgets: Remove use of deprecated activated(const QString &) API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I71c6a10f6593ac28bf8f60d9db8d167cf88715cb Reviewed-by: Paul Olav Tvete Reviewed-by: Tor Arne Vestbø --- src/widgets/widgets/qcombobox.cpp | 15 --------------- src/widgets/widgets/qcombobox_p.h | 10 ++++++++++ 2 files changed, 10 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp index a53c278aea..9a0e969e1c 100644 --- a/src/widgets/widgets/qcombobox.cpp +++ b/src/widgets/widgets/qcombobox.cpp @@ -2539,21 +2539,6 @@ QSize QComboBox::sizeHint() const } #ifdef Q_OS_MAC - -namespace { -struct IndexSetter { - int index; - QComboBox *cb; - - void operator()(void) - { - cb->setCurrentIndex(index); - emit cb->activated(index); - emit cb->activated(cb->itemText(index)); - } -}; -} - void QComboBoxPrivate::cleanupNativePopup() { if (!m_platformMenu) diff --git a/src/widgets/widgets/qcombobox_p.h b/src/widgets/widgets/qcombobox_p.h index eadb21628f..5967776a61 100644 --- a/src/widgets/widgets/qcombobox_p.h +++ b/src/widgets/widgets/qcombobox_p.h @@ -390,6 +390,16 @@ public: #ifdef Q_OS_MAC void cleanupNativePopup(); bool showNativePopup(); + struct IndexSetter { + int index; + QComboBox *cb; + + void operator()(void) + { + cb->setCurrentIndex(index); + cb->d_func()->emitActivated(cb->d_func()->currentIndex); + } + }; #endif QAbstractItemModel *model; -- cgit v1.2.3 From 5f3bbd0cf091d75661e9390696683285368edb2c Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Mon, 1 Jul 2019 18:23:10 +0000 Subject: Revert "Revert "Deprecate QAtomic::load() / store()"" This reverts commit 5859f7d0d9440f82086486639a707f3935696cf4. Reason for revert: the blocker for qtdeclarative has been merged (in qtdeclarative/c060f6e765a2f155b38158f2ed73eac4aad37e02). Change-Id: Ie69cb1567417173f543e88f659658fe03ba28830 Reviewed-by: Liang Qi --- src/corelib/thread/qbasicatomic.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/corelib/thread/qbasicatomic.h b/src/corelib/thread/qbasicatomic.h index dc976819ef..9804e60119 100644 --- a/src/corelib/thread/qbasicatomic.h +++ b/src/corelib/thread/qbasicatomic.h @@ -99,8 +99,10 @@ public: typename Ops::Type _q_value; // Everything below is either implemented in ../arch/qatomic_XXX.h or (as fallback) in qgenericatomic.h - T load() const noexcept { return loadRelaxed(); } - void store(T newValue) noexcept { storeRelaxed(newValue); } +#if QT_DEPRECATED_SINCE(5, 14) + QT_DEPRECATED_VERSION_X_5_14("Use loadRelaxed") T load() const noexcept { return loadRelaxed(); } + QT_DEPRECATED_VERSION_X_5_14("Use storeRelaxed") void store(T newValue) noexcept { storeRelaxed(newValue); } +#endif T loadRelaxed() const noexcept { return Ops::loadRelaxed(_q_value); } void storeRelaxed(T newValue) noexcept { Ops::storeRelaxed(_q_value, newValue); } @@ -238,8 +240,10 @@ public: AtomicType _q_value; - Type load() const noexcept { return loadRelaxed(); } - void store(Type newValue) noexcept { storeRelaxed(newValue); } +#if QT_DEPRECATED_SINCE(5, 14) + QT_DEPRECATED_VERSION_X_5_14("Use loadRelaxed") Type load() const noexcept { return loadRelaxed(); } + QT_DEPRECATED_VERSION_X_5_14("Use storeRelaxed") void store(Type newValue) noexcept { storeRelaxed(newValue); } +#endif Type loadRelaxed() const noexcept { return Ops::loadRelaxed(_q_value); } void storeRelaxed(Type newValue) noexcept { Ops::storeRelaxed(_q_value, newValue); } -- 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') 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 ++++---- src/widgets/styles/qwindowsstyle.cpp | 28 ++-- src/widgets/styles/qwindowsstyle_p_p.h | 4 +- 7 files changed, 180 insertions(+), 187 deletions(-) (limited to 'src') 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; diff --git a/src/widgets/styles/qwindowsstyle.cpp b/src/widgets/styles/qwindowsstyle.cpp index 72c803cb99..7d4e1fe9e7 100644 --- a/src/widgets/styles/qwindowsstyle.cpp +++ b/src/widgets/styles/qwindowsstyle.cpp @@ -120,10 +120,7 @@ enum QSliderDirection { SlUp, SlDown, SlLeft, SlRight }; \internal */ -QWindowsStylePrivate::QWindowsStylePrivate() - : alt_down(false), menuBarTimer(0) -{ -} +QWindowsStylePrivate::QWindowsStylePrivate() = default; qreal QWindowsStylePrivate::appDevicePixelRatio() { @@ -157,7 +154,7 @@ bool QWindowsStyle::eventFilter(QObject *o, QEvent *e) QList l = widget->findChildren(); auto ignorable = [](QWidget *w) { return w->isWindow() || !w->isVisible() - || w->style()->styleHint(SH_UnderlineShortcut, 0, w); + || w->style()->styleHint(SH_UnderlineShortcut, nullptr, w); }; l.erase(std::remove_if(l.begin(), l.end(), ignorable), l.end()); // Update states before repainting @@ -242,7 +239,7 @@ void QWindowsStyle::polish(QApplication *app) QCommonStyle::polish(app); QWindowsStylePrivate *d = const_cast(d_func()); // We only need the overhead when shortcuts are sometimes hidden - if (!proxy()->styleHint(SH_UnderlineShortcut, 0) && app) + if (!proxy()->styleHint(SH_UnderlineShortcut, nullptr) && app) app->installEventFilter(this); const auto &palette = QGuiApplication::palette(); @@ -343,7 +340,6 @@ int QWindowsStylePrivate::fixedPixelMetric(QStyle::PixelMetric pm) case QStyle::PM_MenuVMargin: case QStyle::PM_ToolBarItemMargin: return 1; - break; case QStyle::PM_DockWidgetSeparatorExtent: return 4; #if QT_CONFIG(tabbar) @@ -698,17 +694,17 @@ void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, x -= 2; if (opt->rect.height() > 4) { qDrawShadePanel(p, x, 2, 3, opt->rect.height() - 4, - opt->palette, false, 1, 0); + opt->palette, false, 1, nullptr); qDrawShadePanel(p, x + 3, 2, 3, opt->rect.height() - 4, - opt->palette, false, 1, 0); + opt->palette, false, 1, nullptr); } } else { if (opt->rect.width() > 4) { int y = opt->rect.height() / 2 - 4; qDrawShadePanel(p, 2, y, opt->rect.width() - 4, 3, - opt->palette, false, 1, 0); + opt->palette, false, 1, nullptr); qDrawShadePanel(p, 2, y + 3, opt->rect.width() - 4, 3, - opt->palette, false, 1, 0); + opt->palette, false, 1, nullptr); } } p->restore(); @@ -759,7 +755,7 @@ void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, } } else { qDrawWinButton(p, opt->rect, opt->palette, - opt->state & (State_Sunken | State_On), panel ? &fill : 0); + opt->state & (State_Sunken | State_On), panel ? &fill : nullptr); } } else { p->fillRect(opt->rect, fill); @@ -980,7 +976,7 @@ void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, if (opt->state & (State_Raised | State_On | State_Sunken)) { qDrawWinButton(p, opt->rect, opt->palette, opt->state & (State_Sunken | State_On), - panel ? &fill : 0); + panel ? &fill : nullptr); } else { if (panel) p->fillRect(opt->rect, fill); @@ -1005,7 +1001,7 @@ void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, #endif // QT_CONFIG(dockwidget) case PE_FrameStatusBarItem: - qDrawShadePanel(p, opt->rect, opt->palette, true, 1, 0); + qDrawShadePanel(p, opt->rect, opt->palette, true, 1, nullptr); break; case PE_IndicatorProgressChunk: @@ -1043,7 +1039,7 @@ void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, break; case PE_FrameTabWidget: { - qDrawWinButton(p, opt->rect, opt->palette, false, 0); + qDrawWinButton(p, opt->rect, opt->palette, false, nullptr); break; } default: @@ -1585,6 +1581,7 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai case QStyleOptionToolBar::Beginning: case QStyleOptionToolBar::OnlyOne: paintBottomBorder = false; + break; default: break; } @@ -1600,6 +1597,7 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai case QStyleOptionToolBar::OnlyOne: paintRightBorder = false; paintLeftBorder = false; + break; default: break; } diff --git a/src/widgets/styles/qwindowsstyle_p_p.h b/src/widgets/styles/qwindowsstyle_p_p.h index e6ea809f11..4f6ffcefc2 100644 --- a/src/widgets/styles/qwindowsstyle_p_p.h +++ b/src/widgets/styles/qwindowsstyle_p_p.h @@ -77,9 +77,9 @@ public: bool hasSeenAlt(const QWidget *widget) const; bool altDown() const { return alt_down; } - bool alt_down; + bool alt_down = false; QList seenAlt; - int menuBarTimer; + int menuBarTimer = 0; QColor inactiveCaptionText; QColor activeCaptionColor; -- cgit v1.2.3 From 9c76b82885253bbec9d9019b9113be16b15385f2 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 12 Sep 2019 09:32:02 +0200 Subject: Windows style: Fix size of controls in multimonitor-setups with scaling disabled The function calculating a correction for the size of windows metrics depending on screen would bail out when high DPI scaling was disabled. This is wrong since the correction is also needed in that case, delete the clause. Task-number: QTBUG-64890 Change-Id: Idef22e18fc616a211ccac48400490fc52393a338 Reviewed-by: Oliver Wolff --- src/widgets/styles/qwindowsstyle.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'src') diff --git a/src/widgets/styles/qwindowsstyle.cpp b/src/widgets/styles/qwindowsstyle.cpp index 7d4e1fe9e7..8496a2c223 100644 --- a/src/widgets/styles/qwindowsstyle.cpp +++ b/src/widgets/styles/qwindowsstyle.cpp @@ -392,8 +392,6 @@ static QScreen *screenOf(const QWidget *w) // and account for secondary screens with differing logical DPI. qreal QWindowsStylePrivate::nativeMetricScaleFactor(const QWidget *widget) { - if (!QHighDpiScaling::isActive()) - return 1; qreal result = qreal(1) / QWindowsStylePrivate::devicePixelRatio(widget); if (QGuiApplicationPrivate::screen_list.size() > 1) { const QScreen *primaryScreen = QGuiApplication::primaryScreen(); -- cgit v1.2.3 From 7f0faddf9fe25adc0a3e0827e21c030d6a7a1035 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 12 Sep 2019 15:52:06 +0200 Subject: CoreText: Modernize style hint fallback lookup The DefaultFontFallbacks.plist system file that we used for looking up style fallbacks does not exists in macOS 10.15, nor did it ever exists on iOS. Instead of relying on this file, we hard-code a set of default families, that we then look up the fallbacks for. The result of QFont::defaultFamily() on macOS is now: QFont::Helvetica --> "Helvetica" QFont::Times --> "Times New Roman" QFont::Courier --> "American Typewriter" QFont::OldEnglish --> "" QFont::System --> "Lucida Grande" QFont::AnyStyle --> "Lucida Grande" QFont::Cursive --> "Apple Chancery" QFont::Monospace --> "Menlo" QFont::Fantasy --> "Zapfino" And on iOS: QFont::Helvetica --> "Helvetica" QFont::Times --> "Times New Roman" QFont::Courier --> "American Typewriter" QFont::OldEnglish --> "" QFont::System --> "Helvetica" QFont::AnyStyle --> "Helvetica" QFont::Cursive --> "" QFont::Monospace --> "Menlo" QFont::Fantasy --> "Zapfino" Fixes: QTBUG-78240 Change-Id: Ie9bc13c9c1031d89f024199e4736a046c568a48d Reviewed-by: Simon Hausmann --- .../fontdatabases/mac/qcoretextfontdatabase.mm | 201 ++++++++------------- .../fontdatabases/mac/qcoretextfontdatabase_p.h | 1 + 2 files changed, 73 insertions(+), 129 deletions(-) (limited to 'src') diff --git a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm index 047773d8e3..a52e157768 100644 --- a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm +++ b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm @@ -100,20 +100,6 @@ static const char *languageForWritingSystem[] = { }; enum { LanguageCount = sizeof(languageForWritingSystem) / sizeof(const char *) }; -#ifdef Q_OS_OSX -static NSInteger languageMapSort(id obj1, id obj2, void *context) -{ - NSArray *map1 = reinterpret_cast *>(obj1); - NSArray *map2 = reinterpret_cast *>(obj2); - NSArray *languages = reinterpret_cast *>(context); - - NSString *lang1 = [map1 objectAtIndex:0]; - NSString *lang2 = [map2 objectAtIndex:0]; - - return [languages indexOfObject:lang1] - [languages indexOfObject:lang2]; -} -#endif - QCoreTextFontDatabase::QCoreTextFontDatabase() : m_hasPopulatedAliases(false) { @@ -406,142 +392,99 @@ template class QCoreTextFontDatabaseEngineFactory; template class QCoreTextFontDatabaseEngineFactory; #endif -QFont::StyleHint styleHintFromNSString(NSString *style) +QStringList QCoreTextFontDatabase::fallbacksForFamily(const QString &family) { - if ([style isEqual: @"sans-serif"]) - return QFont::SansSerif; - else if ([style isEqual: @"monospace"]) - return QFont::Monospace; - else if ([style isEqual: @"cursive"]) - return QFont::Cursive; - else if ([style isEqual: @"serif"]) - return QFont::Serif; - else if ([style isEqual: @"fantasy"]) - return QFont::Fantasy; - else // if ([style isEqual: @"default"]) - return QFont::AnyStyle; -} + if (family.isEmpty()) + return QStringList(); -#ifdef Q_OS_OSX -static QString familyNameFromPostScriptName(NSString *psName) -{ - QCFType fontDescriptor = (CTFontDescriptorRef) CTFontDescriptorCreateWithNameAndSize((CFStringRef)psName, 12.0); - QCFString familyName = (CFStringRef) CTFontDescriptorCopyAttribute(fontDescriptor, kCTFontFamilyNameAttribute); - QString name = QString::fromCFString(familyName); - if (name.isEmpty()) - qWarning() << "QCoreTextFontDatabase: Failed to resolve family name for PostScript name " << QString::fromCFString((CFStringRef)psName); + auto attributes = @{ id(kCTFontFamilyNameAttribute): family.toNSString() }; + QCFType fontDescriptor = CTFontDescriptorCreateWithAttributes(CFDictionaryRef(attributes)); + if (!fontDescriptor) { + qWarning() << "Failed to create fallback font descriptor for" << family; + return QStringList(); + } - return name; -} -#endif + QCFType font = CTFontCreateWithFontDescriptor(fontDescriptor, 12.0, 0); + if (!font) { + qWarning() << "Failed to create fallback font for" << family; + return QStringList(); + } -static void addExtraFallbacks(QStringList *fallbackList) -{ -#if defined(Q_OS_MACOS) - // Since we are only returning a list of default fonts for the current language, we do not - // cover all unicode completely. This was especially an issue for some of the common script - // symbols such as mathematical symbols, currency or geometric shapes. To minimize the risk - // of missing glyphs, we add Arial Unicode MS as a final fail safe, since this covers most - // of Unicode 2.1. - if (!fallbackList->contains(QStringLiteral("Arial Unicode MS"))) - fallbackList->append(QStringLiteral("Arial Unicode MS")); - // Since some symbols (specifically Braille) are not in Arial Unicode MS, we - // add Apple Symbols to cover those too. - if (!fallbackList->contains(QStringLiteral("Apple Symbols"))) - fallbackList->append(QStringLiteral("Apple Symbols")); -#else - Q_UNUSED(fallbackList) -#endif + QCFType cascadeList = CFArrayRef(CTFontCopyDefaultCascadeListForLanguages(font, + (CFArrayRef)[NSUserDefaults.standardUserDefaults stringArrayForKey:@"AppleLanguages"])); + if (!cascadeList) { + qWarning() << "Failed to create fallback cascade list for" << family; + return QStringList(); + } + + QStringList fallbackList; + const int numCascades = CFArrayGetCount(cascadeList); + for (int i = 0; i < numCascades; ++i) { + CTFontDescriptorRef fontFallback = CTFontDescriptorRef(CFArrayGetValueAtIndex(cascadeList, i)); + QCFString fallbackFamilyName = CFStringRef(CTFontDescriptorCopyAttribute(fontFallback, kCTFontFamilyNameAttribute)); + fallbackList.append(QString::fromCFString(fallbackFamilyName)); + } + + return fallbackList; } QStringList QCoreTextFontDatabase::fallbacksForFamily(const QString &family, QFont::Style style, QFont::StyleHint styleHint, QChar::Script script) const { Q_UNUSED(style); - Q_UNUSED(script); QMacAutoReleasePool pool; - static QHash fallbackLists; - - if (!family.isEmpty()) { - QCFType attributes = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); - CFDictionaryAddValue(attributes, kCTFontFamilyNameAttribute, QCFString(family)); - if (QCFType fontDescriptor = CTFontDescriptorCreateWithAttributes(attributes)) { - if (QCFType font = CTFontCreateWithFontDescriptor(fontDescriptor, 12.0, 0)) { - NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; - NSArray *languages = [defaults stringArrayForKey: @"AppleLanguages"]; - - QCFType cascadeList = (CFArrayRef) CTFontCopyDefaultCascadeListForLanguages(font, (CFArrayRef) languages); - if (cascadeList) { - QStringList fallbackList; - const int numCascades = CFArrayGetCount(cascadeList); - for (int i = 0; i < numCascades; ++i) { - CTFontDescriptorRef fontFallback = (CTFontDescriptorRef) CFArrayGetValueAtIndex(cascadeList, i); - QCFString fallbackFamilyName = (CFStringRef) CTFontDescriptorCopyAttribute(fontFallback, kCTFontFamilyNameAttribute); - fallbackList.append(QString::fromCFString(fallbackFamilyName)); - } - - addExtraFallbacks(&fallbackList); - extern QStringList qt_sort_families_by_writing_system(QChar::Script, const QStringList &); - fallbackList = qt_sort_families_by_writing_system(script, fallbackList); - - return fallbackList; + QStringList fallbackList = fallbacksForFamily(family); + + if (fallbackList.isEmpty()) { + // We were not able to find a fallback for the specific family, + // or the family was empty, so we fall back to the style hint. + QString styleFamily = [styleHint]{ + switch (styleHint) { + case QFont::SansSerif: return QStringLiteral("Helvetica"); + case QFont::Serif: return QStringLiteral("Times New Roman"); + case QFont::Monospace: return QStringLiteral("Menlo"); +#ifdef Q_OS_MACOS + case QFont::Cursive: return QStringLiteral("Apple Chancery"); +#endif + case QFont::Fantasy: return QStringLiteral("Zapfino"); + case QFont::TypeWriter: return QStringLiteral("American Typewriter"); + case QFont::AnyStyle: Q_FALLTHROUGH(); + case QFont::System: { + QCFType font = CTFontCreateUIFontForLanguage(kCTFontUIFontSystem, 12.0, NULL); + return static_cast(QCFString(CTFontCopyFullName(font))); } + default: return QString(); // No matching font on this platform } + }(); + if (!styleFamily.isEmpty()) { + fallbackList = fallbacksForFamily(styleFamily); + if (!fallbackList.contains(styleFamily)) + fallbackList.prepend(styleFamily); } } - // We were not able to find a fallback for the specific family, - // so we fall back to the stylehint. - - static const QString styleLookupKey = QString::fromLatin1(".QFontStyleHint_%1"); - - static bool didPopulateStyleFallbacks = false; - if (!didPopulateStyleFallbacks) { -#if defined(Q_OS_MACX) - NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; - NSArray *languages = [defaults stringArrayForKey:@"AppleLanguages"]; - - NSDictionary *fallbackDict = [NSDictionary dictionaryWithContentsOfFile:@"/System/Library/Frameworks/ApplicationServices.framework/Frameworks/CoreText.framework/Resources/DefaultFontFallbacks.plist"]; - - for (NSString *style in [fallbackDict allKeys]) { - NSArray *list = [fallbackDict valueForKey:style]; - QFont::StyleHint fallbackStyleHint = styleHintFromNSString(style); - QStringList fallbackList; - for (id item in list) { - // sort the array based on system language preferences - if ([item isKindOfClass:[NSArray class]]) { - NSArray *langs = [reinterpret_cast(item) - sortedArrayUsingFunction:languageMapSort context:languages]; - for (NSArray *map in langs) - fallbackList.append(familyNameFromPostScriptName([map objectAtIndex:1])); - } - else if ([item isKindOfClass: [NSString class]]) - fallbackList.append(familyNameFromPostScriptName(item)); - } - - fallbackList.append(QLatin1String("Apple Color Emoji")); + if (fallbackList.isEmpty()) + return fallbackList; - addExtraFallbacks(&fallbackList); - fallbackLists[styleLookupKey.arg(fallbackStyleHint)] = fallbackList; - } -#else - QStringList staticFallbackList; - staticFallbackList << QString::fromLatin1("Helvetica,Apple Color Emoji,Geeza Pro,Arial Hebrew,Thonburi,Kailasa" - "Hiragino Kaku Gothic ProN,.Heiti J,Apple SD Gothic Neo,.Heiti K,Heiti SC,Heiti TC" - "Bangla Sangam MN,Devanagari Sangam MN,Gujarati Sangam MN,Gurmukhi MN,Kannada Sangam MN" - "Malayalam Sangam MN,Oriya Sangam MN,Sinhala Sangam MN,Tamil Sangam MN,Telugu Sangam MN" - "Euphemia UCAS,.PhoneFallback").split(QLatin1String(",")); - - for (int i = QFont::Helvetica; i <= QFont::Fantasy; ++i) - fallbackLists[styleLookupKey.arg(i)] = staticFallbackList; +#if defined(Q_OS_MACOS) + // Since we are only returning a list of default fonts for the current language, we do not + // cover all Unicode completely. This was especially an issue for some of the common script + // symbols such as mathematical symbols, currency or geometric shapes. To minimize the risk + // of missing glyphs, we add Arial Unicode MS as a final fail safe, since this covers most + // of Unicode 2.1. + if (!fallbackList.contains(QStringLiteral("Arial Unicode MS"))) + fallbackList.append(QStringLiteral("Arial Unicode MS")); + // Since some symbols (specifically Braille) are not in Arial Unicode MS, we + // add Apple Symbols to cover those too. + if (!fallbackList.contains(QStringLiteral("Apple Symbols"))) + fallbackList.append(QStringLiteral("Apple Symbols")); #endif - didPopulateStyleFallbacks = true; - } + extern QStringList qt_sort_families_by_writing_system(QChar::Script, const QStringList &); + fallbackList = qt_sort_families_by_writing_system(script, fallbackList); - Q_ASSERT(!fallbackLists.isEmpty()); - return fallbackLists[styleLookupKey.arg(styleHint)]; + return fallbackList; } QStringList QCoreTextFontDatabase::addApplicationFont(const QByteArray &fontData, const QString &fileName) diff --git a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase_p.h b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase_p.h index 05f6ed641c..45e74b99be 100644 --- a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase_p.h +++ b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase_p.h @@ -92,6 +92,7 @@ protected: private: void populateFromDescriptor(CTFontDescriptorRef font, const QString &familyName = QString()); + static QStringList fallbacksForFamily(const QString &family); mutable QString defaultFontName; -- cgit v1.2.3 From 01ce9c05a31065d3860f042a6616f3559981bc53 Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Sat, 14 Sep 2019 11:50:14 +0200 Subject: doc: Remove ifndef Q_QDOC qdoc needs to see these declarations now because... clang. Change-Id: I93264125db5bcea6adb1a4636e5459ec80702de1 Reviewed-by: Paul Wicking --- src/corelib/tools/qcontainertools_impl.h | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src') diff --git a/src/corelib/tools/qcontainertools_impl.h b/src/corelib/tools/qcontainertools_impl.h index 86a16eb32b..3a0c4381f1 100644 --- a/src/corelib/tools/qcontainertools_impl.h +++ b/src/corelib/tools/qcontainertools_impl.h @@ -49,8 +49,6 @@ #include #include -#ifndef Q_QDOC - QT_BEGIN_NAMESPACE namespace QtPrivate @@ -131,6 +129,4 @@ using IfAssociativeIteratorHasFirstAndSecond = QT_END_NAMESPACE -#endif // Q_QDOC - #endif // QCONTAINERTOOLS_IMPL_H -- cgit v1.2.3 From 0cd134ed13eb5396876efe57b395f7d34a7d073c Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Thu, 5 Sep 2019 12:11:06 +0200 Subject: Standardize indentation of calendar code's documentation There was a haphazard mix of 4-space and 2-space indents. Use four spaces throughout. This commit includes no reflow (which is needed), as the inanity-bot will complain about the mixing of space changes with "non-space" changes if I do that. Change-Id: If55ab035da02d0770471e77ecfe00eb168a3da15 Reviewed-by: Paul Wicking --- src/corelib/time/qcalendar.cpp | 426 ++++++++++++++--------------- src/corelib/time/qhijricalendar.cpp | 48 ++-- src/corelib/time/qislamiccivilcalendar.cpp | 32 +-- src/corelib/time/qromancalendar.cpp | 20 +- 4 files changed, 263 insertions(+), 263 deletions(-) (limited to 'src') diff --git a/src/corelib/time/qcalendar.cpp b/src/corelib/time/qcalendar.cpp index 4d3f1627b5..efd13ed3ad 100644 --- a/src/corelib/time/qcalendar.cpp +++ b/src/corelib/time/qcalendar.cpp @@ -201,7 +201,7 @@ QCalendar::System QCalendarBackend::calendarSystem() const } /*! - The primary name of this calendar. + The primary name of this calendar. */ QString QCalendar::name() const { @@ -440,101 +440,101 @@ int QCalendarBackend::dayOfWeek(qint64 jd) const // Month and week-day name look-ups (implemented in qlocale.cpp): /*! - \fn QString QCalendarBackend::monthName(const QLocale &locale, int month, int year, - QLocale::FormatType format) const + \fn QString QCalendarBackend::monthName(const QLocale &locale, int month, int year, + QLocale::FormatType format) const - Returns the name of the specified \a month in the given \a year for the chosen - \a locale, using the given \a format to determine how complete the name is. + Returns the name of the specified \a month in the given \a year for the chosen + \a locale, using the given \a format to determine how complete the name is. - If \a year is Unspecified, return the name for the month that usually has this - number within a typical year. Calendars with a leap month that isn't always - the last may need to take account of the year to map the month number to the - particular year's month with that number. + If \a year is Unspecified, return the name for the month that usually has this + number within a typical year. Calendars with a leap month that isn't always + the last may need to take account of the year to map the month number to the + particular year's month with that number. - \note Backends for which CLDR provides data can configure the default - implementation of the two month name look-up methods by arranging for - localeMonthIndexData() and localeMonthData() to provide access to the CLDR - data (see cldr2qlocalexml.py, qlocalexml2cpp.py and existing backends). - Conversely, backends that override both month name look-up methods need not - return anything meaningful from localeMonthIndexData() or localeMonthData(). + \note Backends for which CLDR provides data can configure the default + implementation of the two month name look-up methods by arranging for + localeMonthIndexData() and localeMonthData() to provide access to the CLDR + data (see cldr2qlocalexml.py, qlocalexml2cpp.py and existing backends). + Conversely, backends that override both month name look-up methods need not + return anything meaningful from localeMonthIndexData() or localeMonthData(). - \sa standaloneMonthName(), QLocale::monthName() + \sa standaloneMonthName(), QLocale::monthName() */ /*! - \fn QString QCalendarBackend::standaloneMonthName(const QLocale &locale, int month, int year - QLocale::FormatType format) const + \fn QString QCalendarBackend::standaloneMonthName(const QLocale &locale, int month, int year + QLocale::FormatType format) const - Returns the standalone name of the specified \a month in the chosen \a locale, - using the specified \a format to determine how complete the name is. + Returns the standalone name of the specified \a month in the chosen \a locale, + using the specified \a format to determine how complete the name is. - If \a year is Unspecified, return the standalone name for the month that - usually has this number within a typical year. Calendars with a leap month - that isn't always the last may need to take account of the year to map the - month number to the particular year's month with that number. + If \a year is Unspecified, return the standalone name for the month that + usually has this number within a typical year. Calendars with a leap month + that isn't always the last may need to take account of the year to map the + month number to the particular year's month with that number. - \sa monthName(), QLocale::standaloneMonthName() + \sa monthName(), QLocale::standaloneMonthName() */ /*! - \fn QString QCalendarBackend::weekDayName(const QLocale &locale, int day, - QLocale::FormatType format) const + \fn QString QCalendarBackend::weekDayName(const QLocale &locale, int day, + QLocale::FormatType format) const - Returns the name of the specified \a day of the week in the chosen \a locale, - using the specified \a format to determine how complete the name is. + Returns the name of the specified \a day of the week in the chosen \a locale, + using the specified \a format to determine how complete the name is. - The base implementation handles \a day values from 1 to 7 using the day names - CLDR provides, which are suitable for calendards that use the same - (Hebrew-derived) week as the Gregorian calendar. + The base implementation handles \a day values from 1 to 7 using the day names + CLDR provides, which are suitable for calendards that use the same + (Hebrew-derived) week as the Gregorian calendar. - Calendars whose dayOfWeek() returns a value outside the range from 1 to 7 need - to reimplement this method to handle such extra week-day values. They can - assume that \a day is a value returned by the same calendar's dayOfWeek(). + Calendars whose dayOfWeek() returns a value outside the range from 1 to 7 need + to reimplement this method to handle such extra week-day values. They can + assume that \a day is a value returned by the same calendar's dayOfWeek(). - \sa dayOfWeek(), standaloneWeekDayName(), QLocale::dayName() + \sa dayOfWeek(), standaloneWeekDayName(), QLocale::dayName() */ /*! - \fn QString QCalendarBackend::standaloneWeekDayName(const QLocale &locale, int day, - QLocale::FormatType format) const + \fn QString QCalendarBackend::standaloneWeekDayName(const QLocale &locale, int day, + QLocale::FormatType format) const - Returns the standalone name of the specified \a day of the week in the chosen - \a locale, using the specified \a format to determine how complete the name - is. + Returns the standalone name of the specified \a day of the week in the chosen + \a locale, using the specified \a format to determine how complete the name + is. - The base implementation handles \a day values from 1 to 7 using the standalone - day names CLDR provides, which are suitable for calendards that use the same - (Hebrew-derived) week as the Gregorian calendar. + The base implementation handles \a day values from 1 to 7 using the standalone + day names CLDR provides, which are suitable for calendards that use the same + (Hebrew-derived) week as the Gregorian calendar. - Calendars whose dayOfWeek() returns a value outside the range from 1 to 7 need - to reimplement this method to handle such extra week-day values. They can - assume that \a day is a value returned by the same calendar's dayOfWeek(). + Calendars whose dayOfWeek() returns a value outside the range from 1 to 7 need + to reimplement this method to handle such extra week-day values. They can + assume that \a day is a value returned by the same calendar's dayOfWeek(). - \sa dayOfWeek(), weekDayName(), QLocale::standaloneDayName() + \sa dayOfWeek(), weekDayName(), QLocale::standaloneDayName() */ /*! - \fn QString QCalendarBackend::dateTimeToString(QStringView format, const QDateTime &datetime, - const QDate &dateOnly, const QTime &timeOnly, - const QLocale &locale) const - - Returns a string representing a given date, time or date-time. - - If \a datetime is specified and valid, it is used and both date and time - format tokens are converted to appropriate representations of the parts of the - datetime. Otherwise, if \a dateOnly is valid, only date format tokens are - converted; else, if \a timeOnly is valid, only time format tokens are - converted. If none are valid, an empty string is returned. - - The specified \a locale influences how some format tokens are converted; for - example, when substituting day and month names and their short-forms. For the - supported formatting tokens, see QDate::toString() and QTime::toString(). As - described above, the provided date, time and date-time determine which of - these tokens are recognized: where these appear in \a format they are replaced - by data. Any text in \a format not recognized as a format token is copied - verbatim into the result string. - - \sa QDate::toString(), QTime::toString(), QDateTime::toString() + \fn QString QCalendarBackend::dateTimeToString(QStringView format, const QDateTime &datetime, + const QDate &dateOnly, const QTime &timeOnly, + const QLocale &locale) const + + Returns a string representing a given date, time or date-time. + + If \a datetime is specified and valid, it is used and both date and time + format tokens are converted to appropriate representations of the parts of the + datetime. Otherwise, if \a dateOnly is valid, only date format tokens are + converted; else, if \a timeOnly is valid, only time format tokens are + converted. If none are valid, an empty string is returned. + + The specified \a locale influences how some format tokens are converted; for + example, when substituting day and month names and their short-forms. For the + supported formatting tokens, see QDate::toString() and QTime::toString(). As + described above, the provided date, time and date-time determine which of + these tokens are recognized: where these appear in \a format they are replaced + by data. Any text in \a format not recognized as a format token is copied + verbatim into the result string. + + \sa QDate::toString(), QTime::toString(), QDateTime::toString() */ // End of methods implemented in qlocale.cpp @@ -571,16 +571,16 @@ bool QCalendarBackend::registerAlias(const QString &name) } /*! - Returns a pointer to a named calendar backend. + Returns a pointer to a named calendar backend. - If the given \a name is present in availableCalendars(), the backend matching - it is returned; otherwise, \c nullptr is returned. Matching of names ignores - case. Note that this won't provoke construction of a calendar backend, it will - only return ones that have been instantiated (and not yet destroyed) by some - other means. However, calendars available via the QCalendar::System enum are - always registered when this is called. + If the given \a name is present in availableCalendars(), the backend matching + it is returned; otherwise, \c nullptr is returned. Matching of names ignores + case. Note that this won't provoke construction of a calendar backend, it will + only return ones that have been instantiated (and not yet destroyed) by some + other means. However, calendars available via the QCalendar::System enum are + always registered when this is called. - \sa availableCalendars(), registerAlias(), fromEnum() + \sa availableCalendars(), registerAlias(), fromEnum() */ const QCalendarBackend *QCalendarBackend::fromName(QStringView name) { @@ -592,7 +592,7 @@ const QCalendarBackend *QCalendarBackend::fromName(QStringView name) } /*! - \overload + \overload */ const QCalendarBackend *QCalendarBackend::fromName(QLatin1String name) { @@ -604,11 +604,11 @@ const QCalendarBackend *QCalendarBackend::fromName(QLatin1String name) } /*! - Returns a pointer to a calendar backend, specified by enum. + Returns a pointer to a calendar backend, specified by enum. - This will instantiate the indicated calendar (which will enable fromName() to - return it subsequently), but only for the Qt-supported calendars for which - (where relevant) the appropriate feature has been enabled. + This will instantiate the indicated calendar (which will enable fromName() to + return it subsequently), but only for the Qt-supported calendars for which + (where relevant) the appropriate feature has been enabled. */ const QCalendarBackend *QCalendarBackend::fromEnum(QCalendar::System system) { @@ -643,28 +643,28 @@ const QCalendarBackend *QCalendarBackend::fromEnum(QCalendar::System system) } /*! - \since 5.14 + \since 5.14 - \class QCalendar - \inmodule QtCore - \reentrant - \brief The QCalendar class describes calendar systems. + \class QCalendar + \inmodule QtCore + \reentrant + \brief The QCalendar class describes calendar systems. - A QCalendar object maps a year, month, and day-number to a specific day - (ultimately identified by its Julian day number), using the rules of a - particular system. + A QCalendar object maps a year, month, and day-number to a specific day + (ultimately identified by its Julian day number), using the rules of a + particular system. - The default QCalendar() is a proleptic Gregorian calendar, which has no year - zero. Other calendars may be supported by enabling suitable features or - loading plugins. Calendars supported as features can be constructed by passing - the QCalendar::System enumeration to the constructor. All supported calendars - may be constructed by name, once they have been constructed. (Thus plugins - instantiate their calendar backend to register it.) Built-in backends, - accessible via QCalendar::System, are also always available by name. + The default QCalendar() is a proleptic Gregorian calendar, which has no year + zero. Other calendars may be supported by enabling suitable features or + loading plugins. Calendars supported as features can be constructed by passing + the QCalendar::System enumeration to the constructor. All supported calendars + may be constructed by name, once they have been constructed. (Thus plugins + instantiate their calendar backend to register it.) Built-in backends, + accessible via QCalendar::System, are also always available by name. - A QCalendar value is immutable. + A QCalendar value is immutable. - \sa QDate, QDateTime + \sa QDate, QDateTime */ /*! @@ -684,20 +684,20 @@ const QCalendarBackend *QCalendarBackend::fromEnum(QCalendar::System system) */ /*! - \fn QCalendar::QCalendar() - \fn QCalendar::QCalendar(QCalendar::System system) - \fn QCalendar::QCalendar(QLatin1String name) - \fn QCalendar::QCalendar(QStringView name) + \fn QCalendar::QCalendar() + \fn QCalendar::QCalendar(QCalendar::System system) + \fn QCalendar::QCalendar(QLatin1String name) + \fn QCalendar::QCalendar(QStringView name) - Constructs a calendar object. + Constructs a calendar object. - The choice of calendar to use may be indicated as \a system, using the - enumeration QCalendar::System, or by \a name, using a string (either Unicode - or Latin 1). Construction by name may depend on an instance of the given - calendar being constructed by other means first. With no argument, the default - constructor returns the Gregorian calendar. + The choice of calendar to use may be indicated as \a system, using the + enumeration QCalendar::System, or by \a name, using a string (either Unicode + or Latin 1). Construction by name may depend on an instance of the given + calendar being constructed by other means first. With no argument, the default + constructor returns the Gregorian calendar. - \sa QCalendar, System + \sa QCalendar, System */ QCalendar::QCalendar() @@ -722,13 +722,13 @@ QCalendar::QCalendar(QStringView name) // Date queries: /*! - Returns the number of days in the given \a month of the given \a year. + Returns the number of days in the given \a month of the given \a year. - Months are numbered consecutively, starting with 1 for the first month of each - year. If \a year is \c Unspecified (its default, if not passed), the month's - length in a normal year is returned. + Months are numbered consecutively, starting with 1 for the first month of each + year. If \a year is \c Unspecified (its default, if not passed), the month's + length in a normal year is returned. - \sa maximumDaysInMonth(), minimumDaysInMonth() + \sa maximumDaysInMonth(), minimumDaysInMonth() */ int QCalendar::daysInMonth(int month, int year) const { @@ -736,7 +736,7 @@ int QCalendar::daysInMonth(int month, int year) const } /*! - Returns the number of days in the given \a year. + Returns the number of days in the given \a year. */ int QCalendar::daysInYear(int year) const { @@ -752,12 +752,12 @@ int QCalendar::monthsInYear(int year) const } /*! - Returns \c true precisely if the given \a year, \a month, and \a day specify a - valid date in this calendar. + Returns \c true precisely if the given \a year, \a month, and \a day specify a + valid date in this calendar. - Usually this means 1 <= month <= monthsInYear(year) and 1 <= day <= - daysInMonth(month, year). However, calendars with intercallary days or months - may complicate that. + Usually this means 1 <= month <= monthsInYear(year) and 1 <= day <= + daysInMonth(month, year). However, calendars with intercallary days or months + may complicate that. */ bool QCalendar::isDateValid(int year, int month, int day) const { @@ -777,13 +777,13 @@ bool QCalendar::isGregorian() const } /*! - Returns \c true if the given \a year is a leap year. + Returns \c true if the given \a year is a leap year. - Since the year is not a whole number of days long, some years are longer than - others. The difference may be a whole month or just a single day; the details - vary between calendars. + Since the year is not a whole number of days long, some years are longer than + others. The difference may be a whole month or just a single day; the details + vary between calendars. - \sa isDateValid() + \sa isDateValid() */ bool QCalendar::isLeapYear(int year) const { @@ -791,9 +791,9 @@ bool QCalendar::isLeapYear(int year) const } /*! - Returns \c true if this calendar is a lunar calendar. + Returns \c true if this calendar is a lunar calendar. - A lunar calendar is one based primarily on the phases of the moon. + A lunar calendar is one based primarily on the phases of the moon. */ bool QCalendar::isLunar() const { @@ -801,11 +801,11 @@ bool QCalendar::isLunar() const } /*! - Returns \c true if this calendar is luni-solar. + Returns \c true if this calendar is luni-solar. - A luni-solar calendar expresses the phases of the moon but adapts itself to - also keep track of the Sun's varying position in the sky, relative to the - fixed stars. + A luni-solar calendar expresses the phases of the moon but adapts itself to + also keep track of the Sun's varying position in the sky, relative to the + fixed stars. */ bool QCalendar::isLuniSolar() const { @@ -813,10 +813,10 @@ bool QCalendar::isLuniSolar() const } /*! - Returns \c true if this calendar is solar. + Returns \c true if this calendar is solar. - A solar calendar is based primarily on the Sun's varying position in the sky, - relative to the fixed stars. + A solar calendar is based primarily on the Sun's varying position in the sky, + relative to the fixed stars. */ bool QCalendar::isSolar() const { @@ -824,13 +824,13 @@ bool QCalendar::isSolar() const } /*! - Returns \c true if this calendar is proleptic. + Returns \c true if this calendar is proleptic. - A proleptic calendar is able to describe years arbitrarily long before its - first. These are represented by negative year numbers and possibly by a year - zero. + A proleptic calendar is able to describe years arbitrarily long before its + first. These are represented by negative year numbers and possibly by a year + zero. - \sa hasYearZero() + \sa hasYearZero() */ bool QCalendar::isProleptic() const { @@ -868,9 +868,9 @@ bool QCalendar::hasYearZero() const } /*! - Returns the number of days in the longest month in the calendar, in any year. + Returns the number of days in the longest month in the calendar, in any year. - \sa daysInMonth(), minimumDaysInMonth() + \sa daysInMonth(), minimumDaysInMonth() */ int QCalendar::maximumDaysInMonth() const { @@ -878,9 +878,9 @@ int QCalendar::maximumDaysInMonth() const } /*! - Returns the number of days in the shortest month in the calendar, in any year. + Returns the number of days in the shortest month in the calendar, in any year. - \sa daysInMonth(), maximumDaysInMonth() + \sa daysInMonth(), maximumDaysInMonth() */ int QCalendar::minimumDaysInMonth() const { @@ -888,9 +888,9 @@ int QCalendar::minimumDaysInMonth() const } /*! - Returns the largest number of months that any year may contain. + Returns the largest number of months that any year may contain. - \sa monthName(), standaloneMonthName(), monthsInYear() + \sa monthName(), standaloneMonthName(), monthsInYear() */ int QCalendar::maximumMonthsInYear() const { @@ -940,13 +940,13 @@ QCalendar::YearMonthDay QCalendar::partsFromDate(QDate date) const } /*! - Returns the day of the week number for the given \a date. + Returns the day of the week number for the given \a date. - Returns zero if the calendar is unable to represent the indicated date. - Returns 1 for Monday through 7 for Sunday. Calendars with intercallary days - may use other numbers to represent these. + Returns zero if the calendar is unable to represent the indicated date. + Returns 1 for Monday through 7 for Sunday. Calendars with intercallary days + may use other numbers to represent these. - \sa partsFromDate(), Qt::DayOfWeek + \sa partsFromDate(), Qt::DayOfWeek */ int QCalendar::dayOfWeek(QDate date) const { @@ -956,23 +956,23 @@ int QCalendar::dayOfWeek(QDate date) const // Locale data access /*! - Returns a suitably localised name for a month. + Returns a suitably localised name for a month. - The month is indicated by a number, with \a month = 1 meaning the first month - of the year and subsequent months numbered accordingly. Returns an empty - string if the \a month number is unrecognized. + The month is indicated by a number, with \a month = 1 meaning the first month + of the year and subsequent months numbered accordingly. Returns an empty + string if the \a month number is unrecognized. - The \a year may be Unspecified, in which case the mapping from numbers to - names for a typical year's months should be used. Some calendars have leap - months that aren't always at the end of the year; their mapping of month - numbers to names may then depend on the placement of a leap month. Thus the - year should normally be specified, if known. + The \a year may be Unspecified, in which case the mapping from numbers to + names for a typical year's months should be used. Some calendars have leap + months that aren't always at the end of the year; their mapping of month + numbers to names may then depend on the placement of a leap month. Thus the + year should normally be specified, if known. - The name is returned in the form that would normally be used in a full date, - in the specified \a locale; the \a format determines how fully it shall be - expressed (i.e. to what extent it is abbreviated). + The name is returned in the form that would normally be used in a full date, + in the specified \a locale; the \a format determines how fully it shall be + expressed (i.e. to what extent it is abbreviated). - \sa standaloneMonthName(), maximumMonthsInYear(), dateTimeToString() + \sa standaloneMonthName(), maximumMonthsInYear(), dateTimeToString() */ QString QCalendar::monthName(const QLocale &locale, int month, int year, QLocale::FormatType format) const @@ -985,23 +985,23 @@ QString QCalendar::monthName(const QLocale &locale, int month, int year, } /*! - Returns a suitably localised standalone name for a month. + Returns a suitably localised standalone name for a month. - The month is indicated by a number, with \a month = 1 meaning the first month - of the year and subsequent months numbered accordingly. Returns an empty - string if the \a month number is unrecognized. + The month is indicated by a number, with \a month = 1 meaning the first month + of the year and subsequent months numbered accordingly. Returns an empty + string if the \a month number is unrecognized. - The \a year may be Unspecified, in which case the mapping from numbers to - names for a typical year's months should be used. Some calendars have leap - months that aren't always at the end of the year; their mapping of month - numbers to names may then depend on the placement of a leap month. Thus the - year should normally be specified, if known. + The \a year may be Unspecified, in which case the mapping from numbers to + names for a typical year's months should be used. Some calendars have leap + months that aren't always at the end of the year; their mapping of month + numbers to names may then depend on the placement of a leap month. Thus the + year should normally be specified, if known. - The name is returned in the form that would be used in isolation in the - specified \a locale; the \a format determines how fully it shall be expressed - (i.e. to what extent it is abbreviated). + The name is returned in the form that would be used in isolation in the + specified \a locale; the \a format determines how fully it shall be expressed + (i.e. to what extent it is abbreviated). - \sa monthName(), maximumMonthsInYear(), dateTimeToString() + \sa monthName(), maximumMonthsInYear(), dateTimeToString() */ QString QCalendar::standaloneMonthName(const QLocale &locale, int month, int year, QLocale::FormatType format) const @@ -1014,18 +1014,18 @@ QString QCalendar::standaloneMonthName(const QLocale &locale, int month, int yea } /*! - Returns a suitably localised name for a day of the week. + Returns a suitably localised name for a day of the week. - The days of the week are numbered from 1 for Monday through 7 for Sunday. Some - calendars may support higher numbers for other days (e.g. intercallary days, - that are not part of any week). Returns an empty string if the \a day number - is unrecognized. + The days of the week are numbered from 1 for Monday through 7 for Sunday. Some + calendars may support higher numbers for other days (e.g. intercallary days, + that are not part of any week). Returns an empty string if the \a day number + is unrecognized. - The name is returned in the form that would normally be used in a full date, - in the specified \a locale; the \a format determines how fully it shall be - expressed (i.e. to what extent it is abbreviated). + The name is returned in the form that would normally be used in a full date, + in the specified \a locale; the \a format determines how fully it shall be + expressed (i.e. to what extent it is abbreviated). - \sa standaloneWeekDayName(), dayOfWeek() + \sa standaloneWeekDayName(), dayOfWeek() */ QString QCalendar::weekDayName(const QLocale &locale, int day, QLocale::FormatType format) const @@ -1034,19 +1034,19 @@ QString QCalendar::weekDayName(const QLocale &locale, int day, } /*! - Returns a suitably localised standalone name for a day of the week. + Returns a suitably localised standalone name for a day of the week. - The days of the week are numbered from 1 for Monday through 7 for Sunday. Some - calendars may support higher numbers for other days (e.g. intercallary days, - that are not part of any week). Returns an empty string if the \a day number - is unrecognized. + The days of the week are numbered from 1 for Monday through 7 for Sunday. Some + calendars may support higher numbers for other days (e.g. intercallary days, + that are not part of any week). Returns an empty string if the \a day number + is unrecognized. - The name is returned in the form that would be used in isolation (for example - as a column heading in a calendar's tabular display of a month with successive - weeks as rows) in the specified \a locale; the \a format determines how fully - it shall be expressed (i.e. to what extent it is abbreviated). + The name is returned in the form that would be used in isolation (for example + as a column heading in a calendar's tabular display of a month with successive + weeks as rows) in the specified \a locale; the \a format determines how fully + it shall be expressed (i.e. to what extent it is abbreviated). - \sa weekDayName(), dayOfWeek() + \sa weekDayName(), dayOfWeek() */ QString QCalendar::standaloneWeekDayName(const QLocale &locale, int day, QLocale::FormatType format) const @@ -1055,23 +1055,23 @@ QString QCalendar::standaloneWeekDayName(const QLocale &locale, int day, } /*! - Returns a string representing a given date, time or date-time. - - If \a datetime is valid, it is represented and format specifiers for both date - and time fields are recognized; otherwise, if \a dateOnly is valid, it is - represented and only format specifiers for date fields are recognized; - finally, if \a timeOnly is valid, it is represented and only format specifiers - for time fields are recognized. If none of these is valid, an empty string is - returned. - - See QDate::toString and QTime::toString() for the supported field specifiers. - Characters in \a format that are recognized as field specifiers are replaced - by text representing appropriate data from the date and/or time being - represented. The texts to represent them may depend on the \a locale - specified. Other charagers in \a format are copied verbatim into the returned - string. - - \sa monthName(), weekDayName(), QDate::toString(), QTime::toString() + Returns a string representing a given date, time or date-time. + + If \a datetime is valid, it is represented and format specifiers for both date + and time fields are recognized; otherwise, if \a dateOnly is valid, it is + represented and only format specifiers for date fields are recognized; + finally, if \a timeOnly is valid, it is represented and only format specifiers + for time fields are recognized. If none of these is valid, an empty string is + returned. + + See QDate::toString and QTime::toString() for the supported field specifiers. + Characters in \a format that are recognized as field specifiers are replaced + by text representing appropriate data from the date and/or time being + represented. The texts to represent them may depend on the \a locale + specified. Other charagers in \a format are copied verbatim into the returned + string. + + \sa monthName(), weekDayName(), QDate::toString(), QTime::toString() */ QString QCalendar::dateTimeToString(QStringView format, const QDateTime &datetime, const QDate &dateOnly, const QTime &timeOnly, diff --git a/src/corelib/time/qhijricalendar.cpp b/src/corelib/time/qhijricalendar.cpp index a0e6905e91..0c5fa5d739 100644 --- a/src/corelib/time/qhijricalendar.cpp +++ b/src/corelib/time/qhijricalendar.cpp @@ -44,37 +44,37 @@ QT_BEGIN_NAMESPACE /*! - \since 5.14 - \internal + \since 5.14 + \internal - \class QHijriCalendar - \inmodule QtCore - \brief The QHijriCalendar class supports Islamic (Hijri) calendar implementations. + \class QHijriCalendar + \inmodule QtCore + \brief The QHijriCalendar class supports Islamic (Hijri) calendar implementations. - \section1 Islamic Calendar System + \section1 Islamic Calendar System - The Islamic, Muslim, or Hijri calendar is a lunar calendar consisting of 12 - months in a year of 354 or 355 days. It is used (often alongside the - Gregorian calendar) to date events in many Muslim countries. It is also used - by Muslims to determine the proper days of Islamic holidays and rituals, - such as the annual period of fasting and the proper time for the pilgrimage - to Mecca. + The Islamic, Muslim, or Hijri calendar is a lunar calendar consisting of 12 + months in a year of 354 or 355 days. It is used (often alongside the + Gregorian calendar) to date events in many Muslim countries. It is also used + by Muslims to determine the proper days of Islamic holidays and rituals, + such as the annual period of fasting and the proper time for the pilgrimage + to Mecca. - Source: \l {https://en.wikipedia.org/wiki/Islamic_calendar}{Wikipedia page on - Hijri Calendar} + Source: \l {https://en.wikipedia.org/wiki/Islamic_calendar}{Wikipedia page on + Hijri Calendar} - \section1 Support for variants + \section1 Support for variants - This base class provides the common details shared by all variants on the - Islamic calendar. Each year comprises 12 months of 29 or 30 days each; most - years have as many of 29 as of 30, but leap years extend one 29-day month to - 30 days. In tabular versions of the calendar (where mathematical rules are - used to determine the details), odd-numbered months have 30 days, as does the - last (twelfth) month of a leap year; all other months have 29 days. Other - versions are based on actual astronomical observations of the moon's phase at - sunset, which vary from place to place. + This base class provides the common details shared by all variants on the + Islamic calendar. Each year comprises 12 months of 29 or 30 days each; most + years have as many of 29 as of 30, but leap years extend one 29-day month to + 30 days. In tabular versions of the calendar (where mathematical rules are + used to determine the details), odd-numbered months have 30 days, as does the + last (twelfth) month of a leap year; all other months have 29 days. Other + versions are based on actual astronomical observations of the moon's phase at + sunset, which vary from place to place. - \sa QIslamicCivilCalendar, QCalendar + \sa QIslamicCivilCalendar, QCalendar */ bool QHijriCalendar::isLunar() const diff --git a/src/corelib/time/qislamiccivilcalendar.cpp b/src/corelib/time/qislamiccivilcalendar.cpp index 84562849cc..deee0c0fc8 100644 --- a/src/corelib/time/qislamiccivilcalendar.cpp +++ b/src/corelib/time/qislamiccivilcalendar.cpp @@ -47,28 +47,28 @@ QT_BEGIN_NAMESPACE using namespace QRoundingDown; /*! - \since 5.14 - \internal + \since 5.14 + \internal - \class QIslamicCivilCalendar - \inmodule QtCore - \brief Implements a commonly-used computed version of the Islamic calendar. + \class QIslamicCivilCalendar + \inmodule QtCore + \brief Implements a commonly-used computed version of the Islamic calendar. - \section1 Civil Islamic Calendar + \section1 Civil Islamic Calendar - QIslamicCivilCalendar implements a tabular version of the Hijri calendar which - is known as the Islamic Civil Calendar. It has the same numbering of years and - months, but the months are determined by arithmetical rules rather than by - observation or astronomical calculations. + QIslamicCivilCalendar implements a tabular version of the Hijri calendar which + is known as the Islamic Civil Calendar. It has the same numbering of years and + months, but the months are determined by arithmetical rules rather than by + observation or astronomical calculations. - \section2 Calendar Organization + \section2 Calendar Organization - The civil calendar follows the usual tabular scheme of odd-numbered months and - the last month of each leap year being 30 days long, the rest being 29 days - long. Its determination of leap years follows a 30-year cycle, in each of - which the years 2, 5, 7, 10, 13, 16, 18, 21, 24, 26 and 29 are leap years. + The civil calendar follows the usual tabular scheme of odd-numbered months and + the last month of each leap year being 30 days long, the rest being 29 days + long. Its determination of leap years follows a 30-year cycle, in each of + which the years 2, 5, 7, 10, 13, 16, 18, 21, 24, 26 and 29 are leap years. - \sa QHijriCalendar, QCalendar + \sa QHijriCalendar, QCalendar */ QIslamicCivilCalendar::QIslamicCivilCalendar() diff --git a/src/corelib/time/qromancalendar.cpp b/src/corelib/time/qromancalendar.cpp index 36cad01b81..b65e243ea6 100644 --- a/src/corelib/time/qromancalendar.cpp +++ b/src/corelib/time/qromancalendar.cpp @@ -44,20 +44,20 @@ QT_BEGIN_NAMESPACE /*! - \since 5.14 + \since 5.14 - \class QRomanCalendar - \inmodule QtCore - \brief The QRomanCalendar class is a shared base for calendars based on the - ancient Roman calendar. + \class QRomanCalendar + \inmodule QtCore + \brief The QRomanCalendar class is a shared base for calendars based on the + ancient Roman calendar. - \section1 + \section1 - Calendars based on the ancient Roman calendar share the names of months, whose - lengths depend in a common way on whether the year is a leap year. They differ - in how they determine which years are leap years. + Calendars based on the ancient Roman calendar share the names of months, whose + lengths depend in a common way on whether the year is a leap year. They differ + in how they determine which years are leap years. - \sa QGregorianCalendar, QJulianCalendar, QMilankovicCalendar + \sa QGregorianCalendar, QJulianCalendar, QMilankovicCalendar */ int QRomanCalendar::daysInMonth(int month, int year) const -- cgit v1.2.3 From da3c2cc6a8a5733df61d11e712a5d5a3574960ca Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Thu, 5 Sep 2019 14:57:56 +0200 Subject: Reflow documentation after indentation change Combining this with the indentation would be counted as mixing space changes with non-space changes, so they're separate. Change-Id: Iac57050717b1c4c86a253866c9a6cd5ea7add8f7 Reviewed-by: Paul Wicking --- src/corelib/time/qcalendar.cpp | 193 +++++++++++++++-------------- src/corelib/time/qhijricalendar.cpp | 12 +- src/corelib/time/qislamiccivilcalendar.cpp | 17 +-- src/corelib/time/qromancalendar.cpp | 6 +- 4 files changed, 117 insertions(+), 111 deletions(-) (limited to 'src') diff --git a/src/corelib/time/qcalendar.cpp b/src/corelib/time/qcalendar.cpp index efd13ed3ad..d706f1d5ab 100644 --- a/src/corelib/time/qcalendar.cpp +++ b/src/corelib/time/qcalendar.cpp @@ -443,13 +443,14 @@ int QCalendarBackend::dayOfWeek(qint64 jd) const \fn QString QCalendarBackend::monthName(const QLocale &locale, int month, int year, QLocale::FormatType format) const - Returns the name of the specified \a month in the given \a year for the chosen - \a locale, using the given \a format to determine how complete the name is. + Returns the name of the specified \a month in the given \a year for the + chosen \a locale, using the given \a format to determine how complete the + name is. - If \a year is Unspecified, return the name for the month that usually has this - number within a typical year. Calendars with a leap month that isn't always - the last may need to take account of the year to map the month number to the - particular year's month with that number. + If \a year is Unspecified, return the name for the month that usually has + this number within a typical year. Calendars with a leap month that isn't + always the last may need to take account of the year to map the month number + to the particular year's month with that number. \note Backends for which CLDR provides data can configure the default implementation of the two month name look-up methods by arranging for @@ -465,8 +466,8 @@ int QCalendarBackend::dayOfWeek(qint64 jd) const \fn QString QCalendarBackend::standaloneMonthName(const QLocale &locale, int month, int year QLocale::FormatType format) const - Returns the standalone name of the specified \a month in the chosen \a locale, - using the specified \a format to determine how complete the name is. + Returns the standalone name of the specified \a month in the chosen \a + locale, using the specified \a format to determine how complete the name is. If \a year is Unspecified, return the standalone name for the month that usually has this number within a typical year. Calendars with a leap month @@ -480,16 +481,17 @@ int QCalendarBackend::dayOfWeek(qint64 jd) const \fn QString QCalendarBackend::weekDayName(const QLocale &locale, int day, QLocale::FormatType format) const - Returns the name of the specified \a day of the week in the chosen \a locale, - using the specified \a format to determine how complete the name is. + Returns the name of the specified \a day of the week in the chosen \a + locale, using the specified \a format to determine how complete the name is. - The base implementation handles \a day values from 1 to 7 using the day names - CLDR provides, which are suitable for calendards that use the same + The base implementation handles \a day values from 1 to 7 using the day + names CLDR provides, which are suitable for calendards that use the same (Hebrew-derived) week as the Gregorian calendar. - Calendars whose dayOfWeek() returns a value outside the range from 1 to 7 need - to reimplement this method to handle such extra week-day values. They can - assume that \a day is a value returned by the same calendar's dayOfWeek(). + Calendars whose dayOfWeek() returns a value outside the range from 1 to 7 + need to reimplement this method to handle such extra week-day values. They + can assume that \a day is a value returned by the same calendar's + dayOfWeek(). \sa dayOfWeek(), standaloneWeekDayName(), QLocale::dayName() */ @@ -498,17 +500,18 @@ int QCalendarBackend::dayOfWeek(qint64 jd) const \fn QString QCalendarBackend::standaloneWeekDayName(const QLocale &locale, int day, QLocale::FormatType format) const - Returns the standalone name of the specified \a day of the week in the chosen - \a locale, using the specified \a format to determine how complete the name - is. + Returns the standalone name of the specified \a day of the week in the + chosen \a locale, using the specified \a format to determine how complete + the name is. - The base implementation handles \a day values from 1 to 7 using the standalone - day names CLDR provides, which are suitable for calendards that use the same - (Hebrew-derived) week as the Gregorian calendar. + The base implementation handles \a day values from 1 to 7 using the + standalone day names CLDR provides, which are suitable for calendards that + use the same (Hebrew-derived) week as the Gregorian calendar. - Calendars whose dayOfWeek() returns a value outside the range from 1 to 7 need - to reimplement this method to handle such extra week-day values. They can - assume that \a day is a value returned by the same calendar's dayOfWeek(). + Calendars whose dayOfWeek() returns a value outside the range from 1 to 7 + need to reimplement this method to handle such extra week-day values. They + can assume that \a day is a value returned by the same calendar's + dayOfWeek(). \sa dayOfWeek(), weekDayName(), QLocale::standaloneDayName() */ @@ -521,18 +524,18 @@ int QCalendarBackend::dayOfWeek(qint64 jd) const Returns a string representing a given date, time or date-time. If \a datetime is specified and valid, it is used and both date and time - format tokens are converted to appropriate representations of the parts of the - datetime. Otherwise, if \a dateOnly is valid, only date format tokens are - converted; else, if \a timeOnly is valid, only time format tokens are + format tokens are converted to appropriate representations of the parts of + the datetime. Otherwise, if \a dateOnly is valid, only date format tokens + are converted; else, if \a timeOnly is valid, only time format tokens are converted. If none are valid, an empty string is returned. The specified \a locale influences how some format tokens are converted; for - example, when substituting day and month names and their short-forms. For the - supported formatting tokens, see QDate::toString() and QTime::toString(). As - described above, the provided date, time and date-time determine which of - these tokens are recognized: where these appear in \a format they are replaced - by data. Any text in \a format not recognized as a format token is copied - verbatim into the result string. + example, when substituting day and month names and their short-forms. For + the supported formatting tokens, see QDate::toString() and + QTime::toString(). As described above, the provided date, time and date-time + determine which of these tokens are recognized: where these appear in \a + format they are replaced by data. Any text in \a format not recognized as a + format token is copied verbatim into the result string. \sa QDate::toString(), QTime::toString(), QDateTime::toString() */ @@ -573,12 +576,12 @@ bool QCalendarBackend::registerAlias(const QString &name) /*! Returns a pointer to a named calendar backend. - If the given \a name is present in availableCalendars(), the backend matching - it is returned; otherwise, \c nullptr is returned. Matching of names ignores - case. Note that this won't provoke construction of a calendar backend, it will - only return ones that have been instantiated (and not yet destroyed) by some - other means. However, calendars available via the QCalendar::System enum are - always registered when this is called. + If the given \a name is present in availableCalendars(), the backend + matching it is returned; otherwise, \c nullptr is returned. Matching of + names ignores case. Note that this won't provoke construction of a calendar + backend, it will only return ones that have been instantiated (and not yet + destroyed) by some other means. However, calendars available via the + QCalendar::System enum are always registered when this is called. \sa availableCalendars(), registerAlias(), fromEnum() */ @@ -606,9 +609,9 @@ const QCalendarBackend *QCalendarBackend::fromName(QLatin1String name) /*! Returns a pointer to a calendar backend, specified by enum. - This will instantiate the indicated calendar (which will enable fromName() to - return it subsequently), but only for the Qt-supported calendars for which - (where relevant) the appropriate feature has been enabled. + This will instantiate the indicated calendar (which will enable fromName() + to return it subsequently), but only for the Qt-supported calendars for + which (where relevant) the appropriate feature has been enabled. */ const QCalendarBackend *QCalendarBackend::fromEnum(QCalendar::System system) { @@ -656,11 +659,12 @@ const QCalendarBackend *QCalendarBackend::fromEnum(QCalendar::System system) The default QCalendar() is a proleptic Gregorian calendar, which has no year zero. Other calendars may be supported by enabling suitable features or - loading plugins. Calendars supported as features can be constructed by passing - the QCalendar::System enumeration to the constructor. All supported calendars - may be constructed by name, once they have been constructed. (Thus plugins - instantiate their calendar backend to register it.) Built-in backends, - accessible via QCalendar::System, are also always available by name. + loading plugins. Calendars supported as features can be constructed by + passing the QCalendar::System enumeration to the constructor. All supported + calendars may be constructed by name, once they have been constructed. (Thus + plugins instantiate their calendar backend to register it.) Built-in + backends, accessible via QCalendar::System, are also always available by + name. A QCalendar value is immutable. @@ -694,8 +698,8 @@ const QCalendarBackend *QCalendarBackend::fromEnum(QCalendar::System system) The choice of calendar to use may be indicated as \a system, using the enumeration QCalendar::System, or by \a name, using a string (either Unicode or Latin 1). Construction by name may depend on an instance of the given - calendar being constructed by other means first. With no argument, the default - constructor returns the Gregorian calendar. + calendar being constructed by other means first. With no argument, the + default constructor returns the Gregorian calendar. \sa QCalendar, System */ @@ -724,9 +728,9 @@ QCalendar::QCalendar(QStringView name) /*! Returns the number of days in the given \a month of the given \a year. - Months are numbered consecutively, starting with 1 for the first month of each - year. If \a year is \c Unspecified (its default, if not passed), the month's - length in a normal year is returned. + Months are numbered consecutively, starting with 1 for the first month of + each year. If \a year is \c Unspecified (its default, if not passed), the + month's length in a normal year is returned. \sa maximumDaysInMonth(), minimumDaysInMonth() */ @@ -752,12 +756,12 @@ int QCalendar::monthsInYear(int year) const } /*! - Returns \c true precisely if the given \a year, \a month, and \a day specify a - valid date in this calendar. + Returns \c true precisely if the given \a year, \a month, and \a day specify + a valid date in this calendar. Usually this means 1 <= month <= monthsInYear(year) and 1 <= day <= - daysInMonth(month, year). However, calendars with intercallary days or months - may complicate that. + daysInMonth(month, year). However, calendars with intercallary days or + months may complicate that. */ bool QCalendar::isDateValid(int year, int month, int day) const { @@ -779,9 +783,9 @@ bool QCalendar::isGregorian() const /*! Returns \c true if the given \a year is a leap year. - Since the year is not a whole number of days long, some years are longer than - others. The difference may be a whole month or just a single day; the details - vary between calendars. + Since the year is not a whole number of days long, some years are longer + than others. The difference may be a whole month or just a single day; the + details vary between calendars. \sa isDateValid() */ @@ -815,8 +819,8 @@ bool QCalendar::isLuniSolar() const /*! Returns \c true if this calendar is solar. - A solar calendar is based primarily on the Sun's varying position in the sky, - relative to the fixed stars. + A solar calendar is based primarily on the Sun's varying position in the + sky, relative to the fixed stars. */ bool QCalendar::isSolar() const { @@ -958,9 +962,9 @@ int QCalendar::dayOfWeek(QDate date) const /*! Returns a suitably localised name for a month. - The month is indicated by a number, with \a month = 1 meaning the first month - of the year and subsequent months numbered accordingly. Returns an empty - string if the \a month number is unrecognized. + The month is indicated by a number, with \a month = 1 meaning the first + month of the year and subsequent months numbered accordingly. Returns an + empty string if the \a month number is unrecognized. The \a year may be Unspecified, in which case the mapping from numbers to names for a typical year's months should be used. Some calendars have leap @@ -987,9 +991,9 @@ QString QCalendar::monthName(const QLocale &locale, int month, int year, /*! Returns a suitably localised standalone name for a month. - The month is indicated by a number, with \a month = 1 meaning the first month - of the year and subsequent months numbered accordingly. Returns an empty - string if the \a month number is unrecognized. + The month is indicated by a number, with \a month = 1 meaning the first + month of the year and subsequent months numbered accordingly. Returns an + empty string if the \a month number is unrecognized. The \a year may be Unspecified, in which case the mapping from numbers to names for a typical year's months should be used. Some calendars have leap @@ -998,8 +1002,8 @@ QString QCalendar::monthName(const QLocale &locale, int month, int year, year should normally be specified, if known. The name is returned in the form that would be used in isolation in the - specified \a locale; the \a format determines how fully it shall be expressed - (i.e. to what extent it is abbreviated). + specified \a locale; the \a format determines how fully it shall be + expressed (i.e. to what extent it is abbreviated). \sa monthName(), maximumMonthsInYear(), dateTimeToString() */ @@ -1016,10 +1020,10 @@ QString QCalendar::standaloneMonthName(const QLocale &locale, int month, int yea /*! Returns a suitably localised name for a day of the week. - The days of the week are numbered from 1 for Monday through 7 for Sunday. Some - calendars may support higher numbers for other days (e.g. intercallary days, - that are not part of any week). Returns an empty string if the \a day number - is unrecognized. + The days of the week are numbered from 1 for Monday through 7 for + Sunday. Some calendars may support higher numbers for other days + (e.g. intercallary days, that are not part of any week). Returns an empty + string if the \a day number is unrecognized. The name is returned in the form that would normally be used in a full date, in the specified \a locale; the \a format determines how fully it shall be @@ -1036,15 +1040,16 @@ QString QCalendar::weekDayName(const QLocale &locale, int day, /*! Returns a suitably localised standalone name for a day of the week. - The days of the week are numbered from 1 for Monday through 7 for Sunday. Some - calendars may support higher numbers for other days (e.g. intercallary days, - that are not part of any week). Returns an empty string if the \a day number - is unrecognized. + The days of the week are numbered from 1 for Monday through 7 for + Sunday. Some calendars may support higher numbers for other days + (e.g. intercallary days, that are not part of any week). Returns an empty + string if the \a day number is unrecognized. - The name is returned in the form that would be used in isolation (for example - as a column heading in a calendar's tabular display of a month with successive - weeks as rows) in the specified \a locale; the \a format determines how fully - it shall be expressed (i.e. to what extent it is abbreviated). + The name is returned in the form that would be used in isolation (for + example as a column heading in a calendar's tabular display of a month with + successive weeks as rows) in the specified \a locale; the \a format + determines how fully it shall be expressed (i.e. to what extent it is + abbreviated). \sa weekDayName(), dayOfWeek() */ @@ -1057,19 +1062,19 @@ QString QCalendar::standaloneWeekDayName(const QLocale &locale, int day, /*! Returns a string representing a given date, time or date-time. - If \a datetime is valid, it is represented and format specifiers for both date - and time fields are recognized; otherwise, if \a dateOnly is valid, it is - represented and only format specifiers for date fields are recognized; - finally, if \a timeOnly is valid, it is represented and only format specifiers - for time fields are recognized. If none of these is valid, an empty string is - returned. - - See QDate::toString and QTime::toString() for the supported field specifiers. - Characters in \a format that are recognized as field specifiers are replaced - by text representing appropriate data from the date and/or time being - represented. The texts to represent them may depend on the \a locale - specified. Other charagers in \a format are copied verbatim into the returned - string. + If \a datetime is valid, it is represented and format specifiers for both + date and time fields are recognized; otherwise, if \a dateOnly is valid, it + is represented and only format specifiers for date fields are recognized; + finally, if \a timeOnly is valid, it is represented and only format + specifiers for time fields are recognized. If none of these is valid, an + empty string is returned. + + See QDate::toString and QTime::toString() for the supported field + specifiers. Characters in \a format that are recognized as field specifiers + are replaced by text representing appropriate data from the date and/or time + being represented. The texts to represent them may depend on the \a locale + specified. Other charagers in \a format are copied verbatim into the + returned string. \sa monthName(), weekDayName(), QDate::toString(), QTime::toString() */ diff --git a/src/corelib/time/qhijricalendar.cpp b/src/corelib/time/qhijricalendar.cpp index 0c5fa5d739..b5d89fbc5c 100644 --- a/src/corelib/time/qhijricalendar.cpp +++ b/src/corelib/time/qhijricalendar.cpp @@ -60,8 +60,8 @@ QT_BEGIN_NAMESPACE such as the annual period of fasting and the proper time for the pilgrimage to Mecca. - Source: \l {https://en.wikipedia.org/wiki/Islamic_calendar}{Wikipedia page on - Hijri Calendar} + Source: \l {https://en.wikipedia.org/wiki/Islamic_calendar}{Wikipedia page + on Hijri Calendar} \section1 Support for variants @@ -69,10 +69,10 @@ QT_BEGIN_NAMESPACE Islamic calendar. Each year comprises 12 months of 29 or 30 days each; most years have as many of 29 as of 30, but leap years extend one 29-day month to 30 days. In tabular versions of the calendar (where mathematical rules are - used to determine the details), odd-numbered months have 30 days, as does the - last (twelfth) month of a leap year; all other months have 29 days. Other - versions are based on actual astronomical observations of the moon's phase at - sunset, which vary from place to place. + used to determine the details), odd-numbered months have 30 days, as does + the last (twelfth) month of a leap year; all other months have 29 + days. Other versions are based on actual astronomical observations of the + moon's phase at sunset, which vary from place to place. \sa QIslamicCivilCalendar, QCalendar */ diff --git a/src/corelib/time/qislamiccivilcalendar.cpp b/src/corelib/time/qislamiccivilcalendar.cpp index deee0c0fc8..a6a2afd207 100644 --- a/src/corelib/time/qislamiccivilcalendar.cpp +++ b/src/corelib/time/qislamiccivilcalendar.cpp @@ -56,17 +56,18 @@ using namespace QRoundingDown; \section1 Civil Islamic Calendar - QIslamicCivilCalendar implements a tabular version of the Hijri calendar which - is known as the Islamic Civil Calendar. It has the same numbering of years and - months, but the months are determined by arithmetical rules rather than by - observation or astronomical calculations. + QIslamicCivilCalendar implements a tabular version of the Hijri calendar + which is known as the Islamic Civil Calendar. It has the same numbering of + years and months, but the months are determined by arithmetical rules rather + than by observation or astronomical calculations. \section2 Calendar Organization - The civil calendar follows the usual tabular scheme of odd-numbered months and - the last month of each leap year being 30 days long, the rest being 29 days - long. Its determination of leap years follows a 30-year cycle, in each of - which the years 2, 5, 7, 10, 13, 16, 18, 21, 24, 26 and 29 are leap years. + The civil calendar follows the usual tabular scheme of odd-numbered months + and the last month of each leap year being 30 days long, the rest being 29 + days long. Its determination of leap years follows a 30-year cycle, in each + of which the years 2, 5, 7, 10, 13, 16, 18, 21, 24, 26 and 29 are leap + years. \sa QHijriCalendar, QCalendar */ diff --git a/src/corelib/time/qromancalendar.cpp b/src/corelib/time/qromancalendar.cpp index b65e243ea6..c3cd134490 100644 --- a/src/corelib/time/qromancalendar.cpp +++ b/src/corelib/time/qromancalendar.cpp @@ -53,9 +53,9 @@ QT_BEGIN_NAMESPACE \section1 - Calendars based on the ancient Roman calendar share the names of months, whose - lengths depend in a common way on whether the year is a leap year. They differ - in how they determine which years are leap years. + Calendars based on the ancient Roman calendar share the names of months, + whose lengths depend in a common way on whether the year is a leap + year. They differ in how they determine which years are leap years. \sa QGregorianCalendar, QJulianCalendar, QMilankovicCalendar */ -- cgit v1.2.3 From 6cee284001adf9da42b347a074cbff3cb92621b2 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Tue, 10 Sep 2019 16:39:43 +0200 Subject: Fix mis-handling of actual TLD in qIsEffectiveTLD() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the domain passed down is an actual TLD that's the subject of a * rule, e.g. "ck" subject to *.ck, then we were finding no dot in it and concluding that it couldn't be the subject of a * rule. Added a test for the specific .ck case and commented on where we could get some canonical test data that I tripped over while researching this. Cross-reference the cookie-jar test from the QUrl test, too. Fixes: QTBUG-78097 Change-Id: Id858a9dae22e6b306a68df3fc199e0160f537159 Reviewed-by: Mårten Nordheim Reviewed-by: Thiago Macieira --- src/corelib/io/qtldurl.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/corelib/io/qtldurl.cpp b/src/corelib/io/qtldurl.cpp index 912609ec91..fc3e16b241 100644 --- a/src/corelib/io/qtldurl.cpp +++ b/src/corelib/io/qtldurl.cpp @@ -125,10 +125,10 @@ Q_CORE_EXPORT bool qIsEffectiveTLD(const QStringRef &domain) return true; const int dot = domain.indexOf(QLatin1Char('.')); - if (dot >= 0) { - if (containsTLDEntry(domain.mid(dot), SuffixMatch)) // 2 - return !containsTLDEntry(domain, ExceptionMatch); // 3 - } + if (dot < 0) // Actual TLD: may be effective if the subject of a wildcard rule: + return containsTLDEntry(QString(QLatin1Char('.') + domain), SuffixMatch); + if (containsTLDEntry(domain.mid(dot), SuffixMatch)) // 2 + return !containsTLDEntry(domain, ExceptionMatch); // 3 return false; } -- cgit v1.2.3 From b26ac46c5956e716821e64f291749be110731f16 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Fri, 6 Sep 2019 17:32:12 +0200 Subject: Add support for UTC[+-]\d+(:\d+){,2} time zone IDs We presently only support the UTC-based offset timezones that are listed in the CLDR; and it doesn't make sense to list more than these in the list of available zones. However, if someone sets their TZ environment variable to a conformant UTC-offset string, we should make sense of it even if CLDR doesn't mention it. Only do so as final fall-back, as backends may handle the givne name better (some such IDs appear in the windows-compatibility list, for example). Added tests for the new UTC-offset time-zone names. Removed one test that relied on them not being supported. [ChangeLog][QtCore][QTimeZone] The constructor can now handle general UTC-offset zone names. The reported id() of such a zone shall be in canonical form, so might not match the ID passed to the constructor. Fixes: QTBUG-77738 Change-Id: I9a0aa68281a345c4717915c8a8fbc2978490d0aa Reviewed-by: Thiago Macieira --- src/corelib/time/qtimezone.cpp | 23 +++++++++++++---- src/corelib/time/qtimezoneprivate.cpp | 48 ++++++++++++++++++++++++++++++++--- src/corelib/time/qtimezoneprivate_p.h | 3 +++ 3 files changed, 65 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/corelib/time/qtimezone.cpp b/src/corelib/time/qtimezone.cpp index ef323de14a..410a16e3c5 100644 --- a/src/corelib/time/qtimezone.cpp +++ b/src/corelib/time/qtimezone.cpp @@ -325,20 +325,33 @@ QTimeZone::QTimeZone() noexcept /*! Creates an instance of the requested time zone \a ianaId. - The ID must be one of the available system IDs otherwise an invalid - time zone will be returned. + The ID must be one of the available system IDs or a valid UTC-with-offset + ID, otherwise an invalid time zone will be returned. \sa availableTimeZoneIds() */ QTimeZone::QTimeZone(const QByteArray &ianaId) { - // Try and see if it's a valid UTC offset ID, just as quick to try create as look-up + // Try and see if it's a CLDR UTC offset ID - just as quick by creating as + // by looking up. d = new QUtcTimeZonePrivate(ianaId); - // If not a valid UTC offset ID then try create it with the system backend - // Relies on backend not creating valid tz with invalid name + // If not a CLDR UTC offset ID then try creating it with the system backend. + // Relies on backend not creating valid TZ with invalid name. if (!d->isValid()) d = newBackendTimeZone(ianaId); + // Can also handle UTC with arbitrary (valid) offset, but only do so as + // fall-back, since either of the above may handle it more informatively. + if (!d->isValid()) { + qint64 offset = QUtcTimeZonePrivate::offsetFromUtcString(ianaId); + if (offset != QTimeZonePrivate::invalidSeconds()) { + // Should have abs(offset) < 24 * 60 * 60 = 86400. + qint32 seconds = qint32(offset); + Q_ASSERT(qint64(seconds) == offset); + // NB: this canonicalises the name, so it might not match ianaId + d = new QUtcTimeZonePrivate(seconds); + } + } } /*! diff --git a/src/corelib/time/qtimezoneprivate.cpp b/src/corelib/time/qtimezoneprivate.cpp index 569b343187..72a0e3c24e 100644 --- a/src/corelib/time/qtimezoneprivate.cpp +++ b/src/corelib/time/qtimezoneprivate.cpp @@ -1,5 +1,6 @@ /**************************************************************************** ** +** Copyright (C) 2019 The Qt Company Ltd. ** Copyright (C) 2013 John Layt ** Contact: https://www.qt.io/licensing/ ** @@ -761,6 +762,39 @@ QUtcTimeZonePrivate::QUtcTimeZonePrivate(const QByteArray &id) } } +qint64 QUtcTimeZonePrivate::offsetFromUtcString(const QByteArray &id) +{ + // Convert reasonable UTC[+-]\d+(:\d+){,2} to offset in seconds. + // Assumption: id has already been tried as a CLDR UTC offset ID (notably + // including plain "UTC" itself) and a system offset ID; it's neither. + if (!id.startsWith("UTC") || id.size() < 5) + return invalidSeconds(); // Doesn't match + const char signChar = id.at(3); + if (signChar != '-' && signChar != '+') + return invalidSeconds(); // No sign + const int sign = signChar == '-' ? -1 : 1; + + const auto offsets = id.mid(4).split(':'); + if (offsets.isEmpty() || offsets.size() > 3) + return invalidSeconds(); // No numbers, or too many. + + qint32 seconds = 0; + int prior = 0; // Number of fields parsed thus far + for (const auto &offset : offsets) { + bool ok = false; + unsigned short field = offset.toUShort(&ok); + // Bound hour above at 24, minutes and seconds at 60: + if (!ok || field >= (prior ? 60 : 24)) + return invalidSeconds(); + seconds = seconds * 60 + field; + ++prior; + } + while (prior++ < 3) + seconds *= 60; + + return seconds * sign; +} + // Create offset from UTC QUtcTimeZonePrivate::QUtcTimeZonePrivate(qint32 offsetSeconds) { @@ -874,22 +908,25 @@ QByteArray QUtcTimeZonePrivate::systemTimeZoneId() const bool QUtcTimeZonePrivate::isTimeZoneIdAvailable(const QByteArray &ianaId) const { + // Only the zone IDs supplied by CLDR and recognized by constructor. for (int i = 0; i < utcDataTableSize; ++i) { const QUtcData *data = utcData(i); - if (utcId(data) == ianaId) { + if (utcId(data) == ianaId) return true; - } } + // But see offsetFromUtcString(), which lets us accept some "unavailable" IDs. return false; } QList QUtcTimeZonePrivate::availableTimeZoneIds() const { + // Only the zone IDs supplied by CLDR and recognized by constructor. QList result; result.reserve(utcDataTableSize); for (int i = 0; i < utcDataTableSize; ++i) result << utcId(utcData(i)); - std::sort(result.begin(), result.end()); // ### or already sorted?? + // Not guaranteed to be sorted, so sort: + std::sort(result.begin(), result.end()); // ### assuming no duplicates return result; } @@ -904,13 +941,16 @@ QList QUtcTimeZonePrivate::availableTimeZoneIds(QLocale::Country cou QList QUtcTimeZonePrivate::availableTimeZoneIds(qint32 offsetSeconds) const { + // Only if it's present in CLDR. (May get more than one ID: UTC, UTC+00:00 + // and UTC-00:00 all have the same offset.) QList result; for (int i = 0; i < utcDataTableSize; ++i) { const QUtcData *data = utcData(i); if (data->offsetFromUtc == offsetSeconds) result << utcId(data); } - std::sort(result.begin(), result.end()); // ### or already sorted?? + // Not guaranteed to be sorted, so sort: + std::sort(result.begin(), result.end()); // ### assuming no duplicates return result; } diff --git a/src/corelib/time/qtimezoneprivate_p.h b/src/corelib/time/qtimezoneprivate_p.h index 5f6491ef81..a57f61f381 100644 --- a/src/corelib/time/qtimezoneprivate_p.h +++ b/src/corelib/time/qtimezoneprivate_p.h @@ -188,6 +188,9 @@ public: QUtcTimeZonePrivate(const QUtcTimeZonePrivate &other); virtual ~QUtcTimeZonePrivate(); + // Fall-back for UTC[+-]\d+(:\d+){,2} IDs. + static qint64 offsetFromUtcString(const QByteArray &id); + QUtcTimeZonePrivate *clone() const override; Data data(qint64 forMSecsSinceEpoch) const override; -- cgit v1.2.3