Title: [283863] trunk/Source/WebCore
Revision
283863
Author
[email protected]
Date
2021-10-08 23:18:20 -0700 (Fri, 08 Oct 2021)

Log 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/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).

* platform/graphics/displaylists/DisplayListRecorder.h:
* platform/graphics/displaylists/DisplayListRecorder.cpp:
(WebCore::DisplayList::Recorder::Recorder):
* platform/graphics/displaylists/DisplayListRecorderImpl.h:
* platform/graphics/displaylists/DisplayListRecorderImpl.cpp:
(WebCore::DisplayList::Recorder::RecorderImpl):
* 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:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (283862 => 283863)


--- trunk/Source/WebCore/ChangeLog	2021-10-09 03:29:53 UTC (rev 283862)
+++ trunk/Source/WebCore/ChangeLog	2021-10-09 06:18:20 UTC (rev 283863)
@@ -1,3 +1,48 @@
+2021-10-08  Devin Rousso  <[email protected]>
+
+        [iOS][GPU Process] support `<attachment>`
+        https://bugs.webkit.org/show_bug.cgi?id=230781
+        <rdar://problem/70884096>
+
+        Reviewed by Myles Maxfield.
+
+        * 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/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).
+
+        * platform/graphics/displaylists/DisplayListRecorder.h:
+        * platform/graphics/displaylists/DisplayListRecorder.cpp:
+        (WebCore::DisplayList::Recorder::Recorder):
+        * platform/graphics/displaylists/DisplayListRecorderImpl.h:
+        * platform/graphics/displaylists/DisplayListRecorderImpl.cpp:
+        (WebCore::DisplayList::Recorder::RecorderImpl):
+        * platform/graphics/FontCascade.cpp:
+        (WebCore::FontCascade::displayListForTextRun const):
+        Drive-by: Rename `DrawGlyphsDeconstruction` to `DeconstructDrawGlyphs` as it reads better.
+
 2021-10-08  Aditya Keerthi  <[email protected]>
 
         Add support for '-webkit-appearance: auto'

Modified: trunk/Source/WebCore/PAL/ChangeLog (283862 => 283863)


--- trunk/Source/WebCore/PAL/ChangeLog	2021-10-09 03:29:53 UTC (rev 283862)
+++ trunk/Source/WebCore/PAL/ChangeLog	2021-10-09 06:18:20 UTC (rev 283863)
@@ -1,3 +1,13 @@
+2021-10-08  Devin Rousso  <[email protected]>
+
+        [iOS][GPU Process] support `<attachment>`
+        https://bugs.webkit.org/show_bug.cgi?id=230781
+        <rdar://problem/70884096>
+
+        Reviewed by Myles Maxfield.
+
+        * pal/spi/cg/CoreGraphicsSPI.h:
+
 2021-10-05  Aditya Keerthi  <[email protected]>
 
         [iOS] Transcode videos selected from UIImagePickerController

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


--- trunk/Source/WebCore/PAL/pal/spi/cg/CoreGraphicsSPI.h	2021-10-09 03:29:53 UTC (rev 283862)
+++ trunk/Source/WebCore/PAL/pal/spi/cg/CoreGraphicsSPI.h	2021-10-09 06:18:20 UTC (rev 283863)
@@ -270,6 +270,7 @@
 void CGContextDelegateRelease(CGContextDelegateRef);
 CGFloat CGGStateGetAlpha(CGGStateRef);
 CGFontRef CGGStateGetFont(CGGStateRef);
+CGFloat CGGStateGetFontSize(CGGStateRef);
 const CGAffineTransform *CGGStateGetCTM(CGGStateRef);
 CGColorRef CGGStateGetFillColor(CGGStateRef);
 CGColorRef CGGStateGetStrokeColor(CGGStateRef);

Modified: trunk/Source/WebCore/platform/graphics/DrawGlyphsRecorder.h (283862 => 283863)


--- trunk/Source/WebCore/platform/graphics/DrawGlyphsRecorder.h	2021-10-09 03:29:53 UTC (rev 283862)
+++ trunk/Source/WebCore/platform/graphics/DrawGlyphsRecorder.h	2021-10-09 06:18:20 UTC (rev 283863)
@@ -35,6 +35,12 @@
 
 #if USE(CORE_TEXT)
 #include <CoreGraphics/CoreGraphics.h>
