Coordinated Graphics: A Minor optimization of calculating transforms in CoordinagedGraphicsLayer.
https://bugs.webkit.org/show_bug.cgi?id=102309

We calculate an inverse transform each tiledBackingStoreVisibleRect() call by
a TiledBackingStore and every tiles.
This patch caches the inverse transform to reuse it.

Patch by Huang Dongsung <luxtella@company100.net> on 2012-11-15
Reviewed by Noam Rosenthal.

* WebProcess/WebPage/CoordinatedGraphics/CoordinatedGraphicsLayer.cpp:
(WebCore::CoordinatedGraphicsLayer::tiledBackingStoreVisibleRect):
(WebCore::CoordinatedGraphicsLayer::computeTransformedVisibleRect):
* WebProcess/WebPage/CoordinatedGraphics/CoordinatedGraphicsLayer.h:
(CoordinatedGraphicsLayer):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@134868 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebKit2/ChangeLog b/Source/WebKit2/ChangeLog
index 51789e3..7c3d8a8 100644
--- a/Source/WebKit2/ChangeLog
+++ b/Source/WebKit2/ChangeLog
@@ -1,3 +1,20 @@
+2012-11-15  Huang Dongsung  <luxtella@company100.net>
+
+        Coordinated Graphics: A Minor optimization of calculating transforms in CoordinagedGraphicsLayer.
+        https://bugs.webkit.org/show_bug.cgi?id=102309
+
+        We calculate an inverse transform each tiledBackingStoreVisibleRect() call by
+        a TiledBackingStore and every tiles.
+        This patch caches the inverse transform to reuse it.
+
+        Reviewed by Noam Rosenthal.
+
+        * WebProcess/WebPage/CoordinatedGraphics/CoordinatedGraphicsLayer.cpp:
+        (WebCore::CoordinatedGraphicsLayer::tiledBackingStoreVisibleRect):
+        (WebCore::CoordinatedGraphicsLayer::computeTransformedVisibleRect):
+        * WebProcess/WebPage/CoordinatedGraphics/CoordinatedGraphicsLayer.h:
+        (CoordinatedGraphicsLayer):
+
 2012-11-15  Alec Flett  <alecflett@chromium.org>
 
         Add tests for explicit serialization values
diff --git a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedGraphicsLayer.cpp b/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedGraphicsLayer.cpp
index e9e2377..43e7d63 100644
--- a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedGraphicsLayer.cpp
+++ b/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedGraphicsLayer.cpp
@@ -656,7 +656,8 @@
     // Return a projection of the visible rect (surface coordinates) onto the layer's plane (layer coordinates).
     // The resulting quad might be squewed and the visible rect is the bounding box of this quad,
     // so it might spread further than the real visible area (and then even more amplified by the cover rect multiplier).
-    return enclosingIntRect(m_layerTransform.combined().inverse().clampedBoundsOfProjectedQuad(FloatQuad(FloatRect(m_coordinator->visibleContentsRect()))));
+    ASSERT(m_cachedInverseTransform == m_layerTransform.combined().inverse());
+    return enclosingIntRect(m_cachedInverseTransform.clampedBoundsOfProjectedQuad(FloatQuad(FloatRect(m_coordinator->visibleContentsRect()))));
 }
 
 Color CoordinatedGraphicsLayer::tiledBackingStoreBackgroundColor() const
@@ -765,6 +766,7 @@
     m_layerTransform.setFlattening(!preserves3D());
     m_layerTransform.setChildrenTransform(childrenTransform());
     m_layerTransform.combineTransforms(parent() ? toCoordinatedGraphicsLayer(parent())->m_layerTransform.combinedForChildren() : TransformationMatrix());
+    m_cachedInverseTransform = m_layerTransform.combined().inverse();
 
     // The combined transform will be used in tiledBackingStoreVisibleRect.
     adjustVisibleRect();
diff --git a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedGraphicsLayer.h b/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedGraphicsLayer.h
index 8bb81d6..2e94fe4 100644
--- a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedGraphicsLayer.h
+++ b/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedGraphicsLayer.h
@@ -198,6 +198,7 @@
     WebKit::WebLayerInfo m_layerInfo;
     GraphicsLayer* m_maskTarget;
     GraphicsLayerTransform m_layerTransform;
+    TransformationMatrix m_cachedInverseTransform;
     bool m_inUpdateMode : 1;
     bool m_shouldUpdateVisibleRect: 1;
     bool m_shouldSyncLayerState: 1;