Title: [283273] trunk/Source/WebCore
Revision
283273
Author
[email protected]
Date
2021-09-29 16:04:52 -0700 (Wed, 29 Sep 2021)

Log Message

Allow `DrawGlyphsRecorder` to be used with any `GraphicsContext` instead of just `DisplayList::Recorder`
https://bugs.webkit.org/show_bug.cgi?id=230913

Reviewed by Myles Maxfield.

There's really nothing about `DrawGlyphsRecorder` that's specific to display lists other
than it's currently only being used by `DisplayList::Recorder`.

This patch replaces `DisplayList::Recorder` with `GraphicsContext` in `DrawGlyphsRecorder`.
It also requires that new methods be added to `GraphicsContext` that are overridden by
`DisplayList::Recorder`. This is being done to make `<attachment>` drawing work in the
GPUProcess (<https://webkit.org/b/230781>).

* platform/graphics/DrawGlyphsRecorder.h:
* platform/graphics/coretext/DrawGlyphsRecorderCoreText.cpp:
(WebCore::DrawGlyphsRecorder::DrawGlyphsRecorder):
(WebCore::DrawGlyphsRecorder::populateInternalState):
(WebCore::DrawGlyphsRecorder::prepareInternalContext):
(WebCore::DrawGlyphsRecorder::recordDrawGlyphs):
(WebCore::DrawGlyphsRecorder::drawGlyphs):
* platform/graphics/harfbuzz/DrawGlyphsRecorderHarfBuzz.cpp:
(WebCore::DrawGlyphsRecorder::DrawGlyphsRecorder):
(WebCore::DrawGlyphsRecorder::drawGlyphs):
* platform/graphics/win/DrawGlyphsRecorderWin.cpp:
(WebCore::DrawGlyphsRecorder::DrawGlyphsRecorder):
(WebCore::DrawGlyphsRecorder::drawGlyphs):

* platform/graphics/GraphicsContext.h:
(WebCore::GraphicsContext::drawGlyphsAndCacheFont): Added.
* platform/graphics/displaylists/DisplayListRecorder.h:
* platform/graphics/displaylists/DisplayListRecorder.cpp:
(WebCore::DisplayList::Recorder::state const): Added.
(WebCore::DisplayList::Recorder::drawGlyphsAndCacheFont): Renamed from `appendDrawGlyphsItemWithCachedFont`.
AFAICT it seems like the `m_state` in `GraphicsContext` has the same values (but is a
different object) as the `currentState().stateChange.m_state` in `DisplayList::Recorder`.
Many of the non-overriden methods on `GraphicsContext` (e.g. `setStrokeColor`) both modify
the `m_state` and call `updateState`, which `DisplayList::Recorder` uses to modify its
`currentState().stateChange.m_state`. As such, we should be able to expose it as an override
for the `state` "getter" so that `DrawGlyphsRecorder` is able to access the current state in
a `GraphicsContext`-subclass agnostic way.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (283272 => 283273)


--- trunk/Source/WebCore/ChangeLog	2021-09-29 23:02:43 UTC (rev 283272)
+++ trunk/Source/WebCore/ChangeLog	2021-09-29 23:04:52 UTC (rev 283273)
@@ -1,3 +1,46 @@
+2021-09-29  Devin Rousso  <[email protected]>
+
+        Allow `DrawGlyphsRecorder` to be used with any `GraphicsContext` instead of just `DisplayList::Recorder`
+        https://bugs.webkit.org/show_bug.cgi?id=230913
+
+        Reviewed by Myles Maxfield.
+
+        There's really nothing about `DrawGlyphsRecorder` that's specific to display lists other
+        than it's currently only being used by `DisplayList::Recorder`.
+
+        This patch replaces `DisplayList::Recorder` with `GraphicsContext` in `DrawGlyphsRecorder`.
+        It also requires that new methods be added to `GraphicsContext` that are overridden by
+        `DisplayList::Recorder`. This is being done to make `<attachment>` drawing work in the
+        GPUProcess (<https://webkit.org/b/230781>).
+
+        * platform/graphics/DrawGlyphsRecorder.h:
+        * platform/graphics/coretext/DrawGlyphsRecorderCoreText.cpp:
+        (WebCore::DrawGlyphsRecorder::DrawGlyphsRecorder):
+        (WebCore::DrawGlyphsRecorder::populateInternalState):
+        (WebCore::DrawGlyphsRecorder::prepareInternalContext):
+        (WebCore::DrawGlyphsRecorder::recordDrawGlyphs):
+        (WebCore::DrawGlyphsRecorder::drawGlyphs):
+        * platform/graphics/harfbuzz/DrawGlyphsRecorderHarfBuzz.cpp:
+        (WebCore::DrawGlyphsRecorder::DrawGlyphsRecorder):
+        (WebCore::DrawGlyphsRecorder::drawGlyphs):
+        * platform/graphics/win/DrawGlyphsRecorderWin.cpp:
+        (WebCore::DrawGlyphsRecorder::DrawGlyphsRecorder):
+        (WebCore::DrawGlyphsRecorder::drawGlyphs):
+
+        * platform/graphics/GraphicsContext.h:
+        (WebCore::GraphicsContext::drawGlyphsAndCacheFont): Added.
+        * platform/graphics/displaylists/DisplayListRecorder.h:
+        * platform/graphics/displaylists/DisplayListRecorder.cpp:
+        (WebCore::DisplayList::Recorder::state const): Added.
+        (WebCore::DisplayList::Recorder::drawGlyphsAndCacheFont): Renamed from `appendDrawGlyphsItemWithCachedFont`.
+        AFAICT it seems like the `m_state` in `GraphicsContext` has the same values (but is a
+        different object) as the `currentState().stateChange.m_state` in `DisplayList::Recorder`.
+        Many of the non-overriden methods on `GraphicsContext` (e.g. `setStrokeColor`) both modify
+        the `m_state` and call `updateState`, which `DisplayList::Recorder` uses to modify its
+        `currentState().stateChange.m_state`. As such, we should be able to expose it as an override
+        for the `state` "getter" so that `DrawGlyphsRecorder` is able to access the current state in
+        a `GraphicsContext`-subclass agnostic way.
+
 2021-09-29  Sihui Liu  <[email protected]>
 
         Replace FileSystemHandleImpl with FileSystemStorageConnection

Modified: trunk/Source/WebCore/platform/graphics/DrawGlyphsRecorder.h (283272 => 283273)


--- trunk/Source/WebCore/platform/graphics/DrawGlyphsRecorder.h	2021-09-29 23:02:43 UTC (rev 283272)
+++ trunk/Source/WebCore/platform/graphics/DrawGlyphsRecorder.h	2021-09-29 23:04:52 UTC (rev 283273)
@@ -45,10 +45,6 @@
 class GlyphBuffer;
 class GraphicsContext;
 
-namespace DisplayList {
-class Recorder;
-}
-
 class DrawGlyphsRecorder {
 public:
     enum class DrawGlyphsDeconstruction {
@@ -55,7 +51,7 @@
         Deconstruct,
         DontDeconstruct
     };
-    explicit DrawGlyphsRecorder(DisplayList::Recorder&, DrawGlyphsDeconstruction);
+    explicit DrawGlyphsRecorder(GraphicsContext&, DrawGlyphsDeconstruction);
 
     void drawGlyphs(const Font&, const GlyphBufferGlyph*, const GlyphBufferAdvance*, unsigned numGlyphs, const FloatPoint& anchorPoint, FontSmoothingMode);
 
@@ -92,7 +88,7 @@
     void updateShadow(CGStyleRef);
 #endif
 
-    DisplayList::Recorder& m_owner;
+    GraphicsContext& m_owner;
     DrawGlyphsDeconstruction m_drawGlyphsDeconstruction;
 
 #if USE(CORE_TEXT) && !PLATFORM(WIN)

Modified: trunk/Source/WebCore/platform/graphics/GraphicsContext.h (283272 => 283273)


--- trunk/Source/WebCore/platform/graphics/GraphicsContext.h	2021-09-29 23:02:43 UTC (rev 283272)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContext.h	2021-09-29 23:04:52 UTC (rev 283273)
@@ -353,7 +353,7 @@
     bool useDarkAppearance() const { return m_state.useDarkAppearance; }
 #endif
 
-    const GraphicsContextState& state() const { return m_state; }
+    virtual const GraphicsContextState& state() const { return m_state; }
 
     virtual void updateState(const GraphicsContextState&, GraphicsContextState::StateChangeFlags) = 0;
 
@@ -470,6 +470,11 @@
     WEBCORE_EXPORT virtual void drawEmphasisMarks(const FontCascade&, const TextRun&, const AtomString& mark, const FloatPoint&, unsigned from = 0, std::optional<unsigned> to = std::nullopt);
     WEBCORE_EXPORT virtual void drawBidiText(const FontCascade&, const TextRun&, const FloatPoint&, FontCascade::CustomFontNotReadyAction = FontCascade::DoNotPaintIfFontNotReady);
 
+    virtual void drawGlyphsAndCacheFont(const Font& font, const GlyphBufferGlyph* glyphs, const GlyphBufferAdvance* advances, unsigned numGlyphs, const FloatPoint& point, FontSmoothingMode fontSmoothingMode)
+    {
+        drawGlyphs(font, glyphs, advances, numGlyphs, point, fontSmoothingMode);
+    }
+
     WEBCORE_EXPORT FloatRect computeUnderlineBoundsForText(const FloatRect&, bool printing);
     WEBCORE_EXPORT virtual void drawLineForText(const FloatRect&, bool printing, bool doubleLines = false, StrokeStyle = SolidStroke);
     virtual void drawLinesForText(const FloatPoint&, float thickness, const DashArray& widths, bool printing, bool doubleLines = false, StrokeStyle = SolidStroke) = 0;

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


--- trunk/Source/WebCore/platform/graphics/coretext/DrawGlyphsRecorderCoreText.cpp	2021-09-29 23:02:43 UTC (rev 283272)
+++ trunk/Source/WebCore/platform/graphics/coretext/DrawGlyphsRecorderCoreText.cpp	2021-09-29 23:04:52 UTC (rev 283273)
@@ -28,8 +28,6 @@
 
 #include "BitmapImage.h"
 #include "Color.h"
-#include "DisplayListItems.h"
-#include "DisplayListRecorder.h"
 #include "FloatPoint.h"
 #include "Font.h"
 #include "FontCascade.h"
@@ -86,7 +84,7 @@
     return makeUniqueRef<GraphicsContextCG>(context.get());
 }
 
-DrawGlyphsRecorder::DrawGlyphsRecorder(DisplayList::Recorder& owner, DrawGlyphsDeconstruction drawGlyphsDeconstruction)
+DrawGlyphsRecorder::DrawGlyphsRecorder(GraphicsContext& owner, DrawGlyphsDeconstruction drawGlyphsDeconstruction)
     : m_owner(owner)
     , m_drawGlyphsDeconstruction(drawGlyphsDeconstruction)
     , m_internalContext(createInternalContext())
@@ -105,7 +103,7 @@
     m_originalState.strokeStyle.gradientSpaceTransform = contextState.strokeGradientSpaceTransform;
     m_originalState.strokeStyle.pattern = contextState.strokePattern;
 
-    m_originalState.ctm = m_owner.currentState().ctm; // FIXME: Deal with base CTM.
+    m_originalState.ctm = m_owner.getCTM(); // FIXME: Deal with base CTM.
 
     m_originalState.shadow.offset = contextState.shadowOffset;
     m_originalState.shadow.blur = contextState.shadowBlur;
@@ -156,7 +154,7 @@
     if (font.platformData().orientation() == FontOrientation::Vertical)
         m_originalTextMatrix = computeVerticalTextMatrix(font, m_originalTextMatrix);
 
-    auto& contextState = m_owner.currentState().stateChange.m_state;
+    auto& contextState = m_owner.state();
     populateInternalState(contextState);
     populateInternalContext(contextState);
 }
@@ -335,7 +333,7 @@
     updateStrokeColor(Color::createAndPreserveColorSpace(strokeColor));
     updateShadow(CGGStateGetStyle(gstate));
 
-    m_owner.appendDrawGlyphsItemWithCachedFont(*m_originalFont, glyphs, computeAdvancesFromPositions(positions, count, currentTextMatrix).data(), count, currentTextMatrix.mapPoint(positions[0]), m_smoothingMode);
+    m_owner.drawGlyphsAndCacheFont(*m_originalFont, glyphs, computeAdvancesFromPositions(positions, count, currentTextMatrix).data(), count, currentTextMatrix.mapPoint(positions[0]), m_smoothingMode);
 
     m_owner.concatCTM(inverseCTMFixup);
 }