+#include <CoreText/CoreText.h>
+#if PLATFORM(WIN)
+#include <pal/spi/win/CoreTextSPIWin.h>
+#else
+#include <pal/spi/cf/CoreTextSPI.h>
+#endif
 #include <pal/spi/cg/CoreGraphicsSPI.h>
 #endif
 
@@ -47,15 +53,15 @@
 
 class DrawGlyphsRecorder {
 public:
-    enum class DrawGlyphsDeconstruction {
-        Deconstruct,
-        DontDeconstruct
-    };
-    explicit DrawGlyphsRecorder(GraphicsContext&, DrawGlyphsDeconstruction);
+    enum class DeconstructDrawGlyphs : bool { No, Yes };
+    enum class DeriveFontFromContext : bool { No, Yes };
+    explicit DrawGlyphsRecorder(GraphicsContext&, DeconstructDrawGlyphs = DeconstructDrawGlyphs::No, DeriveFontFromContext = DeriveFontFromContext::No);
 
     void drawGlyphs(const Font&, const GlyphBufferGlyph*, const GlyphBufferAdvance*, unsigned numGlyphs, const FloatPoint& anchorPoint, FontSmoothingMode);
 
 #if USE(CORE_TEXT) && !PLATFORM(WIN)
+    void drawNativeText(CTFontRef, CGFloat fontSize, CTLineRef, CGRect lineRect);
+
     void recordBeginLayer(CGRenderingStateRef, CGGStateRef, CGRect);
     void recordEndLayer(CGRenderingStateRef, CGGStateRef);
     void recordDrawGlyphs(CGRenderingStateRef, CGGStateRef, const CGAffineTransform*, const CGGlyph[], const CGPoint positions[], size_t count);
@@ -62,7 +68,7 @@
     void recordDrawImage(CGRenderingStateRef, CGGStateRef, CGRect, CGImageRef);
 #endif
 
-    DrawGlyphsDeconstruction drawGlyphsDeconstruction() const { return m_drawGlyphsDeconstruction; }
+    DeconstructDrawGlyphs deconstructDrawGlyphs() const { return m_deconstructDrawGlyphs; }
 
 private:
 #if USE(CORE_TEXT) && !PLATFORM(WIN)
@@ -89,7 +95,8 @@
 #endif
 
     GraphicsContext& m_owner;
-    DrawGlyphsDeconstruction m_drawGlyphsDeconstruction;
+    DeconstructDrawGlyphs m_deconstructDrawGlyphs;
+    DeriveFontFromContext m_deriveFontFromContext;
 
 #if USE(CORE_TEXT) && !PLATFORM(WIN)
     UniqueRef<GraphicsContext> m_internalContext;

Modified: trunk/Source/WebCore/platform/graphics/FontCascade.cpp (283862 => 283863)


--- trunk/Source/WebCore/platform/graphics/FontCascade.cpp	2021-10-09 03:29:53 UTC (rev 283862)
+++ trunk/Source/WebCore/platform/graphics/FontCascade.cpp	2021-10-09 06:18:20 UTC (rev 283863)
@@ -213,7 +213,7 @@
         return nullptr;
     
     std::unique_ptr<DisplayList::InMemoryDisplayList> displayList = makeUnique<DisplayList::InMemoryDisplayList>();
-    DisplayList::RecorderImpl recordingContext(*displayList, context.state(), FloatRect(), AffineTransform(), nullptr, DrawGlyphsRecorder::DrawGlyphsDeconstruction::DontDeconstruct);
+    DisplayList::RecorderImpl recordingContext(*displayList, context.state(), FloatRect(), AffineTransform(), nullptr, DrawGlyphsRecorder::DeconstructDrawGlyphs::No);
     
     FloatPoint startPoint = toFloatPoint(WebCore::size(glyphBuffer.initialAdvance()));
     drawGlyphBuffer(recordingContext, glyphBuffer, startPoint, customFontNotReadyAction);

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


--- trunk/Source/WebCore/platform/graphics/coretext/DrawGlyphsRecorderCoreText.cpp	2021-10-09 03:29:53 UTC (rev 283862)
+++ trunk/Source/WebCore/platform/graphics/coretext/DrawGlyphsRecorderCoreText.cpp	2021-10-09 06:18:20 UTC (rev 283863)
@@ -31,6 +31,7 @@
 #include "FloatPoint.h"
 #include "Font.h"
 #include "FontCascade.h"
+#include "FontPlatformData.h"
 #include "GlyphBuffer.h"
 #include "GraphicsContextCG.h"
 
@@ -84,9 +85,10 @@
     return makeUniqueRef<GraphicsContextCG>(context.get());
 }
 
