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