[chromium] Track property changes for render surfaces.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 17 Nov 2011 00:59:48 +0000 (00:59 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 17 Nov 2011 00:59:48 +0000 (00:59 +0000)
https://bugs.webkit.org/show_bug.cgi?id=72521

Patch by Shawn Singh <shawnsingh@chromium.org> on 2011-11-16
Reviewed by James Robinson.

Source/WebCore:

Created CCRenderSurfaceTest for testing.

* platform/graphics/chromium/LayerRendererChromium.cpp:
(WebCore::LayerRendererChromium::drawLayersOntoRenderSurfaces):
* platform/graphics/chromium/cc/CCLayerImpl.cpp:
(WebCore::CCLayerImpl::resetPropertyChangedFlagForSubtree):
* platform/graphics/chromium/cc/CCLayerImpl.h:
* platform/graphics/chromium/cc/CCRenderSurface.cpp:
(WebCore::CCRenderSurface::CCRenderSurface):
(WebCore::CCRenderSurface::setClipRect):
(WebCore::CCRenderSurface::setContentRect):
(WebCore::CCRenderSurface::surfacePropertyChanged):
* platform/graphics/chromium/cc/CCRenderSurface.h:
(WebCore::CCRenderSurface::resetPropertyChangedFlag):

Source/WebKit/chromium:

* WebKit.gypi:
* tests/CCLayerImplTest.cpp:
(WebCore::TEST):
* tests/CCRenderSurfaceTest.cpp: Added.
(WebCore::TEST):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@100530 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/chromium/LayerRendererChromium.cpp
Source/WebCore/platform/graphics/chromium/cc/CCLayerImpl.cpp
Source/WebCore/platform/graphics/chromium/cc/CCLayerImpl.h
Source/WebCore/platform/graphics/chromium/cc/CCRenderSurface.cpp
Source/WebCore/platform/graphics/chromium/cc/CCRenderSurface.h
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/WebKit.gypi
Source/WebKit/chromium/tests/CCLayerImplTest.cpp
Source/WebKit/chromium/tests/CCRenderSurfaceTest.cpp [new file with mode: 0644]

index 4128ca638d011cecac4e984d5f2e81472c291042..55973c1f73055c1ac8311659e9386ea8bd764399 100644 (file)
@@ -1,3 +1,25 @@
+2011-11-16  Shawn Singh  <shawnsingh@chromium.org>
+
+        [chromium] Track property changes for render surfaces.
+        https://bugs.webkit.org/show_bug.cgi?id=72521
+
+        Reviewed by James Robinson.
+
+        Created CCRenderSurfaceTest for testing.
+
+        * platform/graphics/chromium/LayerRendererChromium.cpp:
+        (WebCore::LayerRendererChromium::drawLayersOntoRenderSurfaces):
+        * platform/graphics/chromium/cc/CCLayerImpl.cpp:
+        (WebCore::CCLayerImpl::resetPropertyChangedFlagForSubtree):
+        * platform/graphics/chromium/cc/CCLayerImpl.h:
+        * platform/graphics/chromium/cc/CCRenderSurface.cpp:
+        (WebCore::CCRenderSurface::CCRenderSurface):
+        (WebCore::CCRenderSurface::setClipRect):
+        (WebCore::CCRenderSurface::setContentRect):
+        (WebCore::CCRenderSurface::surfacePropertyChanged):
+        * platform/graphics/chromium/cc/CCRenderSurface.h:
+        (WebCore::CCRenderSurface::resetPropertyChangedFlag):
+
 2011-11-16  Ben Wells  <benwells@chromium.org>
 
         Seaming on border corners with mixed colour alpha borders
index bc9f000c222668af8a7a6da754d2d60c6b180bc3..0038a05a156c4cfa1b4b7be52a63e01eb96a0690 100644 (file)
@@ -343,6 +343,9 @@ void LayerRendererChromium::drawLayersOntoRenderSurfaces(CCLayerImpl* rootDrawLa
                 drawLayer(layerList[layerIndex].get(), renderSurface);
         }
     }
