Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Side by Side Diff: cc/trees/layer_tree_host_unittest.cc

Issue 1020803002: Don't let unittests access LTH from the impl thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/synchronization/lock.h" 10 #include "base/synchronization/lock.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 #include "ui/gfx/geometry/vector2d_conversions.h" 63 #include "ui/gfx/geometry/vector2d_conversions.h"
64 64
65 using testing::_; 65 using testing::_;
66 using testing::AnyNumber; 66 using testing::AnyNumber;
67 using testing::AtLeast; 67 using testing::AtLeast;
68 using testing::Mock; 68 using testing::Mock;
69 69
70 namespace cc { 70 namespace cc {
71 namespace { 71 namespace {
72 72
73 class LayerTreeHostTest : public LayerTreeTest {}; 73 class LayerTreeHostTest : public LayerTreeTest {
74 public:
75 LayerTreeHostTest() : contents_texture_manager_(nullptr) {}
76
77 void DidInitializeOutputSurface() override {
78 contents_texture_manager_ = layer_tree_host()->contents_texture_manager();
79 }
80
81 protected:
82 PrioritizedResourceManager* contents_texture_manager_;
83 };
74 84
75 // Test if the LTHI receives ReadyToActivate notifications from the TileManager 85 // Test if the LTHI receives ReadyToActivate notifications from the TileManager
76 // when no raster tasks get scheduled. 86 // when no raster tasks get scheduled.
77 class LayerTreeHostTestReadyToActivateEmpty : public LayerTreeHostTest { 87 class LayerTreeHostTestReadyToActivateEmpty : public LayerTreeHostTest {
78 public: 88 public:
79 LayerTreeHostTestReadyToActivateEmpty() 89 LayerTreeHostTestReadyToActivateEmpty()
80 : did_notify_ready_to_activate_(false), 90 : did_notify_ready_to_activate_(false),
81 all_tiles_required_for_activation_are_ready_to_draw_(false), 91 all_tiles_required_for_activation_are_ready_to_draw_(false),
82 required_for_activation_count_(0) {} 92 required_for_activation_count_(0) {}
83 93
(...skipping 1257 matching lines...) Expand 10 before | Expand all | Expand 10 after
1341 layer_tree_host()->SetRootLayer(layer_); 1351 layer_tree_host()->SetRootLayer(layer_);
1342 LayerTreeHostTest::SetupTree(); 1352 LayerTreeHostTest::SetupTree();
1343 } 1353 }
1344 1354
1345 void BeginTest() override { 1355 void BeginTest() override {
1346 drew_frame_ = -1; 1356 drew_frame_ = -1;
1347 PostSetNeedsCommitToMainThread(); 1357 PostSetNeedsCommitToMainThread();
1348 } 1358 }
1349 1359
1350 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { 1360 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override {
1351 ASSERT_EQ(0u, layer_tree_host()->settings().max_partial_texture_updates); 1361 ASSERT_EQ(0u, impl->settings().max_partial_texture_updates);
1352 1362
1353 TestWebGraphicsContext3D* context = TestContext(); 1363 TestWebGraphicsContext3D* context = TestContext();
1354 1364
1355 switch (impl->active_tree()->source_frame_number()) { 1365 switch (impl->active_tree()->source_frame_number()) {
1356 case 0: 1366 case 0:
1357 // Number of textures should be one for each layer 1367 // Number of textures should be one for each layer
1358 ASSERT_EQ(2u, context->NumTextures()); 1368 ASSERT_EQ(2u, context->NumTextures());
1359 // Number of textures used for commit should be one for each layer. 1369 // Number of textures used for commit should be one for each layer.
1360 EXPECT_EQ(2u, context->NumUsedTextures()); 1370 EXPECT_EQ(2u, context->NumUsedTextures());
1361 // Verify that used texture is correct. 1371 // Verify that used texture is correct.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1420 }; 1430 };
1421 1431
1422 MULTI_THREAD_DIRECT_RENDERER_NOIMPL_TEST_F( 1432 MULTI_THREAD_DIRECT_RENDERER_NOIMPL_TEST_F(
1423 LayerTreeHostTestDirectRendererAtomicCommit); 1433 LayerTreeHostTestDirectRendererAtomicCommit);
1424 1434
1425 // TODO(sohanjg) : Remove it once impl-side painting ships everywhere. 1435 // TODO(sohanjg) : Remove it once impl-side painting ships everywhere.
1426 class LayerTreeHostTestDelegatingRendererAtomicCommit 1436 class LayerTreeHostTestDelegatingRendererAtomicCommit
1427 : public LayerTreeHostTestDirectRendererAtomicCommit { 1437 : public LayerTreeHostTestDirectRendererAtomicCommit {
1428 public: 1438 public:
1429 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { 1439 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override {
1430 ASSERT_EQ(0u, layer_tree_host()->settings().max_partial_texture_updates); 1440 ASSERT_EQ(0u, impl->settings().max_partial_texture_updates);
1431 1441
1432 TestWebGraphicsContext3D* context = TestContext(); 1442 TestWebGraphicsContext3D* context = TestContext();
1433 1443
1434 switch (impl->active_tree()->source_frame_number()) { 1444 switch (impl->active_tree()->source_frame_number()) {
1435 case 0: 1445 case 0:
1436 // Number of textures should be one for each layer 1446 // Number of textures should be one for each layer
1437 ASSERT_EQ(2u, context->NumTextures()); 1447 ASSERT_EQ(2u, context->NumTextures());
1438 // Number of textures used for commit should be one for each layer. 1448 // Number of textures used for commit should be one for each layer.
1439 EXPECT_EQ(2u, context->NumUsedTextures()); 1449 EXPECT_EQ(2u, context->NumUsedTextures());
1440 // Verify that used texture is correct. 1450 // Verify that used texture is correct.
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1537 case 5: 1547 case 5:
1538 EndTest(); 1548 EndTest();
1539 break; 1549 break;
1540 default: 1550 default:
1541 NOTREACHED() << layer_tree_host()->source_frame_number(); 1551 NOTREACHED() << layer_tree_host()->source_frame_number();
1542 break; 1552 break;
1543 } 1553 }
1544 } 1554 }
1545 1555
1546 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { 1556 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
1547 ASSERT_EQ(1u, layer_tree_host()->settings().max_partial_texture_updates); 1557 ASSERT_EQ(1u, impl->settings().max_partial_texture_updates);
1548 1558
1549 TestWebGraphicsContext3D* context = TestContext(); 1559 TestWebGraphicsContext3D* context = TestContext();
1550 1560
1551 switch (impl->active_tree()->source_frame_number()) { 1561 switch (impl->active_tree()->source_frame_number()) {
1552 case 0: 1562 case 0:
1553 // Number of textures should be one for each layer. 1563 // Number of textures should be one for each layer.
1554 ASSERT_EQ(2u, context->NumTextures()); 1564 ASSERT_EQ(2u, context->NumTextures());
1555 // Number of textures used for commit should be one for each layer. 1565 // Number of textures used for commit should be one for each layer.
1556 EXPECT_EQ(2u, context->NumUsedTextures()); 1566 EXPECT_EQ(2u, context->NumUsedTextures());
1557 // Verify that used textures are correct. 1567 // Verify that used textures are correct.
(...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after
2261 root_layer_->AddChild(child_layer1_); 2271 root_layer_->AddChild(child_layer1_);
2262 root_layer_->AddChild(child_layer2_); 2272 root_layer_->AddChild(child_layer2_);
2263 layer_tree_host()->SetRootLayer(root_layer_); 2273 layer_tree_host()->SetRootLayer(root_layer_);
2264 PostSetNeedsCommitToMainThread(); 2274 PostSetNeedsCommitToMainThread();
2265 } 2275 }
2266 2276
2267 void DidSetVisibleOnImplTree(LayerTreeHostImpl* host_impl, 2277 void DidSetVisibleOnImplTree(LayerTreeHostImpl* host_impl,
2268 bool visible) override { 2278 bool visible) override {
2269 if (visible) { 2279 if (visible) {
2270 // One backing should remain unevicted. 2280 // One backing should remain unevicted.
2271 EXPECT_EQ( 2281 EXPECT_EQ(100u * 100u * 4u * 1u,
2272 100u * 100u * 4u * 1u, 2282 contents_texture_manager_->MemoryUseBytes());
2273 layer_tree_host()->contents_texture_manager()->MemoryUseBytes());
2274 } else { 2283 } else {
2275 EXPECT_EQ( 2284 EXPECT_EQ(0u, contents_texture_manager_->MemoryUseBytes());
2276 0u, layer_tree_host()->contents_texture_manager()->MemoryUseBytes());
2277 } 2285 }
2278 2286
2279 // Make sure that contents textures are marked as having been 2287 // Make sure that contents textures are marked as having been
2280 // purged. 2288 // purged.
2281 EXPECT_TRUE(host_impl->active_tree()->ContentsTexturesPurged()); 2289 EXPECT_TRUE(host_impl->active_tree()->ContentsTexturesPurged());
2282 // End the test in this state. 2290 // End the test in this state.
2283 EndTest(); 2291 EndTest();
2284 } 2292 }
2285 2293
2286 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { 2294 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
2287 ++num_commits_; 2295 ++num_commits_;
2288 switch (num_commits_) { 2296 switch (num_commits_) {
2289 case 1: 2297 case 1:
2290 // All three backings should have memory. 2298 // All three backings should have memory.
2291 EXPECT_EQ( 2299 EXPECT_EQ(100u * 100u * 4u * 3u,
2292 100u * 100u * 4u * 3u, 2300 contents_texture_manager_->MemoryUseBytes());
2293 layer_tree_host()->contents_texture_manager()->MemoryUseBytes()); 2301
2294 // Set a new policy that will kick out 1 of the 3 resources. 2302 // Set a new policy that will kick out 1 of the 3 resources.
2295 // Because a resource was evicted, a commit will be kicked off. 2303 // Because a resource was evicted, a commit will be kicked off.
2296 host_impl->SetMemoryPolicy( 2304 host_impl->SetMemoryPolicy(
2297 ManagedMemoryPolicy(100 * 100 * 4 * 2, 2305 ManagedMemoryPolicy(100 * 100 * 4 * 2,
2298 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING, 2306 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING,
2299 1000)); 2307 1000));
2300 break; 2308 break;
2301 case 2: 2309 case 2:
2302 // Only two backings should have memory. 2310 // Only two backings should have memory.
2303 EXPECT_EQ( 2311 EXPECT_EQ(100u * 100u * 4u * 2u,
2304 100u * 100u * 4u * 2u, 2312 contents_texture_manager_->MemoryUseBytes());
2305 layer_tree_host()->contents_texture_manager()->MemoryUseBytes());
2306 // Become backgrounded, which will cause 1 more resource to be 2313 // Become backgrounded, which will cause 1 more resource to be
2307 // evicted. 2314 // evicted.
2308 PostSetVisibleToMainThread(false); 2315 PostSetVisibleToMainThread(false);
2309 break; 2316 break;
2310 default: 2317 default:
2311 // No further commits should happen because this is not visible 2318 // No further commits should happen because this is not visible
2312 // anymore. 2319 // anymore.
2313 NOTREACHED(); 2320 NOTREACHED();
2314 break; 2321 break;
2315 } 2322 }
(...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after
3124 break; 3131 break;
3125 case 4: 3132 case 4:
3126 // Creation after deletion: two more creates should total up to 3133 // Creation after deletion: two more creates should total up to
3127 // three textures. 3134 // three textures.
3128 ASSERT_EQ(3u, context->NumTextures()); 3135 ASSERT_EQ(3u, context->NumTextures());
3129 break; 3136 break;
3130 } 3137 }
3131 } 3138 }
3132 3139
3133 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { 3140 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
3134 if (!layer_tree_host()->settings().impl_side_painting) 3141 if (!impl->settings().impl_side_painting)
3135 PerformTest(impl); 3142 PerformTest(impl);
3136 } 3143 }
3137 3144
3138 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { 3145 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override {
3139 if (layer_tree_host()->settings().impl_side_painting) 3146 if (impl->settings().impl_side_painting)
3140 PerformTest(impl); 3147 PerformTest(impl);
3141 } 3148 }
3142 3149
3143 void AfterTest() override {} 3150 void AfterTest() override {}
3144 3151
3145 private: 3152 private:
3146 // Must clear all resources before exiting. 3153 // Must clear all resources before exiting.
3147 void ClearResources() { 3154 void ClearResources() {
3148 for (int i = 0; i < num_ui_resources_; i++) 3155 for (int i = 0; i < num_ui_resources_; i++)
3149 ui_resources_[i] = nullptr; 3156 ui_resources_[i] = nullptr;
(...skipping 3292 matching lines...) Expand 10 before | Expand all | Expand 10 after
6442 6449
6443 void AfterTest() override {} 6450 void AfterTest() override {}
6444 6451
6445 private: 6452 private:
6446 scoped_refptr<Layer> child_; 6453 scoped_refptr<Layer> child_;
6447 }; 6454 };
6448 6455
6449 SINGLE_AND_MULTI_THREAD_TEST_F(LayerPreserveRenderSurfaceFromOutputRequests); 6456 SINGLE_AND_MULTI_THREAD_TEST_F(LayerPreserveRenderSurfaceFromOutputRequests);
6450 6457
6451 } // namespace cc 6458 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698