Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: cc/surfaces/display_unittest.cc

Issue 2029323004: Get rid of virtual Display::CreateScheduler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@onscreendisplayclient
Patch Set: displaytest: androids Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "cc/output/copy_output_result.h" 11 #include "cc/output/copy_output_result.h"
12 #include "cc/output/delegated_frame_data.h" 12 #include "cc/output/delegated_frame_data.h"
13 #include "cc/quads/render_pass.h" 13 #include "cc/quads/render_pass.h"
14 #include "cc/resources/shared_bitmap_manager.h" 14 #include "cc/resources/shared_bitmap_manager.h"
15 #include "cc/scheduler/begin_frame_source.h"
15 #include "cc/surfaces/display_client.h" 16 #include "cc/surfaces/display_client.h"
16 #include "cc/surfaces/surface.h" 17 #include "cc/surfaces/surface.h"
17 #include "cc/surfaces/surface_factory.h" 18 #include "cc/surfaces/surface_factory.h"
18 #include "cc/surfaces/surface_factory_client.h" 19 #include "cc/surfaces/surface_factory_client.h"
19 #include "cc/surfaces/surface_id_allocator.h" 20 #include "cc/surfaces/surface_id_allocator.h"
20 #include "cc/surfaces/surface_manager.h" 21 #include "cc/surfaces/surface_manager.h"
21 #include "cc/test/fake_output_surface.h" 22 #include "cc/test/fake_output_surface.h"
22 #include "cc/test/scheduler_test_common.h" 23 #include "cc/test/scheduler_test_common.h"
23 #include "cc/test/test_shared_bitmap_manager.h" 24 #include "cc/test/test_shared_bitmap_manager.h"
24 #include "testing/gmock/include/gmock/gmock.h" 25 #include "testing/gmock/include/gmock/gmock.h"
(...skipping 27 matching lines...) Expand all
52 gfx::Rect damage_rect() const { return damage_rect_; } 53 gfx::Rect damage_rect() const { return damage_rect_; }
53 gfx::Size viewport_pixel_size() const { return viewport_pixel_size_; } 54 gfx::Size viewport_pixel_size() const { return viewport_pixel_size_; }
54 }; 55 };
55 56
56 class DisplayTest : public testing::Test { 57 class DisplayTest : public testing::Test {
57 public: 58 public:
58 DisplayTest() 59 DisplayTest()
59 : factory_(&manager_, &surface_factory_client_), 60 : factory_(&manager_, &surface_factory_client_),
60 id_allocator_(kArbitrarySurfaceNamespace), 61 id_allocator_(kArbitrarySurfaceNamespace),
61 software_output_device_(nullptr), 62 software_output_device_(nullptr),
62 task_runner_(new base::NullTaskRunner) { 63 task_runner_(new base::NullTaskRunner),
64 begin_frame_source_(task_runner_.get()) {
63 id_allocator_.RegisterSurfaceIdNamespace(&manager_); 65 id_allocator_.RegisterSurfaceIdNamespace(&manager_);
64 } 66 }
65 67
66 protected: 68 protected:
67 void SetUpContext(std::unique_ptr<TestWebGraphicsContext3D> context) { 69 void SetUpContext(std::unique_ptr<TestWebGraphicsContext3D> context) {
68 if (context) { 70 if (context) {
69 output_surface_ = FakeOutputSurface::Create3d( 71 output_surface_ = FakeOutputSurface::Create3d(
70 TestContextProvider::Create(std::move(context))); 72 TestContextProvider::Create(std::move(context)));
71 } else { 73 } else {
72 std::unique_ptr<TestSoftwareOutputDevice> output_device( 74 std::unique_ptr<TestSoftwareOutputDevice> output_device(
(...skipping 20 matching lines...) Expand all
93 enum { kArbitrarySurfaceNamespace = 3 }; 95 enum { kArbitrarySurfaceNamespace = 3 };
94 96
95 SurfaceManager manager_; 97 SurfaceManager manager_;
96 FakeSurfaceFactoryClient surface_factory_client_; 98 FakeSurfaceFactoryClient surface_factory_client_;
97 SurfaceFactory factory_; 99 SurfaceFactory factory_;
98 SurfaceIdAllocator id_allocator_; 100 SurfaceIdAllocator id_allocator_;
99 TestSoftwareOutputDevice* software_output_device_; 101 TestSoftwareOutputDevice* software_output_device_;
100 std::unique_ptr<FakeOutputSurface> output_surface_; 102 std::unique_ptr<FakeOutputSurface> output_surface_;
101 FakeOutputSurface* output_surface_ptr_; 103 FakeOutputSurface* output_surface_ptr_;
102 scoped_refptr<base::NullTaskRunner> task_runner_; 104 scoped_refptr<base::NullTaskRunner> task_runner_;
105 BackToBackBeginFrameSource begin_frame_source_;
103 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager_; 106 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager_;
104 }; 107 };
105 108
106 class StubDisplayClient : public DisplayClient { 109 class StubDisplayClient : public DisplayClient {
107 public: 110 public:
108 void DisplayOutputSurfaceLost() override {} 111 void DisplayOutputSurfaceLost() override {}
109 void DisplaySetMemoryPolicy(const ManagedMemoryPolicy& policy) override {} 112 void DisplaySetMemoryPolicy(const ManagedMemoryPolicy& policy) override {}
110 }; 113 };
111 114
112 class TestDisplayScheduler : public DisplayScheduler { 115 class TestDisplayScheduler : public DisplayScheduler {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 }; 154 };
152 155
153 class TestDisplay : public Display { 156 class TestDisplay : public Display {
154 public: 157 public:
155 TestDisplay(SurfaceManager* manager, 158 TestDisplay(SurfaceManager* manager,
156 SharedBitmapManager* bitmap_manager, 159 SharedBitmapManager* bitmap_manager,
157 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, 160 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
158 const RendererSettings& settings, 161 const RendererSettings& settings,
159 uint32_t compositor_surface_namespace, 162 uint32_t compositor_surface_namespace,
160 base::SingleThreadTaskRunner* task_runner, 163 base::SingleThreadTaskRunner* task_runner,
164 BeginFrameSource* begin_frame_source,
161 std::unique_ptr<OutputSurface> output_surface) 165 std::unique_ptr<OutputSurface> output_surface)
162 : Display(manager, 166 : Display(manager,
163 bitmap_manager, 167 bitmap_manager,
164 gpu_memory_buffer_manager, 168 gpu_memory_buffer_manager,
165 settings, 169 settings,
166 compositor_surface_namespace, 170 compositor_surface_namespace,
167 task_runner, 171 task_runner,
168 std::move(output_surface)), 172 begin_frame_source,
169 task_runner_(task_runner) {} 173 std::move(output_surface),
174 base::MakeUnique<TestDisplayScheduler>(this,
175 begin_frame_source,
176 task_runner)) {}
170 177
171 TestDisplayScheduler& scheduler() { 178 TestDisplayScheduler& scheduler() {
172 return *static_cast<TestDisplayScheduler*>(scheduler_.get()); 179 return *static_cast<TestDisplayScheduler*>(SchedulerForTesting());
173 } 180 }
174
175 protected:
176 void CreateScheduler() override {
177 scheduler_.reset(new TestDisplayScheduler(this, vsync_begin_frame_source_,
178 task_runner_));
179 }
180
181 private:
182 base::SingleThreadTaskRunner* task_runner_;
183 }; 181 };
184 182
185 void CopyCallback(bool* called, std::unique_ptr<CopyOutputResult> result) { 183 void CopyCallback(bool* called, std::unique_ptr<CopyOutputResult> result) {
186 *called = true; 184 *called = true;
187 } 185 }
188 186
189 // Check that frame is damaged and swapped only under correct conditions. 187 // Check that frame is damaged and swapped only under correct conditions.
190 TEST_F(DisplayTest, DisplayDamaged) { 188 TEST_F(DisplayTest, DisplayDamaged) {
191 SetUpContext(nullptr); 189 SetUpContext(nullptr);
192 StubDisplayClient client; 190 StubDisplayClient client;
193 RendererSettings settings; 191 RendererSettings settings;
194 settings.partial_swap_enabled = true; 192 settings.partial_swap_enabled = true;
195 settings.finish_rendering_on_resize = true; 193 settings.finish_rendering_on_resize = true;
196 TestDisplay display(&manager_, shared_bitmap_manager_.get(), nullptr, 194 TestDisplay display(&manager_, shared_bitmap_manager_.get(), nullptr,
197 settings, id_allocator_.id_namespace(), 195 settings, id_allocator_.id_namespace(),
198 task_runner_.get(), std::move(output_surface_)); 196 task_runner_.get(), &begin_frame_source_,
197 std::move(output_surface_));
199 display.Initialize(&client); 198 display.Initialize(&client);
200 TestDisplayScheduler& scheduler = display.scheduler(); 199 TestDisplayScheduler& scheduler = display.scheduler();
201 200
202 SurfaceId surface_id(id_allocator_.GenerateId()); 201 SurfaceId surface_id(id_allocator_.GenerateId());
203 EXPECT_FALSE(scheduler.damaged); 202 EXPECT_FALSE(scheduler.damaged);
204 EXPECT_FALSE(scheduler.has_new_root_surface); 203 EXPECT_FALSE(scheduler.has_new_root_surface);
205 display.SetSurfaceId(surface_id, 1.f); 204 display.SetSurfaceId(surface_id, 1.f);
206 EXPECT_FALSE(scheduler.damaged); 205 EXPECT_FALSE(scheduler.damaged);
207 EXPECT_FALSE(scheduler.display_resized_); 206 EXPECT_FALSE(scheduler.display_resized_);
208 EXPECT_TRUE(scheduler.has_new_root_surface); 207 EXPECT_TRUE(scheduler.has_new_root_surface);
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM()).Times(0); 455 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM()).Times(0);
457 456
458 SurfaceId surface_id(id_allocator_.GenerateId()); 457 SurfaceId surface_id(id_allocator_.GenerateId());
459 458
460 StubDisplayClient client; 459 StubDisplayClient client;
461 RendererSettings settings; 460 RendererSettings settings;
462 settings.partial_swap_enabled = true; 461 settings.partial_swap_enabled = true;
463 settings.finish_rendering_on_resize = true; 462 settings.finish_rendering_on_resize = true;
464 TestDisplay display(&manager_, shared_bitmap_manager_.get(), nullptr, 463 TestDisplay display(&manager_, shared_bitmap_manager_.get(), nullptr,
465 settings, surface_id.id_namespace(), task_runner_.get(), 464 settings, surface_id.id_namespace(), task_runner_.get(),
466 std::move(output_surface_)); 465 &begin_frame_source_, std::move(output_surface_));
467 display.Initialize(&client); 466 display.Initialize(&client);
468 467
469 display.SetSurfaceId(surface_id, 1.f); 468 display.SetSurfaceId(surface_id, 1.f);
470 469
471 display.Resize(gfx::Size(100, 100)); 470 display.Resize(gfx::Size(100, 100));
472 factory_.Create(surface_id); 471 factory_.Create(surface_id);
473 472
474 { 473 {
475 RenderPassList pass_list; 474 RenderPassList pass_list;
476 std::unique_ptr<RenderPass> pass = RenderPass::Create(); 475 std::unique_ptr<RenderPass> pass = RenderPass::Create();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 513
515 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM()); 514 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM());
516 display.Resize(gfx::Size(250, 250)); 515 display.Resize(gfx::Size(250, 250));
517 testing::Mock::VerifyAndClearExpectations(context_ptr); 516 testing::Mock::VerifyAndClearExpectations(context_ptr);
518 517
519 factory_.Destroy(surface_id); 518 factory_.Destroy(surface_id);
520 } 519 }
521 520
522 } // namespace 521 } // namespace
523 } // namespace cc 522 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698