| 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 "cc/trees/layer_tree_host.h" | 5 #include "cc/trees/layer_tree_host.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/synchronization/lock.h" | 9 #include "base/synchronization/lock.h" |
| 10 #include "cc/animation/timing_function.h" | 10 #include "cc/animation/timing_function.h" |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 | 113 |
| 114 // A setNeedsCommit should lead to 1 commit. Issuing a second commit after that | 114 // A setNeedsCommit should lead to 1 commit. Issuing a second commit after that |
| 115 // first committed frame draws should lead to another commit. | 115 // first committed frame draws should lead to another commit. |
| 116 class LayerTreeHostTestSetNeedsCommit2 : public LayerTreeHostTest { | 116 class LayerTreeHostTestSetNeedsCommit2 : public LayerTreeHostTest { |
| 117 public: | 117 public: |
| 118 LayerTreeHostTestSetNeedsCommit2() : num_commits_(0), num_draws_(0) {} | 118 LayerTreeHostTestSetNeedsCommit2() : num_commits_(0), num_draws_(0) {} |
| 119 | 119 |
| 120 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } | 120 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
| 121 | 121 |
| 122 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 122 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 123 ++num_draws_; |
| 124 } |
| 125 |
| 126 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 127 ++num_commits_; |
| 123 if (impl->active_tree()->source_frame_number() == 0) | 128 if (impl->active_tree()->source_frame_number() == 0) |
| 124 PostSetNeedsCommitToMainThread(); | 129 PostSetNeedsCommitToMainThread(); |
| 125 else if (impl->active_tree()->source_frame_number() == 1) | 130 else if (impl->active_tree()->source_frame_number() == 1) |
| 126 EndTest(); | 131 EndTest(); |
| 127 } | 132 } |
| 128 | 133 |
| 129 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { | |
| 130 num_commits_++; | |
| 131 } | |
| 132 | |
| 133 virtual void AfterTest() OVERRIDE { | 134 virtual void AfterTest() OVERRIDE { |
| 134 EXPECT_EQ(2, num_commits_); | 135 EXPECT_EQ(2, num_commits_); |
| 135 EXPECT_GE(2, num_draws_); | 136 EXPECT_LE(1, num_draws_); |
| 136 } | 137 } |
| 137 | 138 |
| 138 private: | 139 private: |
| 139 int num_commits_; | 140 int num_commits_; |
| 140 int num_draws_; | 141 int num_draws_; |
| 141 }; | 142 }; |
| 142 | 143 |
| 143 MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsCommit2); | 144 MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsCommit2); |
| 144 | 145 |
| 145 // 1 setNeedsRedraw after the first commit has completed should lead to 1 | 146 // 1 setNeedsRedraw after the first commit has completed should lead to 1 |
| (...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 687 | 688 |
| 688 LayerImpl* root = impl->active_tree()->root_layer(); | 689 LayerImpl* root = impl->active_tree()->root_layer(); |
| 689 LayerImpl* child = impl->active_tree()->root_layer()->children()[0]; | 690 LayerImpl* child = impl->active_tree()->root_layer()->children()[0]; |
| 690 | 691 |
| 691 // Positions remain in layout pixels. | 692 // Positions remain in layout pixels. |
| 692 EXPECT_EQ(gfx::Point(0, 0), root->position()); | 693 EXPECT_EQ(gfx::Point(0, 0), root->position()); |
| 693 EXPECT_EQ(gfx::Point(2, 2), child->position()); | 694 EXPECT_EQ(gfx::Point(2, 2), child->position()); |
| 694 | 695 |
| 695 // Compute all the layer transforms for the frame. | 696 // Compute all the layer transforms for the frame. |
| 696 LayerTreeHostImpl::FrameData frame_data; | 697 LayerTreeHostImpl::FrameData frame_data; |
| 697 impl->PrepareToDraw(&frame_data); | 698 impl->PrepareToDraw(&frame_data, gfx::Rect()); |
| 698 impl->DidDrawAllLayers(frame_data); | 699 impl->DidDrawAllLayers(frame_data); |
| 699 | 700 |
| 700 const LayerImplList& render_surface_layer_list = | 701 const LayerImplList& render_surface_layer_list = |
| 701 *frame_data.render_surface_layer_list; | 702 *frame_data.render_surface_layer_list; |
| 702 | 703 |
| 703 // Both layers should be drawing into the root render surface. | 704 // Both layers should be drawing into the root render surface. |
| 704 ASSERT_EQ(1u, render_surface_layer_list.size()); | 705 ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 705 ASSERT_EQ(root->render_surface(), | 706 ASSERT_EQ(root->render_surface(), |
| 706 render_surface_layer_list[0]->render_surface()); | 707 render_surface_layer_list[0]->render_surface()); |
| 707 ASSERT_EQ(2u, root->render_surface()->layer_list().size()); | 708 ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1117 | 1118 |
| 1118 virtual void AfterTest() OVERRIDE {} | 1119 virtual void AfterTest() OVERRIDE {} |
| 1119 }; | 1120 }; |
| 1120 | 1121 |
| 1121 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestCompositeAndReadbackCleanup); | 1122 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestCompositeAndReadbackCleanup); |
| 1122 | 1123 |
| 1123 class LayerTreeHostTestSurfaceNotAllocatedForLayersOutsideMemoryLimit | 1124 class LayerTreeHostTestSurfaceNotAllocatedForLayersOutsideMemoryLimit |
| 1124 : public LayerTreeHostTest { | 1125 : public LayerTreeHostTest { |
| 1125 public: | 1126 public: |
| 1126 LayerTreeHostTestSurfaceNotAllocatedForLayersOutsideMemoryLimit() | 1127 LayerTreeHostTestSurfaceNotAllocatedForLayersOutsideMemoryLimit() |
| 1127 : root_layer_(ContentLayerWithUpdateTracking::Create(&fake_delegate_)), | 1128 : root_layer_(FakeContentLayer::Create(&client_)), |
| 1128 surface_layer1_( | 1129 surface_layer1_( |
| 1129 ContentLayerWithUpdateTracking::Create(&fake_delegate_)), | 1130 FakeContentLayer::Create(&client_)), |
| 1130 replica_layer1_( | 1131 replica_layer1_( |
| 1131 ContentLayerWithUpdateTracking::Create(&fake_delegate_)), | 1132 FakeContentLayer::Create(&client_)), |
| 1132 surface_layer2_( | 1133 surface_layer2_( |
| 1133 ContentLayerWithUpdateTracking::Create(&fake_delegate_)), | 1134 FakeContentLayer::Create(&client_)), |
| 1134 replica_layer2_( | 1135 replica_layer2_( |
| 1135 ContentLayerWithUpdateTracking::Create(&fake_delegate_)) {} | 1136 FakeContentLayer::Create(&client_)) {} |
| 1136 | 1137 |
| 1137 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { | 1138 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { |
| 1138 settings->cache_render_pass_contents = true; | 1139 settings->cache_render_pass_contents = true; |
| 1139 } | 1140 } |
| 1140 | 1141 |
| 1141 virtual void BeginTest() OVERRIDE { | 1142 virtual void BeginTest() OVERRIDE { |
| 1142 layer_tree_host()->SetViewportSize(gfx::Size(100, 100), | 1143 layer_tree_host()->SetViewportSize(gfx::Size(100, 100), |
| 1143 gfx::Size(100, 100)); | 1144 gfx::Size(100, 100)); |
| 1144 | 1145 |
| 1145 root_layer_->SetBounds(gfx::Size(100, 100)); | 1146 root_layer_->SetBounds(gfx::Size(100, 100)); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1185 EXPECT_FALSE(renderer->HaveCachedResourcesForRenderPassId( | 1186 EXPECT_FALSE(renderer->HaveCachedResourcesForRenderPassId( |
| 1186 surface1_render_pass_id)); | 1187 surface1_render_pass_id)); |
| 1187 EXPECT_FALSE(renderer->HaveCachedResourcesForRenderPassId( | 1188 EXPECT_FALSE(renderer->HaveCachedResourcesForRenderPassId( |
| 1188 surface2_render_pass_id)); | 1189 surface2_render_pass_id)); |
| 1189 | 1190 |
| 1190 EndTest(); | 1191 EndTest(); |
| 1191 break; | 1192 break; |
| 1192 } | 1193 } |
| 1193 } | 1194 } |
| 1194 | 1195 |
| 1196 virtual void DidCommitAndDrawFrame() OVERRIDE { |
| 1197 if (!TestEnded()) |
| 1198 root_layer_->SetNeedsDisplay(); |
| 1199 } |
| 1200 |
| 1195 virtual void AfterTest() OVERRIDE { | 1201 virtual void AfterTest() OVERRIDE { |
| 1196 EXPECT_EQ(2, root_layer_->PaintContentsCount()); | 1202 EXPECT_EQ(3u, root_layer_->update_count()); |
| 1197 EXPECT_EQ(2, surface_layer1_->PaintContentsCount()); | 1203 EXPECT_EQ(3u, surface_layer1_->update_count()); |
| 1198 EXPECT_EQ(2, surface_layer2_->PaintContentsCount()); | 1204 EXPECT_EQ(3u, surface_layer2_->update_count()); |
| 1199 } | 1205 } |
| 1200 | 1206 |
| 1201 private: | 1207 private: |
| 1202 FakeContentLayerClient fake_delegate_; | 1208 FakeContentLayerClient client_; |
| 1203 scoped_refptr<ContentLayerWithUpdateTracking> root_layer_; | 1209 scoped_refptr<FakeContentLayer> root_layer_; |
| 1204 scoped_refptr<ContentLayerWithUpdateTracking> surface_layer1_; | 1210 scoped_refptr<FakeContentLayer> surface_layer1_; |
| 1205 scoped_refptr<ContentLayerWithUpdateTracking> replica_layer1_; | 1211 scoped_refptr<FakeContentLayer> replica_layer1_; |
| 1206 scoped_refptr<ContentLayerWithUpdateTracking> surface_layer2_; | 1212 scoped_refptr<FakeContentLayer> surface_layer2_; |
| 1207 scoped_refptr<ContentLayerWithUpdateTracking> replica_layer2_; | 1213 scoped_refptr<FakeContentLayer> replica_layer2_; |
| 1208 }; | 1214 }; |
| 1209 | 1215 |
| 1210 SINGLE_AND_MULTI_THREAD_TEST_F( | 1216 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 1211 LayerTreeHostTestSurfaceNotAllocatedForLayersOutsideMemoryLimit); | 1217 LayerTreeHostTestSurfaceNotAllocatedForLayersOutsideMemoryLimit); |
| 1212 | 1218 |
| 1213 class EvictionTestLayer : public Layer { | 1219 class EvictionTestLayer : public Layer { |
| 1214 public: | 1220 public: |
| 1215 static scoped_refptr<EvictionTestLayer> Create() { | 1221 static scoped_refptr<EvictionTestLayer> Create() { |
| 1216 return make_scoped_refptr(new EvictionTestLayer()); | 1222 return make_scoped_refptr(new EvictionTestLayer()); |
| 1217 } | 1223 } |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1355 // Commit 6: Triggered by the eviction, post an eviction task in | 1361 // Commit 6: Triggered by the eviction, post an eviction task in |
| 1356 // Layout(), which will be a noop, letting the commit (which recreates the | 1362 // Layout(), which will be a noop, letting the commit (which recreates the |
| 1357 // textures) go through and draw a frame, then end the test. | 1363 // textures) go through and draw a frame, then end the test. |
| 1358 // | 1364 // |
| 1359 // Commits 1+2 test the eviction recovery path where eviction happens outside | 1365 // Commits 1+2 test the eviction recovery path where eviction happens outside |
| 1360 // of the beginFrame/commit pair. | 1366 // of the beginFrame/commit pair. |
| 1361 // Commits 3+4 test the eviction recovery path where eviction happens inside | 1367 // Commits 3+4 test the eviction recovery path where eviction happens inside |
| 1362 // the beginFrame/commit pair. | 1368 // the beginFrame/commit pair. |
| 1363 // Commits 5+6 test the path where an eviction happens during the eviction | 1369 // Commits 5+6 test the path where an eviction happens during the eviction |
| 1364 // recovery path. | 1370 // recovery path. |
| 1365 virtual void DidCommitAndDrawFrame() OVERRIDE { | 1371 virtual void DidCommit() OVERRIDE { |
| 1366 switch (num_commits_) { | 1372 switch (num_commits_) { |
| 1367 case 1: | 1373 case 1: |
| 1368 EXPECT_TRUE(layer_->HaveBackingTexture()); | 1374 EXPECT_TRUE(layer_->HaveBackingTexture()); |
| 1369 PostEvictTextures(); | 1375 PostEvictTextures(); |
| 1370 break; | 1376 break; |
| 1371 case 2: | 1377 case 2: |
| 1372 EXPECT_TRUE(layer_->HaveBackingTexture()); | 1378 EXPECT_TRUE(layer_->HaveBackingTexture()); |
| 1373 layer_tree_host()->SetNeedsCommit(); | 1379 layer_tree_host()->SetNeedsCommit(); |
| 1374 break; | 1380 break; |
| 1375 case 3: | 1381 case 3: |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1442 virtual void BeginTest() OVERRIDE { | 1448 virtual void BeginTest() OVERRIDE { |
| 1443 layer_tree_host()->SetViewportSize(gfx::Size(10, 10), gfx::Size(10, 10)); | 1449 layer_tree_host()->SetViewportSize(gfx::Size(10, 10), gfx::Size(10, 10)); |
| 1444 layer_tree_host()->root_layer()->SetBounds(gfx::Size(10, 10)); | 1450 layer_tree_host()->root_layer()->SetBounds(gfx::Size(10, 10)); |
| 1445 | 1451 |
| 1446 PostSetNeedsCommitToMainThread(); | 1452 PostSetNeedsCommitToMainThread(); |
| 1447 } | 1453 } |
| 1448 | 1454 |
| 1449 virtual void DidCommit() OVERRIDE { | 1455 virtual void DidCommit() OVERRIDE { |
| 1450 if (num_draw_layers_ == 2) | 1456 if (num_draw_layers_ == 2) |
| 1451 return; | 1457 return; |
| 1452 PostSetNeedsCommitToMainThread(); | 1458 layer_tree_host()->root_layer()->SetNeedsDisplay(); |
| 1453 } | 1459 } |
| 1454 | 1460 |
| 1455 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 1461 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 1456 if (num_draw_layers_ == 1) | 1462 if (num_draw_layers_ == 1) |
| 1457 num_commit_complete_++; | 1463 num_commit_complete_++; |
| 1458 } | 1464 } |
| 1459 | 1465 |
| 1460 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 1466 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 1461 num_draw_layers_++; | 1467 num_draw_layers_++; |
| 1462 if (num_draw_layers_ == 2) | 1468 if (num_draw_layers_ == 2) |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1477 | 1483 |
| 1478 class LayerTreeHostTestContinuousInvalidate : public LayerTreeHostTest { | 1484 class LayerTreeHostTestContinuousInvalidate : public LayerTreeHostTest { |
| 1479 public: | 1485 public: |
| 1480 LayerTreeHostTestContinuousInvalidate() | 1486 LayerTreeHostTestContinuousInvalidate() |
| 1481 : num_commit_complete_(0), num_draw_layers_(0) {} | 1487 : num_commit_complete_(0), num_draw_layers_(0) {} |
| 1482 | 1488 |
| 1483 virtual void BeginTest() OVERRIDE { | 1489 virtual void BeginTest() OVERRIDE { |
| 1484 layer_tree_host()->SetViewportSize(gfx::Size(10, 10), gfx::Size(10, 10)); | 1490 layer_tree_host()->SetViewportSize(gfx::Size(10, 10), gfx::Size(10, 10)); |
| 1485 layer_tree_host()->root_layer()->SetBounds(gfx::Size(10, 10)); | 1491 layer_tree_host()->root_layer()->SetBounds(gfx::Size(10, 10)); |
| 1486 | 1492 |
| 1487 content_layer_ = ContentLayer::Create(&fake_delegate_); | 1493 content_layer_ = ContentLayer::Create(&client_); |
| 1488 content_layer_->SetBounds(gfx::Size(10, 10)); | 1494 content_layer_->SetBounds(gfx::Size(10, 10)); |
| 1489 content_layer_->SetPosition(gfx::PointF(0.f, 0.f)); | 1495 content_layer_->SetPosition(gfx::PointF(0.f, 0.f)); |
| 1490 content_layer_->SetAnchorPoint(gfx::PointF(0.f, 0.f)); | 1496 content_layer_->SetAnchorPoint(gfx::PointF(0.f, 0.f)); |
| 1491 content_layer_->SetIsDrawable(true); | 1497 content_layer_->SetIsDrawable(true); |
| 1492 layer_tree_host()->root_layer()->AddChild(content_layer_); | 1498 layer_tree_host()->root_layer()->AddChild(content_layer_); |
| 1493 | 1499 |
| 1494 PostSetNeedsCommitToMainThread(); | 1500 PostSetNeedsCommitToMainThread(); |
| 1495 } | 1501 } |
| 1496 | 1502 |
| 1497 virtual void DidCommit() OVERRIDE { | 1503 virtual void DidCommit() OVERRIDE { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1510 if (num_draw_layers_ == 2) | 1516 if (num_draw_layers_ == 2) |
| 1511 EndTest(); | 1517 EndTest(); |
| 1512 } | 1518 } |
| 1513 | 1519 |
| 1514 virtual void AfterTest() OVERRIDE { | 1520 virtual void AfterTest() OVERRIDE { |
| 1515 // Check that we didn't commit twice between first and second draw. | 1521 // Check that we didn't commit twice between first and second draw. |
| 1516 EXPECT_EQ(1, num_commit_complete_); | 1522 EXPECT_EQ(1, num_commit_complete_); |
| 1517 } | 1523 } |
| 1518 | 1524 |
| 1519 private: | 1525 private: |
| 1520 FakeContentLayerClient fake_delegate_; | 1526 FakeContentLayerClient client_; |
| 1521 scoped_refptr<Layer> content_layer_; | 1527 scoped_refptr<Layer> content_layer_; |
| 1522 int num_commit_complete_; | 1528 int num_commit_complete_; |
| 1523 int num_draw_layers_; | 1529 int num_draw_layers_; |
| 1524 }; | 1530 }; |
| 1525 | 1531 |
| 1526 MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousInvalidate); | 1532 MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousInvalidate); |
| 1527 | 1533 |
| 1528 class LayerTreeHostTestDeferCommits : public LayerTreeHostTest { | 1534 class LayerTreeHostTestDeferCommits : public LayerTreeHostTest { |
| 1529 public: | 1535 public: |
| 1530 LayerTreeHostTestDeferCommits() | 1536 LayerTreeHostTestDeferCommits() |
| (...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2174 } | 2180 } |
| 2175 | 2181 |
| 2176 private: | 2182 private: |
| 2177 base::TimeTicks frame_time_; | 2183 base::TimeTicks frame_time_; |
| 2178 }; | 2184 }; |
| 2179 | 2185 |
| 2180 MULTI_THREAD_TEST_F(LayerTreeHostTestVSyncNotification); | 2186 MULTI_THREAD_TEST_F(LayerTreeHostTestVSyncNotification); |
| 2181 | 2187 |
| 2182 } // namespace | 2188 } // namespace |
| 2183 } // namespace cc | 2189 } // namespace cc |
| OLD | NEW |