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 "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/layers/content_layer.h" | 8 #include "cc/layers/content_layer.h" |
9 #include "cc/layers/delegated_frame_provider.h" | 9 #include "cc/layers/delegated_frame_provider.h" |
10 #include "cc/layers/delegated_frame_resource_collection.h" | 10 #include "cc/layers/delegated_frame_resource_collection.h" |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
402 | 402 |
403 protected: | 403 protected: |
404 size_t test_case_; | 404 size_t test_case_; |
405 int num_losses_; | 405 int num_losses_; |
406 bool recovered_context_; | 406 bool recovered_context_; |
407 bool first_initialized_; | 407 bool first_initialized_; |
408 }; | 408 }; |
409 | 409 |
410 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestLostContextSucceeds); | 410 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestLostContextSucceeds); |
411 | 411 |
412 class LayerTreeHostClientNotReadyDoesNotCreateOutputSurface | |
413 : public LayerTreeHostContextTest { | |
414 public: | |
415 LayerTreeHostClientNotReadyDoesNotCreateOutputSurface() | |
416 : LayerTreeHostContextTest() {} | |
417 | |
418 virtual void WillBeginTest() OVERRIDE { | |
419 // Override and do not signal SetLayerTreeHostClientReady. | |
420 } | |
421 | |
422 virtual void BeginTest() OVERRIDE { | |
423 PostSetNeedsCommitToMainThread(); | |
424 EndTest(); | |
425 } | |
426 | |
427 virtual void DidInitializeOutputSurface(bool succeeded) OVERRIDE { | |
428 GTEST_FAIL(); | |
429 } | |
430 | |
431 virtual void AfterTest() OVERRIDE { | |
432 } | |
433 }; | |
434 | |
435 MULTI_THREAD_TEST_F(LayerTreeHostClientNotReadyDoesNotCreateOutputSurface); | |
436 | |
412 class LayerTreeHostContextTestLostContextSucceedsWithContent | 437 class LayerTreeHostContextTestLostContextSucceedsWithContent |
413 : public LayerTreeHostContextTestLostContextSucceeds { | 438 : public LayerTreeHostContextTestLostContextSucceeds { |
414 public: | 439 public: |
415 LayerTreeHostContextTestLostContextSucceedsWithContent() | 440 LayerTreeHostContextTestLostContextSucceedsWithContent() |
416 : LayerTreeHostContextTestLostContextSucceeds() {} | 441 : LayerTreeHostContextTestLostContextSucceeds() {} |
417 | 442 |
418 virtual void SetupTree() OVERRIDE { | 443 virtual void SetupTree() OVERRIDE { |
419 root_ = Layer::Create(); | 444 root_ = Layer::Create(); |
420 root_->SetBounds(gfx::Size(10, 10)); | 445 root_->SetBounds(gfx::Size(10, 10)); |
421 root_->SetAnchorPoint(gfx::PointF()); | 446 root_->SetAnchorPoint(gfx::PointF()); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
520 use_surface_ = true; | 545 use_surface_ = true; |
521 RunTest(false, false, false); | 546 RunTest(false, false, false); |
522 } | 547 } |
523 | 548 |
524 TEST_F(LayerTreeHostContextTestLostContextSucceedsWithContent, | 549 TEST_F(LayerTreeHostContextTestLostContextSucceedsWithContent, |
525 WithSurface_MultiThread_DirectRenderer_MainThreadPaint) { | 550 WithSurface_MultiThread_DirectRenderer_MainThreadPaint) { |
526 use_surface_ = true; | 551 use_surface_ = true; |
527 RunTest(true, false, false); | 552 RunTest(true, false, false); |
528 } | 553 } |
529 | 554 |
555 class LayerTreeHostContextTestCreateOutputSurfaceFails | |
556 : public LayerTreeHostContextTest { | |
557 public: | |
558 // Run a test that initially fails OutputSurface creation |times_to_fail| | |
559 // times. If |expect_fallback_attempt| is |true|, an attempt to create a | |
560 // fallback/software OutputSurface is expected to occur. | |
561 LayerTreeHostContextTestCreateOutputSurfaceFails(int times_to_fail, | |
562 bool expect_fallback_attempt, | |
563 bool expect_to_give_up) | |
564 : times_to_fail_(times_to_fail), | |
565 expect_fallback_attempt_(expect_fallback_attempt), | |
566 expect_to_give_up_(expect_to_give_up), | |
567 did_attempt_fallback_(false), | |
568 times_initialized_(0) {} | |
569 | |
570 virtual void BeginTest() OVERRIDE { | |
571 times_to_fail_create_ = times_to_fail_; | |
572 PostSetNeedsCommitToMainThread(); | |
573 } | |
574 | |
575 virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback) | |
576 OVERRIDE { | |
577 scoped_ptr<OutputSurface> surface = | |
578 LayerTreeHostContextTest::CreateOutputSurface(fallback); | |
579 | |
580 if (surface) | |
581 EXPECT_EQ(times_to_fail_, times_create_failed_); | |
582 | |
583 did_attempt_fallback_ = fallback; | |
584 return surface.Pass(); | |
585 } | |
586 | |
587 virtual void DidInitializeOutputSurface(bool succeeded) OVERRIDE { | |
588 if (succeeded) | |
589 times_initialized_++; | |
590 else | |
591 EndTest(); | |
592 } | |
593 | |
594 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | |
595 EndTest(); | |
596 } | |
597 | |
598 virtual void AfterTest() OVERRIDE { | |
599 EXPECT_EQ(times_to_fail_, times_create_failed_); | |
600 EXPECT_EQ(expect_to_give_up_, times_initialized_ == 0); | |
601 EXPECT_EQ(expect_fallback_attempt_, did_attempt_fallback_); | |
602 } | |
603 | |
604 private: | |
605 int times_to_fail_; | |
606 bool expect_fallback_attempt_; | |
607 bool expect_to_give_up_; | |
608 bool did_attempt_fallback_; | |
609 int times_initialized_; | |
610 }; | |
611 | |
612 class LayerTreeHostContextTestCreateOutputSurfaceFailsOnce | |
613 : public LayerTreeHostContextTestCreateOutputSurfaceFails { | |
614 public: | |
615 LayerTreeHostContextTestCreateOutputSurfaceFailsOnce() | |
616 : LayerTreeHostContextTestCreateOutputSurfaceFails(1, false, false) {} | |
617 }; | |
618 | |
619 SINGLE_AND_MULTI_THREAD_TEST_F( | |
620 LayerTreeHostContextTestCreateOutputSurfaceFailsOnce); | |
621 | |
622 // After 4 failures we expect an attempt to create a fallback/sw OutputSurface | |
danakj
2013/12/02 14:53:02
nit: spell out software. period at end of sentence
| |
623 class LayerTreeHostContextTestCreateOutputSurfaceFailsWithFallback | |
624 : public LayerTreeHostContextTestCreateOutputSurfaceFails { | |
625 public: | |
626 LayerTreeHostContextTestCreateOutputSurfaceFailsWithFallback() | |
627 : LayerTreeHostContextTestCreateOutputSurfaceFails(4, true, false) {} | |
628 }; | |
629 | |
630 SINGLE_AND_MULTI_THREAD_TEST_F( | |
631 LayerTreeHostContextTestCreateOutputSurfaceFailsWithFallback); | |
632 | |
633 // If we fail that often, we should be giving up cleanly. | |
634 class LayerTreeHostContextTestCreateOutputSurfaceIsHopeless | |
635 : public LayerTreeHostContextTestCreateOutputSurfaceFails { | |
636 public: | |
637 LayerTreeHostContextTestCreateOutputSurfaceIsHopeless() | |
638 : LayerTreeHostContextTestCreateOutputSurfaceFails(5, true, true) {} | |
639 }; | |
640 | |
641 SINGLE_AND_MULTI_THREAD_TEST_F( | |
642 LayerTreeHostContextTestCreateOutputSurfaceIsHopeless); | |
643 | |
644 | |
530 class LayerTreeHostContextTestOffscreenContextFails | 645 class LayerTreeHostContextTestOffscreenContextFails |
531 : public LayerTreeHostContextTest { | 646 : public LayerTreeHostContextTest { |
532 public: | 647 public: |
533 virtual void SetupTree() OVERRIDE { | 648 virtual void SetupTree() OVERRIDE { |
534 root_ = Layer::Create(); | 649 root_ = Layer::Create(); |
535 root_->SetBounds(gfx::Size(10, 10)); | 650 root_->SetBounds(gfx::Size(10, 10)); |
536 root_->SetAnchorPoint(gfx::PointF()); | 651 root_->SetAnchorPoint(gfx::PointF()); |
537 root_->SetIsDrawable(true); | 652 root_->SetIsDrawable(true); |
538 | 653 |
539 content_ = FakeContentLayer::Create(&client_); | 654 content_ = FakeContentLayer::Create(&client_); |
(...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1279 if (host_impl->active_tree()->source_frame_number() == 2) { | 1394 if (host_impl->active_tree()->source_frame_number() == 2) { |
1280 // Lose the context during draw on the second commit. This will cause | 1395 // Lose the context during draw on the second commit. This will cause |
1281 // a third commit to recover. | 1396 // a third commit to recover. |
1282 context3d_->set_times_bind_texture_succeeds(0); | 1397 context3d_->set_times_bind_texture_succeeds(0); |
1283 } | 1398 } |
1284 return true; | 1399 return true; |
1285 } | 1400 } |
1286 | 1401 |
1287 virtual scoped_ptr<OutputSurface> CreateOutputSurface( | 1402 virtual scoped_ptr<OutputSurface> CreateOutputSurface( |
1288 bool fallback) OVERRIDE { | 1403 bool fallback) OVERRIDE { |
1289 if (layer_tree_host()) { | 1404 // This will get called twice: |
1405 // First when we create the initial output surface... | |
1406 if (layer_tree_host()->source_frame_number() > 0) { | |
1407 // ... and then again after we forced the context to be lost on the third | |
1408 // frame. Verify this assumption here. | |
1290 lost_context_ = true; | 1409 lost_context_ = true; |
1291 EXPECT_EQ(layer_tree_host()->source_frame_number(), 3); | 1410 EXPECT_EQ(layer_tree_host()->source_frame_number(), 3); |
1292 } | 1411 } |
1293 return LayerTreeHostContextTest::CreateOutputSurface(fallback); | 1412 return LayerTreeHostContextTest::CreateOutputSurface(fallback); |
1294 } | 1413 } |
1295 | 1414 |
1296 virtual void DidCommitAndDrawFrame() OVERRIDE { | 1415 virtual void DidCommitAndDrawFrame() OVERRIDE { |
1297 ASSERT_TRUE(layer_tree_host()->hud_layer()); | 1416 ASSERT_TRUE(layer_tree_host()->hud_layer()); |
1298 // End the test once we know the 3nd frame drew. | 1417 // End the test once we know the 3nd frame drew. |
1299 if (layer_tree_host()->source_frame_number() < 4) { | 1418 if (layer_tree_host()->source_frame_number() < 4) { |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1755 EndTest(); | 1874 EndTest(); |
1756 } | 1875 } |
1757 | 1876 |
1758 private: | 1877 private: |
1759 int failure_count_; | 1878 int failure_count_; |
1760 }; | 1879 }; |
1761 | 1880 |
1762 SINGLE_AND_MULTI_THREAD_TEST_F( | 1881 SINGLE_AND_MULTI_THREAD_TEST_F( |
1763 LayerTreeHostContextTestFailsToCreateSurface); | 1882 LayerTreeHostContextTestFailsToCreateSurface); |
1764 | 1883 |
1765 // Not reusing LayerTreeTest because it expects creating LTH to always succeed. | |
1766 class LayerTreeHostTestCannotCreateIfCannotCreateOutputSurface | |
1767 : public testing::Test, | |
1768 public FakeLayerTreeHostClient { | |
1769 public: | |
1770 LayerTreeHostTestCannotCreateIfCannotCreateOutputSurface() | |
1771 : FakeLayerTreeHostClient(FakeLayerTreeHostClient::DIRECT_3D) {} | |
1772 | |
1773 // FakeLayerTreeHostClient implementation. | |
1774 virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback) | |
1775 OVERRIDE { | |
1776 return scoped_ptr<OutputSurface>(); | |
1777 } | |
1778 | |
1779 void RunTest(bool threaded, | |
1780 bool delegating_renderer, | |
1781 bool impl_side_painting) { | |
1782 LayerTreeSettings settings; | |
1783 settings.impl_side_painting = impl_side_painting; | |
1784 if (threaded) { | |
1785 scoped_ptr<base::Thread> impl_thread(new base::Thread("LayerTreeTest")); | |
1786 ASSERT_TRUE(impl_thread->Start()); | |
1787 ASSERT_TRUE(impl_thread->message_loop_proxy().get()); | |
1788 scoped_ptr<LayerTreeHost> layer_tree_host = LayerTreeHost::CreateThreaded( | |
1789 this, NULL, settings, impl_thread->message_loop_proxy()); | |
1790 EXPECT_FALSE(layer_tree_host); | |
1791 } else { | |
1792 scoped_ptr<LayerTreeHost> layer_tree_host = | |
1793 LayerTreeHost::CreateSingleThreaded(this, this, NULL, settings); | |
1794 EXPECT_FALSE(layer_tree_host); | |
1795 } | |
1796 } | |
1797 }; | |
1798 | |
1799 SINGLE_AND_MULTI_THREAD_TEST_F( | |
1800 LayerTreeHostTestCannotCreateIfCannotCreateOutputSurface); | |
1801 | |
1802 class UIResourceLostTest : public LayerTreeHostContextTest { | 1884 class UIResourceLostTest : public LayerTreeHostContextTest { |
1803 public: | 1885 public: |
1804 UIResourceLostTest() : time_step_(0) {} | 1886 UIResourceLostTest() : time_step_(0) {} |
1805 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { | 1887 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { |
1806 settings->texture_id_allocation_chunk_size = 1; | 1888 settings->texture_id_allocation_chunk_size = 1; |
1807 } | 1889 } |
1808 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } | 1890 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
1809 virtual void AfterTest() OVERRIDE {} | 1891 virtual void AfterTest() OVERRIDE {} |
1810 | 1892 |
1811 // This is called on the main thread after each commit and | 1893 // This is called on the main thread after each commit and |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2290 protected: | 2372 protected: |
2291 FakeContentLayerClient client_; | 2373 FakeContentLayerClient client_; |
2292 scoped_refptr<FakeContentLayer> layer_; | 2374 scoped_refptr<FakeContentLayer> layer_; |
2293 int num_commits_; | 2375 int num_commits_; |
2294 }; | 2376 }; |
2295 | 2377 |
2296 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestSurfaceCreateCallback); | 2378 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestSurfaceCreateCallback); |
2297 | 2379 |
2298 } // namespace | 2380 } // namespace |
2299 } // namespace cc | 2381 } // namespace cc |
OLD | NEW |