diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2021-10-01 12:31:11 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-10-01 15:01:52 +0000 |
commit | 84535d5136304c9b35a261e66743300680a35e8f (patch) | |
tree | 35cf250c77e6684d9c546e0af5f4cdcd79904e84 /src | |
parent | cb10cf1e437a4176b7f1f0e6150b77af5ae9ff43 (diff) |
QFontCache: don't start cleanup timer if we are not in the main thread
We can only start timers in threads started via QThread, and even then
we cannot assume that the thread runs an event loop. So only start the
timer when we are in the main thread.
Add a test that verifies that we don't get the warning message.
Change-Id: I40d7d9ff115720f9ecd3eedaebbade2643daf843
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 132d6d012701ce00a4ff82eae5b14e560632e893)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/text/qfont.cpp | 41 | ||||
-rw-r--r-- | src/gui/text/qfont_p.h | 1 |
2 files changed, 27 insertions, 15 deletions
diff --git a/src/gui/text/qfont.cpp b/src/gui/text/qfont.cpp index 194cccaed9..76ced18099 100644 --- a/src/gui/text/qfont.cpp +++ b/src/gui/text/qfont.cpp @@ -2878,7 +2878,10 @@ static QBasicAtomicInt font_cache_id = Q_BASIC_ATOMIC_INITIALIZER(0); QFontCache::QFontCache() : QObject(), total_cost(0), max_cost(min_cost), - current_timestamp(0), fast(false), timer_id(-1), + current_timestamp(0), fast(false), + autoClean(QGuiApplication::instance() + && (QGuiApplication::instance()->thread() == QThread::currentThread())), + timer_id(-1), m_id(font_cache_id.fetchAndAddRelaxed(1) + 1) { } @@ -3048,10 +3051,14 @@ void QFontCache::increaseCost(uint cost) if (total_cost > max_cost) { max_cost = total_cost; + if (!autoClean) + return; + if (timer_id == -1 || ! fast) { FC_DEBUG(" TIMER: starting fast timer (%d ms)", fast_timeout); - if (timer_id != -1) killTimer(timer_id); + if (timer_id != -1) + killTimer(timer_id); timer_id = startTimer(fast_timeout); fast = true; } @@ -3142,22 +3149,26 @@ void QFontCache::decreaseCache() FC_DEBUG(" after sweep, in use %u kb, total %u kb, max %u kb, new max %u kb", in_use_cost, total_cost, max_cost, new_max_cost); - if (new_max_cost == max_cost) { - if (fast) { - FC_DEBUG(" cannot shrink cache, slowing timer"); + if (autoClean) { + if (new_max_cost == max_cost) { + if (fast) { + FC_DEBUG(" cannot shrink cache, slowing timer"); - killTimer(timer_id); - timer_id = startTimer(slow_timeout); - fast = false; - } + if (timer_id != -1) { + killTimer(timer_id); + timer_id = startTimer(slow_timeout); + fast = false; + } - return; - } else if (! fast) { - FC_DEBUG(" dropping into passing gear"); + return; + } else if (! fast) { + FC_DEBUG(" dropping into passing gear"); - killTimer(timer_id); - timer_id = startTimer(fast_timeout); - fast = true; + if (timer_id != -1) + killTimer(timer_id); + timer_id = startTimer(fast_timeout); + fast = true; } + } } max_cost = new_max_cost; diff --git a/src/gui/text/qfont_p.h b/src/gui/text/qfont_p.h index f285111c4a..156ca4a5a5 100644 --- a/src/gui/text/qfont_p.h +++ b/src/gui/text/qfont_p.h @@ -295,6 +295,7 @@ private: uint total_cost, max_cost; uint current_timestamp; bool fast; + const bool autoClean; int timer_id; const int m_id; }; |