Changeset 283339 in webkit
- Timestamp:
- Sep 30, 2021, 2:13:05 PM (5 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 11 edited
-
ChangeLog (modified) (1 diff)
-
PAL/ChangeLog (modified) (1 diff)
-
PAL/pal/spi/cg/CoreGraphicsSPI.h (modified) (1 diff)
-
platform/graphics/DrawGlyphsRecorder.h (modified) (4 diffs)
-
platform/graphics/FontCascade.cpp (modified) (1 diff)
-
platform/graphics/coretext/DrawGlyphsRecorderCoreText.cpp (modified) (6 diffs)
-
platform/graphics/displaylists/DisplayListRecorder.cpp (modified) (2 diffs)
-
platform/graphics/displaylists/DisplayListRecorder.h (modified) (1 diff)
-
platform/graphics/harfbuzz/DrawGlyphsRecorderHarfBuzz.cpp (modified) (1 diff)
-
platform/graphics/win/DrawGlyphsRecorderWin.cpp (modified) (1 diff)
-
rendering/RenderThemeIOS.mm (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r283335 r283339 1 2021-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 1 43 2021-09-29 Simon Fraser <simon.fraser@apple.com> 2 44 -
trunk/Source/WebCore/PAL/ChangeLog
r283217 r283339 1 2021-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 1 11 2021-09-29 Eric Carlson <eric.carlson@apple.com> 2 12 -
trunk/Source/WebCore/PAL/pal/spi/cg/CoreGraphicsSPI.h
r282157 r283339 271 271 CGFloat CGGStateGetAlpha(CGGStateRef); 272 272 CGFontRef CGGStateGetFont(CGGStateRef); 273 CGFloat CGGStateGetFontSize(CGGStateRef); 273 274 const CGAffineTransform *CGGStateGetCTM(CGGStateRef); 274 275 CGColorRef CGGStateGetFillColor(CGGStateRef); -
trunk/Source/WebCore/platform/graphics/DrawGlyphsRecorder.h
r283273 r283339 36 36 #if USE(CORE_TEXT) 37 37 #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 38 44 #include <pal/spi/cg/CoreGraphicsSPI.h> 39 45 #endif … … 48 54 class DrawGlyphsRecorder { 49 55 public: 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); 55 59 56 60 void drawGlyphs(const Font&, const GlyphBufferGlyph*, const GlyphBufferAdvance*, unsigned numGlyphs, const FloatPoint& anchorPoint, FontSmoothingMode); 57 61 58 62 #if USE(CORE_TEXT) && !PLATFORM(WIN) 63 void drawNativeText(CTFontRef, CGFloat fontSize, CTLineRef, CGRect lineRect); 64 59 65 void recordBeginLayer(CGRenderingStateRef, CGGStateRef, CGRect); 60 66 void recordEndLayer(CGRenderingStateRef, CGGStateRef); … … 63 69 #endif 64 70 65 D rawGlyphsDeconstruction drawGlyphsDeconstruction() const { return m_drawGlyphsDeconstruction; }71 DeconstructDrawGlyphs deconstructDrawGlyphs() const { return m_deconstructDrawGlyphs; } 66 72 67 73 private: … … 90 96 91 97 GraphicsContext& m_owner; 92 DrawGlyphsDeconstruction m_drawGlyphsDeconstruction; 98 DeconstructDrawGlyphs m_deconstructDrawGlyphs; 99 DeriveFontFromContext m_deriveFontFromContext; 93 100 94 101 #if USE(CORE_TEXT) && !PLATFORM(WIN) -
trunk/Source/WebCore/platform/graphics/FontCascade.cpp
r283199 r283339 214 214 215 215 std::unique_ptr<DisplayList::InMemoryDisplayList> displayList = makeUnique<DisplayList::InMemoryDisplayList>(); 216 DisplayList::Recorder recordingContext(*displayList, context.state(), FloatRect(), AffineTransform(), nullptr, DrawGlyphsRecorder::D rawGlyphsDeconstruction::DontDeconstruct);216 DisplayList::Recorder recordingContext(*displayList, context.state(), FloatRect(), AffineTransform(), nullptr, DrawGlyphsRecorder::DeconstructDrawGlyphs::No); 217 217 218 218 FloatPoint startPoint = toFloatPoint(WebCore::size(glyphBuffer.initialAdvance())); -
trunk/Source/WebCore/platform/graphics/coretext/DrawGlyphsRecorderCoreText.cpp
r283273 r283339 32 32 #include "Font.h" 33 33 #include "FontCascade.h" 34 #include "FontPlatformData.h" 34 35 #include "GlyphBuffer.h" 35 36 #include "GraphicsContextCG.h" … … 85 86 } 86 87 87 DrawGlyphsRecorder::DrawGlyphsRecorder(GraphicsContext& owner, D rawGlyphsDeconstruction drawGlyphsDeconstruction)88 DrawGlyphsRecorder::DrawGlyphsRecorder(GraphicsContext& owner, DeconstructDrawGlyphs deconstructDrawGlyphs, DeriveFontFromContext deriveFontFromContext) 88 89 : m_owner(owner) 89 , m_drawGlyphsDeconstruction(drawGlyphsDeconstruction) 90 , m_deconstructDrawGlyphs(deconstructDrawGlyphs) 91 , m_deriveFontFromContext(deriveFontFromContext) 90 92 , m_internalContext(createInternalContext()) 91 93 { … … 290 292 void DrawGlyphsRecorder::recordDrawGlyphs(CGRenderingStateRef, CGGStateRef gstate, const CGAffineTransform*, const CGGlyph glyphs[], const CGPoint positions[], size_t count) 291 293 { 294 ASSERT_IMPLIES(m_deriveFontFromContext == DeriveFontFromContext::No, m_originalFont); 295 292 296 if (!count) 293 297 return; 294 298 295 299 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()) 297 301 return; 298 302 … … 334 338 updateShadow(CGGStateGetStyle(gstate)); 335 339 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); 337 343 338 344 m_owner.concatCTM(inverseCTMFixup); … … 411 417 void DrawGlyphsRecorder::drawGlyphs(const Font& font, const GlyphBufferGlyph* glyphs, const GlyphBufferAdvance* advances, unsigned numGlyphs, const FloatPoint& startPoint, FontSmoothingMode smoothingMode) 412 418 { 413 if (m_d rawGlyphsDeconstruction == DrawGlyphsDeconstruction::DontDeconstruct) {419 if (m_deconstructDrawGlyphs == DeconstructDrawGlyphs::No) { 414 420 m_owner.drawGlyphsAndCacheFont(font, glyphs, advances, numGlyphs, startPoint, smoothingMode); 415 421 return; 416 422 } 417 423 418 ASSERT(m_d rawGlyphsDeconstruction == DrawGlyphsDeconstruction::Deconstruct);424 ASSERT(m_deconstructDrawGlyphs == DeconstructDrawGlyphs::Yes); 419 425 420 426 // FIXME: <rdar://problem/70166552> Record OTSVG glyphs. … … 428 434 } 429 435 436 void 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 430 451 } // namespace WebCore -
trunk/Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.cpp
r283331 r283339 41 41 namespace DisplayList { 42 42 43 Recorder::Recorder(DisplayList& displayList, const GraphicsContextState& state, const FloatRect& initialClip, const AffineTransform& initialCTM, Delegate* delegate, DrawGlyphsRecorder::D rawGlyphsDeconstruction drawGlyphsDeconstruction)43 Recorder::Recorder(DisplayList& displayList, const GraphicsContextState& state, const FloatRect& initialClip, const AffineTransform& initialCTM, Delegate* delegate, DrawGlyphsRecorder::DeconstructDrawGlyphs deconstructDrawGlyphs) 44 44 : m_displayList(displayList) 45 45 , m_delegate(delegate) 46 46 , m_isNested(false) 47 , m_drawGlyphsRecorder(*this, d rawGlyphsDeconstruction)47 , m_drawGlyphsRecorder(*this, deconstructDrawGlyphs) 48 48 { 49 49 LOG_WITH_STREAM(DisplayLists, stream << "\nRecording with clip " << initialClip); … … 55 55 , m_delegate(parent.m_delegate) 56 56 , m_isNested(true) 57 , m_drawGlyphsRecorder(*this, parent.m_drawGlyphsRecorder.d rawGlyphsDeconstruction())57 , m_drawGlyphsRecorder(*this, parent.m_drawGlyphsRecorder.deconstructDrawGlyphs()) 58 58 { 59 59 m_stateStack.append({ state, initialCTM, initialClip }); -
trunk/Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.h
r283273 r283339 56 56 public: 57 57 class Delegate; 58 WEBCORE_EXPORT Recorder(DisplayList&, const GraphicsContextState&, const FloatRect& initialClip, const AffineTransform&, Delegate* = nullptr, DrawGlyphsRecorder::D rawGlyphsDeconstruction = DrawGlyphsRecorder::DrawGlyphsDeconstruction::Deconstruct);58 WEBCORE_EXPORT Recorder(DisplayList&, const GraphicsContextState&, const FloatRect& initialClip, const AffineTransform&, Delegate* = nullptr, DrawGlyphsRecorder::DeconstructDrawGlyphs = DrawGlyphsRecorder::DeconstructDrawGlyphs::Yes); 59 59 WEBCORE_EXPORT virtual ~Recorder(); 60 60 -
trunk/Source/WebCore/platform/graphics/harfbuzz/DrawGlyphsRecorderHarfBuzz.cpp
r283273 r283339 33 33 namespace WebCore { 34 34 35 DrawGlyphsRecorder::DrawGlyphsRecorder(GraphicsContext& owner, D rawGlyphsDeconstruction)35 DrawGlyphsRecorder::DrawGlyphsRecorder(GraphicsContext& owner, DeconstructDrawGlyphs, DeriveFontFromContext) 36 36 : m_owner(owner) 37 37 { -
trunk/Source/WebCore/platform/graphics/win/DrawGlyphsRecorderWin.cpp
r283273 r283339 33 33 namespace WebCore { 34 34 35 DrawGlyphsRecorder::DrawGlyphsRecorder(GraphicsContext& owner, D rawGlyphsDeconstruction)35 DrawGlyphsRecorder::DrawGlyphsRecorder(GraphicsContext& owner, DeconstructDrawGlyphs, DeriveFontFromContext) 36 36 : m_owner(owner) 37 37 { -
trunk/Source/WebCore/rendering/RenderThemeIOS.mm
r283269 r283339 38 38 #import "DateComponents.h" 39 39 #import "Document.h" 40 #import "DrawGlyphsRecorder.h" 40 41 #import "File.h" 41 42 #import "FloatRoundedRect.h" … … 1537 1538 FloatRect rect; 1538 1539 RetainPtr<CTLineRef> line; 1540 RetainPtr<CTFontRef> font; 1539 1541 }; 1540 1542 Vector<LabelLine> lines; … … 1546 1548 void buildSingleLine(const String&, CTFontRef, UIColor *); 1547 1549 1548 void addLine(CT LineRef);1550 void addLine(CTFontRef, CTLineRef); 1549 1551 }; 1550 1552 1551 void RenderAttachmentInfo::addLine(CT LineRef line)1553 void RenderAttachmentInfo::addLine(CTFontRef font, CTLineRef line) 1552 1554 { 1553 1555 CGRect lineBounds = CTLineGetBoundsWithOptions(line, kCTLineBoundsExcludeTypographicLeading); … … 1558 1560 CGFloat xOffset = (attachmentRect.width() / 2) - (lineWidthIgnoringTrailingWhitespace / 2); 1559 1561 LabelLine labelLine; 1562 labelLine.font = font; 1560 1563 labelLine.line = line; 1561 1564 labelLine.rect = FloatRect(xOffset, 0, lineWidthIgnoringTrailingWhitespace, lineHeight); … … 1592 1595 CFIndex nonTruncatedLineCount = std::min<CFIndex>(maximumLineCount - 1, lineCount); 1593 1596 for (; lineIndex < nonTruncatedLineCount; ++lineIndex) 1594 addLine( (CTLineRef)CFArrayGetValueAtIndex(ctLines, lineIndex));1597 addLine(font, (CTLineRef)CFArrayGetValueAtIndex(ctLines, lineIndex)); 1595 1598 1596 1599 if (lineIndex == lineCount) … … 1612 1615 truncatedLine = remainingLine; 1613 1616 1614 addLine( truncatedLine.get());1617 addLine(font, truncatedLine.get()); 1615 1618 } 1616 1619 … … 1626 1629 RetainPtr<NSAttributedString> attributedText = adoptNS([[NSAttributedString alloc] initWithString:text attributes:textAttributes]); 1627 1630 1628 addLine( adoptCF(CTLineCreateWithAttributedString((CFAttributedStringRef)attributedText.get())).get());1631 addLine(font, adoptCF(CTLineCreateWithAttributedString((CFAttributedStringRef)attributedText.get())).get()); 1629 1632 } 1630 1633 … … 1767 1770 static void paintAttachmentText(GraphicsContext& context, RenderAttachmentInfo& info) 1768 1771 { 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); 1778 1776 } 1779 1777
Note:
See TracChangeset
for help on using the changeset viewer.