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

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

Issue 23503003: cc: Add readback and forced draw states to the Scheduler (Closed) Base URL: http://git.chromium.org/chromium/src.git@schedReorg3
Patch Set: Address enne's commetns Created 7 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
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 "cc/trees/layer_tree_host.h" 5 #include "cc/trees/layer_tree_host.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "cc/debug/test_context_provider.h" 8 #include "cc/debug/test_context_provider.h"
9 #include "cc/debug/test_web_graphics_context_3d.h" 9 #include "cc/debug/test_web_graphics_context_3d.h"
10 #include "cc/layers/content_layer.h" 10 #include "cc/layers/content_layer.h"
(...skipping 1443 matching lines...) Expand 10 before | Expand all | Expand 10 after
1454 virtual void DidCommitAndDrawFrame() OVERRIDE { 1454 virtual void DidCommitAndDrawFrame() OVERRIDE {
1455 EndTest(); 1455 EndTest();
1456 } 1456 }
1457 1457
1458 virtual void AfterTest() OVERRIDE { 1458 virtual void AfterTest() OVERRIDE {
1459 // Should not try to create output surface again after successfully 1459 // Should not try to create output surface again after successfully
1460 // created by CompositeAndReadback. 1460 // created by CompositeAndReadback.
1461 EXPECT_EQ(1, times_output_surface_created_); 1461 EXPECT_EQ(1, times_output_surface_created_);
1462 } 1462 }
1463 1463
1464 virtual bool PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
1465 LayerTreeHostImpl::FrameData* frame_data,
1466 bool result) OVERRIDE {
1467 EXPECT_GE(host_impl->active_tree()->source_frame_number(), 0);
1468 EXPECT_LE(host_impl->active_tree()->source_frame_number(), 1);
1469 return true;
1470 }
1471
1472 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
1473 // We should only draw for the readback and the replacement commit.
1474 // The replacement commit will also be the first commit after output
1475 // surface initialization.
1476 EXPECT_GE(host_impl->active_tree()->source_frame_number(), 0);
1477 EXPECT_LE(host_impl->active_tree()->source_frame_number(), 1);
1478 }
1479
1480 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl,
1481 bool result) OVERRIDE {
1482 // We should only swap for the replacement commit.
1483 EXPECT_EQ(host_impl->active_tree()->source_frame_number(), 1);
1484 EndTest();
1485 }
1486
1464 private: 1487 private:
1465 int times_output_surface_created_; 1488 int times_output_surface_created_;
1466 }; 1489 };
1467 1490
1468 SINGLE_AND_MULTI_THREAD_TEST_F( 1491 SINGLE_AND_MULTI_THREAD_TEST_F(
1469 LayerTreeHostContextTestCompositeAndReadbackBeforeOutputSurfaceInit); 1492 LayerTreeHostContextTestCompositeAndReadbackBeforeOutputSurfaceInit);
1470 1493
1494 // This test verifies that losing an output surface right during a
1495 // simultaneous readback and forced redraw works and does not deadlock.
1496 class LayerTreeHostContextTestLoseOutputSurfaceDuringReadbackAndForcedDraw
1497 : public LayerTreeHostContextTest {
1498 protected:
1499 static const int kCommitAfterFirstOutputSurfaceInitSourceFrameNumber = 0;
1500 static const int kReadbackCommitSourceFrameNumber = 1;
1501 static const int kReadbackReplacementCommitSourceFrameNumber = 2;
1502 static const int kCommitAfterSecondOutputSurfaceInitSourceFrameNumber = 3;
1503
1504 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE {
1505 // This enables forced draws after a single prepare to draw failure.
1506 settings->timeout_and_draw_when_animation_checkerboards = true;
1507 settings->maximum_number_of_failed_draws_before_draw_is_forced_ = 1;
1508 }
1509
1510 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
1511
1512 virtual bool PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
1513 LayerTreeHostImpl::FrameData* frame_data,
1514 bool result) OVERRIDE {
1515 EXPECT_TRUE(host_impl->active_tree()->source_frame_number() ==
1516 kCommitAfterFirstOutputSurfaceInitSourceFrameNumber ||
1517 host_impl->active_tree()->source_frame_number() ==
1518 kCommitAfterSecondOutputSurfaceInitSourceFrameNumber ||
1519 host_impl->active_tree()->source_frame_number() ==
1520 kReadbackCommitSourceFrameNumber);
1521
1522 // Before we react to the failed draw by initiating the forced draw
1523 // sequence, start a readback on the main thread and then lose the context
1524 // to start output surface initialization all at the same time.
1525 if (host_impl->active_tree()->source_frame_number() ==
1526 kCommitAfterFirstOutputSurfaceInitSourceFrameNumber) {
1527 PostReadbackToMainThread();
1528 LoseContext();
1529 }
1530
1531 // Returning false will eventually result in a forced draw.
1532 return false;
1533 }
1534
1535 virtual void InitializedRendererOnThread(LayerTreeHostImpl* host_impl,
1536 bool success) OVERRIDE {
1537 // -1 is for the first output surface initialization.
1538 EXPECT_TRUE(host_impl->active_tree()->source_frame_number() == -1 ||
1539 host_impl->active_tree()->source_frame_number() ==
1540 kReadbackReplacementCommitSourceFrameNumber);
1541 }
1542
1543 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
1544 // We should only draw the first commit after output surface initialization
1545 // and attempt to draw the readback commit (which will fail).
1546 // All others should abort because the output surface is lost.
1547 EXPECT_TRUE(host_impl->active_tree()->source_frame_number() ==
1548 kCommitAfterSecondOutputSurfaceInitSourceFrameNumber ||
1549 host_impl->active_tree()->source_frame_number() ==
1550 kReadbackCommitSourceFrameNumber);
1551 }
1552
1553 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl,
1554 bool result) OVERRIDE {
1555 // We should only swap the first commit after the second output surface
1556 // initialization.
1557 EXPECT_TRUE(host_impl->active_tree()->source_frame_number() ==
1558 kCommitAfterSecondOutputSurfaceInitSourceFrameNumber);
1559 EndTest();
1560 }
1561
1562 virtual void AfterTest() OVERRIDE {}
1563 };
1564
1565 MULTI_THREAD_TEST_F(
1566 LayerTreeHostContextTestLoseOutputSurfaceDuringReadbackAndForcedDraw);
1567
1568 // This test verifies that losing an output surface right before a
1569 // simultaneous readback and forced redraw works and does not deadlock.
1570 class LayerTreeHostContextTestReadbackWithForcedDrawAndOutputSurfaceInit
1571 : public LayerTreeHostContextTest {
1572 protected:
1573 static const int kCommitAfterFirstOutputSurfaceInitSourceFrameNumber = 0;
1574 static const int kReadbackCommitSourceFrameNumber = 1;
1575 static const int kReadbackReplacementCommitSourceFrameNumber = 2;
1576 static const int kForcedDrawCommitSourceFrameNumber = 2;
1577 static const int kCommitAfterSecondOutputSurfaceInitSourceFrameNumber = 2;
1578
1579 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE {
1580 // This enables forced draws after a single prepare to draw failure.
1581 settings->timeout_and_draw_when_animation_checkerboards = true;
1582 settings->maximum_number_of_failed_draws_before_draw_is_forced_ = 1;
1583 }
1584
1585 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
1586
1587 virtual bool PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
1588 LayerTreeHostImpl::FrameData* frame_data,
1589 bool result) OVERRIDE {
1590 EXPECT_TRUE(host_impl->active_tree()->source_frame_number() ==
1591 kCommitAfterFirstOutputSurfaceInitSourceFrameNumber ||
1592 host_impl->active_tree()->source_frame_number() ==
1593 kCommitAfterSecondOutputSurfaceInitSourceFrameNumber ||
1594 host_impl->active_tree()->source_frame_number() ==
1595 kReadbackCommitSourceFrameNumber);
1596
1597 // Before we react to the failed draw by initiating the forced draw
1598 // sequence, start a readback on the main thread and then lose the context
1599 // to start output surface initialization all at the same time.
1600 if (host_impl->active_tree()->source_frame_number() ==
1601 kCommitAfterFirstOutputSurfaceInitSourceFrameNumber) {
1602 LoseContext();
1603 }
1604
1605 // Returning false will eventually result in a forced draw.
1606 return false;
1607 }
1608
1609 virtual void DidInitializeOutputSurface(bool succeeded) OVERRIDE {
1610 EXPECT_TRUE(succeeded);
1611 if (layer_tree_host()->source_frame_number() > 0) {
1612 // Perform a readback right after the second output surface
1613 // initialization.
1614 char pixels[4];
1615 layer_tree_host()->CompositeAndReadback(&pixels, gfx::Rect(0, 0, 1, 1));
1616 }
1617 }
1618
1619 virtual void InitializedRendererOnThread(LayerTreeHostImpl* host_impl,
1620 bool success) OVERRIDE {
1621 // -1 is for the first output surface initialization.
1622 EXPECT_TRUE(host_impl->active_tree()->source_frame_number() == -1 ||
1623 host_impl->active_tree()->source_frame_number() ==
1624 kCommitAfterFirstOutputSurfaceInitSourceFrameNumber);
1625 }
1626
1627 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
1628 // We should only draw the first commit after output surface initialization
1629 // and attempt to draw the readback commit (which will fail).
1630 // All others should abort because the output surface is lost.
1631 EXPECT_TRUE(host_impl->active_tree()->source_frame_number() ==
1632 kForcedDrawCommitSourceFrameNumber ||
1633 host_impl->active_tree()->source_frame_number() ==
1634 kReadbackCommitSourceFrameNumber);
1635 }
1636
1637 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl,
1638 bool result) OVERRIDE {
1639 // We should only swap the first commit after the second output surface
1640 // initialization.
1641 EXPECT_TRUE(host_impl->active_tree()->source_frame_number() ==
1642 kForcedDrawCommitSourceFrameNumber);
1643 EndTest();
1644 }
1645
1646 virtual void AfterTest() OVERRIDE {}
1647 };
1648
1649 MULTI_THREAD_TEST_F(
1650 LayerTreeHostContextTestReadbackWithForcedDrawAndOutputSurfaceInit);
1651
1471 class ImplSidePaintingLayerTreeHostContextTest 1652 class ImplSidePaintingLayerTreeHostContextTest
1472 : public LayerTreeHostContextTest { 1653 : public LayerTreeHostContextTest {
1473 public: 1654 public:
1474 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { 1655 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE {
1475 settings->impl_side_painting = true; 1656 settings->impl_side_painting = true;
1476 } 1657 }
1477 }; 1658 };
1478 1659
1479 class LayerTreeHostContextTestImplSidePainting 1660 class LayerTreeHostContextTestImplSidePainting
1480 : public ImplSidePaintingLayerTreeHostContextTest { 1661 : public ImplSidePaintingLayerTreeHostContextTest {
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
1900 RunTest(true, false, true); 2081 RunTest(true, false, true);
1901 } 2082 }
1902 2083
1903 TEST_F(UIResourceLostBeforeActivateTree, 2084 TEST_F(UIResourceLostBeforeActivateTree,
1904 RunMultiThread_DelegatingRenderer_ImplSidePaint) { 2085 RunMultiThread_DelegatingRenderer_ImplSidePaint) {
1905 RunTest(true, true, true); 2086 RunTest(true, true, true);
1906 } 2087 }
1907 2088
1908 } // namespace 2089 } // namespace
1909 } // namespace cc 2090 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698