From: Zhiyi Zhang zzhang@codeweavers.com
Word 2016 queries a lot of font glyph bounding boxes and bitmaps with translation matrices. The result of these queries is not cached because the transform matrix is not the identity matrix. However, the translation offsets don't affect FreeType font operations at all, which can be verified in ft_matrix_from_dwrite_matrix() called by get_glyph_transform(). So these results with translation matrices can be cached as well. With this patch, Word 2016 stuttering is reduced significantly. --- dlls/dwrite/font.c | 10 ++++++++-- dlls/dwrite/freetype.c | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/dlls/dwrite/font.c b/dlls/dwrite/font.c index 9dce26a17c2..30078b85e1d 100644 --- a/dlls/dwrite/font.c +++ b/dlls/dwrite/font.c @@ -69,6 +69,12 @@ struct cache_entry unsigned int has_bitmap : 1; };
+/* Skip cache for transformed cases. Ignore dx and dy because FreeType doesn't actually use it */ +static BOOL skip_cache(const DWRITE_MATRIX *m) +{ + return m && (m->m11 != 1.0f || m->m12 != 0.0f || m->m21 != 0.0f || m->m22 != 1.0f); +} + static void fontface_release_cache_entry(struct cache_entry *entry) { free(entry->bitmap); @@ -161,7 +167,7 @@ void dwrite_fontface_get_glyph_bbox(IDWriteFontFace *iface, struct dwrite_glyphb
EnterCriticalSection(&fontface->cs); /* For now bypass cache for transformed cases. */ - if (bitmap->m && memcmp(bitmap->m, &identity, sizeof(*bitmap->m))) + if (skip_cache(bitmap->m)) { params.bbox = &bitmap->bbox; UNIX_CALL(get_glyph_bbox, ¶ms); @@ -210,7 +216,7 @@ static HRESULT dwrite_fontface_get_glyph_bitmap(struct dwrite_fontface *fontface
EnterCriticalSection(&fontface->cs); /* For now bypass cache for transformed cases. */ - if (memcmp(¶ms.m, &identity, sizeof(params.m))) + if (skip_cache(¶ms.m)) { UNIX_CALL(get_glyph_bitmap, ¶ms); } diff --git a/dlls/dwrite/freetype.c b/dlls/dwrite/freetype.c index 0caf2b03696..58acd46560e 100644 --- a/dlls/dwrite/freetype.c +++ b/dlls/dwrite/freetype.c @@ -515,7 +515,7 @@ static BOOL get_glyph_transform(unsigned int simulations, const DWRITE_MATRIX *m
/* Some fonts provide mostly bitmaps and very few outlines, for example for .notdef. Disable transform if that's the case. */ - if (!memcmp(m, &identity, sizeof(*m)) && !simulations) + if (m->m11 == 1.0f && m->m12 == 0.0f && m->m21 == 0.0f && m->m22 == 1.0f && !simulations) return FALSE;
if (simulations & DWRITE_FONT_SIMULATIONS_OBLIQUE)