From 8da3eea4fb702c2dc369c1628e91a034569aa9f0 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 25 Jun 2019 22:21:44 +0200 Subject: Optimize some atomic counters Define the static QAtomic at file scope to avoid GCC's pessimisation with function-static QAtomic (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79561), and make sure the initial value is 0, so it ends up in BSS, not TEXT. In QRhi..., don't create a static instance of the wrapper class, use a file- static atomic, too. This turns the class into a glorified namespace. Change-Id: I707f628e2b434330028077223071716d5704ba32 Reviewed-by: Thiago Macieira --- src/platformsupport/fbconvenience/qfbwindow.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/platformsupport') diff --git a/src/platformsupport/fbconvenience/qfbwindow.cpp b/src/platformsupport/fbconvenience/qfbwindow.cpp index 36f92b8cea..9f5f87d9d6 100644 --- a/src/platformsupport/fbconvenience/qfbwindow.cpp +++ b/src/platformsupport/fbconvenience/qfbwindow.cpp @@ -45,11 +45,12 @@ QT_BEGIN_NAMESPACE +static QBasicAtomicInt winIdGenerator = Q_BASIC_ATOMIC_INITIALIZER(0); + QFbWindow::QFbWindow(QWindow *window) : QPlatformWindow(window), mBackingStore(0), mWindowState(Qt::WindowNoState) { - static QAtomicInt winIdGenerator(1); - mWindowId = winIdGenerator.fetchAndAddRelaxed(1); + mWindowId = winIdGenerator.fetchAndAddRelaxed(1) + 1; } QFbWindow::~QFbWindow() -- cgit v1.2.3 From cd113d0dcb5e6ff71300ed67af5e296dc6f5dccf Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 27 Jun 2019 15:47:16 +0200 Subject: Port some trivial cases from QMutex to QRecursiveMutex In all of these cases, the effect of the change is local to one file. Change-Id: I3bda3aadee3b42e7797183c2330183390b92d1f2 Reviewed-by: Thiago Macieira --- src/platformsupport/fontdatabases/freetype/qfontengine_ft_p.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/platformsupport') diff --git a/src/platformsupport/fontdatabases/freetype/qfontengine_ft_p.h b/src/platformsupport/fontdatabases/freetype/qfontengine_ft_p.h index 2d1d5e6572..2765db2946 100644 --- a/src/platformsupport/fontdatabases/freetype/qfontengine_ft_p.h +++ b/src/platformsupport/fontdatabases/freetype/qfontengine_ft_p.h @@ -116,11 +116,11 @@ private: friend class QFontEngineFT; friend class QtFreetypeData; friend struct QScopedPointerDeleter; - QFreetypeFace() : _lock(QMutex::Recursive) {} + QFreetypeFace() = default; ~QFreetypeFace() {} void cleanup(); QAtomicInt ref; - QMutex _lock; + QRecursiveMutex _lock; QByteArray fontData; QFontEngine::Holder hbFace; -- cgit v1.2.3 From eea99e1e8f3eb67fda35dd3a656fe9b5a9be84f2 Mon Sep 17 00:00:00 2001 From: Andreas Hartmetz Date: Mon, 10 Jun 2019 14:39:04 +0200 Subject: Fontconfig font database: Short-circuit matching by filename If the filename matches, no other matching is necessary. Fontconfig doesn't have a fast path for that, so implement one here. Fontconfig is unlikely to add that fast path, see here: https://gitlab.freedesktop.org/fontconfig/fontconfig/issues/103 With -O1 builds of Qt and KDE stack, 358 fonts installed according to KDE systemsetting, on a Ryzen 1800X, startup time of kwrite decreases as following according to perf stat: msec task-clock: ~480 ms to ~455 ms cycles: ~1.73e9 to ~1.65e9 Change-Id: I630a80e4bed2647d5bbd95247005aab7d0cb0363 Reviewed-by: Allan Sandfeld Jensen --- .../fontconfig/qfontconfigdatabase.cpp | 72 +++++++++++++++------- 1 file changed, 50 insertions(+), 22 deletions(-) (limited to 'src/platformsupport') diff --git a/src/platformsupport/fontdatabases/fontconfig/qfontconfigdatabase.cpp b/src/platformsupport/fontdatabases/fontconfig/qfontconfigdatabase.cpp index 7abf295782..e28b40c240 100644 --- a/src/platformsupport/fontdatabases/fontconfig/qfontconfigdatabase.cpp +++ b/src/platformsupport/fontdatabases/fontconfig/qfontconfigdatabase.cpp @@ -927,38 +927,66 @@ void QFontconfigDatabase::setupFontEngine(QFontEngineFT *engine, const QFontDef antialias = antialiasingEnabled - 1; } - QFontEngine::GlyphFormat format; - // try and get the pattern + // try to find a match for fid + const QFontEngine::FaceId fid = engine->faceId(); FcPattern *pattern = FcPatternCreate(); + FcPattern *match = nullptr; + + // try a trivial match by filename - FC_FILE is highest priority, so if it matches, FcFontMatch + // will just find the file (fine) and spend a millisecond or so doing unnecessary work (bad). + if (!fid.filename.isEmpty() && QFile::exists(QString::fromUtf8(fid.filename))) { + FcBlanks *blanks = FcConfigGetBlanks(nullptr); + int count = 0; + FcPattern *fileMatch = FcFreeTypeQuery((const FcChar8 *)fid.filename.data(), fid.index, + blanks, &count); + if (fileMatch) { + // Apply Fontconfig configuration - FcFreeTypeQuery only returns information stored in + // the font file, we also want to respect system and user settings. + FcConfigSubstitute(0, pattern, FcMatchPattern); + FcDefaultSubstitute(pattern); + match = FcFontRenderPrepare(0, pattern, fileMatch); + FcPatternDestroy(fileMatch); + } + } - FcValue value; - value.type = FcTypeString; - QByteArray cs = fontDef.family.toUtf8(); - value.u.s = (const FcChar8 *)cs.data(); - FcPatternAdd(pattern,FC_FAMILY,value,true); + if (!match) { + FcValue value; - QFontEngine::FaceId fid = engine->faceId(); + // Fontconfig rules might process this information for arbitrary purposes, so add it, + // even though we already know that it doesn't match an existing file. + if (!fid.filename.isEmpty()) { + value.type = FcTypeString; + value.u.s = (const FcChar8 *)fid.filename.data(); + FcPatternAdd(pattern, FC_FILE, value, true); - if (!fid.filename.isEmpty()) { - value.u.s = (const FcChar8 *)fid.filename.data(); - FcPatternAdd(pattern,FC_FILE,value,true); + value.type = FcTypeInteger; + value.u.i = fid.index; + FcPatternAdd(pattern, FC_INDEX, value, true); + } - value.type = FcTypeInteger; - value.u.i = fid.index; - FcPatternAdd(pattern,FC_INDEX,value,true); - } + const QByteArray cs = fontDef.family.toUtf8(); + value.type = FcTypeString; + value.u.s = (const FcChar8 *)cs.data(); + FcPatternAdd(pattern, FC_FAMILY, value, true); - if (fontDef.pixelSize > 0.1) - FcPatternAddDouble(pattern, FC_PIXEL_SIZE, fontDef.pixelSize); + if (fontDef.pixelSize > 0.1) { + value.type = FcTypeDouble; + value.u.d = fontDef.pixelSize; + FcPatternAdd(pattern, FC_PIXEL_SIZE, value, true); + } - FcResult result; + FcResult result; - FcConfigSubstitute(0, pattern, FcMatchPattern); - FcDefaultSubstitute(pattern); + FcConfigSubstitute(0, pattern, FcMatchPattern); + FcDefaultSubstitute(pattern); - FcPattern *match = FcFontMatch(0, pattern, &result); + match = FcFontMatch(0, pattern, &result); + } + + QFontEngine::GlyphFormat format; if (match) { - engine->setDefaultHintStyle(defaultHintStyleFromMatch((QFont::HintingPreference)fontDef.hintingPreference, match, useXftConf)); + engine->setDefaultHintStyle(defaultHintStyleFromMatch( + (QFont::HintingPreference)fontDef.hintingPreference, match, useXftConf)); FcBool fc_autohint; if (FcPatternGetBool(match, FC_AUTOHINT,0, &fc_autohint) == FcResultMatch) -- cgit v1.2.3