+
+    // The next frame should start by assuming nothing has changed, and changes are noted as they occur.
+    rootDrawLayer->resetPropertyChangedFlagForSubtree();
 }
 
 
index 5dba9d0bfa2213a22c3255ab4f06e12c73b595b7..1ab2e7e8e67786137a39a871525cbb58b9b30f25 100644 (file)
@@ -239,6 +239,17 @@ void CCLayerImpl::noteLayerPropertyChangedForDescendants()
         m_children[i]->noteLayerPropertyChangedForSubtree();
 }
 
+void CCLayerImpl::resetPropertyChangedFlagForSubtree()
+{
+    m_layerPropertyChanged = false;
+
+    if (m_renderSurface)
+        m_renderSurface->resetPropertyChangedFlag();
+
+    for (size_t i = 0; i < m_children.size(); ++i)
+        m_children[i]->resetPropertyChangedFlagForSubtree();
+}
+
 void CCLayerImpl::setBounds(const IntSize& bounds)
 {
     if (m_bounds != bounds) {
index 099f4021ac8b103e46a2843c323b1b94287a6a5e..bf6b68e1e78207ce1ac6fcf26257fd97d4bd8241 100644 (file)
@@ -192,7 +192,7 @@ public:
     String layerTreeAsText() const;
 
     bool layerPropertyChanged() const { return m_layerPropertyChanged; }
-    void resetLayerPropertyChanged() { m_layerPropertyChanged = false; }
+    void resetPropertyChangedFlagForSubtree(); // also resets property change for existing render surfaces.
 
 protected:
     explicit CCLayerImpl(int);
index 47a76310bebc184d838daba39b33a06ff2fbf5cd..cb38fa860ce7b7c8aa2fc1b71892850e5dac51bd 100644 (file)
@@ -43,6 +43,7 @@ CCRenderSurface::CCRenderSurface(CCLayerImpl* owningLayer)
     : m_owningLayer(owningLayer)
     , m_maskLayer(0)
     , m_skipsDraw(false)
+    , m_surfacePropertyChanged(false)
     , m_drawOpacity(1)
 {
 }
@@ -235,5 +236,37 @@ int CCRenderSurface::owningLayerId() const
     return m_owningLayer ? m_owningLayer->id() : 0;
 }
 
+void CCRenderSurface::setClipRect(const IntRect& clipRect)
+{
+    if (m_clipRect == clipRect)
+        return;
+
+    m_surfacePropertyChanged = true;
+    m_clipRect = clipRect;
+}
+
+void CCRenderSurface::setContentRect(const IntRect& contentRect)
+{
+    if (m_contentRect == contentRect)
+        return;
+
+    m_surfacePropertyChanged = true;
+    m_contentRect = contentRect;
+}
+
+bool CCRenderSurface::surfacePropertyChanged() const
+{
+    // Surface property changes are tracked as follows:
+    //
+    // - m_surfacePropertyChanged is flagged when the clipRect or contentRect change. As
+    //   of now, these are the only two properties that can be affected by descendant layers.
+    //
+    // - all other property changes come from the owning layer (or some ancestor layer
+    //   that propagates its change to the owning layer).
+    //
+    ASSERT(m_owningLayer);
+    return m_surfacePropertyChanged || m_owningLayer->layerPropertyChanged();
+}
+
 }
 #endif // USE(ACCELERATED_COMPOSITING)
index d823a6696cbd894f361e77dbcc274893eb31083a..4bd4af858194268cf0c85d3a6a0d2d409e0ebcd8 100644 (file)
@@ -75,10 +75,10 @@ public:
     void setOriginTransform(const TransformationMatrix& originTransform) { m_originTransform = originTransform; }
     const TransformationMatrix& originTransform() const { return m_originTransform; }
 
-    void setClipRect(const IntRect& clipRect) { m_clipRect = clipRect; }
+    void setClipRect(const IntRect&);
     const IntRect& clipRect() const { return m_clipRect; }
 
