diff options
author | Tor Arne Vestbø <[email protected]> | 2025-06-02 23:56:36 +0200 |
---|---|---|
committer | Tor Arne Vestbø <[email protected]> | 2025-06-06 18:10:07 +0200 |
commit | 965b799c3faabdc7b89dc1b8e0495f38f4d3158f (patch) | |
tree | bfb7c4e8cb292bba3a204b0c253ed0aaa097ce94 | |
parent | a589ef5cff160701316b3eebf2139ea9b55b0de5 (diff) |
Decouple QApplication from QColormap
Initialize the shared QColormapPrivate on first call to
QColormap::instance, in a thread safe manner for good measure,
and clean it up on app exit if needed.
The cleanup now also accounts for the possibility of QColormap
instances outliving the cleanup. We still reset to a new QColormap
on next use, following the existing behavior.
Change-Id: Ia16a84994b3ee05f9431ba24dd9126f2dc271b61
Reviewed-by: Paul Olav Tvete <[email protected]>
-rw-r--r-- | src/widgets/kernel/qapplication.cpp | 3 | ||||
-rw-r--r-- | src/widgets/util/qcolormap.cpp | 16 |
2 files changed, 14 insertions, 5 deletions
diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index 8a041a4ac2c..82ecd355baf 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -31,7 +31,6 @@ #include <private/qdnd_p.h> #endif #include "private/qguiapplication_p.h" -#include "qcolormap.h" #include "qdebug.h" #if QT_CONFIG(style_stylesheet) #include "private/qstylesheetstyle_p.h" @@ -480,7 +479,6 @@ void QApplicationPrivate::init() process_cmdline(); // Must be called before initialize() - QColormap::initialize(); initializeWidgetPalettesFromTheme(); qt_init_tooltip_palette(); QApplicationPrivate::initializeWidgetFontHash(); @@ -712,7 +710,6 @@ QApplication::~QApplication() d->cleanupMultitouch(); QPixmapCache::clear(); - QColormap::cleanup(); QApplicationPrivate::active_window = nullptr; //### this should not be necessary diff --git a/src/widgets/util/qcolormap.cpp b/src/widgets/util/qcolormap.cpp index 08f892b109c..dfd32fd9816 100644 --- a/src/widgets/util/qcolormap.cpp +++ b/src/widgets/util/qcolormap.cpp @@ -7,6 +7,8 @@ #include "qscreen.h" #include "qguiapplication.h" +#include <QtCore/qmutex.h> + QT_BEGIN_NAMESPACE class QColormapPrivate @@ -42,16 +44,26 @@ void QColormap::initialize() screenMap->mode = QColormap::Direct; screenMap->numcolors = -1; } + + qAddPostRoutine(QColormap::cleanup); } void QColormap::cleanup() { - delete screenMap; - screenMap = nullptr; + if (screenMap) { + if (!screenMap->ref.deref()) + delete screenMap; + screenMap = nullptr; + } } QColormap QColormap::instance(int /*screen*/) { + static QMutex mutex; + QMutexLocker locker(&mutex); + if (!screenMap) + initialize(); + return QColormap(); } |