| 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 class TestSoftwareOutputDevice : public SoftwareOutputDevice { | 54 class TestSoftwareOutputDevice : public SoftwareOutputDevice { |
| 55 public: | 55 public: |
| 56 TestSoftwareOutputDevice() {} | 56 TestSoftwareOutputDevice() {} |
| 57 | 57 |
| 58 gfx::Rect damage_rect() const { return damage_rect_; } | 58 gfx::Rect damage_rect() const { return damage_rect_; } |
| 59 gfx::Size viewport_pixel_size() const { return viewport_pixel_size_; } | 59 gfx::Size viewport_pixel_size() const { return viewport_pixel_size_; } |
| 60 }; | 60 }; |
| 61 | 61 |
| 62 class TestDisplayScheduler : public DisplayScheduler { | 62 class TestDisplayScheduler : public DisplayScheduler { |
| 63 public: | 63 public: |
| 64 TestDisplayScheduler(BeginFrameSource* begin_frame_source, | 64 explicit TestDisplayScheduler(base::SingleThreadTaskRunner* task_runner) |
| 65 base::SingleThreadTaskRunner* task_runner) | 65 : DisplayScheduler(task_runner, 1), |
| 66 : DisplayScheduler(begin_frame_source, task_runner, 1), | |
| 67 damaged(false), | 66 damaged(false), |
| 68 display_resized_(false), | 67 display_resized_(false), |
| 69 has_new_root_surface(false), | 68 has_new_root_surface(false), |
| 70 swapped(false) {} | 69 swapped(false) {} |
| 71 | 70 |
| 72 ~TestDisplayScheduler() override {} | 71 ~TestDisplayScheduler() override {} |
| 73 | 72 |
| 74 void DisplayResized() override { display_resized_ = true; } | 73 void DisplayResized() override { display_resized_ = true; } |
| 75 | 74 |
| 76 void SetNewRootSurface(const SurfaceId& root_surface_id) override { | 75 void SetNewRootSurface(const SurfaceId& root_surface_id) override { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 104 manager_.RegisterFrameSinkId(kArbitraryFrameSinkId); | 103 manager_.RegisterFrameSinkId(kArbitraryFrameSinkId); |
| 105 } | 104 } |
| 106 | 105 |
| 107 ~DisplayTest() override { | 106 ~DisplayTest() override { |
| 108 manager_.InvalidateFrameSinkId(kArbitraryFrameSinkId); | 107 manager_.InvalidateFrameSinkId(kArbitraryFrameSinkId); |
| 109 factory_.EvictSurface(); | 108 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 begin_frame_source_.reset(new StubBeginFrameSource); |
| 115 new StubBeginFrameSource); | |
| 116 | 114 |
| 117 std::unique_ptr<FakeOutputSurface> output_surface; | 115 std::unique_ptr<FakeOutputSurface> output_surface; |
| 118 if (context) { | 116 if (context) { |
| 119 auto provider = TestContextProvider::Create(std::move(context)); | 117 auto provider = TestContextProvider::Create(std::move(context)); |
| 120 provider->BindToCurrentThread(); | 118 provider->BindToCurrentThread(); |
| 121 output_surface = FakeOutputSurface::Create3d(std::move(provider)); | 119 output_surface = FakeOutputSurface::Create3d(std::move(provider)); |
| 122 } else { | 120 } else { |
| 123 std::unique_ptr<TestSoftwareOutputDevice> device( | 121 std::unique_ptr<TestSoftwareOutputDevice> device( |
| 124 new TestSoftwareOutputDevice); | 122 new TestSoftwareOutputDevice); |
| 125 software_output_device_ = device.get(); | 123 software_output_device_ = device.get(); |
| 126 output_surface = FakeOutputSurface::CreateSoftware(std::move(device)); | 124 output_surface = FakeOutputSurface::CreateSoftware(std::move(device)); |
| 127 } | 125 } |
| 128 output_surface_ = output_surface.get(); | 126 output_surface_ = output_surface.get(); |
| 129 | 127 |
| 130 std::unique_ptr<TestDisplayScheduler> scheduler( | 128 std::unique_ptr<TestDisplayScheduler> scheduler( |
| 131 new TestDisplayScheduler(begin_frame_source.get(), task_runner_.get())); | 129 new TestDisplayScheduler(task_runner_.get())); |
| 132 scheduler_ = scheduler.get(); | 130 scheduler_ = scheduler.get(); |
| 133 | 131 |
| 134 display_ = base::MakeUnique<Display>( | 132 display_ = base::MakeUnique<Display>( |
| 135 &shared_bitmap_manager_, nullptr /* gpu_memory_buffer_manager */, | 133 &shared_bitmap_manager_, nullptr /* gpu_memory_buffer_manager */, |
| 136 settings, kArbitraryFrameSinkId, std::move(begin_frame_source), | 134 settings, kArbitraryFrameSinkId, begin_frame_source_.get(), |
| 137 std::move(output_surface), std::move(scheduler), | 135 std::move(output_surface), std::move(scheduler), |
| 138 base::MakeUnique<TextureMailboxDeleter>(task_runner_.get())); | 136 base::MakeUnique<TextureMailboxDeleter>(task_runner_.get())); |
| 139 display_->SetVisible(true); | 137 display_->SetVisible(true); |
| 140 } | 138 } |
| 141 | 139 |
| 142 protected: | 140 protected: |
| 143 void SubmitCompositorFrame(RenderPassList* pass_list, | 141 void SubmitCompositorFrame(RenderPassList* pass_list, |
| 144 const LocalFrameId& local_frame_id) { | 142 const LocalFrameId& local_frame_id) { |
| 145 CompositorFrame frame; | 143 CompositorFrame frame; |
| 146 pass_list->swap(frame.render_pass_list); | 144 pass_list->swap(frame.render_pass_list); |
| 147 | 145 |
| 148 factory_.SubmitCompositorFrame(local_frame_id, std::move(frame), | 146 factory_.SubmitCompositorFrame(local_frame_id, std::move(frame), |
| 149 SurfaceFactory::DrawCallback()); | 147 SurfaceFactory::DrawCallback()); |
| 150 } | 148 } |
| 151 | 149 |
| 152 SurfaceManager manager_; | 150 SurfaceManager manager_; |
| 153 FakeSurfaceFactoryClient surface_factory_client_; | 151 FakeSurfaceFactoryClient surface_factory_client_; |
| 154 SurfaceFactory factory_; | 152 SurfaceFactory factory_; |
| 155 SurfaceIdAllocator id_allocator_; | 153 SurfaceIdAllocator id_allocator_; |
| 156 scoped_refptr<base::NullTaskRunner> task_runner_; | 154 scoped_refptr<base::NullTaskRunner> task_runner_; |
| 157 TestSharedBitmapManager shared_bitmap_manager_; | 155 TestSharedBitmapManager shared_bitmap_manager_; |
| 156 std::unique_ptr<BeginFrameSource> begin_frame_source_; |
| 158 std::unique_ptr<Display> display_; | 157 std::unique_ptr<Display> display_; |
| 159 TestSoftwareOutputDevice* software_output_device_ = nullptr; | 158 TestSoftwareOutputDevice* software_output_device_ = nullptr; |
| 160 FakeOutputSurface* output_surface_ = nullptr; | 159 FakeOutputSurface* output_surface_ = nullptr; |
| 161 TestDisplayScheduler* scheduler_ = nullptr; | 160 TestDisplayScheduler* scheduler_ = nullptr; |
| 162 }; | 161 }; |
| 163 | 162 |
| 164 class StubDisplayClient : public DisplayClient { | 163 class StubDisplayClient : public DisplayClient { |
| 165 public: | 164 public: |
| 166 void DisplayOutputSurfaceLost() override {} | 165 void DisplayOutputSurfaceLost() override {} |
| 167 void DisplayWillDrawAndSwap(bool will_draw_and_swap, | 166 void DisplayWillDrawAndSwap(bool will_draw_and_swap, |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 // Verify DidLoseOutputSurface callback is hooked up correctly. | 506 // Verify DidLoseOutputSurface callback is hooked up correctly. |
| 508 EXPECT_EQ(0, client.loss_count()); | 507 EXPECT_EQ(0, client.loss_count()); |
| 509 output_surface_->context_provider()->ContextGL()->LoseContextCHROMIUM( | 508 output_surface_->context_provider()->ContextGL()->LoseContextCHROMIUM( |
| 510 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB); | 509 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB); |
| 511 output_surface_->context_provider()->ContextGL()->Flush(); | 510 output_surface_->context_provider()->ContextGL()->Flush(); |
| 512 EXPECT_EQ(1, client.loss_count()); | 511 EXPECT_EQ(1, client.loss_count()); |
| 513 } | 512 } |
| 514 | 513 |
| 515 } // namespace | 514 } // namespace |
| 516 } // namespace cc | 515 } // namespace cc |
| OLD | NEW |