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

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

Issue 2322943003: cc: Move UI Resource management out of LayerTreeHost. (Closed)
Patch Set: virtual dtor Created 4 years, 3 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
« no previous file with comments | « cc/trees/layer_tree_host_unittest.cc ('k') | cc/trees/layer_tree_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "cc/layers/heads_up_display_layer.h" 9 #include "cc/layers/heads_up_display_layer.h"
10 #include "cc/layers/layer_impl.h" 10 #include "cc/layers/layer_impl.h"
11 #include "cc/layers/painted_scrollbar_layer.h" 11 #include "cc/layers/painted_scrollbar_layer.h"
12 #include "cc/layers/picture_layer.h" 12 #include "cc/layers/picture_layer.h"
13 #include "cc/layers/texture_layer.h" 13 #include "cc/layers/texture_layer.h"
14 #include "cc/layers/texture_layer_impl.h" 14 #include "cc/layers/texture_layer_impl.h"
15 #include "cc/layers/video_layer.h" 15 #include "cc/layers/video_layer.h"
16 #include "cc/layers/video_layer_impl.h" 16 #include "cc/layers/video_layer_impl.h"
17 #include "cc/output/filter_operations.h" 17 #include "cc/output/filter_operations.h"
18 #include "cc/resources/single_release_callback.h" 18 #include "cc/resources/single_release_callback.h"
19 #include "cc/resources/ui_resource_manager.h"
19 #include "cc/test/fake_content_layer_client.h" 20 #include "cc/test/fake_content_layer_client.h"
20 #include "cc/test/fake_layer_tree_host_client.h" 21 #include "cc/test/fake_layer_tree_host_client.h"
21 #include "cc/test/fake_output_surface.h" 22 #include "cc/test/fake_output_surface.h"
22 #include "cc/test/fake_output_surface_client.h" 23 #include "cc/test/fake_output_surface_client.h"
23 #include "cc/test/fake_painted_scrollbar_layer.h" 24 #include "cc/test/fake_painted_scrollbar_layer.h"
24 #include "cc/test/fake_picture_layer.h" 25 #include "cc/test/fake_picture_layer.h"
25 #include "cc/test/fake_picture_layer_impl.h" 26 #include "cc/test/fake_picture_layer_impl.h"
26 #include "cc/test/fake_resource_provider.h" 27 #include "cc/test/fake_resource_provider.h"
27 #include "cc/test/fake_scoped_ui_resource.h" 28 #include "cc/test/fake_scoped_ui_resource.h"
28 #include "cc/test/fake_scrollbar.h" 29 #include "cc/test/fake_scrollbar.h"
(...skipping 1193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1222 } 1223 }
1223 }; 1224 };
1224 1225
1225 // Losing context after an UI resource has been created. 1226 // Losing context after an UI resource has been created.
1226 class UIResourceLostAfterCommit : public UIResourceLostTestSimple { 1227 class UIResourceLostAfterCommit : public UIResourceLostTestSimple {
1227 public: 1228 public:
1228 void StepCompleteOnMainThread(int step) override { 1229 void StepCompleteOnMainThread(int step) override {
1229 EXPECT_TRUE(layer_tree_host()->GetTaskRunnerProvider()->IsMainThread()); 1230 EXPECT_TRUE(layer_tree_host()->GetTaskRunnerProvider()->IsMainThread());
1230 switch (step) { 1231 switch (step) {
1231 case 0: 1232 case 0:
1232 ui_resource_ = FakeScopedUIResource::Create(layer_tree_host()); 1233 ui_resource_ = FakeScopedUIResource::Create(
1234 layer_tree_host()->GetUIResourceManager());
1233 // Expects a valid UIResourceId. 1235 // Expects a valid UIResourceId.
1234 EXPECT_NE(0, ui_resource_->id()); 1236 EXPECT_NE(0, ui_resource_->id());
1235 PostSetNeedsCommitToMainThread(); 1237 PostSetNeedsCommitToMainThread();
1236 break; 1238 break;
1237 case 4: 1239 case 4:
1238 // Release resource before ending the test. 1240 // Release resource before ending the test.
1239 ui_resource_ = nullptr; 1241 ui_resource_ = nullptr;
1240 EndTest(); 1242 EndTest();
1241 break; 1243 break;
1242 case 5: 1244 case 5:
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1280 // test_id1_ to have been created. 1282 // test_id1_ to have been created.
1281 // 3. Create one resource -> Delete that same resource -> Context Lost => Expect 1283 // 3. Create one resource -> Delete that same resource -> Context Lost => Expect
1282 // the resource to not exist in the manager. 1284 // the resource to not exist in the manager.
1283 class UIResourceLostBeforeCommit : public UIResourceLostTestSimple { 1285 class UIResourceLostBeforeCommit : public UIResourceLostTestSimple {
1284 public: 1286 public:
1285 UIResourceLostBeforeCommit() : test_id0_(0), test_id1_(0) {} 1287 UIResourceLostBeforeCommit() : test_id0_(0), test_id1_(0) {}
1286 1288
1287 void StepCompleteOnMainThread(int step) override { 1289 void StepCompleteOnMainThread(int step) override {
1288 switch (step) { 1290 switch (step) {
1289 case 0: 1291 case 0:
1290 ui_resource_ = FakeScopedUIResource::Create(layer_tree_host()); 1292 ui_resource_ = FakeScopedUIResource::Create(
1293 layer_tree_host()->GetUIResourceManager());
1291 // Lose the context on the impl thread before the commit. 1294 // Lose the context on the impl thread before the commit.
1292 PostLoseContextToImplThread(); 1295 PostLoseContextToImplThread();
1293 break; 1296 break;
1294 case 2: 1297 case 2:
1295 // Sequence 2: 1298 // Sequence 2:
1296 // Currently one resource has been created. 1299 // Currently one resource has been created.
1297 test_id0_ = ui_resource_->id(); 1300 test_id0_ = ui_resource_->id();
1298 // Delete this resource. 1301 // Delete this resource.
1299 ui_resource_ = nullptr; 1302 ui_resource_ = nullptr;
1300 // Create another resource. 1303 // Create another resource.
1301 ui_resource_ = FakeScopedUIResource::Create(layer_tree_host()); 1304 ui_resource_ = FakeScopedUIResource::Create(
1305 layer_tree_host()->GetUIResourceManager());
1302 test_id1_ = ui_resource_->id(); 1306 test_id1_ = ui_resource_->id();
1303 // Sanity check that two resource creations return different ids. 1307 // Sanity check that two resource creations return different ids.
1304 EXPECT_NE(test_id0_, test_id1_); 1308 EXPECT_NE(test_id0_, test_id1_);
1305 // Lose the context on the impl thread before the commit. 1309 // Lose the context on the impl thread before the commit.
1306 PostLoseContextToImplThread(); 1310 PostLoseContextToImplThread();
1307 break; 1311 break;
1308 case 3: 1312 case 3:
1309 // Clear the manager of resources. 1313 // Clear the manager of resources.
1310 ui_resource_ = nullptr; 1314 ui_resource_ = nullptr;
1311 PostSetNeedsCommitToMainThread(); 1315 PostSetNeedsCommitToMainThread();
1312 break; 1316 break;
1313 case 4: 1317 case 4:
1314 // Sequence 3: 1318 // Sequence 3:
1315 ui_resource_ = FakeScopedUIResource::Create(layer_tree_host()); 1319 ui_resource_ = FakeScopedUIResource::Create(
1320 layer_tree_host()->GetUIResourceManager());
1316 test_id0_ = ui_resource_->id(); 1321 test_id0_ = ui_resource_->id();
1317 // Sanity check the UIResourceId should not be 0. 1322 // Sanity check the UIResourceId should not be 0.
1318 EXPECT_NE(0, test_id0_); 1323 EXPECT_NE(0, test_id0_);
1319 // Usually ScopedUIResource are deleted from the manager in their 1324 // Usually ScopedUIResource are deleted from the manager in their
1320 // destructor (so usually ui_resource_ = nullptr). But here we need 1325 // destructor (so usually ui_resource_ = nullptr). But here we need
1321 // ui_resource_ for the next step, so call DeleteUIResource directly. 1326 // ui_resource_ for the next step, so call DeleteUIResource directly.
1322 layer_tree_host()->DeleteUIResource(test_id0_); 1327 layer_tree_host()->GetUIResourceManager()->DeleteUIResource(test_id0_);
1323 // Delete the resouce and then lose the context. 1328 // Delete the resouce and then lose the context.
1324 PostLoseContextToImplThread(); 1329 PostLoseContextToImplThread();
1325 break; 1330 break;
1326 case 5: 1331 case 5:
1327 // Release resource before ending the test. 1332 // Release resource before ending the test.
1328 ui_resource_ = nullptr; 1333 ui_resource_ = nullptr;
1329 EndTest(); 1334 EndTest();
1330 break; 1335 break;
1331 case 6: 1336 case 6:
1332 NOTREACHED(); 1337 NOTREACHED();
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1377 1382
1378 SINGLE_AND_MULTI_THREAD_TEST_F(UIResourceLostBeforeCommit); 1383 SINGLE_AND_MULTI_THREAD_TEST_F(UIResourceLostBeforeCommit);
1379 1384
1380 // Losing UI resource before the pending trees is activated but after the 1385 // Losing UI resource before the pending trees is activated but after the
1381 // commit. Impl-side-painting only. 1386 // commit. Impl-side-painting only.
1382 class UIResourceLostBeforeActivateTree : public UIResourceLostTest { 1387 class UIResourceLostBeforeActivateTree : public UIResourceLostTest {
1383 void StepCompleteOnMainThread(int step) override { 1388 void StepCompleteOnMainThread(int step) override {
1384 EXPECT_TRUE(layer_tree_host()->GetTaskRunnerProvider()->IsMainThread()); 1389 EXPECT_TRUE(layer_tree_host()->GetTaskRunnerProvider()->IsMainThread());
1385 switch (step) { 1390 switch (step) {
1386 case 0: 1391 case 0:
1387 ui_resource_ = FakeScopedUIResource::Create(layer_tree_host()); 1392 ui_resource_ = FakeScopedUIResource::Create(
1393 layer_tree_host()->GetUIResourceManager());
1388 PostSetNeedsCommitToMainThread(); 1394 PostSetNeedsCommitToMainThread();
1389 break; 1395 break;
1390 case 3: 1396 case 3:
1391 test_id_ = ui_resource_->id(); 1397 test_id_ = ui_resource_->id();
1392 ui_resource_ = nullptr; 1398 ui_resource_ = nullptr;
1393 PostSetNeedsCommitToMainThread(); 1399 PostSetNeedsCommitToMainThread();
1394 break; 1400 break;
1395 case 5: 1401 case 5:
1396 // Release resource before ending the test. 1402 // Release resource before ending the test.
1397 ui_resource_ = nullptr; 1403 ui_resource_ = nullptr;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1460 1466
1461 SINGLE_AND_MULTI_THREAD_TEST_F(UIResourceLostBeforeActivateTree); 1467 SINGLE_AND_MULTI_THREAD_TEST_F(UIResourceLostBeforeActivateTree);
1462 1468
1463 // Resources evicted explicitly and by visibility changes. 1469 // Resources evicted explicitly and by visibility changes.
1464 class UIResourceLostEviction : public UIResourceLostTestSimple { 1470 class UIResourceLostEviction : public UIResourceLostTestSimple {
1465 public: 1471 public:
1466 void StepCompleteOnMainThread(int step) override { 1472 void StepCompleteOnMainThread(int step) override {
1467 EXPECT_TRUE(layer_tree_host()->GetTaskRunnerProvider()->IsMainThread()); 1473 EXPECT_TRUE(layer_tree_host()->GetTaskRunnerProvider()->IsMainThread());
1468 switch (step) { 1474 switch (step) {
1469 case 0: 1475 case 0:
1470 ui_resource_ = FakeScopedUIResource::Create(layer_tree_host()); 1476 ui_resource_ = FakeScopedUIResource::Create(
1471 ui_resource2_ = FakeScopedUIResource::Create(layer_tree_host()); 1477 layer_tree_host()->GetUIResourceManager());
1478 ui_resource2_ = FakeScopedUIResource::Create(
1479 layer_tree_host()->GetUIResourceManager());
1472 EXPECT_NE(0, ui_resource_->id()); 1480 EXPECT_NE(0, ui_resource_->id());
1473 EXPECT_NE(0, ui_resource2_->id()); 1481 EXPECT_NE(0, ui_resource2_->id());
1474 PostSetNeedsCommitToMainThread(); 1482 PostSetNeedsCommitToMainThread();
1475 break; 1483 break;
1476 case 2: 1484 case 2:
1477 // Make the tree not visible. 1485 // Make the tree not visible.
1478 PostSetVisibleToMainThread(false); 1486 PostSetVisibleToMainThread(false);
1479 ui_resource2_->DeleteResource(); 1487 ui_resource2_->DeleteResource();
1480 ui_resource3_ = FakeScopedUIResource::Create(layer_tree_host()); 1488 ui_resource3_ = FakeScopedUIResource::Create(
1489 layer_tree_host()->GetUIResourceManager());
1481 break; 1490 break;
1482 case 3: 1491 case 3:
1483 // Release resources before ending the test. 1492 // Release resources before ending the test.
1484 ui_resource_ = nullptr; 1493 ui_resource_ = nullptr;
1485 ui_resource2_ = nullptr; 1494 ui_resource2_ = nullptr;
1486 ui_resource3_ = nullptr; 1495 ui_resource3_ = nullptr;
1487 EndTest(); 1496 EndTest();
1488 break; 1497 break;
1489 case 4: 1498 case 4:
1490 NOTREACHED(); 1499 NOTREACHED();
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
1617 1626
1618 bool deferred_ = false; 1627 bool deferred_ = false;
1619 bool lost_ = true; 1628 bool lost_ = true;
1620 }; 1629 };
1621 1630
1622 SINGLE_AND_MULTI_THREAD_TEST_F( 1631 SINGLE_AND_MULTI_THREAD_TEST_F(
1623 LayerTreeHostContextTestLoseAfterSendingBeginMainFrame); 1632 LayerTreeHostContextTestLoseAfterSendingBeginMainFrame);
1624 1633
1625 } // namespace 1634 } // namespace
1626 } // namespace cc 1635 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_unittest.cc ('k') | cc/trees/layer_tree_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698