Title: [234368] trunk/Source/WebCore
Revision
234368
Author
[email protected]
Date
2018-07-30 09:36:42 -0700 (Mon, 30 Jul 2018)

Log Message

Shrink GraphicsLayer by making m_transform and m_childrenTransform be unique_ptrs
https://bugs.webkit.org/show_bug.cgi?id=188143

Reviewed by Zalan Bujtas.

m_transform and m_childrenTransform are usually identity; save space by making
these unique_ptrs. The getters still return references by returning a reference
to a NeverDestroyed<TransformationMatrix> if necessary.

Shrinks GraphicsLayerCA from 840 to 640 bytes.

* platform/graphics/GraphicsLayer.cpp:
(WebCore::identityTransform):
(WebCore::GraphicsLayer::transform const):
(WebCore::GraphicsLayer::setTransform):
(WebCore::GraphicsLayer::childrenTransform const):
(WebCore::GraphicsLayer::setChildrenTransform):
(WebCore::GraphicsLayer::dumpProperties const):
* platform/graphics/GraphicsLayer.h:
(WebCore::GraphicsLayer::hasNonIdentityTransform const):
(WebCore::GraphicsLayer::hasNonIdentityChildrenTransform const):
(WebCore::GraphicsLayer::transform const): Deleted.
(WebCore::GraphicsLayer::setTransform): Deleted.
(WebCore::GraphicsLayer::childrenTransform const): Deleted.
(WebCore::GraphicsLayer::setChildrenTransform): Deleted.
(WebCore::GraphicsLayer::hasFlattenedPerspectiveTransform): Deleted. It was unused.
* platform/graphics/ca/GraphicsLayerCA.cpp:
(WebCore::GraphicsLayerCA::setTransform):
(WebCore::GraphicsLayerCA::setChildrenTransform):
(WebCore::GraphicsLayerCA::layerTransform const):
(WebCore::GraphicsLayerCA::updateTransform):
(WebCore::GraphicsLayerCA::updateChildrenTransform):
(WebCore::GraphicsLayerCA::removeCAAnimationFromLayer):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (234367 => 234368)


--- trunk/Source/WebCore/ChangeLog	2018-07-30 15:56:29 UTC (rev 234367)
+++ trunk/Source/WebCore/ChangeLog	2018-07-30 16:36:42 UTC (rev 234368)
@@ -1,3 +1,39 @@
+2018-07-29  Simon Fraser  <[email protected]>
+
+        Shrink GraphicsLayer by making m_transform and m_childrenTransform be unique_ptrs
+        https://bugs.webkit.org/show_bug.cgi?id=188143
+
+        Reviewed by Zalan Bujtas.
+
+        m_transform and m_childrenTransform are usually identity; save space by making
+        these unique_ptrs. The getters still return references by returning a reference
+        to a NeverDestroyed<TransformationMatrix> if necessary.
+        
+        Shrinks GraphicsLayerCA from 840 to 640 bytes.
+
+        * platform/graphics/GraphicsLayer.cpp:
+        (WebCore::identityTransform):
+        (WebCore::GraphicsLayer::transform const):
+        (WebCore::GraphicsLayer::setTransform):
+        (WebCore::GraphicsLayer::childrenTransform const):
+        (WebCore::GraphicsLayer::setChildrenTransform):
+        (WebCore::GraphicsLayer::dumpProperties const):
+        * platform/graphics/GraphicsLayer.h:
+        (WebCore::GraphicsLayer::hasNonIdentityTransform const):
+        (WebCore::GraphicsLayer::hasNonIdentityChildrenTransform const):
+        (WebCore::GraphicsLayer::transform const): Deleted.
+        (WebCore::GraphicsLayer::setTransform): Deleted.
+        (WebCore::GraphicsLayer::childrenTransform const): Deleted.
+        (WebCore::GraphicsLayer::setChildrenTransform): Deleted.
+        (WebCore::GraphicsLayer::hasFlattenedPerspectiveTransform): Deleted. It was unused.
+        * platform/graphics/ca/GraphicsLayerCA.cpp:
+        (WebCore::GraphicsLayerCA::setTransform):
+        (WebCore::GraphicsLayerCA::setChildrenTransform):
+        (WebCore::GraphicsLayerCA::layerTransform const):
+        (WebCore::GraphicsLayerCA::updateTransform):
+        (WebCore::GraphicsLayerCA::updateChildrenTransform):
+        (WebCore::GraphicsLayerCA::removeCAAnimationFromLayer):
+
 2018-07-30  Thibault Saunier  <[email protected]>
 
         [GStreamer] Make codecparsers optionnal

Modified: trunk/Source/WebCore/platform/graphics/GraphicsLayer.cpp (234367 => 234368)


--- trunk/Source/WebCore/platform/graphics/GraphicsLayer.cpp	2018-07-30 15:56:29 UTC (rev 234367)
+++ trunk/Source/WebCore/platform/graphics/GraphicsLayer.cpp	2018-07-30 16:36:42 UTC (rev 234368)
@@ -306,6 +306,38 @@
     }
 }
 