-    void setContentRect(const IntRect& contentRect) { m_contentRect = contentRect; }
+    void setContentRect(const IntRect&);
     const IntRect& contentRect() const { return m_contentRect; }
 
     void setSkipsDraw(bool skipsDraw) { m_skipsDraw = skipsDraw; }
@@ -97,6 +97,10 @@ public:
     ManagedTexture* contentsTexture() const { return m_contentsTexture.get(); }
 
     int owningLayerId() const;
+
+    void resetPropertyChangedFlag() { m_surfacePropertyChanged = false; }
+    bool surfacePropertyChanged() const;
+
 private:
     void drawLayer(LayerRendererChromium*, CCLayerImpl*, const TransformationMatrix&);
     template <class T>
@@ -107,6 +111,7 @@ private:
 
     IntRect m_contentRect;
     bool m_skipsDraw;
+    bool m_surfacePropertyChanged;
 
     OwnPtr<ManagedTexture> m_contentsTexture;
     float m_drawOpacity;
index 1c2ecae3a3f67b615db9e298b72276c643bd67a9..5c3154fcca40822c5ca2d034a7b58c025108350f 100644 (file)
@@ -1,3 +1,16 @@
+2011-11-16  Shawn Singh  <shawnsingh@chromium.org>
+
+        [chromium] Track property changes for render surfaces.
+        https://bugs.webkit.org/show_bug.cgi?id=72521
+
+        Reviewed by James Robinson.
+
+        * WebKit.gypi:
+        * tests/CCLayerImplTest.cpp:
+        (WebCore::TEST):
+        * tests/CCRenderSurfaceTest.cpp: Added.
+        (WebCore::TEST):
+
 2011-11-16  Alexandre Elias  <aelias@google.com>
 
         [chromium] Improvements for page scale delta during commit
index cc2ba191e404c9a93c8f9e973e12d554b8f691b7..0f598e78a9868831e82a2f5c882d4f384cfbc605 100644 (file)
@@ -61,6 +61,7 @@
             'tests/CCLayerTreeHostCommonTest.cpp',
             'tests/CCLayerTreeHostImplTest.cpp',
             'tests/CCLayerTreeHostTest.cpp',
+            'tests/CCRenderSurfaceTest.cpp',
             'tests/CCSchedulerTest.cpp',
             'tests/CCSchedulerStateMachineTest.cpp',
             'tests/CCSchedulerTestCommon.h',
