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

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

Issue 85693007: cc: Defer first OutputSurface creation until client is ready (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase 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 | « cc/trees/layer_tree_host_unittest.cc ('k') | 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 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 protected: 338 protected:
339 size_t test_case_; 339 size_t test_case_;
340 int num_losses_; 340 int num_losses_;
341 int num_losses_last_test_case_; 341 int num_losses_last_test_case_;
342 bool recovered_context_; 342 bool recovered_context_;
343 bool first_initialized_; 343 bool first_initialized_;
344 }; 344 };
345 345
346 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestLostContextSucceeds); 346 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestLostContextSucceeds);
347 347
348 class LayerTreeHostClientNotReadyDoesNotCreateOutputSurface
349 : public LayerTreeHostContextTest {
350 public:
351 LayerTreeHostClientNotReadyDoesNotCreateOutputSurface()
352 : LayerTreeHostContextTest() {}
353
354 virtual void WillBeginTest() OVERRIDE {
355 // Override and do not signal SetLayerTreeHostClientReady.
356 }
357
358 virtual void BeginTest() OVERRIDE {
359 PostSetNeedsCommitToMainThread();
360 EndTest();
361 }
362
363 virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback)
364 OVERRIDE {
365 EXPECT_TRUE(false);
366 return scoped_ptr<OutputSurface>();
367 }
368
369 virtual void DidInitializeOutputSurface(bool succeeded) OVERRIDE {
370 EXPECT_TRUE(false);
371 }
372
373 virtual void AfterTest() OVERRIDE {
374 }
375 };
376
377 MULTI_THREAD_TEST_F(LayerTreeHostClientNotReadyDoesNotCreateOutputSurface);
378
348 class LayerTreeHostContextTestLostContextSucceedsWithContent 379 class LayerTreeHostContextTestLostContextSucceedsWithContent
349 : public LayerTreeHostContextTestLostContextSucceeds { 380 : public LayerTreeHostContextTestLostContextSucceeds {
350 public: 381 public:
351 LayerTreeHostContextTestLostContextSucceedsWithContent() 382 LayerTreeHostContextTestLostContextSucceedsWithContent()
352 : LayerTreeHostContextTestLostContextSucceeds() {} 383 : LayerTreeHostContextTestLostContextSucceeds() {}
353 384
354 virtual void SetupTree() OVERRIDE { 385 virtual void SetupTree() OVERRIDE {
355 root_ = Layer::Create(); 386 root_ = Layer::Create();
356 root_->SetBounds(gfx::Size(10, 10)); 387 root_->SetBounds(gfx::Size(10, 10));
357 root_->SetAnchorPoint(gfx::PointF()); 388 root_->SetAnchorPoint(gfx::PointF());
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 use_surface_ = true; 485 use_surface_ = true;
455 RunTest(false, false, false); 486 RunTest(false, false, false);
456 } 487 }
457 488
458 TEST_F(LayerTreeHostContextTestLostContextSucceedsWithContent, 489 TEST_F(LayerTreeHostContextTestLostContextSucceedsWithContent,
459 WithSurface_MultiThread_DirectRenderer_MainThreadPaint) { 490 WithSurface_MultiThread_DirectRenderer_MainThreadPaint) {
460 use_surface_ = true; 491 use_surface_ = true;
461 RunTest(true, false, false); 492 RunTest(true, false, false);
462 } 493 }
463 494
495 class LayerTreeHostContextTestCreateOutputSurfaceFails
496 : public LayerTreeHostContextTest {
497 public:
498 // Run a test that initially fails OutputSurface creation |times_to_fail|
499 // times. If |expect_fallback_attempt| is |true|, an attempt to create a
500 // fallback/software OutputSurface is expected to occur.
501 LayerTreeHostContextTestCreateOutputSurfaceFails(int times_to_fail,
502 bool expect_fallback_attempt,
503 bool expect_to_give_up)
504 : times_to_fail_(times_to_fail),
505 expect_fallback_attempt_(expect_fallback_attempt),
506 expect_to_give_up_(expect_to_give_up),
507 did_attempt_fallback_(false),
508 times_initialized_(0) {}
509
510 virtual void BeginTest() OVERRIDE {
511 times_to_fail_create_ = times_to_fail_;
512 PostSetNeedsCommitToMainThread();
513 }
514
515 virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback)
516 OVERRIDE {
517 scoped_ptr<OutputSurface> surface =
518 LayerTreeHostContextTest::CreateOutputSurface(fallback);
519
520 if (surface)
521 EXPECT_EQ(times_to_fail_, times_create_failed_);
522
523 did_attempt_fallback_ = fallback;
524 return surface.Pass();
525 }
526
527 virtual void DidInitializeOutputSurface(bool succeeded) OVERRIDE {
528 if (succeeded)
529 times_initialized_++;
530 else
531 EndTest();
532 }
533
534 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
535 EndTest();
536 }
537
538 virtual void AfterTest() OVERRIDE {
539 EXPECT_EQ(times_to_fail_, times_create_failed_);
540 EXPECT_EQ(expect_to_give_up_, times_initialized_ == 0);
541 EXPECT_EQ(expect_fallback_attempt_, did_attempt_fallback_);
542 }
543
544 private:
545 int times_to_fail_;
546 bool expect_fallback_attempt_;
547 bool expect_to_give_up_;
548 bool did_attempt_fallback_;
549 int times_initialized_;
550 };
551
552 class LayerTreeHostContextTestCreateOutputSurfaceFailsOnce
553 : public LayerTreeHostContextTestCreateOutputSurfaceFails {
554 public:
555 LayerTreeHostContextTestCreateOutputSurfaceFailsOnce()
556 : LayerTreeHostContextTestCreateOutputSurfaceFails(1, false, false) {}
557 };
558
559 SINGLE_AND_MULTI_THREAD_TEST_F(
560 LayerTreeHostContextTestCreateOutputSurfaceFailsOnce);
561
562 // After 4 failures we expect an attempt to create a fallback/software
563 // OutputSurface.
564 class LayerTreeHostContextTestCreateOutputSurfaceFailsWithFallback
565 : public LayerTreeHostContextTestCreateOutputSurfaceFails {
566 public:
567 LayerTreeHostContextTestCreateOutputSurfaceFailsWithFallback()
568 : LayerTreeHostContextTestCreateOutputSurfaceFails(4, true, false) {}
569 };
570
571 SINGLE_AND_MULTI_THREAD_TEST_F(
572 LayerTreeHostContextTestCreateOutputSurfaceFailsWithFallback);
573
574 // If we fail that often, we should be giving up cleanly.
575 class LayerTreeHostContextTestCreateOutputSurfaceIsHopeless
576 : public LayerTreeHostContextTestCreateOutputSurfaceFails {
577 public:
578 LayerTreeHostContextTestCreateOutputSurfaceIsHopeless()
579 : LayerTreeHostContextTestCreateOutputSurfaceFails(5, true, true) {}
580 };
581
582 SINGLE_AND_MULTI_THREAD_TEST_F(
583 LayerTreeHostContextTestCreateOutputSurfaceIsHopeless);
584
585
464 class LayerTreeHostContextTestOffscreenContextFails 586 class LayerTreeHostContextTestOffscreenContextFails
465 : public LayerTreeHostContextTest { 587 : public LayerTreeHostContextTest {
466 public: 588 public:
467 virtual void SetupTree() OVERRIDE { 589 virtual void SetupTree() OVERRIDE {
468 root_ = Layer::Create(); 590 root_ = Layer::Create();
469 root_->SetBounds(gfx::Size(10, 10)); 591 root_->SetBounds(gfx::Size(10, 10));
470 root_->SetAnchorPoint(gfx::PointF()); 592 root_->SetAnchorPoint(gfx::PointF());
471 root_->SetIsDrawable(true); 593 root_->SetIsDrawable(true);
472 594
473 content_ = FakeContentLayer::Create(&client_); 595 content_ = FakeContentLayer::Create(&client_);
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after
1025 if (host_impl->active_tree()->source_frame_number() == 2) { 1147 if (host_impl->active_tree()->source_frame_number() == 2) {
1026 // Lose the context during draw on the second commit. This will cause 1148 // Lose the context during draw on the second commit. This will cause
1027 // a third commit to recover. 1149 // a third commit to recover.
1028 context3d_->set_times_bind_texture_succeeds(0); 1150 context3d_->set_times_bind_texture_succeeds(0);
1029 } 1151 }
1030 return true; 1152 return true;
1031 } 1153 }
1032 1154
1033 virtual scoped_ptr<OutputSurface> CreateOutputSurface( 1155 virtual scoped_ptr<OutputSurface> CreateOutputSurface(
1034 bool fallback) OVERRIDE { 1156 bool fallback) OVERRIDE {
1035 if (layer_tree_host()) { 1157 // This will get called twice:
1158 // First when we create the initial output surface...
1159 if (layer_tree_host()->source_frame_number() > 0) {
1160 // ... and then again after we forced the context to be lost on the third
1161 // frame. Verify this assumption here.
1036 lost_context_ = true; 1162 lost_context_ = true;
1037 EXPECT_EQ(layer_tree_host()->source_frame_number(), 3); 1163 EXPECT_EQ(layer_tree_host()->source_frame_number(), 3);
1038 } 1164 }
1039 return LayerTreeHostContextTest::CreateOutputSurface(fallback); 1165 return LayerTreeHostContextTest::CreateOutputSurface(fallback);
1040 } 1166 }
1041 1167
1042 virtual void DidCommitAndDrawFrame() OVERRIDE { 1168 virtual void DidCommitAndDrawFrame() OVERRIDE {
1043 ASSERT_TRUE(layer_tree_host()->hud_layer()); 1169 ASSERT_TRUE(layer_tree_host()->hud_layer());
1044 // End the test once we know the 3nd frame drew. 1170 // End the test once we know the 3nd frame drew.
1045 if (layer_tree_host()->source_frame_number() < 4) { 1171 if (layer_tree_host()->source_frame_number() < 4) {
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
1398 } 1524 }
1399 } 1525 }
1400 1526
1401 private: 1527 private:
1402 int commits_; 1528 int commits_;
1403 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer_; 1529 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer_;
1404 }; 1530 };
1405 1531
1406 SINGLE_AND_MULTI_THREAD_TEST_F(ScrollbarLayerLostContext); 1532 SINGLE_AND_MULTI_THREAD_TEST_F(ScrollbarLayerLostContext);
1407 1533
1408 // Not reusing LayerTreeTest because it expects creating LTH to always succeed.
1409 class LayerTreeHostTestCannotCreateIfCannotCreateOutputSurface
1410 : public testing::Test,
1411 public FakeLayerTreeHostClient {
1412 public:
1413 LayerTreeHostTestCannotCreateIfCannotCreateOutputSurface()
1414 : FakeLayerTreeHostClient(FakeLayerTreeHostClient::DIRECT_3D) {}
1415
1416 // FakeLayerTreeHostClient implementation.
1417 virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback)
1418 OVERRIDE {
1419 return scoped_ptr<OutputSurface>();
1420 }
1421
1422 void RunTest(bool threaded,
1423 bool delegating_renderer,
1424 bool impl_side_painting) {
1425 LayerTreeSettings settings;
1426 settings.impl_side_painting = impl_side_painting;
1427 if (threaded) {
1428 scoped_ptr<base::Thread> impl_thread(new base::Thread("LayerTreeTest"));
1429 ASSERT_TRUE(impl_thread->Start());
1430 ASSERT_TRUE(impl_thread->message_loop_proxy().get());
1431 scoped_ptr<LayerTreeHost> layer_tree_host = LayerTreeHost::CreateThreaded(
1432 this, NULL, settings, impl_thread->message_loop_proxy());
1433 EXPECT_FALSE(layer_tree_host);
1434 } else {
1435 scoped_ptr<LayerTreeHost> layer_tree_host =
1436 LayerTreeHost::CreateSingleThreaded(this, this, NULL, settings);
1437 EXPECT_FALSE(layer_tree_host);
1438 }
1439 }
1440 };
1441
1442 SINGLE_AND_MULTI_THREAD_TEST_F(
1443 LayerTreeHostTestCannotCreateIfCannotCreateOutputSurface);
1444
1445 class UIResourceLostTest : public LayerTreeHostContextTest { 1534 class UIResourceLostTest : public LayerTreeHostContextTest {
1446 public: 1535 public:
1447 UIResourceLostTest() : time_step_(0) {} 1536 UIResourceLostTest() : time_step_(0) {}
1448 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { 1537 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE {
1449 settings->texture_id_allocation_chunk_size = 1; 1538 settings->texture_id_allocation_chunk_size = 1;
1450 } 1539 }
1451 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } 1540 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
1452 virtual void AfterTest() OVERRIDE {} 1541 virtual void AfterTest() OVERRIDE {}
1453 1542
1454 // This is called on the main thread after each commit and 1543 // This is called on the main thread after each commit and
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
1933 protected: 2022 protected:
1934 FakeContentLayerClient client_; 2023 FakeContentLayerClient client_;
1935 scoped_refptr<FakeContentLayer> layer_; 2024 scoped_refptr<FakeContentLayer> layer_;
1936 int num_commits_; 2025 int num_commits_;
1937 }; 2026 };
1938 2027
1939 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestSurfaceCreateCallback); 2028 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestSurfaceCreateCallback);
1940 2029
1941 } // namespace 2030 } // namespace
1942 } // namespace cc 2031 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_unittest.cc ('k') | cc/trees/proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698