| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "CCDamageTracker.h" | 7 #include "CCDamageTracker.h" |
| 8 | 8 |
| 9 #include "CCLayerImpl.h" | 9 #include "CCLayerImpl.h" |
| 10 #include "CCLayerSorter.h" | 10 #include "CCLayerSorter.h" |
| 11 #include "CCLayerTreeHostCommon.h" | 11 #include "CCLayerTreeHostCommon.h" |
| 12 #include "CCMathUtil.h" | 12 #include "CCMathUtil.h" |
| 13 #include "CCSingleThreadProxy.h" | 13 #include "CCSingleThreadProxy.h" |
| 14 #include "cc/test/geometry_test_utils.h" | 14 #include "cc/test/geometry_test_utils.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include <public/WebFilterOperation.h> | 16 #include <public/WebFilterOperation.h> |
| 17 #include <public/WebFilterOperations.h> | 17 #include <public/WebFilterOperations.h> |
| 18 | 18 |
| 19 using namespace cc; | 19 using namespace cc; |
| 20 using namespace WebKit; | 20 using namespace WebKit; |
| 21 using namespace WebKitTests; | 21 using namespace WebKitTests; |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 void executeCalculateDrawTransformsAndVisibility(CCLayerImpl* root, std::vector<
CCLayerImpl*>& renderSurfaceLayerList) | 25 void executeCalculateDrawTransformsAndVisibility(LayerImpl* root, std::vector<La
yerImpl*>& renderSurfaceLayerList) |
| 26 { | 26 { |
| 27 CCLayerSorter layerSorter; | 27 LayerSorter layerSorter; |
| 28 int dummyMaxTextureSize = 512; | 28 int dummyMaxTextureSize = 512; |
| 29 | 29 |
| 30 // Sanity check: The test itself should create the root layer's render surfa
ce, so | 30 // Sanity check: The test itself should create the root layer's render surfa
ce, so |
| 31 // that the surface (and its damage tracker) can persist acros
s multiple | 31 // that the surface (and its damage tracker) can persist acros
s multiple |
| 32 // calls to this function. | 32 // calls to this function. |
| 33 ASSERT_TRUE(root->renderSurface()); | 33 ASSERT_TRUE(root->renderSurface()); |
| 34 ASSERT_FALSE(renderSurfaceLayerList.size()); | 34 ASSERT_FALSE(renderSurfaceLayerList.size()); |
| 35 | 35 |
| 36 CCLayerTreeHostCommon::calculateDrawTransforms(root, root->bounds(), 1, &lay
erSorter, dummyMaxTextureSize, renderSurfaceLayerList); | 36 LayerTreeHostCommon::calculateDrawTransforms(root, root->bounds(), 1, &layer
Sorter, dummyMaxTextureSize, renderSurfaceLayerList); |
| 37 } | 37 } |
| 38 | 38 |
| 39 void clearDamageForAllSurfaces(CCLayerImpl* layer) | 39 void clearDamageForAllSurfaces(LayerImpl* layer) |
| 40 { | 40 { |
| 41 if (layer->renderSurface()) | 41 if (layer->renderSurface()) |
| 42 layer->renderSurface()->damageTracker()->didDrawDamagedArea(); | 42 layer->renderSurface()->damageTracker()->didDrawDamagedArea(); |
| 43 | 43 |
| 44 // Recursively clear damage for any existing surface. | 44 // Recursively clear damage for any existing surface. |
| 45 for (size_t i = 0; i < layer->children().size(); ++i) | 45 for (size_t i = 0; i < layer->children().size(); ++i) |
| 46 clearDamageForAllSurfaces(layer->children()[i]); | 46 clearDamageForAllSurfaces(layer->children()[i]); |
| 47 } | 47 } |
| 48 | 48 |
| 49 void emulateDrawingOneFrame(CCLayerImpl* root) | 49 void emulateDrawingOneFrame(LayerImpl* root) |
| 50 { | 50 { |
| 51 // This emulates only the steps that are relevant to testing the damage trac
ker: | 51 // This emulates only the steps that are relevant to testing the damage trac
ker: |
| 52 // 1. computing the render passes and layerlists | 52 // 1. computing the render passes and layerlists |
| 53 // 2. updating all damage trackers in the correct order | 53 // 2. updating all damage trackers in the correct order |
| 54 // 3. resetting all updateRects and propertyChanged flags for all layers a
nd surfaces. | 54 // 3. resetting all updateRects and propertyChanged flags for all layers a
nd surfaces. |
| 55 | 55 |
| 56 std::vector<CCLayerImpl*> renderSurfaceLayerList; | 56 std::vector<LayerImpl*> renderSurfaceLayerList; |
| 57 executeCalculateDrawTransformsAndVisibility(root, renderSurfaceLayerList); | 57 executeCalculateDrawTransformsAndVisibility(root, renderSurfaceLayerList); |
| 58 | 58 |
| 59 // Iterate back-to-front, so that damage correctly propagates from descendan
t surfaces to ancestors. | 59 // Iterate back-to-front, so that damage correctly propagates from descendan
t surfaces to ancestors. |
| 60 for (int i = renderSurfaceLayerList.size() - 1; i >= 0; --i) { | 60 for (int i = renderSurfaceLayerList.size() - 1; i >= 0; --i) { |
| 61 CCRenderSurface* targetSurface = renderSurfaceLayerList[i]->renderSurfac
e(); | 61 RenderSurfaceImpl* targetSurface = renderSurfaceLayerList[i]->renderSurf
ace(); |
| 62 targetSurface->damageTracker()->updateDamageTrackingState(targetSurface-
>layerList(), targetSurface->owningLayerId(), targetSurface->surfacePropertyChan
gedOnlyFromDescendant(), targetSurface->contentRect(), renderSurfaceLayerList[i]
->maskLayer(), renderSurfaceLayerList[i]->filters()); | 62 targetSurface->damageTracker()->updateDamageTrackingState(targetSurface-
>layerList(), targetSurface->owningLayerId(), targetSurface->surfacePropertyChan
gedOnlyFromDescendant(), targetSurface->contentRect(), renderSurfaceLayerList[i]
->maskLayer(), renderSurfaceLayerList[i]->filters()); |
| 63 } | 63 } |
| 64 | 64 |
| 65 root->resetAllChangeTrackingForSubtree(); | 65 root->resetAllChangeTrackingForSubtree(); |
| 66 } | 66 } |
| 67 | 67 |
| 68 scoped_ptr<CCLayerImpl> createTestTreeWithOneSurface() | 68 scoped_ptr<LayerImpl> createTestTreeWithOneSurface() |
| 69 { | 69 { |
| 70 scoped_ptr<CCLayerImpl> root = CCLayerImpl::create(1); | 70 scoped_ptr<LayerImpl> root = LayerImpl::create(1); |
| 71 scoped_ptr<CCLayerImpl> child = CCLayerImpl::create(2); | 71 scoped_ptr<LayerImpl> child = LayerImpl::create(2); |
| 72 | 72 |
| 73 root->setPosition(FloatPoint::zero()); | 73 root->setPosition(FloatPoint::zero()); |
| 74 root->setAnchorPoint(FloatPoint::zero()); | 74 root->setAnchorPoint(FloatPoint::zero()); |
| 75 root->setBounds(IntSize(500, 500)); | 75 root->setBounds(IntSize(500, 500)); |
| 76 root->setContentBounds(IntSize(500, 500)); | 76 root->setContentBounds(IntSize(500, 500)); |
| 77 root->setDrawsContent(true); | 77 root->setDrawsContent(true); |
| 78 root->createRenderSurface(); | 78 root->createRenderSurface(); |
| 79 root->renderSurface()->setContentRect(IntRect(IntPoint(), IntSize(500, 500))
); | 79 root->renderSurface()->setContentRect(IntRect(IntPoint(), IntSize(500, 500))
); |
| 80 | 80 |
| 81 child->setPosition(FloatPoint(100, 100)); | 81 child->setPosition(FloatPoint(100, 100)); |
| 82 child->setAnchorPoint(FloatPoint::zero()); | 82 child->setAnchorPoint(FloatPoint::zero()); |
| 83 child->setBounds(IntSize(30, 30)); | 83 child->setBounds(IntSize(30, 30)); |
| 84 child->setContentBounds(IntSize(30, 30)); | 84 child->setContentBounds(IntSize(30, 30)); |
| 85 child->setDrawsContent(true); | 85 child->setDrawsContent(true); |
| 86 root->addChild(child.Pass()); | 86 root->addChild(child.Pass()); |
| 87 | 87 |
| 88 return root.Pass(); | 88 return root.Pass(); |
| 89 } | 89 } |
| 90 | 90 |
| 91 scoped_ptr<CCLayerImpl> createTestTreeWithTwoSurfaces() | 91 scoped_ptr<LayerImpl> createTestTreeWithTwoSurfaces() |
| 92 { | 92 { |
| 93 // This test tree has two render surfaces: one for the root, and one for | 93 // This test tree has two render surfaces: one for the root, and one for |
| 94 // child1. Additionally, the root has a second child layer, and child1 has t
wo | 94 // child1. Additionally, the root has a second child layer, and child1 has t
wo |
| 95 // children of its own. | 95 // children of its own. |
| 96 | 96 |
| 97 scoped_ptr<CCLayerImpl> root = CCLayerImpl::create(1); | 97 scoped_ptr<LayerImpl> root = LayerImpl::create(1); |
| 98 scoped_ptr<CCLayerImpl> child1 = CCLayerImpl::create(2); | 98 scoped_ptr<LayerImpl> child1 = LayerImpl::create(2); |
| 99 scoped_ptr<CCLayerImpl> child2 = CCLayerImpl::create(3); | 99 scoped_ptr<LayerImpl> child2 = LayerImpl::create(3); |
| 100 scoped_ptr<CCLayerImpl> grandChild1 = CCLayerImpl::create(4); | 100 scoped_ptr<LayerImpl> grandChild1 = LayerImpl::create(4); |
| 101 scoped_ptr<CCLayerImpl> grandChild2 = CCLayerImpl::create(5); | 101 scoped_ptr<LayerImpl> grandChild2 = LayerImpl::create(5); |
| 102 | 102 |
| 103 root->setPosition(FloatPoint::zero()); | 103 root->setPosition(FloatPoint::zero()); |
| 104 root->setAnchorPoint(FloatPoint::zero()); | 104 root->setAnchorPoint(FloatPoint::zero()); |
| 105 root->setBounds(IntSize(500, 500)); | 105 root->setBounds(IntSize(500, 500)); |
| 106 root->setContentBounds(IntSize(500, 500)); | 106 root->setContentBounds(IntSize(500, 500)); |
| 107 root->setDrawsContent(true); | 107 root->setDrawsContent(true); |
| 108 root->createRenderSurface(); | 108 root->createRenderSurface(); |
| 109 root->renderSurface()->setContentRect(IntRect(IntPoint(), IntSize(500, 500))
); | 109 root->renderSurface()->setContentRect(IntRect(IntPoint(), IntSize(500, 500))
); |
| 110 | 110 |
| 111 child1->setPosition(FloatPoint(100, 100)); | 111 child1->setPosition(FloatPoint(100, 100)); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 134 grandChild2->setDrawsContent(true); | 134 grandChild2->setDrawsContent(true); |
| 135 | 135 |
| 136 child1->addChild(grandChild1.Pass()); | 136 child1->addChild(grandChild1.Pass()); |
| 137 child1->addChild(grandChild2.Pass()); | 137 child1->addChild(grandChild2.Pass()); |
| 138 root->addChild(child1.Pass()); | 138 root->addChild(child1.Pass()); |
| 139 root->addChild(child2.Pass()); | 139 root->addChild(child2.Pass()); |
| 140 | 140 |
| 141 return root.Pass(); | 141 return root.Pass(); |
| 142 } | 142 } |
| 143 | 143 |
| 144 scoped_ptr<CCLayerImpl> createAndSetUpTestTreeWithOneSurface() | 144 scoped_ptr<LayerImpl> createAndSetUpTestTreeWithOneSurface() |
| 145 { | 145 { |
| 146 scoped_ptr<CCLayerImpl> root = createTestTreeWithOneSurface(); | 146 scoped_ptr<LayerImpl> root = createTestTreeWithOneSurface(); |
| 147 | 147 |
| 148 // Setup includes going past the first frame which always damages everything
, so | 148 // Setup includes going past the first frame which always damages everything
, so |
| 149 // that we can actually perform specific tests. | 149 // that we can actually perform specific tests. |
| 150 emulateDrawingOneFrame(root.get()); | 150 emulateDrawingOneFrame(root.get()); |
| 151 | 151 |
| 152 return root.Pass(); | 152 return root.Pass(); |
| 153 } | 153 } |
| 154 | 154 |
| 155 scoped_ptr<CCLayerImpl> createAndSetUpTestTreeWithTwoSurfaces() | 155 scoped_ptr<LayerImpl> createAndSetUpTestTreeWithTwoSurfaces() |
| 156 { | 156 { |
| 157 scoped_ptr<CCLayerImpl> root = createTestTreeWithTwoSurfaces(); | 157 scoped_ptr<LayerImpl> root = createTestTreeWithTwoSurfaces(); |
| 158 | 158 |
| 159 // Setup includes going past the first frame which always damages everything
, so | 159 // Setup includes going past the first frame which always damages everything
, so |
| 160 // that we can actually perform specific tests. | 160 // that we can actually perform specific tests. |
| 161 emulateDrawingOneFrame(root.get()); | 161 emulateDrawingOneFrame(root.get()); |
| 162 | 162 |
| 163 return root.Pass(); | 163 return root.Pass(); |
| 164 } | 164 } |
| 165 | 165 |
| 166 class CCDamageTrackerTest : public testing::Test { | 166 class DamageTrackerTest : public testing::Test { |
| 167 private: | 167 private: |
| 168 // For testing purposes, fake that we are on the impl thread. | 168 // For testing purposes, fake that we are on the impl thread. |
| 169 DebugScopedSetImplThread setImplThread; | 169 DebugScopedSetImplThread setImplThread; |
| 170 }; | 170 }; |
| 171 | 171 |
| 172 TEST_F(CCDamageTrackerTest, sanityCheckTestTreeWithOneSurface) | 172 TEST_F(DamageTrackerTest, sanityCheckTestTreeWithOneSurface) |
| 173 { | 173 { |
| 174 // Sanity check that the simple test tree will actually produce the expected
render | 174 // Sanity check that the simple test tree will actually produce the expected
render |
| 175 // surfaces and layer lists. | 175 // surfaces and layer lists. |
| 176 | 176 |
| 177 scoped_ptr<CCLayerImpl> root = createAndSetUpTestTreeWithOneSurface(); | 177 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithOneSurface(); |
| 178 | 178 |
| 179 EXPECT_EQ(2u, root->renderSurface()->layerList().size()); | 179 EXPECT_EQ(2u, root->renderSurface()->layerList().size()); |
| 180 EXPECT_EQ(1, root->renderSurface()->layerList()[0]->id()); | 180 EXPECT_EQ(1, root->renderSurface()->layerList()[0]->id()); |
| 181 EXPECT_EQ(2, root->renderSurface()->layerList()[1]->id()); | 181 EXPECT_EQ(2, root->renderSurface()->layerList()[1]->id()); |
| 182 | 182 |
| 183 FloatRect rootDamageRect = root->renderSurface()->damageTracker()->currentDa
mageRect(); | 183 FloatRect rootDamageRect = root->renderSurface()->damageTracker()->currentDa
mageRect(); |
| 184 EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 500, 500), rootDamageRect); | 184 EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 500, 500), rootDamageRect); |
| 185 } | 185 } |
| 186 | 186 |
| 187 TEST_F(CCDamageTrackerTest, sanityCheckTestTreeWithTwoSurfaces) | 187 TEST_F(DamageTrackerTest, sanityCheckTestTreeWithTwoSurfaces) |
| 188 { | 188 { |
| 189 // Sanity check that the complex test tree will actually produce the expecte
d render | 189 // Sanity check that the complex test tree will actually produce the expecte
d render |
| 190 // surfaces and layer lists. | 190 // surfaces and layer lists. |
| 191 | 191 |
| 192 scoped_ptr<CCLayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces(); | 192 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces(); |
| 193 | 193 |
| 194 CCLayerImpl* child1 = root->children()[0]; | 194 LayerImpl* child1 = root->children()[0]; |
| 195 CCLayerImpl* child2 = root->children()[1]; | 195 LayerImpl* child2 = root->children()[1]; |
| 196 FloatRect childDamageRect = child1->renderSurface()->damageTracker()->curren
tDamageRect(); | 196 FloatRect childDamageRect = child1->renderSurface()->damageTracker()->curren
tDamageRect(); |
| 197 FloatRect rootDamageRect = root->renderSurface()->damageTracker()->currentDa
mageRect(); | 197 FloatRect rootDamageRect = root->renderSurface()->damageTracker()->currentDa
mageRect(); |
| 198 | 198 |
| 199 ASSERT_TRUE(child1->renderSurface()); | 199 ASSERT_TRUE(child1->renderSurface()); |
| 200 EXPECT_FALSE(child2->renderSurface()); | 200 EXPECT_FALSE(child2->renderSurface()); |
| 201 EXPECT_EQ(3u, root->renderSurface()->layerList().size()); | 201 EXPECT_EQ(3u, root->renderSurface()->layerList().size()); |
| 202 EXPECT_EQ(2u, child1->renderSurface()->layerList().size()); | 202 EXPECT_EQ(2u, child1->renderSurface()->layerList().size()); |
| 203 | 203 |
| 204 // The render surface for child1 only has a contentRect that encloses grandC
hild1 and grandChild2, because child1 does not draw content. | 204 // The render surface for child1 only has a contentRect that encloses grandC
hild1 and grandChild2, because child1 does not draw content. |
| 205 EXPECT_FLOAT_RECT_EQ(FloatRect(190, 190, 16, 18), childDamageRect); | 205 EXPECT_FLOAT_RECT_EQ(FloatRect(190, 190, 16, 18), childDamageRect); |
| 206 EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 500, 500), rootDamageRect); | 206 EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 500, 500), rootDamageRect); |
| 207 } | 207 } |
| 208 | 208 |
| 209 TEST_F(CCDamageTrackerTest, verifyDamageForUpdateRects) | 209 TEST_F(DamageTrackerTest, verifyDamageForUpdateRects) |
| 210 { | 210 { |
| 211 scoped_ptr<CCLayerImpl> root = createAndSetUpTestTreeWithOneSurface(); | 211 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithOneSurface(); |
| 212 CCLayerImpl* child = root->children()[0]; | 212 LayerImpl* child = root->children()[0]; |
| 213 | 213 |
| 214 // CASE 1: Setting the update rect should cause the corresponding damage to
the surface. | 214 // CASE 1: Setting the update rect should cause the corresponding damage to
the surface. |
| 215 // | 215 // |
| 216 clearDamageForAllSurfaces(root.get()); | 216 clearDamageForAllSurfaces(root.get()); |
| 217 child->setUpdateRect(FloatRect(10, 11, 12, 13)); | 217 child->setUpdateRect(FloatRect(10, 11, 12, 13)); |
| 218 emulateDrawingOneFrame(root.get()); | 218 emulateDrawingOneFrame(root.get()); |
| 219 | 219 |
| 220 // Damage position on the surface should be: position of updateRect (10, 11)
relative to the child (100, 100). | 220 // Damage position on the surface should be: position of updateRect (10, 11)
relative to the child (100, 100). |
| 221 FloatRect rootDamageRect = root->renderSurface()->damageTracker()->currentDa
mageRect(); | 221 FloatRect rootDamageRect = root->renderSurface()->damageTracker()->currentDa
mageRect(); |
| 222 EXPECT_FLOAT_RECT_EQ(FloatRect(110, 111, 12, 13), rootDamageRect); | 222 EXPECT_FLOAT_RECT_EQ(FloatRect(110, 111, 12, 13), rootDamageRect); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 233 // | 233 // |
| 234 clearDamageForAllSurfaces(root.get()); | 234 clearDamageForAllSurfaces(root.get()); |
| 235 child->setUpdateRect(FloatRect(20, 25, 1, 2)); | 235 child->setUpdateRect(FloatRect(20, 25, 1, 2)); |
| 236 emulateDrawingOneFrame(root.get()); | 236 emulateDrawingOneFrame(root.get()); |
| 237 | 237 |
| 238 // Damage position on the surface should be: position of updateRect (20, 25)
relative to the child (100, 100). | 238 // Damage position on the surface should be: position of updateRect (20, 25)
relative to the child (100, 100). |
| 239 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect()
; | 239 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect()
; |
| 240 EXPECT_FLOAT_RECT_EQ(FloatRect(120, 125, 1, 2), rootDamageRect); | 240 EXPECT_FLOAT_RECT_EQ(FloatRect(120, 125, 1, 2), rootDamageRect); |
| 241 } | 241 } |
| 242 | 242 |
| 243 TEST_F(CCDamageTrackerTest, verifyDamageForPropertyChanges) | 243 TEST_F(DamageTrackerTest, verifyDamageForPropertyChanges) |
| 244 { | 244 { |
| 245 scoped_ptr<CCLayerImpl> root = createAndSetUpTestTreeWithOneSurface(); | 245 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithOneSurface(); |
| 246 CCLayerImpl* child = root->children()[0]; | 246 LayerImpl* child = root->children()[0]; |
| 247 | 247 |
| 248 // CASE 1: The layer's property changed flag takes priority over update rect
. | 248 // CASE 1: The layer's property changed flag takes priority over update rect
. |
| 249 // | 249 // |
| 250 clearDamageForAllSurfaces(root.get()); | 250 clearDamageForAllSurfaces(root.get()); |
| 251 child->setUpdateRect(FloatRect(10, 11, 12, 13)); | 251 child->setUpdateRect(FloatRect(10, 11, 12, 13)); |
| 252 child->setOpacity(0.5); | 252 child->setOpacity(0.5); |
| 253 emulateDrawingOneFrame(root.get()); | 253 emulateDrawingOneFrame(root.get()); |
| 254 | 254 |
| 255 // Sanity check - we should not have accidentally created a separate render
surface for the translucent layer. | 255 // Sanity check - we should not have accidentally created a separate render
surface for the translucent layer. |
| 256 ASSERT_FALSE(child->renderSurface()); | 256 ASSERT_FALSE(child->renderSurface()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 274 clearDamageForAllSurfaces(root.get()); | 274 clearDamageForAllSurfaces(root.get()); |
| 275 child->setPosition(FloatPoint(200, 230)); | 275 child->setPosition(FloatPoint(200, 230)); |
| 276 emulateDrawingOneFrame(root.get()); | 276 emulateDrawingOneFrame(root.get()); |
| 277 | 277 |
| 278 // Expect damage to be the combination of the previous one and the new one. | 278 // Expect damage to be the combination of the previous one and the new one. |
| 279 expectedRect.uniteIfNonZero(FloatRect(200, 230, 30, 30)); | 279 expectedRect.uniteIfNonZero(FloatRect(200, 230, 30, 30)); |
| 280 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect()
; | 280 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect()
; |
| 281 EXPECT_FLOAT_RECT_EQ(expectedRect, rootDamageRect); | 281 EXPECT_FLOAT_RECT_EQ(expectedRect, rootDamageRect); |
| 282 } | 282 } |
| 283 | 283 |
| 284 TEST_F(CCDamageTrackerTest, verifyDamageForTransformedLayer) | 284 TEST_F(DamageTrackerTest, verifyDamageForTransformedLayer) |
| 285 { | 285 { |
| 286 // If a layer is transformed, the damage rect should still enclose the entir
e | 286 // If a layer is transformed, the damage rect should still enclose the entir
e |
| 287 // transformed layer. | 287 // transformed layer. |
| 288 | 288 |
| 289 scoped_ptr<CCLayerImpl> root = createAndSetUpTestTreeWithOneSurface(); | 289 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithOneSurface(); |
| 290 CCLayerImpl* child = root->children()[0]; | 290 LayerImpl* child = root->children()[0]; |
| 291 | 291 |
| 292 WebTransformationMatrix rotation; | 292 WebTransformationMatrix rotation; |
| 293 rotation.rotate(45); | 293 rotation.rotate(45); |
| 294 | 294 |
| 295 clearDamageForAllSurfaces(root.get()); | 295 clearDamageForAllSurfaces(root.get()); |
| 296 child->setAnchorPoint(FloatPoint(0.5, 0.5)); | 296 child->setAnchorPoint(FloatPoint(0.5, 0.5)); |
| 297 child->setPosition(FloatPoint(85, 85)); | 297 child->setPosition(FloatPoint(85, 85)); |
| 298 emulateDrawingOneFrame(root.get()); | 298 emulateDrawingOneFrame(root.get()); |
| 299 | 299 |
| 300 // Sanity check that the layer actually moved to (85, 85), damaging its old
location and new location. | 300 // Sanity check that the layer actually moved to (85, 85), damaging its old
location and new location. |
| 301 FloatRect rootDamageRect = root->renderSurface()->damageTracker()->currentDa
mageRect(); | 301 FloatRect rootDamageRect = root->renderSurface()->damageTracker()->currentDa
mageRect(); |
| 302 EXPECT_FLOAT_RECT_EQ(FloatRect(85, 85, 45, 45), rootDamageRect); | 302 EXPECT_FLOAT_RECT_EQ(FloatRect(85, 85, 45, 45), rootDamageRect); |
| 303 | 303 |
| 304 // With the anchor on the layer's center, now we can test the rotation more | 304 // With the anchor on the layer's center, now we can test the rotation more |
| 305 // intuitively, since it applies about the layer's anchor. | 305 // intuitively, since it applies about the layer's anchor. |
| 306 clearDamageForAllSurfaces(root.get()); | 306 clearDamageForAllSurfaces(root.get()); |
| 307 child->setTransform(rotation); | 307 child->setTransform(rotation); |
| 308 emulateDrawingOneFrame(root.get()); | 308 emulateDrawingOneFrame(root.get()); |
| 309 | 309 |
| 310 // Since the child layer is square, rotation by 45 degrees about the center
should | 310 // Since the child layer is square, rotation by 45 degrees about the center
should |
| 311 // increase the size of the expected rect by sqrt(2), centered around (100,
100). The | 311 // increase the size of the expected rect by sqrt(2), centered around (100,
100). The |
| 312 // old exposed region should be fully contained in the new region. | 312 // old exposed region should be fully contained in the new region. |
| 313 double expectedWidth = 30 * sqrt(2.0); | 313 double expectedWidth = 30 * sqrt(2.0); |
| 314 double expectedPosition = 100 - 0.5 * expectedWidth; | 314 double expectedPosition = 100 - 0.5 * expectedWidth; |
| 315 FloatRect expectedRect(expectedPosition, expectedPosition, expectedWidth, ex
pectedWidth); | 315 FloatRect expectedRect(expectedPosition, expectedPosition, expectedWidth, ex
pectedWidth); |
| 316 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect()
; | 316 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect()
; |
| 317 EXPECT_FLOAT_RECT_EQ(expectedRect, rootDamageRect); | 317 EXPECT_FLOAT_RECT_EQ(expectedRect, rootDamageRect); |
| 318 } | 318 } |
| 319 | 319 |
| 320 TEST_F(CCDamageTrackerTest, verifyDamageForPerspectiveClippedLayer) | 320 TEST_F(DamageTrackerTest, verifyDamageForPerspectiveClippedLayer) |
| 321 { | 321 { |
| 322 // If a layer has a perspective transform that causes w < 0, then not clippi
ng the | 322 // If a layer has a perspective transform that causes w < 0, then not clippi
ng the |
| 323 // layer can cause an invalid damage rect. This test checks that the w < 0 c
ase is | 323 // layer can cause an invalid damage rect. This test checks that the w < 0 c
ase is |
| 324 // tracked properly. | 324 // tracked properly. |
| 325 // | 325 // |
| 326 // The transform is constructed so that if w < 0 clipping is not performed,
the | 326 // The transform is constructed so that if w < 0 clipping is not performed,
the |
| 327 // incorrect rect will be very small, specifically: position (500.972504, 49
8.544617) and size 0.056610 x 2.910767. | 327 // incorrect rect will be very small, specifically: position (500.972504, 49
8.544617) and size 0.056610 x 2.910767. |
| 328 // Instead, the correctly transformed rect should actually be very huge (i.e
. in theory, -infinity on the left), | 328 // Instead, the correctly transformed rect should actually be very huge (i.e
. in theory, -infinity on the left), |
| 329 // and positioned so that the right-most bound rect will be approximately 50
1 units in root surface space. | 329 // and positioned so that the right-most bound rect will be approximately 50
1 units in root surface space. |
| 330 // | 330 // |
| 331 | 331 |
| 332 scoped_ptr<CCLayerImpl> root = createAndSetUpTestTreeWithOneSurface(); | 332 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithOneSurface(); |
| 333 CCLayerImpl* child = root->children()[0]; | 333 LayerImpl* child = root->children()[0]; |
| 334 | 334 |
| 335 WebTransformationMatrix transform; | 335 WebTransformationMatrix transform; |
| 336 transform.translate3d(500, 500, 0); | 336 transform.translate3d(500, 500, 0); |
| 337 transform.applyPerspective(1); | 337 transform.applyPerspective(1); |
| 338 transform.rotate3d(0, 45, 0); | 338 transform.rotate3d(0, 45, 0); |
| 339 transform.translate3d(-50, -50, 0); | 339 transform.translate3d(-50, -50, 0); |
| 340 | 340 |
| 341 // Set up the child | 341 // Set up the child |
| 342 child->setPosition(FloatPoint(0, 0)); | 342 child->setPosition(FloatPoint(0, 0)); |
| 343 child->setBounds(IntSize(100, 100)); | 343 child->setBounds(IntSize(100, 100)); |
| 344 child->setContentBounds(IntSize(100, 100)); | 344 child->setContentBounds(IntSize(100, 100)); |
| 345 child->setTransform(transform); | 345 child->setTransform(transform); |
| 346 emulateDrawingOneFrame(root.get()); | 346 emulateDrawingOneFrame(root.get()); |
| 347 | 347 |
| 348 // Sanity check that the child layer's bounds would actually get clipped by
w < 0, | 348 // Sanity check that the child layer's bounds would actually get clipped by
w < 0, |
| 349 // otherwise this test is not actually testing the intended scenario. | 349 // otherwise this test is not actually testing the intended scenario. |
| 350 FloatQuad testQuad(FloatRect(FloatPoint::zero(), FloatSize(100, 100))); | 350 FloatQuad testQuad(FloatRect(FloatPoint::zero(), FloatSize(100, 100))); |
| 351 bool clipped = false; | 351 bool clipped = false; |
| 352 CCMathUtil::mapQuad(transform, testQuad, clipped); | 352 MathUtil::mapQuad(transform, testQuad, clipped); |
| 353 EXPECT_TRUE(clipped); | 353 EXPECT_TRUE(clipped); |
| 354 | 354 |
| 355 // Damage the child without moving it. | 355 // Damage the child without moving it. |
| 356 clearDamageForAllSurfaces(root.get()); | 356 clearDamageForAllSurfaces(root.get()); |
| 357 child->setOpacity(0.5); | 357 child->setOpacity(0.5); |
| 358 emulateDrawingOneFrame(root.get()); | 358 emulateDrawingOneFrame(root.get()); |
| 359 | 359 |
| 360 // The expected damage should cover the entire root surface (500x500), but w
e don't | 360 // The expected damage should cover the entire root surface (500x500), but w
e don't |
| 361 // care whether the damage rect was clamped or is larger than the surface fo
r this test. | 361 // care whether the damage rect was clamped or is larger than the surface fo
r this test. |
| 362 FloatRect rootDamageRect = root->renderSurface()->damageTracker()->currentDa
mageRect(); | 362 FloatRect rootDamageRect = root->renderSurface()->damageTracker()->currentDa
mageRect(); |
| 363 FloatRect damageWeCareAbout = FloatRect(FloatPoint::zero(), FloatSize(500, 5
00)); | 363 FloatRect damageWeCareAbout = FloatRect(FloatPoint::zero(), FloatSize(500, 5
00)); |
| 364 EXPECT_TRUE(rootDamageRect.contains(damageWeCareAbout)); | 364 EXPECT_TRUE(rootDamageRect.contains(damageWeCareAbout)); |
| 365 } | 365 } |
| 366 | 366 |
| 367 TEST_F(CCDamageTrackerTest, verifyDamageForBlurredSurface) | 367 TEST_F(DamageTrackerTest, verifyDamageForBlurredSurface) |
| 368 { | 368 { |
| 369 scoped_ptr<CCLayerImpl> root = createAndSetUpTestTreeWithOneSurface(); | 369 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithOneSurface(); |
| 370 CCLayerImpl* child = root->children()[0]; | 370 LayerImpl* child = root->children()[0]; |
| 371 | 371 |
| 372 WebFilterOperations filters; | 372 WebFilterOperations filters; |
| 373 filters.append(WebFilterOperation::createBlurFilter(5)); | 373 filters.append(WebFilterOperation::createBlurFilter(5)); |
| 374 int outsetTop, outsetRight, outsetBottom, outsetLeft; | 374 int outsetTop, outsetRight, outsetBottom, outsetLeft; |
| 375 filters.getOutsets(outsetTop, outsetRight, outsetBottom, outsetLeft); | 375 filters.getOutsets(outsetTop, outsetRight, outsetBottom, outsetLeft); |
| 376 | 376 |
| 377 // Setting the filter will damage the whole surface. | 377 // Setting the filter will damage the whole surface. |
| 378 clearDamageForAllSurfaces(root.get()); | 378 clearDamageForAllSurfaces(root.get()); |
| 379 root->setFilters(filters); | 379 root->setFilters(filters); |
| 380 emulateDrawingOneFrame(root.get()); | 380 emulateDrawingOneFrame(root.get()); |
| 381 | 381 |
| 382 // Setting the update rect should cause the corresponding damage to the surf
ace, blurred based on the size of the blur filter. | 382 // Setting the update rect should cause the corresponding damage to the surf
ace, blurred based on the size of the blur filter. |
| 383 clearDamageForAllSurfaces(root.get()); | 383 clearDamageForAllSurfaces(root.get()); |
| 384 child->setUpdateRect(FloatRect(10, 11, 12, 13)); | 384 child->setUpdateRect(FloatRect(10, 11, 12, 13)); |
| 385 emulateDrawingOneFrame(root.get()); | 385 emulateDrawingOneFrame(root.get()); |
| 386 | 386 |
| 387 // Damage position on the surface should be: position of updateRect (10, 11)
relative to the child (100, 100), but expanded by the blur outsets. | 387 // Damage position on the surface should be: position of updateRect (10, 11)
relative to the child (100, 100), but expanded by the blur outsets. |
| 388 FloatRect rootDamageRect = root->renderSurface()->damageTracker()->currentDa
mageRect(); | 388 FloatRect rootDamageRect = root->renderSurface()->damageTracker()->currentDa
mageRect(); |
| 389 FloatRect expectedDamageRect = FloatRect(110, 111, 12, 13); | 389 FloatRect expectedDamageRect = FloatRect(110, 111, 12, 13); |
| 390 expectedDamageRect.move(-outsetLeft, -outsetTop); | 390 expectedDamageRect.move(-outsetLeft, -outsetTop); |
| 391 expectedDamageRect.expand(outsetLeft + outsetRight, outsetTop + outsetBottom
); | 391 expectedDamageRect.expand(outsetLeft + outsetRight, outsetTop + outsetBottom
); |
| 392 EXPECT_FLOAT_RECT_EQ(expectedDamageRect, rootDamageRect); | 392 EXPECT_FLOAT_RECT_EQ(expectedDamageRect, rootDamageRect); |
| 393 } | 393 } |
| 394 | 394 |
| 395 TEST_F(CCDamageTrackerTest, verifyDamageForBackgroundBlurredChild) | 395 TEST_F(DamageTrackerTest, verifyDamageForBackgroundBlurredChild) |
| 396 { | 396 { |
| 397 scoped_ptr<CCLayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces(); | 397 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces(); |
| 398 CCLayerImpl* child1 = root->children()[0]; | 398 LayerImpl* child1 = root->children()[0]; |
| 399 CCLayerImpl* child2 = root->children()[1]; | 399 LayerImpl* child2 = root->children()[1]; |
| 400 | 400 |
| 401 // Allow us to set damage on child1 too. | 401 // Allow us to set damage on child1 too. |
| 402 child1->setDrawsContent(true); | 402 child1->setDrawsContent(true); |
| 403 | 403 |
| 404 WebFilterOperations filters; | 404 WebFilterOperations filters; |
| 405 filters.append(WebFilterOperation::createBlurFilter(2)); | 405 filters.append(WebFilterOperation::createBlurFilter(2)); |
| 406 int outsetTop, outsetRight, outsetBottom, outsetLeft; | 406 int outsetTop, outsetRight, outsetBottom, outsetLeft; |
| 407 filters.getOutsets(outsetTop, outsetRight, outsetBottom, outsetLeft); | 407 filters.getOutsets(outsetTop, outsetRight, outsetBottom, outsetLeft); |
| 408 | 408 |
| 409 // Setting the filter will damage the whole surface. | 409 // Setting the filter will damage the whole surface. |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 emulateDrawingOneFrame(root.get()); | 488 emulateDrawingOneFrame(root.get()); |
| 489 | 489 |
| 490 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect()
; | 490 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect()
; |
| 491 // Damage on child1 should be: position of updateRect offset by the child's
position (100, 100), and expanded by the damage. | 491 // Damage on child1 should be: position of updateRect offset by the child's
position (100, 100), and expanded by the damage. |
| 492 expectedDamageRect = FloatRect(100, 100, 1, 1); | 492 expectedDamageRect = FloatRect(100, 100, 1, 1); |
| 493 expectedDamageRect.move(-outsetLeft, -outsetTop); | 493 expectedDamageRect.move(-outsetLeft, -outsetTop); |
| 494 expectedDamageRect.expand(outsetLeft + outsetRight, outsetTop + outsetBottom
); | 494 expectedDamageRect.expand(outsetLeft + outsetRight, outsetTop + outsetBottom
); |
| 495 EXPECT_FLOAT_RECT_EQ(expectedDamageRect, rootDamageRect); | 495 EXPECT_FLOAT_RECT_EQ(expectedDamageRect, rootDamageRect); |
| 496 } | 496 } |
| 497 | 497 |
| 498 TEST_F(CCDamageTrackerTest, verifyDamageForAddingAndRemovingLayer) | 498 TEST_F(DamageTrackerTest, verifyDamageForAddingAndRemovingLayer) |
| 499 { | 499 { |
| 500 scoped_ptr<CCLayerImpl> root = createAndSetUpTestTreeWithOneSurface(); | 500 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithOneSurface(); |
| 501 CCLayerImpl* child1 = root->children()[0]; | 501 LayerImpl* child1 = root->children()[0]; |
| 502 | 502 |
| 503 // CASE 1: Adding a new layer should cause the appropriate damage. | 503 // CASE 1: Adding a new layer should cause the appropriate damage. |
| 504 // | 504 // |
| 505 clearDamageForAllSurfaces(root.get()); | 505 clearDamageForAllSurfaces(root.get()); |
| 506 { | 506 { |
| 507 scoped_ptr<CCLayerImpl> child2 = CCLayerImpl::create(3); | 507 scoped_ptr<LayerImpl> child2 = LayerImpl::create(3); |
| 508 child2->setPosition(FloatPoint(400, 380)); | 508 child2->setPosition(FloatPoint(400, 380)); |
| 509 child2->setAnchorPoint(FloatPoint::zero()); | 509 child2->setAnchorPoint(FloatPoint::zero()); |
| 510 child2->setBounds(IntSize(6, 8)); | 510 child2->setBounds(IntSize(6, 8)); |
| 511 child2->setContentBounds(IntSize(6, 8)); | 511 child2->setContentBounds(IntSize(6, 8)); |
| 512 child2->setDrawsContent(true); | 512 child2->setDrawsContent(true); |
| 513 root->addChild(child2.Pass()); | 513 root->addChild(child2.Pass()); |
| 514 } | 514 } |
| 515 emulateDrawingOneFrame(root.get()); | 515 emulateDrawingOneFrame(root.get()); |
| 516 | 516 |
| 517 // Sanity check - all 3 layers should be on the same render surface; render
surfaces are tested elsewhere. | 517 // Sanity check - all 3 layers should be on the same render surface; render
surfaces are tested elsewhere. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 528 emulateDrawingOneFrame(root.get()); | 528 emulateDrawingOneFrame(root.get()); |
| 529 EXPECT_TRUE(root->renderSurface()->damageTracker()->currentDamageRect().isEm
pty()); | 529 EXPECT_TRUE(root->renderSurface()->damageTracker()->currentDamageRect().isEm
pty()); |
| 530 | 530 |
| 531 // Then, test removing child1. | 531 // Then, test removing child1. |
| 532 child1->removeFromParent(); | 532 child1->removeFromParent(); |
| 533 emulateDrawingOneFrame(root.get()); | 533 emulateDrawingOneFrame(root.get()); |
| 534 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect()
; | 534 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect()
; |
| 535 EXPECT_FLOAT_RECT_EQ(FloatRect(100, 100, 30, 30), rootDamageRect); | 535 EXPECT_FLOAT_RECT_EQ(FloatRect(100, 100, 30, 30), rootDamageRect); |
| 536 } | 536 } |
| 537 | 537 |
| 538 TEST_F(CCDamageTrackerTest, verifyDamageForNewUnchangedLayer) | 538 TEST_F(DamageTrackerTest, verifyDamageForNewUnchangedLayer) |
| 539 { | 539 { |
| 540 // If child2 is added to the layer tree, but it doesn't have any explicit da
mage of | 540 // If child2 is added to the layer tree, but it doesn't have any explicit da
mage of |
| 541 // its own, it should still indeed damage the target surface. | 541 // its own, it should still indeed damage the target surface. |
| 542 | 542 |
| 543 scoped_ptr<CCLayerImpl> root = createAndSetUpTestTreeWithOneSurface(); | 543 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithOneSurface(); |
| 544 | 544 |
| 545 clearDamageForAllSurfaces(root.get()); | 545 clearDamageForAllSurfaces(root.get()); |
| 546 { | 546 { |
| 547 scoped_ptr<CCLayerImpl> child2 = CCLayerImpl::create(3); | 547 scoped_ptr<LayerImpl> child2 = LayerImpl::create(3); |
| 548 child2->setPosition(FloatPoint(400, 380)); | 548 child2->setPosition(FloatPoint(400, 380)); |
| 549 child2->setAnchorPoint(FloatPoint::zero()); | 549 child2->setAnchorPoint(FloatPoint::zero()); |
| 550 child2->setBounds(IntSize(6, 8)); | 550 child2->setBounds(IntSize(6, 8)); |
| 551 child2->setContentBounds(IntSize(6, 8)); | 551 child2->setContentBounds(IntSize(6, 8)); |
| 552 child2->setDrawsContent(true); | 552 child2->setDrawsContent(true); |
| 553 child2->resetAllChangeTrackingForSubtree(); | 553 child2->resetAllChangeTrackingForSubtree(); |
| 554 // Sanity check the initial conditions of the test, if these asserts tri
gger, it | 554 // Sanity check the initial conditions of the test, if these asserts tri
gger, it |
| 555 // means the test no longer actually covers the intended scenario. | 555 // means the test no longer actually covers the intended scenario. |
| 556 ASSERT_FALSE(child2->layerPropertyChanged()); | 556 ASSERT_FALSE(child2->layerPropertyChanged()); |
| 557 ASSERT_TRUE(child2->updateRect().isEmpty()); | 557 ASSERT_TRUE(child2->updateRect().isEmpty()); |
| 558 root->addChild(child2.Pass()); | 558 root->addChild(child2.Pass()); |
| 559 } | 559 } |
| 560 emulateDrawingOneFrame(root.get()); | 560 emulateDrawingOneFrame(root.get()); |
| 561 | 561 |
| 562 // Sanity check - all 3 layers should be on the same render surface; render
surfaces are tested elsewhere. | 562 // Sanity check - all 3 layers should be on the same render surface; render
surfaces are tested elsewhere. |
| 563 ASSERT_EQ(3u, root->renderSurface()->layerList().size()); | 563 ASSERT_EQ(3u, root->renderSurface()->layerList().size()); |
| 564 | 564 |
| 565 FloatRect rootDamageRect = root->renderSurface()->damageTracker()->currentDa
mageRect(); | 565 FloatRect rootDamageRect = root->renderSurface()->damageTracker()->currentDa
mageRect(); |
| 566 EXPECT_FLOAT_RECT_EQ(FloatRect(400, 380, 6, 8), rootDamageRect); | 566 EXPECT_FLOAT_RECT_EQ(FloatRect(400, 380, 6, 8), rootDamageRect); |
| 567 } | 567 } |
| 568 | 568 |
| 569 TEST_F(CCDamageTrackerTest, verifyDamageForMultipleLayers) | 569 TEST_F(DamageTrackerTest, verifyDamageForMultipleLayers) |
| 570 { | 570 { |
| 571 scoped_ptr<CCLayerImpl> root = createAndSetUpTestTreeWithOneSurface(); | 571 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithOneSurface(); |
| 572 CCLayerImpl* child1 = root->children()[0]; | 572 LayerImpl* child1 = root->children()[0]; |
| 573 | 573 |
| 574 // In this test we don't want the above tree manipulation to be considered p
art of the same frame. | 574 // In this test we don't want the above tree manipulation to be considered p
art of the same frame. |
| 575 clearDamageForAllSurfaces(root.get()); | 575 clearDamageForAllSurfaces(root.get()); |
| 576 { | 576 { |
| 577 scoped_ptr<CCLayerImpl> child2 = CCLayerImpl::create(3); | 577 scoped_ptr<LayerImpl> child2 = LayerImpl::create(3); |
| 578 child2->setPosition(FloatPoint(400, 380)); | 578 child2->setPosition(FloatPoint(400, 380)); |
| 579 child2->setAnchorPoint(FloatPoint::zero()); | 579 child2->setAnchorPoint(FloatPoint::zero()); |
| 580 child2->setBounds(IntSize(6, 8)); | 580 child2->setBounds(IntSize(6, 8)); |
| 581 child2->setContentBounds(IntSize(6, 8)); | 581 child2->setContentBounds(IntSize(6, 8)); |
| 582 child2->setDrawsContent(true); | 582 child2->setDrawsContent(true); |
| 583 root->addChild(child2.Pass()); | 583 root->addChild(child2.Pass()); |
| 584 } | 584 } |
| 585 CCLayerImpl* child2 = root->children()[1]; | 585 LayerImpl* child2 = root->children()[1]; |
| 586 emulateDrawingOneFrame(root.get()); | 586 emulateDrawingOneFrame(root.get()); |
| 587 | 587 |
| 588 // Damaging two layers simultaneously should cause combined damage. | 588 // Damaging two layers simultaneously should cause combined damage. |
| 589 // - child1 update rect in surface space: FloatRect(100, 100, 1, 2); | 589 // - child1 update rect in surface space: FloatRect(100, 100, 1, 2); |
| 590 // - child2 update rect in surface space: FloatRect(400, 380, 3, 4); | 590 // - child2 update rect in surface space: FloatRect(400, 380, 3, 4); |
| 591 clearDamageForAllSurfaces(root.get()); | 591 clearDamageForAllSurfaces(root.get()); |
| 592 child1->setUpdateRect(FloatRect(0, 0, 1, 2)); | 592 child1->setUpdateRect(FloatRect(0, 0, 1, 2)); |
| 593 child2->setUpdateRect(FloatRect(0, 0, 3, 4)); | 593 child2->setUpdateRect(FloatRect(0, 0, 3, 4)); |
| 594 emulateDrawingOneFrame(root.get()); | 594 emulateDrawingOneFrame(root.get()); |
| 595 FloatRect rootDamageRect = root->renderSurface()->damageTracker()->currentDa
mageRect(); | 595 FloatRect rootDamageRect = root->renderSurface()->damageTracker()->currentDa
mageRect(); |
| 596 EXPECT_FLOAT_RECT_EQ(FloatRect(100, 100, 303, 284), rootDamageRect); | 596 EXPECT_FLOAT_RECT_EQ(FloatRect(100, 100, 303, 284), rootDamageRect); |
| 597 } | 597 } |
| 598 | 598 |
| 599 TEST_F(CCDamageTrackerTest, verifyDamageForNestedSurfaces) | 599 TEST_F(DamageTrackerTest, verifyDamageForNestedSurfaces) |
| 600 { | 600 { |
| 601 scoped_ptr<CCLayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces(); | 601 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces(); |
| 602 CCLayerImpl* child1 = root->children()[0]; | 602 LayerImpl* child1 = root->children()[0]; |
| 603 CCLayerImpl* child2 = root->children()[1]; | 603 LayerImpl* child2 = root->children()[1]; |
| 604 CCLayerImpl* grandChild1 = root->children()[0]->children()[0]; | 604 LayerImpl* grandChild1 = root->children()[0]->children()[0]; |
| 605 FloatRect childDamageRect; | 605 FloatRect childDamageRect; |
| 606 FloatRect rootDamageRect; | 606 FloatRect rootDamageRect; |
| 607 | 607 |
| 608 // CASE 1: Damage to a descendant surface should propagate properly to ances
tor surface. | 608 // CASE 1: Damage to a descendant surface should propagate properly to ances
tor surface. |
| 609 // | 609 // |
| 610 clearDamageForAllSurfaces(root.get()); | 610 clearDamageForAllSurfaces(root.get()); |
| 611 grandChild1->setOpacity(0.5); | 611 grandChild1->setOpacity(0.5); |
| 612 emulateDrawingOneFrame(root.get()); | 612 emulateDrawingOneFrame(root.get()); |
| 613 childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRec
t(); | 613 childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRec
t(); |
| 614 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect()
; | 614 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect()
; |
| 615 EXPECT_FLOAT_RECT_EQ(FloatRect(200, 200, 6, 8), childDamageRect); | 615 EXPECT_FLOAT_RECT_EQ(FloatRect(200, 200, 6, 8), childDamageRect); |
| 616 EXPECT_FLOAT_RECT_EQ(FloatRect(300, 300, 6, 8), rootDamageRect); | 616 EXPECT_FLOAT_RECT_EQ(FloatRect(300, 300, 6, 8), rootDamageRect); |
| 617 | 617 |
| 618 // CASE 2: Same as previous case, but with additional damage elsewhere that
should be properly unioned. | 618 // CASE 2: Same as previous case, but with additional damage elsewhere that
should be properly unioned. |
| 619 // - child1 surface damage in root surface space: FloatRect(300, 300, 6, 8); | 619 // - child1 surface damage in root surface space: FloatRect(300, 300, 6, 8); |
| 620 // - child2 damage in root surface space: FloatRect(11, 11, 18, 18); | 620 // - child2 damage in root surface space: FloatRect(11, 11, 18, 18); |
| 621 clearDamageForAllSurfaces(root.get()); | 621 clearDamageForAllSurfaces(root.get()); |
| 622 grandChild1->setOpacity(0.7f); | 622 grandChild1->setOpacity(0.7f); |
| 623 child2->setOpacity(0.7f); | 623 child2->setOpacity(0.7f); |
| 624 emulateDrawingOneFrame(root.get()); | 624 emulateDrawingOneFrame(root.get()); |
| 625 childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRec
t(); | 625 childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRec
t(); |
| 626 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect()
; | 626 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect()
; |
| 627 EXPECT_FLOAT_RECT_EQ(FloatRect(200, 200, 6, 8), childDamageRect); | 627 EXPECT_FLOAT_RECT_EQ(FloatRect(200, 200, 6, 8), childDamageRect); |
| 628 EXPECT_FLOAT_RECT_EQ(FloatRect(11, 11, 295, 297), rootDamageRect); | 628 EXPECT_FLOAT_RECT_EQ(FloatRect(11, 11, 295, 297), rootDamageRect); |
| 629 } | 629 } |
| 630 | 630 |
| 631 TEST_F(CCDamageTrackerTest, verifyDamageForSurfaceChangeFromDescendantLayer) | 631 TEST_F(DamageTrackerTest, verifyDamageForSurfaceChangeFromDescendantLayer) |
| 632 { | 632 { |
| 633 // If descendant layer changes and affects the content bounds of the render
surface, | 633 // If descendant layer changes and affects the content bounds of the render
surface, |
| 634 // then the entire descendant surface should be damaged, and it should damag
e its | 634 // then the entire descendant surface should be damaged, and it should damag
e its |
| 635 // ancestor surface with the old and new surface regions. | 635 // ancestor surface with the old and new surface regions. |
| 636 | 636 |
| 637 // This is a tricky case, since only the first grandChild changes, but the e
ntire | 637 // This is a tricky case, since only the first grandChild changes, but the e
ntire |
| 638 // surface should be marked dirty. | 638 // surface should be marked dirty. |
| 639 | 639 |
| 640 scoped_ptr<CCLayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces(); | 640 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces(); |
| 641 CCLayerImpl* child1 = root->children()[0]; | 641 LayerImpl* child1 = root->children()[0]; |
| 642 CCLayerImpl* grandChild1 = root->children()[0]->children()[0]; | 642 LayerImpl* grandChild1 = root->children()[0]->children()[0]; |
| 643 FloatRect childDamageRect; | 643 FloatRect childDamageRect; |
| 644 FloatRect rootDamageRect; | 644 FloatRect rootDamageRect; |
| 645 | 645 |
| 646 clearDamageForAllSurfaces(root.get()); | 646 clearDamageForAllSurfaces(root.get()); |
| 647 grandChild1->setPosition(FloatPoint(195, 205)); | 647 grandChild1->setPosition(FloatPoint(195, 205)); |
| 648 emulateDrawingOneFrame(root.get()); | 648 emulateDrawingOneFrame(root.get()); |
| 649 childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRec
t(); | 649 childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRec
t(); |
| 650 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect()
; | 650 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect()
; |
| 651 | 651 |
| 652 // The new surface bounds should be damaged entirely, even though only one o
f the layers changed. | 652 // The new surface bounds should be damaged entirely, even though only one o
f the layers changed. |
| 653 EXPECT_FLOAT_RECT_EQ(FloatRect(190, 190, 11, 23), childDamageRect); | 653 EXPECT_FLOAT_RECT_EQ(FloatRect(190, 190, 11, 23), childDamageRect); |
| 654 | 654 |
| 655 // Damage to the root surface should be the union of child1's *entire* rende
r surface | 655 // Damage to the root surface should be the union of child1's *entire* rende
r surface |
| 656 // (in target space), and its old exposed area (also in target space). | 656 // (in target space), and its old exposed area (also in target space). |
| 657 EXPECT_FLOAT_RECT_EQ(FloatRect(290, 290, 16, 23), rootDamageRect); | 657 EXPECT_FLOAT_RECT_EQ(FloatRect(290, 290, 16, 23), rootDamageRect); |
| 658 } | 658 } |
| 659 | 659 |
| 660 TEST_F(CCDamageTrackerTest, verifyDamageForSurfaceChangeFromAncestorLayer) | 660 TEST_F(DamageTrackerTest, verifyDamageForSurfaceChangeFromAncestorLayer) |
| 661 { | 661 { |
| 662 // An ancestor/owning layer changes that affects the position/transform of t
he render | 662 // An ancestor/owning layer changes that affects the position/transform of t
he render |
| 663 // surface. Note that in this case, the layerPropertyChanged flag already pr
opagates | 663 // surface. Note that in this case, the layerPropertyChanged flag already pr
opagates |
| 664 // to the subtree (tested in CCLayerImpltest), which damages the entire chil
d1 | 664 // to the subtree (tested in LayerImpltest), which damages the entire child1 |
| 665 // surface, but the damage tracker still needs the correct logic to compute
the | 665 // surface, but the damage tracker still needs the correct logic to compute
the |
| 666 // exposed region on the root surface. | 666 // exposed region on the root surface. |
| 667 | 667 |
| 668 // FIXME: the expectations of this test case should change when we add suppo
rt for a | 668 // FIXME: the expectations of this test case should change when we add suppo
rt for a |
| 669 // unique scissorRect per renderSurface. In that case, the child1 sur
face | 669 // unique scissorRect per renderSurface. In that case, the child1 sur
face |
| 670 // should be completely unchanged, since we are only transforming it,
while the | 670 // should be completely unchanged, since we are only transforming it,
while the |
| 671 // root surface would be damaged appropriately. | 671 // root surface would be damaged appropriately. |
| 672 | 672 |
| 673 scoped_ptr<CCLayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces(); | 673 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces(); |
| 674 CCLayerImpl* child1 = root->children()[0]; | 674 LayerImpl* child1 = root->children()[0]; |
| 675 FloatRect childDamageRect; | 675 FloatRect childDamageRect; |
| 676 FloatRect rootDamageRect; | 676 FloatRect rootDamageRect; |
| 677 | 677 |
| 678 clearDamageForAllSurfaces(root.get()); | 678 clearDamageForAllSurfaces(root.get()); |
| 679 child1->setPosition(FloatPoint(50, 50)); | 679 child1->setPosition(FloatPoint(50, 50)); |
| 680 emulateDrawingOneFrame(root.get()); | 680 emulateDrawingOneFrame(root.get()); |
| 681 childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRec
t(); | 681 childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRec
t(); |
| 682 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect()
; | 682 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect()
; |
| 683 | 683 |
| 684 // The new surface bounds should be damaged entirely. | 684 // The new surface bounds should be damaged entirely. |
| 685 EXPECT_FLOAT_RECT_EQ(FloatRect(190, 190, 16, 18), childDamageRect); | 685 EXPECT_FLOAT_RECT_EQ(FloatRect(190, 190, 16, 18), childDamageRect); |
| 686 | 686 |
| 687 // The entire child1 surface and the old exposed child1 surface should damag
e the root surface. | 687 // The entire child1 surface and the old exposed child1 surface should damag
e the root surface. |
| 688 // - old child1 surface in target space: FloatRect(290, 290, 16, 18) | 688 // - old child1 surface in target space: FloatRect(290, 290, 16, 18) |
| 689 // - new child1 surface in target space: FloatRect(240, 240, 16, 18) | 689 // - new child1 surface in target space: FloatRect(240, 240, 16, 18) |
| 690 EXPECT_FLOAT_RECT_EQ(FloatRect(240, 240, 66, 68), rootDamageRect); | 690 EXPECT_FLOAT_RECT_EQ(FloatRect(240, 240, 66, 68), rootDamageRect); |
| 691 } | 691 } |
| 692 | 692 |
| 693 TEST_F(CCDamageTrackerTest, verifyDamageForAddingAndRemovingRenderSurfaces) | 693 TEST_F(DamageTrackerTest, verifyDamageForAddingAndRemovingRenderSurfaces) |
| 694 { | 694 { |
| 695 scoped_ptr<CCLayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces(); | 695 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces(); |
| 696 CCLayerImpl* child1 = root->children()[0]; | 696 LayerImpl* child1 = root->children()[0]; |
| 697 FloatRect childDamageRect; | 697 FloatRect childDamageRect; |
| 698 FloatRect rootDamageRect; | 698 FloatRect rootDamageRect; |
| 699 | 699 |
| 700 // CASE 1: If a descendant surface disappears, its entire old area becomes e
xposed. | 700 // CASE 1: If a descendant surface disappears, its entire old area becomes e
xposed. |
| 701 // | 701 // |
| 702 clearDamageForAllSurfaces(root.get()); | 702 clearDamageForAllSurfaces(root.get()); |
| 703 child1->setOpacity(1); | 703 child1->setOpacity(1); |
| 704 emulateDrawingOneFrame(root.get()); | 704 emulateDrawingOneFrame(root.get()); |
| 705 | 705 |
| 706 // Sanity check that there is only one surface now. | 706 // Sanity check that there is only one surface now. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 727 ASSERT_TRUE(child1->renderSurface()); | 727 ASSERT_TRUE(child1->renderSurface()); |
| 728 EXPECT_EQ(3u, root->renderSurface()->layerList().size()); | 728 EXPECT_EQ(3u, root->renderSurface()->layerList().size()); |
| 729 EXPECT_EQ(2u, child1->renderSurface()->layerList().size()); | 729 EXPECT_EQ(2u, child1->renderSurface()->layerList().size()); |
| 730 | 730 |
| 731 childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRec
t(); | 731 childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRec
t(); |
| 732 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect()
; | 732 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect()
; |
| 733 EXPECT_FLOAT_RECT_EQ(FloatRect(190, 190, 16, 18), childDamageRect); | 733 EXPECT_FLOAT_RECT_EQ(FloatRect(190, 190, 16, 18), childDamageRect); |
| 734 EXPECT_FLOAT_RECT_EQ(FloatRect(290, 290, 16, 18), rootDamageRect); | 734 EXPECT_FLOAT_RECT_EQ(FloatRect(290, 290, 16, 18), rootDamageRect); |
| 735 } | 735 } |
| 736 | 736 |
| 737 TEST_F(CCDamageTrackerTest, verifyNoDamageWhenNothingChanged) | 737 TEST_F(DamageTrackerTest, verifyNoDamageWhenNothingChanged) |
| 738 { | 738 { |
| 739 scoped_ptr<CCLayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces(); | 739 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces(); |
| 740 CCLayerImpl* child1 = root->children()[0]; | 740 LayerImpl* child1 = root->children()[0]; |
| 741 FloatRect childDamageRect; | 741 FloatRect childDamageRect; |
| 742 FloatRect rootDamageRect; | 742 FloatRect rootDamageRect; |
| 743 | 743 |
| 744 // CASE 1: If nothing changes, the damage rect should be empty. | 744 // CASE 1: If nothing changes, the damage rect should be empty. |
| 745 // | 745 // |
| 746 clearDamageForAllSurfaces(root.get()); | 746 clearDamageForAllSurfaces(root.get()); |
| 747 emulateDrawingOneFrame(root.get()); | 747 emulateDrawingOneFrame(root.get()); |
| 748 childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRec
t(); | 748 childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRec
t(); |
| 749 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect()
; | 749 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect()
; |
| 750 EXPECT_TRUE(childDamageRect.isEmpty()); | 750 EXPECT_TRUE(childDamageRect.isEmpty()); |
| 751 EXPECT_TRUE(rootDamageRect.isEmpty()); | 751 EXPECT_TRUE(rootDamageRect.isEmpty()); |
| 752 | 752 |
| 753 // CASE 2: If nothing changes twice in a row, the damage rect should still b
e empty. | 753 // CASE 2: If nothing changes twice in a row, the damage rect should still b
e empty. |
| 754 // | 754 // |
| 755 clearDamageForAllSurfaces(root.get()); | 755 clearDamageForAllSurfaces(root.get()); |
| 756 emulateDrawingOneFrame(root.get()); | 756 emulateDrawingOneFrame(root.get()); |
| 757 childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRec
t(); | 757 childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRec
t(); |
| 758 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect()
; | 758 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect()
; |
| 759 EXPECT_TRUE(childDamageRect.isEmpty()); | 759 EXPECT_TRUE(childDamageRect.isEmpty()); |
| 760 EXPECT_TRUE(rootDamageRect.isEmpty()); | 760 EXPECT_TRUE(rootDamageRect.isEmpty()); |
| 761 } | 761 } |
| 762 | 762 |
| 763 TEST_F(CCDamageTrackerTest, verifyNoDamageForUpdateRectThatDoesNotDrawContent) | 763 TEST_F(DamageTrackerTest, verifyNoDamageForUpdateRectThatDoesNotDrawContent) |
| 764 { | 764 { |
| 765 scoped_ptr<CCLayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces(); | 765 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces(); |
| 766 CCLayerImpl* child1 = root->children()[0]; | 766 LayerImpl* child1 = root->children()[0]; |
| 767 FloatRect childDamageRect; | 767 FloatRect childDamageRect; |
| 768 FloatRect rootDamageRect; | 768 FloatRect rootDamageRect; |
| 769 | 769 |
| 770 // In our specific tree, the update rect of child1 should not cause any dama
ge to any | 770 // In our specific tree, the update rect of child1 should not cause any dama
ge to any |
| 771 // surface because it does not actually draw content. | 771 // surface because it does not actually draw content. |
| 772 clearDamageForAllSurfaces(root.get()); | 772 clearDamageForAllSurfaces(root.get()); |
| 773 child1->setUpdateRect(FloatRect(0, 0, 1, 2)); | 773 child1->setUpdateRect(FloatRect(0, 0, 1, 2)); |
| 774 emulateDrawingOneFrame(root.get()); | 774 emulateDrawingOneFrame(root.get()); |
| 775 childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRec
t(); | 775 childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRec
t(); |
| 776 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect()
; | 776 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect()
; |
| 777 EXPECT_TRUE(childDamageRect.isEmpty()); | 777 EXPECT_TRUE(childDamageRect.isEmpty()); |
| 778 EXPECT_TRUE(rootDamageRect.isEmpty()); | 778 EXPECT_TRUE(rootDamageRect.isEmpty()); |
| 779 } | 779 } |
| 780 | 780 |
| 781 TEST_F(CCDamageTrackerTest, verifyDamageForReplica) | 781 TEST_F(DamageTrackerTest, verifyDamageForReplica) |
| 782 { | 782 { |
| 783 scoped_ptr<CCLayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces(); | 783 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces(); |
| 784 CCLayerImpl* child1 = root->children()[0]; | 784 LayerImpl* child1 = root->children()[0]; |
| 785 CCLayerImpl* grandChild1 = child1->children()[0]; | 785 LayerImpl* grandChild1 = child1->children()[0]; |
| 786 CCLayerImpl* grandChild2 = child1->children()[1]; | 786 LayerImpl* grandChild2 = child1->children()[1]; |
| 787 | 787 |
| 788 // Damage on a surface that has a reflection should cause the target surface
to | 788 // Damage on a surface that has a reflection should cause the target surface
to |
| 789 // receive the surface's damage and the surface's reflected damage. | 789 // receive the surface's damage and the surface's reflected damage. |
| 790 | 790 |
| 791 // For this test case, we modify grandChild2, and add grandChild3 to extend
the bounds | 791 // For this test case, we modify grandChild2, and add grandChild3 to extend
the bounds |
| 792 // of child1's surface. This way, we can test reflection changes without cha
nging | 792 // of child1's surface. This way, we can test reflection changes without cha
nging |
| 793 // contentBounds of the surface. | 793 // contentBounds of the surface. |
| 794 grandChild2->setPosition(FloatPoint(180, 180)); | 794 grandChild2->setPosition(FloatPoint(180, 180)); |
| 795 { | 795 { |
| 796 scoped_ptr<CCLayerImpl> grandChild3 = CCLayerImpl::create(6); | 796 scoped_ptr<LayerImpl> grandChild3 = LayerImpl::create(6); |
| 797 grandChild3->setPosition(FloatPoint(240, 240)); | 797 grandChild3->setPosition(FloatPoint(240, 240)); |
| 798 grandChild3->setAnchorPoint(FloatPoint::zero()); | 798 grandChild3->setAnchorPoint(FloatPoint::zero()); |
| 799 grandChild3->setBounds(IntSize(10, 10)); | 799 grandChild3->setBounds(IntSize(10, 10)); |
| 800 grandChild3->setContentBounds(IntSize(10, 10)); | 800 grandChild3->setContentBounds(IntSize(10, 10)); |
| 801 grandChild3->setDrawsContent(true); | 801 grandChild3->setDrawsContent(true); |
| 802 child1->addChild(grandChild3.Pass()); | 802 child1->addChild(grandChild3.Pass()); |
| 803 } | 803 } |
| 804 child1->setOpacity(0.5); | 804 child1->setOpacity(0.5); |
| 805 emulateDrawingOneFrame(root.get()); | 805 emulateDrawingOneFrame(root.get()); |
| 806 | 806 |
| 807 // CASE 1: adding a reflection about the left edge of grandChild1. | 807 // CASE 1: adding a reflection about the left edge of grandChild1. |
| 808 // | 808 // |
| 809 clearDamageForAllSurfaces(root.get()); | 809 clearDamageForAllSurfaces(root.get()); |
| 810 { | 810 { |
| 811 scoped_ptr<CCLayerImpl> grandChild1Replica = CCLayerImpl::create(7); | 811 scoped_ptr<LayerImpl> grandChild1Replica = LayerImpl::create(7); |
| 812 grandChild1Replica->setPosition(FloatPoint::zero()); | 812 grandChild1Replica->setPosition(FloatPoint::zero()); |
| 813 grandChild1Replica->setAnchorPoint(FloatPoint::zero()); | 813 grandChild1Replica->setAnchorPoint(FloatPoint::zero()); |
| 814 WebTransformationMatrix reflection; | 814 WebTransformationMatrix reflection; |
| 815 reflection.scale3d(-1, 1, 1); | 815 reflection.scale3d(-1, 1, 1); |
| 816 grandChild1Replica->setTransform(reflection); | 816 grandChild1Replica->setTransform(reflection); |
| 817 grandChild1->setReplicaLayer(grandChild1Replica.Pass()); | 817 grandChild1->setReplicaLayer(grandChild1Replica.Pass()); |
| 818 } | 818 } |
| 819 emulateDrawingOneFrame(root.get()); | 819 emulateDrawingOneFrame(root.get()); |
| 820 | 820 |
| 821 FloatRect grandChildDamageRect = grandChild1->renderSurface()->damageTracker
()->currentDamageRect(); | 821 FloatRect grandChildDamageRect = grandChild1->renderSurface()->damageTracker
()->currentDamageRect(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 844 // The child surface damage should include normal and replica surfaces for b
oth old and new locations. | 844 // The child surface damage should include normal and replica surfaces for b
oth old and new locations. |
| 845 // - old location in target space: FloatRect(194, 200, 12, 8) | 845 // - old location in target space: FloatRect(194, 200, 12, 8) |
| 846 // - new location in target space: FloatRect(189, 205, 12, 8) | 846 // - new location in target space: FloatRect(189, 205, 12, 8) |
| 847 EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 6, 8), grandChildDamageRect); | 847 EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 6, 8), grandChildDamageRect); |
| 848 EXPECT_FLOAT_RECT_EQ(FloatRect(189, 200, 17, 13), childDamageRect); | 848 EXPECT_FLOAT_RECT_EQ(FloatRect(189, 200, 17, 13), childDamageRect); |
| 849 EXPECT_FLOAT_RECT_EQ(FloatRect(289, 300, 17, 13), rootDamageRect); | 849 EXPECT_FLOAT_RECT_EQ(FloatRect(289, 300, 17, 13), rootDamageRect); |
| 850 | 850 |
| 851 // CASE 3: removing the reflection should cause the entire region including
reflection | 851 // CASE 3: removing the reflection should cause the entire region including
reflection |
| 852 // to damage the target surface. | 852 // to damage the target surface. |
| 853 clearDamageForAllSurfaces(root.get()); | 853 clearDamageForAllSurfaces(root.get()); |
| 854 grandChild1->setReplicaLayer(scoped_ptr<CCLayerImpl>()); | 854 grandChild1->setReplicaLayer(scoped_ptr<LayerImpl>()); |
| 855 emulateDrawingOneFrame(root.get()); | 855 emulateDrawingOneFrame(root.get()); |
| 856 ASSERT_EQ(oldContentRect.width(), child1->renderSurface()->contentRect().wid
th()); | 856 ASSERT_EQ(oldContentRect.width(), child1->renderSurface()->contentRect().wid
th()); |
| 857 ASSERT_EQ(oldContentRect.height(), child1->renderSurface()->contentRect().he
ight()); | 857 ASSERT_EQ(oldContentRect.height(), child1->renderSurface()->contentRect().he
ight()); |
| 858 | 858 |
| 859 EXPECT_FALSE(grandChild1->renderSurface()); | 859 EXPECT_FALSE(grandChild1->renderSurface()); |
| 860 childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRec
t(); | 860 childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRec
t(); |
| 861 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect()
; | 861 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect()
; |
| 862 | 862 |
| 863 EXPECT_FLOAT_RECT_EQ(FloatRect(189, 205, 12, 8), childDamageRect); | 863 EXPECT_FLOAT_RECT_EQ(FloatRect(189, 205, 12, 8), childDamageRect); |
| 864 EXPECT_FLOAT_RECT_EQ(FloatRect(289, 305, 12, 8), rootDamageRect); | 864 EXPECT_FLOAT_RECT_EQ(FloatRect(289, 305, 12, 8), rootDamageRect); |
| 865 } | 865 } |
| 866 | 866 |
| 867 TEST_F(CCDamageTrackerTest, verifyDamageForMask) | 867 TEST_F(DamageTrackerTest, verifyDamageForMask) |
| 868 { | 868 { |
| 869 scoped_ptr<CCLayerImpl> root = createAndSetUpTestTreeWithOneSurface(); | 869 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithOneSurface(); |
| 870 CCLayerImpl* child = root->children()[0]; | 870 LayerImpl* child = root->children()[0]; |
| 871 | 871 |
| 872 // In the current implementation of the damage tracker, changes to mask laye
rs should | 872 // In the current implementation of the damage tracker, changes to mask laye
rs should |
| 873 // damage the entire corresponding surface. | 873 // damage the entire corresponding surface. |
| 874 | 874 |
| 875 clearDamageForAllSurfaces(root.get()); | 875 clearDamageForAllSurfaces(root.get()); |
| 876 | 876 |
| 877 // Set up the mask layer. | 877 // Set up the mask layer. |
| 878 { | 878 { |
| 879 scoped_ptr<CCLayerImpl> maskLayer = CCLayerImpl::create(3); | 879 scoped_ptr<LayerImpl> maskLayer = LayerImpl::create(3); |
| 880 maskLayer->setPosition(child->position()); | 880 maskLayer->setPosition(child->position()); |
| 881 maskLayer->setAnchorPoint(FloatPoint::zero()); | 881 maskLayer->setAnchorPoint(FloatPoint::zero()); |
| 882 maskLayer->setBounds(child->bounds()); | 882 maskLayer->setBounds(child->bounds()); |
| 883 maskLayer->setContentBounds(child->bounds()); | 883 maskLayer->setContentBounds(child->bounds()); |
| 884 child->setMaskLayer(maskLayer.Pass()); | 884 child->setMaskLayer(maskLayer.Pass()); |
| 885 } | 885 } |
| 886 CCLayerImpl* maskLayer = child->maskLayer(); | 886 LayerImpl* maskLayer = child->maskLayer(); |
| 887 | 887 |
| 888 // Add opacity and a grandChild so that the render surface persists even aft
er we remove the mask. | 888 // Add opacity and a grandChild so that the render surface persists even aft
er we remove the mask. |
| 889 child->setOpacity(0.5); | 889 child->setOpacity(0.5); |
| 890 { | 890 { |
| 891 scoped_ptr<CCLayerImpl> grandChild = CCLayerImpl::create(4); | 891 scoped_ptr<LayerImpl> grandChild = LayerImpl::create(4); |
| 892 grandChild->setPosition(FloatPoint(2, 2)); | 892 grandChild->setPosition(FloatPoint(2, 2)); |
| 893 grandChild->setAnchorPoint(FloatPoint::zero()); | 893 grandChild->setAnchorPoint(FloatPoint::zero()); |
| 894 grandChild->setBounds(IntSize(2, 2)); | 894 grandChild->setBounds(IntSize(2, 2)); |
| 895 grandChild->setContentBounds(IntSize(2, 2)); | 895 grandChild->setContentBounds(IntSize(2, 2)); |
| 896 grandChild->setDrawsContent(true); | 896 grandChild->setDrawsContent(true); |
| 897 child->addChild(grandChild.Pass()); | 897 child->addChild(grandChild.Pass()); |
| 898 } | 898 } |
| 899 emulateDrawingOneFrame(root.get()); | 899 emulateDrawingOneFrame(root.get()); |
| 900 | 900 |
| 901 // Sanity check that a new surface was created for the child. | 901 // Sanity check that a new surface was created for the child. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 930 // | 930 // |
| 931 | 931 |
| 932 // Advance one frame without damage so that we know the damage rect is not l
eftover from the previous case. | 932 // Advance one frame without damage so that we know the damage rect is not l
eftover from the previous case. |
| 933 clearDamageForAllSurfaces(root.get()); | 933 clearDamageForAllSurfaces(root.get()); |
| 934 emulateDrawingOneFrame(root.get()); | 934 emulateDrawingOneFrame(root.get()); |
| 935 childDamageRect = child->renderSurface()->damageTracker()->currentDamageRect
(); | 935 childDamageRect = child->renderSurface()->damageTracker()->currentDamageRect
(); |
| 936 EXPECT_TRUE(childDamageRect.isEmpty()); | 936 EXPECT_TRUE(childDamageRect.isEmpty()); |
| 937 | 937 |
| 938 // Then test mask removal. | 938 // Then test mask removal. |
| 939 clearDamageForAllSurfaces(root.get()); | 939 clearDamageForAllSurfaces(root.get()); |
| 940 child->setMaskLayer(scoped_ptr<CCLayerImpl>()); | 940 child->setMaskLayer(scoped_ptr<LayerImpl>()); |
| 941 ASSERT_TRUE(child->layerPropertyChanged()); | 941 ASSERT_TRUE(child->layerPropertyChanged()); |
| 942 emulateDrawingOneFrame(root.get()); | 942 emulateDrawingOneFrame(root.get()); |
| 943 | 943 |
| 944 // Sanity check that a render surface still exists. | 944 // Sanity check that a render surface still exists. |
| 945 ASSERT_TRUE(child->renderSurface()); | 945 ASSERT_TRUE(child->renderSurface()); |
| 946 | 946 |
| 947 childDamageRect = child->renderSurface()->damageTracker()->currentDamageRect
(); | 947 childDamageRect = child->renderSurface()->damageTracker()->currentDamageRect
(); |
| 948 EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 30, 30), childDamageRect); | 948 EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 30, 30), childDamageRect); |
| 949 } | 949 } |
| 950 | 950 |
| 951 TEST_F(CCDamageTrackerTest, verifyDamageForReplicaMask) | 951 TEST_F(DamageTrackerTest, verifyDamageForReplicaMask) |
| 952 { | 952 { |
| 953 scoped_ptr<CCLayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces(); | 953 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces(); |
| 954 CCLayerImpl* child1 = root->children()[0]; | 954 LayerImpl* child1 = root->children()[0]; |
| 955 CCLayerImpl* grandChild1 = child1->children()[0]; | 955 LayerImpl* grandChild1 = child1->children()[0]; |
| 956 | 956 |
| 957 // Changes to a replica's mask should not damage the original surface, becau
se it is | 957 // Changes to a replica's mask should not damage the original surface, becau
se it is |
| 958 // not masked. But it does damage the ancestor target surface. | 958 // not masked. But it does damage the ancestor target surface. |
| 959 | 959 |
| 960 clearDamageForAllSurfaces(root.get()); | 960 clearDamageForAllSurfaces(root.get()); |
| 961 | 961 |
| 962 // Create a reflection about the left edge of grandChild1. | 962 // Create a reflection about the left edge of grandChild1. |
| 963 { | 963 { |
| 964 scoped_ptr<CCLayerImpl> grandChild1Replica = CCLayerImpl::create(6); | 964 scoped_ptr<LayerImpl> grandChild1Replica = LayerImpl::create(6); |
| 965 grandChild1Replica->setPosition(FloatPoint::zero()); | 965 grandChild1Replica->setPosition(FloatPoint::zero()); |
| 966 grandChild1Replica->setAnchorPoint(FloatPoint::zero()); | 966 grandChild1Replica->setAnchorPoint(FloatPoint::zero()); |
| 967 WebTransformationMatrix reflection; | 967 WebTransformationMatrix reflection; |
| 968 reflection.scale3d(-1, 1, 1); | 968 reflection.scale3d(-1, 1, 1); |
| 969 grandChild1Replica->setTransform(reflection); | 969 grandChild1Replica->setTransform(reflection); |
| 970 grandChild1->setReplicaLayer(grandChild1Replica.Pass()); | 970 grandChild1->setReplicaLayer(grandChild1Replica.Pass()); |
| 971 } | 971 } |
| 972 CCLayerImpl* grandChild1Replica = grandChild1->replicaLayer(); | 972 LayerImpl* grandChild1Replica = grandChild1->replicaLayer(); |
| 973 | 973 |
| 974 // Set up the mask layer on the replica layer | 974 // Set up the mask layer on the replica layer |
| 975 { | 975 { |
| 976 scoped_ptr<CCLayerImpl> replicaMaskLayer = CCLayerImpl::create(7); | 976 scoped_ptr<LayerImpl> replicaMaskLayer = LayerImpl::create(7); |
| 977 replicaMaskLayer->setPosition(FloatPoint::zero()); | 977 replicaMaskLayer->setPosition(FloatPoint::zero()); |
| 978 replicaMaskLayer->setAnchorPoint(FloatPoint::zero()); | 978 replicaMaskLayer->setAnchorPoint(FloatPoint::zero()); |
| 979 replicaMaskLayer->setBounds(grandChild1->bounds()); | 979 replicaMaskLayer->setBounds(grandChild1->bounds()); |
| 980 replicaMaskLayer->setContentBounds(grandChild1->bounds()); | 980 replicaMaskLayer->setContentBounds(grandChild1->bounds()); |
| 981 grandChild1Replica->setMaskLayer(replicaMaskLayer.Pass()); | 981 grandChild1Replica->setMaskLayer(replicaMaskLayer.Pass()); |
| 982 } | 982 } |
| 983 CCLayerImpl* replicaMaskLayer = grandChild1Replica->maskLayer(); | 983 LayerImpl* replicaMaskLayer = grandChild1Replica->maskLayer(); |
| 984 | 984 |
| 985 emulateDrawingOneFrame(root.get()); | 985 emulateDrawingOneFrame(root.get()); |
| 986 | 986 |
| 987 // Sanity check that the appropriate render surfaces were created | 987 // Sanity check that the appropriate render surfaces were created |
| 988 ASSERT_TRUE(grandChild1->renderSurface()); | 988 ASSERT_TRUE(grandChild1->renderSurface()); |
| 989 | 989 |
| 990 // CASE 1: a property change on the mask should damage only the reflected re
gion on the target surface. | 990 // CASE 1: a property change on the mask should damage only the reflected re
gion on the target surface. |
| 991 clearDamageForAllSurfaces(root.get()); | 991 clearDamageForAllSurfaces(root.get()); |
| 992 replicaMaskLayer->setStackingOrderChanged(true); | 992 replicaMaskLayer->setStackingOrderChanged(true); |
| 993 emulateDrawingOneFrame(root.get()); | 993 emulateDrawingOneFrame(root.get()); |
| 994 | 994 |
| 995 FloatRect grandChildDamageRect = grandChild1->renderSurface()->damageTracker
()->currentDamageRect(); | 995 FloatRect grandChildDamageRect = grandChild1->renderSurface()->damageTracker
()->currentDamageRect(); |
| 996 FloatRect childDamageRect = child1->renderSurface()->damageTracker()->curren
tDamageRect(); | 996 FloatRect childDamageRect = child1->renderSurface()->damageTracker()->curren
tDamageRect(); |
| 997 | 997 |
| 998 EXPECT_TRUE(grandChildDamageRect.isEmpty()); | 998 EXPECT_TRUE(grandChildDamageRect.isEmpty()); |
| 999 EXPECT_FLOAT_RECT_EQ(FloatRect(194, 200, 6, 8), childDamageRect); | 999 EXPECT_FLOAT_RECT_EQ(FloatRect(194, 200, 6, 8), childDamageRect); |
| 1000 | 1000 |
| 1001 // CASE 2: removing the replica mask damages only the reflected region on th
e target surface. | 1001 // CASE 2: removing the replica mask damages only the reflected region on th
e target surface. |
| 1002 // | 1002 // |
| 1003 clearDamageForAllSurfaces(root.get()); | 1003 clearDamageForAllSurfaces(root.get()); |
| 1004 grandChild1Replica->setMaskLayer(scoped_ptr<CCLayerImpl>()); | 1004 grandChild1Replica->setMaskLayer(scoped_ptr<LayerImpl>()); |
| 1005 emulateDrawingOneFrame(root.get()); | 1005 emulateDrawingOneFrame(root.get()); |
| 1006 | 1006 |
| 1007 grandChildDamageRect = grandChild1->renderSurface()->damageTracker()->curren
tDamageRect(); | 1007 grandChildDamageRect = grandChild1->renderSurface()->damageTracker()->curren
tDamageRect(); |
| 1008 childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRec
t(); | 1008 childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRec
t(); |
| 1009 | 1009 |
| 1010 EXPECT_TRUE(grandChildDamageRect.isEmpty()); | 1010 EXPECT_TRUE(grandChildDamageRect.isEmpty()); |
| 1011 EXPECT_FLOAT_RECT_EQ(FloatRect(194, 200, 6, 8), childDamageRect); | 1011 EXPECT_FLOAT_RECT_EQ(FloatRect(194, 200, 6, 8), childDamageRect); |
| 1012 } | 1012 } |
| 1013 | 1013 |
| 1014 TEST_F(CCDamageTrackerTest, verifyDamageForReplicaMaskWithAnchor) | 1014 TEST_F(DamageTrackerTest, verifyDamageForReplicaMaskWithAnchor) |
| 1015 { | 1015 { |
| 1016 scoped_ptr<CCLayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces(); | 1016 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces(); |
| 1017 CCLayerImpl* child1 = root->children()[0]; | 1017 LayerImpl* child1 = root->children()[0]; |
| 1018 CCLayerImpl* grandChild1 = child1->children()[0]; | 1018 LayerImpl* grandChild1 = child1->children()[0]; |
| 1019 | 1019 |
| 1020 // Verify that the correct replicaOriginTransform is used for the replicaMas
k; | 1020 // Verify that the correct replicaOriginTransform is used for the replicaMas
k; |
| 1021 clearDamageForAllSurfaces(root.get()); | 1021 clearDamageForAllSurfaces(root.get()); |
| 1022 | 1022 |
| 1023 grandChild1->setAnchorPoint(FloatPoint(1, 0)); // This is not exactly the an
chor being tested, but by convention its expected to be the same as the replica'
s anchor point. | 1023 grandChild1->setAnchorPoint(FloatPoint(1, 0)); // This is not exactly the an
chor being tested, but by convention its expected to be the same as the replica'
s anchor point. |
| 1024 | 1024 |
| 1025 { | 1025 { |
| 1026 scoped_ptr<CCLayerImpl> grandChild1Replica = CCLayerImpl::create(6); | 1026 scoped_ptr<LayerImpl> grandChild1Replica = LayerImpl::create(6); |
| 1027 grandChild1Replica->setPosition(FloatPoint::zero()); | 1027 grandChild1Replica->setPosition(FloatPoint::zero()); |
| 1028 grandChild1Replica->setAnchorPoint(FloatPoint(1, 0)); // This is the anc
hor being tested. | 1028 grandChild1Replica->setAnchorPoint(FloatPoint(1, 0)); // This is the anc
hor being tested. |
| 1029 WebTransformationMatrix reflection; | 1029 WebTransformationMatrix reflection; |
| 1030 reflection.scale3d(-1, 1, 1); | 1030 reflection.scale3d(-1, 1, 1); |
| 1031 grandChild1Replica->setTransform(reflection); | 1031 grandChild1Replica->setTransform(reflection); |
| 1032 grandChild1->setReplicaLayer(grandChild1Replica.Pass()); | 1032 grandChild1->setReplicaLayer(grandChild1Replica.Pass()); |
| 1033 } | 1033 } |
| 1034 CCLayerImpl* grandChild1Replica = grandChild1->replicaLayer(); | 1034 LayerImpl* grandChild1Replica = grandChild1->replicaLayer(); |
| 1035 | 1035 |
| 1036 // Set up the mask layer on the replica layer | 1036 // Set up the mask layer on the replica layer |
| 1037 { | 1037 { |
| 1038 scoped_ptr<CCLayerImpl> replicaMaskLayer = CCLayerImpl::create(7); | 1038 scoped_ptr<LayerImpl> replicaMaskLayer = LayerImpl::create(7); |
| 1039 replicaMaskLayer->setPosition(FloatPoint::zero()); | 1039 replicaMaskLayer->setPosition(FloatPoint::zero()); |
| 1040 replicaMaskLayer->setAnchorPoint(FloatPoint::zero()); // note, this is n
ot the anchor being tested. | 1040 replicaMaskLayer->setAnchorPoint(FloatPoint::zero()); // note, this is n
ot the anchor being tested. |
| 1041 replicaMaskLayer->setBounds(grandChild1->bounds()); | 1041 replicaMaskLayer->setBounds(grandChild1->bounds()); |
| 1042 replicaMaskLayer->setContentBounds(grandChild1->bounds()); | 1042 replicaMaskLayer->setContentBounds(grandChild1->bounds()); |
| 1043 grandChild1Replica->setMaskLayer(replicaMaskLayer.Pass()); | 1043 grandChild1Replica->setMaskLayer(replicaMaskLayer.Pass()); |
| 1044 } | 1044 } |
| 1045 CCLayerImpl* replicaMaskLayer = grandChild1Replica->maskLayer(); | 1045 LayerImpl* replicaMaskLayer = grandChild1Replica->maskLayer(); |
| 1046 | 1046 |
| 1047 emulateDrawingOneFrame(root.get()); | 1047 emulateDrawingOneFrame(root.get()); |
| 1048 | 1048 |
| 1049 // Sanity check that the appropriate render surfaces were created | 1049 // Sanity check that the appropriate render surfaces were created |
| 1050 ASSERT_TRUE(grandChild1->renderSurface()); | 1050 ASSERT_TRUE(grandChild1->renderSurface()); |
| 1051 | 1051 |
| 1052 // A property change on the replicaMask should damage the reflected region o
n the target surface. | 1052 // A property change on the replicaMask should damage the reflected region o
n the target surface. |
| 1053 clearDamageForAllSurfaces(root.get()); | 1053 clearDamageForAllSurfaces(root.get()); |
| 1054 replicaMaskLayer->setStackingOrderChanged(true); | 1054 replicaMaskLayer->setStackingOrderChanged(true); |
| 1055 | 1055 |
| 1056 emulateDrawingOneFrame(root.get()); | 1056 emulateDrawingOneFrame(root.get()); |
| 1057 | 1057 |
| 1058 FloatRect childDamageRect = child1->renderSurface()->damageTracker()->curren
tDamageRect(); | 1058 FloatRect childDamageRect = child1->renderSurface()->damageTracker()->curren
tDamageRect(); |
| 1059 EXPECT_FLOAT_RECT_EQ(FloatRect(206, 200, 6, 8), childDamageRect); | 1059 EXPECT_FLOAT_RECT_EQ(FloatRect(206, 200, 6, 8), childDamageRect); |
| 1060 } | 1060 } |
| 1061 | 1061 |
| 1062 TEST_F(CCDamageTrackerTest, verifyDamageWhenForcedFullDamage) | 1062 TEST_F(DamageTrackerTest, verifyDamageWhenForcedFullDamage) |
| 1063 { | 1063 { |
| 1064 scoped_ptr<CCLayerImpl> root = createAndSetUpTestTreeWithOneSurface(); | 1064 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithOneSurface(); |
| 1065 CCLayerImpl* child = root->children()[0]; | 1065 LayerImpl* child = root->children()[0]; |
| 1066 | 1066 |
| 1067 // Case 1: This test ensures that when the tracker is forced to have full da
mage, that | 1067 // Case 1: This test ensures that when the tracker is forced to have full da
mage, that |
| 1068 // it takes priority over any other partial damage. | 1068 // it takes priority over any other partial damage. |
| 1069 // | 1069 // |
| 1070 clearDamageForAllSurfaces(root.get()); | 1070 clearDamageForAllSurfaces(root.get()); |
| 1071 child->setUpdateRect(FloatRect(10, 11, 12, 13)); | 1071 child->setUpdateRect(FloatRect(10, 11, 12, 13)); |
| 1072 root->renderSurface()->damageTracker()->forceFullDamageNextUpdate(); | 1072 root->renderSurface()->damageTracker()->forceFullDamageNextUpdate(); |
| 1073 emulateDrawingOneFrame(root.get()); | 1073 emulateDrawingOneFrame(root.get()); |
| 1074 FloatRect rootDamageRect = root->renderSurface()->damageTracker()->currentDa
mageRect(); | 1074 FloatRect rootDamageRect = root->renderSurface()->damageTracker()->currentDa
mageRect(); |
| 1075 EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 500, 500), rootDamageRect); | 1075 EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 500, 500), rootDamageRect); |
| 1076 | 1076 |
| 1077 // Case 2: An additional sanity check that forcing full damage works even wh
en nothing | 1077 // Case 2: An additional sanity check that forcing full damage works even wh
en nothing |
| 1078 // on the layer tree changed. | 1078 // on the layer tree changed. |
| 1079 // | 1079 // |
| 1080 clearDamageForAllSurfaces(root.get()); | 1080 clearDamageForAllSurfaces(root.get()); |
| 1081 root->renderSurface()->damageTracker()->forceFullDamageNextUpdate(); | 1081 root->renderSurface()->damageTracker()->forceFullDamageNextUpdate(); |
| 1082 emulateDrawingOneFrame(root.get()); | 1082 emulateDrawingOneFrame(root.get()); |
| 1083 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect()
; | 1083 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect()
; |
| 1084 EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 500, 500), rootDamageRect); | 1084 EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 500, 500), rootDamageRect); |
| 1085 } | 1085 } |
| 1086 | 1086 |
| 1087 TEST_F(CCDamageTrackerTest, verifyDamageForEmptyLayerList) | 1087 TEST_F(DamageTrackerTest, verifyDamageForEmptyLayerList) |
| 1088 { | 1088 { |
| 1089 // Though it should never happen, its a good idea to verify that the damage
tracker | 1089 // Though it should never happen, its a good idea to verify that the damage
tracker |
| 1090 // does not crash when it receives an empty layerList. | 1090 // does not crash when it receives an empty layerList. |
| 1091 | 1091 |
| 1092 scoped_ptr<CCLayerImpl> root = CCLayerImpl::create(1); | 1092 scoped_ptr<LayerImpl> root = LayerImpl::create(1); |
| 1093 root->createRenderSurface(); | 1093 root->createRenderSurface(); |
| 1094 | 1094 |
| 1095 ASSERT_TRUE(root == root->renderTarget()); | 1095 ASSERT_TRUE(root == root->renderTarget()); |
| 1096 CCRenderSurface* targetSurface = root->renderSurface(); | 1096 RenderSurfaceImpl* targetSurface = root->renderSurface(); |
| 1097 targetSurface->clearLayerLists(); | 1097 targetSurface->clearLayerLists(); |
| 1098 targetSurface->damageTracker()->updateDamageTrackingState(targetSurface->lay
erList(), targetSurface->owningLayerId(), false, IntRect(), 0, WebFilterOperatio
ns()); | 1098 targetSurface->damageTracker()->updateDamageTrackingState(targetSurface->lay
erList(), targetSurface->owningLayerId(), false, IntRect(), 0, WebFilterOperatio
ns()); |
| 1099 | 1099 |
| 1100 FloatRect damageRect = targetSurface->damageTracker()->currentDamageRect(); | 1100 FloatRect damageRect = targetSurface->damageTracker()->currentDamageRect(); |
| 1101 EXPECT_TRUE(damageRect.isEmpty()); | 1101 EXPECT_TRUE(damageRect.isEmpty()); |
| 1102 } | 1102 } |
| 1103 | 1103 |
| 1104 TEST_F(CCDamageTrackerTest, verifyDamageAccumulatesUntilReset) | 1104 TEST_F(DamageTrackerTest, verifyDamageAccumulatesUntilReset) |
| 1105 { | 1105 { |
| 1106 // If damage is not cleared, it should accumulate. | 1106 // If damage is not cleared, it should accumulate. |
| 1107 | 1107 |
| 1108 scoped_ptr<CCLayerImpl> root = createAndSetUpTestTreeWithOneSurface(); | 1108 scoped_ptr<LayerImpl> root = createAndSetUpTestTreeWithOneSurface(); |
| 1109 CCLayerImpl* child = root->children()[0]; | 1109 LayerImpl* child = root->children()[0]; |
| 1110 | 1110 |
| 1111 clearDamageForAllSurfaces(root.get()); | 1111 clearDamageForAllSurfaces(root.get()); |
| 1112 child->setUpdateRect(FloatRect(10, 11, 1, 2)); | 1112 child->setUpdateRect(FloatRect(10, 11, 1, 2)); |
| 1113 emulateDrawingOneFrame(root.get()); | 1113 emulateDrawingOneFrame(root.get()); |
| 1114 | 1114 |
| 1115 // Sanity check damage after the first frame; this isnt the actual test yet. | 1115 // Sanity check damage after the first frame; this isnt the actual test yet. |
| 1116 FloatRect rootDamageRect = root->renderSurface()->damageTracker()->currentDa
mageRect(); | 1116 FloatRect rootDamageRect = root->renderSurface()->damageTracker()->currentDa
mageRect(); |
| 1117 EXPECT_FLOAT_RECT_EQ(FloatRect(110, 111, 1, 2), rootDamageRect); | 1117 EXPECT_FLOAT_RECT_EQ(FloatRect(110, 111, 1, 2), rootDamageRect); |
| 1118 | 1118 |
| 1119 // New damage, without having cleared the previous damage, should be unioned
to the previous one. | 1119 // New damage, without having cleared the previous damage, should be unioned
to the previous one. |
| 1120 child->setUpdateRect(FloatRect(20, 25, 1, 2)); | 1120 child->setUpdateRect(FloatRect(20, 25, 1, 2)); |
| 1121 emulateDrawingOneFrame(root.get()); | 1121 emulateDrawingOneFrame(root.get()); |
| 1122 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect()
; | 1122 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect()
; |
| 1123 EXPECT_FLOAT_RECT_EQ(FloatRect(110, 111, 11, 16), rootDamageRect); | 1123 EXPECT_FLOAT_RECT_EQ(FloatRect(110, 111, 11, 16), rootDamageRect); |
| 1124 | 1124 |
| 1125 // If we notify the damage tracker that we drew the damaged area, then damag
e should be emptied. | 1125 // If we notify the damage tracker that we drew the damaged area, then damag
e should be emptied. |
| 1126 root->renderSurface()->damageTracker()->didDrawDamagedArea(); | 1126 root->renderSurface()->damageTracker()->didDrawDamagedArea(); |
| 1127 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect()
; | 1127 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect()
; |
| 1128 EXPECT_TRUE(rootDamageRect.isEmpty()); | 1128 EXPECT_TRUE(rootDamageRect.isEmpty()); |
| 1129 | 1129 |
| 1130 // Damage should remain empty even after one frame, since there's yet no new
damage | 1130 // Damage should remain empty even after one frame, since there's yet no new
damage |
| 1131 emulateDrawingOneFrame(root.get()); | 1131 emulateDrawingOneFrame(root.get()); |
| 1132 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect()
; | 1132 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect()
; |
| 1133 EXPECT_TRUE(rootDamageRect.isEmpty()); | 1133 EXPECT_TRUE(rootDamageRect.isEmpty()); |
| 1134 } | 1134 } |
| 1135 | 1135 |
| 1136 } // namespace | 1136 } // namespace |
| OLD | NEW |