Chromium Code Reviews| 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 "SkBlurImageFilter.h" | |
| 12 #include "cc/math_util.h" | 13 #include "cc/math_util.h" |
| 13 #include "cc/single_thread_proxy.h" | 14 #include "cc/single_thread_proxy.h" |
| 14 #include "cc/test/geometry_test_utils.h" | 15 #include "cc/test/geometry_test_utils.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include <public/WebFilterOperation.h> | 17 #include <public/WebFilterOperation.h> |
| 17 #include <public/WebFilterOperations.h> | 18 #include <public/WebFilterOperations.h> |
| 18 | 19 |
| 19 using namespace cc; | 20 using namespace cc; |
| 20 using namespace WebKit; | 21 using namespace WebKit; |
| 21 using namespace WebKitTests; | 22 using namespace WebKitTests; |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 52 // 1. computing the render passes and layerlists | 53 // 1. computing the render passes and layerlists |
| 53 // 2. updating all damage trackers in the correct order | 54 // 2. updating all damage trackers in the correct order |
| 54 // 3. resetting all updateRects and propertyChanged flags for all layers a nd surfaces. | 55 // 3. resetting all updateRects and propertyChanged flags for all layers a nd surfaces. |
| 55 | 56 |
| 56 std::vector<CCLayerImpl*> renderSurfaceLayerList; | 57 std::vector<CCLayerImpl*> renderSurfaceLayerList; |
| 57 executeCalculateDrawTransformsAndVisibility(root, renderSurfaceLayerList); | 58 executeCalculateDrawTransformsAndVisibility(root, renderSurfaceLayerList); |
| 58 | 59 |
| 59 // Iterate back-to-front, so that damage correctly propagates from descendan t surfaces to ancestors. | 60 // 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) { | 61 for (int i = renderSurfaceLayerList.size() - 1; i >= 0; --i) { |
| 61 CCRenderSurface* targetSurface = renderSurfaceLayerList[i]->renderSurfac e(); | 62 CCRenderSurface* targetSurface = renderSurfaceLayerList[i]->renderSurfac e(); |
| 62 targetSurface->damageTracker()->updateDamageTrackingState(targetSurface- >layerList(), targetSurface->owningLayerId(), targetSurface->surfacePropertyChan gedOnlyFromDescendant(), targetSurface->contentRect(), renderSurfaceLayerList[i] ->maskLayer(), renderSurfaceLayerList[i]->filters()); | 63 targetSurface->damageTracker()->updateDamageTrackingState(targetSurface- >layerList(), targetSurface->owningLayerId(), targetSurface->surfacePropertyChan gedOnlyFromDescendant(), targetSurface->contentRect(), renderSurfaceLayerList[i] ->maskLayer(), renderSurfaceLayerList[i]->filters(), renderSurfaceLayerList[i]-> filter()); |
| 63 } | 64 } |
| 64 | 65 |
| 65 root->resetAllChangeTrackingForSubtree(); | 66 root->resetAllChangeTrackingForSubtree(); |
| 66 } | 67 } |
| 67 | 68 |
| 68 scoped_ptr<CCLayerImpl> createTestTreeWithOneSurface() | 69 scoped_ptr<CCLayerImpl> createTestTreeWithOneSurface() |
| 69 { | 70 { |
| 70 scoped_ptr<CCLayerImpl> root = CCLayerImpl::create(1); | 71 scoped_ptr<CCLayerImpl> root = CCLayerImpl::create(1); |
| 71 scoped_ptr<CCLayerImpl> child = CCLayerImpl::create(2); | 72 scoped_ptr<CCLayerImpl> child = CCLayerImpl::create(2); |
| 72 | 73 |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 385 emulateDrawingOneFrame(root.get()); | 386 emulateDrawingOneFrame(root.get()); |
| 386 | 387 |
| 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 // 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(); | 389 FloatRect rootDamageRect = root->renderSurface()->damageTracker()->currentDa mageRect(); |
| 389 FloatRect expectedDamageRect = FloatRect(110, 111, 12, 13); | 390 FloatRect expectedDamageRect = FloatRect(110, 111, 12, 13); |
| 390 expectedDamageRect.move(-outsetLeft, -outsetTop); | 391 expectedDamageRect.move(-outsetLeft, -outsetTop); |
| 391 expectedDamageRect.expand(outsetLeft + outsetRight, outsetTop + outsetBottom ); | 392 expectedDamageRect.expand(outsetLeft + outsetRight, outsetTop + outsetBottom ); |
| 392 EXPECT_FLOAT_RECT_EQ(expectedDamageRect, rootDamageRect); | 393 EXPECT_FLOAT_RECT_EQ(expectedDamageRect, rootDamageRect); |
| 393 } | 394 } |
| 394 | 395 |
| 396 TEST_F(CCDamageTrackerTest, verifyDamageForImageFilter) | |
| 397 { | |
| 398 scoped_ptr<CCLayerImpl> root = createAndSetUpTestTreeWithOneSurface(); | |
| 399 CCLayerImpl* child = root->children()[0]; | |
| 400 FloatRect rootDamageRect; | |
| 401 | |
| 402 // Allow us to set damage on child too. | |
| 403 child->setDrawsContent(true); | |
| 404 | |
| 405 SkAutoTUnref<SkImageFilter> filter(new SkBlurImageFilter(SkIntToScalar(2), | |
| 406 SkIntToScalar(2))); | |
| 407 // Setting the filter will damage the whole surface. | |
| 408 clearDamageForAllSurfaces(root.get()); | |
| 409 child->setFilter(filter); | |
| 410 emulateDrawingOneFrame(root.get()); | |
| 411 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ; | |
| 412 EXPECT_FLOAT_RECT_EQ(FloatRect(100, 100, 30, 30), rootDamageRect); | |
| 413 | |
| 414 // CASE 1: Setting the update rect should damage the whole surface (for now) | |
| 415 clearDamageForAllSurfaces(root.get()); | |
| 416 root->setUpdateRect(FloatRect(297, 297, 2, 2)); | |
|
danakj
2012/10/22 18:56:02
This is a copy/paste from background filters. Does
| |
| 417 emulateDrawingOneFrame(root.get()); | |
| 418 | |
| 419 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ; | |
| 420 EXPECT_FLOAT_RECT_EQ(FloatRect(100, 100, 199, 199), rootDamageRect); | |
| 421 } | |
| 422 | |
| 395 TEST_F(CCDamageTrackerTest, verifyDamageForBackgroundBlurredChild) | 423 TEST_F(CCDamageTrackerTest, verifyDamageForBackgroundBlurredChild) |
| 396 { | 424 { |
| 397 scoped_ptr<CCLayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces(); | 425 scoped_ptr<CCLayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces(); |
| 398 CCLayerImpl* child1 = root->children()[0]; | 426 CCLayerImpl* child1 = root->children()[0]; |
| 399 CCLayerImpl* child2 = root->children()[1]; | 427 CCLayerImpl* child2 = root->children()[1]; |
| 400 | 428 |
| 401 // Allow us to set damage on child1 too. | 429 // Allow us to set damage on child1 too. |
| 402 child1->setDrawsContent(true); | 430 child1->setDrawsContent(true); |
| 403 | 431 |
| 404 WebFilterOperations filters; | 432 WebFilterOperations filters; |
| (...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1088 { | 1116 { |
| 1089 // Though it should never happen, its a good idea to verify that the damage tracker | 1117 // 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. | 1118 // does not crash when it receives an empty layerList. |
| 1091 | 1119 |
| 1092 scoped_ptr<CCLayerImpl> root = CCLayerImpl::create(1); | 1120 scoped_ptr<CCLayerImpl> root = CCLayerImpl::create(1); |
| 1093 root->createRenderSurface(); | 1121 root->createRenderSurface(); |
| 1094 | 1122 |
| 1095 ASSERT_TRUE(root == root->renderTarget()); | 1123 ASSERT_TRUE(root == root->renderTarget()); |
| 1096 CCRenderSurface* targetSurface = root->renderSurface(); | 1124 CCRenderSurface* targetSurface = root->renderSurface(); |
| 1097 targetSurface->clearLayerLists(); | 1125 targetSurface->clearLayerLists(); |
| 1098 targetSurface->damageTracker()->updateDamageTrackingState(targetSurface->lay erList(), targetSurface->owningLayerId(), false, IntRect(), 0, WebFilterOperatio ns()); | 1126 targetSurface->damageTracker()->updateDamageTrackingState(targetSurface->lay erList(), targetSurface->owningLayerId(), false, IntRect(), 0, WebFilterOperatio ns(), 0); |
| 1099 | 1127 |
| 1100 FloatRect damageRect = targetSurface->damageTracker()->currentDamageRect(); | 1128 FloatRect damageRect = targetSurface->damageTracker()->currentDamageRect(); |
| 1101 EXPECT_TRUE(damageRect.isEmpty()); | 1129 EXPECT_TRUE(damageRect.isEmpty()); |
| 1102 } | 1130 } |
| 1103 | 1131 |
| 1104 TEST_F(CCDamageTrackerTest, verifyDamageAccumulatesUntilReset) | 1132 TEST_F(CCDamageTrackerTest, verifyDamageAccumulatesUntilReset) |
| 1105 { | 1133 { |
| 1106 // If damage is not cleared, it should accumulate. | 1134 // If damage is not cleared, it should accumulate. |
| 1107 | 1135 |
| 1108 scoped_ptr<CCLayerImpl> root = createAndSetUpTestTreeWithOneSurface(); | 1136 scoped_ptr<CCLayerImpl> root = createAndSetUpTestTreeWithOneSurface(); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 1127 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ; | 1155 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ; |
| 1128 EXPECT_TRUE(rootDamageRect.isEmpty()); | 1156 EXPECT_TRUE(rootDamageRect.isEmpty()); |
| 1129 | 1157 |
| 1130 // Damage should remain empty even after one frame, since there's yet no new damage | 1158 // Damage should remain empty even after one frame, since there's yet no new damage |
| 1131 emulateDrawingOneFrame(root.get()); | 1159 emulateDrawingOneFrame(root.get()); |
| 1132 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ; | 1160 rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect() ; |
| 1133 EXPECT_TRUE(rootDamageRect.isEmpty()); | 1161 EXPECT_TRUE(rootDamageRect.isEmpty()); |
| 1134 } | 1162 } |
| 1135 | 1163 |
| 1136 } // namespace | 1164 } // namespace |
| OLD | NEW |