- Revision
- 285620
- Author
- [email protected]
- Date
- 2021-11-10 22:12:07 -0800 (Wed, 10 Nov 2021)
Log Message
REGRESSION(r283863): `<attachment>` with a long `action` do not render correctly
https://bugs.webkit.org/show_bug.cgi?id=232645
<rdar://problem/84558377>
Reviewed by Myles C. Maxfield.
Source/WebCore:
Unlike the `DisplayList` concept in WebCore, when using `CGContextDelegateRef` (which is
what `DrawGlyphsRecorder` uses on Cocoa platforms) the callbacks for each action are only
told about the current state of all-the-things at the time of that action, not each of the
corresponding API-level calls that resulted in that final state (e.g. where `DisplayList`
would see separate `scale` and `rotate` calls, `CGContextDelegateRef` would only be able to
get the final calculated CTM). In order for `DrawGlyphsRecorder` to (re)generate WebCore
calls, it needs to have information about the starting state of the `CGContext` before any
actions are performed so it can at least derive some diff/idea of what happened.
This is further complicated by the fact that when drawing text CG separates the state of
all-the-things into two: the CTM and the text matrix. WebKit does not have this separation,
however, so it needs to combine the two into a single CTM, but only when dealing with text.
A new path (`drawNativeText`) was added in r283863 that allows `DrawGlyphsRecorder` to be
used directly with native text-related objects (e.g. `CTLineRef`) instead of objects/data
derived in WebCore. A result of this on Cocoa platforms is that now a single `drawNativeText`
can result in multiple `recordDrawGlyphs` invocations if the `CTLineRef` contains multiple
"groupings" of glyphs to draw (e.g. if a line is truncated with a "..." in the middle then
the three groups will be the remaining text before, the "..." and the remaining text after).
AFAICT before this new path it was never the case that the text matrix had a translate, only
rotate/skew/etc., meaning that when `DrawGlyphsRecorder` needed to convert from the CG's
computed glyph positions back into WebCore's glyph advances it could use the text matrix
since there would be no translation. With this new path, however, if a `drawNativeText` call
results in multiple `recordDrawGlyphs` then there will be a translation in the text matrix
to account for that. As such, we end up double counting the text matrix: once when we
(re)generate the CTM to give to WebCore and _again_ when we (re)compute the WebCore advances.
Since we've already counted the text matrix once, we don't need to do it again. Also, by
this point we've already modified WebCore's CTM, so we only really need to account for the
difference from the original position when we first called `drawNativeText`. As such, we
just need invert what was used to generate CG positions from WebCore advances.
Note that in the name of expediently fixing a regression, this change only considers
horizontal text as `<attachment>` are never drawn vertically. Fixing vertical text will be
done in a followup <https://webkit.org/b/232917>.
Test: fast/attachment/attachment-truncated-action.html
* platform/graphics/coretext/DrawGlyphsRecorderCoreText.cpp:
(WebCore::DrawGlyphsRecorder::recordDrawGlyphs):
* platform/graphics/FontCascade.h:
* platform/graphics/coretext/FontCascadeCoreText.cpp:
(WebCore::fillVectorWithHorizontalGlyphPositions):
(WebCore::fillVectorWithVerticalGlyphPositions):
Add a comment indicating the related nature of these functions with `DrawGlyphsRecorder::recordDrawGlyphs`.
Drive-by: `fillVectorWithHorizontalGlyphPositions` is only called by this class, so don't export it.
LayoutTests:
* fast/attachment/attachment-truncated-action.html: Added.
* fast/attachment/attachment-truncated-action-expected-mismatch.html: Added.
* TestExpectations:
* platform/ios/TestExpectations:
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (285619 => 285620)
--- trunk/LayoutTests/ChangeLog 2021-11-11 05:03:15 UTC (rev 285619)
+++ trunk/LayoutTests/ChangeLog 2021-11-11 06:12:07 UTC (rev 285620)
@@ -1,3 +1,17 @@
+2021-11-10 Devin Rousso <[email protected]>
+
+ REGRESSION(r283863): `<attachment>` with a long `action` do not render correctly
+ https://bugs.webkit.org/show_bug.cgi?id=232645
+ <rdar://problem/84558377>
+
+ Reviewed by Myles C. Maxfield.
+
+ * fast/attachment/attachment-truncated-action.html: Added.
+ * fast/attachment/attachment-truncated-action-expected-mismatch.html: Added.
+
+ * TestExpectations:
+ * platform/ios/TestExpectations:
+
2021-11-10 Said Abou-Hallawa <[email protected]>
[GPU Process] Make CSSFilter be a composite of FilterFunctions
Modified: trunk/LayoutTests/TestExpectations (285619 => 285620)
--- trunk/LayoutTests/TestExpectations 2021-11-11 05:03:15 UTC (rev 285619)
+++ trunk/LayoutTests/TestExpectations 2021-11-11 06:12:07 UTC (rev 285620)
@@ -226,6 +226,7 @@
fast/attachment/attachment-subtitle-resize.html [ Skip ]
# This test only makes sense on iOS
+fast/attachment/attachment-truncated-action.html [ Skip ]
fast/attachment/attachment-wrapping-action.html [ Skip ]
fast/attachment/attachment-borderless.html [ Skip ]
fast/attachment/attachment-dynamic-type.html [ Skip ]
Added: trunk/LayoutTests/fast/attachment/attachment-truncated-action-expected-mismatch.html (0 => 285620)
--- trunk/LayoutTests/fast/attachment/attachment-truncated-action-expected-mismatch.html (rev 0)
+++ trunk/LayoutTests/fast/attachment/attachment-truncated-action-expected-mismatch.html 2021-11-11 06:12:07 UTC (rev 285620)
@@ -0,0 +1 @@
+<div></div>
Added: trunk/LayoutTests/fast/attachment/attachment-truncated-action.html (0 => 285620)
--- trunk/LayoutTests/fast/attachment/attachment-truncated-action.html (rev 0)
+++ trunk/LayoutTests/fast/attachment/attachment-truncated-action.html 2021-11-11 06:12:07 UTC (rev 285620)
@@ -0,0 +1,6 @@
+<!DOCTYPE html><!-- webkit-test-runner [ AttachmentElementEnabled=true ] -->
+<html>
+<body>
+<attachment action="" is very very very very very very very very very very long action" title="title" style="clip-path: inset(45% 25% 40% 50%)"></attachment>
+</body>
+</html>
Modified: trunk/LayoutTests/platform/ios/TestExpectations (285619 => 285620)
--- trunk/LayoutTests/platform/ios/TestExpectations 2021-11-11 05:03:15 UTC (rev 285619)
+++ trunk/LayoutTests/platform/ios/TestExpectations 2021-11-11 06:12:07 UTC (rev 285620)
@@ -2411,6 +2411,7 @@
imported/w3c/web-platform-tests/dom/events/scrolling [ Pass ]
+fast/attachment/attachment-truncated-action.html [ Pass ]
fast/attachment/attachment-wrapping-action.html [ Pass ]
fast/attachment/attachment-borderless.html [ Pass ]
fast/attachment/attachment-dynamic-type.html [ Pass ]
Modified: trunk/Source/WebCore/ChangeLog (285619 => 285620)
--- trunk/Source/WebCore/ChangeLog 2021-11-11 05:03:15 UTC (rev 285619)
+++ trunk/Source/WebCore/ChangeLog 2021-11-11 06:12:07 UTC (rev 285620)
@@ -1,3 +1,60 @@
+2021-11-10 Devin Rousso <[email protected]>
+
+ REGRESSION(r283863): `<attachment>` with a long `action` do not render correctly
+ https://bugs.webkit.org/show_bug.cgi?id=232645
+ <rdar://problem/84558377>
+
+ Reviewed by Myles C. Maxfield.
+
+ Unlike the `DisplayList` concept in WebCore, when using `CGContextDelegateRef` (which is
+ what `DrawGlyphsRecorder` uses on Cocoa platforms) the callbacks for each action are only
+ told about the current state of all-the-things at the time of that action, not each of the
+ corresponding API-level calls that resulted in that final state (e.g. where `DisplayList`
+ would see separate `scale` and `rotate` calls, `CGContextDelegateRef` would only be able to
+ get the final calculated CTM). In order for `DrawGlyphsRecorder` to (re)generate WebCore
+ calls, it needs to have information about the starting state of the `CGContext` before any
+ actions are performed so it can at least derive some diff/idea of what happened.
+
+ This is further complicated by the fact that when drawing text CG separates the state of
+ all-the-things into two: the CTM and the text matrix. WebKit does not have this separation,
+ however, so it needs to combine the two into a single CTM, but only when dealing with text.
+
+ A new path (`drawNativeText`) was added in r283863 that allows `DrawGlyphsRecorder` to be
+ used directly with native text-related objects (e.g. `CTLineRef`) instead of objects/data
+ derived in WebCore. A result of this on Cocoa platforms is that now a single `drawNativeText`
+ can result in multiple `recordDrawGlyphs` invocations if the `CTLineRef` contains multiple
+ "groupings" of glyphs to draw (e.g. if a line is truncated with a "..." in the middle then
+ the three groups will be the remaining text before, the "..." and the remaining text after).
+
+ AFAICT before this new path it was never the case that the text matrix had a translate, only
+ rotate/skew/etc., meaning that when `DrawGlyphsRecorder` needed to convert from the CG's
+ computed glyph positions back into WebCore's glyph advances it could use the text matrix
+ since there would be no translation. With this new path, however, if a `drawNativeText` call
+ results in multiple `recordDrawGlyphs` then there will be a translation in the text matrix
+ to account for that. As such, we end up double counting the text matrix: once when we
+ (re)generate the CTM to give to WebCore and _again_ when we (re)compute the WebCore advances.
+
+ Since we've already counted the text matrix once, we don't need to do it again. Also, by
+ this point we've already modified WebCore's CTM, so we only really need to account for the
+ difference from the original position when we first called `drawNativeText`. As such, we
+ just need invert what was used to generate CG positions from WebCore advances.
+
+ Note that in the name of expediently fixing a regression, this change only considers
+ horizontal text as `<attachment>` are never drawn vertically. Fixing vertical text will be
+ done in a followup <https://webkit.org/b/232917>.
+
+ Test: fast/attachment/attachment-truncated-action.html
+
+ * platform/graphics/coretext/DrawGlyphsRecorderCoreText.cpp:
+ (WebCore::DrawGlyphsRecorder::recordDrawGlyphs):
+
+ * platform/graphics/FontCascade.h:
+ * platform/graphics/coretext/FontCascadeCoreText.cpp:
+ (WebCore::fillVectorWithHorizontalGlyphPositions):
+ (WebCore::fillVectorWithVerticalGlyphPositions):
+ Add a comment indicating the related nature of these functions with `DrawGlyphsRecorder::recordDrawGlyphs`.
+ Drive-by: `fillVectorWithHorizontalGlyphPositions` is only called by this class, so don't export it.
+
2021-11-10 Said Abou-Hallawa <[email protected]>
[GPU Process] Make CSSFilter be a composite of FilterFunctions
Modified: trunk/Source/WebCore/platform/graphics/FontCascade.h (285619 => 285620)
--- trunk/Source/WebCore/platform/graphics/FontCascade.h 2021-11-11 05:03:15 UTC (rev 285619)
+++ trunk/Source/WebCore/platform/graphics/FontCascade.h 2021-11-11 06:12:07 UTC (rev 285620)
@@ -91,7 +91,6 @@
};
#if USE(CORE_TEXT)
-void fillVectorWithHorizontalGlyphPositions(Vector<CGPoint, 256>& positions, CGContextRef, const CGSize* advances, unsigned count, const FloatPoint&);
AffineTransform computeOverallTextMatrix(const Font&);
AffineTransform computeVerticalTextMatrix(const Font&, const AffineTransform& previousTextMatrix);
#endif
Modified: trunk/Source/WebCore/platform/graphics/coretext/DrawGlyphsRecorderCoreText.cpp (285619 => 285620)
--- trunk/Source/WebCore/platform/graphics/coretext/DrawGlyphsRecorderCoreText.cpp 2021-11-11 05:03:15 UTC (rev 285619)
+++ trunk/Source/WebCore/platform/graphics/coretext/DrawGlyphsRecorderCoreText.cpp 2021-11-11 06:12:07 UTC (rev 285620)
@@ -333,8 +333,19 @@
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);
+ // The above does the work of ensuring the right CTM (which is the combination of CG's CTM and
+ // CG's text matrix) is set for the replayer, but in order to provide the right values to
+ // `FontCascade::drawGlyphs` we need to recalculate the original advances from the resulting
+ // positions by inverting the operations applied to the original advances.
+ auto textMatrix = m_originalTextMatrix;
+ if (font->platformData().orientation() == FontOrientation::Vertical) {
+ // Keep this in sync as the inverse of `fillVectorWithVerticalGlyphPositions`.
+ // FIXME: <https://webkit.org/b/232917> (`DrawGlyphsRecorder` should be able to record+replay vertical text)
+ }
+
+ m_owner.drawGlyphsAndCacheFont(font, glyphs, computeAdvancesFromPositions(positions, count, textMatrix).data(), count, textMatrix.mapPoint(positions[0]), m_smoothingMode);
+
m_owner.concatCTM(inverseCTMFixup);
}
Modified: trunk/Source/WebCore/platform/graphics/coretext/FontCascadeCoreText.cpp (285619 => 285620)
--- trunk/Source/WebCore/platform/graphics/coretext/FontCascadeCoreText.cpp 2021-11-11 05:03:15 UTC (rev 285619)
+++ trunk/Source/WebCore/platform/graphics/coretext/FontCascadeCoreText.cpp 2021-11-11 06:12:07 UTC (rev 285620)
@@ -118,8 +118,9 @@
#endif
}
-void fillVectorWithHorizontalGlyphPositions(Vector<CGPoint, 256>& positions, CGContextRef context, const CGSize* advances, unsigned count, const FloatPoint& point)
+static void fillVectorWithHorizontalGlyphPositions(Vector<CGPoint, 256>& positions, CGContextRef context, const CGSize* advances, unsigned count, const FloatPoint& point)
{
+ // Keep this in sync as the inverse of `DrawGlyphsRecorder::recordDrawGlyphs`.
// The input positions are in the context's coordinate system, without the text matrix.
// However, the positions that CT/CG accept are in the text matrix's coordinate system.
// CGContextGetTextMatrix() gives us the matrix that maps from text's coordinate system to the context's (non-text) coordinate system.
@@ -139,6 +140,7 @@
static void fillVectorWithVerticalGlyphPositions(Vector<CGPoint, 256>& positions, CGContextRef context, const CGSize* translations, const CGSize* advances, unsigned count, const FloatPoint& point, float ascentDelta)
{
+ // Keep this in sync as the inverse of `DrawGlyphsRecorder::recordDrawGlyphs`.
CGAffineTransform transform = CGAffineTransformInvert(CGContextGetTextMatrix(context));
auto position = CGPointMake(point.x(), point.y() + ascentDelta);