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