| 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" |
| 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/output/texture_mailbox_deleter.h" |
| 13 #include "cc/quads/render_pass.h" | 14 #include "cc/quads/render_pass.h" |
| 14 #include "cc/resources/shared_bitmap_manager.h" | 15 #include "cc/resources/shared_bitmap_manager.h" |
| 16 #include "cc/scheduler/begin_frame_source.h" |
| 15 #include "cc/surfaces/display_client.h" | 17 #include "cc/surfaces/display_client.h" |
| 18 #include "cc/surfaces/display_scheduler.h" |
| 16 #include "cc/surfaces/surface.h" | 19 #include "cc/surfaces/surface.h" |
| 17 #include "cc/surfaces/surface_factory.h" | 20 #include "cc/surfaces/surface_factory.h" |
| 18 #include "cc/surfaces/surface_factory_client.h" | 21 #include "cc/surfaces/surface_factory_client.h" |
| 19 #include "cc/surfaces/surface_id_allocator.h" | 22 #include "cc/surfaces/surface_id_allocator.h" |
| 20 #include "cc/surfaces/surface_manager.h" | 23 #include "cc/surfaces/surface_manager.h" |
| 21 #include "cc/test/fake_output_surface.h" | 24 #include "cc/test/fake_output_surface.h" |
| 22 #include "cc/test/scheduler_test_common.h" | 25 #include "cc/test/scheduler_test_common.h" |
| 23 #include "cc/test/test_shared_bitmap_manager.h" | 26 #include "cc/test/test_shared_bitmap_manager.h" |
| 24 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 46 }; | 49 }; |
| 47 | 50 |
| 48 class TestSoftwareOutputDevice : public SoftwareOutputDevice { | 51 class TestSoftwareOutputDevice : public SoftwareOutputDevice { |
| 49 public: | 52 public: |
| 50 TestSoftwareOutputDevice() {} | 53 TestSoftwareOutputDevice() {} |
| 51 | 54 |
| 52 gfx::Rect damage_rect() const { return damage_rect_; } | 55 gfx::Rect damage_rect() const { return damage_rect_; } |
| 53 gfx::Size viewport_pixel_size() const { return viewport_pixel_size_; } | 56 gfx::Size viewport_pixel_size() const { return viewport_pixel_size_; } |
| 54 }; | 57 }; |
| 55 | 58 |
| 56 class DisplayTest : public testing::Test { | |
| 57 public: | |
| 58 DisplayTest() | |
| 59 : factory_(&manager_, &surface_factory_client_), | |
| 60 id_allocator_(kArbitrarySurfaceNamespace), | |
| 61 software_output_device_(nullptr), | |
| 62 task_runner_(new base::NullTaskRunner) { | |
| 63 id_allocator_.RegisterSurfaceIdNamespace(&manager_); | |
| 64 } | |
| 65 | |
| 66 protected: | |
| 67 void SetUpContext(std::unique_ptr<TestWebGraphicsContext3D> context) { | |
| 68 if (context) { | |
| 69 output_surface_ = FakeOutputSurface::Create3d( | |
| 70 TestContextProvider::Create(std::move(context))); | |
| 71 } else { | |
| 72 std::unique_ptr<TestSoftwareOutputDevice> output_device( | |
| 73 new TestSoftwareOutputDevice); | |
| 74 software_output_device_ = output_device.get(); | |
| 75 output_surface_ = | |
| 76 FakeOutputSurface::CreateSoftware(std::move(output_device)); | |
| 77 } | |
| 78 shared_bitmap_manager_.reset(new TestSharedBitmapManager); | |
| 79 output_surface_ptr_ = output_surface_.get(); | |
| 80 } | |
| 81 | |
| 82 void SubmitCompositorFrame(RenderPassList* pass_list, SurfaceId surface_id) { | |
| 83 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); | |
| 84 pass_list->swap(frame_data->render_pass_list); | |
| 85 | |
| 86 std::unique_ptr<CompositorFrame> frame(new CompositorFrame); | |
| 87 frame->delegated_frame_data = std::move(frame_data); | |
| 88 | |
| 89 factory_.SubmitCompositorFrame(surface_id, std::move(frame), | |
| 90 SurfaceFactory::DrawCallback()); | |
| 91 } | |
| 92 | |
| 93 enum { kArbitrarySurfaceNamespace = 3 }; | |
| 94 | |
| 95 SurfaceManager manager_; | |
| 96 FakeSurfaceFactoryClient surface_factory_client_; | |
| 97 SurfaceFactory factory_; | |
| 98 SurfaceIdAllocator id_allocator_; | |
| 99 TestSoftwareOutputDevice* software_output_device_; | |
| 100 std::unique_ptr<FakeOutputSurface> output_surface_; | |
| 101 FakeOutputSurface* output_surface_ptr_; | |
| 102 scoped_refptr<base::NullTaskRunner> task_runner_; | |
| 103 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager_; | |
| 104 }; | |
| 105 | |
| 106 class StubDisplayClient : public DisplayClient { | |
| 107 public: | |
| 108 void DisplayOutputSurfaceLost() override {} | |
| 109 void DisplaySetMemoryPolicy(const ManagedMemoryPolicy& policy) override {} | |
| 110 }; | |
| 111 | |
| 112 class TestDisplayScheduler : public DisplayScheduler { | 59 class TestDisplayScheduler : public DisplayScheduler { |
| 113 public: | 60 public: |
| 114 TestDisplayScheduler(DisplaySchedulerClient* client, | 61 TestDisplayScheduler(BeginFrameSource* begin_frame_source, |
| 115 BeginFrameSource* begin_frame_source, | |
| 116 base::SingleThreadTaskRunner* task_runner) | 62 base::SingleThreadTaskRunner* task_runner) |
| 117 : DisplayScheduler(client, begin_frame_source, task_runner, 1), | 63 : DisplayScheduler(begin_frame_source, task_runner, 1), |
| 118 damaged(false), | 64 damaged(false), |
| 119 display_resized_(false), | 65 display_resized_(false), |
| 120 has_new_root_surface(false), | 66 has_new_root_surface(false), |
| 121 swapped(false) {} | 67 swapped(false) {} |
| 122 | 68 |
| 123 ~TestDisplayScheduler() override {} | 69 ~TestDisplayScheduler() override {} |
| 124 | 70 |
| 125 void DisplayResized() override { display_resized_ = true; } | 71 void DisplayResized() override { display_resized_ = true; } |
| 126 | 72 |
| 127 void SetNewRootSurface(SurfaceId root_surface_id) override { | 73 void SetNewRootSurface(SurfaceId root_surface_id) override { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 138 void ResetDamageForTest() { | 84 void ResetDamageForTest() { |
| 139 damaged = false; | 85 damaged = false; |
| 140 display_resized_ = false; | 86 display_resized_ = false; |
| 141 has_new_root_surface = false; | 87 has_new_root_surface = false; |
| 142 } | 88 } |
| 143 | 89 |
| 144 bool damaged; | 90 bool damaged; |
| 145 bool display_resized_; | 91 bool display_resized_; |
| 146 bool has_new_root_surface; | 92 bool has_new_root_surface; |
| 147 bool swapped; | 93 bool swapped; |
| 148 | |
| 149 private: | |
| 150 RendererSettings settings_; | |
| 151 }; | 94 }; |
| 152 | 95 |
| 153 class TestDisplay : public Display { | 96 class DisplayTest : public testing::Test { |
| 154 public: | 97 public: |
| 155 TestDisplay(SurfaceManager* manager, | 98 DisplayTest() |
| 156 SharedBitmapManager* bitmap_manager, | 99 : factory_(&manager_, &surface_factory_client_), |
| 157 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 100 id_allocator_(kArbitrarySurfaceNamespace), |
| 158 const RendererSettings& settings, | 101 task_runner_(new base::NullTaskRunner) { |
| 159 uint32_t compositor_surface_namespace, | 102 id_allocator_.RegisterSurfaceIdNamespace(&manager_); |
| 160 base::SingleThreadTaskRunner* task_runner, | 103 } |
| 161 std::unique_ptr<OutputSurface> output_surface) | |
| 162 : Display(manager, | |
| 163 bitmap_manager, | |
| 164 gpu_memory_buffer_manager, | |
| 165 settings, | |
| 166 compositor_surface_namespace, | |
| 167 task_runner, | |
| 168 std::move(output_surface)), | |
| 169 task_runner_(task_runner) {} | |
| 170 | 104 |
| 171 TestDisplayScheduler& scheduler() { | 105 void SetUpDisplay(const RendererSettings& settings, |
| 172 return *static_cast<TestDisplayScheduler*>(scheduler_.get()); | 106 std::unique_ptr<TestWebGraphicsContext3D> context) { |
| 107 std::unique_ptr<BeginFrameSource> begin_frame_source( |
| 108 new StubBeginFrameSource); |
| 109 |
| 110 std::unique_ptr<FakeOutputSurface> output_surface; |
| 111 if (context) { |
| 112 output_surface = FakeOutputSurface::Create3d(std::move(context)); |
| 113 } else { |
| 114 std::unique_ptr<TestSoftwareOutputDevice> device( |
| 115 new TestSoftwareOutputDevice); |
| 116 software_output_device_ = device.get(); |
| 117 output_surface = FakeOutputSurface::CreateSoftware(std::move(device)); |
| 118 } |
| 119 output_surface_ = output_surface.get(); |
| 120 |
| 121 std::unique_ptr<TestDisplayScheduler> scheduler( |
| 122 new TestDisplayScheduler(begin_frame_source.get(), task_runner_.get())); |
| 123 scheduler_ = scheduler.get(); |
| 124 |
| 125 display_ = base::MakeUnique<Display>( |
| 126 &manager_, &shared_bitmap_manager_, |
| 127 nullptr /* gpu_memory_buffer_manager */, settings, |
| 128 id_allocator_.id_namespace(), std::move(begin_frame_source), |
| 129 std::move(output_surface), std::move(scheduler), |
| 130 base::MakeUnique<TextureMailboxDeleter>(task_runner_.get())); |
| 173 } | 131 } |
| 174 | 132 |
| 175 protected: | 133 protected: |
| 176 void CreateScheduler() override { | 134 void SubmitCompositorFrame(RenderPassList* pass_list, SurfaceId surface_id) { |
| 177 scheduler_.reset(new TestDisplayScheduler(this, vsync_begin_frame_source_, | 135 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); |
| 178 task_runner_)); | 136 pass_list->swap(frame_data->render_pass_list); |
| 137 |
| 138 std::unique_ptr<CompositorFrame> frame(new CompositorFrame); |
| 139 frame->delegated_frame_data = std::move(frame_data); |
| 140 |
| 141 factory_.SubmitCompositorFrame(surface_id, std::move(frame), |
| 142 SurfaceFactory::DrawCallback()); |
| 179 } | 143 } |
| 180 | 144 |
| 181 private: | 145 static constexpr int kArbitrarySurfaceNamespace = 3; |
| 182 base::SingleThreadTaskRunner* task_runner_; | 146 |
| 147 SurfaceManager manager_; |
| 148 FakeSurfaceFactoryClient surface_factory_client_; |
| 149 SurfaceFactory factory_; |
| 150 SurfaceIdAllocator id_allocator_; |
| 151 scoped_refptr<base::NullTaskRunner> task_runner_; |
| 152 TestSharedBitmapManager shared_bitmap_manager_; |
| 153 std::unique_ptr<Display> display_; |
| 154 TestSoftwareOutputDevice* software_output_device_ = nullptr; |
| 155 FakeOutputSurface* output_surface_ = nullptr; |
| 156 TestDisplayScheduler* scheduler_ = nullptr; |
| 157 }; |
| 158 |
| 159 class StubDisplayClient : public DisplayClient { |
| 160 public: |
| 161 void DisplayOutputSurfaceLost() override {} |
| 162 void DisplaySetMemoryPolicy(const ManagedMemoryPolicy& policy) override {} |
| 183 }; | 163 }; |
| 184 | 164 |
| 185 void CopyCallback(bool* called, std::unique_ptr<CopyOutputResult> result) { | 165 void CopyCallback(bool* called, std::unique_ptr<CopyOutputResult> result) { |
| 186 *called = true; | 166 *called = true; |
| 187 } | 167 } |
| 188 | 168 |
| 189 // Check that frame is damaged and swapped only under correct conditions. | 169 // Check that frame is damaged and swapped only under correct conditions. |
| 190 TEST_F(DisplayTest, DisplayDamaged) { | 170 TEST_F(DisplayTest, DisplayDamaged) { |
| 191 SetUpContext(nullptr); | |
| 192 StubDisplayClient client; | |
| 193 RendererSettings settings; | 171 RendererSettings settings; |
| 194 settings.partial_swap_enabled = true; | 172 settings.partial_swap_enabled = true; |
| 195 settings.finish_rendering_on_resize = true; | 173 settings.finish_rendering_on_resize = true; |
| 196 TestDisplay display(&manager_, shared_bitmap_manager_.get(), nullptr, | 174 SetUpDisplay(settings, nullptr); |
| 197 settings, id_allocator_.id_namespace(), | 175 |
| 198 task_runner_.get(), std::move(output_surface_)); | 176 StubDisplayClient client; |
| 199 display.Initialize(&client); | 177 display_->Initialize(&client); |
| 200 TestDisplayScheduler& scheduler = display.scheduler(); | |
| 201 | 178 |
| 202 SurfaceId surface_id(id_allocator_.GenerateId()); | 179 SurfaceId surface_id(id_allocator_.GenerateId()); |
| 203 EXPECT_FALSE(scheduler.damaged); | 180 EXPECT_FALSE(scheduler_->damaged); |
| 204 EXPECT_FALSE(scheduler.has_new_root_surface); | 181 EXPECT_FALSE(scheduler_->has_new_root_surface); |
| 205 display.SetSurfaceId(surface_id, 1.f); | 182 display_->SetSurfaceId(surface_id, 1.f); |
| 206 EXPECT_FALSE(scheduler.damaged); | 183 EXPECT_FALSE(scheduler_->damaged); |
| 207 EXPECT_FALSE(scheduler.display_resized_); | 184 EXPECT_FALSE(scheduler_->display_resized_); |
| 208 EXPECT_TRUE(scheduler.has_new_root_surface); | 185 EXPECT_TRUE(scheduler_->has_new_root_surface); |
| 209 | 186 |
| 210 scheduler.ResetDamageForTest(); | 187 scheduler_->ResetDamageForTest(); |
| 211 display.Resize(gfx::Size(100, 100)); | 188 display_->Resize(gfx::Size(100, 100)); |
| 212 EXPECT_FALSE(scheduler.damaged); | 189 EXPECT_FALSE(scheduler_->damaged); |
| 213 EXPECT_TRUE(scheduler.display_resized_); | 190 EXPECT_TRUE(scheduler_->display_resized_); |
| 214 EXPECT_FALSE(scheduler.has_new_root_surface); | 191 EXPECT_FALSE(scheduler_->has_new_root_surface); |
| 215 | 192 |
| 216 factory_.Create(surface_id); | 193 factory_.Create(surface_id); |
| 217 | 194 |
| 218 // First draw from surface should have full damage. | 195 // First draw from surface should have full damage. |
| 219 RenderPassList pass_list; | 196 RenderPassList pass_list; |
| 220 std::unique_ptr<RenderPass> pass = RenderPass::Create(); | 197 std::unique_ptr<RenderPass> pass = RenderPass::Create(); |
| 221 pass->output_rect = gfx::Rect(0, 0, 100, 100); | 198 pass->output_rect = gfx::Rect(0, 0, 100, 100); |
| 222 pass->damage_rect = gfx::Rect(10, 10, 1, 1); | 199 pass->damage_rect = gfx::Rect(10, 10, 1, 1); |
| 223 pass->id = RenderPassId(1, 1); | 200 pass->id = RenderPassId(1, 1); |
| 224 pass_list.push_back(std::move(pass)); | 201 pass_list.push_back(std::move(pass)); |
| 225 | 202 |
| 226 scheduler.ResetDamageForTest(); | 203 scheduler_->ResetDamageForTest(); |
| 227 SubmitCompositorFrame(&pass_list, surface_id); | 204 SubmitCompositorFrame(&pass_list, surface_id); |
| 228 EXPECT_TRUE(scheduler.damaged); | 205 EXPECT_TRUE(scheduler_->damaged); |
| 229 EXPECT_FALSE(scheduler.display_resized_); | 206 EXPECT_FALSE(scheduler_->display_resized_); |
| 230 EXPECT_FALSE(scheduler.has_new_root_surface); | 207 EXPECT_FALSE(scheduler_->has_new_root_surface); |
| 231 | 208 |
| 232 EXPECT_FALSE(scheduler.swapped); | 209 EXPECT_FALSE(scheduler_->swapped); |
| 233 EXPECT_EQ(0u, output_surface_ptr_->num_sent_frames()); | 210 EXPECT_EQ(0u, output_surface_->num_sent_frames()); |
| 234 display.DrawAndSwap(); | 211 display_->DrawAndSwap(); |
| 235 EXPECT_TRUE(scheduler.swapped); | 212 EXPECT_TRUE(scheduler_->swapped); |
| 236 EXPECT_EQ(1u, output_surface_ptr_->num_sent_frames()); | 213 EXPECT_EQ(1u, output_surface_->num_sent_frames()); |
| 237 EXPECT_EQ(gfx::Size(100, 100), | 214 EXPECT_EQ(gfx::Size(100, 100), |
| 238 software_output_device_->viewport_pixel_size()); | 215 software_output_device_->viewport_pixel_size()); |
| 239 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), software_output_device_->damage_rect()); | 216 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), software_output_device_->damage_rect()); |
| 240 | 217 |
| 241 { | 218 { |
| 242 // Only damaged portion should be swapped. | 219 // Only damaged portion should be swapped. |
| 243 pass = RenderPass::Create(); | 220 pass = RenderPass::Create(); |
| 244 pass->output_rect = gfx::Rect(0, 0, 100, 100); | 221 pass->output_rect = gfx::Rect(0, 0, 100, 100); |
| 245 pass->damage_rect = gfx::Rect(10, 10, 1, 1); | 222 pass->damage_rect = gfx::Rect(10, 10, 1, 1); |
| 246 pass->id = RenderPassId(1, 1); | 223 pass->id = RenderPassId(1, 1); |
| 247 | 224 |
| 248 pass_list.push_back(std::move(pass)); | 225 pass_list.push_back(std::move(pass)); |
| 249 scheduler.ResetDamageForTest(); | 226 scheduler_->ResetDamageForTest(); |
| 250 SubmitCompositorFrame(&pass_list, surface_id); | 227 SubmitCompositorFrame(&pass_list, surface_id); |
| 251 EXPECT_TRUE(scheduler.damaged); | 228 EXPECT_TRUE(scheduler_->damaged); |
| 252 EXPECT_FALSE(scheduler.display_resized_); | 229 EXPECT_FALSE(scheduler_->display_resized_); |
| 253 EXPECT_FALSE(scheduler.has_new_root_surface); | 230 EXPECT_FALSE(scheduler_->has_new_root_surface); |
| 254 | 231 |
| 255 scheduler.swapped = false; | 232 scheduler_->swapped = false; |
| 256 display.DrawAndSwap(); | 233 display_->DrawAndSwap(); |
| 257 EXPECT_TRUE(scheduler.swapped); | 234 EXPECT_TRUE(scheduler_->swapped); |
| 258 EXPECT_EQ(2u, output_surface_ptr_->num_sent_frames()); | 235 EXPECT_EQ(2u, output_surface_->num_sent_frames()); |
| 259 EXPECT_EQ(gfx::Size(100, 100), | 236 EXPECT_EQ(gfx::Size(100, 100), |
| 260 software_output_device_->viewport_pixel_size()); | 237 software_output_device_->viewport_pixel_size()); |
| 261 EXPECT_EQ(gfx::Rect(10, 10, 1, 1), software_output_device_->damage_rect()); | 238 EXPECT_EQ(gfx::Rect(10, 10, 1, 1), software_output_device_->damage_rect()); |
| 262 } | 239 } |
| 263 | 240 |
| 264 { | 241 { |
| 265 // Pass has no damage so shouldn't be swapped. | 242 // Pass has no damage so shouldn't be swapped. |
| 266 pass = RenderPass::Create(); | 243 pass = RenderPass::Create(); |
| 267 pass->output_rect = gfx::Rect(0, 0, 100, 100); | 244 pass->output_rect = gfx::Rect(0, 0, 100, 100); |
| 268 pass->damage_rect = gfx::Rect(10, 10, 0, 0); | 245 pass->damage_rect = gfx::Rect(10, 10, 0, 0); |
| 269 pass->id = RenderPassId(1, 1); | 246 pass->id = RenderPassId(1, 1); |
| 270 | 247 |
| 271 pass_list.push_back(std::move(pass)); | 248 pass_list.push_back(std::move(pass)); |
| 272 scheduler.ResetDamageForTest(); | 249 scheduler_->ResetDamageForTest(); |
| 273 SubmitCompositorFrame(&pass_list, surface_id); | 250 SubmitCompositorFrame(&pass_list, surface_id); |
| 274 EXPECT_TRUE(scheduler.damaged); | 251 EXPECT_TRUE(scheduler_->damaged); |
| 275 EXPECT_FALSE(scheduler.display_resized_); | 252 EXPECT_FALSE(scheduler_->display_resized_); |
| 276 EXPECT_FALSE(scheduler.has_new_root_surface); | 253 EXPECT_FALSE(scheduler_->has_new_root_surface); |
| 277 | 254 |
| 278 scheduler.swapped = false; | 255 scheduler_->swapped = false; |
| 279 display.DrawAndSwap(); | 256 display_->DrawAndSwap(); |
| 280 EXPECT_TRUE(scheduler.swapped); | 257 EXPECT_TRUE(scheduler_->swapped); |
| 281 EXPECT_EQ(2u, output_surface_ptr_->num_sent_frames()); | 258 EXPECT_EQ(2u, output_surface_->num_sent_frames()); |
| 282 } | 259 } |
| 283 | 260 |
| 284 { | 261 { |
| 285 // Pass is wrong size so shouldn't be swapped. | 262 // Pass is wrong size so shouldn't be swapped. |
| 286 pass = RenderPass::Create(); | 263 pass = RenderPass::Create(); |
| 287 pass->output_rect = gfx::Rect(0, 0, 99, 99); | 264 pass->output_rect = gfx::Rect(0, 0, 99, 99); |
| 288 pass->damage_rect = gfx::Rect(10, 10, 10, 10); | 265 pass->damage_rect = gfx::Rect(10, 10, 10, 10); |
| 289 pass->id = RenderPassId(1, 1); | 266 pass->id = RenderPassId(1, 1); |
| 290 | 267 |
| 291 pass_list.push_back(std::move(pass)); | 268 pass_list.push_back(std::move(pass)); |
| 292 scheduler.ResetDamageForTest(); | 269 scheduler_->ResetDamageForTest(); |
| 293 SubmitCompositorFrame(&pass_list, surface_id); | 270 SubmitCompositorFrame(&pass_list, surface_id); |
| 294 EXPECT_TRUE(scheduler.damaged); | 271 EXPECT_TRUE(scheduler_->damaged); |
| 295 EXPECT_FALSE(scheduler.display_resized_); | 272 EXPECT_FALSE(scheduler_->display_resized_); |
| 296 EXPECT_FALSE(scheduler.has_new_root_surface); | 273 EXPECT_FALSE(scheduler_->has_new_root_surface); |
| 297 | 274 |
| 298 scheduler.swapped = false; | 275 scheduler_->swapped = false; |
| 299 display.DrawAndSwap(); | 276 display_->DrawAndSwap(); |
| 300 EXPECT_TRUE(scheduler.swapped); | 277 EXPECT_TRUE(scheduler_->swapped); |
| 301 EXPECT_EQ(2u, output_surface_ptr_->num_sent_frames()); | 278 EXPECT_EQ(2u, output_surface_->num_sent_frames()); |
| 302 } | 279 } |
| 303 | 280 |
| 304 { | 281 { |
| 305 // Previous frame wasn't swapped, so next swap should have full damage. | 282 // Previous frame wasn't swapped, so next swap should have full damage. |
| 306 pass = RenderPass::Create(); | 283 pass = RenderPass::Create(); |
| 307 pass->output_rect = gfx::Rect(0, 0, 100, 100); | 284 pass->output_rect = gfx::Rect(0, 0, 100, 100); |
| 308 pass->damage_rect = gfx::Rect(10, 10, 0, 0); | 285 pass->damage_rect = gfx::Rect(10, 10, 0, 0); |
| 309 pass->id = RenderPassId(1, 1); | 286 pass->id = RenderPassId(1, 1); |
| 310 | 287 |
| 311 pass_list.push_back(std::move(pass)); | 288 pass_list.push_back(std::move(pass)); |
| 312 scheduler.ResetDamageForTest(); | 289 scheduler_->ResetDamageForTest(); |
| 313 SubmitCompositorFrame(&pass_list, surface_id); | 290 SubmitCompositorFrame(&pass_list, surface_id); |
| 314 EXPECT_TRUE(scheduler.damaged); | 291 EXPECT_TRUE(scheduler_->damaged); |
| 315 EXPECT_FALSE(scheduler.display_resized_); | 292 EXPECT_FALSE(scheduler_->display_resized_); |
| 316 EXPECT_FALSE(scheduler.has_new_root_surface); | 293 EXPECT_FALSE(scheduler_->has_new_root_surface); |
| 317 | 294 |
| 318 scheduler.swapped = false; | 295 scheduler_->swapped = false; |
| 319 display.DrawAndSwap(); | 296 display_->DrawAndSwap(); |
| 320 EXPECT_TRUE(scheduler.swapped); | 297 EXPECT_TRUE(scheduler_->swapped); |
| 321 EXPECT_EQ(3u, output_surface_ptr_->num_sent_frames()); | 298 EXPECT_EQ(3u, output_surface_->num_sent_frames()); |
| 322 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), | 299 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 323 software_output_device_->damage_rect()); | 300 software_output_device_->damage_rect()); |
| 324 } | 301 } |
| 325 | 302 |
| 326 { | 303 { |
| 327 // Pass has copy output request so should be swapped. | 304 // Pass has copy output request so should be swapped. |
| 328 pass = RenderPass::Create(); | 305 pass = RenderPass::Create(); |
| 329 pass->output_rect = gfx::Rect(0, 0, 100, 100); | 306 pass->output_rect = gfx::Rect(0, 0, 100, 100); |
| 330 pass->damage_rect = gfx::Rect(10, 10, 0, 0); | 307 pass->damage_rect = gfx::Rect(10, 10, 0, 0); |
| 331 bool copy_called = false; | 308 bool copy_called = false; |
| 332 pass->copy_requests.push_back(CopyOutputRequest::CreateRequest( | 309 pass->copy_requests.push_back(CopyOutputRequest::CreateRequest( |
| 333 base::Bind(&CopyCallback, ©_called))); | 310 base::Bind(&CopyCallback, ©_called))); |
| 334 pass->id = RenderPassId(1, 1); | 311 pass->id = RenderPassId(1, 1); |
| 335 | 312 |
| 336 pass_list.push_back(std::move(pass)); | 313 pass_list.push_back(std::move(pass)); |
| 337 scheduler.ResetDamageForTest(); | 314 scheduler_->ResetDamageForTest(); |
| 338 SubmitCompositorFrame(&pass_list, surface_id); | 315 SubmitCompositorFrame(&pass_list, surface_id); |
| 339 EXPECT_TRUE(scheduler.damaged); | 316 EXPECT_TRUE(scheduler_->damaged); |
| 340 EXPECT_FALSE(scheduler.display_resized_); | 317 EXPECT_FALSE(scheduler_->display_resized_); |
| 341 EXPECT_FALSE(scheduler.has_new_root_surface); | 318 EXPECT_FALSE(scheduler_->has_new_root_surface); |
| 342 | 319 |
| 343 scheduler.swapped = false; | 320 scheduler_->swapped = false; |
| 344 display.DrawAndSwap(); | 321 display_->DrawAndSwap(); |
| 345 EXPECT_TRUE(scheduler.swapped); | 322 EXPECT_TRUE(scheduler_->swapped); |
| 346 EXPECT_EQ(4u, output_surface_ptr_->num_sent_frames()); | 323 EXPECT_EQ(4u, output_surface_->num_sent_frames()); |
| 347 EXPECT_TRUE(copy_called); | 324 EXPECT_TRUE(copy_called); |
| 348 } | 325 } |
| 349 | 326 |
| 350 // Pass has no damage, so shouldn't be swapped, but latency info should be | 327 // Pass has no damage, so shouldn't be swapped, but latency info should be |
| 351 // saved for next swap. | 328 // saved for next swap. |
| 352 { | 329 { |
| 353 pass = RenderPass::Create(); | 330 pass = RenderPass::Create(); |
| 354 pass->output_rect = gfx::Rect(0, 0, 100, 100); | 331 pass->output_rect = gfx::Rect(0, 0, 100, 100); |
| 355 pass->damage_rect = gfx::Rect(10, 10, 0, 0); | 332 pass->damage_rect = gfx::Rect(10, 10, 0, 0); |
| 356 pass->id = RenderPassId(1, 1); | 333 pass->id = RenderPassId(1, 1); |
| 357 | 334 |
| 358 pass_list.push_back(std::move(pass)); | 335 pass_list.push_back(std::move(pass)); |
| 359 scheduler.ResetDamageForTest(); | 336 scheduler_->ResetDamageForTest(); |
| 360 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); | 337 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); |
| 361 pass_list.swap(frame_data->render_pass_list); | 338 pass_list.swap(frame_data->render_pass_list); |
| 362 | 339 |
| 363 std::unique_ptr<CompositorFrame> frame(new CompositorFrame); | 340 std::unique_ptr<CompositorFrame> frame(new CompositorFrame); |
| 364 frame->delegated_frame_data = std::move(frame_data); | 341 frame->delegated_frame_data = std::move(frame_data); |
| 365 frame->metadata.latency_info.push_back(ui::LatencyInfo()); | 342 frame->metadata.latency_info.push_back(ui::LatencyInfo()); |
| 366 | 343 |
| 367 factory_.SubmitCompositorFrame(surface_id, std::move(frame), | 344 factory_.SubmitCompositorFrame(surface_id, std::move(frame), |
| 368 SurfaceFactory::DrawCallback()); | 345 SurfaceFactory::DrawCallback()); |
| 369 EXPECT_TRUE(scheduler.damaged); | 346 EXPECT_TRUE(scheduler_->damaged); |
| 370 EXPECT_FALSE(scheduler.display_resized_); | 347 EXPECT_FALSE(scheduler_->display_resized_); |
| 371 EXPECT_FALSE(scheduler.has_new_root_surface); | 348 EXPECT_FALSE(scheduler_->has_new_root_surface); |
| 372 | 349 |
| 373 scheduler.swapped = false; | 350 scheduler_->swapped = false; |
| 374 display.DrawAndSwap(); | 351 display_->DrawAndSwap(); |
| 375 EXPECT_TRUE(scheduler.swapped); | 352 EXPECT_TRUE(scheduler_->swapped); |
| 376 EXPECT_EQ(4u, output_surface_ptr_->num_sent_frames()); | 353 EXPECT_EQ(4u, output_surface_->num_sent_frames()); |
| 377 } | 354 } |
| 378 | 355 |
| 379 // Resize should cause a swap if no frame was swapped at the previous size. | 356 // Resize should cause a swap if no frame was swapped at the previous size. |
| 380 { | 357 { |
| 381 scheduler.swapped = false; | 358 scheduler_->swapped = false; |
| 382 display.Resize(gfx::Size(200, 200)); | 359 display_->Resize(gfx::Size(200, 200)); |
| 383 EXPECT_FALSE(scheduler.swapped); | 360 EXPECT_FALSE(scheduler_->swapped); |
| 384 EXPECT_EQ(4u, output_surface_ptr_->num_sent_frames()); | 361 EXPECT_EQ(4u, output_surface_->num_sent_frames()); |
| 385 | 362 |
| 386 pass = RenderPass::Create(); | 363 pass = RenderPass::Create(); |
| 387 pass->output_rect = gfx::Rect(0, 0, 200, 200); | 364 pass->output_rect = gfx::Rect(0, 0, 200, 200); |
| 388 pass->damage_rect = gfx::Rect(10, 10, 10, 10); | 365 pass->damage_rect = gfx::Rect(10, 10, 10, 10); |
| 389 pass->id = RenderPassId(1, 1); | 366 pass->id = RenderPassId(1, 1); |
| 390 | 367 |
| 391 pass_list.push_back(std::move(pass)); | 368 pass_list.push_back(std::move(pass)); |
| 392 scheduler.ResetDamageForTest(); | 369 scheduler_->ResetDamageForTest(); |
| 393 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); | 370 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); |
| 394 pass_list.swap(frame_data->render_pass_list); | 371 pass_list.swap(frame_data->render_pass_list); |
| 395 | 372 |
| 396 std::unique_ptr<CompositorFrame> frame(new CompositorFrame); | 373 std::unique_ptr<CompositorFrame> frame(new CompositorFrame); |
| 397 frame->delegated_frame_data = std::move(frame_data); | 374 frame->delegated_frame_data = std::move(frame_data); |
| 398 | 375 |
| 399 factory_.SubmitCompositorFrame(surface_id, std::move(frame), | 376 factory_.SubmitCompositorFrame(surface_id, std::move(frame), |
| 400 SurfaceFactory::DrawCallback()); | 377 SurfaceFactory::DrawCallback()); |
| 401 EXPECT_TRUE(scheduler.damaged); | 378 EXPECT_TRUE(scheduler_->damaged); |
| 402 EXPECT_FALSE(scheduler.display_resized_); | 379 EXPECT_FALSE(scheduler_->display_resized_); |
| 403 EXPECT_FALSE(scheduler.has_new_root_surface); | 380 EXPECT_FALSE(scheduler_->has_new_root_surface); |
| 404 | 381 |
| 405 scheduler.swapped = false; | 382 scheduler_->swapped = false; |
| 406 display.Resize(gfx::Size(100, 100)); | 383 display_->Resize(gfx::Size(100, 100)); |
| 407 EXPECT_TRUE(scheduler.swapped); | 384 EXPECT_TRUE(scheduler_->swapped); |
| 408 EXPECT_EQ(5u, output_surface_ptr_->num_sent_frames()); | 385 EXPECT_EQ(5u, output_surface_->num_sent_frames()); |
| 409 | 386 |
| 410 // Latency info from previous frame should be sent now. | 387 // Latency info from previous frame should be sent now. |
| 411 EXPECT_EQ( | 388 EXPECT_EQ(1u, |
| 412 1u, | 389 output_surface_->last_sent_frame().metadata.latency_info.size()); |
| 413 output_surface_ptr_->last_sent_frame().metadata.latency_info.size()); | |
| 414 } | 390 } |
| 415 | 391 |
| 416 { | 392 { |
| 417 // Surface that's damaged completely should be resized and swapped. | 393 // Surface that's damaged completely should be resized and swapped. |
| 418 pass = RenderPass::Create(); | 394 pass = RenderPass::Create(); |
| 419 pass->output_rect = gfx::Rect(0, 0, 99, 99); | 395 pass->output_rect = gfx::Rect(0, 0, 99, 99); |
| 420 pass->damage_rect = gfx::Rect(0, 0, 99, 99); | 396 pass->damage_rect = gfx::Rect(0, 0, 99, 99); |
| 421 pass->id = RenderPassId(1, 1); | 397 pass->id = RenderPassId(1, 1); |
| 422 | 398 |
| 423 pass_list.push_back(std::move(pass)); | 399 pass_list.push_back(std::move(pass)); |
| 424 scheduler.ResetDamageForTest(); | 400 scheduler_->ResetDamageForTest(); |
| 425 SubmitCompositorFrame(&pass_list, surface_id); | 401 SubmitCompositorFrame(&pass_list, surface_id); |
| 426 EXPECT_TRUE(scheduler.damaged); | 402 EXPECT_TRUE(scheduler_->damaged); |
| 427 EXPECT_FALSE(scheduler.display_resized_); | 403 EXPECT_FALSE(scheduler_->display_resized_); |
| 428 EXPECT_FALSE(scheduler.has_new_root_surface); | 404 EXPECT_FALSE(scheduler_->has_new_root_surface); |
| 429 | 405 |
| 430 scheduler.swapped = false; | 406 scheduler_->swapped = false; |
| 431 display.DrawAndSwap(); | 407 display_->DrawAndSwap(); |
| 432 EXPECT_TRUE(scheduler.swapped); | 408 EXPECT_TRUE(scheduler_->swapped); |
| 433 EXPECT_EQ(6u, output_surface_ptr_->num_sent_frames()); | 409 EXPECT_EQ(6u, output_surface_->num_sent_frames()); |
| 434 EXPECT_EQ(gfx::Size(100, 100), | 410 EXPECT_EQ(gfx::Size(100, 100), |
| 435 software_output_device_->viewport_pixel_size()); | 411 software_output_device_->viewport_pixel_size()); |
| 436 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), | 412 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 437 software_output_device_->damage_rect()); | 413 software_output_device_->damage_rect()); |
| 438 EXPECT_EQ( | 414 EXPECT_EQ(0u, |
| 439 0u, | 415 output_surface_->last_sent_frame().metadata.latency_info.size()); |
| 440 output_surface_ptr_->last_sent_frame().metadata.latency_info.size()); | |
| 441 } | 416 } |
| 442 | 417 |
| 443 factory_.Destroy(surface_id); | 418 factory_.Destroy(surface_id); |
| 444 } | 419 } |
| 445 | 420 |
| 446 class MockedContext : public TestWebGraphicsContext3D { | 421 class MockedContext : public TestWebGraphicsContext3D { |
| 447 public: | 422 public: |
| 448 MOCK_METHOD0(shallowFinishCHROMIUM, void()); | 423 MOCK_METHOD0(shallowFinishCHROMIUM, void()); |
| 449 }; | 424 }; |
| 450 | 425 |
| 451 TEST_F(DisplayTest, Finish) { | 426 TEST_F(DisplayTest, Finish) { |
| 452 std::unique_ptr<MockedContext> context(new MockedContext()); | |
| 453 MockedContext* context_ptr = context.get(); | |
| 454 SetUpContext(std::move(context)); | |
| 455 | |
| 456 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM()).Times(0); | |
| 457 | |
| 458 SurfaceId surface_id(id_allocator_.GenerateId()); | 427 SurfaceId surface_id(id_allocator_.GenerateId()); |
| 459 | 428 |
| 460 StubDisplayClient client; | |
| 461 RendererSettings settings; | 429 RendererSettings settings; |
| 462 settings.partial_swap_enabled = true; | 430 settings.partial_swap_enabled = true; |
| 463 settings.finish_rendering_on_resize = true; | 431 settings.finish_rendering_on_resize = true; |
| 464 TestDisplay display(&manager_, shared_bitmap_manager_.get(), nullptr, | |
| 465 settings, surface_id.id_namespace(), task_runner_.get(), | |
| 466 std::move(output_surface_)); | |
| 467 display.Initialize(&client); | |
| 468 | 432 |
| 469 display.SetSurfaceId(surface_id, 1.f); | 433 std::unique_ptr<MockedContext> context(new MockedContext()); |
| 434 MockedContext* context_ptr = context.get(); |
| 435 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM()).Times(0); |
| 470 | 436 |
| 471 display.Resize(gfx::Size(100, 100)); | 437 SetUpDisplay(settings, std::move(context)); |
| 438 |
| 439 StubDisplayClient client; |
| 440 display_->Initialize(&client); |
| 441 |
| 442 display_->SetSurfaceId(surface_id, 1.f); |
| 443 |
| 444 display_->Resize(gfx::Size(100, 100)); |
| 472 factory_.Create(surface_id); | 445 factory_.Create(surface_id); |
| 473 | 446 |
| 474 { | 447 { |
| 475 RenderPassList pass_list; | 448 RenderPassList pass_list; |
| 476 std::unique_ptr<RenderPass> pass = RenderPass::Create(); | 449 std::unique_ptr<RenderPass> pass = RenderPass::Create(); |
| 477 pass->output_rect = gfx::Rect(0, 0, 100, 100); | 450 pass->output_rect = gfx::Rect(0, 0, 100, 100); |
| 478 pass->damage_rect = gfx::Rect(10, 10, 1, 1); | 451 pass->damage_rect = gfx::Rect(10, 10, 1, 1); |
| 479 pass->id = RenderPassId(1, 1); | 452 pass->id = RenderPassId(1, 1); |
| 480 pass_list.push_back(std::move(pass)); | 453 pass_list.push_back(std::move(pass)); |
| 481 | 454 |
| 482 SubmitCompositorFrame(&pass_list, surface_id); | 455 SubmitCompositorFrame(&pass_list, surface_id); |
| 483 } | 456 } |
| 484 | 457 |
| 485 display.DrawAndSwap(); | 458 display_->DrawAndSwap(); |
| 486 | 459 |
| 487 // First resize and draw shouldn't finish. | 460 // First resize and draw shouldn't finish. |
| 488 testing::Mock::VerifyAndClearExpectations(context_ptr); | 461 testing::Mock::VerifyAndClearExpectations(context_ptr); |
| 489 | 462 |
| 490 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM()); | 463 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM()); |
| 491 display.Resize(gfx::Size(150, 150)); | 464 display_->Resize(gfx::Size(150, 150)); |
| 492 testing::Mock::VerifyAndClearExpectations(context_ptr); | 465 testing::Mock::VerifyAndClearExpectations(context_ptr); |
| 493 | 466 |
| 494 // Another resize without a swap doesn't need to finish. | 467 // Another resize without a swap doesn't need to finish. |
| 495 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM()).Times(0); | 468 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM()).Times(0); |
| 496 display.Resize(gfx::Size(200, 200)); | 469 display_->Resize(gfx::Size(200, 200)); |
| 497 testing::Mock::VerifyAndClearExpectations(context_ptr); | 470 testing::Mock::VerifyAndClearExpectations(context_ptr); |
| 498 | 471 |
| 499 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM()).Times(0); | 472 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM()).Times(0); |
| 500 { | 473 { |
| 501 RenderPassList pass_list; | 474 RenderPassList pass_list; |
| 502 std::unique_ptr<RenderPass> pass = RenderPass::Create(); | 475 std::unique_ptr<RenderPass> pass = RenderPass::Create(); |
| 503 pass->output_rect = gfx::Rect(0, 0, 200, 200); | 476 pass->output_rect = gfx::Rect(0, 0, 200, 200); |
| 504 pass->damage_rect = gfx::Rect(10, 10, 1, 1); | 477 pass->damage_rect = gfx::Rect(10, 10, 1, 1); |
| 505 pass->id = RenderPassId(1, 1); | 478 pass->id = RenderPassId(1, 1); |
| 506 pass_list.push_back(std::move(pass)); | 479 pass_list.push_back(std::move(pass)); |
| 507 | 480 |
| 508 SubmitCompositorFrame(&pass_list, surface_id); | 481 SubmitCompositorFrame(&pass_list, surface_id); |
| 509 } | 482 } |
| 510 | 483 |
| 511 display.DrawAndSwap(); | 484 display_->DrawAndSwap(); |
| 512 | 485 |
| 513 testing::Mock::VerifyAndClearExpectations(context_ptr); | 486 testing::Mock::VerifyAndClearExpectations(context_ptr); |
| 514 | 487 |
| 515 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM()); | 488 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM()); |
| 516 display.Resize(gfx::Size(250, 250)); | 489 display_->Resize(gfx::Size(250, 250)); |
| 517 testing::Mock::VerifyAndClearExpectations(context_ptr); | 490 testing::Mock::VerifyAndClearExpectations(context_ptr); |
| 518 | 491 |
| 519 factory_.Destroy(surface_id); | 492 factory_.Destroy(surface_id); |
| 520 } | 493 } |
| 521 | 494 |
| 522 } // namespace | 495 } // namespace |
| 523 } // namespace cc | 496 } // namespace cc |
| OLD | NEW |