From 49ab1b8756df3a2b6124a45873444afff7ed6215 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Mon, 20 Nov 2023 13:45:47 +0100 Subject: [PATCH] Fix cache cost on DirectWrite font engines In Qt 6, we deferred getting the ascent/descent of the font until requested. This was used to calculate the cache cost of the font engine, so as an unintended result, the DirectWrite engines were seen as extremely cheap in the font cache, and we would accumulate thousands of them before triggering a flush. The cache_cost is just a heuristic and does not need to be accurate. For most engines, we should just flush when the number of cached fonts exceed 256, so we use the basic em square of a lowercase letter as the cost here instead. Pick-to: 6.5 Change-Id: I73a65cab38adfd9ef56e436f311a7d1a2d7fbf41 Reviewed-by: Allan Sandfeld Jensen (cherry picked from commit db6f7908d01134eb2f20e9b2122d4d47456db6c9) Reviewed-by: Qt Cherry-pick Bot --- src/gui/text/windows/qwindowsfontenginedirectwrite.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/text/windows/qwindowsfontenginedirectwrite.cpp b/src/gui/text/windows/qwindowsfontenginedirectwrite.cpp index 24417ac79e8..4829d6760de 100644 --- a/src/gui/text/windows/qwindowsfontenginedirectwrite.cpp +++ b/src/gui/text/windows/qwindowsfontenginedirectwrite.cpp @@ -212,7 +212,7 @@ QWindowsFontEngineDirectWrite::QWindowsFontEngineDirectWrite(IDWriteFontFace *di fontDef.pixelSize = pixelSize; collectMetrics(); - cache_cost = (m_ascent.toInt() + m_descent.toInt()) * m_xHeight.toInt() * 2000; + cache_cost = m_xHeight.toInt() * m_xHeight.toInt() * 2000; } QWindowsFontEngineDirectWrite::~QWindowsFontEngineDirectWrite()