Title: [253417] trunk
Revision
253417
Author
wenson_hs...@apple.com
Date
2019-12-11 19:49:14 -0800 (Wed, 11 Dec 2019)

Log Message

Implement DisplayListRecorder::Recorder::getCTM and DisplayListRecorder::Recorder::setCTM
https://bugs.webkit.org/show_bug.cgi?id=205139

Reviewed by Simon Fraser.

Source/WebCore:

Implements these two methods on Recorder, which are invoked from GraphicsContext::setCTM and
GraphicsContext::getCTM, respectively. See below for more details.

Additionally rebaselines displaylists/extent-includes-transforms.html.

* platform/graphics/displaylists/DisplayList.h:

Add a new type to represent the SetCTM display list item.

(WebCore::DisplayList::Item::isStateItemType):
* platform/graphics/displaylists/DisplayListItems.cpp:
(WebCore::DisplayList::Item::sizeInBytes):
(WebCore::DisplayList::SetCTM::SetCTM):
(WebCore::DisplayList::SetCTM::apply const):
(WebCore::DisplayList::operator<<):
* platform/graphics/displaylists/DisplayListItems.h:
(WebCore::DisplayList::SetCTM::create):
(WebCore::DisplayList::SetCTM::transform const):
(WebCore::DisplayList::SetCTM::encode const):
(WebCore::DisplayList::SetCTM::decode):
(WebCore::DisplayList::Item::encode const):
(WebCore::DisplayList::Item::decode):

Add DisplayList::SetCTM, which represents a call to set the current transformation matrix on the graphics
context. This is very similar to ConcatCTM.

* platform/graphics/displaylists/DisplayListRecorder.cpp:
(WebCore::DisplayList::Recorder::setCTM):

Set the current state's CTM to the new value. Additionally, update clipBounds by applying the inverse
transformation matrix of the inverse of the original CTM, multiplied by the new CTM. This is because setting
the CTM from to `B` from `A` is equivalent to multiplying `A` by `A_inverse * B`, so we want to map the clip
rect through the inverse of this matrix, `(A_inverse * B)_inverse`.

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

Return the current CTM by asking the topmost state on the stack, and ignore the IncludeDeviceScale flag for the
time being.

(WebCore::DisplayList::Recorder::ContextState::setCTM):
* platform/graphics/displaylists/DisplayListRecorder.h:

LayoutTests:

* displaylists/extent-includes-transforms-expected.txt:
* platform/mac-wk1/displaylists/extent-includes-transforms-expected.txt:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (253416 => 253417)


--- trunk/LayoutTests/ChangeLog	2019-12-12 02:24:29 UTC (rev 253416)
+++ trunk/LayoutTests/ChangeLog	2019-12-12 03:49:14 UTC (rev 253417)
@@ -1,3 +1,13 @@
+2019-12-11  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        Implement DisplayListRecorder::Recorder::getCTM and DisplayListRecorder::Recorder::setCTM
+        https://bugs.webkit.org/show_bug.cgi?id=205139
+
+        Reviewed by Simon Fraser.
+
+        * displaylists/extent-includes-transforms-expected.txt:
+        * platform/mac-wk1/displaylists/extent-includes-transforms-expected.txt:
+
 2019-12-11  Chris Dumez  <cdu...@apple.com>
 
         [Bindings] Cross-origin checks happen too late for overloaded methods

Modified: trunk/LayoutTests/displaylists/extent-includes-transforms-expected.txt (253416 => 253417)


--- trunk/LayoutTests/displaylists/extent-includes-transforms-expected.txt	2019-12-12 02:24:29 UTC (rev 253416)
+++ trunk/LayoutTests/displaylists/extent-includes-transforms-expected.txt	2019-12-12 03:49:14 UTC (rev 253417)
@@ -18,3 +18,5 @@
   (composite-operation source-over)
   (blend-mode normal))
 (restore)
+(set-ctm
+  (set-ctm {m=((1.00,0.00)(0.00,1.00)) t=(0.00,22.00)}))