-DrawGlyphsRecorder::DrawGlyphsRecorder(GraphicsContext& owner, DrawGlyphsDeconstruction drawGlyphsDeconstruction)
+DrawGlyphsRecorder::DrawGlyphsRecorder(GraphicsContext& owner, DeconstructDrawGlyphs deconstructDrawGlyphs, DeriveFontFromContext deriveFontFromContext)
     : m_owner(owner)
-    , m_drawGlyphsDeconstruction(drawGlyphsDeconstruction)
+    , m_deconstructDrawGlyphs(deconstructDrawGlyphs)
+    , m_deriveFontFromContext(deriveFontFromContext)
     , m_internalContext(createInternalContext())
 {
 }
@@ -289,19 +291,15 @@
 
 void DrawGlyphsRecorder::recordDrawGlyphs(CGRenderingStateRef, CGGStateRef gstate, const CGAffineTransform*, const CGGlyph glyphs[], const CGPoint positions[], size_t count)
 {
+    ASSERT_IMPLIES(m_deriveFontFromContext == DeriveFontFromContext::No, m_originalFont);
+
     if (!count)
         return;
 
     CGFontRef usedFont = CGGStateGetFont(gstate);
-    if (usedFont != adoptCF(CTFontCopyGraphicsFont(m_originalFont->platformData().ctFont(), nullptr)).get())
+    if (m_deriveFontFromContext == DeriveFontFromContext::No && usedFont != adoptCF(CTFontCopyGraphicsFont(m_originalFont->platformData().ctFont(), nullptr)).get())
         return;
 
-#if ASSERT_ENABLED
-    auto textPosition = CGContextGetTextPosition(m_internalContext->platformContext());
-    ASSERT(!textPosition.x);
-    ASSERT(!textPosition.y);
-#endif
-
     updateCTM(*CGGStateGetCTM(gstate));
 
     // We want the replayer's CTM and text matrix to match the current CTM and text matrix.
@@ -333,7 +331,9 @@
     updateStrokeColor(Color::createAndPreserveColorSpace(strokeColor));
     updateShadow(CGGStateGetStyle(gstate));
 
-    m_owner.drawGlyphsAndCacheFont(*m_originalFont, glyphs, computeAdvancesFromPositions(positions, count, currentTextMatrix).data(), count, currentTextMatrix.mapPoint(positions[0]), m_smoothingMode);
+    auto fontSize = CGGStateGetFontSize(gstate);
+    Ref font = m_deriveFontFromContext == DeriveFontFromContext::No ? *m_originalFont : Font::create(FontPlatformData(adoptCF(CTFontCreateWithGraphicsFont(usedFont, fontSize, nullptr, nullptr)), fontSize));
+    m_owner.drawGlyphsAndCacheFont(font, glyphs, computeAdvancesFromPositions(positions, count, currentTextMatrix).data(), count, currentTextMatrix.mapPoint(positions[0]), m_smoothingMode);
 
     m_owner.concatCTM(inverseCTMFixup);
 }