@@ -413,7 +411,7 @@
 void DrawGlyphsRecorder::drawGlyphs(const Font& font, const GlyphBufferGlyph* glyphs, const GlyphBufferAdvance* advances, unsigned numGlyphs, const FloatPoint& startPoint, FontSmoothingMode smoothingMode)
 {
     if (m_drawGlyphsDeconstruction == DrawGlyphsDeconstruction::DontDeconstruct) {
-        m_owner.appendDrawGlyphsItemWithCachedFont(font, glyphs, advances, numGlyphs, startPoint, smoothingMode);
+        m_owner.drawGlyphsAndCacheFont(font, glyphs, advances, numGlyphs, startPoint, smoothingMode);
         return;
     }
 

Modified: trunk/Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.cpp (283272 => 283273)


--- trunk/Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.cpp	2021-09-29 23:02:43 UTC (rev 283272)
+++ trunk/Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.cpp	2021-09-29 23:04:52 UTC (rev 283273)
@@ -150,6 +150,11 @@
     currentState().lastDrawingState = stateChanges.m_state;
 }
 
+const GraphicsContextState& Recorder::state() const
+{
+    return currentState().stateChange.m_state;
+}
+
 void Recorder::updateState(const GraphicsContextState& state, GraphicsContextState::StateChangeFlags flags)
 {
     currentState().stateChange.accumulate(state, flags);
@@ -190,7 +195,7 @@
     m_drawGlyphsRecorder.drawGlyphs(font, glyphs, advances, numGlyphs, startPoint, smoothingMode);
 }
 