Modified: trunk/LayoutTests/platform/mac-wk1/displaylists/extent-includes-transforms-expected.txt (253416 => 253417)


--- trunk/LayoutTests/platform/mac-wk1/displaylists/extent-includes-transforms-expected.txt	2019-12-12 02:24:29 UTC (rev 253416)
+++ trunk/LayoutTests/platform/mac-wk1/displaylists/extent-includes-transforms-expected.txt	2019-12-12 03:49:14 UTC (rev 253417)
@@ -19,3 +19,5 @@
   (composite-operation source-over)
   (blend-mode normal))
 (restore)
+(set-ctm
+  (set-ctm {m=((1.00,0.00)(0.00,1.00)) t=(0.00,22.00)}))

Modified: trunk/Source/WebCore/ChangeLog (253416 => 253417)


--- trunk/Source/WebCore/ChangeLog	2019-12-12 02:24:29 UTC (rev 253416)
+++ trunk/Source/WebCore/ChangeLog	2019-12-12 03:49:14 UTC (rev 253417)
@@ -1,3 +1,52 @@
+2019-12-11  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        Implement DisplayListRecorder::Recorder::getCTM and DisplayListRecorder::Recorder::setCTM
+        https://bugs.webkit.org/show_bug.cgi?id=205139
+
+        Reviewed by Simon Fraser.
+
+        Implements these two methods on Recorder, which are invoked from GraphicsContext::setCTM and
+        GraphicsContext::getCTM, respectively. See below for more details.
+
+        Additionally rebaselines displaylists/extent-includes-transforms.html.
+
+        * platform/graphics/displaylists/DisplayList.h:
+
+        Add a new type to represent the SetCTM display list item.
+
+        (WebCore::DisplayList::Item::isStateItemType):
+        * platform/graphics/displaylists/DisplayListItems.cpp:
+        (WebCore::DisplayList::Item::sizeInBytes):
+        (WebCore::DisplayList::SetCTM::SetCTM):
+        (WebCore::DisplayList::SetCTM::apply const):
+        (WebCore::DisplayList::operator<<):
+        * platform/graphics/displaylists/DisplayListItems.h:
+        (WebCore::DisplayList::SetCTM::create):
+        (WebCore::DisplayList::SetCTM::transform const):
+        (WebCore::DisplayList::SetCTM::encode const):
+        (WebCore::DisplayList::SetCTM::decode):
+        (WebCore::DisplayList::Item::encode const):
+        (WebCore::DisplayList::Item::decode):
+
+        Add DisplayList::SetCTM, which represents a call to set the current transformation matrix on the graphics
+        context. This is very similar to ConcatCTM.
+
+        * platform/graphics/displaylists/DisplayListRecorder.cpp:
+        (WebCore::DisplayList::Recorder::setCTM):
+
+        Set the current state's CTM to the new value. Additionally, update clipBounds by applying the inverse
+        transformation matrix of the inverse of the original CTM, multiplied by the new CTM. This is because setting
+        the CTM from to `B` from `A` is equivalent to multiplying `A` by `A_inverse * B`, so we want to map the clip
+        rect through the inverse of this matrix, `(A_inverse * B)_inverse`.
+
+        (WebCore::DisplayList::Recorder::getCTM):
+
+        Return the current CTM by asking the topmost state on the stack, and ignore the IncludeDeviceScale flag for the
+        time being.
+
+        (WebCore::DisplayList::Recorder::ContextState::setCTM):
+        * platform/graphics/displaylists/DisplayListRecorder.h:
+
 2019-12-11  Don Olmstead  <don.olmst...@sony.com>
 
         [CMake] Add OpenJPEG find module

Modified: trunk/Source/WebCore/platform/graphics/displaylists/DisplayList.h (253416 => 253417)


--- trunk/Source/WebCore/platform/graphics/displaylists/DisplayList.h	2019-12-12 02:24:29 UTC (rev 253416)
+++ trunk/Source/WebCore/platform/graphics/displaylists/DisplayList.h	2019-12-12 03:49:14 UTC (rev 253417)
@@ -46,6 +46,7 @@
     Rotate,
     Scale,
     ConcatenateCTM,
