| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 class DisplayTest : public testing::Test { | 56 class DisplayTest : public testing::Test { |
| 57 public: | 57 public: |
| 58 DisplayTest() | 58 DisplayTest() |
| 59 : factory_(&manager_, &surface_factory_client_), | 59 : factory_(&manager_, &surface_factory_client_), |
| 60 software_output_device_(nullptr), | 60 software_output_device_(nullptr), |
| 61 task_runner_(new base::NullTaskRunner) {} | 61 task_runner_(new base::NullTaskRunner) {} |
| 62 | 62 |
| 63 protected: | 63 protected: |
| 64 void SetUpContext(scoped_ptr<TestWebGraphicsContext3D> context) { | 64 void SetUpContext(std::unique_ptr<TestWebGraphicsContext3D> context) { |
| 65 if (context) { | 65 if (context) { |
| 66 output_surface_ = FakeOutputSurface::Create3d( | 66 output_surface_ = FakeOutputSurface::Create3d( |
| 67 TestContextProvider::Create(std::move(context))); | 67 TestContextProvider::Create(std::move(context))); |
| 68 } else { | 68 } else { |
| 69 scoped_ptr<TestSoftwareOutputDevice> output_device( | 69 std::unique_ptr<TestSoftwareOutputDevice> output_device( |
| 70 new TestSoftwareOutputDevice); | 70 new TestSoftwareOutputDevice); |
| 71 software_output_device_ = output_device.get(); | 71 software_output_device_ = output_device.get(); |
| 72 output_surface_ = | 72 output_surface_ = |
| 73 FakeOutputSurface::CreateSoftware(std::move(output_device)); | 73 FakeOutputSurface::CreateSoftware(std::move(output_device)); |
| 74 } | 74 } |
| 75 shared_bitmap_manager_.reset(new TestSharedBitmapManager); | 75 shared_bitmap_manager_.reset(new TestSharedBitmapManager); |
| 76 output_surface_ptr_ = output_surface_.get(); | 76 output_surface_ptr_ = output_surface_.get(); |
| 77 } | 77 } |
| 78 | 78 |
| 79 void SubmitCompositorFrame(RenderPassList* pass_list, SurfaceId surface_id) { | 79 void SubmitCompositorFrame(RenderPassList* pass_list, SurfaceId surface_id) { |
| 80 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); | 80 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); |
| 81 pass_list->swap(frame_data->render_pass_list); | 81 pass_list->swap(frame_data->render_pass_list); |
| 82 | 82 |
| 83 scoped_ptr<CompositorFrame> frame(new CompositorFrame); | 83 std::unique_ptr<CompositorFrame> frame(new CompositorFrame); |
| 84 frame->delegated_frame_data = std::move(frame_data); | 84 frame->delegated_frame_data = std::move(frame_data); |
| 85 | 85 |
| 86 factory_.SubmitCompositorFrame(surface_id, std::move(frame), | 86 factory_.SubmitCompositorFrame(surface_id, std::move(frame), |
| 87 SurfaceFactory::DrawCallback()); | 87 SurfaceFactory::DrawCallback()); |
| 88 } | 88 } |
| 89 | 89 |
| 90 SurfaceManager manager_; | 90 SurfaceManager manager_; |
| 91 FakeSurfaceFactoryClient surface_factory_client_; | 91 FakeSurfaceFactoryClient surface_factory_client_; |
| 92 SurfaceFactory factory_; | 92 SurfaceFactory factory_; |
| 93 TestSoftwareOutputDevice* software_output_device_; | 93 TestSoftwareOutputDevice* software_output_device_; |
| 94 scoped_ptr<FakeOutputSurface> output_surface_; | 94 std::unique_ptr<FakeOutputSurface> output_surface_; |
| 95 FakeOutputSurface* output_surface_ptr_; | 95 FakeOutputSurface* output_surface_ptr_; |
| 96 FakeBeginFrameSource fake_begin_frame_source_; | 96 FakeBeginFrameSource fake_begin_frame_source_; |
| 97 scoped_refptr<base::NullTaskRunner> task_runner_; | 97 scoped_refptr<base::NullTaskRunner> task_runner_; |
| 98 scoped_ptr<SharedBitmapManager> shared_bitmap_manager_; | 98 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager_; |
| 99 }; | 99 }; |
| 100 | 100 |
| 101 class TestDisplayClient : public DisplayClient { | 101 class TestDisplayClient : public DisplayClient { |
| 102 public: | 102 public: |
| 103 TestDisplayClient() {} | 103 TestDisplayClient() {} |
| 104 ~TestDisplayClient() override {} | 104 ~TestDisplayClient() override {} |
| 105 | 105 |
| 106 void CommitVSyncParameters(base::TimeTicks timebase, | 106 void CommitVSyncParameters(base::TimeTicks timebase, |
| 107 base::TimeDelta interval) override {} | 107 base::TimeDelta interval) override {} |
| 108 void OutputSurfaceLost() override {} | 108 void OutputSurfaceLost() override {} |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 display_resized_ = false; | 142 display_resized_ = false; |
| 143 has_new_root_surface = false; | 143 has_new_root_surface = false; |
| 144 } | 144 } |
| 145 | 145 |
| 146 bool damaged; | 146 bool damaged; |
| 147 bool display_resized_; | 147 bool display_resized_; |
| 148 bool has_new_root_surface; | 148 bool has_new_root_surface; |
| 149 bool swapped; | 149 bool swapped; |
| 150 }; | 150 }; |
| 151 | 151 |
| 152 void CopyCallback(bool* called, scoped_ptr<CopyOutputResult> result) { | 152 void CopyCallback(bool* called, std::unique_ptr<CopyOutputResult> result) { |
| 153 *called = true; | 153 *called = true; |
| 154 } | 154 } |
| 155 | 155 |
| 156 // Check that frame is damaged and swapped only under correct conditions. | 156 // Check that frame is damaged and swapped only under correct conditions. |
| 157 TEST_F(DisplayTest, DisplayDamaged) { | 157 TEST_F(DisplayTest, DisplayDamaged) { |
| 158 SetUpContext(nullptr); | 158 SetUpContext(nullptr); |
| 159 TestDisplayClient client; | 159 TestDisplayClient client; |
| 160 RendererSettings settings; | 160 RendererSettings settings; |
| 161 settings.partial_swap_enabled = true; | 161 settings.partial_swap_enabled = true; |
| 162 settings.finish_rendering_on_resize = true; | 162 settings.finish_rendering_on_resize = true; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 178 scheduler.ResetDamageForTest(); | 178 scheduler.ResetDamageForTest(); |
| 179 display.Resize(gfx::Size(100, 100)); | 179 display.Resize(gfx::Size(100, 100)); |
| 180 EXPECT_FALSE(scheduler.damaged); | 180 EXPECT_FALSE(scheduler.damaged); |
| 181 EXPECT_TRUE(scheduler.display_resized_); | 181 EXPECT_TRUE(scheduler.display_resized_); |
| 182 EXPECT_FALSE(scheduler.has_new_root_surface); | 182 EXPECT_FALSE(scheduler.has_new_root_surface); |
| 183 | 183 |
| 184 factory_.Create(surface_id); | 184 factory_.Create(surface_id); |
| 185 | 185 |
| 186 // First draw from surface should have full damage. | 186 // First draw from surface should have full damage. |
| 187 RenderPassList pass_list; | 187 RenderPassList pass_list; |
| 188 scoped_ptr<RenderPass> pass = RenderPass::Create(); | 188 std::unique_ptr<RenderPass> pass = RenderPass::Create(); |
| 189 pass->output_rect = gfx::Rect(0, 0, 100, 100); | 189 pass->output_rect = gfx::Rect(0, 0, 100, 100); |
| 190 pass->damage_rect = gfx::Rect(10, 10, 1, 1); | 190 pass->damage_rect = gfx::Rect(10, 10, 1, 1); |
| 191 pass->id = RenderPassId(1, 1); | 191 pass->id = RenderPassId(1, 1); |
| 192 pass_list.push_back(std::move(pass)); | 192 pass_list.push_back(std::move(pass)); |
| 193 | 193 |
| 194 scheduler.ResetDamageForTest(); | 194 scheduler.ResetDamageForTest(); |
| 195 SubmitCompositorFrame(&pass_list, surface_id); | 195 SubmitCompositorFrame(&pass_list, surface_id); |
| 196 EXPECT_TRUE(scheduler.damaged); | 196 EXPECT_TRUE(scheduler.damaged); |
| 197 EXPECT_FALSE(scheduler.display_resized_); | 197 EXPECT_FALSE(scheduler.display_resized_); |
| 198 EXPECT_FALSE(scheduler.has_new_root_surface); | 198 EXPECT_FALSE(scheduler.has_new_root_surface); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 // Pass has no damage, so shouldn't be swapped, but latency info should be | 318 // Pass has no damage, so shouldn't be swapped, but latency info should be |
| 319 // saved for next swap. | 319 // saved for next swap. |
| 320 { | 320 { |
| 321 pass = RenderPass::Create(); | 321 pass = RenderPass::Create(); |
| 322 pass->output_rect = gfx::Rect(0, 0, 100, 100); | 322 pass->output_rect = gfx::Rect(0, 0, 100, 100); |
| 323 pass->damage_rect = gfx::Rect(10, 10, 0, 0); | 323 pass->damage_rect = gfx::Rect(10, 10, 0, 0); |
| 324 pass->id = RenderPassId(1, 1); | 324 pass->id = RenderPassId(1, 1); |
| 325 | 325 |
| 326 pass_list.push_back(std::move(pass)); | 326 pass_list.push_back(std::move(pass)); |
| 327 scheduler.ResetDamageForTest(); | 327 scheduler.ResetDamageForTest(); |
| 328 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); | 328 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); |
| 329 pass_list.swap(frame_data->render_pass_list); | 329 pass_list.swap(frame_data->render_pass_list); |
| 330 | 330 |
| 331 scoped_ptr<CompositorFrame> frame(new CompositorFrame); | 331 std::unique_ptr<CompositorFrame> frame(new CompositorFrame); |
| 332 frame->delegated_frame_data = std::move(frame_data); | 332 frame->delegated_frame_data = std::move(frame_data); |
| 333 frame->metadata.latency_info.push_back(ui::LatencyInfo()); | 333 frame->metadata.latency_info.push_back(ui::LatencyInfo()); |
| 334 | 334 |
| 335 factory_.SubmitCompositorFrame(surface_id, std::move(frame), | 335 factory_.SubmitCompositorFrame(surface_id, std::move(frame), |
| 336 SurfaceFactory::DrawCallback()); | 336 SurfaceFactory::DrawCallback()); |
| 337 EXPECT_TRUE(scheduler.damaged); | 337 EXPECT_TRUE(scheduler.damaged); |
| 338 EXPECT_FALSE(scheduler.display_resized_); | 338 EXPECT_FALSE(scheduler.display_resized_); |
| 339 EXPECT_FALSE(scheduler.has_new_root_surface); | 339 EXPECT_FALSE(scheduler.has_new_root_surface); |
| 340 | 340 |
| 341 scheduler.swapped = false; | 341 scheduler.swapped = false; |
| 342 display.DrawAndSwap(); | 342 display.DrawAndSwap(); |
| 343 EXPECT_TRUE(scheduler.swapped); | 343 EXPECT_TRUE(scheduler.swapped); |
| 344 EXPECT_EQ(4u, output_surface_ptr_->num_sent_frames()); | 344 EXPECT_EQ(4u, output_surface_ptr_->num_sent_frames()); |
| 345 } | 345 } |
| 346 | 346 |
| 347 // Resize should cause a swap if no frame was swapped at the previous size. | 347 // Resize should cause a swap if no frame was swapped at the previous size. |
| 348 { | 348 { |
| 349 scheduler.swapped = false; | 349 scheduler.swapped = false; |
| 350 display.Resize(gfx::Size(200, 200)); | 350 display.Resize(gfx::Size(200, 200)); |
| 351 EXPECT_FALSE(scheduler.swapped); | 351 EXPECT_FALSE(scheduler.swapped); |
| 352 EXPECT_EQ(4u, output_surface_ptr_->num_sent_frames()); | 352 EXPECT_EQ(4u, output_surface_ptr_->num_sent_frames()); |
| 353 | 353 |
| 354 pass = RenderPass::Create(); | 354 pass = RenderPass::Create(); |
| 355 pass->output_rect = gfx::Rect(0, 0, 200, 200); | 355 pass->output_rect = gfx::Rect(0, 0, 200, 200); |
| 356 pass->damage_rect = gfx::Rect(10, 10, 10, 10); | 356 pass->damage_rect = gfx::Rect(10, 10, 10, 10); |
| 357 pass->id = RenderPassId(1, 1); | 357 pass->id = RenderPassId(1, 1); |
| 358 | 358 |
| 359 pass_list.push_back(std::move(pass)); | 359 pass_list.push_back(std::move(pass)); |
| 360 scheduler.ResetDamageForTest(); | 360 scheduler.ResetDamageForTest(); |
| 361 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); | 361 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); |
| 362 pass_list.swap(frame_data->render_pass_list); | 362 pass_list.swap(frame_data->render_pass_list); |
| 363 | 363 |
| 364 scoped_ptr<CompositorFrame> frame(new CompositorFrame); | 364 std::unique_ptr<CompositorFrame> frame(new CompositorFrame); |
| 365 frame->delegated_frame_data = std::move(frame_data); | 365 frame->delegated_frame_data = std::move(frame_data); |
| 366 | 366 |
| 367 factory_.SubmitCompositorFrame(surface_id, std::move(frame), | 367 factory_.SubmitCompositorFrame(surface_id, std::move(frame), |
| 368 SurfaceFactory::DrawCallback()); | 368 SurfaceFactory::DrawCallback()); |
| 369 EXPECT_TRUE(scheduler.damaged); | 369 EXPECT_TRUE(scheduler.damaged); |
| 370 EXPECT_FALSE(scheduler.display_resized_); | 370 EXPECT_FALSE(scheduler.display_resized_); |
| 371 EXPECT_FALSE(scheduler.has_new_root_surface); | 371 EXPECT_FALSE(scheduler.has_new_root_surface); |
| 372 | 372 |
| 373 scheduler.swapped = false; | 373 scheduler.swapped = false; |
| 374 display.Resize(gfx::Size(100, 100)); | 374 display.Resize(gfx::Size(100, 100)); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 | 410 |
| 411 factory_.Destroy(surface_id); | 411 factory_.Destroy(surface_id); |
| 412 } | 412 } |
| 413 | 413 |
| 414 class MockedContext : public TestWebGraphicsContext3D { | 414 class MockedContext : public TestWebGraphicsContext3D { |
| 415 public: | 415 public: |
| 416 MOCK_METHOD0(shallowFinishCHROMIUM, void()); | 416 MOCK_METHOD0(shallowFinishCHROMIUM, void()); |
| 417 }; | 417 }; |
| 418 | 418 |
| 419 TEST_F(DisplayTest, Finish) { | 419 TEST_F(DisplayTest, Finish) { |
| 420 scoped_ptr<MockedContext> context(new MockedContext()); | 420 std::unique_ptr<MockedContext> context(new MockedContext()); |
| 421 MockedContext* context_ptr = context.get(); | 421 MockedContext* context_ptr = context.get(); |
| 422 SetUpContext(std::move(context)); | 422 SetUpContext(std::move(context)); |
| 423 | 423 |
| 424 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM()).Times(0); | 424 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM()).Times(0); |
| 425 TestDisplayClient client; | 425 TestDisplayClient client; |
| 426 RendererSettings settings; | 426 RendererSettings settings; |
| 427 settings.partial_swap_enabled = true; | 427 settings.partial_swap_enabled = true; |
| 428 settings.finish_rendering_on_resize = true; | 428 settings.finish_rendering_on_resize = true; |
| 429 Display display(&client, &manager_, shared_bitmap_manager_.get(), nullptr, | 429 Display display(&client, &manager_, shared_bitmap_manager_.get(), nullptr, |
| 430 settings); | 430 settings); |
| 431 | 431 |
| 432 TestDisplayScheduler scheduler(&display, &fake_begin_frame_source_, | 432 TestDisplayScheduler scheduler(&display, &fake_begin_frame_source_, |
| 433 task_runner_.get()); | 433 task_runner_.get()); |
| 434 display.Initialize(std::move(output_surface_), &scheduler); | 434 display.Initialize(std::move(output_surface_), &scheduler); |
| 435 | 435 |
| 436 SurfaceId surface_id(7u); | 436 SurfaceId surface_id(7u); |
| 437 display.SetSurfaceId(surface_id, 1.f); | 437 display.SetSurfaceId(surface_id, 1.f); |
| 438 | 438 |
| 439 display.Resize(gfx::Size(100, 100)); | 439 display.Resize(gfx::Size(100, 100)); |
| 440 factory_.Create(surface_id); | 440 factory_.Create(surface_id); |
| 441 | 441 |
| 442 { | 442 { |
| 443 RenderPassList pass_list; | 443 RenderPassList pass_list; |
| 444 scoped_ptr<RenderPass> pass = RenderPass::Create(); | 444 std::unique_ptr<RenderPass> pass = RenderPass::Create(); |
| 445 pass->output_rect = gfx::Rect(0, 0, 100, 100); | 445 pass->output_rect = gfx::Rect(0, 0, 100, 100); |
| 446 pass->damage_rect = gfx::Rect(10, 10, 1, 1); | 446 pass->damage_rect = gfx::Rect(10, 10, 1, 1); |
| 447 pass->id = RenderPassId(1, 1); | 447 pass->id = RenderPassId(1, 1); |
| 448 pass_list.push_back(std::move(pass)); | 448 pass_list.push_back(std::move(pass)); |
| 449 | 449 |
| 450 SubmitCompositorFrame(&pass_list, surface_id); | 450 SubmitCompositorFrame(&pass_list, surface_id); |
| 451 } | 451 } |
| 452 | 452 |
| 453 display.DrawAndSwap(); | 453 display.DrawAndSwap(); |
| 454 | 454 |
| 455 // First resize and draw shouldn't finish. | 455 // First resize and draw shouldn't finish. |
| 456 testing::Mock::VerifyAndClearExpectations(context_ptr); | 456 testing::Mock::VerifyAndClearExpectations(context_ptr); |
| 457 | 457 |
| 458 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM()); | 458 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM()); |
| 459 display.Resize(gfx::Size(150, 150)); | 459 display.Resize(gfx::Size(150, 150)); |
| 460 testing::Mock::VerifyAndClearExpectations(context_ptr); | 460 testing::Mock::VerifyAndClearExpectations(context_ptr); |
| 461 | 461 |
| 462 // Another resize without a swap doesn't need to finish. | 462 // Another resize without a swap doesn't need to finish. |
| 463 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM()).Times(0); | 463 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM()).Times(0); |
| 464 display.Resize(gfx::Size(200, 200)); | 464 display.Resize(gfx::Size(200, 200)); |
| 465 testing::Mock::VerifyAndClearExpectations(context_ptr); | 465 testing::Mock::VerifyAndClearExpectations(context_ptr); |
| 466 | 466 |
| 467 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM()).Times(0); | 467 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM()).Times(0); |
| 468 { | 468 { |
| 469 RenderPassList pass_list; | 469 RenderPassList pass_list; |
| 470 scoped_ptr<RenderPass> pass = RenderPass::Create(); | 470 std::unique_ptr<RenderPass> pass = RenderPass::Create(); |
| 471 pass->output_rect = gfx::Rect(0, 0, 200, 200); | 471 pass->output_rect = gfx::Rect(0, 0, 200, 200); |
| 472 pass->damage_rect = gfx::Rect(10, 10, 1, 1); | 472 pass->damage_rect = gfx::Rect(10, 10, 1, 1); |
| 473 pass->id = RenderPassId(1, 1); | 473 pass->id = RenderPassId(1, 1); |
| 474 pass_list.push_back(std::move(pass)); | 474 pass_list.push_back(std::move(pass)); |
| 475 | 475 |
| 476 SubmitCompositorFrame(&pass_list, surface_id); | 476 SubmitCompositorFrame(&pass_list, surface_id); |
| 477 } | 477 } |
| 478 | 478 |
| 479 display.DrawAndSwap(); | 479 display.DrawAndSwap(); |
| 480 | 480 |
| 481 testing::Mock::VerifyAndClearExpectations(context_ptr); | 481 testing::Mock::VerifyAndClearExpectations(context_ptr); |
| 482 | 482 |
| 483 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM()); | 483 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM()); |
| 484 display.Resize(gfx::Size(250, 250)); | 484 display.Resize(gfx::Size(250, 250)); |
| 485 testing::Mock::VerifyAndClearExpectations(context_ptr); | 485 testing::Mock::VerifyAndClearExpectations(context_ptr); |
| 486 | 486 |
| 487 factory_.Destroy(surface_id); | 487 factory_.Destroy(surface_id); |
| 488 } | 488 } |
| 489 | 489 |
| 490 } // namespace | 490 } // namespace |
| 491 } // namespace cc | 491 } // namespace cc |
| OLD | NEW |