diff options
author | Eskil Abrahamsen Blomfeldt <[email protected]> | 2022-03-18 12:57:01 +0100 |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <[email protected]> | 2022-04-08 07:48:57 +0200 |
commit | 2fb43a35dfa08bb0746913e3363f1fcf21815e72 (patch) | |
tree | f21107060994df759deb2ba8cfebb55113e4f5dc /src/quick/items/qquickwindow.h | |
parent | 54a71e8c83de9b0312c920bc52378efcf20d537b (diff) |
Invalidate text when application fonts are added or removed
We had multiple related issues due to application fonts being added
or removed during the application lifetime.
1. If a text had font family "foo" set, and this font did not
exist at the time, then loading "foo" at a later stage would not
update the text to use the correct font, since the result of
the previous request had been cached.
2. A variation of #1 was if the font "foo" was loaded by a FontLoader
in the scene and referred to by name in the text component. In this
case, there was a race condition, where the font lookup would sometimes
yield different results on the main thread and on the render thread,
and text would be garbled.
3. When a font was removed from the font database, then references to
it would remain in the caches (glyph cache + font cache) in the render
thread. With certain backends (DirectWrite, CoreText) this caused errors
or even crashes, as the cached font engines would be referring to data
that had been removed.
The work-around for #1 and #2 was merely to avoid hardcoding names for
fonts, but instead getting them from the FontLoader. This way, you can
avoid requesting the font family before it is available (and thus avoid
caching the wrong result). However, for #3 there is no known work-around.
This patch fixes all three (together with a smaller patch for qtbase) by
invalidating all text and related caches in Qt Quick when fonts are
either added or removed from the font database. This does add some
overhead if font loading happens during runtime, but the alternative is
broken behavior and dangling pointers.
This is done during the synchronization step. Before synchronization,
the font cache is flushed and all text components are marked for update,
so that fonts are re-requested against the new font database.
After synchronization, we delete all distance field glyph caches which
are not currently in use, to avoid having references to stale application
font data in the list.
[ChangeLog][Text] Fix multiple issues with usage of application fonts when
they are added or removed during the lifetime of the application.
Task-number: QTBUG-100697
Task-number: QDS-1142
Change-Id: Ib309e54e0ee97b6be6d2a7211964043fd51c9ec5
Reviewed-by: Tor Arne Vestbø <[email protected]>
Diffstat (limited to 'src/quick/items/qquickwindow.h')
-rw-r--r-- | src/quick/items/qquickwindow.h | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/src/quick/items/qquickwindow.h b/src/quick/items/qquickwindow.h index 48878b057d..2d5b18dbcf 100644 --- a/src/quick/items/qquickwindow.h +++ b/src/quick/items/qquickwindow.h @@ -259,6 +259,7 @@ private Q_SLOTS: void setTransientParent_helper(QQuickWindow *window); void runJobsAfterSwap(); void handleApplicationStateChanged(Qt::ApplicationState state); + void handleFontDatabaseChanged(); private: #ifndef QT_NO_DEBUG_STREAM inline friend QQmlInfo operator<<(QQmlInfo info, const QQuickWindow *window) |