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

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

Issue 1821863002: Hook up ui::Compositor to Display's BeginFrameSource (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move Android external BFS into output surface too Created 4 years, 8 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"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 TestSoftwareOutputDevice() {} 50 TestSoftwareOutputDevice() {}
51 51
52 gfx::Rect damage_rect() const { return damage_rect_; } 52 gfx::Rect damage_rect() const { return damage_rect_; }
53 gfx::Size viewport_pixel_size() const { return viewport_pixel_size_; } 53 gfx::Size viewport_pixel_size() const { return viewport_pixel_size_; }
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 id_allocator_(kArbitrarySurfaceNamespace),
61 task_runner_(new base::NullTaskRunner) {} 61 software_output_device_(nullptr) {
62 id_allocator_.RegisterSurfaceIdNamespace(&manager_);
63 }
62 64
63 protected: 65 protected:
64 void SetUpContext(scoped_ptr<TestWebGraphicsContext3D> context) { 66 void SetUpContext(scoped_ptr<TestWebGraphicsContext3D> context) {
65 if (context) { 67 if (context) {
66 output_surface_ = FakeOutputSurface::Create3d( 68 output_surface_ = FakeOutputSurface::Create3d(
67 TestContextProvider::Create(std::move(context))); 69 TestContextProvider::Create(std::move(context)));
68 } else { 70 } else {
69 scoped_ptr<TestSoftwareOutputDevice> output_device( 71 scoped_ptr<TestSoftwareOutputDevice> output_device(
70 new TestSoftwareOutputDevice); 72 new TestSoftwareOutputDevice);
71 software_output_device_ = output_device.get(); 73 software_output_device_ = output_device.get();
72 output_surface_ = 74 output_surface_ =
73 FakeOutputSurface::CreateSoftware(std::move(output_device)); 75 FakeOutputSurface::CreateSoftware(std::move(output_device));
74 } 76 }
75 shared_bitmap_manager_.reset(new TestSharedBitmapManager); 77 shared_bitmap_manager_.reset(new TestSharedBitmapManager);
76 output_surface_ptr_ = output_surface_.get(); 78 output_surface_ptr_ = output_surface_.get();
77 } 79 }
78 80
79 void SubmitCompositorFrame(RenderPassList* pass_list, SurfaceId surface_id) { 81 void SubmitCompositorFrame(RenderPassList* pass_list, SurfaceId surface_id) {
80 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); 82 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
81 pass_list->swap(frame_data->render_pass_list); 83 pass_list->swap(frame_data->render_pass_list);
82 84
83 scoped_ptr<CompositorFrame> frame(new CompositorFrame); 85 scoped_ptr<CompositorFrame> frame(new CompositorFrame);
84 frame->delegated_frame_data = std::move(frame_data); 86 frame->delegated_frame_data = std::move(frame_data);
85 87
86 factory_.SubmitCompositorFrame(surface_id, std::move(frame), 88 factory_.SubmitCompositorFrame(surface_id, std::move(frame),
87 SurfaceFactory::DrawCallback()); 89 SurfaceFactory::DrawCallback());
88 } 90 }
89 91
92 enum { kArbitrarySurfaceNamespace = 3 };
93
90 SurfaceManager manager_; 94 SurfaceManager manager_;
91 FakeSurfaceFactoryClient surface_factory_client_; 95 FakeSurfaceFactoryClient surface_factory_client_;
92 SurfaceFactory factory_; 96 SurfaceFactory factory_;
97 SurfaceIdAllocator id_allocator_;
93 TestSoftwareOutputDevice* software_output_device_; 98 TestSoftwareOutputDevice* software_output_device_;
94 scoped_ptr<FakeOutputSurface> output_surface_; 99 scoped_ptr<FakeOutputSurface> output_surface_;
95 FakeOutputSurface* output_surface_ptr_; 100 FakeOutputSurface* output_surface_ptr_;
96 FakeBeginFrameSource fake_begin_frame_source_;
97 scoped_refptr<base::NullTaskRunner> task_runner_;
98 scoped_ptr<SharedBitmapManager> shared_bitmap_manager_; 101 scoped_ptr<SharedBitmapManager> shared_bitmap_manager_;
99 }; 102 };
100 103
101 class TestDisplayClient : public DisplayClient { 104 class TestDisplayClient : public DisplayClient {
102 public: 105 public:
103 TestDisplayClient() {} 106 TestDisplayClient() {}
104 ~TestDisplayClient() override {} 107 ~TestDisplayClient() override {}
105 108
106 void CommitVSyncParameters(base::TimeTicks timebase,
107 base::TimeDelta interval) override {}
108 void OutputSurfaceLost() override {} 109 void OutputSurfaceLost() override {}
109 void SetMemoryPolicy(const ManagedMemoryPolicy& policy) override {} 110 void SetMemoryPolicy(const ManagedMemoryPolicy& policy) override {}
110 }; 111 };
111 112
112 class TestDisplayScheduler : public DisplayScheduler { 113 class TestDisplayScheduler : public DisplayScheduler {
113 public: 114 public:
114 TestDisplayScheduler(DisplaySchedulerClient* client, 115 TestDisplayScheduler(DisplaySchedulerClient* client,
115 BeginFrameSource* begin_frame_source, 116 BeginFrameSource* begin_frame_source,
116 base::NullTaskRunner* task_runner) 117 base::SingleThreadTaskRunner* task_runner)
117 : DisplayScheduler(client, begin_frame_source, task_runner, 1), 118 : DisplayScheduler(client, begin_frame_source, task_runner, 1),
118 damaged(false), 119 damaged(false),
119 display_resized_(false), 120 display_resized_(false),
120 has_new_root_surface(false), 121 has_new_root_surface(false),
121 swapped(false) { 122 swapped(false) {}
122 begin_frame_source_for_children_.reset(new FakeBeginFrameSource);
123 }
124 123
125 ~TestDisplayScheduler() override {} 124 ~TestDisplayScheduler() override {}
126 125
127 void DisplayResized() override { display_resized_ = true; } 126 void DisplayResized() override { display_resized_ = true; }
128 127
129 void SetNewRootSurface(SurfaceId root_surface_id) override { 128 void SetNewRootSurface(SurfaceId root_surface_id) override {
130 has_new_root_surface = true; 129 has_new_root_surface = true;
131 } 130 }
132 131
133 void SurfaceDamaged(SurfaceId surface_id) override { 132 void SurfaceDamaged(SurfaceId surface_id) override {
134 damaged = true; 133 damaged = true;
135 needs_draw_ = true; 134 needs_draw_ = true;
136 } 135 }
137 136
138 void DidSwapBuffers() override { swapped = true; } 137 void DidSwapBuffers() override { swapped = true; }
139 138
140 void ResetDamageForTest() { 139 void ResetDamageForTest() {
141 damaged = false; 140 damaged = false;
142 display_resized_ = false; 141 display_resized_ = false;
143 has_new_root_surface = false; 142 has_new_root_surface = false;
144 } 143 }
145 144
146 bool damaged; 145 bool damaged;
147 bool display_resized_; 146 bool display_resized_;
148 bool has_new_root_surface; 147 bool has_new_root_surface;
149 bool swapped; 148 bool swapped;
149
150 private:
151 RendererSettings settings_;
152 };
153
154 class TestDisplay : public Display {
155 public:
156 TestDisplay(DisplayClient* client,
157 SurfaceManager* manager,
158 SharedBitmapManager* bitmap_manager,
159 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
160 const RendererSettings& settings,
161 uint32_t compositor_surface_namespace)
162 : Display(client,
163 manager,
164 bitmap_manager,
165 gpu_memory_buffer_manager,
166 settings,
167 compositor_surface_namespace),
168 task_runner_(new base::NullTaskRunner) {}
169
170 TestDisplayScheduler& scheduler() {
171 return *static_cast<TestDisplayScheduler*>(scheduler_.get());
172 }
173
174 protected:
175 void CreateScheduler() override {
176 scheduler_.reset(new TestDisplayScheduler(this, vsync_begin_frame_source_,
177 task_runner_.get()));
178 }
179
180 private:
181 scoped_refptr<base::NullTaskRunner> task_runner_;
150 }; 182 };
151 183
152 void CopyCallback(bool* called, scoped_ptr<CopyOutputResult> result) { 184 void CopyCallback(bool* called, scoped_ptr<CopyOutputResult> result) {
153 *called = true; 185 *called = true;
154 } 186 }
155 187
156 // Check that frame is damaged and swapped only under correct conditions. 188 // Check that frame is damaged and swapped only under correct conditions.
157 TEST_F(DisplayTest, DisplayDamaged) { 189 TEST_F(DisplayTest, DisplayDamaged) {
158 SetUpContext(nullptr); 190 SetUpContext(nullptr);
159 TestDisplayClient client; 191 TestDisplayClient client;
160 RendererSettings settings; 192 RendererSettings settings;
161 settings.partial_swap_enabled = true; 193 settings.partial_swap_enabled = true;
162 settings.finish_rendering_on_resize = true; 194 settings.finish_rendering_on_resize = true;
163 Display display(&client, &manager_, shared_bitmap_manager_.get(), nullptr, 195 TestDisplay display(&client, &manager_, shared_bitmap_manager_.get(), nullptr,
164 settings); 196 settings, id_allocator_.id_namespace());
197 display.Initialize(std::move(output_surface_));
198 TestDisplayScheduler& scheduler = display.scheduler();
165 199
166 TestDisplayScheduler scheduler(&display, &fake_begin_frame_source_, 200 SurfaceId surface_id(id_allocator_.GenerateId());
167 task_runner_.get());
168 display.Initialize(std::move(output_surface_), &scheduler);
169
170 SurfaceId surface_id(7u);
171 EXPECT_FALSE(scheduler.damaged); 201 EXPECT_FALSE(scheduler.damaged);
172 EXPECT_FALSE(scheduler.has_new_root_surface); 202 EXPECT_FALSE(scheduler.has_new_root_surface);
173 display.SetSurfaceId(surface_id, 1.f); 203 display.SetSurfaceId(surface_id, 1.f);
174 EXPECT_FALSE(scheduler.damaged); 204 EXPECT_FALSE(scheduler.damaged);
175 EXPECT_FALSE(scheduler.display_resized_); 205 EXPECT_FALSE(scheduler.display_resized_);
176 EXPECT_TRUE(scheduler.has_new_root_surface); 206 EXPECT_TRUE(scheduler.has_new_root_surface);
177 207
178 scheduler.ResetDamageForTest(); 208 scheduler.ResetDamageForTest();
179 display.Resize(gfx::Size(100, 100)); 209 display.Resize(gfx::Size(100, 100));
180 EXPECT_FALSE(scheduler.damaged); 210 EXPECT_FALSE(scheduler.damaged);
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 public: 445 public:
416 MOCK_METHOD0(shallowFinishCHROMIUM, void()); 446 MOCK_METHOD0(shallowFinishCHROMIUM, void());
417 }; 447 };
418 448
419 TEST_F(DisplayTest, Finish) { 449 TEST_F(DisplayTest, Finish) {
420 scoped_ptr<MockedContext> context(new MockedContext()); 450 scoped_ptr<MockedContext> context(new MockedContext());
421 MockedContext* context_ptr = context.get(); 451 MockedContext* context_ptr = context.get();
422 SetUpContext(std::move(context)); 452 SetUpContext(std::move(context));
423 453
424 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM()).Times(0); 454 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM()).Times(0);
455
456 SurfaceId surface_id(id_allocator_.GenerateId());
457
425 TestDisplayClient client; 458 TestDisplayClient client;
426 RendererSettings settings; 459 RendererSettings settings;
427 settings.partial_swap_enabled = true; 460 settings.partial_swap_enabled = true;
428 settings.finish_rendering_on_resize = true; 461 settings.finish_rendering_on_resize = true;
429 Display display(&client, &manager_, shared_bitmap_manager_.get(), nullptr, 462 TestDisplay display(&client, &manager_, shared_bitmap_manager_.get(), nullptr,
430 settings); 463 settings, surface_id.id_namespace());
464 display.Initialize(std::move(output_surface_));
431 465
432 TestDisplayScheduler scheduler(&display, &fake_begin_frame_source_,
433 task_runner_.get());
434 display.Initialize(std::move(output_surface_), &scheduler);
435
436 SurfaceId surface_id(7u);
437 display.SetSurfaceId(surface_id, 1.f); 466 display.SetSurfaceId(surface_id, 1.f);
438 467
439 display.Resize(gfx::Size(100, 100)); 468 display.Resize(gfx::Size(100, 100));
440 factory_.Create(surface_id); 469 factory_.Create(surface_id);
441 470
442 { 471 {
443 RenderPassList pass_list; 472 RenderPassList pass_list;
444 scoped_ptr<RenderPass> pass = RenderPass::Create(); 473 scoped_ptr<RenderPass> pass = RenderPass::Create();
445 pass->output_rect = gfx::Rect(0, 0, 100, 100); 474 pass->output_rect = gfx::Rect(0, 0, 100, 100);
446 pass->damage_rect = gfx::Rect(10, 10, 1, 1); 475 pass->damage_rect = gfx::Rect(10, 10, 1, 1);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 511
483 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM()); 512 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM());
484 display.Resize(gfx::Size(250, 250)); 513 display.Resize(gfx::Size(250, 250));
485 testing::Mock::VerifyAndClearExpectations(context_ptr); 514 testing::Mock::VerifyAndClearExpectations(context_ptr);
486 515
487 factory_.Destroy(surface_id); 516 factory_.Destroy(surface_id);
488 } 517 }
489 518
490 } // namespace 519 } // namespace
491 } // namespace cc 520 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698