OLD | NEW |
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" |
(...skipping 1257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1268 } | 1268 } |
1269 } | 1269 } |
1270 }; | 1270 }; |
1271 | 1271 |
1272 SINGLE_AND_MULTI_THREAD_TEST_F(UIResourceLostAfterCommit); | 1272 SINGLE_AND_MULTI_THREAD_TEST_F(UIResourceLostAfterCommit); |
1273 | 1273 |
1274 // Losing context before UI resource requests can be commited. Three sequences | 1274 // Losing context before UI resource requests can be commited. Three sequences |
1275 // of creation/deletion are considered: | 1275 // of creation/deletion are considered: |
1276 // 1. Create one resource -> Context Lost => Expect the resource to have been | 1276 // 1. Create one resource -> Context Lost => Expect the resource to have been |
1277 // created. | 1277 // created. |
1278 // 2. Delete an exisiting resource (test_id0_) -> create a second resource | 1278 // 2. Delete an existing resource (test_id0_) -> create a second resource |
1279 // (test_id1_) -> Context Lost => Expect the test_id0_ to be removed and | 1279 // (test_id1_) -> Context Lost => Expect the test_id0_ to be removed and |
1280 // test_id1_ to have been created. | 1280 // test_id1_ to have been created. |
1281 // 3. Create one resource -> Delete that same resource -> Context Lost => Expect | 1281 // 3. Create one resource -> Delete that same resource -> Context Lost => Expect |
1282 // the resource to not exist in the manager. | 1282 // the resource to not exist in the manager. |
1283 class UIResourceLostBeforeCommit : public UIResourceLostTestSimple { | 1283 class UIResourceLostBeforeCommit : public UIResourceLostTestSimple { |
1284 public: | 1284 public: |
1285 UIResourceLostBeforeCommit() : test_id0_(0), test_id1_(0) {} | 1285 UIResourceLostBeforeCommit() : test_id0_(0), test_id1_(0) {} |
1286 | 1286 |
1287 void StepCompleteOnMainThread(int step) override { | 1287 void StepCompleteOnMainThread(int step) override { |
1288 switch (step) { | 1288 switch (step) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1346 EXPECT_EQ(0, ui_resource_->lost_resource_count); | 1346 EXPECT_EQ(0, ui_resource_->lost_resource_count); |
1347 // Resource Id on the impl-side has been created. | 1347 // Resource Id on the impl-side has been created. |
1348 PostSetNeedsCommitToMainThread(); | 1348 PostSetNeedsCommitToMainThread(); |
1349 break; | 1349 break; |
1350 case 3: | 1350 case 3: |
1351 // Sequence 2 (continued): | 1351 // Sequence 2 (continued): |
1352 // The previous resource should have been deleted. | 1352 // The previous resource should have been deleted. |
1353 EXPECT_EQ(0u, impl->ResourceIdForUIResource(test_id0_)); | 1353 EXPECT_EQ(0u, impl->ResourceIdForUIResource(test_id0_)); |
1354 // The second resource should have been created. | 1354 // The second resource should have been created. |
1355 EXPECT_NE(0u, impl->ResourceIdForUIResource(test_id1_)); | 1355 EXPECT_NE(0u, impl->ResourceIdForUIResource(test_id1_)); |
1356 // The second resource called the resource callback once and since the | 1356 // The second resource was not actually uploaded before the context |
1357 // context is lost, a "resource lost" callback was also issued. | 1357 // was lost, so it only got created once. |
1358 EXPECT_EQ(2, ui_resource_->resource_create_count); | 1358 EXPECT_EQ(1, ui_resource_->resource_create_count); |
1359 EXPECT_EQ(1, ui_resource_->lost_resource_count); | 1359 EXPECT_EQ(0, ui_resource_->lost_resource_count); |
1360 break; | 1360 break; |
1361 case 5: | 1361 case 5: |
1362 // Sequence 3 (continued): | 1362 // Sequence 3 (continued): |
1363 // Expect the resource callback to have been called once. | 1363 // Expect the resource callback to have been called once. |
1364 EXPECT_EQ(1, ui_resource_->resource_create_count); | 1364 EXPECT_EQ(1, ui_resource_->resource_create_count); |
1365 // No "resource lost" callbacks. | 1365 // No "resource lost" callbacks. |
1366 EXPECT_EQ(0, ui_resource_->lost_resource_count); | 1366 EXPECT_EQ(0, ui_resource_->lost_resource_count); |
1367 // The UI resource id should not be valid | 1367 // The UI resource id should not be valid |
1368 EXPECT_EQ(0u, impl->ResourceIdForUIResource(test_id0_)); | 1368 EXPECT_EQ(0u, impl->ResourceIdForUIResource(test_id0_)); |
1369 break; | 1369 break; |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1461 SINGLE_AND_MULTI_THREAD_TEST_F(UIResourceLostBeforeActivateTree); | 1461 SINGLE_AND_MULTI_THREAD_TEST_F(UIResourceLostBeforeActivateTree); |
1462 | 1462 |
1463 // Resources evicted explicitly and by visibility changes. | 1463 // Resources evicted explicitly and by visibility changes. |
1464 class UIResourceLostEviction : public UIResourceLostTestSimple { | 1464 class UIResourceLostEviction : public UIResourceLostTestSimple { |
1465 public: | 1465 public: |
1466 void StepCompleteOnMainThread(int step) override { | 1466 void StepCompleteOnMainThread(int step) override { |
1467 EXPECT_TRUE(layer_tree_host()->task_runner_provider()->IsMainThread()); | 1467 EXPECT_TRUE(layer_tree_host()->task_runner_provider()->IsMainThread()); |
1468 switch (step) { | 1468 switch (step) { |
1469 case 0: | 1469 case 0: |
1470 ui_resource_ = FakeScopedUIResource::Create(layer_tree_host()); | 1470 ui_resource_ = FakeScopedUIResource::Create(layer_tree_host()); |
| 1471 ui_resource2_ = FakeScopedUIResource::Create(layer_tree_host()); |
1471 EXPECT_NE(0, ui_resource_->id()); | 1472 EXPECT_NE(0, ui_resource_->id()); |
| 1473 EXPECT_NE(0, ui_resource2_->id()); |
1472 PostSetNeedsCommitToMainThread(); | 1474 PostSetNeedsCommitToMainThread(); |
1473 break; | 1475 break; |
1474 case 2: | 1476 case 2: |
1475 // Make the tree not visible. | 1477 // Make the tree not visible. |
1476 PostSetVisibleToMainThread(false); | 1478 PostSetVisibleToMainThread(false); |
| 1479 ui_resource2_->DeleteResource(); |
| 1480 ui_resource3_ = FakeScopedUIResource::Create(layer_tree_host()); |
1477 break; | 1481 break; |
1478 case 3: | 1482 case 3: |
1479 // Release resource before ending the test. | 1483 // Release resources before ending the test. |
1480 ui_resource_ = nullptr; | 1484 ui_resource_ = nullptr; |
| 1485 ui_resource2_ = nullptr; |
| 1486 ui_resource3_ = nullptr; |
1481 EndTest(); | 1487 EndTest(); |
1482 break; | 1488 break; |
1483 case 4: | 1489 case 4: |
1484 NOTREACHED(); | 1490 NOTREACHED(); |
1485 } | 1491 } |
1486 } | 1492 } |
1487 | 1493 |
1488 void DidSetVisibleOnImplTree(LayerTreeHostImpl* impl, bool visible) override { | 1494 void DidSetVisibleOnImplTree(LayerTreeHostImpl* impl, bool visible) override { |
1489 if (!visible) { | 1495 if (!visible) { |
1490 // All resources should have been evicted. | 1496 // All resources should have been evicted. |
1491 ASSERT_EQ(0u, context3d_->NumTextures()); | 1497 ASSERT_EQ(0u, context3d_->NumTextures()); |
1492 EXPECT_EQ(0u, impl->ResourceIdForUIResource(ui_resource_->id())); | 1498 EXPECT_EQ(0u, impl->ResourceIdForUIResource(ui_resource_->id())); |
| 1499 EXPECT_EQ(0u, impl->ResourceIdForUIResource(ui_resource2_->id())); |
| 1500 EXPECT_EQ(0u, impl->ResourceIdForUIResource(ui_resource3_->id())); |
1493 EXPECT_EQ(2, ui_resource_->resource_create_count); | 1501 EXPECT_EQ(2, ui_resource_->resource_create_count); |
1494 EXPECT_EQ(1, ui_resource_->lost_resource_count); | 1502 EXPECT_EQ(1, ui_resource_->lost_resource_count); |
1495 // Drawing is disabled both because of the evicted resources and | 1503 // Drawing is disabled both because of the evicted resources and |
1496 // because the renderer is not visible. | 1504 // because the renderer is not visible. |
1497 EXPECT_FALSE(impl->CanDraw()); | 1505 EXPECT_FALSE(impl->CanDraw()); |
1498 // Make the renderer visible again. | 1506 // Make the renderer visible again. |
1499 PostSetVisibleToMainThread(true); | 1507 PostSetVisibleToMainThread(true); |
1500 } | 1508 } |
1501 } | 1509 } |
1502 | 1510 |
1503 void StepCompleteOnImplThread(LayerTreeHostImpl* impl) override { | 1511 void StepCompleteOnImplThread(LayerTreeHostImpl* impl) override { |
1504 LayerTreeHostContextTest::CommitCompleteOnThread(impl); | 1512 LayerTreeHostContextTest::CommitCompleteOnThread(impl); |
1505 switch (time_step_) { | 1513 switch (time_step_) { |
1506 case 1: | 1514 case 1: |
1507 // The resource should have been created on LTHI after the commit. | 1515 // The first two resources should have been created on LTHI after the |
1508 ASSERT_EQ(1u, context3d_->NumTextures()); | 1516 // commit. |
| 1517 ASSERT_EQ(2u, context3d_->NumTextures()); |
1509 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id())); | 1518 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id())); |
| 1519 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource2_->id())); |
1510 EXPECT_EQ(1, ui_resource_->resource_create_count); | 1520 EXPECT_EQ(1, ui_resource_->resource_create_count); |
1511 EXPECT_EQ(0, ui_resource_->lost_resource_count); | 1521 EXPECT_EQ(0, ui_resource_->lost_resource_count); |
1512 EXPECT_TRUE(impl->CanDraw()); | 1522 EXPECT_TRUE(impl->CanDraw()); |
1513 // Evict all UI resources. This will trigger a commit. | 1523 // Evict all UI resources. This will trigger a commit. |
1514 impl->EvictAllUIResources(); | 1524 impl->EvictAllUIResources(); |
1515 ASSERT_EQ(0u, context3d_->NumTextures()); | 1525 ASSERT_EQ(0u, context3d_->NumTextures()); |
1516 EXPECT_EQ(0u, impl->ResourceIdForUIResource(ui_resource_->id())); | 1526 EXPECT_EQ(0u, impl->ResourceIdForUIResource(ui_resource_->id())); |
| 1527 EXPECT_EQ(0u, impl->ResourceIdForUIResource(ui_resource2_->id())); |
1517 EXPECT_EQ(1, ui_resource_->resource_create_count); | 1528 EXPECT_EQ(1, ui_resource_->resource_create_count); |
1518 EXPECT_EQ(0, ui_resource_->lost_resource_count); | 1529 EXPECT_EQ(0, ui_resource_->lost_resource_count); |
1519 EXPECT_FALSE(impl->CanDraw()); | 1530 EXPECT_FALSE(impl->CanDraw()); |
1520 break; | 1531 break; |
1521 case 2: | 1532 case 2: |
1522 // The resource should have been recreated. | 1533 // The first two resources should have been recreated. |
1523 ASSERT_EQ(1u, context3d_->NumTextures()); | 1534 ASSERT_EQ(2u, context3d_->NumTextures()); |
1524 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id())); | 1535 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id())); |
1525 EXPECT_EQ(2, ui_resource_->resource_create_count); | 1536 EXPECT_EQ(2, ui_resource_->resource_create_count); |
1526 EXPECT_EQ(1, ui_resource_->lost_resource_count); | 1537 EXPECT_EQ(1, ui_resource_->lost_resource_count); |
| 1538 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource2_->id())); |
| 1539 EXPECT_EQ(2, ui_resource2_->resource_create_count); |
| 1540 EXPECT_EQ(1, ui_resource2_->lost_resource_count); |
1527 EXPECT_TRUE(impl->CanDraw()); | 1541 EXPECT_TRUE(impl->CanDraw()); |
1528 break; | 1542 break; |
1529 case 3: | 1543 case 3: |
1530 // The resource should have been recreated after visibility was | 1544 // The first resource should have been recreated after visibility was |
1531 // restored. | 1545 // restored. |
1532 ASSERT_EQ(1u, context3d_->NumTextures()); | 1546 ASSERT_EQ(2u, context3d_->NumTextures()); |
1533 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id())); | 1547 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id())); |
1534 EXPECT_EQ(3, ui_resource_->resource_create_count); | 1548 EXPECT_EQ(3, ui_resource_->resource_create_count); |
1535 EXPECT_EQ(2, ui_resource_->lost_resource_count); | 1549 EXPECT_EQ(2, ui_resource_->lost_resource_count); |
| 1550 |
| 1551 // This resource was deleted. |
| 1552 EXPECT_EQ(0u, impl->ResourceIdForUIResource(ui_resource2_->id())); |
| 1553 EXPECT_EQ(2, ui_resource2_->resource_create_count); |
| 1554 EXPECT_EQ(1, ui_resource2_->lost_resource_count); |
| 1555 |
| 1556 // This resource should have been created now. |
| 1557 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource3_->id())); |
| 1558 EXPECT_EQ(1, ui_resource3_->resource_create_count); |
| 1559 EXPECT_EQ(0, ui_resource3_->lost_resource_count); |
1536 EXPECT_TRUE(impl->CanDraw()); | 1560 EXPECT_TRUE(impl->CanDraw()); |
1537 break; | 1561 break; |
1538 } | 1562 } |
1539 } | 1563 } |
| 1564 |
| 1565 private: |
| 1566 std::unique_ptr<FakeScopedUIResource> ui_resource2_; |
| 1567 std::unique_ptr<FakeScopedUIResource> ui_resource3_; |
1540 }; | 1568 }; |
1541 | 1569 |
1542 SINGLE_AND_MULTI_THREAD_TEST_F(UIResourceLostEviction); | 1570 SINGLE_AND_MULTI_THREAD_TEST_F(UIResourceLostEviction); |
1543 | 1571 |
1544 class LayerTreeHostContextTestLoseAfterSendingBeginMainFrame | 1572 class LayerTreeHostContextTestLoseAfterSendingBeginMainFrame |
1545 : public LayerTreeHostContextTest { | 1573 : public LayerTreeHostContextTest { |
1546 protected: | 1574 protected: |
1547 void BeginTest() override { | 1575 void BeginTest() override { |
1548 deferred_ = false; | 1576 deferred_ = false; |
1549 PostSetNeedsCommitToMainThread(); | 1577 PostSetNeedsCommitToMainThread(); |
(...skipping 29 matching lines...) Expand all Loading... |
1579 void AfterTest() override {} | 1607 void AfterTest() override {} |
1580 | 1608 |
1581 bool deferred_; | 1609 bool deferred_; |
1582 }; | 1610 }; |
1583 | 1611 |
1584 SINGLE_AND_MULTI_THREAD_TEST_F( | 1612 SINGLE_AND_MULTI_THREAD_TEST_F( |
1585 LayerTreeHostContextTestLoseAfterSendingBeginMainFrame); | 1613 LayerTreeHostContextTestLoseAfterSendingBeginMainFrame); |
1586 | 1614 |
1587 } // namespace | 1615 } // namespace |
1588 } // namespace cc | 1616 } // namespace cc |
OLD | NEW |