+    SetCTM,
     SetState,
     SetLineCap,
     SetLineDash,
@@ -124,6 +125,7 @@
         case ItemType::Rotate:
         case ItemType::Scale:
         case ItemType::ConcatenateCTM:
+        case ItemType::SetCTM:
         case ItemType::SetState:
         case ItemType::SetLineCap:
         case ItemType::SetLineDash:

Modified: trunk/Source/WebCore/platform/graphics/displaylists/DisplayListItems.cpp (253416 => 253417)


--- trunk/Source/WebCore/platform/graphics/displaylists/DisplayListItems.cpp	2019-12-12 02:24:29 UTC (rev 253416)
+++ trunk/Source/WebCore/platform/graphics/displaylists/DisplayListItems.cpp	2019-12-12 03:49:14 UTC (rev 253417)
@@ -68,6 +68,8 @@
         return sizeof(downcast<Rotate>(item));
     case ItemType::Scale:
         return sizeof(downcast<Scale>(item));
+    case ItemType::SetCTM:
+        return sizeof(downcast<SetCTM>(item));
     case ItemType::ConcatenateCTM:
         return sizeof(downcast<ConcatenateCTM>(item));
     case ItemType::SetState:
@@ -272,6 +274,26 @@
     return ts;
 }
 
+SetCTM::SetCTM(const AffineTransform& transform)
+    : Item(ItemType::SetCTM)
+    , m_transform(transform)
+{
+}
+
+SetCTM::~SetCTM() = default;
+
+void SetCTM::apply(GraphicsContext& context) const
+{
+    context.setCTM(m_transform);
+}
+
+static TextStream& operator<<(TextStream& ts, const SetCTM& item)
+{
+    ts.dumpProperty("set-ctm", item.transform());
+
+    return ts;
+}
+
 ConcatenateCTM::ConcatenateCTM(const AffineTransform& transform)
     : Item(ItemType::ConcatenateCTM)
     , m_transform(transform)
@@ -1308,6 +1330,7 @@
     case ItemType::Translate: ts << "translate"; break;
     case ItemType::Rotate: ts << "rotate"; break;
     case ItemType::Scale: ts << "scale"; break;
+    case ItemType::SetCTM: ts << "set-ctm"; break;
     case ItemType::ConcatenateCTM: ts << "concatentate-ctm"; break;
     case ItemType::SetState: ts << "set-state"; break;
     case ItemType::SetLineCap: ts << "set-line-cap"; break;
@@ -1377,6 +1400,9 @@
     case ItemType::Scale:
         ts << downcast<Scale>(item);
         break;
+    case ItemType::SetCTM:
+        ts << downcast<SetCTM>(item);
+        break;
     case ItemType::ConcatenateCTM:
         ts << downcast<ConcatenateCTM>(item);
         break;

Modified: trunk/Source/WebCore/platform/graphics/displaylists/DisplayListItems.h (253416 => 253417)


--- trunk/Source/WebCore/platform/graphics/displaylists/DisplayListItems.h	2019-12-12 02:24:29 UTC (rev 253416)
+++ trunk/Source/WebCore/platform/graphics/displaylists/DisplayListItems.h	2019-12-12 03:49:14 UTC (rev 253417)
@@ -264,6 +264,45 @@
     return Scale::create(*scale);
 }
 
