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

Changeset 283339 in webkit


Ignore:
Timestamp:
Sep 30, 2021, 2:13:05 PM (5 years ago)
Author:
Devin Rousso
Message:

[iOS][GPU Process] support <attachment>
https://bugs.webkit.org/show_bug.cgi?id=230781
<rdar://problem/70884096>

Reviewed by Myles Maxfield.

Source/WebCore:

  • rendering/RenderThemeIOS.mm:

(WebCore::RenderAttachmentInfo::addLine):
(WebCore::RenderAttachmentInfo::buildWrappedLines):
(WebCore::RenderAttachmentInfo::buildSingleLine):
(WebCore::paintAttachmentText):
Instead of drawing directly into the GraphicsContext::platformContext (which will not be
valid in the WebProcess when DOM rendering happens in the GPUProcess), use DrawGlyphsRecorder
to "translate" native CTLineDraw into a sequence of actions from which a GraphicsContext
method can be derived, thereby hooking into and benefiting from existing GPUProcess support.

  • platform/graphics/DrawGlyphsRecorder.h:

(WebCore::DrawGlyphsRecorder::deconstructDrawGlyphs const): Renamed from drawGlyphsDeconstruction.

  • platform/graphics/coretext/DrawGlyphsRecorderCoreText.cpp:

(WebCore::DrawGlyphsRecorder::DrawGlyphsRecorder):
(WebCore::DrawGlyphsRecorder::recordDrawGlyphs):
(WebCore::DrawGlyphsRecorder::drawGlyphs):
(WebCore::DrawGlyphsRecorder::drawNativeText):

  • platform/graphics/displaylists/DisplayListRecorder.cpp:
  • platform/graphics/harfbuzz/DrawGlyphsRecorderHarfBuzz.cpp:

(WebCore::DrawGlyphsRecorder::DrawGlyphsRecorder):

  • platform/graphics/win/DrawGlyphsRecorderWin.cpp:

(WebCore::DrawGlyphsRecorder::DrawGlyphsRecorder):
Add a new parameter to DrawGlyphsRenderer that controls whether fonts other than the one
initially provided to drawGlyphs/drawNativeText can be used to draw glyphs. This is only
used by the above as we know that the initial font is a system font, and therefore that the
fallback list will also only contain system fonts, meaning that sending the font to the
GPUProcess is cheap (a file path instead of actual data).

(WebCore::DisplayList::Recorder::Recorder):

  • platform/graphics/displaylists/DisplayListRecorder.h:
  • platform/graphics/FontCascade.cpp:

(WebCore::FontCascade::displayListForTextRun const):
Drive-by: Rename DrawGlyphsDeconstruction to DeconstructDrawGlyphs as it reads better.

Source/WebCore/PAL:

  • pal/spi/cg/CoreGraphicsSPI.h:
