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

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

Issue 103163003: Revert 238458 "cc: Defer first OutputSurface creation until clie..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « trunk/src/cc/trees/layer_tree_host_unittest.cc ('k') | trunk/src/cc/trees/proxy.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 "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
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 scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback)
428 OVERRIDE {
429 EXPECT_TRUE(false);
430 return scoped_ptr<OutputSurface>();
431 }
432
433 virtual void DidInitializeOutputSurface(bool succeeded) OVERRIDE {
434 EXPECT_TRUE(false);
435 }
436
437 virtual void AfterTest() OVERRIDE {
438 }
439 };
440
441 MULTI_THREAD_TEST_F(LayerTreeHostClientNotReadyDoesNotCreateOutputSurface);
442
443 class LayerTreeHostContextTestLostContextSucceedsWithContent 412 class LayerTreeHostContextTestLostContextSucceedsWithContent
444 : public LayerTreeHostContextTestLostContextSucceeds { 413 : public LayerTreeHostContextTestLostContextSucceeds {
445 public: 414 public:
446 LayerTreeHostContextTestLostContextSucceedsWithContent() 415 LayerTreeHostContextTestLostContextSucceedsWithContent()
447 : LayerTreeHostContextTestLostContextSucceeds() {} 416 : LayerTreeHostContextTestLostContextSucceeds() {}
448 417
449 virtual void SetupTree() OVERRIDE { 418 virtual void SetupTree() OVERRIDE {
450 root_ = Layer::Create(); 419 root_ = Layer::Create();
451 root_->SetBounds(gfx::Size(10, 10)); 420 root_->SetBounds(gfx::Size(10, 10));
452 root_->SetAnchorPoint(gfx::PointF()); 421 root_->SetAnchorPoint(gfx::PointF());
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 use_surface_ = true; 520 use_surface_ = true;
552 RunTest(false, false, false); 521 RunTest(false, false, false);
553 } 522 }
554 523
555 TEST_F(LayerTreeHostContextTestLostContextSucceedsWithContent, 524 TEST_F(LayerTreeHostContextTestLostContextSucceedsWithContent,
556 WithSurface_MultiThread_DirectRenderer_MainThreadPaint) { 525 WithSurface_MultiThread_DirectRenderer_MainThreadPaint) {
557 use_surface_ = true; 526 use_surface_ = true;
558 RunTest(true, false, false); 527 RunTest(true, false, false);
559 } 528 }
560 529
561 class LayerTreeHostContextTestCreateOutputSurfaceFails
562 : public LayerTreeHostContextTest {
563 public:
564 // Run a test that initially fails OutputSurface creation |times_to_fail|
565 // times. If |expect_fallback_attempt| is |true|, an attempt to create a
566 // fallback/software OutputSurface is expected to occur.
567 LayerTreeHostContextTestCreateOutputSurfaceFails(int times_to_fail,
568 bool expect_fallback_attempt,
569 bool expect_to_give_up)
570 : times_to_fail_(times_to_fail),
571 expect_fallback_attempt_(expect_fallback_attempt),
572 expect_to_give_up_(expect_to_give_up),
573 did_attempt_fallback_(false),
574 times_initialized_(0) {}
575
576 virtual void BeginTest() OVERRIDE {
577 times_to_fail_create_ = times_to_fail_;
578 PostSetNeedsCommitToMainThread();
579 }
580
581 virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback)
582 OVERRIDE {
583 scoped_ptr<OutputSurface> surface =
584 LayerTreeHostContextTest::CreateOutputSurface(fallback);
585
586 if (surface)
587 EXPECT_EQ(times_to_fail_, times_create_failed_);
588
589 did_attempt_fallback_ = fallback;
590 return surface.Pass();
591 }
592
593 virtual void DidInitializeOutputSurface(bool succeeded) OVERRIDE {
594 if (succeeded)
595 times_initialized_++;
596 else
597 EndTest();
598 }
599
600 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
601 EndTest();
602 }
603
604 virtual void AfterTest() OVERRIDE {
605 EXPECT_EQ(times_to_fail_, times_create_failed_);
606 EXPECT_EQ(expect_to_give_up_, times_initialized_ == 0);
607 EXPECT_EQ(expect_fallback_attempt_, did_attempt_fallback_);
608 }
609
610 private:
611 int times_to_fail_;
612 bool expect_fallback_attempt_;
613 bool expect_to_give_up_;
614 bool did_attempt_fallback_;
615 int times_initialized_;
616 };
617
618 class LayerTreeHostContextTestCreateOutputSurfaceFailsOnce
619 : public LayerTreeHostContextTestCreateOutputSurfaceFails {
620 public:
621 LayerTreeHostContextTestCreateOutputSurfaceFailsOnce()
622 : LayerTreeHostContextTestCreateOutputSurfaceFails(1, false, false) {}
623 };
624
625 SINGLE_AND_MULTI_THREAD_TEST_F(
626 LayerTreeHostContextTestCreateOutputSurfaceFailsOnce);
627
628 // After 4 failures we expect an attempt to create a fallback/software
629 // OutputSurface.
630 class LayerTreeHostContextTestCreateOutputSurfaceFailsWithFallback
631 : public LayerTreeHostContextTestCreateOutputSurfaceFails {
632 public:
633 LayerTreeHostContextTestCreateOutputSurfaceFailsWithFallback()
634 : LayerTreeHostContextTestCreateOutputSurfaceFails(4, true, false) {}
635 };
636
637 SINGLE_AND_MULTI_THREAD_TEST_F(
638 LayerTreeHostContextTestCreateOutputSurfaceFailsWithFallback);
639
640 // If we fail that often, we should be giving up cleanly.
641 class LayerTreeHostContextTestCreateOutputSurfaceIsHopeless
642 : public LayerTreeHostContextTestCreateOutputSurfaceFails {
643 public:
644 LayerTreeHostContextTestCreateOutputSurfaceIsHopeless()
645 : LayerTreeHostContextTestCreateOutputSurfaceFails(5, true, true) {}
646 };
647
648 SINGLE_AND_MULTI_THREAD_TEST_F(
649 LayerTreeHostContextTestCreateOutputSurfaceIsHopeless);
650
651
652 class LayerTreeHostContextTestOffscreenContextFails 530 class LayerTreeHostContextTestOffscreenContextFails
653 : public LayerTreeHostContextTest { 531 : public LayerTreeHostContextTest {
654 public: 532 public:
655 virtual void SetupTree() OVERRIDE { 533 virtual void SetupTree() OVERRIDE {
656 root_ = Layer::Create(); 534 root_ = Layer::Create();
657 root_->SetBounds(gfx::Size(10, 10)); 535 root_->SetBounds(gfx::Size(10, 10));
658 root_->SetAnchorPoint(gfx::PointF()); 536 root_->SetAnchorPoint(gfx::PointF());
659 root_->SetIsDrawable(true); 537 root_->SetIsDrawable(true);
660 538
661 content_ = FakeContentLayer::Create(&client_); 539 content_ = FakeContentLayer::Create(&client_);
(...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after
1400 if (host_impl->active_tree()->source_frame_number() == 2) { 1278 if (host_impl->active_tree()->source_frame_number() == 2) {
1401 // Lose the context during draw on the second commit. This will cause 1279 // Lose the context during draw on the second commit. This will cause
1402 // a third commit to recover. 1280 // a third commit to recover.
1403 context3d_->set_times_bind_texture_succeeds(0); 1281 context3d_->set_times_bind_texture_succeeds(0);
1404 } 1282 }
1405 return true; 1283 return true;
1406 } 1284 }
1407 1285
1408 virtual scoped_ptr<OutputSurface> CreateOutputSurface( 1286 virtual scoped_ptr<OutputSurface> CreateOutputSurface(
1409 bool fallback) OVERRIDE { 1287 bool fallback) OVERRIDE {
1410 // This will get called twice: 1288 if (layer_tree_host()) {
1411 // First when we create the initial output surface...
1412 if (layer_tree_host()->source_frame_number() > 0) {
1413 // ... and then again after we forced the context to be lost on the third
1414 // frame. Verify this assumption here.
1415 lost_context_ = true; 1289 lost_context_ = true;
1416 EXPECT_EQ(layer_tree_host()->source_frame_number(), 3); 1290 EXPECT_EQ(layer_tree_host()->source_frame_number(), 3);
1417 } 1291 }
1418 return LayerTreeHostContextTest::CreateOutputSurface(fallback); 1292 return LayerTreeHostContextTest::CreateOutputSurface(fallback);
1419 } 1293 }
1420 1294
1421 virtual void DidCommitAndDrawFrame() OVERRIDE { 1295 virtual void DidCommitAndDrawFrame() OVERRIDE {
1422 ASSERT_TRUE(layer_tree_host()->hud_layer()); 1296 ASSERT_TRUE(layer_tree_host()->hud_layer());
1423 // End the test once we know the 3nd frame drew. 1297 // End the test once we know the 3nd frame drew.
1424 if (layer_tree_host()->source_frame_number() < 4) { 1298 if (layer_tree_host()->source_frame_number() < 4) {
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
1880 EndTest(); 1754 EndTest();
1881 } 1755 }
1882 1756
1883 private: 1757 private:
1884 int failure_count_; 1758 int failure_count_;
1885 }; 1759 };
1886 1760
1887 SINGLE_AND_MULTI_THREAD_TEST_F( 1761 SINGLE_AND_MULTI_THREAD_TEST_F(
1888 LayerTreeHostContextTestFailsToCreateSurface); 1762 LayerTreeHostContextTestFailsToCreateSurface);
1889 1763
1764 // Not reusing LayerTreeTest because it expects creating LTH to always succeed.
1765 class LayerTreeHostTestCannotCreateIfCannotCreateOutputSurface
1766 : public testing::Test,
1767 public FakeLayerTreeHostClient {
1768 public:
1769 LayerTreeHostTestCannotCreateIfCannotCreateOutputSurface()
1770 : FakeLayerTreeHostClient(FakeLayerTreeHostClient::DIRECT_3D) {}
1771
1772 // FakeLayerTreeHostClient implementation.
1773 virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback)
1774 OVERRIDE {
1775 return scoped_ptr<OutputSurface>();
1776 }
1777
1778 void RunTest(bool threaded,
1779 bool delegating_renderer,
1780 bool impl_side_painting) {
1781 LayerTreeSettings settings;
1782 settings.impl_side_painting = impl_side_painting;
1783 if (threaded) {
1784 scoped_ptr<base::Thread> impl_thread(new base::Thread("LayerTreeTest"));
1785 ASSERT_TRUE(impl_thread->Start());
1786 ASSERT_TRUE(impl_thread->message_loop_proxy().get());
1787 scoped_ptr<LayerTreeHost> layer_tree_host = LayerTreeHost::CreateThreaded(
1788 this, NULL, settings, impl_thread->message_loop_proxy());
1789 EXPECT_FALSE(layer_tree_host);
1790 } else {
1791 scoped_ptr<LayerTreeHost> layer_tree_host =
1792 LayerTreeHost::CreateSingleThreaded(this, this, NULL, settings);
1793 EXPECT_FALSE(layer_tree_host);
1794 }
1795 }
1796 };
1797
1798 SINGLE_AND_MULTI_THREAD_TEST_F(
1799 LayerTreeHostTestCannotCreateIfCannotCreateOutputSurface);
1800
1890 class UIResourceLostTest : public LayerTreeHostContextTest { 1801 class UIResourceLostTest : public LayerTreeHostContextTest {
1891 public: 1802 public:
1892 UIResourceLostTest() : time_step_(0) {} 1803 UIResourceLostTest() : time_step_(0) {}
1893 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { 1804 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE {
1894 settings->texture_id_allocation_chunk_size = 1; 1805 settings->texture_id_allocation_chunk_size = 1;
1895 } 1806 }
1896 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } 1807 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
1897 virtual void AfterTest() OVERRIDE {} 1808 virtual void AfterTest() OVERRIDE {}
1898 1809
1899 // This is called on the main thread after each commit and 1810 // This is called on the main thread after each commit and
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
2378 protected: 2289 protected:
2379 FakeContentLayerClient client_; 2290 FakeContentLayerClient client_;
2380 scoped_refptr<FakeContentLayer> layer_; 2291 scoped_refptr<FakeContentLayer> layer_;
2381 int num_commits_; 2292 int num_commits_;
2382 }; 2293 };
2383 2294
2384 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestSurfaceCreateCallback); 2295 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestSurfaceCreateCallback);
2385 2296
2386 } // namespace 2297 } // namespace
2387 } // namespace cc 2298 } // namespace cc
OLDNEW
« no previous file with comments | « trunk/src/cc/trees/layer_tree_host_unittest.cc ('k') | trunk/src/cc/trees/proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698