Title: [292026] trunk/Source/WebCore
Revision
292026
Author
[email protected]
Date
2022-03-29 02:43:07 -0700 (Tue, 29 Mar 2022)

Log Message

REGRESSION(r291771): [ iOS ] Text sometimes draw with incorrect color
https://bugs.webkit.org/show_bug.cgi?id=238466
rdar://90941790

Reviewed by Simon Fraser.

r291771 uncovers this bug: TextBoxPainter::paintForeground() records the
glyphs to a DisplayList before settings the destination GraphicsContext.

The fix is to apply all the changes to the GraphicsContext before calling
TextPainter::setGlyphDisplayListIfNeeded().

Delete TextPainter::paint() because it is not used.

Initialize TextPainter with a reference to FontCascade.

* rendering/TextBoxPainter.cpp:
(WebCore::TextBoxPainter::paintForeground):
* rendering/TextPainter.cpp:
(WebCore::TextPainter::TextPainter):
(WebCore::TextPainter::paintTextAndEmphasisMarksIfNeeded):
(WebCore::TextPainter::paintRange):
(WebCore::TextPainter::paint): Deleted.
* rendering/TextPainter.h:
(WebCore::TextPainter::setShadowColorFilter):
(WebCore::TextPainter::setGlyphDisplayListIfNeeded):
(WebCore::TextPainter::setFont): Deleted.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (292025 => 292026)


--- trunk/Source/WebCore/ChangeLog	2022-03-29 07:59:35 UTC (rev 292025)
+++ trunk/Source/WebCore/ChangeLog	2022-03-29 09:43:07 UTC (rev 292026)
@@ -1,3 +1,33 @@
+2022-03-29  Said Abou-Hallawa  <[email protected]>
+
+        REGRESSION(r291771): [ iOS ] Text sometimes draw with incorrect color
+        https://bugs.webkit.org/show_bug.cgi?id=238466
+        rdar://90941790
+
+        Reviewed by Simon Fraser.
+
+        r291771 uncovers this bug: TextBoxPainter::paintForeground() records the
+        glyphs to a DisplayList before settings the destination GraphicsContext.
+
+        The fix is to apply all the changes to the GraphicsContext before calling
+        TextPainter::setGlyphDisplayListIfNeeded().
+
+        Delete TextPainter::paint() because it is not used.
+
+        Initialize TextPainter with a reference to FontCascade.
+
+        * rendering/TextBoxPainter.cpp:
+        (WebCore::TextBoxPainter::paintForeground):
+        * rendering/TextPainter.cpp:
+        (WebCore::TextPainter::TextPainter):
+        (WebCore::TextPainter::paintTextAndEmphasisMarksIfNeeded):
+        (WebCore::TextPainter::paintRange):
+        (WebCore::TextPainter::paint): Deleted.
+        * rendering/TextPainter.h:
+        (WebCore::TextPainter::setShadowColorFilter):
+        (WebCore::TextPainter::setGlyphDisplayListIfNeeded):
+        (WebCore::TextPainter::setFont): Deleted.
+
 2022-03-29  Zan Dobersek  <[email protected]>
 
         [GTK][WPE] Use GBMBufferSwapchain in GraphicsContextGLTextureMapperANGLE

Modified: trunk/Source/WebCore/rendering/TextBoxPainter.cpp (292025 => 292026)


--- trunk/Source/WebCore/rendering/TextBoxPainter.cpp	2022-03-29 07:59:35 UTC (rev 292025)
+++ trunk/Source/WebCore/rendering/TextBoxPainter.cpp	2022-03-29 09:43:07 UTC (rev 292026)
@@ -324,8 +324,7 @@
     if (!emphasisMark.isEmpty())
         emphasisMarkOffset = *m_emphasisMarkExistsAndIsAbove ? -font.metricsOfPrimaryFont().ascent() - font.emphasisMarkDescent(emphasisMark) : font.metricsOfPrimaryFont().descent() + font.emphasisMarkAscent(emphasisMark);
 