@@ -410,12 +410,12 @@
 
 void DrawGlyphsRecorder::drawGlyphs(const Font& font, const GlyphBufferGlyph* glyphs, const GlyphBufferAdvance* advances, unsigned numGlyphs, const FloatPoint& startPoint, FontSmoothingMode smoothingMode)
 {
-    if (m_drawGlyphsDeconstruction == DrawGlyphsDeconstruction::DontDeconstruct) {
+    if (m_deconstructDrawGlyphs == DeconstructDrawGlyphs::No) {
         m_owner.drawGlyphsAndCacheFont(font, glyphs, advances, numGlyphs, startPoint, smoothingMode);
         return;
     }
 
-    ASSERT(m_drawGlyphsDeconstruction == DrawGlyphsDeconstruction::Deconstruct);
+    ASSERT(m_deconstructDrawGlyphs == DeconstructDrawGlyphs::Yes);
 
     // FIXME: <rdar://problem/70166552> Record OTSVG glyphs.
     GlyphsAndAdvances glyphsAndAdvancesWithoutOTSVGGlyphs = filterOutOTSVGGlyphs(font, glyphs, advances, numGlyphs);
@@ -427,4 +427,19 @@
     concludeInternalContext();
 }
 
+void DrawGlyphsRecorder::drawNativeText(CTFontRef font, CGFloat fontSize, CTLineRef line, CGRect lineRect)
+{
+    ASSERT(m_deconstructDrawGlyphs == DeconstructDrawGlyphs::Yes);
+
+    GraphicsContextStateSaver saver(m_owner);
+
+    m_owner.translate(lineRect.origin.x, lineRect.origin.y + lineRect.size.height);
+    m_owner.scale(FloatSize(1, -1));
+
+    prepareInternalContext(Font::create(FontPlatformData(font, fontSize)), FontSmoothingMode::SubpixelAntialiased);
+    CGContextSetTextPosition(m_internalContext->platformContext(), 0, 0);
+    CTLineDraw(line, m_internalContext->platformContext());
+    concludeInternalContext();
+}
+
 } // namespace WebCore

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


