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

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

Issue 645853008: Standardize usage of virtual/override/final in cc/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Formatted Created 6 years, 2 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/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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 CHECK(context3d_); 74 CHECK(context3d_);
75 context3d_->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, 75 context3d_->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB,
76 GL_INNOCENT_CONTEXT_RESET_ARB); 76 GL_INNOCENT_CONTEXT_RESET_ARB);
77 context3d_ = NULL; 77 context3d_ = NULL;
78 } 78 }
79 79
80 virtual scoped_ptr<TestWebGraphicsContext3D> CreateContext3d() { 80 virtual scoped_ptr<TestWebGraphicsContext3D> CreateContext3d() {
81 return TestWebGraphicsContext3D::Create(); 81 return TestWebGraphicsContext3D::Create();
82 } 82 }
83 83
84 virtual scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(bool fallback) 84 scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(
85 override { 85 bool fallback) override {
86 if (times_to_fail_create_) { 86 if (times_to_fail_create_) {
87 --times_to_fail_create_; 87 --times_to_fail_create_;
88 ExpectCreateToFail(); 88 ExpectCreateToFail();
89 return nullptr; 89 return nullptr;
90 } 90 }
91 91
92 scoped_ptr<TestWebGraphicsContext3D> context3d = CreateContext3d(); 92 scoped_ptr<TestWebGraphicsContext3D> context3d = CreateContext3d();
93 context3d_ = context3d.get(); 93 context3d_ = context3d.get();
94 94
95 if (context_should_support_io_surface_) { 95 if (context_should_support_io_surface_) {
96 context3d_->set_have_extension_io_surface(true); 96 context3d_->set_have_extension_io_surface(true);
97 context3d_->set_have_extension_egl_image(true); 97 context3d_->set_have_extension_egl_image(true);
98 } 98 }
99 99
100 if (delegating_renderer()) 100 if (delegating_renderer())
101 return FakeOutputSurface::CreateDelegating3d(context3d.Pass()); 101 return FakeOutputSurface::CreateDelegating3d(context3d.Pass());
102 else 102 else
103 return FakeOutputSurface::Create3d(context3d.Pass()); 103 return FakeOutputSurface::Create3d(context3d.Pass());
104 } 104 }
105 105
106 virtual DrawResult PrepareToDrawOnThread( 106 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
107 LayerTreeHostImpl* host_impl, 107 LayerTreeHostImpl::FrameData* frame,
108 LayerTreeHostImpl::FrameData* frame, 108 DrawResult draw_result) override {
109 DrawResult draw_result) override {
110 if (draw_result == DRAW_ABORTED_MISSING_HIGH_RES_CONTENT) { 109 if (draw_result == DRAW_ABORTED_MISSING_HIGH_RES_CONTENT) {
111 // Only valid for single-threaded impl-side painting, which activates 110 // Only valid for single-threaded impl-side painting, which activates
112 // immediately and will try to draw again when content has finished. 111 // immediately and will try to draw again when content has finished.
113 DCHECK(!host_impl->proxy()->HasImplThread()); 112 DCHECK(!host_impl->proxy()->HasImplThread());
114 DCHECK(layer_tree_host()->settings().impl_side_painting); 113 DCHECK(layer_tree_host()->settings().impl_side_painting);
115 return draw_result; 114 return draw_result;
116 } 115 }
117 EXPECT_EQ(DRAW_SUCCESS, draw_result); 116 EXPECT_EQ(DRAW_SUCCESS, draw_result);
118 if (!times_to_lose_during_draw_) 117 if (!times_to_lose_during_draw_)
119 return draw_result; 118 return draw_result;
120 119
121 --times_to_lose_during_draw_; 120 --times_to_lose_during_draw_;
122 LoseContext(); 121 LoseContext();
123 122
124 times_to_fail_create_ = times_to_fail_recreate_; 123 times_to_fail_create_ = times_to_fail_recreate_;
125 times_to_fail_recreate_ = 0; 124 times_to_fail_recreate_ = 0;
126 125
127 return draw_result; 126 return draw_result;
128 } 127 }
129 128
130 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { 129 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
131 committed_at_least_once_ = true; 130 committed_at_least_once_ = true;
132 131
133 if (!times_to_lose_during_commit_) 132 if (!times_to_lose_during_commit_)
134 return; 133 return;
135 --times_to_lose_during_commit_; 134 --times_to_lose_during_commit_;
136 LoseContext(); 135 LoseContext();
137 136
138 times_to_fail_create_ = times_to_fail_recreate_; 137 times_to_fail_create_ = times_to_fail_recreate_;
139 times_to_fail_recreate_ = 0; 138 times_to_fail_recreate_ = 0;
140 } 139 }
141 140
142 virtual void DidFailToInitializeOutputSurface() override { 141 void DidFailToInitializeOutputSurface() override { ++times_create_failed_; }
143 ++times_create_failed_;
144 }
145 142
146 virtual void TearDown() override { 143 virtual void TearDown() override {
147 LayerTreeTest::TearDown(); 144 LayerTreeTest::TearDown();
148 EXPECT_EQ(times_to_expect_create_failed_, times_create_failed_); 145 EXPECT_EQ(times_to_expect_create_failed_, times_create_failed_);
149 } 146 }
150 147
151 void ExpectCreateToFail() { ++times_to_expect_create_failed_; } 148 void ExpectCreateToFail() { ++times_to_expect_create_failed_; }
152 149
153 protected: 150 protected:
154 TestWebGraphicsContext3D* context3d_; 151 TestWebGraphicsContext3D* context3d_;
(...skipping 13 matching lines...) Expand all
168 : public LayerTreeHostContextTest { 165 : public LayerTreeHostContextTest {
169 public: 166 public:
170 LayerTreeHostContextTestLostContextSucceeds() 167 LayerTreeHostContextTestLostContextSucceeds()
171 : LayerTreeHostContextTest(), 168 : LayerTreeHostContextTest(),
172 test_case_(0), 169 test_case_(0),
173 num_losses_(0), 170 num_losses_(0),
174 num_losses_last_test_case_(-1), 171 num_losses_last_test_case_(-1),
175 recovered_context_(true), 172 recovered_context_(true),
176 first_initialized_(false) {} 173 first_initialized_(false) {}
177 174
178 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); } 175 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
179 176
180 virtual void RequestNewOutputSurface(bool fallback) override { 177 void RequestNewOutputSurface(bool fallback) override {
181 if (async_output_surface_creation_) { 178 if (async_output_surface_creation_) {
182 MainThreadTaskRunner()->PostTask( 179 MainThreadTaskRunner()->PostTask(
183 FROM_HERE, 180 FROM_HERE,
184 base::Bind(&LayerTreeHostContextTestLostContextSucceeds:: 181 base::Bind(&LayerTreeHostContextTestLostContextSucceeds::
185 CreateAndSetOutputSurface, 182 CreateAndSetOutputSurface,
186 base::Unretained(this), 183 base::Unretained(this),
187 fallback)); 184 fallback));
188 } else { 185 } else {
189 CreateAndSetOutputSurface(fallback); 186 CreateAndSetOutputSurface(fallback);
190 } 187 }
191 } 188 }
192 189
193 void CreateAndSetOutputSurface(bool fallback) { 190 void CreateAndSetOutputSurface(bool fallback) {
194 layer_tree_host()->SetOutputSurface( 191 layer_tree_host()->SetOutputSurface(
195 LayerTreeHostContextTest::CreateOutputSurface(fallback)); 192 LayerTreeHostContextTest::CreateOutputSurface(fallback));
196 } 193 }
197 194
198 virtual void DidInitializeOutputSurface() override { 195 void DidInitializeOutputSurface() override {
199 if (first_initialized_) 196 if (first_initialized_)
200 ++num_losses_; 197 ++num_losses_;
201 else 198 else
202 first_initialized_ = true; 199 first_initialized_ = true;
203 200
204 recovered_context_ = true; 201 recovered_context_ = true;
205 } 202 }
206 203
207 virtual void AfterTest() override { EXPECT_EQ(11u, test_case_); } 204 void AfterTest() override { EXPECT_EQ(11u, test_case_); }
208 205
209 virtual void DidCommitAndDrawFrame() override { 206 void DidCommitAndDrawFrame() override {
210 // If the last frame had a context loss, then we'll commit again to 207 // If the last frame had a context loss, then we'll commit again to
211 // recover. 208 // recover.
212 if (!recovered_context_) 209 if (!recovered_context_)
213 return; 210 return;
214 if (times_to_lose_during_commit_) 211 if (times_to_lose_during_commit_)
215 return; 212 return;
216 if (times_to_lose_during_draw_) 213 if (times_to_lose_during_draw_)
217 return; 214 return;
218 215
219 recovered_context_ = false; 216 recovered_context_ = false;
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 }; 348 };
352 349
353 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestLostContextSucceeds); 350 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestLostContextSucceeds);
354 351
355 class LayerTreeHostClientNotReadyDoesNotCreateOutputSurface 352 class LayerTreeHostClientNotReadyDoesNotCreateOutputSurface
356 : public LayerTreeHostContextTest { 353 : public LayerTreeHostContextTest {
357 public: 354 public:
358 LayerTreeHostClientNotReadyDoesNotCreateOutputSurface() 355 LayerTreeHostClientNotReadyDoesNotCreateOutputSurface()
359 : LayerTreeHostContextTest() {} 356 : LayerTreeHostContextTest() {}
360 357
361 virtual void WillBeginTest() override { 358 void WillBeginTest() override {
362 // Override and do not signal SetLayerTreeHostClientReady. 359 // Override and do not signal SetLayerTreeHostClientReady.
363 } 360 }
364 361
365 virtual void BeginTest() override { 362 void BeginTest() override {
366 PostSetNeedsCommitToMainThread(); 363 PostSetNeedsCommitToMainThread();
367 EndTest(); 364 EndTest();
368 } 365 }
369 366
370 virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback) 367 scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback) override {
371 override {
372 EXPECT_TRUE(false); 368 EXPECT_TRUE(false);
373 return nullptr; 369 return nullptr;
374 } 370 }
375 371
376 virtual void DidInitializeOutputSurface() override { EXPECT_TRUE(false); } 372 void DidInitializeOutputSurface() override { EXPECT_TRUE(false); }
377 373
378 virtual void AfterTest() override { 374 void AfterTest() override {}
379 }
380 }; 375 };
381 376
382 SINGLE_AND_MULTI_THREAD_TEST_F( 377 SINGLE_AND_MULTI_THREAD_TEST_F(
383 LayerTreeHostClientNotReadyDoesNotCreateOutputSurface); 378 LayerTreeHostClientNotReadyDoesNotCreateOutputSurface);
384 379
385 class MultipleCompositeDoesNotCreateOutputSurface 380 class MultipleCompositeDoesNotCreateOutputSurface
386 : public LayerTreeHostContextTest { 381 : public LayerTreeHostContextTest {
387 public: 382 public:
388 MultipleCompositeDoesNotCreateOutputSurface() 383 MultipleCompositeDoesNotCreateOutputSurface()
389 : LayerTreeHostContextTest(), request_count_(0) {} 384 : LayerTreeHostContextTest(), request_count_(0) {}
390 385
391 virtual void InitializeSettings(LayerTreeSettings* settings) override { 386 void InitializeSettings(LayerTreeSettings* settings) override {
392 settings->single_thread_proxy_scheduler = false; 387 settings->single_thread_proxy_scheduler = false;
393 } 388 }
394 389
395 virtual void RequestNewOutputSurface(bool fallback) override { 390 void RequestNewOutputSurface(bool fallback) override {
396 EXPECT_GE(1, ++request_count_); 391 EXPECT_GE(1, ++request_count_);
397 EndTest(); 392 EndTest();
398 } 393 }
399 394
400 virtual void BeginTest() override { 395 void BeginTest() override {
401 layer_tree_host()->Composite(base::TimeTicks()); 396 layer_tree_host()->Composite(base::TimeTicks());
402 layer_tree_host()->Composite(base::TimeTicks()); 397 layer_tree_host()->Composite(base::TimeTicks());
403 } 398 }
404 399
405 virtual scoped_ptr<OutputSurface> CreateOutputSurface( 400 scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback) override {
406 bool fallback) override {
407 EXPECT_TRUE(false); 401 EXPECT_TRUE(false);
408 return nullptr; 402 return nullptr;
409 } 403 }
410 404
411 virtual void DidInitializeOutputSurface() override { EXPECT_TRUE(false); } 405 void DidInitializeOutputSurface() override { EXPECT_TRUE(false); }
412 406
413 virtual void AfterTest() override {} 407 void AfterTest() override {}
414 408
415 int request_count_; 409 int request_count_;
416 }; 410 };
417 411
418 SINGLE_THREAD_TEST_F(MultipleCompositeDoesNotCreateOutputSurface); 412 SINGLE_THREAD_TEST_F(MultipleCompositeDoesNotCreateOutputSurface);
419 413
420 class FailedCreateDoesNotCreateExtraOutputSurface 414 class FailedCreateDoesNotCreateExtraOutputSurface
421 : public LayerTreeHostContextTest { 415 : public LayerTreeHostContextTest {
422 public: 416 public:
423 FailedCreateDoesNotCreateExtraOutputSurface() 417 FailedCreateDoesNotCreateExtraOutputSurface()
424 : LayerTreeHostContextTest(), request_count_(0) {} 418 : LayerTreeHostContextTest(), request_count_(0) {}
425 419
426 virtual void InitializeSettings(LayerTreeSettings* settings) override { 420 void InitializeSettings(LayerTreeSettings* settings) override {
427 settings->single_thread_proxy_scheduler = false; 421 settings->single_thread_proxy_scheduler = false;
428 } 422 }
429 423
430 virtual void RequestNewOutputSurface(bool fallback) override { 424 void RequestNewOutputSurface(bool fallback) override {
431 if (request_count_ == 0) { 425 if (request_count_ == 0) {
432 ExpectCreateToFail(); 426 ExpectCreateToFail();
433 layer_tree_host()->SetOutputSurface(nullptr); 427 layer_tree_host()->SetOutputSurface(nullptr);
434 } 428 }
435 EXPECT_GE(2, ++request_count_); 429 EXPECT_GE(2, ++request_count_);
436 EndTest(); 430 EndTest();
437 } 431 }
438 432
439 virtual void BeginTest() override { 433 void BeginTest() override {
440 layer_tree_host()->Composite(base::TimeTicks()); 434 layer_tree_host()->Composite(base::TimeTicks());
441 layer_tree_host()->Composite(base::TimeTicks()); 435 layer_tree_host()->Composite(base::TimeTicks());
442 } 436 }
443 437
444 virtual scoped_ptr<OutputSurface> CreateOutputSurface( 438 scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback) override {
445 bool fallback) override {
446 EXPECT_TRUE(false); 439 EXPECT_TRUE(false);
447 return nullptr; 440 return nullptr;
448 } 441 }
449 442
450 virtual void DidInitializeOutputSurface() override { EXPECT_TRUE(false); } 443 void DidInitializeOutputSurface() override { EXPECT_TRUE(false); }
451 444
452 virtual void AfterTest() override {} 445 void AfterTest() override {}
453 446
454 int request_count_; 447 int request_count_;
455 }; 448 };
456 449
457 SINGLE_THREAD_TEST_F(FailedCreateDoesNotCreateExtraOutputSurface); 450 SINGLE_THREAD_TEST_F(FailedCreateDoesNotCreateExtraOutputSurface);
458 451
459 class LayerTreeHostContextTestLostContextSucceedsWithContent 452 class LayerTreeHostContextTestLostContextSucceedsWithContent
460 : public LayerTreeHostContextTestLostContextSucceeds { 453 : public LayerTreeHostContextTestLostContextSucceeds {
461 public: 454 public:
462 virtual void SetupTree() override { 455 void SetupTree() override {
463 root_ = Layer::Create(); 456 root_ = Layer::Create();
464 root_->SetBounds(gfx::Size(10, 10)); 457 root_->SetBounds(gfx::Size(10, 10));
465 root_->SetIsDrawable(true); 458 root_->SetIsDrawable(true);
466 459
467 // Paint non-solid color. 460 // Paint non-solid color.
468 SkPaint paint; 461 SkPaint paint;
469 paint.setColor(SkColorSetARGB(100, 80, 200, 200)); 462 paint.setColor(SkColorSetARGB(100, 80, 200, 200));
470 client_.add_draw_rect(gfx::Rect(0, 0, 5, 5), paint); 463 client_.add_draw_rect(gfx::Rect(0, 0, 5, 5), paint);
471 464
472 if (layer_tree_host()->settings().impl_side_painting) 465 if (layer_tree_host()->settings().impl_side_painting)
473 layer_ = FakePictureLayer::Create(&client_); 466 layer_ = FakePictureLayer::Create(&client_);
474 else 467 else
475 layer_ = FakeContentLayer::Create(&client_); 468 layer_ = FakeContentLayer::Create(&client_);
476 layer_->SetBounds(gfx::Size(10, 10)); 469 layer_->SetBounds(gfx::Size(10, 10));
477 layer_->SetIsDrawable(true); 470 layer_->SetIsDrawable(true);
478 471
479 root_->AddChild(layer_); 472 root_->AddChild(layer_);
480 473
481 layer_tree_host()->SetRootLayer(root_); 474 layer_tree_host()->SetRootLayer(root_);
482 LayerTreeHostContextTest::SetupTree(); 475 LayerTreeHostContextTest::SetupTree();
483 } 476 }
484 477
485 virtual void InvalidateAndSetNeedsCommit() override { 478 void InvalidateAndSetNeedsCommit() override {
486 // Invalidate the render surface so we don't try to use a cached copy of the 479 // Invalidate the render surface so we don't try to use a cached copy of the
487 // surface. We want to make sure to test the drawing paths for drawing to 480 // surface. We want to make sure to test the drawing paths for drawing to
488 // a child surface. 481 // a child surface.
489 layer_->SetNeedsDisplay(); 482 layer_->SetNeedsDisplay();
490 LayerTreeHostContextTestLostContextSucceeds::InvalidateAndSetNeedsCommit(); 483 LayerTreeHostContextTestLostContextSucceeds::InvalidateAndSetNeedsCommit();
491 } 484 }
492 485
493 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { 486 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override {
494 if (!host_impl->settings().impl_side_painting) { 487 if (!host_impl->settings().impl_side_painting) {
495 FakeContentLayerImpl* content_impl = static_cast<FakeContentLayerImpl*>( 488 FakeContentLayerImpl* content_impl = static_cast<FakeContentLayerImpl*>(
496 host_impl->active_tree()->root_layer()->children()[0]); 489 host_impl->active_tree()->root_layer()->children()[0]);
497 // Even though the context was lost, we should have a resource. The 490 // Even though the context was lost, we should have a resource. The
498 // TestWebGraphicsContext3D ensures that this resource is created with 491 // TestWebGraphicsContext3D ensures that this resource is created with
499 // the active context. 492 // the active context.
500 EXPECT_TRUE(content_impl->HaveResourceForTileAt(0, 0)); 493 EXPECT_TRUE(content_impl->HaveResourceForTileAt(0, 0));
501 } else { 494 } else {
502 FakePictureLayerImpl* picture_impl = static_cast<FakePictureLayerImpl*>( 495 FakePictureLayerImpl* picture_impl = static_cast<FakePictureLayerImpl*>(
503 host_impl->active_tree()->root_layer()->children()[0]); 496 host_impl->active_tree()->root_layer()->children()[0]);
(...skipping 19 matching lines...) Expand all
523 // fallback/software OutputSurface is expected to occur. 516 // fallback/software OutputSurface is expected to occur.
524 LayerTreeHostContextTestCreateOutputSurfaceFails(int times_to_fail, 517 LayerTreeHostContextTestCreateOutputSurfaceFails(int times_to_fail,
525 bool expect_fallback_attempt) 518 bool expect_fallback_attempt)
526 : times_to_fail_(times_to_fail), 519 : times_to_fail_(times_to_fail),
527 expect_fallback_attempt_(expect_fallback_attempt), 520 expect_fallback_attempt_(expect_fallback_attempt),
528 did_attempt_fallback_(false), 521 did_attempt_fallback_(false),
529 times_initialized_(0) { 522 times_initialized_(0) {
530 times_to_fail_create_ = times_to_fail_; 523 times_to_fail_create_ = times_to_fail_;
531 } 524 }
532 525
533 virtual void BeginTest() override { 526 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
534 PostSetNeedsCommitToMainThread();
535 }
536 527
537 virtual scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(bool fallback) 528 scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(
538 override { 529 bool fallback) override {
539 scoped_ptr<FakeOutputSurface> surface = 530 scoped_ptr<FakeOutputSurface> surface =
540 LayerTreeHostContextTest::CreateFakeOutputSurface(fallback); 531 LayerTreeHostContextTest::CreateFakeOutputSurface(fallback);
541 532
542 if (surface) 533 if (surface)
543 EXPECT_EQ(times_to_fail_, times_create_failed_); 534 EXPECT_EQ(times_to_fail_, times_create_failed_);
544 535
545 did_attempt_fallback_ = fallback; 536 did_attempt_fallback_ = fallback;
546 return surface.Pass(); 537 return surface.Pass();
547 } 538 }
548 539
549 virtual void DidInitializeOutputSurface() override { times_initialized_++; } 540 void DidInitializeOutputSurface() override { times_initialized_++; }
550 541
551 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { 542 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { EndTest(); }
552 EndTest();
553 }
554 543
555 virtual void AfterTest() override { 544 void AfterTest() override {
556 EXPECT_EQ(times_to_fail_, times_create_failed_); 545 EXPECT_EQ(times_to_fail_, times_create_failed_);
557 EXPECT_NE(0, times_initialized_); 546 EXPECT_NE(0, times_initialized_);
558 EXPECT_EQ(expect_fallback_attempt_, did_attempt_fallback_); 547 EXPECT_EQ(expect_fallback_attempt_, did_attempt_fallback_);
559 } 548 }
560 549
561 private: 550 private:
562 int times_to_fail_; 551 int times_to_fail_;
563 bool expect_fallback_attempt_; 552 bool expect_fallback_attempt_;
564 bool did_attempt_fallback_; 553 bool did_attempt_fallback_;
565 int times_initialized_; 554 int times_initialized_;
(...skipping 23 matching lines...) Expand all
589 578
590 class LayerTreeHostContextTestLostContextAndEvictTextures 579 class LayerTreeHostContextTestLostContextAndEvictTextures
591 : public LayerTreeHostContextTest { 580 : public LayerTreeHostContextTest {
592 public: 581 public:
593 LayerTreeHostContextTestLostContextAndEvictTextures() 582 LayerTreeHostContextTestLostContextAndEvictTextures()
594 : LayerTreeHostContextTest(), 583 : LayerTreeHostContextTest(),
595 impl_host_(0), 584 impl_host_(0),
596 num_commits_(0), 585 num_commits_(0),
597 lost_context_(false) {} 586 lost_context_(false) {}
598 587
599 virtual void SetupTree() override { 588 void SetupTree() override {
600 // Paint non-solid color. 589 // Paint non-solid color.
601 SkPaint paint; 590 SkPaint paint;
602 paint.setColor(SkColorSetARGB(100, 80, 200, 200)); 591 paint.setColor(SkColorSetARGB(100, 80, 200, 200));
603 client_.add_draw_rect(gfx::Rect(0, 0, 5, 5), paint); 592 client_.add_draw_rect(gfx::Rect(0, 0, 5, 5), paint);
604 593
605 if (layer_tree_host()->settings().impl_side_painting) { 594 if (layer_tree_host()->settings().impl_side_painting) {
606 picture_layer_ = FakePictureLayer::Create(&client_); 595 picture_layer_ = FakePictureLayer::Create(&client_);
607 picture_layer_->SetBounds(gfx::Size(10, 20)); 596 picture_layer_->SetBounds(gfx::Size(10, 20));
608 layer_tree_host()->SetRootLayer(picture_layer_); 597 layer_tree_host()->SetRootLayer(picture_layer_);
609 } else { 598 } else {
610 content_layer_ = FakeContentLayer::Create(&client_); 599 content_layer_ = FakeContentLayer::Create(&client_);
611 content_layer_->SetBounds(gfx::Size(10, 20)); 600 content_layer_->SetBounds(gfx::Size(10, 20));
612 layer_tree_host()->SetRootLayer(content_layer_); 601 layer_tree_host()->SetRootLayer(content_layer_);
613 } 602 }
614 603
615 LayerTreeHostContextTest::SetupTree(); 604 LayerTreeHostContextTest::SetupTree();
616 } 605 }
617 606
618 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); } 607 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
619 608
620 void PostEvictTextures() { 609 void PostEvictTextures() {
621 if (HasImplThread()) { 610 if (HasImplThread()) {
622 ImplThreadTaskRunner()->PostTask( 611 ImplThreadTaskRunner()->PostTask(
623 FROM_HERE, 612 FROM_HERE,
624 base::Bind(&LayerTreeHostContextTestLostContextAndEvictTextures:: 613 base::Bind(&LayerTreeHostContextTestLostContextAndEvictTextures::
625 EvictTexturesOnImplThread, 614 EvictTexturesOnImplThread,
626 base::Unretained(this))); 615 base::Unretained(this)));
627 } else { 616 } else {
628 DebugScopedSetImplThread impl(proxy()); 617 DebugScopedSetImplThread impl(proxy());
629 EvictTexturesOnImplThread(); 618 EvictTexturesOnImplThread();
630 } 619 }
631 } 620 }
632 621
633 void EvictTexturesOnImplThread() { 622 void EvictTexturesOnImplThread() {
634 impl_host_->EvictTexturesForTesting(); 623 impl_host_->EvictTexturesForTesting();
635 624
636 if (lose_after_evict_) { 625 if (lose_after_evict_) {
637 LoseContext(); 626 LoseContext();
638 lost_context_ = true; 627 lost_context_ = true;
639 } 628 }
640 } 629 }
641 630
642 virtual void DidCommitAndDrawFrame() override { 631 void DidCommitAndDrawFrame() override {
643 if (num_commits_ > 1) 632 if (num_commits_ > 1)
644 return; 633 return;
645 if (!layer_tree_host()->settings().impl_side_painting) { 634 if (!layer_tree_host()->settings().impl_side_painting) {
646 EXPECT_TRUE(content_layer_->HaveBackingAt(0, 0)); 635 EXPECT_TRUE(content_layer_->HaveBackingAt(0, 0));
647 } 636 }
648 PostEvictTextures(); 637 PostEvictTextures();
649 } 638 }
650 639
651 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { 640 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
652 LayerTreeHostContextTest::CommitCompleteOnThread(impl); 641 LayerTreeHostContextTest::CommitCompleteOnThread(impl);
653 if (num_commits_ > 1) 642 if (num_commits_ > 1)
654 return; 643 return;
655 ++num_commits_; 644 ++num_commits_;
656 if (!lose_after_evict_) { 645 if (!lose_after_evict_) {
657 LoseContext(); 646 LoseContext();
658 lost_context_ = true; 647 lost_context_ = true;
659 } 648 }
660 } 649 }
661 650
662 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) override { 651 void DrawLayersOnThread(LayerTreeHostImpl* impl) override {
663 if (impl->settings().impl_side_painting) { 652 if (impl->settings().impl_side_painting) {
664 FakePictureLayerImpl* picture_impl = 653 FakePictureLayerImpl* picture_impl =
665 static_cast<FakePictureLayerImpl*>(impl->active_tree()->root_layer()); 654 static_cast<FakePictureLayerImpl*>(impl->active_tree()->root_layer());
666 EXPECT_TRUE(picture_impl->HighResTiling()->TileAt(0, 0)->IsReadyToDraw()); 655 EXPECT_TRUE(picture_impl->HighResTiling()->TileAt(0, 0)->IsReadyToDraw());
667 } else { 656 } else {
668 FakeContentLayerImpl* content_impl = 657 FakeContentLayerImpl* content_impl =
669 static_cast<FakeContentLayerImpl*>(impl->active_tree()->root_layer()); 658 static_cast<FakeContentLayerImpl*>(impl->active_tree()->root_layer());
670 EXPECT_TRUE(content_impl->HaveResourceForTileAt(0, 0)); 659 EXPECT_TRUE(content_impl->HaveResourceForTileAt(0, 0));
671 } 660 }
672 661
673 impl_host_ = impl; 662 impl_host_ = impl;
674 if (lost_context_) 663 if (lost_context_)
675 EndTest(); 664 EndTest();
676 } 665 }
677 666
678 virtual void DidInitializeOutputSurface() override {} 667 void DidInitializeOutputSurface() override {}
679 668
680 virtual void AfterTest() override {} 669 void AfterTest() override {}
681 670
682 protected: 671 protected:
683 bool lose_after_evict_; 672 bool lose_after_evict_;
684 FakeContentLayerClient client_; 673 FakeContentLayerClient client_;
685 scoped_refptr<FakeContentLayer> content_layer_; 674 scoped_refptr<FakeContentLayer> content_layer_;
686 scoped_refptr<FakePictureLayer> picture_layer_; 675 scoped_refptr<FakePictureLayer> picture_layer_;
687 LayerTreeHostImpl* impl_host_; 676 LayerTreeHostImpl* impl_host_;
688 int num_commits_; 677 int num_commits_;
689 bool lost_context_; 678 bool lost_context_;
690 }; 679 };
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 lose_after_evict_ = false; 744 lose_after_evict_ = false;
756 RunTest(true, true, true); 745 RunTest(true, true, true);
757 } 746 }
758 747
759 class LayerTreeHostContextTestLostContextWhileUpdatingResources 748 class LayerTreeHostContextTestLostContextWhileUpdatingResources
760 : public LayerTreeHostContextTest { 749 : public LayerTreeHostContextTest {
761 public: 750 public:
762 LayerTreeHostContextTestLostContextWhileUpdatingResources() 751 LayerTreeHostContextTestLostContextWhileUpdatingResources()
763 : num_children_(50), times_to_lose_on_end_query_(3) {} 752 : num_children_(50), times_to_lose_on_end_query_(3) {}
764 753
765 virtual scoped_ptr<TestWebGraphicsContext3D> CreateContext3d() override { 754 scoped_ptr<TestWebGraphicsContext3D> CreateContext3d() override {
766 scoped_ptr<TestWebGraphicsContext3D> context = 755 scoped_ptr<TestWebGraphicsContext3D> context =
767 LayerTreeHostContextTest::CreateContext3d(); 756 LayerTreeHostContextTest::CreateContext3d();
768 if (times_to_lose_on_end_query_) { 757 if (times_to_lose_on_end_query_) {
769 --times_to_lose_on_end_query_; 758 --times_to_lose_on_end_query_;
770 context->set_times_end_query_succeeds(5); 759 context->set_times_end_query_succeeds(5);
771 } 760 }
772 return context.Pass(); 761 return context.Pass();
773 } 762 }
774 763
775 virtual void SetupTree() override { 764 void SetupTree() override {
776 if (layer_tree_host()->settings().impl_side_painting) 765 if (layer_tree_host()->settings().impl_side_painting)
777 parent_ = FakePictureLayer::Create(&client_); 766 parent_ = FakePictureLayer::Create(&client_);
778 else 767 else
779 parent_ = FakeContentLayer::Create(&client_); 768 parent_ = FakeContentLayer::Create(&client_);
780 769
781 parent_->SetBounds(gfx::Size(num_children_, 1)); 770 parent_->SetBounds(gfx::Size(num_children_, 1));
782 771
783 for (int i = 0; i < num_children_; i++) { 772 for (int i = 0; i < num_children_; i++) {
784 scoped_refptr<Layer> child; 773 scoped_refptr<Layer> child;
785 if (layer_tree_host()->settings().impl_side_painting) 774 if (layer_tree_host()->settings().impl_side_painting)
786 child = FakePictureLayer::Create(&client_); 775 child = FakePictureLayer::Create(&client_);
787 else 776 else
788 child = FakeContentLayer::Create(&client_); 777 child = FakeContentLayer::Create(&client_);
789 child->SetPosition(gfx::PointF(i, 0.f)); 778 child->SetPosition(gfx::PointF(i, 0.f));
790 child->SetBounds(gfx::Size(1, 1)); 779 child->SetBounds(gfx::Size(1, 1));
791 parent_->AddChild(child); 780 parent_->AddChild(child);
792 } 781 }
793 782
794 layer_tree_host()->SetRootLayer(parent_); 783 layer_tree_host()->SetRootLayer(parent_);
795 LayerTreeHostContextTest::SetupTree(); 784 LayerTreeHostContextTest::SetupTree();
796 } 785 }
797 786
798 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); } 787 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
799 788
800 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { 789 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override {
801 EXPECT_EQ(0, times_to_lose_on_end_query_); 790 EXPECT_EQ(0, times_to_lose_on_end_query_);
802 EndTest(); 791 EndTest();
803 } 792 }
804 793
805 virtual void AfterTest() override { 794 void AfterTest() override { EXPECT_EQ(0, times_to_lose_on_end_query_); }
806 EXPECT_EQ(0, times_to_lose_on_end_query_);
807 }
808 795
809 private: 796 private:
810 FakeContentLayerClient client_; 797 FakeContentLayerClient client_;
811 scoped_refptr<Layer> parent_; 798 scoped_refptr<Layer> parent_;
812 int num_children_; 799 int num_children_;
813 int times_to_lose_on_end_query_; 800 int times_to_lose_on_end_query_;
814 }; 801 };
815 802
816 SINGLE_AND_MULTI_THREAD_NOIMPL_TEST_F( 803 SINGLE_AND_MULTI_THREAD_NOIMPL_TEST_F(
817 LayerTreeHostContextTestLostContextWhileUpdatingResources); 804 LayerTreeHostContextTestLostContextWhileUpdatingResources);
818 805
819 class LayerTreeHostContextTestLayersNotified : public LayerTreeHostContextTest { 806 class LayerTreeHostContextTestLayersNotified : public LayerTreeHostContextTest {
820 public: 807 public:
821 LayerTreeHostContextTestLayersNotified() 808 LayerTreeHostContextTestLayersNotified()
822 : LayerTreeHostContextTest(), num_commits_(0) {} 809 : LayerTreeHostContextTest(), num_commits_(0) {}
823 810
824 virtual void SetupTree() override { 811 void SetupTree() override {
825 if (layer_tree_host()->settings().impl_side_painting) { 812 if (layer_tree_host()->settings().impl_side_painting) {
826 root_ = FakePictureLayer::Create(&client_); 813 root_ = FakePictureLayer::Create(&client_);
827 child_ = FakePictureLayer::Create(&client_); 814 child_ = FakePictureLayer::Create(&client_);
828 grandchild_ = FakePictureLayer::Create(&client_); 815 grandchild_ = FakePictureLayer::Create(&client_);
829 } else { 816 } else {
830 root_ = FakeContentLayer::Create(&client_); 817 root_ = FakeContentLayer::Create(&client_);
831 child_ = FakeContentLayer::Create(&client_); 818 child_ = FakeContentLayer::Create(&client_);
832 grandchild_ = FakeContentLayer::Create(&client_); 819 grandchild_ = FakeContentLayer::Create(&client_);
833 } 820 }
834 821
835 root_->AddChild(child_); 822 root_->AddChild(child_);
836 child_->AddChild(grandchild_); 823 child_->AddChild(grandchild_);
837 824
838 layer_tree_host()->SetRootLayer(root_); 825 layer_tree_host()->SetRootLayer(root_);
839 LayerTreeHostContextTest::SetupTree(); 826 LayerTreeHostContextTest::SetupTree();
840 } 827 }
841 828
842 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); } 829 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
843 830
844 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { 831 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
845 LayerTreeHostContextTest::DidActivateTreeOnThread(host_impl); 832 LayerTreeHostContextTest::DidActivateTreeOnThread(host_impl);
846 833
847 FakePictureLayerImpl* root_picture = NULL; 834 FakePictureLayerImpl* root_picture = NULL;
848 FakePictureLayerImpl* child_picture = NULL; 835 FakePictureLayerImpl* child_picture = NULL;
849 FakePictureLayerImpl* grandchild_picture = NULL; 836 FakePictureLayerImpl* grandchild_picture = NULL;
850 FakeContentLayerImpl* root_content = NULL; 837 FakeContentLayerImpl* root_content = NULL;
851 FakeContentLayerImpl* child_content = NULL; 838 FakeContentLayerImpl* child_content = NULL;
852 FakeContentLayerImpl* grandchild_content = NULL; 839 FakeContentLayerImpl* grandchild_content = NULL;
853 840
854 if (layer_tree_host()->settings().impl_side_painting) { 841 if (layer_tree_host()->settings().impl_side_painting) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 EXPECT_TRUE(grandchild_content->lost_output_surface_count()); 883 EXPECT_TRUE(grandchild_content->lost_output_surface_count());
897 } 884 }
898 885
899 EndTest(); 886 EndTest();
900 break; 887 break;
901 default: 888 default:
902 NOTREACHED(); 889 NOTREACHED();
903 } 890 }
904 } 891 }
905 892
906 virtual void AfterTest() override {} 893 void AfterTest() override {}
907 894
908 private: 895 private:
909 int num_commits_; 896 int num_commits_;
910 897
911 FakeContentLayerClient client_; 898 FakeContentLayerClient client_;
912 scoped_refptr<Layer> root_; 899 scoped_refptr<Layer> root_;
913 scoped_refptr<Layer> child_; 900 scoped_refptr<Layer> child_;
914 scoped_refptr<Layer> grandchild_; 901 scoped_refptr<Layer> grandchild_;
915 }; 902 };
916 903
(...skipping 14 matching lines...) Expand all
931 NULL, 918 NULL,
932 NULL, 919 NULL,
933 0, 920 0,
934 false, 921 false,
935 1, 922 1,
936 false); 923 false);
937 } 924 }
938 925
939 static void EmptyReleaseCallback(unsigned sync_point, bool lost) {} 926 static void EmptyReleaseCallback(unsigned sync_point, bool lost) {}
940 927
941 virtual void SetupTree() override { 928 void SetupTree() override {
942 gpu::gles2::GLES2Interface* gl = 929 gpu::gles2::GLES2Interface* gl =
943 child_output_surface_->context_provider()->ContextGL(); 930 child_output_surface_->context_provider()->ContextGL();
944 931
945 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); 932 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
946 933
947 scoped_ptr<TestRenderPass> pass_for_quad = TestRenderPass::Create(); 934 scoped_ptr<TestRenderPass> pass_for_quad = TestRenderPass::Create();
948 pass_for_quad->SetNew( 935 pass_for_quad->SetNew(
949 // AppendOneOfEveryQuadType() makes a RenderPass quad with this id. 936 // AppendOneOfEveryQuadType() makes a RenderPass quad with this id.
950 RenderPassId(2, 1), 937 RenderPassId(2, 1),
951 gfx::Rect(0, 0, 10, 10), 938 gfx::Rect(0, 0, 10, 10),
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
1087 PaintedScrollbarLayer::Create( 1074 PaintedScrollbarLayer::Create(
1088 scoped_ptr<Scrollbar>(new FakeScrollbar).Pass(), layer->id()); 1075 scoped_ptr<Scrollbar>(new FakeScrollbar).Pass(), layer->id());
1089 scrollbar->SetBounds(gfx::Size(10, 10)); 1076 scrollbar->SetBounds(gfx::Size(10, 10));
1090 scrollbar->SetIsDrawable(true); 1077 scrollbar->SetIsDrawable(true);
1091 root->AddChild(scrollbar); 1078 root->AddChild(scrollbar);
1092 1079
1093 layer_tree_host()->SetRootLayer(root); 1080 layer_tree_host()->SetRootLayer(root);
1094 LayerTreeHostContextTest::SetupTree(); 1081 LayerTreeHostContextTest::SetupTree();
1095 } 1082 }
1096 1083
1097 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); } 1084 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
1098 1085
1099 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { 1086 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
1100 LayerTreeHostContextTest::CommitCompleteOnThread(host_impl); 1087 LayerTreeHostContextTest::CommitCompleteOnThread(host_impl);
1101 1088
1102 if (host_impl->active_tree()->source_frame_number() == 3) { 1089 if (host_impl->active_tree()->source_frame_number() == 3) {
1103 // On the third commit we're recovering from context loss. Hardware 1090 // On the third commit we're recovering from context loss. Hardware
1104 // video frames should not be reused by the VideoFrameProvider, but 1091 // video frames should not be reused by the VideoFrameProvider, but
1105 // software frames can be. 1092 // software frames can be.
1106 hw_frame_provider_.set_frame(NULL); 1093 hw_frame_provider_.set_frame(NULL);
1107 scaled_hw_frame_provider_.set_frame(NULL); 1094 scaled_hw_frame_provider_.set_frame(NULL);
1108 } 1095 }
1109 } 1096 }
1110 1097
1111 virtual DrawResult PrepareToDrawOnThread( 1098 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
1112 LayerTreeHostImpl* host_impl, 1099 LayerTreeHostImpl::FrameData* frame,
1113 LayerTreeHostImpl::FrameData* frame, 1100 DrawResult draw_result) override {
1114 DrawResult draw_result) override {
1115 if (host_impl->active_tree()->source_frame_number() == 2) { 1101 if (host_impl->active_tree()->source_frame_number() == 2) {
1116 // Lose the context during draw on the second commit. This will cause 1102 // Lose the context during draw on the second commit. This will cause
1117 // a third commit to recover. 1103 // a third commit to recover.
1118 context3d_->set_times_bind_texture_succeeds(0); 1104 context3d_->set_times_bind_texture_succeeds(0);
1119 } 1105 }
1120 return draw_result; 1106 return draw_result;
1121 } 1107 }
1122 1108
1123 virtual scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(bool fallback) 1109 scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(
1124 override { 1110 bool fallback) override {
1125 // This will get called twice: 1111 // This will get called twice:
1126 // First when we create the initial output surface... 1112 // First when we create the initial output surface...
1127 if (layer_tree_host()->source_frame_number() > 0) { 1113 if (layer_tree_host()->source_frame_number() > 0) {
1128 // ... and then again after we forced the context to be lost. 1114 // ... and then again after we forced the context to be lost.
1129 lost_context_ = true; 1115 lost_context_ = true;
1130 } 1116 }
1131 return LayerTreeHostContextTest::CreateFakeOutputSurface(fallback); 1117 return LayerTreeHostContextTest::CreateFakeOutputSurface(fallback);
1132 } 1118 }
1133 1119
1134 virtual void DidCommitAndDrawFrame() override { 1120 void DidCommitAndDrawFrame() override {
1135 ASSERT_TRUE(layer_tree_host()->hud_layer()); 1121 ASSERT_TRUE(layer_tree_host()->hud_layer());
1136 // End the test once we know the 3nd frame drew. 1122 // End the test once we know the 3nd frame drew.
1137 if (layer_tree_host()->source_frame_number() < 5) { 1123 if (layer_tree_host()->source_frame_number() < 5) {
1138 layer_tree_host()->root_layer()->SetNeedsDisplay(); 1124 layer_tree_host()->root_layer()->SetNeedsDisplay();
1139 layer_tree_host()->SetNeedsCommit(); 1125 layer_tree_host()->SetNeedsCommit();
1140 } else { 1126 } else {
1141 EndTest(); 1127 EndTest();
1142 } 1128 }
1143 } 1129 }
1144 1130
1145 virtual void AfterTest() override { EXPECT_TRUE(lost_context_); } 1131 void AfterTest() override { EXPECT_TRUE(lost_context_); }
1146 1132
1147 private: 1133 private:
1148 FakeContentLayerClient client_; 1134 FakeContentLayerClient client_;
1149 bool lost_context_; 1135 bool lost_context_;
1150 1136
1151 FakeOutputSurfaceClient output_surface_client_; 1137 FakeOutputSurfaceClient output_surface_client_;
1152 scoped_ptr<FakeOutputSurface> child_output_surface_; 1138 scoped_ptr<FakeOutputSurface> child_output_surface_;
1153 scoped_ptr<SharedBitmapManager> shared_bitmap_manager_; 1139 scoped_ptr<SharedBitmapManager> shared_bitmap_manager_;
1154 scoped_ptr<ResourceProvider> child_resource_provider_; 1140 scoped_ptr<ResourceProvider> child_resource_provider_;
1155 1141
1156 scoped_refptr<DelegatedFrameResourceCollection> 1142 scoped_refptr<DelegatedFrameResourceCollection>
1157 delegated_resource_collection_; 1143 delegated_resource_collection_;
1158 scoped_refptr<DelegatedFrameProvider> delegated_frame_provider_; 1144 scoped_refptr<DelegatedFrameProvider> delegated_frame_provider_;
1159 1145
1160 scoped_refptr<VideoFrame> color_video_frame_; 1146 scoped_refptr<VideoFrame> color_video_frame_;
1161 scoped_refptr<VideoFrame> hw_video_frame_; 1147 scoped_refptr<VideoFrame> hw_video_frame_;
1162 scoped_refptr<VideoFrame> scaled_hw_video_frame_; 1148 scoped_refptr<VideoFrame> scaled_hw_video_frame_;
1163 1149
1164 FakeVideoFrameProvider color_frame_provider_; 1150 FakeVideoFrameProvider color_frame_provider_;
1165 FakeVideoFrameProvider hw_frame_provider_; 1151 FakeVideoFrameProvider hw_frame_provider_;
1166 FakeVideoFrameProvider scaled_hw_frame_provider_; 1152 FakeVideoFrameProvider scaled_hw_frame_provider_;
1167 }; 1153 };
1168 1154
1169 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestDontUseLostResources); 1155 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestDontUseLostResources);
1170 1156
1171 class ImplSidePaintingLayerTreeHostContextTest 1157 class ImplSidePaintingLayerTreeHostContextTest
1172 : public LayerTreeHostContextTest { 1158 : public LayerTreeHostContextTest {
1173 public: 1159 public:
1174 virtual void InitializeSettings(LayerTreeSettings* settings) override { 1160 void InitializeSettings(LayerTreeSettings* settings) override {
1175 settings->impl_side_painting = true; 1161 settings->impl_side_painting = true;
1176 } 1162 }
1177 }; 1163 };
1178 1164
1179 class LayerTreeHostContextTestImplSidePainting 1165 class LayerTreeHostContextTestImplSidePainting
1180 : public ImplSidePaintingLayerTreeHostContextTest { 1166 : public ImplSidePaintingLayerTreeHostContextTest {
1181 public: 1167 public:
1182 virtual void SetupTree() override { 1168 void SetupTree() override {
1183 scoped_refptr<Layer> root = Layer::Create(); 1169 scoped_refptr<Layer> root = Layer::Create();
1184 root->SetBounds(gfx::Size(10, 10)); 1170 root->SetBounds(gfx::Size(10, 10));
1185 root->SetIsDrawable(true); 1171 root->SetIsDrawable(true);
1186 1172
1187 scoped_refptr<PictureLayer> picture = PictureLayer::Create(&client_); 1173 scoped_refptr<PictureLayer> picture = PictureLayer::Create(&client_);
1188 picture->SetBounds(gfx::Size(10, 10)); 1174 picture->SetBounds(gfx::Size(10, 10));
1189 picture->SetIsDrawable(true); 1175 picture->SetIsDrawable(true);
1190 root->AddChild(picture); 1176 root->AddChild(picture);
1191 1177
1192 layer_tree_host()->SetRootLayer(root); 1178 layer_tree_host()->SetRootLayer(root);
1193 LayerTreeHostContextTest::SetupTree(); 1179 LayerTreeHostContextTest::SetupTree();
1194 } 1180 }
1195 1181
1196 virtual void BeginTest() override { 1182 void BeginTest() override {
1197 times_to_lose_during_commit_ = 1; 1183 times_to_lose_during_commit_ = 1;
1198 PostSetNeedsCommitToMainThread(); 1184 PostSetNeedsCommitToMainThread();
1199 } 1185 }
1200 1186
1201 virtual void AfterTest() override {} 1187 void AfterTest() override {}
1202 1188
1203 virtual void DidInitializeOutputSurface() override { EndTest(); } 1189 void DidInitializeOutputSurface() override { EndTest(); }
1204 1190
1205 private: 1191 private:
1206 FakeContentLayerClient client_; 1192 FakeContentLayerClient client_;
1207 }; 1193 };
1208 1194
1209 MULTI_THREAD_TEST_F(LayerTreeHostContextTestImplSidePainting); 1195 MULTI_THREAD_TEST_F(LayerTreeHostContextTestImplSidePainting);
1210 1196
1211 class ScrollbarLayerLostContext : public LayerTreeHostContextTest { 1197 class ScrollbarLayerLostContext : public LayerTreeHostContextTest {
1212 public: 1198 public:
1213 ScrollbarLayerLostContext() : commits_(0) {} 1199 ScrollbarLayerLostContext() : commits_(0) {}
1214 1200
1215 virtual void BeginTest() override { 1201 void BeginTest() override {
1216 scoped_refptr<Layer> scroll_layer = Layer::Create(); 1202 scoped_refptr<Layer> scroll_layer = Layer::Create();
1217 scrollbar_layer_ = 1203 scrollbar_layer_ =
1218 FakePaintedScrollbarLayer::Create(false, true, scroll_layer->id()); 1204 FakePaintedScrollbarLayer::Create(false, true, scroll_layer->id());
1219 scrollbar_layer_->SetBounds(gfx::Size(10, 100)); 1205 scrollbar_layer_->SetBounds(gfx::Size(10, 100));
1220 layer_tree_host()->root_layer()->AddChild(scrollbar_layer_); 1206 layer_tree_host()->root_layer()->AddChild(scrollbar_layer_);
1221 layer_tree_host()->root_layer()->AddChild(scroll_layer); 1207 layer_tree_host()->root_layer()->AddChild(scroll_layer);
1222 PostSetNeedsCommitToMainThread(); 1208 PostSetNeedsCommitToMainThread();
1223 } 1209 }
1224 1210
1225 virtual void AfterTest() override {} 1211 void AfterTest() override {}
1226 1212
1227 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { 1213 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
1228 LayerTreeHostContextTest::CommitCompleteOnThread(impl); 1214 LayerTreeHostContextTest::CommitCompleteOnThread(impl);
1229 1215
1230 ++commits_; 1216 ++commits_;
1231 switch (commits_) { 1217 switch (commits_) {
1232 case 1: 1218 case 1:
1233 // First (regular) update, we should upload 2 resources (thumb, and 1219 // First (regular) update, we should upload 2 resources (thumb, and
1234 // backtrack). 1220 // backtrack).
1235 EXPECT_EQ(1, scrollbar_layer_->update_count()); 1221 EXPECT_EQ(1, scrollbar_layer_->update_count());
1236 LoseContext(); 1222 LoseContext();
1237 break; 1223 break;
(...skipping 11 matching lines...) Expand all
1249 private: 1235 private:
1250 int commits_; 1236 int commits_;
1251 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer_; 1237 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer_;
1252 }; 1238 };
1253 1239
1254 SINGLE_AND_MULTI_THREAD_TEST_F(ScrollbarLayerLostContext); 1240 SINGLE_AND_MULTI_THREAD_TEST_F(ScrollbarLayerLostContext);
1255 1241
1256 class UIResourceLostTest : public LayerTreeHostContextTest { 1242 class UIResourceLostTest : public LayerTreeHostContextTest {
1257 public: 1243 public:
1258 UIResourceLostTest() : time_step_(0) {} 1244 UIResourceLostTest() : time_step_(0) {}
1259 virtual void InitializeSettings(LayerTreeSettings* settings) override { 1245 void InitializeSettings(LayerTreeSettings* settings) override {
1260 settings->texture_id_allocation_chunk_size = 1; 1246 settings->texture_id_allocation_chunk_size = 1;
1261 } 1247 }
1262 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); } 1248 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
1263 virtual void AfterTest() override {} 1249 void AfterTest() override {}
1264 1250
1265 // This is called on the main thread after each commit and 1251 // This is called on the main thread after each commit and
1266 // DidActivateTreeOnThread, with the value of time_step_ at the time 1252 // DidActivateTreeOnThread, with the value of time_step_ at the time
1267 // of the call to DidActivateTreeOnThread. Similar tests will do 1253 // of the call to DidActivateTreeOnThread. Similar tests will do
1268 // work on the main thread in DidCommit but that is unsuitable because 1254 // work on the main thread in DidCommit but that is unsuitable because
1269 // the main thread work for these tests must happen after 1255 // the main thread work for these tests must happen after
1270 // DidActivateTreeOnThread, which happens after DidCommit with impl-side 1256 // DidActivateTreeOnThread, which happens after DidCommit with impl-side
1271 // painting. 1257 // painting.
1272 virtual void StepCompleteOnMainThread(int time_step) = 0; 1258 virtual void StepCompleteOnMainThread(int time_step) = 0;
1273 1259
(...skipping 26 matching lines...) Expand all
1300 StepCompleteOnMainThread(step); 1286 StepCompleteOnMainThread(step);
1301 } 1287 }
1302 }; 1288 };
1303 1289
1304 class UIResourceLostTestSimple : public UIResourceLostTest { 1290 class UIResourceLostTestSimple : public UIResourceLostTest {
1305 public: 1291 public:
1306 // This is called when the commit is complete and the new layer tree has been 1292 // This is called when the commit is complete and the new layer tree has been
1307 // activated. 1293 // activated.
1308 virtual void StepCompleteOnImplThread(LayerTreeHostImpl* impl) = 0; 1294 virtual void StepCompleteOnImplThread(LayerTreeHostImpl* impl) = 0;
1309 1295
1310 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { 1296 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
1311 if (!layer_tree_host()->settings().impl_side_painting) { 1297 if (!layer_tree_host()->settings().impl_side_painting) {
1312 StepCompleteOnImplThread(impl); 1298 StepCompleteOnImplThread(impl);
1313 PostStepCompleteToMainThread(); 1299 PostStepCompleteToMainThread();
1314 ++time_step_; 1300 ++time_step_;
1315 } 1301 }
1316 } 1302 }
1317 1303
1318 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { 1304 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override {
1319 if (layer_tree_host()->settings().impl_side_painting) { 1305 if (layer_tree_host()->settings().impl_side_painting) {
1320 StepCompleteOnImplThread(impl); 1306 StepCompleteOnImplThread(impl);
1321 PostStepCompleteToMainThread(); 1307 PostStepCompleteToMainThread();
1322 ++time_step_; 1308 ++time_step_;
1323 } 1309 }
1324 } 1310 }
1325 }; 1311 };
1326 1312
1327 // Losing context after an UI resource has been created. 1313 // Losing context after an UI resource has been created.
1328 class UIResourceLostAfterCommit : public UIResourceLostTestSimple { 1314 class UIResourceLostAfterCommit : public UIResourceLostTestSimple {
1329 public: 1315 public:
1330 virtual void StepCompleteOnMainThread(int step) override { 1316 void StepCompleteOnMainThread(int step) override {
1331 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); 1317 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread());
1332 switch (step) { 1318 switch (step) {
1333 case 0: 1319 case 0:
1334 ui_resource_ = FakeScopedUIResource::Create(layer_tree_host()); 1320 ui_resource_ = FakeScopedUIResource::Create(layer_tree_host());
1335 // Expects a valid UIResourceId. 1321 // Expects a valid UIResourceId.
1336 EXPECT_NE(0, ui_resource_->id()); 1322 EXPECT_NE(0, ui_resource_->id());
1337 PostSetNeedsCommitToMainThread(); 1323 PostSetNeedsCommitToMainThread();
1338 break; 1324 break;
1339 case 4: 1325 case 4:
1340 // Release resource before ending the test. 1326 // Release resource before ending the test.
1341 ui_resource_ = nullptr; 1327 ui_resource_ = nullptr;
1342 EndTest(); 1328 EndTest();
1343 break; 1329 break;
1344 case 5: 1330 case 5:
1345 NOTREACHED(); 1331 NOTREACHED();
1346 break; 1332 break;
1347 } 1333 }
1348 } 1334 }
1349 1335
1350 virtual void StepCompleteOnImplThread(LayerTreeHostImpl* impl) override { 1336 void StepCompleteOnImplThread(LayerTreeHostImpl* impl) override {
1351 LayerTreeHostContextTest::CommitCompleteOnThread(impl); 1337 LayerTreeHostContextTest::CommitCompleteOnThread(impl);
1352 switch (time_step_) { 1338 switch (time_step_) {
1353 case 1: 1339 case 1:
1354 // The resource should have been created on LTHI after the commit. 1340 // The resource should have been created on LTHI after the commit.
1355 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id())); 1341 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id()));
1356 PostSetNeedsCommitToMainThread(); 1342 PostSetNeedsCommitToMainThread();
1357 break; 1343 break;
1358 case 2: 1344 case 2:
1359 LoseContext(); 1345 LoseContext();
1360 break; 1346 break;
(...skipping 18 matching lines...) Expand all
1379 // created. 1365 // created.
1380 // 2. Delete an exisiting resource (test_id0_) -> create a second resource 1366 // 2. Delete an exisiting resource (test_id0_) -> create a second resource
1381 // (test_id1_) -> Context Lost => Expect the test_id0_ to be removed and 1367 // (test_id1_) -> Context Lost => Expect the test_id0_ to be removed and
1382 // test_id1_ to have been created. 1368 // test_id1_ to have been created.
1383 // 3. Create one resource -> Delete that same resource -> Context Lost => Expect 1369 // 3. Create one resource -> Delete that same resource -> Context Lost => Expect
1384 // the resource to not exist in the manager. 1370 // the resource to not exist in the manager.
1385 class UIResourceLostBeforeCommit : public UIResourceLostTestSimple { 1371 class UIResourceLostBeforeCommit : public UIResourceLostTestSimple {
1386 public: 1372 public:
1387 UIResourceLostBeforeCommit() : test_id0_(0), test_id1_(0) {} 1373 UIResourceLostBeforeCommit() : test_id0_(0), test_id1_(0) {}
1388 1374
1389 virtual void StepCompleteOnMainThread(int step) override { 1375 void StepCompleteOnMainThread(int step) override {
1390 switch (step) { 1376 switch (step) {
1391 case 0: 1377 case 0:
1392 ui_resource_ = FakeScopedUIResource::Create(layer_tree_host()); 1378 ui_resource_ = FakeScopedUIResource::Create(layer_tree_host());
1393 // Lose the context on the impl thread before the commit. 1379 // Lose the context on the impl thread before the commit.
1394 PostLoseContextToImplThread(); 1380 PostLoseContextToImplThread();
1395 break; 1381 break;
1396 case 2: 1382 case 2:
1397 // Sequence 2: 1383 // Sequence 2:
1398 // Currently one resource has been created. 1384 // Currently one resource has been created.
1399 test_id0_ = ui_resource_->id(); 1385 test_id0_ = ui_resource_->id();
(...skipping 29 matching lines...) Expand all
1429 // Release resource before ending the test. 1415 // Release resource before ending the test.
1430 ui_resource_ = nullptr; 1416 ui_resource_ = nullptr;
1431 EndTest(); 1417 EndTest();
1432 break; 1418 break;
1433 case 6: 1419 case 6:
1434 NOTREACHED(); 1420 NOTREACHED();
1435 break; 1421 break;
1436 } 1422 }
1437 } 1423 }
1438 1424
1439 virtual void StepCompleteOnImplThread(LayerTreeHostImpl* impl) override { 1425 void StepCompleteOnImplThread(LayerTreeHostImpl* impl) override {
1440 LayerTreeHostContextTest::CommitCompleteOnThread(impl); 1426 LayerTreeHostContextTest::CommitCompleteOnThread(impl);
1441 switch (time_step_) { 1427 switch (time_step_) {
1442 case 1: 1428 case 1:
1443 // Sequence 1 (continued): 1429 // Sequence 1 (continued):
1444 // The first context lost happens before the resources were created, 1430 // The first context lost happens before the resources were created,
1445 // and because it resulted in no resources being destroyed, it does not 1431 // and because it resulted in no resources being destroyed, it does not
1446 // trigger resource re-creation. 1432 // trigger resource re-creation.
1447 EXPECT_EQ(1, ui_resource_->resource_create_count); 1433 EXPECT_EQ(1, ui_resource_->resource_create_count);
1448 EXPECT_EQ(0, ui_resource_->lost_resource_count); 1434 EXPECT_EQ(0, ui_resource_->lost_resource_count);
1449 // Resource Id on the impl-side has been created. 1435 // Resource Id on the impl-side has been created.
(...skipping 25 matching lines...) Expand all
1475 private: 1461 private:
1476 UIResourceId test_id0_; 1462 UIResourceId test_id0_;
1477 UIResourceId test_id1_; 1463 UIResourceId test_id1_;
1478 }; 1464 };
1479 1465
1480 SINGLE_AND_MULTI_THREAD_TEST_F(UIResourceLostBeforeCommit); 1466 SINGLE_AND_MULTI_THREAD_TEST_F(UIResourceLostBeforeCommit);
1481 1467
1482 // Losing UI resource before the pending trees is activated but after the 1468 // Losing UI resource before the pending trees is activated but after the
1483 // commit. Impl-side-painting only. 1469 // commit. Impl-side-painting only.
1484 class UIResourceLostBeforeActivateTree : public UIResourceLostTest { 1470 class UIResourceLostBeforeActivateTree : public UIResourceLostTest {
1485 virtual void StepCompleteOnMainThread(int step) override { 1471 void StepCompleteOnMainThread(int step) override {
1486 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); 1472 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread());
1487 switch (step) { 1473 switch (step) {
1488 case 0: 1474 case 0:
1489 ui_resource_ = FakeScopedUIResource::Create(layer_tree_host()); 1475 ui_resource_ = FakeScopedUIResource::Create(layer_tree_host());
1490 PostSetNeedsCommitToMainThread(); 1476 PostSetNeedsCommitToMainThread();
1491 break; 1477 break;
1492 case 3: 1478 case 3:
1493 test_id_ = ui_resource_->id(); 1479 test_id_ = ui_resource_->id();
1494 ui_resource_ = nullptr; 1480 ui_resource_ = nullptr;
1495 PostSetNeedsCommitToMainThread(); 1481 PostSetNeedsCommitToMainThread();
1496 break; 1482 break;
1497 case 5: 1483 case 5:
1498 // Release resource before ending the test. 1484 // Release resource before ending the test.
1499 ui_resource_ = nullptr; 1485 ui_resource_ = nullptr;
1500 EndTest(); 1486 EndTest();
1501 break; 1487 break;
1502 case 6: 1488 case 6:
1503 // Make sure no extra commits happened. 1489 // Make sure no extra commits happened.
1504 NOTREACHED(); 1490 NOTREACHED();
1505 } 1491 }
1506 } 1492 }
1507 1493
1508 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { 1494 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
1509 LayerTreeHostContextTest::CommitCompleteOnThread(impl); 1495 LayerTreeHostContextTest::CommitCompleteOnThread(impl);
1510 switch (time_step_) { 1496 switch (time_step_) {
1511 case 2: 1497 case 2:
1512 PostSetNeedsCommitToMainThread(); 1498 PostSetNeedsCommitToMainThread();
1513 break; 1499 break;
1514 case 4: 1500 case 4:
1515 PostSetNeedsCommitToMainThread(); 1501 PostSetNeedsCommitToMainThread();
1516 break; 1502 break;
1517 } 1503 }
1518 } 1504 }
1519 1505
1520 virtual void WillActivateTreeOnThread(LayerTreeHostImpl* impl) override { 1506 void WillActivateTreeOnThread(LayerTreeHostImpl* impl) override {
1521 switch (time_step_) { 1507 switch (time_step_) {
1522 case 1: 1508 case 1:
1523 // The resource creation callback has been called. 1509 // The resource creation callback has been called.
1524 EXPECT_EQ(1, ui_resource_->resource_create_count); 1510 EXPECT_EQ(1, ui_resource_->resource_create_count);
1525 // The resource is not yet lost (sanity check). 1511 // The resource is not yet lost (sanity check).
1526 EXPECT_EQ(0, ui_resource_->lost_resource_count); 1512 EXPECT_EQ(0, ui_resource_->lost_resource_count);
1527 // The resource should not have been created yet on the impl-side. 1513 // The resource should not have been created yet on the impl-side.
1528 EXPECT_EQ(0u, impl->ResourceIdForUIResource(ui_resource_->id())); 1514 EXPECT_EQ(0u, impl->ResourceIdForUIResource(ui_resource_->id()));
1529 LoseContext(); 1515 LoseContext();
1530 break; 1516 break;
1531 case 3: 1517 case 3:
1532 LoseContext(); 1518 LoseContext();
1533 break; 1519 break;
1534 } 1520 }
1535 } 1521 }
1536 1522
1537 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { 1523 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override {
1538 LayerTreeHostContextTest::DidActivateTreeOnThread(impl); 1524 LayerTreeHostContextTest::DidActivateTreeOnThread(impl);
1539 switch (time_step_) { 1525 switch (time_step_) {
1540 case 1: 1526 case 1:
1541 // The pending requests on the impl-side should have been processed. 1527 // The pending requests on the impl-side should have been processed.
1542 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id())); 1528 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id()));
1543 break; 1529 break;
1544 case 2: 1530 case 2:
1545 // The "lost resource" callback should have been called once. 1531 // The "lost resource" callback should have been called once.
1546 EXPECT_EQ(1, ui_resource_->lost_resource_count); 1532 EXPECT_EQ(1, ui_resource_->lost_resource_count);
1547 break; 1533 break;
(...skipping 18 matching lines...) Expand all
1566 } 1552 }
1567 1553
1568 TEST_F(UIResourceLostBeforeActivateTree, 1554 TEST_F(UIResourceLostBeforeActivateTree,
1569 RunMultiThread_DelegatingRenderer_ImplSidePaint) { 1555 RunMultiThread_DelegatingRenderer_ImplSidePaint) {
1570 RunTest(true, true, true); 1556 RunTest(true, true, true);
1571 } 1557 }
1572 1558
1573 // Resources evicted explicitly and by visibility changes. 1559 // Resources evicted explicitly and by visibility changes.
1574 class UIResourceLostEviction : public UIResourceLostTestSimple { 1560 class UIResourceLostEviction : public UIResourceLostTestSimple {
1575 public: 1561 public:
1576 virtual void StepCompleteOnMainThread(int step) override { 1562 void StepCompleteOnMainThread(int step) override {
1577 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); 1563 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread());
1578 switch (step) { 1564 switch (step) {
1579 case 0: 1565 case 0:
1580 ui_resource_ = FakeScopedUIResource::Create(layer_tree_host()); 1566 ui_resource_ = FakeScopedUIResource::Create(layer_tree_host());
1581 EXPECT_NE(0, ui_resource_->id()); 1567 EXPECT_NE(0, ui_resource_->id());
1582 PostSetNeedsCommitToMainThread(); 1568 PostSetNeedsCommitToMainThread();
1583 break; 1569 break;
1584 case 2: 1570 case 2:
1585 // Make the tree not visible. 1571 // Make the tree not visible.
1586 PostSetVisibleToMainThread(false); 1572 PostSetVisibleToMainThread(false);
1587 break; 1573 break;
1588 case 3: 1574 case 3:
1589 // Release resource before ending the test. 1575 // Release resource before ending the test.
1590 ui_resource_ = nullptr; 1576 ui_resource_ = nullptr;
1591 EndTest(); 1577 EndTest();
1592 break; 1578 break;
1593 case 4: 1579 case 4:
1594 NOTREACHED(); 1580 NOTREACHED();
1595 } 1581 }
1596 } 1582 }
1597 1583
1598 virtual void DidSetVisibleOnImplTree(LayerTreeHostImpl* impl, 1584 void DidSetVisibleOnImplTree(LayerTreeHostImpl* impl, bool visible) override {
1599 bool visible) override {
1600 TestWebGraphicsContext3D* context = TestContext(); 1585 TestWebGraphicsContext3D* context = TestContext();
1601 if (!visible) { 1586 if (!visible) {
1602 // All resources should have been evicted. 1587 // All resources should have been evicted.
1603 ASSERT_EQ(0u, context->NumTextures()); 1588 ASSERT_EQ(0u, context->NumTextures());
1604 EXPECT_EQ(0u, impl->ResourceIdForUIResource(ui_resource_->id())); 1589 EXPECT_EQ(0u, impl->ResourceIdForUIResource(ui_resource_->id()));
1605 EXPECT_EQ(2, ui_resource_->resource_create_count); 1590 EXPECT_EQ(2, ui_resource_->resource_create_count);
1606 EXPECT_EQ(1, ui_resource_->lost_resource_count); 1591 EXPECT_EQ(1, ui_resource_->lost_resource_count);
1607 // Drawing is disabled both because of the evicted resources and 1592 // Drawing is disabled both because of the evicted resources and
1608 // because the renderer is not visible. 1593 // because the renderer is not visible.
1609 EXPECT_FALSE(impl->CanDraw()); 1594 EXPECT_FALSE(impl->CanDraw());
1610 // Make the renderer visible again. 1595 // Make the renderer visible again.
1611 PostSetVisibleToMainThread(true); 1596 PostSetVisibleToMainThread(true);
1612 } 1597 }
1613 } 1598 }
1614 1599
1615 virtual void StepCompleteOnImplThread(LayerTreeHostImpl* impl) override { 1600 void StepCompleteOnImplThread(LayerTreeHostImpl* impl) override {
1616 TestWebGraphicsContext3D* context = TestContext(); 1601 TestWebGraphicsContext3D* context = TestContext();
1617 LayerTreeHostContextTest::CommitCompleteOnThread(impl); 1602 LayerTreeHostContextTest::CommitCompleteOnThread(impl);
1618 switch (time_step_) { 1603 switch (time_step_) {
1619 case 1: 1604 case 1:
1620 // The resource should have been created on LTHI after the commit. 1605 // The resource should have been created on LTHI after the commit.
1621 ASSERT_EQ(1u, context->NumTextures()); 1606 ASSERT_EQ(1u, context->NumTextures());
1622 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id())); 1607 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id()));
1623 EXPECT_EQ(1, ui_resource_->resource_create_count); 1608 EXPECT_EQ(1, ui_resource_->resource_create_count);
1624 EXPECT_EQ(0, ui_resource_->lost_resource_count); 1609 EXPECT_EQ(0, ui_resource_->lost_resource_count);
1625 EXPECT_TRUE(impl->CanDraw()); 1610 EXPECT_TRUE(impl->CanDraw());
(...skipping 27 matching lines...) Expand all
1653 }; 1638 };
1654 1639
1655 SINGLE_AND_MULTI_THREAD_TEST_F(UIResourceLostEviction); 1640 SINGLE_AND_MULTI_THREAD_TEST_F(UIResourceLostEviction);
1656 1641
1657 class LayerTreeHostContextTestSurfaceCreateCallback 1642 class LayerTreeHostContextTestSurfaceCreateCallback
1658 : public LayerTreeHostContextTest { 1643 : public LayerTreeHostContextTest {
1659 public: 1644 public:
1660 LayerTreeHostContextTestSurfaceCreateCallback() 1645 LayerTreeHostContextTestSurfaceCreateCallback()
1661 : LayerTreeHostContextTest() {} 1646 : LayerTreeHostContextTest() {}
1662 1647
1663 virtual void SetupTree() override { 1648 void SetupTree() override {
1664 if (layer_tree_host()->settings().impl_side_painting) { 1649 if (layer_tree_host()->settings().impl_side_painting) {
1665 picture_layer_ = FakePictureLayer::Create(&client_); 1650 picture_layer_ = FakePictureLayer::Create(&client_);
1666 picture_layer_->SetBounds(gfx::Size(10, 20)); 1651 picture_layer_->SetBounds(gfx::Size(10, 20));
1667 layer_tree_host()->SetRootLayer(picture_layer_); 1652 layer_tree_host()->SetRootLayer(picture_layer_);
1668 } else { 1653 } else {
1669 content_layer_ = FakeContentLayer::Create(&client_); 1654 content_layer_ = FakeContentLayer::Create(&client_);
1670 content_layer_->SetBounds(gfx::Size(10, 20)); 1655 content_layer_->SetBounds(gfx::Size(10, 20));
1671 layer_tree_host()->SetRootLayer(content_layer_); 1656 layer_tree_host()->SetRootLayer(content_layer_);
1672 } 1657 }
1673 1658
1674 LayerTreeHostContextTest::SetupTree(); 1659 LayerTreeHostContextTest::SetupTree();
1675 } 1660 }
1676 1661
1677 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); } 1662 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
1678 1663
1679 virtual void DidCommit() override { 1664 void DidCommit() override {
1680 switch (layer_tree_host()->source_frame_number()) { 1665 switch (layer_tree_host()->source_frame_number()) {
1681 case 1: 1666 case 1:
1682 if (layer_tree_host()->settings().impl_side_painting) 1667 if (layer_tree_host()->settings().impl_side_painting)
1683 EXPECT_EQ(1u, picture_layer_->output_surface_created_count()); 1668 EXPECT_EQ(1u, picture_layer_->output_surface_created_count());
1684 else 1669 else
1685 EXPECT_EQ(1u, content_layer_->output_surface_created_count()); 1670 EXPECT_EQ(1u, content_layer_->output_surface_created_count());
1686 layer_tree_host()->SetNeedsCommit(); 1671 layer_tree_host()->SetNeedsCommit();
1687 break; 1672 break;
1688 case 2: 1673 case 2:
1689 if (layer_tree_host()->settings().impl_side_painting) 1674 if (layer_tree_host()->settings().impl_side_painting)
(...skipping 11 matching lines...) Expand all
1701 case 4: 1686 case 4:
1702 if (layer_tree_host()->settings().impl_side_painting) 1687 if (layer_tree_host()->settings().impl_side_painting)
1703 EXPECT_EQ(2u, picture_layer_->output_surface_created_count()); 1688 EXPECT_EQ(2u, picture_layer_->output_surface_created_count());
1704 else 1689 else
1705 EXPECT_EQ(2u, content_layer_->output_surface_created_count()); 1690 EXPECT_EQ(2u, content_layer_->output_surface_created_count());
1706 layer_tree_host()->SetNeedsCommit(); 1691 layer_tree_host()->SetNeedsCommit();
1707 break; 1692 break;
1708 } 1693 }
1709 } 1694 }
1710 1695
1711 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { 1696 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
1712 LayerTreeHostContextTest::CommitCompleteOnThread(impl); 1697 LayerTreeHostContextTest::CommitCompleteOnThread(impl);
1713 switch (LastCommittedSourceFrameNumber(impl)) { 1698 switch (LastCommittedSourceFrameNumber(impl)) {
1714 case 0: 1699 case 0:
1715 break; 1700 break;
1716 case 1: 1701 case 1:
1717 break; 1702 break;
1718 case 2: 1703 case 2:
1719 LoseContext(); 1704 LoseContext();
1720 break; 1705 break;
1721 case 3: 1706 case 3:
1722 EndTest(); 1707 EndTest();
1723 break; 1708 break;
1724 } 1709 }
1725 } 1710 }
1726 1711
1727 virtual void AfterTest() override {} 1712 void AfterTest() override {}
1728 1713
1729 protected: 1714 protected:
1730 FakeContentLayerClient client_; 1715 FakeContentLayerClient client_;
1731 scoped_refptr<FakePictureLayer> picture_layer_; 1716 scoped_refptr<FakePictureLayer> picture_layer_;
1732 scoped_refptr<FakeContentLayer> content_layer_; 1717 scoped_refptr<FakeContentLayer> content_layer_;
1733 }; 1718 };
1734 1719
1735 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestSurfaceCreateCallback); 1720 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestSurfaceCreateCallback);
1736 1721
1737 class LayerTreeHostContextTestLoseAfterSendingBeginMainFrame 1722 class LayerTreeHostContextTestLoseAfterSendingBeginMainFrame
1738 : public LayerTreeHostContextTest { 1723 : public LayerTreeHostContextTest {
1739 protected: 1724 protected:
1740 virtual void BeginTest() override { 1725 void BeginTest() override {
1741 deferred_ = false; 1726 deferred_ = false;
1742 PostSetNeedsCommitToMainThread(); 1727 PostSetNeedsCommitToMainThread();
1743 } 1728 }
1744 1729
1745 virtual void ScheduledActionWillSendBeginMainFrame() override { 1730 void ScheduledActionWillSendBeginMainFrame() override {
1746 if (deferred_) 1731 if (deferred_)
1747 return; 1732 return;
1748 deferred_ = true; 1733 deferred_ = true;
1749 1734
1750 // Defer commits before the BeginFrame arrives, causing it to be delayed. 1735 // Defer commits before the BeginFrame arrives, causing it to be delayed.
1751 MainThreadTaskRunner()->PostTask( 1736 MainThreadTaskRunner()->PostTask(
1752 FROM_HERE, 1737 FROM_HERE,
1753 base::Bind(&LayerTreeHostContextTestLoseAfterSendingBeginMainFrame:: 1738 base::Bind(&LayerTreeHostContextTestLoseAfterSendingBeginMainFrame::
1754 DeferCommitsOnMainThread, 1739 DeferCommitsOnMainThread,
1755 base::Unretained(this), 1740 base::Unretained(this),
(...skipping 15 matching lines...) Expand all
1771 base::Bind(&LayerTreeHostContextTestLoseAfterSendingBeginMainFrame:: 1756 base::Bind(&LayerTreeHostContextTestLoseAfterSendingBeginMainFrame::
1772 DeferCommitsOnMainThread, 1757 DeferCommitsOnMainThread,
1773 base::Unretained(this), 1758 base::Unretained(this),
1774 false)); 1759 false));
1775 } 1760 }
1776 1761
1777 void DeferCommitsOnMainThread(bool defer_commits) { 1762 void DeferCommitsOnMainThread(bool defer_commits) {
1778 layer_tree_host()->SetDeferCommits(defer_commits); 1763 layer_tree_host()->SetDeferCommits(defer_commits);
1779 } 1764 }
1780 1765
1781 virtual void WillBeginMainFrame() override { 1766 void WillBeginMainFrame() override {
1782 // Don't begin a frame with a lost surface. 1767 // Don't begin a frame with a lost surface.
1783 EXPECT_FALSE(layer_tree_host()->output_surface_lost()); 1768 EXPECT_FALSE(layer_tree_host()->output_surface_lost());
1784 } 1769 }
1785 1770
1786 virtual void DidCommitAndDrawFrame() override { EndTest(); } 1771 void DidCommitAndDrawFrame() override { EndTest(); }
1787 1772
1788 virtual void AfterTest() override {} 1773 void AfterTest() override {}
1789 1774
1790 bool deferred_; 1775 bool deferred_;
1791 }; 1776 };
1792 1777
1793 SINGLE_AND_MULTI_THREAD_TEST_F( 1778 SINGLE_AND_MULTI_THREAD_TEST_F(
1794 LayerTreeHostContextTestLoseAfterSendingBeginMainFrame); 1779 LayerTreeHostContextTestLoseAfterSendingBeginMainFrame);
1795 1780
1796 } // namespace 1781 } // namespace
1797 } // namespace cc 1782 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_unittest_animation.cc ('k') | cc/trees/layer_tree_host_unittest_copyrequest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698