-    TextPainter textPainter { context };
-    textPainter.setFont(font);
+    TextPainter textPainter { context, font };
     textPainter.setStyle(markedText.style.textStyles);
     textPainter.setIsHorizontal(textBox().isHorizontal());
     if (markedText.style.textShadow) {
@@ -337,18 +336,18 @@
     if (auto* debugShadow = debugTextShadow())
         textPainter.setShadow(debugShadow);
 
+    GraphicsContextStateSaver stateSaver(context, markedText.style.textStyles.strokeWidth > 0 || markedText.type == MarkedText::DraggedContent);
+    if (markedText.type == MarkedText::DraggedContent)
+        context.setAlpha(markedText.style.alpha);
+    updateGraphicsContext(context, markedText.style.textStyles);
+
     if (auto* legacyInlineBox = textBox().legacyInlineBox())
-        textPainter.setGlyphDisplayListIfNeeded(*legacyInlineBox, m_paintInfo, font, context, m_paintTextRun);
+        textPainter.setGlyphDisplayListIfNeeded(*legacyInlineBox, m_paintInfo, m_paintTextRun);
 #if ENABLE(LAYOUT_FORMATTING_CONTEXT)
     else
-        textPainter.setGlyphDisplayListIfNeeded(*textBox().inlineBox(), m_paintInfo, font, context, m_paintTextRun);
+        textPainter.setGlyphDisplayListIfNeeded(*textBox().inlineBox(), m_paintInfo, m_paintTextRun);
 #endif
 
-    GraphicsContextStateSaver stateSaver { context, false };
-    if (markedText.type == MarkedText::DraggedContent) {
-        stateSaver.save();
-        context.setAlpha(markedText.style.alpha);
-    }
     // TextPainter wants the box rectangle and text origin of the entire line box.
     textPainter.paintRange(m_paintTextRun, m_paintRect, textOriginFromPaintRect(m_paintRect), markedText.startOffset, markedText.endOffset);
 }

Modified: trunk/Source/WebCore/rendering/TextPainter.cpp (292025 => 292026)


--- trunk/Source/WebCore/rendering/TextPainter.cpp	2022-03-29 07:59:35 UTC (rev 292025)
+++ trunk/Source/WebCore/rendering/TextPainter.cpp	2022-03-29 09:43:07 UTC (rev 292026)
@@ -97,8 +97,9 @@
         m_context.clearShadow();
 }
 
-TextPainter::TextPainter(GraphicsContext& context)
+TextPainter::TextPainter(GraphicsContext& context, const FontCascade& font)
     : m_context(context)
+    , m_font(font)
 {
 }
 
