summaryrefslogtreecommitdiffstats
path: root/src/gui/text/qfontdatabase.cpp
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2022-03-25 11:26:20 +0100
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2022-03-31 20:12:54 +0100
commita08e15cda1823ae41fe9ab211c85d737515f6fcd (patch)
tree98f075945657cac16ff90e7594d5a3d7480f15f9 /src/gui/text/qfontdatabase.cpp
parentc256bede99a3c6395a88e92a39d49473c57a01ba (diff)
QFontDatabase: Centralize initialization in ensureFontDatabase()
Instead of having multiple code paths call initializeDb(), we use the already existing ensureFontDatabase() to provide the central point of ensuring an initialized font database. A couple of locks for the fontDatabaseMutex was added since the ensureFontDatabase() function documents that as a requirement for calling the function, but these locks were presumably already needed as the original code paths accessed the database in the same way. Change-Id: I5e29a069c4c7f68902dbe0c6c949a168d54f5f0e Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
Diffstat (limited to 'src/gui/text/qfontdatabase.cpp')
-rw-r--r--src/gui/text/qfontdatabase.cpp36
1 files changed, 10 insertions, 26 deletions
diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp
index b6a55d8ca6..a2cdd1e498 100644
--- a/src/gui/text/qfontdatabase.cpp
+++ b/src/gui/text/qfontdatabase.cpp
@@ -666,13 +666,10 @@ QStringList QPlatformFontDatabase::fallbacksForFamily(const QString &family, QFo
return preferredFallbacks + otherFallbacks;
}
-static void initializeDb();
-
static QStringList fallbacksForFamily(const QString &family, QFont::Style style, QFont::StyleHint styleHint, QChar::Script script)
{
- auto *db = QFontDatabasePrivate::instance();
- if (!db->count)
- initializeDb();
+ QMutexLocker locker(fontDatabaseMutex());
+ auto *db = QFontDatabasePrivate::ensureFontDatabase();
const QtFontFallbacksCacheKey cacheKey = { family, style, styleHint, script };
@@ -710,25 +707,10 @@ QStringList qt_fallbacksForFamily(const QString &family, QFont::Style style, QFo
static void registerFont(QFontDatabasePrivate::ApplicationFont *fnt);
-static void initializeDb()
-{
- auto *db = QFontDatabasePrivate::instance();
-
- // init by asking for the platformfontdb for the first time or after invalidation
- if (!db->count) {
- QGuiApplicationPrivate::platformIntegration()->fontDatabase()->populateFontDatabase();
- for (int i = 0; i < db->applicationFonts.count(); i++) {
- if (!db->applicationFonts.at(i).properties.isEmpty())
- registerFont(&db->applicationFonts[i]);
- }
- }
-}
-
static inline void load(const QString & = QString(), int = -1)
{
- // Only initialize the database if it has been cleared or not initialized yet
- if (!QFontDatabasePrivate::instance()->count)
- initializeDb();
+ QMutexLocker locker(fontDatabaseMutex());
+ QFontDatabasePrivate::ensureFontDatabase();
}
static
@@ -1320,7 +1302,11 @@ QFontDatabasePrivate *QFontDatabasePrivate::ensureFontDatabase()
if (Q_UNLIKELY(qGuiApp == nullptr || QGuiApplicationPrivate::platformIntegration() == nullptr))
qFatal("QFontDatabase: Must construct a QGuiApplication before accessing QFontDatabase");
- initializeDb();
+ QGuiApplicationPrivate::platformIntegration()->fontDatabase()->populateFontDatabase();
+ for (int i = 0; i < d->applicationFonts.count(); i++) {
+ if (!d->applicationFonts.at(i).properties.isEmpty())
+ registerFont(&d->applicationFonts[i]);
+ }
}
return d;
}
@@ -2357,9 +2343,7 @@ QFontEngine *QFontDatabasePrivate::findFont(const QFontDef &req,
bool preferScriptOverFamily)
{
QMutexLocker locker(fontDatabaseMutex());
-
- if (!QFontDatabasePrivate::instance()->count)
- initializeDb();
+ ensureFontDatabase();
QFontEngine *engine;