Location:
trunk/Source/WebCore
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r283335 r283339  
     12021-09-30  Devin Rousso  <drousso@apple.com>
     2
     3        [iOS][GPU Process] support `<attachment>`
     4        https://bugs.webkit.org/show_bug.cgi?id=230781
     5        <rdar://problem/70884096>
     6
     7        Reviewed by Myles Maxfield.
     8
     9        * rendering/RenderThemeIOS.mm:
     10        (WebCore::RenderAttachmentInfo::addLine):
     11        (WebCore::RenderAttachmentInfo::buildWrappedLines):
     12        (WebCore::RenderAttachmentInfo::buildSingleLine):
     13        (WebCore::paintAttachmentText):
     14        Instead of drawing directly into the `GraphicsContext::platformContext` (which will not be
     15        valid in the WebProcess when DOM rendering happens in the GPUProcess), use `DrawGlyphsRecorder`
     16        to "translate" native `CTLineDraw` into a sequence of actions from which a `GraphicsContext`
     17        method can be derived, thereby hooking into and benefiting from existing GPUProcess support.
     18
     19        * platform/graphics/DrawGlyphsRecorder.h:
     20        (WebCore::DrawGlyphsRecorder::deconstructDrawGlyphs const): Renamed from `drawGlyphsDeconstruction`.
     21        * platform/graphics/coretext/DrawGlyphsRecorderCoreText.cpp:
     22        (WebCore::DrawGlyphsRecorder::DrawGlyphsRecorder):
     23        (WebCore::DrawGlyphsRecorder::recordDrawGlyphs):
     24        (WebCore::DrawGlyphsRecorder::drawGlyphs):
     25        (WebCore::DrawGlyphsRecorder::drawNativeText):
     26        * platform/graphics/displaylists/DisplayListRecorder.cpp:
     27        * platform/graphics/harfbuzz/DrawGlyphsRecorderHarfBuzz.cpp:
     28        (WebCore::DrawGlyphsRecorder::DrawGlyphsRecorder):
     29        * platform/graphics/win/DrawGlyphsRecorderWin.cpp:
     30        (WebCore::DrawGlyphsRecorder::DrawGlyphsRecorder):
     31        Add a new parameter to `DrawGlyphsRenderer` that controls whether fonts other than the one
     32        initially provided to `drawGlyphs`/`drawNativeText` can be used to draw glyphs. This is only
     33        used by the above as we know that the initial font is a system font, and therefore that the
     34        fallback list will also only contain system fonts, meaning that sending the font to the
     35        GPUProcess is cheap (a file path instead of actual data).
     36
     37        (WebCore::DisplayList::Recorder::Recorder):
     38        * platform/graphics/displaylists/DisplayListRecorder.h:
     39        * platform/graphics/FontCascade.cpp:
     40        (WebCore::FontCascade::displayListForTextRun const):
     41        Drive-by: Rename `DrawGlyphsDeconstruction` to `DeconstructDrawGlyphs` as it reads better.
     42
    1432021-09-29  Simon Fraser  <simon.fraser@apple.com>
    244
  • trunk/Source/WebCore/PAL/ChangeLog

    r283217 r283339  
     12021-09-30  Devin Rousso  <drousso@apple.com>
     2
     3        [iOS][GPU Process] support `<attachment>`
     4        https://bugs.webkit.org/show_bug.cgi?id=230781
     5        <rdar://problem/70884096>
     6
     7        Reviewed by Myles Maxfield.
     8
     9        * pal/spi/cg/CoreGraphicsSPI.h:
     10
    1112021-09-29  Eric Carlson  <eric.carlson@apple.com>
    212
  • trunk/Source/WebCore/PAL/pal/spi/cg/CoreGraphicsSPI.h

    r282157 r283339  
    271271CGFloat CGGStateGetAlpha(CGGStateRef);
    272272CGFontRef CGGStateGetFont(CGGStateRef);
     273CGFloat CGGStateGetFontSize(CGGStateRef);
    273274const CGAffineTransform *CGGStateGetCTM(CGGStateRef);
    274275CGColorRef CGGStateGetFillColor(CGGStateRef);
  • trunk/Source/WebCore/platform/graphics/DrawGlyphsRecorder.h

    r283273 r283339  
    3636#if USE(CORE_TEXT)
    3737#include <CoreGraphics/CoreGraphics.h>
     38#include <CoreText/CoreText.h>
     39#if PLATFORM(WIN)
     40#include <pal/spi/win/CoreTextSPIWin.h>
     41#else
     42#include <pal/spi/cf/CoreTextSPI.h>
     43#endif
    3844#include <pal/spi/cg/CoreGraphicsSPI.h>
    3945#endif
     
    4854class DrawGlyphsRecorder {
    4955public:
    50     enum class DrawGlyphsDeconstruction {
    51         Deconstruct,
    52         DontDeconstruct
    53     };
    54     explicit DrawGlyphsRecorder(GraphicsContext&, DrawGlyphsDeconstruction);
     56    enum class DeconstructDrawGlyphs : bool { No, Yes };
     57    enum class DeriveFontFromContext : bool { No, Yes };
     58    explicit DrawGlyphsRecorder(GraphicsContext&, DeconstructDrawGlyphs = DeconstructDrawGlyphs::No, DeriveFontFromContext = DeriveFontFromContext::No);
    5559
    5660    void drawGlyphs(const Font&, const GlyphBufferGlyph*, const GlyphBufferAdvance*, unsigned numGlyphs, const FloatPoint& anchorPoint, FontSmoothingMode);
    5761
    5862#if USE(CORE_TEXT) && !PLATFORM(WIN)
     63    void drawNativeText(CTFontRef, CGFloat fontSize, CTLineRef, CGRect lineRect);
     64
    5965    void recordBeginLayer(CGRenderingStateRef, CGGStateRef, CGRect);
    6066    void recordEndLayer(CGRenderingStateRef, CGGStateRef);
     
    6369#endif
    6470
    65     DrawGlyphsDeconstruction drawGlyphsDeconstruction() const { return m_drawGlyphsDeconstruction; }
     71    DeconstructDrawGlyphs deconstructDrawGlyphs() const { return m_deconstructDrawGlyphs; }
    6672
    6773private:
     
    9096
    9197    GraphicsContext& m_owner;
    92     DrawGlyphsDeconstruction m_drawGlyphsDeconstruction;
     98    DeconstructDrawGlyphs m_deconstructDrawGlyphs;
     99    DeriveFontFromContext m_deriveFontFromContext;
    93100
    94101#if USE(CORE_TEXT) && !PLATFORM(WIN)
  • trunk/Source/WebCore/platform/graphics/FontCascade.cpp

    r283199 r283339  
    214214   
    215215    std::unique_ptr<DisplayList::InMemoryDisplayList> displayList = makeUnique<DisplayList::InMemoryDisplayList>();
    216     DisplayList::Recorder recordingContext(*displayList, context.state(), FloatRect(), AffineTransform(), nullptr, DrawGlyphsRecorder::DrawGlyphsDeconstruction::DontDeconstruct);
     216    DisplayList::Recorder recordingContext(*displayList, context.state(), FloatRect(), AffineTransform(), nullptr, DrawGlyphsRecorder::DeconstructDrawGlyphs::No);
    217217   
    218218    FloatPoint startPoint = toFloatPoint(WebCore::size(glyphBuffer.initialAdvance()));
  • trunk/Source/WebCore/platform/graphics/coretext/DrawGlyphsRecorderCoreText.cpp

    r283273 r283339  
    3232#include "Font.h"
    3333#include "FontCascade.h"
     34#include "FontPlatformData.h"
    3435#include "GlyphBuffer.h"
    3536#include "GraphicsContextCG.h"
     
    8586}
    8687
    87 DrawGlyphsRecorder::DrawGlyphsRecorder(GraphicsContext& owner, DrawGlyphsDeconstruction drawGlyphsDeconstruction)
     88DrawGlyphsRecorder::DrawGlyphsRecorder(GraphicsContext& owner, DeconstructDrawGlyphs deconstructDrawGlyphs, DeriveFontFromContext deriveFontFromContext)
    8889    : m_owner(owner)
    89     , m_drawGlyphsDeconstruction(drawGlyphsDeconstruction)
     90    , m_deconstructDrawGlyphs(deconstructDrawGlyphs)
     91    , m_deriveFontFromContext(deriveFontFromContext)
    9092    , m_internalContext(createInternalContext())
    9193{
     
    290292void DrawGlyphsRecorder::recordDrawGlyphs(CGRenderingStateRef, CGGStateRef gstate, const CGAffineTransform*, const CGGlyph glyphs[], const CGPoint positions[], size_t count)
    291293{
     294    ASSERT_IMPLIES(m_deriveFontFromContext == DeriveFontFromContext::No, m_originalFont);
     295
    292296    if (!count)
    293297        return;
    294298
    295299    CGFontRef usedFont = CGGStateGetFont(gstate);
    296     if (usedFont != adoptCF(CTFontCopyGraphicsFont(m_originalFont->platformData().ctFont(), nullptr)).get())
     300    if (m_deriveFontFromContext == DeriveFontFromContext::No && usedFont != adoptCF(CTFontCopyGraphicsFont(m_originalFont->platformData().ctFont(), nullptr)).get())
    297301        return;
    298302
     
    334338    updateShadow(CGGStateGetStyle(gstate));
    335339
    336     m_owner.drawGlyphsAndCacheFont(*m_originalFont, glyphs, computeAdvancesFromPositions(positions, count, currentTextMatrix).data(), count, currentTextMatrix.mapPoint(positions[0]), m_smoothingMode);
     340    auto fontSize = CGGStateGetFontSize(gstate);
     341    Ref font = m_deriveFontFromContext == DeriveFontFromContext::No ? *m_originalFont : Font::create(FontPlatformData(adoptCF(CTFontCreateWithGraphicsFont(usedFont, fontSize, nullptr, nullptr)), fontSize));
     342    m_owner.drawGlyphsAndCacheFont(font, glyphs, computeAdvancesFromPositions(positions, count, currentTextMatrix).data(), count, currentTextMatrix.mapPoint(positions[0]), m_smoothingMode);
    337343
    338344    m_owner.concatCTM(inverseCTMFixup);
     
    411417void DrawGlyphsRecorder::drawGlyphs(const Font& font, const GlyphBufferGlyph* glyphs, const GlyphBufferAdvance* advances, unsigned numGlyphs, const FloatPoint& startPoint, FontSmoothingMode smoothingMode)
    412418{
    413     if (m_drawGlyphsDeconstruction == DrawGlyphsDeconstruction::DontDeconstruct) {
     419    if (m_deconstructDrawGlyphs == DeconstructDrawGlyphs::No) {
    414420        m_owner.drawGlyphsAndCacheFont(font, glyphs, advances, numGlyphs, startPoint, smoothingMode);
    415421        return;
    416422    }
    417423
    418     ASSERT(m_drawGlyphsDeconstruction == DrawGlyphsDeconstruction::Deconstruct);
     424    ASSERT(m_deconstructDrawGlyphs == DeconstructDrawGlyphs::Yes);
    419425
    420426    // FIXME: <rdar://problem/70166552> Record OTSVG glyphs.
     
    428434}
    429435
     436void DrawGlyphsRecorder::drawNativeText(CTFontRef font, CGFloat fontSize, CTLineRef line, CGRect lineRect)
     437{
     438    ASSERT(m_deconstructDrawGlyphs == DeconstructDrawGlyphs::Yes);
     439
     440    GraphicsContextStateSaver saver(m_owner);
     441
     442    m_owner.translate(lineRect.origin.x, lineRect.origin.y + lineRect.size.height);
     443    m_owner.scale(FloatSize(1, -1));
     444
     445    prepareInternalContext(Font::create(FontPlatformData(font, fontSize)), FontSmoothingMode::SubpixelAntialiased);
     446    CGContextSetTextPosition(m_internalContext->platformContext(), 0, 0);
     447    CTLineDraw(line, m_internalContext->platformContext());
     448    concludeInternalContext();
     449}
     450
    430451} // namespace WebCore
  • trunk/Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.cpp

    r283331 r283339  
    4141namespace DisplayList {
    4242
    43 Recorder::Recorder(DisplayList& displayList, const GraphicsContextState& state, const FloatRect& initialClip, const AffineTransform& initialCTM, Delegate* delegate, DrawGlyphsRecorder::DrawGlyphsDeconstruction drawGlyphsDeconstruction)
     43Recorder::Recorder(DisplayList& displayList, const GraphicsContextState& state, const FloatRect& initialClip, const AffineTransform& initialCTM, Delegate* delegate, DrawGlyphsRecorder::DeconstructDrawGlyphs deconstructDrawGlyphs)
    4444    : m_displayList(displayList)
    4545    , m_delegate(delegate)
    4646    , m_isNested(false)
    47     , m_drawGlyphsRecorder(*this, drawGlyphsDeconstruction)
     47    , m_drawGlyphsRecorder(*this, deconstructDrawGlyphs)
    4848{
    4949    LOG_WITH_STREAM(DisplayLists, stream << "\nRecording with clip " << initialClip);
     
    5555    , m_delegate(parent.m_delegate)
    5656    , m_isNested(true)
    57     , m_drawGlyphsRecorder(*this, parent.m_drawGlyphsRecorder.drawGlyphsDeconstruction())
     57    , m_drawGlyphsRecorder(*this, parent.m_drawGlyphsRecorder.deconstructDrawGlyphs())
    5858{
    5959    m_stateStack.append({ state, initialCTM, initialClip });
  • trunk/Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.h

    r283273 r283339  
    5656public:
    5757    class Delegate;
    58     WEBCORE_EXPORT Recorder(DisplayList&, const GraphicsContextState&, const FloatRect& initialClip, const AffineTransform&, Delegate* = nullptr, DrawGlyphsRecorder::DrawGlyphsDeconstruction = DrawGlyphsRecorder::DrawGlyphsDeconstruction::Deconstruct);
     58    WEBCORE_EXPORT Recorder(DisplayList&, const GraphicsContextState&, const FloatRect& initialClip, const AffineTransform&, Delegate* = nullptr, DrawGlyphsRecorder::DeconstructDrawGlyphs = DrawGlyphsRecorder::DeconstructDrawGlyphs::Yes);
    5959    WEBCORE_EXPORT virtual ~Recorder();
    6060
  • trunk/Source/WebCore/platform/graphics/harfbuzz/DrawGlyphsRecorderHarfBuzz.cpp

    r283273 r283339  
    3333namespace WebCore {
    3434
    35 DrawGlyphsRecorder::DrawGlyphsRecorder(GraphicsContext& owner, DrawGlyphsDeconstruction)
     35DrawGlyphsRecorder::DrawGlyphsRecorder(GraphicsContext& owner, DeconstructDrawGlyphs, DeriveFontFromContext)
    3636    : m_owner(owner)
    3737{
  • trunk/Source/WebCore/platform/graphics/win/DrawGlyphsRecorderWin.cpp

    r283273 r283339  
    3333namespace WebCore {
    3434
    35 DrawGlyphsRecorder::DrawGlyphsRecorder(GraphicsContext& owner, DrawGlyphsDeconstruction)
     35DrawGlyphsRecorder::DrawGlyphsRecorder(GraphicsContext& owner, DeconstructDrawGlyphs, DeriveFontFromContext)
    3636    : m_owner(owner)
    3737{
  • trunk/Source/WebCore/rendering/RenderThemeIOS.mm

    r283269 r283339  
    3838#import "DateComponents.h"
    3939#import "Document.h"
     40#import "DrawGlyphsRecorder.h"
    4041#import "File.h"
    4142#import "FloatRoundedRect.h"
     
    15371538        FloatRect rect;
    15381539        RetainPtr<CTLineRef> line;
     1540        RetainPtr<CTFontRef> font;
    15391541    };
    15401542    Vector<LabelLine> lines;
     
    15461548    void buildSingleLine(const String&, CTFontRef, UIColor *);
    15471549
    1548     void addLine(CTLineRef);
     1550    void addLine(CTFontRef, CTLineRef);
    15491551};
    15501552
    1551 void RenderAttachmentInfo::addLine(CTLineRef line)
     1553void RenderAttachmentInfo::addLine(CTFontRef font, CTLineRef line)
    15521554{
    15531555    CGRect lineBounds = CTLineGetBoundsWithOptions(line, kCTLineBoundsExcludeTypographicLeading);
     
    15581560    CGFloat xOffset = (attachmentRect.width() / 2) - (lineWidthIgnoringTrailingWhitespace / 2);
    15591561    LabelLine labelLine;
     1562    labelLine.font = font;
    15601563    labelLine.line = line;
    15611564    labelLine.rect = FloatRect(xOffset, 0, lineWidthIgnoringTrailingWhitespace, lineHeight);
     
    15921595    CFIndex nonTruncatedLineCount = std::min<CFIndex>(maximumLineCount - 1, lineCount);
    15931596    for (; lineIndex < nonTruncatedLineCount; ++lineIndex)
    1594         addLine((CTLineRef)CFArrayGetValueAtIndex(ctLines, lineIndex));
     1597        addLine(font, (CTLineRef)CFArrayGetValueAtIndex(ctLines, lineIndex));
    15951598
    15961599    if (lineIndex == lineCount)
     
    16121615        truncatedLine = remainingLine;
    16131616
    1614     addLine(truncatedLine.get());
     1617    addLine(font, truncatedLine.get());
    16151618}
    16161619
     
    16261629    RetainPtr<NSAttributedString> attributedText = adoptNS([[NSAttributedString alloc] initWithString:text attributes:textAttributes]);
    16271630
    1628     addLine(adoptCF(CTLineCreateWithAttributedString((CFAttributedStringRef)attributedText.get())).get());
     1631    addLine(font, adoptCF(CTLineCreateWithAttributedString((CFAttributedStringRef)attributedText.get())).get());
    16291632}
    16301633
     
    17671770static void paintAttachmentText(GraphicsContext& context, RenderAttachmentInfo& info)
    17681771{
    1769     for (const auto& line : info.lines) {
    1770         GraphicsContextStateSaver saver(context);
    1771 
    1772         context.translate(toFloatSize(line.rect.minXMaxYCorner()));
    1773         context.scale(FloatSize(1, -1));
    1774 
    1775         CGContextSetTextPosition(context.platformContext(), 0, 0);
    1776         CTLineDraw(line.line.get(), context.platformContext());
    1777     }
     1772    DrawGlyphsRecorder recorder(context, DrawGlyphsRecorder::DeconstructDrawGlyphs::Yes, DrawGlyphsRecorder::DeriveFontFromContext::Yes);
     1773
     1774    for (const auto& line : info.lines)
     1775        recorder.drawNativeText(line.font.get(), CTFontGetSize(line.font.get()), line.line.get(), line.rect);
    17781776}
    17791777
Note: See TracChangeset for help on using the changeset viewer.