+static const TransformationMatrix& identityTransform()
+{
+    static NeverDestroyed<TransformationMatrix> identityTransform;
+    return identityTransform;
+}
+
+const TransformationMatrix& GraphicsLayer::transform() const
+{
+    return m_transform ? *m_transform : identityTransform();
+}
+
+void GraphicsLayer::setTransform(const TransformationMatrix& matrix)
+{
+    if (m_transform)
+        *m_transform = matrix;
+    else
+        m_transform = std::make_unique<TransformationMatrix>(matrix);
+}
+
+const TransformationMatrix& GraphicsLayer::childrenTransform() const
+{
+    return m_childrenTransform ? *m_childrenTransform : identityTransform();
+}
+
+void GraphicsLayer::setChildrenTransform(const TransformationMatrix& matrix)
+{
+    if (m_childrenTransform)
+        *m_childrenTransform = matrix;
+    else
+        m_childrenTransform = std::make_unique<TransformationMatrix>(matrix);
+}
+
 void GraphicsLayer::setMaskLayer(GraphicsLayer* layer)
 {
     if (layer == m_maskLayer)
@@ -789,22 +821,22 @@
     if (behavior & LayerTreeAsTextIncludeBackingStoreAttached)
         ts << indent << "(backingStoreAttached " << backingStoreAttachedForTesting() << ")\n";
 
-    if (!m_transform.isIdentity()) {
+    if (m_transform && !m_transform->isIdentity()) {
         ts << indent << "(transform ";
-        ts << "[" << m_transform.m11() << " " << m_transform.m12() << " " << m_transform.m13() << " " << m_transform.m14() << "] ";
-        ts << "[" << m_transform.m21() << " " << m_transform.m22() << " " << m_transform.m23() << " " << m_transform.m24() << "] ";
-        ts << "[" << m_transform.m31() << " " << m_transform.m32() << " " << m_transform.m33() << " " << m_transform.m34() << "] ";
-        ts << "[" << m_transform.m41() << " " << m_transform.m42() << " " << m_transform.m43() << " " << m_transform.m44() << "])\n";
+        ts << "[" << m_transform->m11() << " " << m_transform->m12() << " " << m_transform->m13() << " " << m_transform->m14() << "] ";
+        ts << "[" << m_transform->m21() << " " << m_transform->m22() << " " << m_transform->m23() << " " << m_transform->m24() << "] ";
+        ts << "[" << m_transform->m31() << " " << m_transform->m32() << " " << m_transform->m33() << " " << m_transform->m34() << "] ";
+        ts << "[" << m_transform->m41() << " " << m_transform->m42() << " " << m_transform->m43() << " " << m_transform->m44() << "])\n";
     }
 
     // Avoid dumping the sublayer transform on the root layer, because it's used for geometry flipping, whose behavior
     // differs between platforms.
-    if (parent() && !m_childrenTransform.isIdentity()) {
+    if (parent() && m_childrenTransform && !m_childrenTransform->isIdentity()) {
         ts << indent << "(childrenTransform ";
-        ts << "[" << m_childrenTransform.m11() << " " << m_childrenTransform.m12() << " " << m_childrenTransform.m13() << " " << m_childrenTransform.m14() << "] ";
-        ts << "[" << m_childrenTransform.m21() << " " << m_childrenTransform.m22() << " " << m_childrenTransform.m23() << " " << m_childrenTransform.m24() << "] ";
-        ts << "[" << m_childrenTransform.m31() << " " << m_childrenTransform.m32() << " " << m_childrenTransform.m33() << " " << m_childrenTransform.m34() << "] ";
-        ts << "[" << m_childrenTransform.m41() << " " << m_childrenTransform.m42() << " " << m_childrenTransform.m43() << " " << m_childrenTransform.m44() << "])\n";
+        ts << "[" << m_childrenTransform->m11() << " " << m_childrenTransform->m12() << " " << m_childrenTransform->m13() << " " << m_childrenTransform->m14() << "] ";
+        ts << "[" << m_childrenTransform->m21() << " " << m_childrenTransform->m22() << " " << m_childrenTransform->m23() << " " << m_childrenTransform->m24() << "] ";
+        ts << "[" << m_childrenTransform->m31() << " " << m_childrenTransform->m32() << " " << m_childrenTransform->m33() << " " << m_childrenTransform->m34() << "] ";
+        ts << "[" << m_childrenTransform->m41() << " " << m_childrenTransform->m42() << " " << m_childrenTransform->m43() << " " << m_childrenTransform->m44() << "])\n";
     }
 
     if (m_maskLayer) {

Modified: trunk/Source/WebCore/platform/graphics/GraphicsLayer.h (234367 => 234368)


--- trunk/Source/WebCore/platform/graphics/GraphicsLayer.h	2018-07-30 15:56:29 UTC (rev 234367)
+++ trunk/Source/WebCore/platform/graphics/GraphicsLayer.h	2018-07-30 16:36:42 UTC (rev 234368)
@@ -339,11 +339,13 @@
     // For platforms that move underlying platform layers on a different thread for scrolling; just update the GraphicsLayer state.
     virtual void syncBoundsOrigin(const FloatPoint& origin) { m_boundsOrigin = origin; }
 
-    const TransformationMatrix& transform() const { return m_transform; }
-    virtual void setTransform(const TransformationMatrix& t) { m_transform = t; }
+    const TransformationMatrix& transform() const;
+    virtual void setTransform(const TransformationMatrix&);
+    bool hasNonIdentityTransform() const { return m_transform && !m_transform->isIdentity(); }
 
-    const TransformationMatrix& childrenTransform() const { return m_childrenTransform; }
-    virtual void setChildrenTransform(const TransformationMatrix& t) { m_childrenTransform = t; }
+    const TransformationMatrix& childrenTransform() const;
+    virtual void setChildrenTransform(const TransformationMatrix&);
+    bool hasNonIdentityChildrenTransform() const { return m_childrenTransform && !m_childrenTransform->isIdentity(); }
 
     bool preserves3D() const { return m_preserves3D; }
     virtual void setPreserves3D(bool b) { m_preserves3D = b; }
@@ -507,9 +509,6 @@
     WEBCORE_EXPORT virtual void distributeOpacity(float);
     WEBCORE_EXPORT virtual float accumulatedOpacity() const;
 
-#if PLATFORM(IOS)
-    bool hasFlattenedPerspectiveTransform() const { return !preserves3D() && m_childrenTransform.hasPerspective(); }
-#endif
     virtual FloatSize pixelAlignmentOffset() const { return FloatSize(); }
     
     virtual void setAppliesPageScale(bool appliesScale = true) { m_appliesPageScale = appliesScale; }
@@ -632,8 +631,8 @@
     FloatSize m_size;
     FloatPoint m_boundsOrigin;
 
-    TransformationMatrix m_transform;
-    TransformationMatrix m_childrenTransform;
+    std::unique_ptr<TransformationMatrix> m_transform;
+    std::unique_ptr<TransformationMatrix> m_childrenTransform;
 
     Color m_backgroundColor;
     float m_opacity;

Modified: trunk/Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp (234367 => 234368)


--- trunk/Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp	2018-07-30 15:56:29 UTC (rev 234367)
+++ trunk/Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp	2018-07-30 16:36:42 UTC (rev 234368)
@@ -647,7 +647,7 @@
 
 void GraphicsLayerCA::setTransform(const TransformationMatrix& t)
 {
-    if (t == m_transform)
+    if (t == transform())
         return;
 
     GraphicsLayer::setTransform(t);
@@ -656,7 +656,7 @@
 
 void GraphicsLayerCA::setChildrenTransform(const TransformationMatrix& t)
 {
-    if (t == m_childrenTransform)
+    if (t == childrenTransform())
         return;
 
     GraphicsLayer::setChildrenTransform(t);
@@ -1332,7 +1332,11 @@
     TransformationMatrix transform;
     transform.translate(position.x(), position.y());
 
-    TransformationMatrix currentTransform = customTransform ? *customTransform : m_transform;
+    TransformationMatrix currentTransform;
+    if (customTransform)
+        currentTransform = *customTransform;
+    else if (m_transform)
+        currentTransform = *m_transform;
     
     if (!currentTransform.isIdentity()) {
         FloatPoint3D absoluteAnchorPoint(anchorPoint());
@@ -1343,7 +1347,7 @@
     }
 
     if (GraphicsLayer* parentLayer = parent()) {
-        if (!parentLayer->childrenTransform().isIdentity()) {
+        if (parentLayer->hasNonIdentityChildrenTransform()) {
             FloatPoint3D parentAnchorPoint(parentLayer->anchorPoint());
             parentAnchorPoint.scale(parentLayer->size().width(), parentLayer->size().height(), 1);
 
@@ -2010,7 +2014,7 @@
 
 void GraphicsLayerCA::updateTransform()
 {
-    primaryLayer()->setTransform(m_transform);
+    primaryLayer()->setTransform(transform());
 
     if (LayerMap* layerCloneMap = primaryLayerClones()) {
         for (auto& clone : *layerCloneMap) {
@@ -2020,7 +2024,7 @@
                 // which we set up in replicatedLayerRoot().
                 currLayer->setTransform(TransformationMatrix());
             } else
-                currLayer->setTransform(m_transform);
+                currLayer->setTransform(transform());
         }
     }
 }
@@ -2027,11 +2031,11 @@
 
 void GraphicsLayerCA::updateChildrenTransform()
 {
-    primaryLayer()->setSublayerTransform(m_childrenTransform);
+    primaryLayer()->setSublayerTransform(childrenTransform());
 
     if (LayerMap* layerCloneMap = primaryLayerClones()) {
         for (auto& layer : layerCloneMap->values())
-            layer->setSublayerTransform(m_childrenTransform);
+            layer->setSublayerTransform(childrenTransform());
     }
 }
 
@@ -2916,7 +2920,7 @@
         return false;
     
     layer->removeAnimationForKey(animationID);
-    bug7311367Workaround(m_structuralLayer.get(), m_transform);
+    bug7311367Workaround(m_structuralLayer.get(), transform());
 
     if (LayerMap* layerCloneMap = animatedLayerClones(property)) {
         for (auto& clone : *layerCloneMap) {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to