--- trunk/Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.cpp	2021-10-09 03:29:53 UTC (rev 283862)
+++ trunk/Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.cpp	2021-10-09 06:18:20 UTC (rev 283863)
@@ -40,14 +40,14 @@
 namespace WebCore {
 namespace DisplayList {
 
-Recorder::Recorder(const GraphicsContextState& state, const FloatRect& initialClip, const AffineTransform& initialCTM, DrawGlyphsRecorder::DrawGlyphsDeconstruction drawGlyphsDeconstruction)
-    : m_drawGlyphsRecorder(*this, drawGlyphsDeconstruction)
+Recorder::Recorder(const GraphicsContextState& state, const FloatRect& initialClip, const AffineTransform& initialCTM, DrawGlyphsRecorder::DeconstructDrawGlyphs deconstructDrawGlyphs)
+    : m_drawGlyphsRecorder(*this, deconstructDrawGlyphs)
 {
     m_stateStack.append({ state, initialCTM, initialClip });
 }
 
 Recorder::Recorder(Recorder& parent, const GraphicsContextState& state, const FloatRect& initialClip, const AffineTransform& initialCTM)
-    : m_drawGlyphsRecorder(*this, parent.m_drawGlyphsRecorder.drawGlyphsDeconstruction())
+    : m_drawGlyphsRecorder(*this, parent.m_drawGlyphsRecorder.deconstructDrawGlyphs())
 {
     m_stateStack.append({ state, initialCTM, initialClip });
 }

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


--- trunk/Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.h	2021-10-09 03:29:53 UTC (rev 283862)
+++ trunk/Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.h	2021-10-09 06:18:20 UTC (rev 283863)
@@ -55,7 +55,7 @@
     WTF_MAKE_FAST_ALLOCATED;
     WTF_MAKE_NONCOPYABLE(Recorder);
 public:
-    WEBCORE_EXPORT Recorder(const GraphicsContextState&, const FloatRect& initialClip, const AffineTransform&, DrawGlyphsRecorder::DrawGlyphsDeconstruction = DrawGlyphsRecorder::DrawGlyphsDeconstruction::Deconstruct);
+    WEBCORE_EXPORT Recorder(const GraphicsContextState&, const FloatRect& initialClip, const AffineTransform&, DrawGlyphsRecorder::DeconstructDrawGlyphs = DrawGlyphsRecorder::DeconstructDrawGlyphs::Yes);
     WEBCORE_EXPORT virtual ~Recorder();
 
     virtual void getPixelBuffer(const PixelBufferFormat& outputFormat, const IntRect& sourceRect) = 0;

Modified: trunk/Source/WebCore/platform/graphics/displaylists/DisplayListRecorderImpl.cpp (283862 => 283863)


--- trunk/Source/WebCore/platform/graphics/displaylists/DisplayListRecorderImpl.cpp	2021-10-09 03:29:53 UTC (rev 283862)
+++ trunk/Source/WebCore/platform/graphics/displaylists/DisplayListRecorderImpl.cpp	2021-10-09 06:18:20 UTC (rev 283863)
@@ -40,8 +40,8 @@
 namespace WebCore {
 namespace DisplayList {
 
-RecorderImpl::RecorderImpl(DisplayList& displayList, const GraphicsContextState& state, const FloatRect& initialClip, const AffineTransform& initialCTM, Delegate* delegate, DrawGlyphsRecorder::DrawGlyphsDeconstruction drawGlyphsDeconstruction)
-    : Recorder(state, initialClip, initialCTM, drawGlyphsDeconstruction)
+RecorderImpl::RecorderImpl(DisplayList& displayList, const GraphicsContextState& state, const FloatRect& initialClip, const AffineTransform& initialCTM, Delegate* delegate, DrawGlyphsRecorder::DeconstructDrawGlyphs deconstructDrawGlyphs)
+    : Recorder(state, initialClip, initialCTM, deconstructDrawGlyphs)
     , m_displayList(displayList)
     , m_delegate(delegate)
 {

Modified: trunk/Source/WebCore/platform/graphics/displaylists/DisplayListRecorderImpl.h (283862 => 283863)


--- trunk/Source/WebCore/platform/graphics/displaylists/DisplayListRecorderImpl.h	2021-10-09 03:29:53 UTC (rev 283862)
+++ trunk/Source/WebCore/platform/graphics/displaylists/DisplayListRecorderImpl.h	2021-10-09 06:18:20 UTC (rev 283863)
@@ -36,7 +36,7 @@
     WTF_MAKE_NONCOPYABLE(RecorderImpl);
 public:
     class Delegate;
-    WEBCORE_EXPORT RecorderImpl(DisplayList&, const GraphicsContextState&, const FloatRect& initialClip, const AffineTransform&, Delegate* = nullptr, DrawGlyphsRecorder::DrawGlyphsDeconstruction = DrawGlyphsRecorder::DrawGlyphsDeconstruction::Deconstruct);
+    WEBCORE_EXPORT RecorderImpl(DisplayList&, const GraphicsContextState&, const FloatRect& initialClip, const AffineTransform&, Delegate* = nullptr, DrawGlyphsRecorder::DeconstructDrawGlyphs = DrawGlyphsRecorder::DeconstructDrawGlyphs::Yes);
     RecorderImpl(RecorderImpl& parent, const GraphicsContextState&, const FloatRect& initialClip, const AffineTransform& initialCTM);
 
     WEBCORE_EXPORT virtual ~RecorderImpl();

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


--- trunk/Source/WebCore/platform/graphics/harfbuzz/DrawGlyphsRecorderHarfBuzz.cpp	2021-10-09 03:29:53 UTC (rev 283862)
+++ trunk/Source/WebCore/platform/graphics/harfbuzz/DrawGlyphsRecorderHarfBuzz.cpp	2021-10-09 06:18:20 UTC (rev 283863)
@@ -32,7 +32,7 @@
 
 namespace WebCore {
 
-DrawGlyphsRecorder::DrawGlyphsRecorder(GraphicsContext& owner, DrawGlyphsDeconstruction)
+DrawGlyphsRecorder::DrawGlyphsRecorder(GraphicsContext& owner, DeconstructDrawGlyphs, DeriveFontFromContext)
     : m_owner(owner)
 {
 }

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


--- trunk/Source/WebCore/platform/graphics/win/DrawGlyphsRecorderWin.cpp	2021-10-09 03:29:53 UTC (rev 283862)
+++ trunk/Source/WebCore/platform/graphics/win/DrawGlyphsRecorderWin.cpp	2021-10-09 06:18:20 UTC (rev 283863)
@@ -32,7 +32,7 @@
 
 namespace WebCore {
 
-DrawGlyphsRecorder::DrawGlyphsRecorder(GraphicsContext& owner, DrawGlyphsDeconstruction)
+DrawGlyphsRecorder::DrawGlyphsRecorder(GraphicsContext& owner, DeconstructDrawGlyphs, DeriveFontFromContext)
     : m_owner(owner)
 {
 }

Modified: trunk/Source/WebCore/rendering/RenderThemeIOS.mm (283862 => 283863)


--- trunk/Source/WebCore/rendering/RenderThemeIOS.mm	2021-10-09 03:29:53 UTC (rev 283862)
+++ trunk/Source/WebCore/rendering/RenderThemeIOS.mm	2021-10-09 06:18:20 UTC (rev 283863)
@@ -37,6 +37,7 @@
 #import "ColorIOS.h"
 #import "DateComponents.h"
 #import "Document.h"
+#import "DrawGlyphsRecorder.h"
 #import "File.h"
 #import "FloatRoundedRect.h"
 #import "FontCache.h"
@@ -1536,6 +1537,7 @@
     struct LabelLine {
         FloatRect rect;
         RetainPtr<CTLineRef> line;
+        RetainPtr<CTFontRef> font;
     };
     Vector<LabelLine> lines;
 
@@ -1545,10 +1547,10 @@
     void buildWrappedLines(const String&, CTFontRef, UIColor *, unsigned maximumLineCount);
     void buildSingleLine(const String&, CTFontRef, UIColor *);
 
-    void addLine(CTLineRef);
+    void addLine(CTFontRef, CTLineRef);
 };
 
-void RenderAttachmentInfo::addLine(CTLineRef line)
+void RenderAttachmentInfo::addLine(CTFontRef font, CTLineRef line)
 {
     CGRect lineBounds = CTLineGetBoundsWithOptions(line, kCTLineBoundsExcludeTypographicLeading);
     CGFloat trailingWhitespaceWidth = CTLineGetTrailingWhitespaceWidth(line);
@@ -1557,6 +1559,7 @@
 
     CGFloat xOffset = (attachmentRect.width() / 2) - (lineWidthIgnoringTrailingWhitespace / 2);
     LabelLine labelLine;
+    labelLine.font = font;
     labelLine.line = line;
     labelLine.rect = FloatRect(xOffset, 0, lineWidthIgnoringTrailingWhitespace, lineHeight);
 
@@ -1591,7 +1594,7 @@
     CFIndex lineIndex = 0;
     CFIndex nonTruncatedLineCount = std::min<CFIndex>(maximumLineCount - 1, lineCount);
     for (; lineIndex < nonTruncatedLineCount; ++lineIndex)
-        addLine((CTLineRef)CFArrayGetValueAtIndex(ctLines, lineIndex));
+        addLine(font, (CTLineRef)CFArrayGetValueAtIndex(ctLines, lineIndex));
 
     if (lineIndex == lineCount)
         return;
@@ -1611,7 +1614,7 @@
     if (!truncatedLine)
         truncatedLine = remainingLine;
 
-    addLine(truncatedLine.get());
+    addLine(font, truncatedLine.get());
 }
 
 void RenderAttachmentInfo::buildSingleLine(const String& text, CTFontRef font, UIColor *color)
@@ -1625,7 +1628,7 @@
     };
     RetainPtr<NSAttributedString> attributedText = adoptNS([[NSAttributedString alloc] initWithString:text attributes:textAttributes]);
 
-    addLine(adoptCF(CTLineCreateWithAttributedString((CFAttributedStringRef)attributedText.get())).get());
+    addLine(font, adoptCF(CTLineCreateWithAttributedString((CFAttributedStringRef)attributedText.get())).get());
 }
 
 static BOOL getAttachmentProgress(const RenderAttachment& attachment, float& progress)
@@ -1766,15 +1769,10 @@
 
 static void paintAttachmentText(GraphicsContext& context, RenderAttachmentInfo& info)
 {
-    for (const auto& line : info.lines) {
-        GraphicsContextStateSaver saver(context);
+    DrawGlyphsRecorder recorder(context, DrawGlyphsRecorder::DeconstructDrawGlyphs::Yes, DrawGlyphsRecorder::DeriveFontFromContext::Yes);
 
-        context.translate(toFloatSize(line.rect.minXMaxYCorner()));
-        context.scale(FloatSize(1, -1));
-
-        CGContextSetTextPosition(context.platformContext(), 0, 0);
-        CTLineDraw(line.line.get(), context.platformContext());
-    }
+    for (const auto& line : info.lines)
+        recorder.drawNativeText(line.font.get(), CTFontGetSize(line.font.get()), line.line.get(), line.rect);
 }
 
 static void paintAttachmentProgress(GraphicsContext& context, RenderAttachmentInfo& info)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to