OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/surfaces/display.h" | 5 #include "cc/surfaces/display.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/test/null_task_runner.h" | 9 #include "base/test/null_task_runner.h" |
10 #include "cc/output/compositor_frame.h" | 10 #include "cc/output/compositor_frame.h" |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 class DisplayTest : public testing::Test { | 99 class DisplayTest : public testing::Test { |
100 public: | 100 public: |
101 DisplayTest() | 101 DisplayTest() |
102 : factory_(kArbitraryFrameSinkId, &manager_, &surface_factory_client_), | 102 : factory_(kArbitraryFrameSinkId, &manager_, &surface_factory_client_), |
103 task_runner_(new base::NullTaskRunner) { | 103 task_runner_(new base::NullTaskRunner) { |
104 manager_.RegisterFrameSinkId(kArbitraryFrameSinkId); | 104 manager_.RegisterFrameSinkId(kArbitraryFrameSinkId); |
105 } | 105 } |
106 | 106 |
107 ~DisplayTest() override { | 107 ~DisplayTest() override { |
108 manager_.InvalidateFrameSinkId(kArbitraryFrameSinkId); | 108 manager_.InvalidateFrameSinkId(kArbitraryFrameSinkId); |
| 109 factory_.EvictSurface(); |
109 } | 110 } |
110 | 111 |
111 void SetUpDisplay(const RendererSettings& settings, | 112 void SetUpDisplay(const RendererSettings& settings, |
112 std::unique_ptr<TestWebGraphicsContext3D> context) { | 113 std::unique_ptr<TestWebGraphicsContext3D> context) { |
113 std::unique_ptr<BeginFrameSource> begin_frame_source( | 114 std::unique_ptr<BeginFrameSource> begin_frame_source( |
114 new StubBeginFrameSource); | 115 new StubBeginFrameSource); |
115 | 116 |
116 std::unique_ptr<FakeOutputSurface> output_surface; | 117 std::unique_ptr<FakeOutputSurface> output_surface; |
117 if (context) { | 118 if (context) { |
118 auto provider = TestContextProvider::Create(std::move(context)); | 119 auto provider = TestContextProvider::Create(std::move(context)); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 EXPECT_FALSE(scheduler_->damaged); | 190 EXPECT_FALSE(scheduler_->damaged); |
190 EXPECT_FALSE(scheduler_->display_resized_); | 191 EXPECT_FALSE(scheduler_->display_resized_); |
191 EXPECT_TRUE(scheduler_->has_new_root_surface); | 192 EXPECT_TRUE(scheduler_->has_new_root_surface); |
192 | 193 |
193 scheduler_->ResetDamageForTest(); | 194 scheduler_->ResetDamageForTest(); |
194 display_->Resize(gfx::Size(100, 100)); | 195 display_->Resize(gfx::Size(100, 100)); |
195 EXPECT_FALSE(scheduler_->damaged); | 196 EXPECT_FALSE(scheduler_->damaged); |
196 EXPECT_TRUE(scheduler_->display_resized_); | 197 EXPECT_TRUE(scheduler_->display_resized_); |
197 EXPECT_FALSE(scheduler_->has_new_root_surface); | 198 EXPECT_FALSE(scheduler_->has_new_root_surface); |
198 | 199 |
199 factory_.Create(local_frame_id); | |
200 | |
201 // First draw from surface should have full damage. | 200 // First draw from surface should have full damage. |
202 RenderPassList pass_list; | 201 RenderPassList pass_list; |
203 std::unique_ptr<RenderPass> pass = RenderPass::Create(); | 202 std::unique_ptr<RenderPass> pass = RenderPass::Create(); |
204 pass->output_rect = gfx::Rect(0, 0, 100, 100); | 203 pass->output_rect = gfx::Rect(0, 0, 100, 100); |
205 pass->damage_rect = gfx::Rect(10, 10, 1, 1); | 204 pass->damage_rect = gfx::Rect(10, 10, 1, 1); |
206 pass->id = RenderPassId(1, 1); | 205 pass->id = RenderPassId(1, 1); |
207 pass_list.push_back(std::move(pass)); | 206 pass_list.push_back(std::move(pass)); |
208 | 207 |
209 scheduler_->ResetDamageForTest(); | 208 scheduler_->ResetDamageForTest(); |
210 SubmitCompositorFrame(&pass_list, local_frame_id); | 209 SubmitCompositorFrame(&pass_list, local_frame_id); |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 scheduler_->swapped = false; | 406 scheduler_->swapped = false; |
408 display_->DrawAndSwap(); | 407 display_->DrawAndSwap(); |
409 EXPECT_TRUE(scheduler_->swapped); | 408 EXPECT_TRUE(scheduler_->swapped); |
410 EXPECT_EQ(6u, output_surface_->num_sent_frames()); | 409 EXPECT_EQ(6u, output_surface_->num_sent_frames()); |
411 EXPECT_EQ(gfx::Size(100, 100), | 410 EXPECT_EQ(gfx::Size(100, 100), |
412 software_output_device_->viewport_pixel_size()); | 411 software_output_device_->viewport_pixel_size()); |
413 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), | 412 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), |
414 software_output_device_->damage_rect()); | 413 software_output_device_->damage_rect()); |
415 EXPECT_EQ(0u, output_surface_->last_sent_frame()->latency_info.size()); | 414 EXPECT_EQ(0u, output_surface_->last_sent_frame()->latency_info.size()); |
416 } | 415 } |
417 | |
418 factory_.Destroy(local_frame_id); | |
419 } | 416 } |
420 | 417 |
421 class MockedContext : public TestWebGraphicsContext3D { | 418 class MockedContext : public TestWebGraphicsContext3D { |
422 public: | 419 public: |
423 MOCK_METHOD0(shallowFinishCHROMIUM, void()); | 420 MOCK_METHOD0(shallowFinishCHROMIUM, void()); |
424 }; | 421 }; |
425 | 422 |
426 TEST_F(DisplayTest, Finish) { | 423 TEST_F(DisplayTest, Finish) { |
427 LocalFrameId local_frame_id(id_allocator_.GenerateId()); | 424 LocalFrameId local_frame_id(id_allocator_.GenerateId()); |
428 | 425 |
429 RendererSettings settings; | 426 RendererSettings settings; |
430 settings.partial_swap_enabled = true; | 427 settings.partial_swap_enabled = true; |
431 settings.finish_rendering_on_resize = true; | 428 settings.finish_rendering_on_resize = true; |
432 | 429 |
433 std::unique_ptr<MockedContext> context(new MockedContext()); | 430 std::unique_ptr<MockedContext> context(new MockedContext()); |
434 MockedContext* context_ptr = context.get(); | 431 MockedContext* context_ptr = context.get(); |
435 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM()).Times(0); | 432 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM()).Times(0); |
436 | 433 |
437 SetUpDisplay(settings, std::move(context)); | 434 SetUpDisplay(settings, std::move(context)); |
438 | 435 |
439 StubDisplayClient client; | 436 StubDisplayClient client; |
440 display_->Initialize(&client, &manager_); | 437 display_->Initialize(&client, &manager_); |
441 | 438 |
442 display_->SetLocalFrameId(local_frame_id, 1.f); | 439 display_->SetLocalFrameId(local_frame_id, 1.f); |
443 | 440 |
444 display_->Resize(gfx::Size(100, 100)); | 441 display_->Resize(gfx::Size(100, 100)); |
445 factory_.Create(local_frame_id); | |
446 | 442 |
447 { | 443 { |
448 RenderPassList pass_list; | 444 RenderPassList pass_list; |
449 std::unique_ptr<RenderPass> pass = RenderPass::Create(); | 445 std::unique_ptr<RenderPass> pass = RenderPass::Create(); |
450 pass->output_rect = gfx::Rect(0, 0, 100, 100); | 446 pass->output_rect = gfx::Rect(0, 0, 100, 100); |
451 pass->damage_rect = gfx::Rect(10, 10, 1, 1); | 447 pass->damage_rect = gfx::Rect(10, 10, 1, 1); |
452 pass->id = RenderPassId(1, 1); | 448 pass->id = RenderPassId(1, 1); |
453 pass_list.push_back(std::move(pass)); | 449 pass_list.push_back(std::move(pass)); |
454 | 450 |
455 SubmitCompositorFrame(&pass_list, local_frame_id); | 451 SubmitCompositorFrame(&pass_list, local_frame_id); |
(...skipping 25 matching lines...) Expand all Loading... |
481 SubmitCompositorFrame(&pass_list, local_frame_id); | 477 SubmitCompositorFrame(&pass_list, local_frame_id); |
482 } | 478 } |
483 | 479 |
484 display_->DrawAndSwap(); | 480 display_->DrawAndSwap(); |
485 | 481 |
486 testing::Mock::VerifyAndClearExpectations(context_ptr); | 482 testing::Mock::VerifyAndClearExpectations(context_ptr); |
487 | 483 |
488 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM()); | 484 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM()); |
489 display_->Resize(gfx::Size(250, 250)); | 485 display_->Resize(gfx::Size(250, 250)); |
490 testing::Mock::VerifyAndClearExpectations(context_ptr); | 486 testing::Mock::VerifyAndClearExpectations(context_ptr); |
491 | |
492 factory_.Destroy(local_frame_id); | |
493 } | 487 } |
494 | 488 |
495 class CountLossDisplayClient : public StubDisplayClient { | 489 class CountLossDisplayClient : public StubDisplayClient { |
496 public: | 490 public: |
497 CountLossDisplayClient() = default; | 491 CountLossDisplayClient() = default; |
498 | 492 |
499 void DisplayOutputSurfaceLost() override { ++loss_count_; } | 493 void DisplayOutputSurfaceLost() override { ++loss_count_; } |
500 | 494 |
501 int loss_count() const { return loss_count_; } | 495 int loss_count() const { return loss_count_; } |
502 | 496 |
(...skipping 10 matching lines...) Expand all Loading... |
513 // Verify DidLoseOutputSurface callback is hooked up correctly. | 507 // Verify DidLoseOutputSurface callback is hooked up correctly. |
514 EXPECT_EQ(0, client.loss_count()); | 508 EXPECT_EQ(0, client.loss_count()); |
515 output_surface_->context_provider()->ContextGL()->LoseContextCHROMIUM( | 509 output_surface_->context_provider()->ContextGL()->LoseContextCHROMIUM( |
516 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB); | 510 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB); |
517 output_surface_->context_provider()->ContextGL()->Flush(); | 511 output_surface_->context_provider()->ContextGL()->Flush(); |
518 EXPECT_EQ(1, client.loss_count()); | 512 EXPECT_EQ(1, client.loss_count()); |
519 } | 513 } |
520 | 514 |
521 } // namespace | 515 } // namespace |
522 } // namespace cc | 516 } // namespace cc |
OLD | NEW |