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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 FakeSurfaceFactoryClient surface_factory_client_; | 96 FakeSurfaceFactoryClient surface_factory_client_; |
97 SurfaceFactory factory_; | 97 SurfaceFactory factory_; |
98 SurfaceIdAllocator id_allocator_; | 98 SurfaceIdAllocator id_allocator_; |
99 TestSoftwareOutputDevice* software_output_device_; | 99 TestSoftwareOutputDevice* software_output_device_; |
100 std::unique_ptr<FakeOutputSurface> output_surface_; | 100 std::unique_ptr<FakeOutputSurface> output_surface_; |
101 FakeOutputSurface* output_surface_ptr_; | 101 FakeOutputSurface* output_surface_ptr_; |
102 scoped_refptr<base::NullTaskRunner> task_runner_; | 102 scoped_refptr<base::NullTaskRunner> task_runner_; |
103 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager_; | 103 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager_; |
104 }; | 104 }; |
105 | 105 |
106 class TestDisplayClient : public DisplayClient { | 106 class StubDisplayClient : public DisplayClient { |
107 public: | 107 public: |
108 TestDisplayClient() {} | 108 void DisplayOutputSurfaceLost() override {} |
109 ~TestDisplayClient() override {} | 109 void DisplaySetMemoryPolicy(const ManagedMemoryPolicy& policy) override {} |
110 | |
111 void OutputSurfaceLost() override {} | |
112 void SetMemoryPolicy(const ManagedMemoryPolicy& policy) override {} | |
113 }; | 110 }; |
114 | 111 |
115 class TestDisplayScheduler : public DisplayScheduler { | 112 class TestDisplayScheduler : public DisplayScheduler { |
116 public: | 113 public: |
117 TestDisplayScheduler(DisplaySchedulerClient* client, | 114 TestDisplayScheduler(DisplaySchedulerClient* client, |
118 BeginFrameSource* begin_frame_source, | 115 BeginFrameSource* begin_frame_source, |
119 base::SingleThreadTaskRunner* task_runner) | 116 base::SingleThreadTaskRunner* task_runner) |
120 : DisplayScheduler(client, begin_frame_source, task_runner, 1), | 117 : DisplayScheduler(client, begin_frame_source, task_runner, 1), |
121 damaged(false), | 118 damaged(false), |
122 display_resized_(false), | 119 display_resized_(false), |
(...skipping 25 matching lines...) Expand all Loading... |
148 bool display_resized_; | 145 bool display_resized_; |
149 bool has_new_root_surface; | 146 bool has_new_root_surface; |
150 bool swapped; | 147 bool swapped; |
151 | 148 |
152 private: | 149 private: |
153 RendererSettings settings_; | 150 RendererSettings settings_; |
154 }; | 151 }; |
155 | 152 |
156 class TestDisplay : public Display { | 153 class TestDisplay : public Display { |
157 public: | 154 public: |
158 TestDisplay(DisplayClient* client, | 155 TestDisplay(SurfaceManager* manager, |
159 SurfaceManager* manager, | |
160 SharedBitmapManager* bitmap_manager, | 156 SharedBitmapManager* bitmap_manager, |
161 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 157 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
162 const RendererSettings& settings, | 158 const RendererSettings& settings, |
163 uint32_t compositor_surface_namespace) | 159 uint32_t compositor_surface_namespace, |
164 : Display(client, | 160 base::SingleThreadTaskRunner* task_runner, |
165 manager, | 161 std::unique_ptr<OutputSurface> output_surface) |
| 162 : Display(manager, |
166 bitmap_manager, | 163 bitmap_manager, |
167 gpu_memory_buffer_manager, | 164 gpu_memory_buffer_manager, |
168 settings, | 165 settings, |
169 compositor_surface_namespace) {} | 166 compositor_surface_namespace, |
| 167 task_runner, |
| 168 std::move(output_surface)), |
| 169 task_runner_(task_runner) {} |
170 | 170 |
171 TestDisplayScheduler& scheduler() { | 171 TestDisplayScheduler& scheduler() { |
172 return *static_cast<TestDisplayScheduler*>(scheduler_.get()); | 172 return *static_cast<TestDisplayScheduler*>(scheduler_.get()); |
173 } | 173 } |
174 | 174 |
175 protected: | 175 protected: |
176 void CreateScheduler(base::SingleThreadTaskRunner* task_runner) override { | 176 void CreateScheduler() override { |
177 scheduler_.reset( | 177 scheduler_.reset(new TestDisplayScheduler(this, vsync_begin_frame_source_, |
178 new TestDisplayScheduler(this, vsync_begin_frame_source_, task_runner)); | 178 task_runner_)); |
179 } | 179 } |
| 180 |
| 181 private: |
| 182 base::SingleThreadTaskRunner* task_runner_; |
180 }; | 183 }; |
181 | 184 |
182 void CopyCallback(bool* called, std::unique_ptr<CopyOutputResult> result) { | 185 void CopyCallback(bool* called, std::unique_ptr<CopyOutputResult> result) { |
183 *called = true; | 186 *called = true; |
184 } | 187 } |
185 | 188 |
186 // Check that frame is damaged and swapped only under correct conditions. | 189 // Check that frame is damaged and swapped only under correct conditions. |
187 TEST_F(DisplayTest, DisplayDamaged) { | 190 TEST_F(DisplayTest, DisplayDamaged) { |
188 SetUpContext(nullptr); | 191 SetUpContext(nullptr); |
189 TestDisplayClient client; | 192 StubDisplayClient client; |
190 RendererSettings settings; | 193 RendererSettings settings; |
191 settings.partial_swap_enabled = true; | 194 settings.partial_swap_enabled = true; |
192 settings.finish_rendering_on_resize = true; | 195 settings.finish_rendering_on_resize = true; |
193 TestDisplay display(&client, &manager_, shared_bitmap_manager_.get(), nullptr, | 196 TestDisplay display(&manager_, shared_bitmap_manager_.get(), nullptr, |
194 settings, id_allocator_.id_namespace()); | 197 settings, id_allocator_.id_namespace(), |
195 display.Initialize(std::move(output_surface_), task_runner_.get()); | 198 task_runner_.get(), std::move(output_surface_)); |
| 199 display.Initialize(&client); |
196 TestDisplayScheduler& scheduler = display.scheduler(); | 200 TestDisplayScheduler& scheduler = display.scheduler(); |
197 | 201 |
198 SurfaceId surface_id(id_allocator_.GenerateId()); | 202 SurfaceId surface_id(id_allocator_.GenerateId()); |
199 EXPECT_FALSE(scheduler.damaged); | 203 EXPECT_FALSE(scheduler.damaged); |
200 EXPECT_FALSE(scheduler.has_new_root_surface); | 204 EXPECT_FALSE(scheduler.has_new_root_surface); |
201 display.SetSurfaceId(surface_id, 1.f); | 205 display.SetSurfaceId(surface_id, 1.f); |
202 EXPECT_FALSE(scheduler.damaged); | 206 EXPECT_FALSE(scheduler.damaged); |
203 EXPECT_FALSE(scheduler.display_resized_); | 207 EXPECT_FALSE(scheduler.display_resized_); |
204 EXPECT_TRUE(scheduler.has_new_root_surface); | 208 EXPECT_TRUE(scheduler.has_new_root_surface); |
205 | 209 |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 | 450 |
447 TEST_F(DisplayTest, Finish) { | 451 TEST_F(DisplayTest, Finish) { |
448 std::unique_ptr<MockedContext> context(new MockedContext()); | 452 std::unique_ptr<MockedContext> context(new MockedContext()); |
449 MockedContext* context_ptr = context.get(); | 453 MockedContext* context_ptr = context.get(); |
450 SetUpContext(std::move(context)); | 454 SetUpContext(std::move(context)); |
451 | 455 |
452 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM()).Times(0); | 456 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM()).Times(0); |
453 | 457 |
454 SurfaceId surface_id(id_allocator_.GenerateId()); | 458 SurfaceId surface_id(id_allocator_.GenerateId()); |
455 | 459 |
456 TestDisplayClient client; | 460 StubDisplayClient client; |
457 RendererSettings settings; | 461 RendererSettings settings; |
458 settings.partial_swap_enabled = true; | 462 settings.partial_swap_enabled = true; |
459 settings.finish_rendering_on_resize = true; | 463 settings.finish_rendering_on_resize = true; |
460 TestDisplay display(&client, &manager_, shared_bitmap_manager_.get(), nullptr, | 464 TestDisplay display(&manager_, shared_bitmap_manager_.get(), nullptr, |
461 settings, surface_id.id_namespace()); | 465 settings, surface_id.id_namespace(), task_runner_.get(), |
462 display.Initialize(std::move(output_surface_), task_runner_.get()); | 466 std::move(output_surface_)); |
| 467 display.Initialize(&client); |
463 | 468 |
464 display.SetSurfaceId(surface_id, 1.f); | 469 display.SetSurfaceId(surface_id, 1.f); |
465 | 470 |
466 display.Resize(gfx::Size(100, 100)); | 471 display.Resize(gfx::Size(100, 100)); |
467 factory_.Create(surface_id); | 472 factory_.Create(surface_id); |
468 | 473 |
469 { | 474 { |
470 RenderPassList pass_list; | 475 RenderPassList pass_list; |
471 std::unique_ptr<RenderPass> pass = RenderPass::Create(); | 476 std::unique_ptr<RenderPass> pass = RenderPass::Create(); |
472 pass->output_rect = gfx::Rect(0, 0, 100, 100); | 477 pass->output_rect = gfx::Rect(0, 0, 100, 100); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 | 514 |
510 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM()); | 515 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM()); |
511 display.Resize(gfx::Size(250, 250)); | 516 display.Resize(gfx::Size(250, 250)); |
512 testing::Mock::VerifyAndClearExpectations(context_ptr); | 517 testing::Mock::VerifyAndClearExpectations(context_ptr); |
513 | 518 |
514 factory_.Destroy(surface_id); | 519 factory_.Destroy(surface_id); |
515 } | 520 } |
516 | 521 |
517 } // namespace | 522 } // namespace |
518 } // namespace cc | 523 } // namespace cc |
OLD | NEW |