From 97b85d8b7d52292f1587582d10c0f13d69ee8186 Mon Sep 17 00:00:00 2001 From: Jonathan Kew Date: Tue, 16 Apr 2024 20:10:51 +0000 Subject: [PATCH] Bug 1891630 - Avoid calling GetPathForGlyphs with a TextDrawTarget. r=gfx-reviewers,lsalzman Differential Revision: https://phabricator.services.mozilla.com/D207619 --- gfx/thebes/COLRFonts.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/gfx/thebes/COLRFonts.cpp b/gfx/thebes/COLRFonts.cpp index 6369bf191dc9..4a451f22d31c 100644 --- a/gfx/thebes/COLRFonts.cpp +++ b/gfx/thebes/COLRFonts.cpp @@ -1298,8 +1298,7 @@ struct PaintGlyph { // Core Text's own color font support may step in and ignore the // pattern. So to avoid this, fill the glyph as a path instead. #if XP_MACOSX - RefPtr path = - aState.mScaledFont->GetPathForGlyphs(buffer, aState.mDrawTarget); + RefPtr path = GetPathForGlyphs(aState, buffer); aState.mDrawTarget->Fill(path, *fillPattern, aState.mDrawOptions); #else aState.mDrawTarget->FillGlyphs(aState.mScaledFont, buffer, *fillPattern, @@ -1307,8 +1306,7 @@ struct PaintGlyph { #endif return true; } - RefPtr path = - aState.mScaledFont->GetPathForGlyphs(buffer, aState.mDrawTarget); + RefPtr path = GetPathForGlyphs(aState, buffer); aState.mDrawTarget->PushClip(path); bool ok = DispatchPaint(aState, aOffset + paintOffset, aBounds); aState.mDrawTarget->PopClip(); @@ -1319,10 +1317,19 @@ struct PaintGlyph { MOZ_ASSERT(format == kFormat); Glyph g{uint16_t(glyphID), Point()}; GlyphBuffer buffer{&g, 1}; - RefPtr path = - aState.mScaledFont->GetPathForGlyphs(buffer, aState.mDrawTarget); + RefPtr path = GetPathForGlyphs(aState, buffer); return path->GetFastBounds(); } + + private: + RefPtr GetPathForGlyphs(const PaintState& aState, + const GlyphBuffer& buffer) const { + if (aState.mDrawTarget->GetBackendType() == BackendType::WEBRENDER_TEXT) { + RefPtr dt = gfxPlatform::ThreadLocalScreenReferenceDrawTarget(); + return aState.mScaledFont->GetPathForGlyphs(buffer, dt); + } + return aState.mScaledFont->GetPathForGlyphs(buffer, aState.mDrawTarget); + } }; struct PaintColrGlyph {