index 06dc6c1df385d5fab0cab57f4d06cf5ff5440f47..942bec2f713a284521baa943eccc44e20b8ac5ff 100644 (file)
@@ -35,27 +35,21 @@ using namespace WebCore;
 namespace {
 
 #define EXECUTE_AND_VERIFY_SUBTREE_CHANGED(codeToTest)                  \
-    root->resetLayerPropertyChanged();                                  \
-    child->resetLayerPropertyChanged();                                 \
-    grandChild->resetLayerPropertyChanged();                            \
+    root->resetPropertyChangedFlagForSubtree();                         \
     codeToTest;                                                         \
     EXPECT_TRUE(root->layerPropertyChanged());                          \
     EXPECT_TRUE(child->layerPropertyChanged());                         \
     EXPECT_TRUE(grandChild->layerPropertyChanged())
 
 #define EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(codeToTest)           \
-    root->resetLayerPropertyChanged();                                  \
-    child->resetLayerPropertyChanged();                                 \
-    grandChild->resetLayerPropertyChanged();                            \
+    root->resetPropertyChangedFlagForSubtree();                         \
     codeToTest;                                                         \
     EXPECT_FALSE(root->layerPropertyChanged());                         \
     EXPECT_FALSE(child->layerPropertyChanged());                        \
     EXPECT_FALSE(grandChild->layerPropertyChanged())
 
 #define EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(codeToTest)               \
-    root->resetLayerPropertyChanged();                                  \
-    child->resetLayerPropertyChanged();                                 \
-    grandChild->resetLayerPropertyChanged();                            \
+    root->resetPropertyChangedFlagForSubtree();                         \
     codeToTest;                                                         \
     EXPECT_TRUE(root->layerPropertyChanged());                          \
     EXPECT_FALSE(child->layerPropertyChanged());                        \
@@ -121,9 +115,7 @@ TEST(CCLayerImplTest, verifyLayerChangesAreTrackedProperly)
     EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(root->setBackgroundColor(Color::gray));
 
     // Special case: check that sublayer transform changes all layer's descendants, but not the layer itself.
-    root->resetLayerPropertyChanged();
-    child->resetLayerPropertyChanged();
-    grandChild->resetLayerPropertyChanged();
+    root->resetPropertyChangedFlagForSubtree();
     root->setSublayerTransform(arbitraryTransform);
     EXPECT_FALSE(root->layerPropertyChanged());
     EXPECT_TRUE(child->layerPropertyChanged());
diff --git a/Source/WebKit/chromium/tests/CCRenderSurfaceTest.cpp b/Source/WebKit/chromium/tests/CCRenderSurfaceTest.cpp
new file mode 100644 (file)
index 0000000..704544b
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2011 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#include "cc/CCRenderSurface.h"
+
+#include "cc/CCLayerImpl.h"
+#include "cc/CCSingleThreadProxy.h"
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+using namespace WebCore;
+
+namespace {
+
+#define EXECUTE_AND_VERIFY_SURFACE_CHANGED(codeToTest)                  \
+    renderSurface->resetPropertyChangedFlag();                          \
+    codeToTest;                                                         \
+    EXPECT_TRUE(renderSurface->surfacePropertyChanged())
+
+#define EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(codeToTest)           \
+    renderSurface->resetPropertyChangedFlag();                          \
+    codeToTest;                                                         \
+    EXPECT_FALSE(renderSurface->surfacePropertyChanged())
+
+TEST(CCRenderSurfaceTest, verifySurfaceChangesAreTrackedProperly)
+{
+    //
+    // This test checks that surfacePropertyChanged() has the correct behavior.
+    //
+
+    // This will fake that we are on the correct thread for testing purposes.
+    DebugScopedSetImplThread setImplThread;
+
+    RefPtr<CCLayerImpl> owningLayer = CCLayerImpl::create(0);
+    owningLayer->createRenderSurface();
+    ASSERT_TRUE(owningLayer->renderSurface());
+    CCRenderSurface* renderSurface = owningLayer->renderSurface();
+    IntRect testRect = IntRect(IntPoint(3, 4), IntSize(5, 6));
+
+    owningLayer->resetPropertyChangedFlagForSubtree();
+
+    // Currently, the contentRect, clipRect, and owningLayer->layerPropertyChanged() are
+    // the only sources of change.
+    EXECUTE_AND_VERIFY_SURFACE_CHANGED(renderSurface->setClipRect(testRect));
+    EXECUTE_AND_VERIFY_SURFACE_CHANGED(renderSurface->setContentRect(testRect));
+
+    owningLayer->resetPropertyChangedFlagForSubtree();
+    owningLayer->setOpacity(0.5f);
+    EXPECT_TRUE(renderSurface->surfacePropertyChanged());
+    owningLayer->resetPropertyChangedFlagForSubtree();
+
+    // Setting the surface properties to the same values again should not be considered "change".
+    EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->setClipRect(testRect));
+    EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->setContentRect(testRect));
+
+    RefPtr<CCLayerImpl> dummyMask = CCLayerImpl::create(1);
+    TransformationMatrix dummyMatrix;
+    dummyMatrix.translate(1.0, 2.0);
+
+    // The rest of the surface properties are either internal and should not cause change,
+    // or they are already accounted for by the owninglayer->layerPropertyChanged().
+    EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->setDrawOpacity(0.5));
+    EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->setDrawTransform(dummyMatrix));
+    EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->setReplicaDrawTransform(dummyMatrix));
+    EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->setOriginTransform(dummyMatrix));
+    EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->setSkipsDraw(true));
+    EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->clearLayerList());
+    EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->setMaskLayer(dummyMask.get()));
+}
+
+} // namespace