Title: [293867] trunk/Source/WebCore
Revision
293867
Author
[email protected]
Date
2022-05-05 16:15:31 -0700 (Thu, 05 May 2022)

Log Message

Avoid using WebCore::Colors created with out-of-line components in DrawGlyphsRecorder
https://bugs.webkit.org/show_bug.cgi?id=235604
rdar://88345680

Reviewed by Simon Fraser.

Source/WebCore:

In DrawGlyphsRecorder::recordDrawGlyphs we interrogate the CGContext's
state to find out the current fill and stroke color. This needed to
record color font glyphs correctly. When we're not using a color font,
the CGColors for the fill and stroke will be the same as we set them
in prepareInternalContext.

Those CGColors we create in prepareInternalContext from the
WebCore::Colors (created by calling cachedCGColor) don't record the
exact form the original colors had. CGColors only expose float
components, so Color::createAndPreserveColorSpace conservatively
creates a Color with out-of-line components to store those float
values, even if the original Color the CGColor was created from had
uint8_t components.

Color::operator== treats colors of different forms as being different,
which means we generate additional, unnecessary SetState display list
items changing say the fill color from Color(255, 255, 255) (inline) to
Color(1.0, 1.0, 1.0) (out of line).

We can avoid this by checking whether the context state's fill and
stroke CGColors are the same object as the ones we set in
prepareInternalContext, and if so, set the current fill/stroke brush
based on m_originalState.fillBrush/strokeBrush. In the common case of
a non-color glyph, this brush change will be detected as the same as
the current value, and the SetState item generation will be avoided.

This improves the MotionMark design subtest by 2.4%, and the overall
score by 0.7%, when GPUP DOM rendering is enabled.

* platform/graphics/DrawGlyphsRecorder.h:
* platform/graphics/coretext/DrawGlyphsRecorderCoreText.cpp:
(WebCore::DrawGlyphsRecorder::recordInitialColors):
(WebCore::DrawGlyphsRecorder::prepareInternalContext):
(WebCore::DrawGlyphsRecorder::updateFillColor):
(WebCore::DrawGlyphsRecorder::updateStrokeColor):

Source/WebCore/PAL:

* pal/spi/cg/CoreGraphicsSPI.h: Add CGContextGetStrokeColorAsColor.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (293866 => 293867)


--- trunk/Source/WebCore/ChangeLog	2022-05-05 23:11:30 UTC (rev 293866)
+++ trunk/Source/WebCore/ChangeLog	2022-05-05 23:15:31 UTC (rev 293867)
@@ -1,3 +1,47 @@
+2022-05-05  Cameron McCormack  <[email protected]>
+
+        Avoid using WebCore::Colors created with out-of-line components in DrawGlyphsRecorder
+        https://bugs.webkit.org/show_bug.cgi?id=235604
+        rdar://88345680
+
+        Reviewed by Simon Fraser.
+
+        In DrawGlyphsRecorder::recordDrawGlyphs we interrogate the CGContext's
+        state to find out the current fill and stroke color. This needed to
+        record color font glyphs correctly. When we're not using a color font,
+        the CGColors for the fill and stroke will be the same as we set them
+        in prepareInternalContext.
+
+        Those CGColors we create in prepareInternalContext from the
+        WebCore::Colors (created by calling cachedCGColor) don't record the
+        exact form the original colors had. CGColors only expose float
+        components, so Color::createAndPreserveColorSpace conservatively
+        creates a Color with out-of-line components to store those float
+        values, even if the original Color the CGColor was created from had
+        uint8_t components.
+
+        Color::operator== treats colors of different forms as being different,
+        which means we generate additional, unnecessary SetState display list
+        items changing say the fill color from Color(255, 255, 255) (inline) to
+        Color(1.0, 1.0, 1.0) (out of line).
+
+        We can avoid this by checking whether the context state's fill and
+        stroke CGColors are the same object as the ones we set in
+        prepareInternalContext, and if so, set the current fill/stroke brush
+        based on m_originalState.fillBrush/strokeBrush. In the common case of
+        a non-color glyph, this brush change will be detected as the same as
+        the current value, and the SetState item generation will be avoided.
+
+        This improves the MotionMark design subtest by 2.4%, and the overall
+        score by 0.7%, when GPUP DOM rendering is enabled.
+
+        * platform/graphics/DrawGlyphsRecorder.h:
+        * platform/graphics/coretext/DrawGlyphsRecorderCoreText.cpp:
+        (WebCore::DrawGlyphsRecorder::recordInitialColors):
+        (WebCore::DrawGlyphsRecorder::prepareInternalContext):
+        (WebCore::DrawGlyphsRecorder::updateFillColor):
+        (WebCore::DrawGlyphsRecorder::updateStrokeColor):
+
 2022-05-05  Brent Fulgham  <[email protected]>
 
         Remove abandoned WKPreference for AlwaysUseAcceleratedOverflowScroll

Modified: trunk/Source/WebCore/PAL/ChangeLog (293866 => 293867)