@@ -159,7 +160,7 @@
 {
     if (paintStyle.paintOrder == PaintOrder::Normal) {
         // FIXME: Truncate right-to-left text correctly.
-        paintTextWithShadows(shadow, shadowColorFilter, *m_font, textRun, boxRect, textOrigin, startOffset, endOffset, nullAtom(), 0, paintStyle.strokeWidth > 0);
+        paintTextWithShadows(shadow, shadowColorFilter, m_font, textRun, boxRect, textOrigin, startOffset, endOffset, nullAtom(), 0, paintStyle.strokeWidth > 0);
     } else {
         auto textDrawingMode = m_context.textDrawingMode();
         auto paintOrder = RenderStyle::paintTypesForPaintOrder(paintStyle.paintOrder);
@@ -171,7 +172,7 @@
                 auto textDrawingModeWithoutStroke = textDrawingMode;
                 textDrawingModeWithoutStroke.remove(TextDrawingMode::Stroke);
                 m_context.setTextDrawingMode(textDrawingModeWithoutStroke);
-                paintTextWithShadows(shadowToUse, shadowColorFilter, *m_font, textRun, boxRect, textOrigin, startOffset, endOffset, nullAtom(), 0, false);
+                paintTextWithShadows(shadowToUse, shadowColorFilter, m_font, textRun, boxRect, textOrigin, startOffset, endOffset, nullAtom(), 0, false);
                 shadowToUse = nullptr;
                 m_context.setTextDrawingMode(textDrawingMode);
                 break;
@@ -180,7 +181,7 @@
                 auto textDrawingModeWithoutFill = textDrawingMode;
                 textDrawingModeWithoutFill.remove(TextDrawingMode::Fill);
                 m_context.setTextDrawingMode(textDrawingModeWithoutFill);
-                paintTextWithShadows(shadowToUse, shadowColorFilter, *m_font, textRun, boxRect, textOrigin, startOffset, endOffset, nullAtom(), 0, paintStyle.strokeWidth > 0);
+                paintTextWithShadows(shadowToUse, shadowColorFilter, m_font, textRun, boxRect, textOrigin, startOffset, endOffset, nullAtom(), 0, paintStyle.strokeWidth > 0);
                 shadowToUse = nullptr;
                 m_context.setTextDrawingMode(textDrawingMode);
             }
@@ -198,12 +199,12 @@
     updateGraphicsContext(m_context, paintStyle, UseEmphasisMarkColor);
     static NeverDestroyed<TextRun> objectReplacementCharacterTextRun(StringView(&objectReplacementCharacter, 1));
     const TextRun& emphasisMarkTextRun = m_combinedText ? objectReplacementCharacterTextRun.get() : textRun;
-    FloatPoint emphasisMarkTextOrigin = m_combinedText ? FloatPoint(boxOrigin.x() + boxRect.width() / 2, boxOrigin.y() + m_font->metricsOfPrimaryFont().ascent()) : textOrigin;
+    FloatPoint emphasisMarkTextOrigin = m_combinedText ? FloatPoint(boxOrigin.x() + boxRect.width() / 2, boxOrigin.y() + m_font.metricsOfPrimaryFont().ascent()) : textOrigin;
     if (m_combinedText)
         m_context.concatCTM(rotation(boxRect, Clockwise));
 
     // FIXME: Truncate right-to-left text correctly.
-    paintTextWithShadows(shadow, shadowColorFilter, m_combinedText ? m_combinedText->originalFont() : *m_font, emphasisMarkTextRun, boxRect, emphasisMarkTextOrigin, startOffset, endOffset,
+    paintTextWithShadows(shadow, shadowColorFilter, m_combinedText ? m_combinedText->originalFont() : m_font, emphasisMarkTextRun, boxRect, emphasisMarkTextOrigin, startOffset, endOffset,
         m_emphasisMark, m_emphasisMarkOffset, paintStyle.strokeWidth > 0);
 
     if (m_combinedText)
@@ -210,18 +211,9 @@
         m_context.concatCTM(rotation(boxRect, Counterclockwise));
 }
 
-void TextPainter::paint(const TextRun& textRun, const FloatRect& boxRect, const FloatPoint& textOrigin)
-{
-    paintRange(textRun, boxRect, textOrigin, 0, textRun.length());
-}
-
 void TextPainter::paintRange(const TextRun& textRun, const FloatRect& boxRect, const FloatPoint& textOrigin, unsigned start, unsigned end)
 {
-    ASSERT(m_font);
     ASSERT(start < end);
-
-    GraphicsContextStateSaver stateSaver(m_context, m_style.strokeWidth > 0);
-    updateGraphicsContext(m_context, m_style);
     paintTextAndEmphasisMarksIfNeeded(textRun, boxRect, textOrigin, start, end, m_style, m_shadow, m_shadowColorFilter);
 }
 

Modified: trunk/Source/WebCore/rendering/TextPainter.h (292025 => 292026)


--- trunk/Source/WebCore/rendering/TextPainter.h	2022-03-29 07:59:35 UTC (rev 292025)
+++ trunk/Source/WebCore/rendering/TextPainter.h	2022-03-29 09:43:07 UTC (rev 292026)
@@ -49,25 +49,23 @@
 
 class TextPainter {
 public:
-    TextPainter(GraphicsContext&);
+    TextPainter(GraphicsContext&, const FontCascade&);
 
     void setStyle(const TextPaintStyle& textPaintStyle) { m_style = textPaintStyle; }
     void setShadow(const ShadowData* shadow) { m_shadow = shadow; }
     void setShadowColorFilter(const FilterOperations* colorFilter) { m_shadowColorFilter = colorFilter; }
-    void setFont(const FontCascade& font) { m_font = &font; }
     void setIsHorizontal(bool isHorizontal) { m_textBoxIsHorizontal = isHorizontal; }
     void setEmphasisMark(const AtomString& mark, float offset, const RenderCombineText*);
 
-    void paint(const TextRun&, const FloatRect& boxRect, const FloatPoint& textOrigin);
     void paintRange(const TextRun&, const FloatRect& boxRect, const FloatPoint& textOrigin, unsigned start, unsigned end);
 
     template<typename LayoutRun>
-    void setGlyphDisplayListIfNeeded(const LayoutRun& run, const PaintInfo& paintInfo, const FontCascade& font, GraphicsContext& context, const TextRun& textRun)
+    void setGlyphDisplayListIfNeeded(const LayoutRun& run, const PaintInfo& paintInfo, const TextRun& textRun)
     {
         if (!TextPainter::shouldUseGlyphDisplayList(paintInfo))
             TextPainter::removeGlyphDisplayList(run);
         else
-            m_glyphDisplayList = GlyphDisplayListCache<LayoutRun>::singleton().get(run, font, context, textRun);
+            m_glyphDisplayList = GlyphDisplayListCache<LayoutRun>::singleton().get(run, m_font, m_context, textRun);
     }
 
     template<typename LayoutRun>
@@ -85,7 +83,7 @@
         const TextPaintStyle&, const ShadowData*, const FilterOperations*);
 
     GraphicsContext& m_context;
-    const FontCascade* m_font { nullptr };
+    const FontCascade& m_font;
     TextPaintStyle m_style;
     AtomString m_emphasisMark;
     const ShadowData* m_shadow { nullptr };
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to