summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/corelib/global/qglobal.cpp4
-rw-r--r--src/corelib/io/qfilesystemwatcher_win.cpp1
-rw-r--r--src/corelib/kernel/qeventdispatcher_unix_p.h2
-rw-r--r--src/corelib/text/qregularexpression.cpp4
-rw-r--r--src/corelib/text/qstring.cpp44
-rw-r--r--src/dbus/qdbusreply.h1
-rw-r--r--src/gui/kernel/qguiapplication.cpp141
-rw-r--r--src/gui/kernel/qguiapplication_p.h11
-rw-r--r--src/gui/rhi/qrhigles2.cpp129
-rw-r--r--src/gui/rhi/qrhigles2_p_p.h11
-rw-r--r--src/gui/rhi/qrhivulkan.cpp157
-rw-r--r--src/gui/rhi/qrhivulkan_p_p.h17
-rw-r--r--src/gui/rhi/qshader.cpp13
-rw-r--r--src/gui/rhi/qshader_p_p.h3
-rw-r--r--src/gui/rhi/qshaderdescription.cpp235
-rw-r--r--src/gui/rhi/qshaderdescription_p.h3
-rw-r--r--src/gui/rhi/qshaderdescription_p_p.h2
-rw-r--r--src/network/access/qnetworkreply.cpp23
-rw-r--r--src/network/access/qnetworkreply.h7
-rw-r--r--src/platformsupport/fontdatabases/windows/qwindowsfontenginedirectwrite.cpp3
-rw-r--r--src/plugins/platforms/wasm/qwasmeventdispatcher.cpp23
-rw-r--r--src/plugins/platforms/wasm/qwasmeventdispatcher.h2
-rw-r--r--src/plugins/platforms/windows/qwindowscombase.h3
-rw-r--r--src/plugins/styles/mac/qmacstyle_mac.mm2
-rw-r--r--src/plugins/styles/windowsvista/qwindowsxpstyle.cpp3
-rw-r--r--src/widgets/kernel/qapplication.cpp231
-rw-r--r--src/widgets/kernel/qapplication_p.h10
27 files changed, 837 insertions, 248 deletions
diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp
index f9f005a83f..ea91dee471 100644
--- a/src/corelib/global/qglobal.cpp
+++ b/src/corelib/global/qglobal.cpp
@@ -139,10 +139,12 @@ Q_CORE_EXPORT void *qMemSet(void *dest, int c, size_t n);
// in. The idea here is to error or warn if otherwise implicit Qt
// assumptions are not fulfilled on new hardware or compilers
// (if this list becomes too long, consider factoring into a separate file)
-Q_STATIC_ASSERT_X(sizeof(int) == 4, "Qt assumes that int is 32 bits");
Q_STATIC_ASSERT_X(UCHAR_MAX == 255, "Qt assumes that char is 8 bits");
+Q_STATIC_ASSERT_X(sizeof(int) == 4, "Qt assumes that int is 32 bits");
Q_STATIC_ASSERT_X(QT_POINTER_SIZE == sizeof(void *), "QT_POINTER_SIZE defined incorrectly");
Q_STATIC_ASSERT_X(sizeof(float) == 4, "Qt assumes that float is 32 bits");
+Q_STATIC_ASSERT_X(sizeof(char16_t) == 2, "Qt assumes that char16_t is 16 bits");
+Q_STATIC_ASSERT_X(sizeof(char32_t) == 4, "Qt assumes that char32_t is 32 bits");
// While we'd like to check for __STDC_IEC_559__, as per ISO/IEC 9899:2011
// Annex F (C11, normative for C++11), there are a few corner cases regarding
diff --git a/src/corelib/io/qfilesystemwatcher_win.cpp b/src/corelib/io/qfilesystemwatcher_win.cpp
index 1d42dbfc70..f955e3b53a 100644
--- a/src/corelib/io/qfilesystemwatcher_win.cpp
+++ b/src/corelib/io/qfilesystemwatcher_win.cpp
@@ -403,6 +403,7 @@ QStringList QWindowsFileSystemWatcherEngine::addPaths(const QStringList &paths,
const QString absolutePath = isDir ? fileInfo.absoluteFilePath() : fileInfo.absolutePath();
const uint flags = isDir
? (FILE_NOTIFY_CHANGE_DIR_NAME
+ | FILE_NOTIFY_CHANGE_ATTRIBUTES
| FILE_NOTIFY_CHANGE_FILE_NAME)
: (FILE_NOTIFY_CHANGE_DIR_NAME
| FILE_NOTIFY_CHANGE_FILE_NAME
diff --git a/src/corelib/kernel/qeventdispatcher_unix_p.h b/src/corelib/kernel/qeventdispatcher_unix_p.h
index f37edfc967..581df9242c 100644
--- a/src/corelib/kernel/qeventdispatcher_unix_p.h
+++ b/src/corelib/kernel/qeventdispatcher_unix_p.h
@@ -118,7 +118,7 @@ public:
int remainingTime(int timerId) final;
- void wakeUp() final;
+ void wakeUp() override;
void interrupt() final;
void flush() override;
diff --git a/src/corelib/text/qregularexpression.cpp b/src/corelib/text/qregularexpression.cpp
index fb8f5a5efc..a3a4921690 100644
--- a/src/corelib/text/qregularexpression.cpp
+++ b/src/corelib/text/qregularexpression.cpp
@@ -463,10 +463,10 @@ QT_BEGIN_NAMESPACE
\c{\xHHHH} with more than 2 digits. A pattern like \c{\x2022} neeeds to
be ported to \c{\x{2022}}, or it will match a space (\c{0x20}) followed
by the string \c{"22"}. In general, it is highly recommended to always use
- curly braces with the \c{\\x} escape, no matter the amount of digits
+ curly braces with the \c{\x} escape, no matter the amount of digits
specified.
- \li A 0-to-n quantification like \c{{,n}} needs to be ported to c{{0,n}} to
+ \li A 0-to-n quantification like \c{{,n}} needs to be ported to \c{{0,n}} to
preserve semantics. Otherwise, a pattern such as \c{\d{,3}} would
actually match a digit followed by the exact string \c{"{,3}"}.
diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp
index ff1152b4e9..877f5df462 100644
--- a/src/corelib/text/qstring.cpp
+++ b/src/corelib/text/qstring.cpp
@@ -5036,21 +5036,25 @@ bool QString::endsWith(QChar c, Qt::CaseSensitivity cs) const
}
/*!
- Returns \c true if the string only contains uppercase letters,
- otherwise returns \c false.
+ Returns \c true if the string is uppercase, that is, it's identical
+ to its toUpper() folding.
+
+ Note that this does \e not mean that the string does not contain
+ lowercase letters (some lowercase letters do not have a uppercase
+ folding; they are left unchanged by toUpper()).
+ For more information, refer to the Unicode standard, section 3.13.
+
\since 5.12
- \sa QChar::isUpper(), isLower()
+ \sa QChar::toUpper(), isLower()
*/
bool QString::isUpper() const
{
- if (isEmpty())
- return false;
+ QStringIterator it(*this);
- const QChar *d = data();
-
- for (int i = 0, max = size(); i < max; ++i) {
- if (!d[i].isUpper())
+ while (it.hasNext()) {
+ uint uc = it.nextUnchecked();
+ if (qGetProp(uc)->cases[QUnicodeTables::UpperCase].diff)
return false;
}
@@ -5058,21 +5062,25 @@ bool QString::isUpper() const
}
/*!
- Returns \c true if the string only contains lowercase letters,
- otherwise returns \c false.
+ Returns \c true if the string is lowercase, that is, it's identical
+ to its toLower() folding.
+
+ Note that this does \e not mean that the string does not contain
+ uppercase letters (some uppercase letters do not have a lowercase
+ folding; they are left unchanged by toLower()).
+ For more information, refer to the Unicode standard, section 3.13.
+
\since 5.12
- \sa QChar::isLower(), isUpper()
+ \sa QChar::toLower(), isUpper()
*/
bool QString::isLower() const
{
- if (isEmpty())
- return false;
+ QStringIterator it(*this);
- const QChar *d = data();
-
- for (int i = 0, max = size(); i < max; ++i) {
- if (!d[i].isLower())
+ while (it.hasNext()) {
+ uint uc = it.nextUnchecked();
+ if (qGetProp(uc)->cases[QUnicodeTables::LowerCase].diff)
return false;
}
diff --git a/src/dbus/qdbusreply.h b/src/dbus/qdbusreply.h
index 869687ac85..8cdc0ae246 100644
--- a/src/dbus/qdbusreply.h
+++ b/src/dbus/qdbusreply.h
@@ -64,6 +64,7 @@ public:
{
*this = reply;
}
+ inline QDBusReply(const QDBusReply &) = default;
inline QDBusReply& operator=(const QDBusMessage &reply)
{
QVariant data(qMetaTypeId<Type>(), nullptr);
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp
index 6503acaef0..d72cc2df79 100644
--- a/src/gui/kernel/qguiapplication.cpp
+++ b/src/gui/kernel/qguiapplication.cpp
@@ -236,21 +236,6 @@ static bool qt_detectRTLLanguage()
" and Arabic) to get proper widget layout.") == QLatin1String("RTL"));
}
-static void initPalette()
-{
- if (!QGuiApplicationPrivate::app_pal)
- if (const QPalette *themePalette = QGuiApplicationPrivate::platformTheme()->palette())
- QGuiApplicationPrivate::app_pal = new QPalette(*themePalette);
- if (!QGuiApplicationPrivate::app_pal)
- QGuiApplicationPrivate::app_pal = new QPalette(Qt::gray);
-}
-
-static inline void clearPalette()
-{
- delete QGuiApplicationPrivate::app_pal;
- QGuiApplicationPrivate::app_pal = nullptr;
-}
-
static void initFontUnlocked()
{
if (!QGuiApplicationPrivate::app_font) {
@@ -605,8 +590,13 @@ static QWindowGeometrySpecification windowGeometrySpecification = Q_WINDOW_GEOME
The following parameters are available for \c {-platform windows}:
\list
+ \li \c {altgr}, detect the key \c {AltGr} found on some keyboards as
+ Qt::GroupSwitchModifier (since Qt 5.12).
\li \c {dialogs=[xp|none]}, \c xp uses XP-style native dialogs and
\c none disables them.
+
+ \li \c {dpiawareness=[0|1|2} Sets the DPI awareness of the process
+ (see \l{High DPI Displays}, since Qt 5.4).
\li \c {fontengine=freetype}, uses the FreeType font engine.
\li \c {menus=[native|none]}, controls the use of native menus.
@@ -616,10 +606,23 @@ static QWindowGeometrySpecification windowGeometrySpecification = Q_WINDOW_GEOME
provide hover signals. They are mainly intended for Qt Quick.
By default, they will be used if the application is not an
instance of QApplication or for Qt Quick Controls 2
- applications.
+ applications (since Qt 5.10).
- \li \c {altgr}, detect the key \c {AltGr} found on some keyboards as
- Qt::GroupSwitchModifier.
+ \li \c {nocolorfonts} Turn off DirectWrite Color fonts
+ (since Qt 5.8).
+
+ \li \c {nodirectwrite} Turn off DirectWrite fonts (since Qt 5.8).
+
+ \li \c {nomousefromtouch} Ignores mouse events synthesized
+ from touch events by the operating system.
+
+ \li \c {nowmpointer} Switches from Pointer Input Messages handling
+ to legacy mouse handling (since Qt 5.12).
+ \li \c {reverse} Activates Right-to-left mode (experimental).
+ Windows title bars will be shown accordingly in Right-to-left locales
+ (since Qt 5.13).
+ \li \c {tabletabsoluterange=<value>} Sets a value for mouse mode detection
+ of WinTab tablets (Legacy, since Qt 5.3).
\endlist
The following parameter is available for \c {-platform cocoa} (on macOS):
@@ -673,7 +676,7 @@ QGuiApplication::~QGuiApplication()
d->session_manager = nullptr;
#endif //QT_NO_SESSIONMANAGER
- clearPalette();
+ QGuiApplicationPrivate::clearPalette();
QFontDatabase::removeAllApplicationFonts();
#ifndef QT_NO_CURSOR
@@ -1597,7 +1600,7 @@ void QGuiApplicationPrivate::init()
if (platform_integration == nullptr)
createPlatformIntegration();
- initPalette();
+ updatePalette();
QFont::initialize();
initThemeHints();
@@ -3275,46 +3278,97 @@ QClipboard * QGuiApplication::clipboard()
*/
/*!
- Returns the default application palette.
+ Returns the current application palette.
+
+ Roles that have not been explicitly set will reflect the system's platform theme.
\sa setPalette()
*/
QPalette QGuiApplication::palette()
{
- initPalette();
+ if (!QGuiApplicationPrivate::app_pal)
+ QGuiApplicationPrivate::updatePalette();
+
return *QGuiApplicationPrivate::app_pal;
}
+void QGuiApplicationPrivate::updatePalette()
+{
+ if (app_pal) {
+ if (setPalette(*app_pal) && qGuiApp)
+ qGuiApp->d_func()->handlePaletteChanged();
+ } else {
+ setPalette(QPalette());
+ }
+}
+
+void QGuiApplicationPrivate::clearPalette()
+{
+ delete app_pal;
+ app_pal = nullptr;
+}
+
/*!
- Changes the default application palette to \a pal.
+ Changes the application palette to \a pal.
+
+ The color roles from this palette are combined with the system's platform
+ theme to form the application's final palette.
\sa palette()
*/
void QGuiApplication::setPalette(const QPalette &pal)
{
- if (!QGuiApplicationPrivate::setPalette(pal))
- return;
-
- QCoreApplication::setAttribute(Qt::AA_SetPalette);
-
- if (qGuiApp)
- qGuiApp->d_func()->sendApplicationPaletteChange();
+ if (QGuiApplicationPrivate::setPalette(pal) && qGuiApp)
+ qGuiApp->d_func()->handlePaletteChanged();
}
bool QGuiApplicationPrivate::setPalette(const QPalette &palette)
{
- if (app_pal && palette.isCopyOf(*app_pal))
+ // Resolve the palette against the theme palette, filling in
+ // any missing roles, while keeping the original resolve mask.
+ QPalette basePalette = qGuiApp ? qGuiApp->d_func()->basePalette() : Qt::gray;
+ basePalette.resolve(0); // The base palette only contributes missing colors roles
+ QPalette resolvedPalette = palette.resolve(basePalette);
+
+ if (app_pal && resolvedPalette == *app_pal && resolvedPalette.resolve() == app_pal->resolve())
return false;
if (!app_pal)
- app_pal = new QPalette(palette);
+ app_pal = new QPalette(resolvedPalette);
else
- *app_pal = palette;
+ *app_pal = resolvedPalette;
+
+ QCoreApplication::setAttribute(Qt::AA_SetPalette, app_pal->resolve() != 0);
return true;
}
+/*
+ Returns the base palette used to fill in missing roles in
+ the current application palette.
+
+ Normally this is the theme palette, but QApplication
+ overrides this for compatibility reasons.
+*/
+QPalette QGuiApplicationPrivate::basePalette() const
+{
+ return platformTheme() ? *platformTheme()->palette() : Qt::gray;
+}
+
+void QGuiApplicationPrivate::handlePaletteChanged(const char *className)
+{
+ if (!className) {
+ Q_ASSERT(app_pal);
+ emit qGuiApp->paletteChanged(*QGuiApplicationPrivate::app_pal);
+ }
+
+ if (is_app_running && !is_app_closing) {
+ QEvent event(QEvent::ApplicationPaletteChange);
+ QGuiApplication::sendEvent(qGuiApp, &event);
+ }
+}
+
void QGuiApplicationPrivate::applyWindowGeometrySpecificationTo(QWindow *window)
{
windowGeometrySpecification.applyTo(window);
@@ -4113,11 +4167,8 @@ QPixmap QGuiApplicationPrivate::getPixmapCursor(Qt::CursorShape cshape)
void QGuiApplicationPrivate::notifyThemeChanged()
{
- if (!testAttribute(Qt::AA_SetPalette)) {
- clearPalette();
- initPalette();
- sendApplicationPaletteChange();
- }
+ updatePalette();
+
if (!(applicationResourceFlags & ApplicationFontExplicitlySet)) {
const auto locker = qt_scoped_lock(applicationFontMutex);
clearFontUnlocked();
@@ -4126,20 +4177,6 @@ void QGuiApplicationPrivate::notifyThemeChanged()
initThemeHints();
}
-void QGuiApplicationPrivate::sendApplicationPaletteChange(bool toAllWidgets, const char *className)
-{
- Q_UNUSED(toAllWidgets)
-
- if (!className)
- emit qGuiApp->paletteChanged(*QGuiApplicationPrivate::app_pal);
-
- if (!is_app_running || is_app_closing)
- return;
-
- QEvent event(QEvent::ApplicationPaletteChange);
- QGuiApplication::sendEvent(QGuiApplication::instance(), &event);
-}
-
#if QT_CONFIG(draganddrop)
void QGuiApplicationPrivate::notifyDragStarted(const QDrag *drag)
{
diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h
index a8017216d4..dc2963aee7 100644
--- a/src/gui/kernel/qguiapplication_p.h
+++ b/src/gui/kernel/qguiapplication_p.h
@@ -326,17 +326,22 @@ public:
static void resetCachedDevicePixelRatio();
- static bool setPalette(const QPalette &palette);
-
protected:
virtual void notifyThemeChanged();
- virtual void sendApplicationPaletteChange(bool toAllWidgets = false, const char *className = nullptr);
+
+ static bool setPalette(const QPalette &palette);
+ virtual QPalette basePalette() const;
+ virtual void handlePaletteChanged(const char *className = nullptr);
+
bool tryCloseRemainingWindows(QWindowList processedWindows);
#if QT_CONFIG(draganddrop)
virtual void notifyDragStarted(const QDrag *);
#endif // QT_CONFIG(draganddrop)
private:
+ static void clearPalette();
+ static void updatePalette();
+
friend class QDragManager;
static QGuiApplicationPrivate *self;
diff --git a/src/gui/rhi/qrhigles2.cpp b/src/gui/rhi/qrhigles2.cpp
index afa3a397e6..ec5e531e14 100644
--- a/src/gui/rhi/qrhigles2.cpp
+++ b/src/gui/rhi/qrhigles2.cpp
@@ -269,6 +269,14 @@ QT_BEGIN_NAMESPACE
#define GL_ALL_BARRIER_BITS 0xFFFFFFFF
#endif
+#ifndef GL_SHADER_IMAGE_ACCESS_BARRIER_BIT
+#define GL_SHADER_IMAGE_ACCESS_BARRIER_BIT 0x00000020
+#endif
+
+#ifndef GL_SHADER_STORAGE_BARRIER_BIT
+#define GL_SHADER_STORAGE_BARRIER_BIT 0x00002000
+#endif
+
#ifndef GL_VERTEX_PROGRAM_POINT_SIZE
#define GL_VERTEX_PROGRAM_POINT_SIZE 0x8642
#endif
@@ -1307,6 +1315,21 @@ QRhi::FrameOpResult QRhiGles2::finish()
return QRhi::FrameOpSuccess;
}
+static bool bufferAccessIsWrite(QGles2Buffer::Access access)
+{
+ return access == QGles2Buffer::AccessStorageWrite
+ || access == QGles2Buffer::AccessStorageReadWrite
+ || access == QGles2Buffer::AccessUpdate;
+}
+
+static bool textureAccessIsWrite(QGles2Texture::Access access)
+{
+ return access == QGles2Texture::AccessStorageWrite
+ || access == QGles2Texture::AccessStorageReadWrite
+ || access == QGles2Texture::AccessUpdate
+ || access == QGles2Texture::AccessFramebuffer;
+}
+
void QRhiGles2::trackedBufferBarrier(QGles2CommandBuffer *cbD, QGles2Buffer *bufD, QGles2Buffer::Access access)
{
Q_ASSERT(cbD->recordingPass == QGles2CommandBuffer::NoPass); // this is for resource updates only
@@ -1314,7 +1337,7 @@ void QRhiGles2::trackedBufferBarrier(QGles2CommandBuffer *cbD, QGles2Buffer *buf
if (access == prevAccess)
return;
- if (prevAccess == QGles2Buffer::AccessStorageWrite || prevAccess == QGles2Buffer::AccessStorageReadWrite) {
+ if (bufferAccessIsWrite(prevAccess)) {
// Generating the minimal barrier set is way too complicated to do
// correctly (prevAccess is overwritten so we won't have proper
// tracking across multiple passes) so setting all barrier bits will do
@@ -1335,7 +1358,7 @@ void QRhiGles2::trackedImageBarrier(QGles2CommandBuffer *cbD, QGles2Texture *tex
if (access == prevAccess)
return;
- if (prevAccess == QGles2Texture::AccessStorageWrite || prevAccess == QGles2Texture::AccessStorageReadWrite) {
+ if (textureAccessIsWrite(prevAccess)) {
QGles2CommandBuffer::Command cmd;
cmd.cmd = QGles2CommandBuffer::Command::Barrier;
cmd.args.barrier.barriers = GL_ALL_BARRIER_BITS;
@@ -2273,26 +2296,21 @@ void QRhiGles2::executeCommandBuffer(QRhiCommandBuffer *cb)
// subsequent pass.
for (auto it = tracker.cbeginBuffers(), itEnd = tracker.cendBuffers(); it != itEnd; ++it) {
QGles2Buffer::Access accessBeforePass = QGles2Buffer::Access(it->stateAtPassBegin.access);
- if (accessBeforePass == QGles2Buffer::AccessStorageWrite
- || accessBeforePass == QGles2Buffer::AccessStorageReadWrite)
- {
+ if (bufferAccessIsWrite(accessBeforePass))
barriers |= GL_ALL_BARRIER_BITS;
- }
}
for (auto it = tracker.cbeginTextures(), itEnd = tracker.cendTextures(); it != itEnd; ++it) {
QGles2Texture::Access accessBeforePass = QGles2Texture::Access(it->stateAtPassBegin.access);
- if (accessBeforePass == QGles2Texture::AccessStorageWrite
- || accessBeforePass == QGles2Texture::AccessStorageReadWrite)
- {
+ if (textureAccessIsWrite(accessBeforePass))
barriers |= GL_ALL_BARRIER_BITS;
- }
}
- if (barriers)
+ if (barriers && caps.compute)
f->glMemoryBarrier(barriers);
}
break;
case QGles2CommandBuffer::Command::Barrier:
- f->glMemoryBarrier(cmd.args.barrier.barriers);
+ if (caps.compute)
+ f->glMemoryBarrier(cmd.args.barrier.barriers);
break;
default:
break;
@@ -2791,6 +2809,8 @@ void QRhiGles2::beginComputePass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch
cbD->recordingPass = QGles2CommandBuffer::ComputePass;
cbD->resetCachedState();
+
+ cbD->computePassState.reset();
}
void QRhiGles2::endComputePass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates)
@@ -2823,11 +2843,96 @@ void QRhiGles2::setComputePipeline(QRhiCommandBuffer *cb, QRhiComputePipeline *p
}
}
+template<typename T>
+inline void qrhigl_accumulateComputeResource(T *writtenResources, QRhiResource *resource,
+ QRhiShaderResourceBinding::Type bindingType,
+ int loadTypeVal, int storeTypeVal, int loadStoreTypeVal)
+{
+ int access = 0;
+ if (bindingType == loadTypeVal) {
+ access = QGles2CommandBuffer::ComputePassState::Read;
+ } else {
+ access = QGles2CommandBuffer::ComputePassState::Write;
+ if (bindingType == loadStoreTypeVal)
+ access |= QGles2CommandBuffer::ComputePassState::Read;
+ }
+ auto it = writtenResources->find(resource);
+ if (it != writtenResources->end())
+ it->first |= access;
+ else if (bindingType == storeTypeVal || bindingType == loadStoreTypeVal)
+ writtenResources->insert(resource, { access, true });
+}
+
void QRhiGles2::dispatch(QRhiCommandBuffer *cb, int x, int y, int z)
{
QGles2CommandBuffer *cbD = QRHI_RES(QGles2CommandBuffer, cb);
Q_ASSERT(cbD->recordingPass == QGles2CommandBuffer::ComputePass);
+ if (cbD->currentComputeSrb) {
+ GLbitfield barriers = 0;
+
+ // The key in the writtenResources map indicates that the resource was
+ // written in a previous dispatch, whereas the value accumulates the
+ // access mask in the current one.
+ for (auto &accessAndIsNewFlag : cbD->computePassState.writtenResources)
+ accessAndIsNewFlag = { 0, false };
+
+ QGles2ShaderResourceBindings *srbD = QRHI_RES(QGles2ShaderResourceBindings, cbD->currentComputeSrb);
+ const int bindingCount = srbD->m_bindings.count();
+ for (int i = 0; i < bindingCount; ++i) {
+ const QRhiShaderResourceBinding::Data *b = srbD->m_bindings.at(i).data();
+ switch (b->type) {
+ case QRhiShaderResourceBinding::ImageLoad:
+ case QRhiShaderResourceBinding::ImageStore:
+ case QRhiShaderResourceBinding::ImageLoadStore:
+ qrhigl_accumulateComputeResource(&cbD->computePassState.writtenResources,
+ b->u.simage.tex,
+ b->type,
+ QRhiShaderResourceBinding::ImageLoad,
+ QRhiShaderResourceBinding::ImageStore,
+ QRhiShaderResourceBinding::ImageLoadStore);
+ break;
+ case QRhiShaderResourceBinding::BufferLoad:
+ case QRhiShaderResourceBinding::BufferStore:
+ case QRhiShaderResourceBinding::BufferLoadStore:
+ qrhigl_accumulateComputeResource(&cbD->computePassState.writtenResources,
+ b->u.sbuf.buf,
+ b->type,
+ QRhiShaderResourceBinding::BufferLoad,
+ QRhiShaderResourceBinding::BufferStore,
+ QRhiShaderResourceBinding::BufferLoadStore);
+ break;
+ default:
+ break;
+ }
+ }
+
+ for (auto it = cbD->computePassState.writtenResources.begin(); it != cbD->computePassState.writtenResources.end(); ) {
+ const int accessInThisDispatch = it->first;
+ const bool isNewInThisDispatch = it->second;
+ if (accessInThisDispatch && !isNewInThisDispatch) {
+ if (it.key()->resourceType() == QRhiResource::Texture)
+ barriers |= GL_SHADER_IMAGE_ACCESS_BARRIER_BIT;
+ else
+ barriers |= GL_SHADER_STORAGE_BARRIER_BIT;
+ }
+ // Anything that was previously written, but is only read now, can be
+ // removed from the written list (because that previous write got a
+ // corresponding barrier now).
+ if (accessInThisDispatch == QGles2CommandBuffer::ComputePassState::Read)
+ it = cbD->computePassState.writtenResources.erase(it);
+ else
+ ++it;
+ }
+
+ if (barriers) {
+ QGles2CommandBuffer::Command cmd;
+ cmd.cmd = QGles2CommandBuffer::Command::Barrier;
+ cmd.args.barrier.barriers = barriers;
+ cbD->commands.append(cmd);
+ }
+ }
+
QGles2CommandBuffer::Command cmd;
cmd.cmd = QGles2CommandBuffer::Command::Dispatch;
cmd.args.dispatch.x = GLuint(x);
diff --git a/src/gui/rhi/qrhigles2_p_p.h b/src/gui/rhi/qrhigles2_p_p.h
index a9b3022612..679f806004 100644
--- a/src/gui/rhi/qrhigles2_p_p.h
+++ b/src/gui/rhi/qrhigles2_p_p.h
@@ -521,6 +521,17 @@ struct QGles2CommandBuffer : public QRhiCommandBuffer
QRhiShaderResourceBindings *currentComputeSrb;
uint currentSrbGeneration;
+ struct ComputePassState {
+ enum Access {
+ Read = 0x01,
+ Write = 0x02
+ };
+ QHash<QRhiResource *, QPair<int, bool> > writtenResources;
+ void reset() {
+ writtenResources.clear();
+ }
+ } computePassState;
+
QVector<QByteArray> dataRetainPool;
QVector<QImage> imageRetainPool;
diff --git a/src/gui/rhi/qrhivulkan.cpp b/src/gui/rhi/qrhivulkan.cpp
index c4f56f2dd2..f4c72d2cca 100644
--- a/src/gui/rhi/qrhivulkan.cpp
+++ b/src/gui/rhi/qrhivulkan.cpp
@@ -2219,6 +2219,8 @@ void QRhiVulkan::beginComputePass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch
cbD->recordingPass = QVkCommandBuffer::ComputePass;
+ cbD->computePassState.reset();
+
if (cbD->useSecondaryCb)
cbD->secondaryCbs.append(startSecondaryCommandBuffer());
}
@@ -2267,15 +2269,152 @@ void QRhiVulkan::setComputePipeline(QRhiCommandBuffer *cb, QRhiComputePipeline *
psD->lastActiveFrameSlot = currentFrameSlot;
}
+template<typename T>
+inline void qrhivk_accumulateComputeResource(T *writtenResources, QRhiResource *resource,
+ QRhiShaderResourceBinding::Type bindingType,
+ int loadTypeVal, int storeTypeVal, int loadStoreTypeVal)
+{
+ VkAccessFlags access = 0;
+ if (bindingType == loadTypeVal) {
+ access = VK_ACCESS_SHADER_READ_BIT;
+ } else {
+ access = VK_ACCESS_SHADER_WRITE_BIT;
+ if (bindingType == loadStoreTypeVal)
+ access |= VK_ACCESS_SHADER_READ_BIT;
+ }
+ auto it = writtenResources->find(resource);
+ if (it != writtenResources->end())
+ it->first |= access;
+ else if (bindingType == storeTypeVal || bindingType == loadStoreTypeVal)
+ writtenResources->insert(resource, { access, true });
+}
+
void QRhiVulkan::dispatch(QRhiCommandBuffer *cb, int x, int y, int z)
{
QVkCommandBuffer *cbD = QRHI_RES(QVkCommandBuffer, cb);
Q_ASSERT(cbD->recordingPass == QVkCommandBuffer::ComputePass);
+ // When there are multiple dispatches, read-after-write and
+ // write-after-write need a barrier.
+ QVarLengthArray<VkImageMemoryBarrier, 8> imageBarriers;
+ QVarLengthArray<VkBufferMemoryBarrier, 8> bufferBarriers;
+ if (cbD->currentComputeSrb) {
+ // The key in the writtenResources map indicates that the resource was
+ // written in a previous dispatch, whereas the value accumulates the
+ // access mask in the current one.
+ for (auto &accessAndIsNewFlag : cbD->computePassState.writtenResources)
+ accessAndIsNewFlag = { 0, false };
+
+ QVkShaderResourceBindings *srbD = QRHI_RES(QVkShaderResourceBindings, cbD->currentComputeSrb);
+ const int bindingCount = srbD->m_bindings.count();
+ for (int i = 0; i < bindingCount; ++i) {
+ const QRhiShaderResourceBinding::Data *b = srbD->m_bindings.at(i).data();
+ switch (b->type) {
+ case QRhiShaderResourceBinding::ImageLoad:
+ case QRhiShaderResourceBinding::ImageStore:
+ case QRhiShaderResourceBinding::ImageLoadStore:
+ qrhivk_accumulateComputeResource(&cbD->computePassState.writtenResources,
+ b->u.simage.tex,
+ b->type,
+ QRhiShaderResourceBinding::ImageLoad,
+ QRhiShaderResourceBinding::ImageStore,
+ QRhiShaderResourceBinding::ImageLoadStore);
+ break;
+ case QRhiShaderResourceBinding::BufferLoad:
+ case QRhiShaderResourceBinding::BufferStore:
+ case QRhiShaderResourceBinding::BufferLoadStore:
+ qrhivk_accumulateComputeResource(&cbD->computePassState.writtenResources,
+ b->u.sbuf.buf,
+ b->type,
+ QRhiShaderResourceBinding::BufferLoad,
+ QRhiShaderResourceBinding::BufferStore,
+ QRhiShaderResourceBinding::BufferLoadStore);
+ break;
+ default:
+ break;
+ }
+ }
+
+ for (auto it = cbD->computePassState.writtenResources.begin(); it != cbD->computePassState.writtenResources.end(); ) {
+ const int accessInThisDispatch = it->first;
+ const bool isNewInThisDispatch = it->second;
+ if (accessInThisDispatch && !isNewInThisDispatch) {
+ if (it.key()->resourceType() == QRhiResource::Texture) {
+ QVkTexture *texD = QRHI_RES(QVkTexture, it.key());
+ VkImageMemoryBarrier barrier;
+ memset(&barrier, 0, sizeof(barrier));
+ barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
+ barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
+ // won't care about subresources, pretend the whole resource was written
+ barrier.subresourceRange.baseMipLevel = 0;
+ barrier.subresourceRange.levelCount = VK_REMAINING_MIP_LEVELS;
+ barrier.subresourceRange.baseArrayLayer = 0;
+ barrier.subresourceRange.layerCount = VK_REMAINING_ARRAY_LAYERS;
+ barrier.oldLayout = texD->usageState.layout;
+ barrier.newLayout = texD->usageState.layout;
+ barrier.srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT;
+ barrier.dstAccessMask = accessInThisDispatch;
+ barrier.image = texD->image;
+ imageBarriers.append(barrier);
+ } else {
+ QVkBuffer *bufD = QRHI_RES(QVkBuffer, it.key());
+ VkBufferMemoryBarrier barrier;
+ memset(&barrier, 0, sizeof(barrier));
+ barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
+ barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
+ barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
+ barrier.srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT;
+ barrier.dstAccessMask = accessInThisDispatch;
+ barrier.buffer = bufD->buffers[bufD->m_type == QRhiBuffer::Dynamic ? currentFrameSlot : 0];
+ barrier.size = VK_WHOLE_SIZE;
+ bufferBarriers.append(barrier);
+ }
+ }
+ // Anything that was previously written, but is only read now, can be
+ // removed from the written list (because that previous write got a
+ // corresponding barrier now).
+ if (accessInThisDispatch == VK_ACCESS_SHADER_READ_BIT)
+ it = cbD->computePassState.writtenResources.erase(it);
+ else
+ ++it;
+ }
+ }
+
if (cbD->useSecondaryCb) {
- df->vkCmdDispatch(cbD->secondaryCbs.last(), uint32_t(x), uint32_t(y), uint32_t(z));
+ VkCommandBuffer secondaryCb = cbD->secondaryCbs.last();
+ if (!imageBarriers.isEmpty()) {
+ df->vkCmdPipelineBarrier(secondaryCb, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
+ 0, 0, nullptr,
+ 0, nullptr,
+ imageBarriers.count(), imageBarriers.constData());
+ }
+ if (!bufferBarriers.isEmpty()) {
+ df->vkCmdPipelineBarrier(secondaryCb, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
+ 0, 0, nullptr,
+ bufferBarriers.count(), bufferBarriers.constData(),
+ 0, nullptr);
+ }
+ df->vkCmdDispatch(secondaryCb, uint32_t(x), uint32_t(y), uint32_t(z));
} else {
QVkCommandBuffer::Command cmd;
+ if (!imageBarriers.isEmpty()) {
+ cmd.cmd = QVkCommandBuffer::Command::ImageBarrier;
+ cmd.args.imageBarrier.srcStageMask = VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT;
+ cmd.args.imageBarrier.dstStageMask = VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT;
+ cmd.args.imageBarrier.count = imageBarriers.count();
+ cmd.args.imageBarrier.index = cbD->pools.imageBarrier.count();
+ cbD->pools.imageBarrier.append(imageBarriers.constData(), imageBarriers.count());
+ cbD->commands.append(cmd);
+ }
+ if (!bufferBarriers.isEmpty()) {
+ cmd.cmd = QVkCommandBuffer::Command::BufferBarrier;
+ cmd.args.bufferBarrier.srcStageMask = VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT;
+ cmd.args.bufferBarrier.dstStageMask = VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT;
+ cmd.args.bufferBarrier.count = bufferBarriers.count();
+ cmd.args.bufferBarrier.index = cbD->pools.bufferBarrier.count();
+ cbD->pools.bufferBarrier.append(bufferBarriers.constData(), bufferBarriers.count());
+ cbD->commands.append(cmd);
+ }
cmd.cmd = QVkCommandBuffer::Command::Dispatch;
cmd.args.dispatch.x = x;
cmd.args.dispatch.y = y;
@@ -2465,7 +2604,9 @@ void QRhiVulkan::trackedBufferBarrier(QVkCommandBuffer *cbD, QVkBuffer *bufD, in
cmd.cmd = QVkCommandBuffer::Command::BufferBarrier;
cmd.args.bufferBarrier.srcStageMask = s.stage;
cmd.args.bufferBarrier.dstStageMask = stage;
- cmd.args.bufferBarrier.desc = bufMemBarrier;
+ cmd.args.bufferBarrier.count = 1;
+ cmd.args.bufferBarrier.index = cbD->pools.bufferBarrier.count();
+ cbD->pools.bufferBarrier.append(bufMemBarrier);
cbD->commands.append(cmd);
s.access = access;
@@ -2507,7 +2648,9 @@ void QRhiVulkan::trackedImageBarrier(QVkCommandBuffer *cbD, QVkTexture *texD,
cmd.cmd = QVkCommandBuffer::Command::ImageBarrier;
cmd.args.imageBarrier.srcStageMask = srcStage;
cmd.args.imageBarrier.dstStageMask = stage;
- cmd.args.imageBarrier.desc = barrier;
+ cmd.args.imageBarrier.count = 1;
+ cmd.args.imageBarrier.index = cbD->pools.imageBarrier.count();
+ cbD->pools.imageBarrier.append(barrier);
cbD->commands.append(cmd);
s.layout = layout;
@@ -2541,7 +2684,9 @@ void QRhiVulkan::subresourceBarrier(QVkCommandBuffer *cbD, VkImage image,
cmd.cmd = QVkCommandBuffer::Command::ImageBarrier;
cmd.args.imageBarrier.srcStageMask = srcStage;
cmd.args.imageBarrier.dstStageMask = dstStage;
- cmd.args.imageBarrier.desc = barrier;
+ cmd.args.imageBarrier.count = 1;
+ cmd.args.imageBarrier.index = cbD->pools.imageBarrier.count();
+ cbD->pools.imageBarrier.append(barrier);
cbD->commands.append(cmd);
}
@@ -3409,12 +3554,12 @@ void QRhiVulkan::recordPrimaryCommandBuffer(QVkCommandBuffer *cbD)
case QVkCommandBuffer::Command::ImageBarrier:
df->vkCmdPipelineBarrier(cbD->cb, cmd.args.imageBarrier.srcStageMask, cmd.args.imageBarrier.dstStageMask,
0, 0, nullptr, 0, nullptr,
- 1, &cmd.args.imageBarrier.desc);
+ cmd.args.imageBarrier.count, cbD->pools.imageBarrier.constData() + cmd.args.imageBarrier.index);
break;
case QVkCommandBuffer::Command::BufferBarrier:
df->vkCmdPipelineBarrier(cbD->cb, cmd.args.bufferBarrier.srcStageMask, cmd.args.bufferBarrier.dstStageMask,
0, 0, nullptr,
- 1, &cmd.args.bufferBarrier.desc,
+ cmd.args.bufferBarrier.count, cbD->pools.bufferBarrier.constData() + cmd.args.bufferBarrier.index,
0, nullptr);
break;
case QVkCommandBuffer::Command::BlitImage:
diff --git a/src/gui/rhi/qrhivulkan_p_p.h b/src/gui/rhi/qrhivulkan_p_p.h
index 9f18d0bf5e..b0e90dae56 100644
--- a/src/gui/rhi/qrhivulkan_p_p.h
+++ b/src/gui/rhi/qrhivulkan_p_p.h
@@ -370,6 +370,13 @@ struct QVkCommandBuffer : public QRhiCommandBuffer
QVarLengthArray<VkCommandBuffer, 4> secondaryCbs;
bool inExternal;
+ struct {
+ QHash<QRhiResource *, QPair<VkAccessFlags, bool> > writtenResources;
+ void reset() {
+ writtenResources.clear();
+ }
+ } computePassState;
+
struct Command {
enum Cmd {
CopyBuffer,
@@ -429,12 +436,14 @@ struct QVkCommandBuffer : public QRhiCommandBuffer
struct {
VkPipelineStageFlags srcStageMask;
VkPipelineStageFlags dstStageMask;
- VkImageMemoryBarrier desc;
+ int count;
+ int index;
} imageBarrier;
struct {
VkPipelineStageFlags srcStageMask;
VkPipelineStageFlags dstStageMask;
- VkBufferMemoryBarrier desc;
+ int count;
+ int index;
} bufferBarrier;
struct {
VkImage src;
@@ -537,6 +546,8 @@ struct QVkCommandBuffer : public QRhiCommandBuffer
pools.vertexBuffer.clear();
pools.vertexBufferOffset.clear();
pools.debugMarkerData.clear();
+ pools.imageBarrier.clear();
+ pools.bufferBarrier.clear();
}
struct {
@@ -546,6 +557,8 @@ struct QVkCommandBuffer : public QRhiCommandBuffer
QVarLengthArray<VkBuffer, 4> vertexBuffer;
QVarLengthArray<VkDeviceSize, 4> vertexBufferOffset;
QVarLengthArray<QByteArray, 4> debugMarkerData;
+ QVarLengthArray<VkImageMemoryBarrier, 8> imageBarrier;
+ QVarLengthArray<VkBufferMemoryBarrier, 8> bufferBarrier;
} pools;
friend class QRhiVulkan;
diff --git a/src/gui/rhi/qshader.cpp b/src/gui/rhi/qshader.cpp
index 9203d63cd2..69f4a68215 100644
--- a/src/gui/rhi/qshader.cpp
+++ b/src/gui/rhi/qshader.cpp
@@ -367,7 +367,7 @@ QByteArray QShader::serialized() const
ds << QShaderPrivate::QSB_VERSION;
ds << int(d->stage);
- ds << d->desc.toCbor();
+ d->desc.serialize(&ds);
ds << d->shaders.count();
for (auto it = d->shaders.cbegin(), itEnd = d->shaders.cend(); it != itEnd; ++it) {
const QShaderKey &k(it.key());
@@ -428,6 +428,7 @@ QShader QShader::fromSerialized(const QByteArray &data)
ds >> intVal;
d->qsbVersion = intVal;
if (d->qsbVersion != QShaderPrivate::QSB_VERSION
+ && d->qsbVersion != QShaderPrivate::QSB_VERSION_WITH_CBOR
&& d->qsbVersion != QShaderPrivate::QSB_VERSION_WITH_BINARY_JSON
&& d->qsbVersion != QShaderPrivate::QSB_VERSION_WITHOUT_BINDINGS)
{
@@ -437,14 +438,18 @@ QShader QShader::fromSerialized(const QByteArray &data)
ds >> intVal;
d->stage = Stage(intVal);
- QByteArray descBin;
- ds >> descBin;
- if (d->qsbVersion > QShaderPrivate::QSB_VERSION_WITH_BINARY_JSON) {
+ if (d->qsbVersion > QShaderPrivate::QSB_VERSION_WITH_CBOR) {
+ d->desc = QShaderDescription::deserialize(&ds);
+ } else if (d->qsbVersion > QShaderPrivate::QSB_VERSION_WITH_BINARY_JSON) {
+ QByteArray descBin;
+ ds >> descBin;
d->desc = QShaderDescription::fromCbor(descBin);
} else {
#if QT_CONFIG(binaryjson) && QT_DEPRECATED_SINCE(5, 15)
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
+ QByteArray descBin;
+ ds >> descBin;
d->desc = QShaderDescription::fromBinaryJson(descBin);
QT_WARNING_POP
#else
diff --git a/src/gui/rhi/qshader_p_p.h b/src/gui/rhi/qshader_p_p.h
index 8c89f2b45f..66ef18f391 100644
--- a/src/gui/rhi/qshader_p_p.h
+++ b/src/gui/rhi/qshader_p_p.h
@@ -57,7 +57,8 @@ QT_BEGIN_NAMESPACE
struct Q_GUI_EXPORT QShaderPrivate
{
- static const int QSB_VERSION = 3;
+ static const int QSB_VERSION = 4;
+ static const int QSB_VERSION_WITH_CBOR = 3;
static const int QSB_VERSION_WITH_BINARY_JSON = 2;
static const int QSB_VERSION_WITHOUT_BINDINGS = 1;
diff --git a/src/gui/rhi/qshaderdescription.cpp b/src/gui/rhi/qshaderdescription.cpp
index 76c5d0ebef..96c8d082fc 100644
--- a/src/gui/rhi/qshaderdescription.cpp
+++ b/src/gui/rhi/qshaderdescription.cpp
@@ -36,6 +36,7 @@
#include "qshaderdescription_p_p.h"
#include <QDebug>
+#include <QDataStream>
#include <QJsonObject>
#include <QJsonArray>
#include <QCborValue>
@@ -358,6 +359,11 @@ QByteArray QShaderDescription::toJson() const
return d->makeDoc().toJson();
}
+void QShaderDescription::serialize(QDataStream *stream) const
+{
+ d->writeToStream(stream);
+}
+
#if QT_CONFIG(binaryjson) && QT_DEPRECATED_SINCE(5, 15)
/*!
\deprecated
@@ -396,6 +402,13 @@ QShaderDescription QShaderDescription::fromCbor(const QByteArray &data)
return desc;
}
+QShaderDescription QShaderDescription::deserialize(QDataStream *stream)
+{
+ QShaderDescription desc;
+ QShaderDescriptionPrivate::get(&desc)->loadFromStream(stream);
+ return desc;
+}
+
/*!
\return the list of input variables. This includes vertex inputs (sometimes
called attributes) for the vertex stage, and inputs for other stages
@@ -867,6 +880,15 @@ static void addDeco(QJsonObject *obj, const QShaderDescription::InOutVariable &v
(*obj)[imageFlagsKey] = int(v.imageFlags);
}
+static void serializeDecorations(QDataStream *stream, const QShaderDescription::InOutVariable &v)
+{
+ (*stream) << v.location;
+ (*stream) << v.binding;
+ (*stream) << v.descriptorSet;
+ (*stream) << int(v.imageFormat);
+ (*stream) << int(v.imageFlags);
+}
+
static QJsonObject inOutObject(const QShaderDescription::InOutVariable &v)
{
QJsonObject obj;
@@ -876,6 +898,13 @@ static QJsonObject inOutObject(const QShaderDescription::InOutVariable &v)
return obj;
}
+static void serializeInOutVar(QDataStream *stream, const QShaderDescription::InOutVariable &v)
+{
+ (*stream) << v.name;
+ (*stream) << int(v.type);
+ serializeDecorations(stream, v);
+}
+
static QJsonObject blockMemberObject(const QShaderDescription::BlockVariable &v)
{
QJsonObject obj;
@@ -904,6 +933,23 @@ static QJsonObject blockMemberObject(const QShaderDescription::BlockVariable &v)
return obj;
}
+static void serializeBlockMemberVar(QDataStream *stream, const QShaderDescription::BlockVariable &v)
+{
+ (*stream) << v.name;
+ (*stream) << int(v.type);
+ (*stream) << v.offset;
+ (*stream) << v.size;
+ (*stream) << v.arrayDims.count();
+ for (int dim : v.arrayDims)
+ (*stream) << dim;
+ (*stream) << v.arrayStride;
+ (*stream) << v.matrixStride;
+ (*stream) << v.matrixIsRowMajor;
+ (*stream) << v.structMembers.count();
+ for (const QShaderDescription::BlockVariable &sv : v.structMembers)
+ serializeBlockMemberVar(stream, sv);
+}
+
QJsonDocument QShaderDescriptionPrivate::makeDoc()
{
QJsonObject root;
@@ -1002,6 +1048,67 @@ QJsonDocument QShaderDescriptionPrivate::makeDoc()
return QJsonDocument(root);
}
+void QShaderDescriptionPrivate::writeToStream(QDataStream *stream)
+{
+ (*stream) << inVars.count();
+ for (const QShaderDescription::InOutVariable &v : qAsConst(inVars))
+ serializeInOutVar(stream, v);
+
+ (*stream) << outVars.count();
+ for (const QShaderDescription::InOutVariable &v : qAsConst(outVars))
+ serializeInOutVar(stream, v);
+
+ (*stream) << uniformBlocks.count();
+ for (const QShaderDescription::UniformBlock &b : uniformBlocks) {
+ (*stream) << b.blockName;
+ (*stream) << b.structName;
+ (*stream) << b.size;
+ (*stream) << b.binding;
+ (*stream) << b.descriptorSet;
+ (*stream) << b.members.count();
+ for (const QShaderDescription::BlockVariable &v : b.members)
+ serializeBlockMemberVar(stream, v);
+ }
+
+ (*stream) << pushConstantBlocks.count();
+ for (const QShaderDescription::PushConstantBlock &b : pushConstantBlocks) {
+ (*stream) << b.name;
+ (*stream) << b.size;
+ (*stream) << b.members.count();
+ for (const QShaderDescription::BlockVariable &v : b.members)
+ serializeBlockMemberVar(stream, v);
+ }
+
+ (*stream) << storageBlocks.count();
+ for (const QShaderDescription::StorageBlock &b : storageBlocks) {
+ (*stream) << b.blockName;
+ (*stream) << b.instanceName;
+ (*stream) << b.knownSize;
+ (*stream) << b.binding;
+ (*stream) << b.descriptorSet;
+ (*stream) << b.members.count();
+ for (const QShaderDescription::BlockVariable &v : b.members)
+ serializeBlockMemberVar(stream, v);
+ }
+
+ (*stream) << combinedImageSamplers.count();
+ for (const QShaderDescription::InOutVariable &v : qAsConst(combinedImageSamplers)) {
+ (*stream) << v.name;
+ (*stream) << int(v.type);
+ serializeDecorations(stream, v);
+ }
+
+ (*stream) << storageImages.count();
+ for (const QShaderDescription::InOutVariable &v : qAsConst(storageImages)) {
+ (*stream) << v.name;
+ (*stream) << int(v.type);
+ serializeDecorations(stream, v);
+ }
+
+ for (size_t i = 0; i < 3; ++i)
+ (*stream) << localSize[i];
+}
+
static QShaderDescription::InOutVariable inOutVar(const QJsonObject &obj)
{
QShaderDescription::InOutVariable var;
@@ -1020,6 +1127,29 @@ static QShaderDescription::InOutVariable inOutVar(const QJsonObject &obj)
return var;
}
+static void deserializeDecorations(QDataStream *stream, QShaderDescription::InOutVariable *v)
+{
+ (*stream) >> v->location;
+ (*stream) >> v->binding;
+ (*stream) >> v->descriptorSet;
+ int f;
+ (*stream) >> f;
+ v->imageFormat = QShaderDescription::ImageFormat(f);
+ (*stream) >> f;
+ v->imageFlags = QShaderDescription::ImageFlags(f);
+}
+
+static QShaderDescription::InOutVariable deserializeInOutVar(QDataStream *stream)
+{
+ QShaderDescription::InOutVariable var;
+ (*stream) >> var.name;
+ int t;
+ (*stream) >> t;
+ var.type = QShaderDescription::VariableType(t);
+ deserializeDecorations(stream, &var);
+ return var;
+}
+
static QShaderDescription::BlockVariable blockVar(const QJsonObject &obj)
{
QShaderDescription::BlockVariable var;
@@ -1046,6 +1176,30 @@ static QShaderDescription::BlockVariable blockVar(const QJsonObject &obj)
return var;
}
+static QShaderDescription::BlockVariable deserializeBlockMemberVar(QDataStream *stream)
+{
+ QShaderDescription::BlockVariable var;
+ (*stream) >> var.name;
+ int t;
+ (*stream) >> t;
+ var.type = QShaderDescription::VariableType(t);
+ (*stream) >> var.offset;
+ (*stream) >> var.size;
+ int count;
+ (*stream) >> count;
+ var.arrayDims.resize(count);
+ for (int i = 0; i < count; ++i)
+ (*stream) >> var.arrayDims[i];
+ (*stream) >> var.arrayStride;
+ (*stream) >> var.matrixStride;
+ (*stream) >> var.matrixIsRowMajor;
+ (*stream) >> count;
+ var.structMembers.resize(count);
+ for (int i = 0; i < count; ++i)
+ var.structMembers[i] = deserializeBlockMemberVar(stream);
+ return var;
+}
+
void QShaderDescriptionPrivate::loadDoc(const QJsonDocument &doc)
{
if (doc.isNull()) {
@@ -1150,6 +1304,87 @@ void QShaderDescriptionPrivate::loadDoc(const QJsonDocument &doc)
}
}
+void QShaderDescriptionPrivate::loadFromStream(QDataStream *stream)
+{
+ Q_ASSERT(ref.loadRelaxed() == 1); // must be detached
+
+ int count;
+ (*stream) >> count;
+ inVars.resize(count);
+ for (int i = 0; i < count; ++i)
+ inVars[i] = deserializeInOutVar(stream);
+
+ (*stream) >> count;
+ outVars.resize(count);
+ for (int i = 0; i < count; ++i)
+ outVars[i] = deserializeInOutVar(stream);
+
+ (*stream) >> count;
+ uniformBlocks.resize(count);
+ for (int i = 0; i < count; ++i) {
+ (*stream) >> uniformBlocks[i].blockName;
+ (*stream) >> uniformBlocks[i].structName;
+ (*stream) >> uniformBlocks[i].size;
+ (*stream) >> uniformBlocks[i].binding;
+ (*stream) >> uniformBlocks[i].descriptorSet;
+ int memberCount;
+ (*stream) >> memberCount;
+ uniformBlocks[i].members.resize(memberCount);
+ for (int memberIdx = 0; memberIdx < memberCount; ++memberIdx)
+ uniformBlocks[i].members[memberIdx] = deserializeBlockMemberVar(stream);
+ }
+
+ (*stream) >> count;
+ pushConstantBlocks.resize(count);
+ for (int i = 0; i < count; ++i) {
+ (*stream) >> pushConstantBlocks[i].name;
+ (*stream) >> pushConstantBlocks[i].size;
+ int memberCount;
+ (*stream) >> memberCount;
+ pushConstantBlocks[i].members.resize(memberCount);
+ for (int memberIdx = 0; memberIdx < memberCount; ++memberIdx)
+ pushConstantBlocks[i].members[memberIdx] = deserializeBlockMemberVar(stream);
+ }
+
+ (*stream) >> count;
+ storageBlocks.resize(count);
+ for (int i = 0; i < count; ++i) {
+ (*stream) >> storageBlocks[i].blockName;
+ (*stream) >> storageBlocks[i].instanceName;
+ (*stream) >> storageBlocks[i].knownSize;
+ (*stream) >> storageBlocks[i].binding;
+ (*stream) >> storageBlocks[i].descriptorSet;
+ int memberCount;
+ (*stream) >> memberCount;
+ storageBlocks[i].members.resize(memberCount);
+ for (int memberIdx = 0; memberIdx < memberCount; ++memberIdx)
+ storageBlocks[i].members[memberIdx] = deserializeBlockMemberVar(stream);
+ }
+
+ (*stream) >> count;
+ combinedImageSamplers.resize(count);
+ for (int i = 0; i < count; ++i) {
+ (*stream) >> combinedImageSamplers[i].name;
+ int t;
+ (*stream) >> t;
+ combinedImageSamplers[i].type = QShaderDescription::VariableType(t);
+ deserializeDecorations(stream, &combinedImageSamplers[i]);
+ }
+
+ (*stream) >> count;
+ storageImages.resize(count);
+ for (int i = 0; i < count; ++i) {
+ (*stream) >> storageImages[i].name;
+ int t;
+ (*stream) >> t;
+ storageImages[i].type = QShaderDescription::VariableType(t);
+ deserializeDecorations(stream, &storageImages[i]);
+ }
+
+ for (size_t i = 0; i < 3; ++i)
+ (*stream) >> localSize[i];
+}
+
/*!
Returns \c true if the two QShaderDescription objects \a lhs and \a rhs are
equal.
diff --git a/src/gui/rhi/qshaderdescription_p.h b/src/gui/rhi/qshaderdescription_p.h
index 872ee8b138..108fc32a56 100644
--- a/src/gui/rhi/qshaderdescription_p.h
+++ b/src/gui/rhi/qshaderdescription_p.h
@@ -56,6 +56,7 @@
QT_BEGIN_NAMESPACE
struct QShaderDescriptionPrivate;
+class QDataStream;
class Q_GUI_EXPORT QShaderDescription
{
@@ -69,6 +70,7 @@ public:
bool isValid() const;
QByteArray toCbor() const;
+ void serialize(QDataStream *stream) const;
QByteArray toJson() const;
#if QT_CONFIG(binaryjson) && QT_DEPRECATED_SINCE(5, 15)
@@ -76,6 +78,7 @@ public:
static QShaderDescription fromBinaryJson(const QByteArray &data);
#endif
static QShaderDescription fromCbor(const QByteArray &data);
+ static QShaderDescription deserialize(QDataStream *stream);
enum VariableType {
Unknown = 0,
diff --git a/src/gui/rhi/qshaderdescription_p_p.h b/src/gui/rhi/qshaderdescription_p_p.h
index 1caee24984..69b6e811a1 100644
--- a/src/gui/rhi/qshaderdescription_p_p.h
+++ b/src/gui/rhi/qshaderdescription_p_p.h
@@ -80,7 +80,9 @@ struct Q_GUI_EXPORT QShaderDescriptionPrivate
static const QShaderDescriptionPrivate *get(const QShaderDescription *desc) { return desc->d; }
QJsonDocument makeDoc();
+ void writeToStream(QDataStream *stream);
void loadDoc(const QJsonDocument &doc);
+ void loadFromStream(QDataStream *stream);
QAtomicInt ref;
QVector<QShaderDescription::InOutVariable> inVars;
diff --git a/src/network/access/qnetworkreply.cpp b/src/network/access/qnetworkreply.cpp
index fb30bfd4f1..c22dce8f1c 100644
--- a/src/network/access/qnetworkreply.cpp
+++ b/src/network/access/qnetworkreply.cpp
@@ -554,14 +554,33 @@ QNetworkAccessManager::Operation QNetworkReply::operation() const
return d_func()->operation;
}
+#if QT_DEPRECATED_SINCE(5, 15)
/*!
+ \deprecated
+
+ Use networkError() instead.
+
Returns the error that was found during the processing of this
request. If no error was found, returns NoError.
- \sa setError()
+ \sa setError(), networkError()
*/
QNetworkReply::NetworkError QNetworkReply::error() const
{
+ return networkError();
+}
+#endif // QT_DEPRECATED_SINCE(5, 15)
+
+/*!
+ \since 5.15
+
+ Returns the error that was found during the processing of this
+ request. If no error was found, returns NoError.
+
+ \sa setError()
+*/
+QNetworkReply::NetworkError QNetworkReply::networkError() const
+{
return d_func()->errorCode;
}
@@ -858,7 +877,7 @@ void QNetworkReply::setRequest(const QNetworkRequest &request)
Calling setError() does not emit the error(QNetworkReply::NetworkError)
signal.
- \sa error(), errorString()
+ \sa error(), errorString(), networkError()
*/
void QNetworkReply::setError(NetworkError errorCode, const QString &errorString)
{
diff --git a/src/network/access/qnetworkreply.h b/src/network/access/qnetworkreply.h
index 4a402daa91..139009a56a 100644
--- a/src/network/access/qnetworkreply.h
+++ b/src/network/access/qnetworkreply.h
@@ -124,7 +124,12 @@ public:
QNetworkAccessManager *manager() const;
QNetworkAccessManager::Operation operation() const;
QNetworkRequest request() const;
- NetworkError error() const;
+
+#if QT_DEPRECATED_SINCE(5, 15)
+ QT_DEPRECATED_X("Use networkError()") NetworkError error() const;
+#endif // QT_DEPRECATED_SINCE(5, 15)
+ NetworkError networkError() const;
+
bool isFinished() const;
bool isRunning() const;
QUrl url() const;
diff --git a/src/platformsupport/fontdatabases/windows/qwindowsfontenginedirectwrite.cpp b/src/platformsupport/fontdatabases/windows/qwindowsfontenginedirectwrite.cpp
index 98246de0a5..5c999f455e 100644
--- a/src/platformsupport/fontdatabases/windows/qwindowsfontenginedirectwrite.cpp
+++ b/src/platformsupport/fontdatabases/windows/qwindowsfontenginedirectwrite.cpp
@@ -62,6 +62,9 @@
QT_BEGIN_NAMESPACE
+// Clang does not consider __declspec(nothrow) as nothrow
+QT_WARNING_DISABLE_CLANG("-Wmicrosoft-exception-spec")
+
// Convert from design units to logical pixels
#define DESIGN_TO_LOGICAL(DESIGN_UNIT_VALUE) \
QFixed::fromReal((qreal(DESIGN_UNIT_VALUE) / qreal(m_unitsPerEm)) * fontDef.pixelSize)
diff --git a/src/plugins/platforms/wasm/qwasmeventdispatcher.cpp b/src/plugins/platforms/wasm/qwasmeventdispatcher.cpp
index 41355d72ae..d89cd78b28 100644
--- a/src/plugins/platforms/wasm/qwasmeventdispatcher.cpp
+++ b/src/plugins/platforms/wasm/qwasmeventdispatcher.cpp
@@ -33,6 +33,14 @@
#include <emscripten.h>
+#if (__EMSCRIPTEN_major__ > 1 || __EMSCRIPTEN_minor__ > 38 || __EMSCRIPTEN_minor__ == 38 && __EMSCRIPTEN_tiny__ >= 22)
+# define EMSCRIPTEN_HAS_ASYNC_RUN_IN_MAIN_RUNTIME_THREAD
+#endif
+
+#ifdef EMSCRIPTEN_HAS_ASYNC_RUN_IN_MAIN_RUNTIME_THREAD
+#include <emscripten/threading.h>
+#endif
+
class QWasmEventDispatcherPrivate : public QEventDispatcherUNIXPrivate
{
@@ -179,3 +187,18 @@ void QWasmEventDispatcher::doMaintainTimers()
emscripten_async_call(callback, this, toWaitDuration);
m_currentTargetTime = newTargetTime;
}
+
+void QWasmEventDispatcher::wakeUp()
+{
+#ifdef EMSCRIPTEN_HAS_ASYNC_RUN_IN_MAIN_RUNTIME_THREAD
+ if (!emscripten_is_main_runtime_thread())
+ emscripten_async_run_in_main_runtime_thread_(EM_FUNC_SIG_VI, (void*)(&QWasmEventDispatcher::mainThreadWakeUp), this);
+#endif
+ QEventDispatcherUNIX::wakeUp();
+}
+
+void QWasmEventDispatcher::mainThreadWakeUp(void *eventDispatcher)
+{
+ emscripten_resume_main_loop(); // Service possible requestUpdate Calls
+ static_cast<QWasmEventDispatcher *>(eventDispatcher)->processEvents(QEventLoop::AllEvents);
+}
diff --git a/src/plugins/platforms/wasm/qwasmeventdispatcher.h b/src/plugins/platforms/wasm/qwasmeventdispatcher.h
index 5300b3de73..f72d92ce07 100644
--- a/src/plugins/platforms/wasm/qwasmeventdispatcher.h
+++ b/src/plugins/platforms/wasm/qwasmeventdispatcher.h
@@ -51,6 +51,8 @@ public:
protected:
bool processEvents(QEventLoop::ProcessEventsFlags flags) override;
void doMaintainTimers();
+ void wakeUp() override;
+ static void mainThreadWakeUp(void *eventDispatcher);
private:
bool m_hasMainLoop = false;
diff --git a/src/plugins/platforms/windows/qwindowscombase.h b/src/plugins/platforms/windows/qwindowscombase.h
index 45cba9c68b..bb4b295395 100644
--- a/src/plugins/platforms/windows/qwindowscombase.h
+++ b/src/plugins/platforms/windows/qwindowscombase.h
@@ -107,6 +107,9 @@ private:
ULONG m_ref;
};
+// Clang does not consider __declspec(nothrow) as nothrow
+QT_WARNING_DISABLE_CLANG("-Wmicrosoft-exception-spec")
+
QT_END_NAMESPACE
#endif // QWINDOWSCOMBASE_H
diff --git a/src/plugins/styles/mac/qmacstyle_mac.mm b/src/plugins/styles/mac/qmacstyle_mac.mm
index f0bc51b796..24efb641f2 100644
--- a/src/plugins/styles/mac/qmacstyle_mac.mm
+++ b/src/plugins/styles/mac/qmacstyle_mac.mm
@@ -2585,7 +2585,7 @@ QPalette QMacStyle::standardPalette() const
auto platformTheme = QGuiApplicationPrivate::platformTheme();
auto styleNames = platformTheme->themeHint(QPlatformTheme::StyleNames);
if (styleNames.toStringList().contains("macintosh"))
- return *platformTheme->palette();
+ return QPalette(); // Inherit everything from theme
else
return QStyle::standardPalette();
}
diff --git a/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp b/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp
index bf80138b32..5d2e8efd68 100644
--- a/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp
+++ b/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp
@@ -3774,8 +3774,7 @@ int QWindowsXPStyle::styleHint(StyleHint hint, const QStyleOption *option, const
/*! \reimp */
QPalette QWindowsXPStyle::standardPalette() const
{
- return QWindowsXPStylePrivate::useXP() && QApplicationPrivate::sys_pal
- ? *QApplicationPrivate::sys_pal : QWindowsStyle::standardPalette();
+ return QWindowsXPStylePrivate::useXP() ? QPalette() : QWindowsStyle::standardPalette();
}
/*!
diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp
index 4b1daab4cf..eea97b2c0b 100644
--- a/src/widgets/kernel/qapplication.cpp
+++ b/src/widgets/kernel/qapplication.cpp
@@ -140,30 +140,6 @@ Q_GUI_EXPORT bool qt_sendShortcutOverrideEvent(QObject *o, ulong timestamp, int
QApplicationPrivate *QApplicationPrivate::self = nullptr;
-static void initSystemPalette()
-{
- if (QApplicationPrivate::sys_pal)
- return; // Already initialized
-
- QPalette defaultPalette;
- if (QApplicationPrivate::app_style)
- defaultPalette = QApplicationPrivate::app_style->standardPalette();
-
- auto *platformTheme = QGuiApplicationPrivate::platformTheme();
- if (const QPalette *themePalette = platformTheme ? platformTheme->palette() : nullptr) {
- QApplicationPrivate::setSystemPalette(themePalette->resolve(defaultPalette));
- QApplicationPrivate::initializeWidgetPaletteHash();
- } else {
- QApplicationPrivate::setSystemPalette(defaultPalette);
- }
-}
-
-static void clearSystemPalette()
-{
- delete QApplicationPrivate::sys_pal;
- QApplicationPrivate::sys_pal = nullptr;
-}
-
bool QApplicationPrivate::autoSipEnabled = true;
QApplicationPrivate::QApplicationPrivate(int &argc, char **argv, int flags)
@@ -381,8 +357,6 @@ QString QApplicationPrivate::styleSheet; // default application styles
#endif
QPointer<QWidget> QApplicationPrivate::leaveAfterRelease = nullptr;
-QPalette *QApplicationPrivate::sys_pal = nullptr; // default system palette
-
QFont *QApplicationPrivate::sys_font = nullptr; // default system font
QFont *QApplicationPrivate::set_font = nullptr; // default font set by programmer
@@ -545,12 +519,7 @@ void QApplicationPrivate::init()
// Must be called before initialize()
QColormap::initialize();
- if (sys_pal) {
- // Now that we have a platform theme we need to reset
- // the system palette to pick up the theme colors.
- clearSystemPalette();
- initSystemPalette();
- }
+ initializeWidgetPalettesFromTheme();
qt_init_tooltip_palette();
QApplicationPrivate::initializeWidgetFontHash();
@@ -629,38 +598,6 @@ void QApplicationPrivate::initialize()
is_app_running = true; // no longer starting up
}
-static void setPossiblePalette(const QPalette *palette, const char *className)
-{
- if (palette == nullptr)
- return;
- QApplicationPrivate::setPalette_helper(*palette, className);
-}
-
-void QApplicationPrivate::initializeWidgetPaletteHash()
-{
- QPlatformTheme *platformTheme = QGuiApplicationPrivate::platformTheme();
- if (!platformTheme)
- return;
-
- widgetPalettes.clear();
-
- setPossiblePalette(platformTheme->palette(QPlatformTheme::ToolButtonPalette), "QToolButton");
- setPossiblePalette(platformTheme->palette(QPlatformTheme::ButtonPalette), "QAbstractButton");
- setPossiblePalette(platformTheme->palette(QPlatformTheme::CheckBoxPalette), "QCheckBox");
- setPossiblePalette(platformTheme->palette(QPlatformTheme::RadioButtonPalette), "QRadioButton");
- setPossiblePalette(platformTheme->palette(QPlatformTheme::HeaderPalette), "QHeaderView");
- setPossiblePalette(platformTheme->palette(QPlatformTheme::ItemViewPalette), "QAbstractItemView");
- setPossiblePalette(platformTheme->palette(QPlatformTheme::MessageBoxLabelPalette), "QMessageBoxLabel");
- setPossiblePalette(platformTheme->palette(QPlatformTheme::TabBarPalette), "QTabBar");
- setPossiblePalette(platformTheme->palette(QPlatformTheme::LabelPalette), "QLabel");
- setPossiblePalette(platformTheme->palette(QPlatformTheme::GroupBoxPalette), "QGroupBox");
- setPossiblePalette(platformTheme->palette(QPlatformTheme::MenuPalette), "QMenu");
- setPossiblePalette(platformTheme->palette(QPlatformTheme::MenuBarPalette), "QMenuBar");
- setPossiblePalette(platformTheme->palette(QPlatformTheme::TextEditPalette), "QTextEdit");
- setPossiblePalette(platformTheme->palette(QPlatformTheme::TextEditPalette), "QTextControl");
- setPossiblePalette(platformTheme->palette(QPlatformTheme::TextLineEditPalette), "QLineEdit");
-}
-
void QApplicationPrivate::initializeWidgetFontHash()
{
const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme();
@@ -798,9 +735,6 @@ QApplication::~QApplication()
delete qt_desktopWidget;
qt_desktopWidget = nullptr;
- delete QApplicationPrivate::app_pal;
- QApplicationPrivate::app_pal = nullptr;
- clearSystemPalette();
QApplicationPrivate::widgetPalettes.clear();
delete QApplicationPrivate::sys_font;
@@ -1051,10 +985,10 @@ QStyle *QApplication::style()
// Take ownership of the style
defaultStyle->setParent(qApp);
- initSystemPalette();
-
if (testAttribute(Qt::AA_SetPalette))
defaultStyle->polish(*QGuiApplicationPrivate::app_pal);
+ else
+ QApplicationPrivate::initializeWidgetPalettesFromTheme();
#ifndef QT_NO_STYLE_STYLESHEET
if (!QApplicationPrivate::styleSheet.isEmpty()) {
@@ -1128,13 +1062,10 @@ void QApplication::setStyle(QStyle *style)
// take care of possible palette requirements of certain gui
// styles. Do it before polishing the application since the style
// might call QApplication::setPalette() itself
- if (testAttribute(Qt::AA_SetPalette)) {
+ if (testAttribute(Qt::AA_SetPalette))
QApplicationPrivate::app_style->polish(*QGuiApplicationPrivate::app_pal);
- } else {
- if (QApplicationPrivate::sys_pal)
- clearSystemPalette();
- initSystemPalette();
- }
+ else
+ QApplicationPrivate::initializeWidgetPalettesFromTheme();
// The default widget font hash is based on the platform theme,
// not the style, but the widget fonts could in theory have been
@@ -1317,6 +1248,22 @@ void QApplication::setGlobalStrut(const QSize& strut)
// Widget specific palettes
QApplicationPrivate::PaletteHash QApplicationPrivate::widgetPalettes;
+QPalette QApplicationPrivate::basePalette() const
+{
+ // Start out with a palette based on the style, in case there's no theme
+ // available, or so that we can fill in missing roles in the theme.
+ QPalette palette = app_style ? app_style->standardPalette() : Qt::gray;
+
+ // Prefer theme palette if available, but fill in missing roles from style
+ // for compatibility. Note that the style's standard palette is not prioritized
+ // over the theme palette, as the documented way of applying the style's palette
+ // is to set it explicitly using QApplication::setPalette().
+ if (const QPalette *themePalette = platformTheme() ? platformTheme()->palette() : nullptr)
+ palette = themePalette->resolve(palette);
+
+ return palette;
+}
+
/*!
\fn QPalette QApplication::palette(const QWidget* widget)
@@ -1363,35 +1310,8 @@ QPalette QApplication::palette(const char *className)
return QGuiApplication::palette();
}
-void QApplicationPrivate::setPalette_helper(const QPalette &palette, const char* className)
-{
- QPalette pal = palette;
-
- if (QApplicationPrivate::app_style)
- QApplicationPrivate::app_style->polish(pal); // NB: non-const reference
-
- bool all = false;
- if (!className) {
- if (!QGuiApplicationPrivate::setPalette(pal))
- return;
-
- if (!QApplicationPrivate::sys_pal || !palette.isCopyOf(*QApplicationPrivate::sys_pal))
- QCoreApplication::setAttribute(Qt::AA_SetPalette);
-
- if (!widgetPalettes.isEmpty()) {
- all = true;
- widgetPalettes.clear();
- }
- } else {
- widgetPalettes.insert(className, pal);
- }
-
- if (qApp)
- qApp->d_func()->sendApplicationPaletteChange(all, className);
-}
-
/*!
- Changes the default application palette to \a palette.
+ Changes the application palette to \a palette.
If \a className is passed, the change applies only to widgets that inherit
\a className (as reported by QObject::inherits()). If \a className is left
@@ -1412,23 +1332,87 @@ void QApplicationPrivate::setPalette_helper(const QPalette &palette, const char*
\sa QWidget::setPalette(), palette(), QStyle::polish()
*/
-
void QApplication::setPalette(const QPalette &palette, const char* className)
{
- QApplicationPrivate::setPalette_helper(palette, className);
+ QPalette polishedPalette = palette;
+
+ if (QApplicationPrivate::app_style)
+ QApplicationPrivate::app_style->polish(polishedPalette);
+
+ if (className) {
+ QApplicationPrivate::widgetPalettes.insert(className, polishedPalette);
+ if (qApp)
+ qApp->d_func()->handlePaletteChanged(className);
+ } else {
+ QGuiApplication::setPalette(polishedPalette);
+ }
}
+void QApplicationPrivate::handlePaletteChanged(const char *className)
+{
+ if (!is_app_running || is_app_closing)
+ return;
+
+ // Setting the global application palette is documented to
+ // reset any previously set class specific widget palettes.
+ bool sendPaletteChangeToAllWidgets = false;
+ if (!className && !widgetPalettes.isEmpty()) {
+ sendPaletteChangeToAllWidgets = true;
+ widgetPalettes.clear();
+ }
+ QGuiApplicationPrivate::handlePaletteChanged(className);
-void QApplicationPrivate::setSystemPalette(const QPalette &pal)
+ QEvent event(QEvent::ApplicationPaletteChange);
+ const QWidgetList widgets = QApplication::allWidgets();
+ for (auto widget : widgets) {
+ if (sendPaletteChangeToAllWidgets || (!className && widget->isWindow()) || (className && widget->inherits(className)))
+ QCoreApplication::sendEvent(widget, &event);
+ }
+
+#if QT_CONFIG(graphicsview)
+ for (auto scene : qAsConst(scene_list))
+ QCoreApplication::sendEvent(scene, &event);
+#endif
+
+ // Palette has been reset back to the default application palette,
+ // so we need to reinitialize the widget palettes from the theme.
+ if (!className && !testAttribute(Qt::AA_SetPalette))
+ initializeWidgetPalettesFromTheme();
+}
+
+void QApplicationPrivate::initializeWidgetPalettesFromTheme()
{
- if (!sys_pal)
- sys_pal = new QPalette(pal);
- else
- *sys_pal = pal;
+ QPlatformTheme *platformTheme = QGuiApplicationPrivate::platformTheme();
+ if (!platformTheme)
+ return;
- if (!testAttribute(Qt::AA_SetPalette))
- QApplication::setPalette(*sys_pal);
+ widgetPalettes.clear();
+
+ struct ThemedWidget { const char *className; QPlatformTheme::Palette palette; };
+
+ static const ThemedWidget themedWidgets[] = {
+ { "QToolButton", QPlatformTheme::ToolButtonPalette },
+ { "QAbstractButton", QPlatformTheme::ButtonPalette },
+ { "QCheckBox", QPlatformTheme::CheckBoxPalette },
+ { "QRadioButton", QPlatformTheme::RadioButtonPalette },
+ { "QHeaderView", QPlatformTheme::HeaderPalette },
+ { "QAbstractItemView", QPlatformTheme::ItemViewPalette },
+ { "QMessageBoxLabel", QPlatformTheme::MessageBoxLabelPalette },
+ { "QTabBar", QPlatformTheme::TabBarPalette },
+ { "QLabel", QPlatformTheme::LabelPalette },
+ { "QGroupBox", QPlatformTheme::GroupBoxPalette },
+ { "QMenu", QPlatformTheme::MenuPalette },
+ { "QMenuBar", QPlatformTheme::MenuBarPalette },
+ { "QTextEdit", QPlatformTheme::TextEditPalette },
+ { "QTextControl", QPlatformTheme::TextEditPalette },
+ { "QLineEdit", QPlatformTheme::TextLineEditPalette },
+ };
+
+ for (const auto themedWidget : themedWidgets) {
+ if (auto *palette = platformTheme->palette(themedWidget.palette))
+ QApplication::setPalette(*palette, themedWidget.className);
+ }
}
/*!
@@ -4413,29 +4397,8 @@ void QApplicationPrivate::translateTouchCancel(QTouchDevice *device, ulong times
void QApplicationPrivate::notifyThemeChanged()
{
QGuiApplicationPrivate::notifyThemeChanged();
- clearSystemPalette();
- initSystemPalette();
- qt_init_tooltip_palette();
-}
-
-void QApplicationPrivate::sendApplicationPaletteChange(bool toAllWidgets, const char *className)
-{
- if (!is_app_running || is_app_closing)
- return;
- QGuiApplicationPrivate::sendApplicationPaletteChange(toAllWidgets, className);
-
- QEvent event(QEvent::ApplicationPaletteChange);
- const QWidgetList widgets = QApplication::allWidgets();
- for (auto widget : widgets) {
- if (toAllWidgets || (!className && widget->isWindow()) || (className && widget->inherits(className)))
- QCoreApplication::sendEvent(widget, &event);
- }
-
-#if QT_CONFIG(graphicsview)
- for (auto scene : qAsConst(scene_list))
- QCoreApplication::sendEvent(scene, &event);
-#endif // QT_CONFIG(graphicsview)
+ qt_init_tooltip_palette();
}
#if QT_CONFIG(draganddrop)
diff --git a/src/widgets/kernel/qapplication_p.h b/src/widgets/kernel/qapplication_p.h
index 71f695cc18..ab6d85aeb9 100644
--- a/src/widgets/kernel/qapplication_p.h
+++ b/src/widgets/kernel/qapplication_p.h
@@ -158,12 +158,12 @@ public:
static QSize app_strut;
static QWidgetList *popupWidgets;
static QStyle *app_style;
- static QPalette *sys_pal;
protected:
void notifyThemeChanged() override;
- void sendApplicationPaletteChange(bool toAllWidgets = false,
- const char *className = nullptr) override;
+
+ QPalette basePalette() const override;
+ void handlePaletteChanged(const char *className = nullptr) override;
#if QT_CONFIG(draganddrop)
void notifyDragStarted(const QDrag *) override;
@@ -184,9 +184,7 @@ public:
static int enabledAnimations; // Combination of QPlatformTheme::UiEffect
static bool widgetCount; // Coupled with -widgetcount switch
- static void setSystemPalette(const QPalette &pal);
- static void setPalette_helper(const QPalette &palette, const char* className);
- static void initializeWidgetPaletteHash();
+ static void initializeWidgetPalettesFromTheme();
static void initializeWidgetFontHash();
static void setSystemFont(const QFont &font);