--- trunk/Source/WebCore/PAL/ChangeLog	2022-05-05 23:11:30 UTC (rev 293866)
+++ trunk/Source/WebCore/PAL/ChangeLog	2022-05-05 23:15:31 UTC (rev 293867)
@@ -1,3 +1,13 @@
+2022-05-05  Cameron McCormack  <[email protected]>
+
+        Avoid using WebCore::Colors created with out-of-line components in DrawGlyphsRecorder
+        https://bugs.webkit.org/show_bug.cgi?id=235604
+        rdar://88345680
+
+        Reviewed by Simon Fraser.
+
+        * pal/spi/cg/CoreGraphicsSPI.h: Add CGContextGetStrokeColorAsColor.
+
 2022-04-22  Alex Christensen  <[email protected]>
 
         Adjust SPI headers to fix build with non-internal SDK

Modified: trunk/Source/WebCore/PAL/pal/spi/cg/CoreGraphicsSPI.h (293866 => 293867)


--- trunk/Source/WebCore/PAL/pal/spi/cg/CoreGraphicsSPI.h	2022-05-05 23:11:30 UTC (rev 293866)
+++ trunk/Source/WebCore/PAL/pal/spi/cg/CoreGraphicsSPI.h	2022-05-05 23:15:31 UTC (rev 293867)
@@ -244,6 +244,7 @@
 CGAffineTransform CGContextGetBaseCTM(CGContextRef);
 CGCompositeOperation CGContextGetCompositeOperation(CGContextRef);
 CGColorRef CGContextGetFillColorAsColor(CGContextRef);
+CGColorRef CGContextGetStrokeColorAsColor(CGContextRef);
 CGFloat CGContextGetLineWidth(CGContextRef);
 bool CGContextGetShouldSmoothFonts(CGContextRef);
 bool CGContextGetShouldAntialias(CGContextRef);

Modified: trunk/Source/WebCore/platform/graphics/DrawGlyphsRecorder.h (293866 => 293867)


--- trunk/Source/WebCore/platform/graphics/DrawGlyphsRecorder.h	2022-05-05 23:11:30 UTC (rev 293866)
+++ trunk/Source/WebCore/platform/graphics/DrawGlyphsRecorder.h	2022-05-05 23:15:31 UTC (rev 293867)
@@ -84,6 +84,7 @@
     void populateInternalState(const GraphicsContextState&);
     void populateInternalContext(const GraphicsContextState&);
     void prepareInternalContext(const Font&, FontSmoothingMode);
+    void recordInitialColors();
     void concludeInternalContext();
 
     void updateFillBrush(const SourceBrush&);
@@ -122,6 +123,11 @@
         bool ignoreTransforms { false };
     };
     State m_originalState;
+
+#if USE(CORE_TEXT) && !PLATFORM(WIN)
+    RetainPtr<CGColorRef> m_initialFillColor;
+    RetainPtr<CGColorRef> m_initialStrokeColor;
+#endif
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/graphics/coretext/DrawGlyphsRecorderCoreText.cpp (293866 => 293867)


--- trunk/Source/WebCore/platform/graphics/coretext/DrawGlyphsRecorderCoreText.cpp	2022-05-05 23:11:30 UTC (rev 293866)
+++ trunk/Source/WebCore/platform/graphics/coretext/DrawGlyphsRecorderCoreText.cpp	2022-05-05 23:15:31 UTC (rev 293867)
@@ -122,6 +122,13 @@
     m_internalContext->setTextDrawingMode(contextState.textDrawingMode());
 }
 
+void DrawGlyphsRecorder::recordInitialColors()
+{
+    CGContextRef cgContext = m_internalContext->platformContext();
+    m_initialFillColor = CGContextGetFillColorAsColor(cgContext);
+    m_initialStrokeColor = CGContextGetStrokeColorAsColor(cgContext);
+}
+
 void DrawGlyphsRecorder::prepareInternalContext(const Font& font, FontSmoothingMode smoothingMode)
 {
     ASSERT(CGAffineTransformIsIdentity(CTFontGetMatrix(font.platformData().ctFont())));
@@ -136,6 +143,7 @@
     auto& contextState = m_owner.state();
     populateInternalState(contextState);
     populateInternalContext(contextState);
+    recordInitialColors();
 }
 
 void DrawGlyphsRecorder::concludeInternalContext()
@@ -152,7 +160,10 @@
         ASSERT(m_originalState.fillBrush.pattern());
         return;
     }
-    m_owner.setFillBrush(Color::createAndPreserveColorSpace(fillColor));
+    if (fillColor == m_initialFillColor)
+        m_owner.setFillBrush(m_originalState.fillBrush);
+    else
+        m_owner.setFillBrush(Color::createAndPreserveColorSpace(fillColor));
 }
 
 void DrawGlyphsRecorder::updateFillBrush(const SourceBrush& newBrush)
@@ -166,7 +177,10 @@
         ASSERT(m_originalState.strokeBrush.pattern());
         return;
     }
-    m_owner.setStrokeBrush(Color::createAndPreserveColorSpace(strokeColor));
+    if (strokeColor == m_initialStrokeColor)
+        m_owner.setStrokeBrush(m_originalState.strokeBrush);
+    else
+        m_owner.setStrokeBrush(Color::createAndPreserveColorSpace(strokeColor));
 }
 
 void DrawGlyphsRecorder::updateStrokeBrush(const SourceBrush& newBrush)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to