⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 283273 in webkit


Ignore:
Timestamp:
Sep 29, 2021, 4:04:52 PM (5 years ago)
Author:
Devin Rousso
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.

Location:
trunk/Source/WebCore
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r283271 r283273  
     12021-09-29  Devin Rousso  <drousso@apple.com>
     2
     3        Allow `DrawGlyphsRecorder` to be used with any `GraphicsContext` instead of just `DisplayList::Recorder`
     4        https://bugs.webkit.org/show_bug.cgi?id=230913
     5
     6        Reviewed by Myles Maxfield.
     7
     8        There's really nothing about `DrawGlyphsRecorder` that's specific to display lists other
     9        than it's currently only being used by `DisplayList::Recorder`.
     10
     11        This patch replaces `DisplayList::Recorder` with `GraphicsContext` in `DrawGlyphsRecorder`.
     12        It also requires that new methods be added to `GraphicsContext` that are overridden by
     13        `DisplayList::Recorder`. This is being done to make `<attachment>` drawing work in the
     14        GPUProcess (<https://webkit.org/b/230781>).
     15
     16        * platform/graphics/DrawGlyphsRecorder.h:
     17        * platform/graphics/coretext/DrawGlyphsRecorderCoreText.cpp:
     18        (WebCore::DrawGlyphsRecorder::DrawGlyphsRecorder):
     19        (WebCore::DrawGlyphsRecorder::populateInternalState):
     20        (WebCore::DrawGlyphsRecorder::prepareInternalContext):
     21        (WebCore::DrawGlyphsRecorder::recordDrawGlyphs):
     22        (WebCore::DrawGlyphsRecorder::drawGlyphs):
     23        * platform/graphics/harfbuzz/DrawGlyphsRecorderHarfBuzz.cpp:
     24        (WebCore::DrawGlyphsRecorder::DrawGlyphsRecorder):
     25        (WebCore::DrawGlyphsRecorder::drawGlyphs):
     26        * platform/graphics/win/DrawGlyphsRecorderWin.cpp:
     27        (WebCore::DrawGlyphsRecorder::DrawGlyphsRecorder):
     28        (WebCore::DrawGlyphsRecorder::drawGlyphs):
     29
     30        * platform/graphics/GraphicsContext.h:
     31        (WebCore::GraphicsContext::drawGlyphsAndCacheFont): Added.
     32        * platform/graphics/displaylists/DisplayListRecorder.h:
     33        * platform/graphics/displaylists/DisplayListRecorder.cpp:
     34        (WebCore::DisplayList::Recorder::state const): Added.
     35        (WebCore::DisplayList::Recorder::drawGlyphsAndCacheFont): Renamed from `appendDrawGlyphsItemWithCachedFont`.
     36        AFAICT it seems like the `m_state` in `GraphicsContext` has the same values (but is a
     37        different object) as the `currentState().stateChange.m_state` in `DisplayList::Recorder`.
     38        Many of the non-overriden methods on `GraphicsContext` (e.g. `setStrokeColor`) both modify
     39        the `m_state` and call `updateState`, which `DisplayList::Recorder` uses to modify its
     40        `currentState().stateChange.m_state`. As such, we should be able to expose it as an override
     41        for the `state` "getter" so that `DrawGlyphsRecorder` is able to access the current state in
     42        a `GraphicsContext`-subclass agnostic way.
     43
    1442021-09-29  Sihui Liu  <sihui_liu@apple.com>
    245
  • trunk/Source/WebCore/platform/graphics/DrawGlyphsRecorder.h

    r283199 r283273  
    4646class GraphicsContext;
    4747
    48 namespace DisplayList {
    49 class Recorder;
    50 }
    51 
    5248class DrawGlyphsRecorder {
    5349public:
     
    5652        DontDeconstruct
    5753    };
    58     explicit DrawGlyphsRecorder(DisplayList::Recorder&, DrawGlyphsDeconstruction);
     54    explicit DrawGlyphsRecorder(GraphicsContext&, DrawGlyphsDeconstruction);
    5955
    6056    void drawGlyphs(const Font&, const GlyphBufferGlyph*, const GlyphBufferAdvance*, unsigned numGlyphs, const FloatPoint& anchorPoint, FontSmoothingMode);
     
    9389#endif
    9490
    95     DisplayList::Recorder& m_owner;
     91    GraphicsContext& m_owner;
    9692    DrawGlyphsDeconstruction m_drawGlyphsDeconstruction;
    9793
  • trunk/Source/WebCore/platform/graphics/GraphicsContext.h

    r282723 r283273  
    354354#endif
    355355
    356     const GraphicsContextState& state() const { return m_state; }
     356    virtual const GraphicsContextState& state() const { return m_state; }
    357357
    358358    virtual void updateState(const GraphicsContextState&, GraphicsContextState::StateChangeFlags) = 0;
     
    470470    WEBCORE_EXPORT virtual void drawEmphasisMarks(const FontCascade&, const TextRun&, const AtomString& mark, const FloatPoint&, unsigned from = 0, std::optional<unsigned> to = std::nullopt);
    471471    WEBCORE_EXPORT virtual void drawBidiText(const FontCascade&, const TextRun&, const FloatPoint&, FontCascade::CustomFontNotReadyAction = FontCascade::DoNotPaintIfFontNotReady);
     472
     473    virtual void drawGlyphsAndCacheFont(const Font& font, const GlyphBufferGlyph* glyphs, const GlyphBufferAdvance* advances, unsigned numGlyphs, const FloatPoint& point, FontSmoothingMode fontSmoothingMode)
     474    {
     475        drawGlyphs(font, glyphs, advances, numGlyphs, point, fontSmoothingMode);
     476    }
    472477
    473478    WEBCORE_EXPORT FloatRect computeUnderlineBoundsForText(const FloatRect&, bool printing);
  • trunk/Source/WebCore/platform/graphics/coretext/DrawGlyphsRecorderCoreText.cpp

    r283199 r283273  
    2929#include "BitmapImage.h"
    3030#include "Color.h"
    31 #include "DisplayListItems.h"
    32 #include "DisplayListRecorder.h"
    3331#include "FloatPoint.h"
    3432#include "Font.h"
     
    8785}
    8886
    89 DrawGlyphsRecorder::DrawGlyphsRecorder(DisplayList::Recorder& owner, DrawGlyphsDeconstruction drawGlyphsDeconstruction)
     87DrawGlyphsRecorder::DrawGlyphsRecorder(GraphicsContext& owner, DrawGlyphsDeconstruction drawGlyphsDeconstruction)
    9088    : m_owner(owner)
    9189    , m_drawGlyphsDeconstruction(drawGlyphsDeconstruction)
     
    106104    m_originalState.strokeStyle.pattern = contextState.strokePattern;
    107105
    108     m_originalState.ctm = m_owner.currentState().ctm; // FIXME: Deal with base CTM.
     106    m_originalState.ctm = m_owner.getCTM(); // FIXME: Deal with base CTM.
    109107
    110108    m_originalState.shadow.offset = contextState.shadowOffset;
     
    157155        m_originalTextMatrix = computeVerticalTextMatrix(font, m_originalTextMatrix);
    158156
    159     auto& contextState = m_owner.currentState().stateChange.m_state;
     157    auto& contextState = m_owner.state();
    160158    populateInternalState(contextState);
    161159    populateInternalContext(contextState);
     
    336334    updateShadow(CGGStateGetStyle(gstate));
    337335
    338     m_owner.appendDrawGlyphsItemWithCachedFont(*m_originalFont, glyphs, computeAdvancesFromPositions(positions, count, currentTextMatrix).data(), count, currentTextMatrix.mapPoint(positions[0]), m_smoothingMode);
     336    m_owner.drawGlyphsAndCacheFont(*m_originalFont, glyphs, computeAdvancesFromPositions(positions, count, currentTextMatrix).data(), count, currentTextMatrix.mapPoint(positions[0]), m_smoothingMode);
    339337
    340338    m_owner.concatCTM(inverseCTMFixup);
     
    414412{
    415413    if (m_drawGlyphsDeconstruction == DrawGlyphsDeconstruction::DontDeconstruct) {
    416         m_owner.appendDrawGlyphsItemWithCachedFont(font, glyphs, advances, numGlyphs, startPoint, smoothingMode);
     414        m_owner.drawGlyphsAndCacheFont(font, glyphs, advances, numGlyphs, startPoint, smoothingMode);
    417415        return;
    418416    }
  • trunk/Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.cpp

    r280401 r283273  
    151151}
    152152
     153const GraphicsContextState& Recorder::state() const
     154{
     155    return currentState().stateChange.m_state;
     156}
     157
    153158void Recorder::updateState(const GraphicsContextState& state, GraphicsContextState::StateChangeFlags flags)
    154159{
     
    191196}
    192197
    193 void Recorder::appendDrawGlyphsItemWithCachedFont(const Font& font, const GlyphBufferGlyph* glyphs, const GlyphBufferAdvance* advances, unsigned count, const FloatPoint& localAnchor, FontSmoothingMode smoothingMode)
     198void Recorder::drawGlyphsAndCacheFont(const Font& font, const GlyphBufferGlyph* glyphs, const GlyphBufferAdvance* advances, unsigned count, const FloatPoint& localAnchor, FontSmoothingMode smoothingMode)
    194199{
    195200    if (m_delegate)
  • trunk/Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.h

    r283199 r283273  
    7878
    7979private:
    80     friend class WebCore::DrawGlyphsRecorder;
    8180    Recorder(Recorder& parent, const GraphicsContextState&, const FloatRect& initialClip, const AffineTransform& initialCTM);
    8281
     
    9594    void fillRoundedRectImpl(const FloatRoundedRect&, const Color&) final { ASSERT_NOT_REACHED(); }
    9695    void drawLineForText(const FloatRect&, bool, bool, StrokeStyle) final { ASSERT_NOT_REACHED(); }
     96
     97    const GraphicsContextState& state() const final;
    9798
    9899    void updateState(const GraphicsContextState&, GraphicsContextState::StateChangeFlags) final;
     
    122123
    123124    void drawGlyphs(const Font&, const GlyphBufferGlyph*, const GlyphBufferAdvance*, unsigned numGlyphs, const FloatPoint& anchorPoint, FontSmoothingMode) final;
    124 
    125     void appendDrawGlyphsItemWithCachedFont(const Font&, const GlyphBufferGlyph*, const GlyphBufferAdvance*, unsigned count, const FloatPoint& localAnchor, FontSmoothingMode);
     125    void drawGlyphsAndCacheFont(const Font&, const GlyphBufferGlyph*, const GlyphBufferAdvance*, unsigned count, const FloatPoint& localAnchor, FontSmoothingMode);
    126126
    127127    void drawImageBuffer(WebCore::ImageBuffer&, const FloatRect& destination, const FloatRect& source, const ImagePaintingOptions&) final;
  • trunk/Source/WebCore/platform/graphics/harfbuzz/DrawGlyphsRecorderHarfBuzz.cpp

    r283199 r283273  
    2727#include "DrawGlyphsRecorder.h"
    2828
    29 #include "DisplayListItems.h"
    30 #include "DisplayListRecorder.h"
    3129#include "FloatPoint.h"
    3230#include "Font.h"
     
    3533namespace WebCore {
    3634
    37 DrawGlyphsRecorder::DrawGlyphsRecorder(DisplayList::Recorder& owner, DrawGlyphsDeconstruction)
     35DrawGlyphsRecorder::DrawGlyphsRecorder(GraphicsContext& owner, DrawGlyphsDeconstruction)
    3836    : m_owner(owner)
    3937{
     
    4240void DrawGlyphsRecorder::drawGlyphs(const Font& font, const GlyphBufferGlyph* glyphs, const GlyphBufferAdvance* advances, unsigned numGlyphs, const FloatPoint& startPoint, FontSmoothingMode smoothingMode)
    4341{
    44     m_owner.appendDrawGlyphsItemWithCachedFont(font, glyphs, advances, numGlyphs, startPoint, smoothingMode);
     42    m_owner.drawGlyphsAndCacheFont(font, glyphs, advances, numGlyphs, startPoint, smoothingMode);
    4543}
    4644
  • trunk/Source/WebCore/platform/graphics/win/DrawGlyphsRecorderWin.cpp

    r283199 r283273  
    2727#include "DrawGlyphsRecorder.h"
    2828
    29 #include "DisplayListItems.h"
    30 #include "DisplayListRecorder.h"
    3129#include "FloatPoint.h"
    3230#include "Font.h"
     
    3533namespace WebCore {
    3634
    37 DrawGlyphsRecorder::DrawGlyphsRecorder(DisplayList::Recorder& owner, DrawGlyphsDeconstruction)
     35DrawGlyphsRecorder::DrawGlyphsRecorder(GraphicsContext& owner, DrawGlyphsDeconstruction)
    3836    : m_owner(owner)
    3937{
     
    4240void DrawGlyphsRecorder::drawGlyphs(const Font& font, const GlyphBufferGlyph* glyphs, const GlyphBufferAdvance* advances, unsigned numGlyphs, const FloatPoint& startPoint, FontSmoothingMode smoothingMode)
    4341{
    44     m_owner.appendDrawGlyphsItemWithCachedFont(font, glyphs, advances, numGlyphs, startPoint, m_smoothingMode);
     42    m_owner.drawGlyphsAndCacheFont(font, glyphs, advances, numGlyphs, startPoint, m_smoothingMode);
    4543}
    4644
Note: See TracChangeset for help on using the changeset viewer.