-void Recorder::appendDrawGlyphsItemWithCachedFont(const Font& font, const GlyphBufferGlyph* glyphs, const GlyphBufferAdvance* advances, unsigned count, const FloatPoint& localAnchor, FontSmoothingMode smoothingMode)
+void Recorder::drawGlyphsAndCacheFont(const Font& font, const GlyphBufferGlyph* glyphs, const GlyphBufferAdvance* advances, unsigned count, const FloatPoint& localAnchor, FontSmoothingMode smoothingMode)
 {
     if (m_delegate)
         m_delegate->recordFontUse(const_cast<Font&>(font));

Modified: trunk/Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.h (283272 => 283273)


--- trunk/Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.h	2021-09-29 23:02:43 UTC (rev 283272)
+++ trunk/Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.h	2021-09-29 23:04:52 UTC (rev 283273)
@@ -77,7 +77,6 @@
     void flushContext(FlushIdentifier identifier) { append<FlushContext>(identifier); }
 
 private:
-    friend class WebCore::DrawGlyphsRecorder;
     Recorder(Recorder& parent, const GraphicsContextState&, const FloatRect& initialClip, const AffineTransform& initialCTM);
 
     bool hasPlatformContext() const final { return false; }
@@ -95,6 +94,8 @@
     void fillRoundedRectImpl(const FloatRoundedRect&, const Color&) final { ASSERT_NOT_REACHED(); }
     void drawLineForText(const FloatRect&, bool, bool, StrokeStyle) final { ASSERT_NOT_REACHED(); }
 
+    const GraphicsContextState& state() const final;
+
     void updateState(const GraphicsContextState&, GraphicsContextState::StateChangeFlags) final;
 
     void setLineCap(LineCap) final;
@@ -121,9 +122,8 @@
 #endif
 
     void drawGlyphs(const Font&, const GlyphBufferGlyph*, const GlyphBufferAdvance*, unsigned numGlyphs, const FloatPoint& anchorPoint, FontSmoothingMode) final;
+    void drawGlyphsAndCacheFont(const Font&, const GlyphBufferGlyph*, const GlyphBufferAdvance*, unsigned count, const FloatPoint& localAnchor, FontSmoothingMode);
 
-    void appendDrawGlyphsItemWithCachedFont(const Font&, const GlyphBufferGlyph*, const GlyphBufferAdvance*, unsigned count, const FloatPoint& localAnchor, FontSmoothingMode);
-
     void drawImageBuffer(WebCore::ImageBuffer&, const FloatRect& destination, const FloatRect& source, const ImagePaintingOptions&) final;
     void drawNativeImage(NativeImage&, const FloatSize& imageSize, const FloatRect& destRect, const FloatRect& srcRect, const ImagePaintingOptions&) final;
     void drawPattern(NativeImage&, const FloatSize& imageSize, const FloatRect& destRect, const FloatRect& srcRect, const AffineTransform&, const FloatPoint& phase, const FloatSize& spacing, const ImagePaintingOptions&) final;

Modified: trunk/Source/WebCore/platform/graphics/harfbuzz/DrawGlyphsRecorderHarfBuzz.cpp (283272 => 283273)


--- trunk/Source/WebCore/platform/graphics/harfbuzz/DrawGlyphsRecorderHarfBuzz.cpp	2021-09-29 23:02:43 UTC (rev 283272)
+++ trunk/Source/WebCore/platform/graphics/harfbuzz/DrawGlyphsRecorderHarfBuzz.cpp	2021-09-29 23:04:52 UTC (rev 283273)
@@ -26,8 +26,6 @@
 #include "config.h"
 #include "DrawGlyphsRecorder.h"
 
-#include "DisplayListItems.h"
-#include "DisplayListRecorder.h"
 #include "FloatPoint.h"
 #include "Font.h"
 #include "GlyphBuffer.h"
@@ -34,7 +32,7 @@
 
 namespace WebCore {
 
-DrawGlyphsRecorder::DrawGlyphsRecorder(DisplayList::Recorder& owner, DrawGlyphsDeconstruction)
+DrawGlyphsRecorder::DrawGlyphsRecorder(GraphicsContext& owner, DrawGlyphsDeconstruction)
     : m_owner(owner)
 {
 }
@@ -41,7 +39,7 @@
 
 void DrawGlyphsRecorder::drawGlyphs(const Font& font, const GlyphBufferGlyph* glyphs, const GlyphBufferAdvance* advances, unsigned numGlyphs, const FloatPoint& startPoint, FontSmoothingMode smoothingMode)
 {
-    m_owner.appendDrawGlyphsItemWithCachedFont(font, glyphs, advances, numGlyphs, startPoint, smoothingMode);
+    m_owner.drawGlyphsAndCacheFont(font, glyphs, advances, numGlyphs, startPoint, smoothingMode);
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/graphics/win/DrawGlyphsRecorderWin.cpp (283272 => 283273)


--- trunk/Source/WebCore/platform/graphics/win/DrawGlyphsRecorderWin.cpp	2021-09-29 23:02:43 UTC (rev 283272)
+++ trunk/Source/WebCore/platform/graphics/win/DrawGlyphsRecorderWin.cpp	2021-09-29 23:04:52 UTC (rev 283273)
@@ -26,8 +26,6 @@
 #include "config.h"
 #include "DrawGlyphsRecorder.h"
 
-#include "DisplayListItems.h"
-#include "DisplayListRecorder.h"
 #include "FloatPoint.h"
 #include "Font.h"
 #include "GlyphBuffer.h"
@@ -34,7 +32,7 @@
 
 namespace WebCore {
 
-DrawGlyphsRecorder::DrawGlyphsRecorder(DisplayList::Recorder& owner, DrawGlyphsDeconstruction)
+DrawGlyphsRecorder::DrawGlyphsRecorder(GraphicsContext& owner, DrawGlyphsDeconstruction)
     : m_owner(owner)
 {
 }
@@ -41,7 +39,7 @@
 
 void DrawGlyphsRecorder::drawGlyphs(const Font& font, const GlyphBufferGlyph* glyphs, const GlyphBufferAdvance* advances, unsigned numGlyphs, const FloatPoint& startPoint, FontSmoothingMode smoothingMode)
 {
-    m_owner.appendDrawGlyphsItemWithCachedFont(font, glyphs, advances, numGlyphs, startPoint, m_smoothingMode);
+    m_owner.drawGlyphsAndCacheFont(font, glyphs, advances, numGlyphs, startPoint, m_smoothingMode);
 }
 
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to