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

Side by Side Diff: cc/tiles/tile_manager_unittest.cc

Issue 2654643004: cc: Fix missing ready to activate/draw callbacks. (Closed)
Patch Set: Created 3 years, 11 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/tiles/tile_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/threading/thread_task_runner_handle.h" 10 #include "base/threading/thread_task_runner_handle.h"
(...skipping 1462 matching lines...) Expand 10 before | Expand all | Expand 10 after
1473 // MockLayerTreeHostImpl allows us to intercept tile manager callbacks. 1473 // MockLayerTreeHostImpl allows us to intercept tile manager callbacks.
1474 class MockLayerTreeHostImpl : public FakeLayerTreeHostImpl { 1474 class MockLayerTreeHostImpl : public FakeLayerTreeHostImpl {
1475 public: 1475 public:
1476 MockLayerTreeHostImpl(const LayerTreeSettings& settings, 1476 MockLayerTreeHostImpl(const LayerTreeSettings& settings,
1477 TaskRunnerProvider* task_runner_provider, 1477 TaskRunnerProvider* task_runner_provider,
1478 TaskGraphRunner* task_graph_runner) 1478 TaskGraphRunner* task_graph_runner)
1479 : FakeLayerTreeHostImpl(settings, 1479 : FakeLayerTreeHostImpl(settings,
1480 task_runner_provider, 1480 task_runner_provider,
1481 task_graph_runner) {} 1481 task_graph_runner) {}
1482 1482
1483 MOCK_METHOD0(NotifyReadyToActivate, void());
1484 MOCK_METHOD0(NotifyReadyToDraw, void());
1483 MOCK_METHOD0(NotifyAllTileTasksCompleted, void()); 1485 MOCK_METHOD0(NotifyAllTileTasksCompleted, void());
1484 MOCK_METHOD0(NotifyReadyToDraw, void());
1485 }; 1486 };
1486 1487
1487 std::unique_ptr<FakeLayerTreeHostImpl> CreateHostImpl( 1488 std::unique_ptr<FakeLayerTreeHostImpl> CreateHostImpl(
1488 const LayerTreeSettings& settings, 1489 const LayerTreeSettings& settings,
1489 TaskRunnerProvider* task_runner_provider, 1490 TaskRunnerProvider* task_runner_provider,
1490 TaskGraphRunner* task_graph_runner) override { 1491 TaskGraphRunner* task_graph_runner) override {
1491 return base::MakeUnique<MockLayerTreeHostImpl>( 1492 return base::MakeUnique<MockLayerTreeHostImpl>(
1492 settings, task_runner_provider, task_graph_runner); 1493 settings, task_runner_provider, task_graph_runner);
1493 } 1494 }
1494 1495
1495 // By default use software compositing (no context provider). 1496 // By default use software compositing (no context provider).
1496 std::unique_ptr<CompositorFrameSink> CreateCompositorFrameSink() override { 1497 std::unique_ptr<CompositorFrameSink> CreateCompositorFrameSink() override {
1497 return FakeCompositorFrameSink::CreateSoftware(); 1498 return FakeCompositorFrameSink::CreateSoftware();
1498 } 1499 }
1499 1500
1500 MockLayerTreeHostImpl& MockHostImpl() { 1501 MockLayerTreeHostImpl& MockHostImpl() {
1501 return *static_cast<MockLayerTreeHostImpl*>(host_impl()); 1502 return *static_cast<MockLayerTreeHostImpl*>(host_impl());
1502 } 1503 }
1503 }; 1504 };
1504 1505
1505 // Test to ensure that we call NotifyAllTileTasksCompleted when PrepareTiles is 1506 // Test to ensure that we call NotifyAllTileTasksCompleted when PrepareTiles is
1506 // called. 1507 // called.
1507 TEST_F(TileManagerTest, AllWorkFinishedTest) { 1508 TEST_F(TileManagerTest, AllWorkFinished) {
1508 // Check with no tile work enqueued. 1509 // Check with no tile work enqueued.
1509 { 1510 {
1510 base::RunLoop run_loop; 1511 base::RunLoop run_loop;
1511 EXPECT_FALSE( 1512 EXPECT_FALSE(
1512 host_impl()->tile_manager()->HasScheduledTileTasksForTesting()); 1513 host_impl()->tile_manager()->HasScheduledTileTasksForTesting());
1514 EXPECT_CALL(MockHostImpl(), NotifyReadyToActivate());
1515 EXPECT_CALL(MockHostImpl(), NotifyReadyToDraw());
1513 EXPECT_CALL(MockHostImpl(), NotifyAllTileTasksCompleted()) 1516 EXPECT_CALL(MockHostImpl(), NotifyAllTileTasksCompleted())
1514 .WillOnce(testing::Invoke([&run_loop]() { run_loop.Quit(); })); 1517 .WillOnce(testing::Invoke([&run_loop]() { run_loop.Quit(); }));
1515 host_impl()->tile_manager()->PrepareTiles(host_impl()->global_tile_state()); 1518 host_impl()->tile_manager()->PrepareTiles(host_impl()->global_tile_state());
1516 EXPECT_TRUE(host_impl()->tile_manager()->HasScheduledTileTasksForTesting()); 1519 EXPECT_TRUE(host_impl()->tile_manager()->HasScheduledTileTasksForTesting());
1517 run_loop.Run(); 1520 run_loop.Run();
1518 } 1521 }
1519 1522
1520 // Check that the "schedule more work" path also triggers the expected 1523 // Check that the "schedule more work" path also triggers the expected
1521 // callback. 1524 // callback.
1522 { 1525 {
1523 base::RunLoop run_loop; 1526 base::RunLoop run_loop;
1524 EXPECT_FALSE( 1527 EXPECT_FALSE(
1525 host_impl()->tile_manager()->HasScheduledTileTasksForTesting()); 1528 host_impl()->tile_manager()->HasScheduledTileTasksForTesting());
1529 EXPECT_CALL(MockHostImpl(), NotifyReadyToActivate());
1530 EXPECT_CALL(MockHostImpl(), NotifyReadyToDraw());
1526 EXPECT_CALL(MockHostImpl(), NotifyAllTileTasksCompleted()) 1531 EXPECT_CALL(MockHostImpl(), NotifyAllTileTasksCompleted())
1527 .WillOnce(testing::Invoke([&run_loop]() { run_loop.Quit(); })); 1532 .WillOnce(testing::Invoke([&run_loop]() { run_loop.Quit(); }));
1528 host_impl()->tile_manager()->PrepareTiles(host_impl()->global_tile_state()); 1533 host_impl()->tile_manager()->PrepareTiles(host_impl()->global_tile_state());
1529 host_impl()->tile_manager()->SetMoreTilesNeedToBeRasterizedForTesting(); 1534 host_impl()->tile_manager()->SetMoreTilesNeedToBeRasterizedForTesting();
1530 EXPECT_TRUE(host_impl()->tile_manager()->HasScheduledTileTasksForTesting()); 1535 EXPECT_TRUE(host_impl()->tile_manager()->HasScheduledTileTasksForTesting());
1531 run_loop.Run(); 1536 run_loop.Run();
1532 } 1537 }
1538
1539 // Check that if callbacks are called by CheckIfMoreTilesNeedToBePrepared if
1540 // they haven't been called already.
1541 {
1542 base::RunLoop run_loop;
1543 EXPECT_FALSE(
1544 host_impl()->tile_manager()->HasScheduledTileTasksForTesting());
1545 EXPECT_CALL(MockHostImpl(), NotifyReadyToActivate());
1546 EXPECT_CALL(MockHostImpl(), NotifyReadyToDraw());
1547 EXPECT_CALL(MockHostImpl(), NotifyAllTileTasksCompleted())
1548 .WillOnce(testing::Invoke([&run_loop]() { run_loop.Quit(); }));
1549 host_impl()->tile_manager()->ResetSignalsForTesting();
1550 host_impl()->tile_manager()->SetMoreTilesNeedToBeRasterizedForTesting();
1551 host_impl()->tile_manager()->CheckIfMoreTilesNeedToBePreparedForTesting();
1552 run_loop.Run();
1553 }
1533 } 1554 }
1534 1555
1535 TEST_F(TileManagerTest, ActivateAndDrawWhenOOM) { 1556 TEST_F(TileManagerTest, ActivateAndDrawWhenOOM) {
1536 SetupDefaultTrees(gfx::Size(1000, 1000)); 1557 SetupDefaultTrees(gfx::Size(1000, 1000));
1537 1558
1538 auto global_state = host_impl()->global_tile_state(); 1559 auto global_state = host_impl()->global_tile_state();
1539 global_state.hard_memory_limit_in_bytes = 1u; 1560 global_state.hard_memory_limit_in_bytes = 1u;
1540 global_state.soft_memory_limit_in_bytes = 1u; 1561 global_state.soft_memory_limit_in_bytes = 1u;
1541 1562
1542 { 1563 {
1543 base::RunLoop run_loop; 1564 base::RunLoop run_loop;
1544 EXPECT_FALSE( 1565 EXPECT_FALSE(
1545 host_impl()->tile_manager()->HasScheduledTileTasksForTesting()); 1566 host_impl()->tile_manager()->HasScheduledTileTasksForTesting());
1567 EXPECT_CALL(MockHostImpl(), NotifyReadyToActivate());
1568 EXPECT_CALL(MockHostImpl(), NotifyReadyToDraw());
1546 EXPECT_CALL(MockHostImpl(), NotifyAllTileTasksCompleted()) 1569 EXPECT_CALL(MockHostImpl(), NotifyAllTileTasksCompleted())
1547 .WillOnce(testing::Invoke([&run_loop]() { run_loop.Quit(); })); 1570 .WillOnce(testing::Invoke([&run_loop]() { run_loop.Quit(); }));
1548 host_impl()->tile_manager()->PrepareTiles(global_state); 1571 host_impl()->tile_manager()->PrepareTiles(global_state);
1549 EXPECT_TRUE(host_impl()->tile_manager()->HasScheduledTileTasksForTesting()); 1572 EXPECT_TRUE(host_impl()->tile_manager()->HasScheduledTileTasksForTesting());
1550 run_loop.Run(); 1573 run_loop.Run();
1551 } 1574 }
1552 1575
1553 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToDraw()); 1576 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToDraw());
1554 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToActivate()); 1577 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToActivate());
1555 EXPECT_TRUE(host_impl()->notify_tile_state_changed_called()); 1578 EXPECT_TRUE(host_impl()->notify_tile_state_changed_called());
1556 1579
1557 // Next PrepareTiles should skip NotifyTileStateChanged since all tiles 1580 // Next PrepareTiles should skip NotifyTileStateChanged since all tiles
1558 // are marked oom already. 1581 // are marked oom already.
1559 { 1582 {
1560 base::RunLoop run_loop; 1583 base::RunLoop run_loop;
1561 host_impl()->set_notify_tile_state_changed_called(false); 1584 host_impl()->set_notify_tile_state_changed_called(false);
1585 EXPECT_CALL(MockHostImpl(), NotifyReadyToActivate());
1586 EXPECT_CALL(MockHostImpl(), NotifyReadyToDraw());
1562 EXPECT_CALL(MockHostImpl(), NotifyAllTileTasksCompleted()) 1587 EXPECT_CALL(MockHostImpl(), NotifyAllTileTasksCompleted())
1563 .WillOnce(testing::Invoke([&run_loop]() { run_loop.Quit(); })); 1588 .WillOnce(testing::Invoke([&run_loop]() { run_loop.Quit(); }));
1564 host_impl()->tile_manager()->PrepareTiles(global_state); 1589 host_impl()->tile_manager()->PrepareTiles(global_state);
1565 run_loop.Run(); 1590 run_loop.Run();
1566 EXPECT_FALSE(host_impl()->notify_tile_state_changed_called()); 1591 EXPECT_FALSE(host_impl()->notify_tile_state_changed_called());
1567 } 1592 }
1568 } 1593 }
1569 1594
1570 TEST_F(TileManagerTest, LowResHasNoImage) { 1595 TEST_F(TileManagerTest, LowResHasNoImage) {
1571 gfx::Size size(10, 12); 1596 gfx::Size size(10, 12);
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
1879 } 1904 }
1880 1905
1881 // Ensures that the tile manager does not attempt to reuse tiles when partial 1906 // Ensures that the tile manager does not attempt to reuse tiles when partial
1882 // raster is disabled. 1907 // raster is disabled.
1883 TEST_F(TileManagerTest, PartialRasterSuccessfullyDisabled) { 1908 TEST_F(TileManagerTest, PartialRasterSuccessfullyDisabled) {
1884 RunPartialRasterCheck(TakeHostImpl(), false /* partial_raster_enabled */); 1909 RunPartialRasterCheck(TakeHostImpl(), false /* partial_raster_enabled */);
1885 } 1910 }
1886 1911
1887 } // namespace 1912 } // namespace
1888 } // namespace cc 1913 } // namespace cc
OLDNEW
« no previous file with comments | « cc/tiles/tile_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698