+class SetCTM : public Item {
+public:
+    static Ref<SetCTM> create(const AffineTransform& matrix)
+    {
+        return adoptRef(*new SetCTM(matrix));
+    }
+
+    WEBCORE_EXPORT virtual ~SetCTM();
+
+    const AffineTransform& transform() const { return m_transform; }
+
+    template<class Encoder> void encode(Encoder&) const;
+    template<class Decoder> static Optional<Ref<SetCTM>> decode(Decoder&);
+
+private:
+    WEBCORE_EXPORT SetCTM(const AffineTransform&);
+
+    void apply(GraphicsContext&) const override;
+
+    AffineTransform m_transform;
+};
+
+template<class Encoder>
+void SetCTM::encode(Encoder& encoder) const
+{
+    encoder << m_transform;
+}
+
+template<class Decoder>
+Optional<Ref<SetCTM>> SetCTM::decode(Decoder& decoder)
+{
+    Optional<AffineTransform> transform;
+    decoder >> transform;
+    if (!transform)
+        return WTF::nullopt;
+
+    return SetCTM::create(*transform);
+}
+
 class ConcatenateCTM : public Item {
 public:
     static Ref<ConcatenateCTM> create(const AffineTransform& matrix)
@@ -2590,6 +2629,9 @@
     case ItemType::Scale:
         encoder << downcast<Scale>(*this);
         break;
+    case ItemType::SetCTM:
+        encoder << downcast<SetCTM>(*this);
+        break;
     case ItemType::ConcatenateCTM:
         encoder << downcast<ConcatenateCTM>(*this);
         break;
@@ -2752,6 +2794,10 @@
         if (auto item = Scale::decode(decoder))
             return static_reference_cast<Item>(WTFMove(*item));
         break;
+    case ItemType::SetCTM:
+        if (auto item = SetCTM::decode(decoder))
+            return static_reference_cast<Item>(WTFMove(*item));
+        break;
     case ItemType::ConcatenateCTM:
         if (auto item = ConcatenateCTM::decode(decoder))
             return static_reference_cast<Item>(WTFMove(*item));
@@ -2948,6 +2994,7 @@
 SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(Translate)
 SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(Rotate)
 SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(Scale)
+SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(SetCTM)
 SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(ConcatenateCTM)
 SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(SetState)
 SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(SetLineCap)

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


--- trunk/Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.cpp	2019-12-12 02:24:29 UTC (rev 253416)
+++ trunk/Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.cpp	2019-12-12 03:49:14 UTC (rev 253417)
@@ -196,15 +196,16 @@
     appendItem(ConcatenateCTM::create(transform));
 }
 
-void Recorder::setCTM(const AffineTransform&)
+void Recorder::setCTM(const AffineTransform& transform)
 {
-    WTFLogAlways("GraphicsContext::setCTM() is not compatible with DisplayList::Recorder.");
+    currentState().setCTM(transform);
+    appendItem(SetCTM::create(transform));
 }
 
 AffineTransform Recorder::getCTM(GraphicsContext::IncludeDeviceScale)
 {
-    WTFLogAlways("GraphicsContext::getCTM() is not yet compatible with DisplayList::Recorder.");
-    return { };
+    // FIXME: Respect the given value of IncludeDeviceScale.
+    return currentState().ctm;
 }
 
 void Recorder::beginTransparencyLayer(float opacity)
@@ -483,6 +484,18 @@
     clipBounds.scale(1 / size.width(), 1 / size.height());
 }
 
+void Recorder::ContextState::setCTM(const AffineTransform& matrix)
+{
+    Optional<AffineTransform> inverseTransformForClipBounds;
+    if (auto originalCTMInverse = ctm.inverse())
+        inverseTransformForClipBounds = originalCTMInverse->multiply(matrix).inverse();
+
+    ctm = matrix;
+
+    if (inverseTransformForClipBounds)
+        clipBounds = inverseTransformForClipBounds->mapRect(clipBounds);
+}
+
 void Recorder::ContextState::concatCTM(const AffineTransform& matrix)
 {
     ctm *= matrix;

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


--- trunk/Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.h	2019-12-12 02:24:29 UTC (rev 253416)
+++ trunk/Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.h	2019-12-12 03:49:14 UTC (rev 253417)
@@ -166,6 +166,7 @@
         void rotate(float angleInRadians);
         void scale(const FloatSize&);
         void concatCTM(const AffineTransform&);
+        void setCTM(const AffineTransform&);
     };
     
     const ContextState& currentState() const;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to