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/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/test/null_task_runner.h" | 10 #include "base/test/null_task_runner.h" |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 EXPECT_FALSE(scheduler_->swapped); | 200 EXPECT_FALSE(scheduler_->swapped); |
201 EXPECT_EQ(0u, output_surface_->num_sent_frames()); | 201 EXPECT_EQ(0u, output_surface_->num_sent_frames()); |
202 EXPECT_EQ(gfx::ColorSpace(), output_surface_->last_reshape_color_space()); | 202 EXPECT_EQ(gfx::ColorSpace(), output_surface_->last_reshape_color_space()); |
203 display_->DrawAndSwap(); | 203 display_->DrawAndSwap(); |
204 EXPECT_EQ(color_space_1, output_surface_->last_reshape_color_space()); | 204 EXPECT_EQ(color_space_1, output_surface_->last_reshape_color_space()); |
205 EXPECT_TRUE(scheduler_->swapped); | 205 EXPECT_TRUE(scheduler_->swapped); |
206 EXPECT_EQ(1u, output_surface_->num_sent_frames()); | 206 EXPECT_EQ(1u, output_surface_->num_sent_frames()); |
207 EXPECT_EQ(gfx::Size(100, 100), | 207 EXPECT_EQ(gfx::Size(100, 100), |
208 software_output_device_->viewport_pixel_size()); | 208 software_output_device_->viewport_pixel_size()); |
209 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), software_output_device_->damage_rect()); | 209 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), software_output_device_->damage_rect()); |
210 | |
211 { | 210 { |
212 // Only damaged portion should be swapped. | 211 // Only damaged portion should be swapped. |
213 pass = RenderPass::Create(); | 212 pass = RenderPass::Create(); |
214 pass->output_rect = gfx::Rect(0, 0, 100, 100); | 213 pass->output_rect = gfx::Rect(0, 0, 100, 100); |
215 pass->damage_rect = gfx::Rect(10, 10, 1, 1); | 214 pass->damage_rect = gfx::Rect(10, 10, 1, 1); |
216 pass->id = 1; | 215 pass->id = 1; |
217 | 216 |
218 pass_list.push_back(std::move(pass)); | 217 pass_list.push_back(std::move(pass)); |
219 scheduler_->ResetDamageForTest(); | 218 scheduler_->ResetDamageForTest(); |
220 SubmitCompositorFrame(&pass_list, local_surface_id); | 219 SubmitCompositorFrame(&pass_list, local_surface_id); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 EXPECT_EQ(2u, output_surface_->num_sent_frames()); | 253 EXPECT_EQ(2u, output_surface_->num_sent_frames()); |
255 } | 254 } |
256 | 255 |
257 { | 256 { |
258 // Pass is wrong size so shouldn't be swapped. | 257 // Pass is wrong size so shouldn't be swapped. |
259 pass = RenderPass::Create(); | 258 pass = RenderPass::Create(); |
260 pass->output_rect = gfx::Rect(0, 0, 99, 99); | 259 pass->output_rect = gfx::Rect(0, 0, 99, 99); |
261 pass->damage_rect = gfx::Rect(10, 10, 10, 10); | 260 pass->damage_rect = gfx::Rect(10, 10, 10, 10); |
262 pass->id = 1; | 261 pass->id = 1; |
263 | 262 |
| 263 local_surface_id = id_allocator_.GenerateId(); |
| 264 display_->SetLocalSurfaceId(local_surface_id, 1.f); |
| 265 |
264 pass_list.push_back(std::move(pass)); | 266 pass_list.push_back(std::move(pass)); |
265 scheduler_->ResetDamageForTest(); | 267 scheduler_->ResetDamageForTest(); |
266 SubmitCompositorFrame(&pass_list, local_surface_id); | 268 SubmitCompositorFrame(&pass_list, local_surface_id); |
267 EXPECT_TRUE(scheduler_->damaged); | 269 EXPECT_TRUE(scheduler_->damaged); |
268 EXPECT_FALSE(scheduler_->display_resized_); | 270 EXPECT_FALSE(scheduler_->display_resized_); |
269 EXPECT_FALSE(scheduler_->has_new_root_surface); | 271 EXPECT_FALSE(scheduler_->has_new_root_surface); |
270 | 272 |
271 scheduler_->swapped = false; | 273 scheduler_->swapped = false; |
272 display_->DrawAndSwap(); | 274 display_->DrawAndSwap(); |
273 EXPECT_TRUE(scheduler_->swapped); | 275 EXPECT_TRUE(scheduler_->swapped); |
274 EXPECT_EQ(2u, output_surface_->num_sent_frames()); | 276 EXPECT_EQ(2u, output_surface_->num_sent_frames()); |
275 } | 277 } |
276 | 278 |
277 { | 279 { |
278 // Previous frame wasn't swapped, so next swap should have full damage. | 280 // Previous frame wasn't swapped, so next swap should have full damage. |
279 pass = RenderPass::Create(); | 281 pass = RenderPass::Create(); |
280 pass->output_rect = gfx::Rect(0, 0, 100, 100); | 282 pass->output_rect = gfx::Rect(0, 0, 100, 100); |
281 pass->damage_rect = gfx::Rect(10, 10, 0, 0); | 283 pass->damage_rect = gfx::Rect(10, 10, 0, 0); |
282 pass->id = 1; | 284 pass->id = 1; |
283 | 285 |
| 286 local_surface_id = id_allocator_.GenerateId(); |
| 287 display_->SetLocalSurfaceId(local_surface_id, 1.f); |
| 288 |
284 pass_list.push_back(std::move(pass)); | 289 pass_list.push_back(std::move(pass)); |
285 scheduler_->ResetDamageForTest(); | 290 scheduler_->ResetDamageForTest(); |
286 SubmitCompositorFrame(&pass_list, local_surface_id); | 291 SubmitCompositorFrame(&pass_list, local_surface_id); |
287 EXPECT_TRUE(scheduler_->damaged); | 292 EXPECT_TRUE(scheduler_->damaged); |
288 EXPECT_FALSE(scheduler_->display_resized_); | 293 EXPECT_FALSE(scheduler_->display_resized_); |
289 EXPECT_FALSE(scheduler_->has_new_root_surface); | 294 EXPECT_FALSE(scheduler_->has_new_root_surface); |
290 | 295 |
291 scheduler_->swapped = false; | 296 scheduler_->swapped = false; |
292 display_->DrawAndSwap(); | 297 display_->DrawAndSwap(); |
293 EXPECT_TRUE(scheduler_->swapped); | 298 EXPECT_TRUE(scheduler_->swapped); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 EXPECT_FALSE(scheduler_->has_new_root_surface); | 346 EXPECT_FALSE(scheduler_->has_new_root_surface); |
342 | 347 |
343 scheduler_->swapped = false; | 348 scheduler_->swapped = false; |
344 display_->DrawAndSwap(); | 349 display_->DrawAndSwap(); |
345 EXPECT_TRUE(scheduler_->swapped); | 350 EXPECT_TRUE(scheduler_->swapped); |
346 EXPECT_EQ(4u, output_surface_->num_sent_frames()); | 351 EXPECT_EQ(4u, output_surface_->num_sent_frames()); |
347 } | 352 } |
348 | 353 |
349 // Resize should cause a swap if no frame was swapped at the previous size. | 354 // Resize should cause a swap if no frame was swapped at the previous size. |
350 { | 355 { |
| 356 local_surface_id = id_allocator_.GenerateId(); |
| 357 display_->SetLocalSurfaceId(local_surface_id, 1.f); |
351 scheduler_->swapped = false; | 358 scheduler_->swapped = false; |
352 display_->Resize(gfx::Size(200, 200)); | 359 display_->Resize(gfx::Size(200, 200)); |
353 EXPECT_FALSE(scheduler_->swapped); | 360 EXPECT_FALSE(scheduler_->swapped); |
354 EXPECT_EQ(4u, output_surface_->num_sent_frames()); | 361 EXPECT_EQ(4u, output_surface_->num_sent_frames()); |
355 | 362 |
356 pass = RenderPass::Create(); | 363 pass = RenderPass::Create(); |
357 pass->output_rect = gfx::Rect(0, 0, 200, 200); | 364 pass->output_rect = gfx::Rect(0, 0, 200, 200); |
358 pass->damage_rect = gfx::Rect(10, 10, 10, 10); | 365 pass->damage_rect = gfx::Rect(10, 10, 10, 10); |
359 pass->id = 1; | 366 pass->id = 1; |
360 | 367 |
(...skipping 11 matching lines...) Expand all Loading... |
372 scheduler_->swapped = false; | 379 scheduler_->swapped = false; |
373 display_->Resize(gfx::Size(100, 100)); | 380 display_->Resize(gfx::Size(100, 100)); |
374 EXPECT_TRUE(scheduler_->swapped); | 381 EXPECT_TRUE(scheduler_->swapped); |
375 EXPECT_EQ(5u, output_surface_->num_sent_frames()); | 382 EXPECT_EQ(5u, output_surface_->num_sent_frames()); |
376 | 383 |
377 // Latency info from previous frame should be sent now. | 384 // Latency info from previous frame should be sent now. |
378 EXPECT_EQ(1u, output_surface_->last_sent_frame()->latency_info.size()); | 385 EXPECT_EQ(1u, output_surface_->last_sent_frame()->latency_info.size()); |
379 } | 386 } |
380 | 387 |
381 { | 388 { |
| 389 local_surface_id = id_allocator_.GenerateId(); |
| 390 display_->SetLocalSurfaceId(local_surface_id, 1.0f); |
382 // Surface that's damaged completely should be resized and swapped. | 391 // Surface that's damaged completely should be resized and swapped. |
383 pass = RenderPass::Create(); | 392 pass = RenderPass::Create(); |
384 pass->output_rect = gfx::Rect(0, 0, 99, 99); | 393 pass->output_rect = gfx::Rect(0, 0, 99, 99); |
385 pass->damage_rect = gfx::Rect(0, 0, 99, 99); | 394 pass->damage_rect = gfx::Rect(0, 0, 99, 99); |
386 pass->id = 1; | 395 pass->id = 1; |
387 | 396 |
388 pass_list.push_back(std::move(pass)); | 397 pass_list.push_back(std::move(pass)); |
389 scheduler_->ResetDamageForTest(); | 398 scheduler_->ResetDamageForTest(); |
390 SubmitCompositorFrame(&pass_list, local_surface_id); | 399 SubmitCompositorFrame(&pass_list, local_surface_id); |
391 EXPECT_TRUE(scheduler_->damaged); | 400 EXPECT_TRUE(scheduler_->damaged); |
(...skipping 11 matching lines...) Expand all Loading... |
403 EXPECT_EQ(0u, output_surface_->last_sent_frame()->latency_info.size()); | 412 EXPECT_EQ(0u, output_surface_->last_sent_frame()->latency_info.size()); |
404 } | 413 } |
405 } | 414 } |
406 | 415 |
407 class MockedContext : public TestWebGraphicsContext3D { | 416 class MockedContext : public TestWebGraphicsContext3D { |
408 public: | 417 public: |
409 MOCK_METHOD0(shallowFinishCHROMIUM, void()); | 418 MOCK_METHOD0(shallowFinishCHROMIUM, void()); |
410 }; | 419 }; |
411 | 420 |
412 TEST_F(DisplayTest, Finish) { | 421 TEST_F(DisplayTest, Finish) { |
413 LocalSurfaceId local_surface_id(id_allocator_.GenerateId()); | 422 LocalSurfaceId local_surface_id1(id_allocator_.GenerateId()); |
| 423 LocalSurfaceId local_surface_id2(id_allocator_.GenerateId()); |
414 | 424 |
415 RendererSettings settings; | 425 RendererSettings settings; |
416 settings.partial_swap_enabled = true; | 426 settings.partial_swap_enabled = true; |
417 settings.finish_rendering_on_resize = true; | 427 settings.finish_rendering_on_resize = true; |
418 | 428 |
419 std::unique_ptr<MockedContext> context(new MockedContext()); | 429 std::unique_ptr<MockedContext> context(new MockedContext()); |
420 MockedContext* context_ptr = context.get(); | 430 MockedContext* context_ptr = context.get(); |
421 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM()).Times(0); | 431 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM()).Times(0); |
422 | 432 |
423 SetUpDisplay(settings, std::move(context)); | 433 SetUpDisplay(settings, std::move(context)); |
424 | 434 |
425 StubDisplayClient client; | 435 StubDisplayClient client; |
426 display_->Initialize(&client, &manager_); | 436 display_->Initialize(&client, &manager_); |
427 | 437 |
428 display_->SetLocalSurfaceId(local_surface_id, 1.f); | 438 display_->SetLocalSurfaceId(local_surface_id1, 1.f); |
429 | 439 |
430 display_->Resize(gfx::Size(100, 100)); | 440 display_->Resize(gfx::Size(100, 100)); |
431 | 441 |
432 { | 442 { |
433 RenderPassList pass_list; | 443 RenderPassList pass_list; |
434 std::unique_ptr<RenderPass> pass = RenderPass::Create(); | 444 std::unique_ptr<RenderPass> pass = RenderPass::Create(); |
435 pass->output_rect = gfx::Rect(0, 0, 100, 100); | 445 pass->output_rect = gfx::Rect(0, 0, 100, 100); |
436 pass->damage_rect = gfx::Rect(10, 10, 1, 1); | 446 pass->damage_rect = gfx::Rect(10, 10, 1, 1); |
437 pass->id = 1; | 447 pass->id = 1; |
438 pass_list.push_back(std::move(pass)); | 448 pass_list.push_back(std::move(pass)); |
439 | 449 |
440 SubmitCompositorFrame(&pass_list, local_surface_id); | 450 SubmitCompositorFrame(&pass_list, local_surface_id1); |
441 } | 451 } |
442 | 452 |
443 display_->DrawAndSwap(); | 453 display_->DrawAndSwap(); |
444 | 454 |
445 // First resize and draw shouldn't finish. | 455 // First resize and draw shouldn't finish. |
446 testing::Mock::VerifyAndClearExpectations(context_ptr); | 456 testing::Mock::VerifyAndClearExpectations(context_ptr); |
447 | 457 |
448 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM()); | 458 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM()); |
449 display_->Resize(gfx::Size(150, 150)); | 459 display_->Resize(gfx::Size(150, 150)); |
450 testing::Mock::VerifyAndClearExpectations(context_ptr); | 460 testing::Mock::VerifyAndClearExpectations(context_ptr); |
451 | 461 |
452 // Another resize without a swap doesn't need to finish. | 462 // Another resize without a swap doesn't need to finish. |
453 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM()).Times(0); | 463 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM()).Times(0); |
| 464 display_->SetLocalSurfaceId(local_surface_id2, 1.f); |
454 display_->Resize(gfx::Size(200, 200)); | 465 display_->Resize(gfx::Size(200, 200)); |
455 testing::Mock::VerifyAndClearExpectations(context_ptr); | 466 testing::Mock::VerifyAndClearExpectations(context_ptr); |
456 | 467 |
457 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM()).Times(0); | 468 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM()).Times(0); |
458 { | 469 { |
459 RenderPassList pass_list; | 470 RenderPassList pass_list; |
460 std::unique_ptr<RenderPass> pass = RenderPass::Create(); | 471 std::unique_ptr<RenderPass> pass = RenderPass::Create(); |
461 pass->output_rect = gfx::Rect(0, 0, 200, 200); | 472 pass->output_rect = gfx::Rect(0, 0, 200, 200); |
462 pass->damage_rect = gfx::Rect(10, 10, 1, 1); | 473 pass->damage_rect = gfx::Rect(10, 10, 1, 1); |
463 pass->id = 1; | 474 pass->id = 1; |
464 pass_list.push_back(std::move(pass)); | 475 pass_list.push_back(std::move(pass)); |
465 | 476 |
466 SubmitCompositorFrame(&pass_list, local_surface_id); | 477 SubmitCompositorFrame(&pass_list, local_surface_id2); |
467 } | 478 } |
468 | 479 |
469 display_->DrawAndSwap(); | 480 display_->DrawAndSwap(); |
470 | 481 |
471 testing::Mock::VerifyAndClearExpectations(context_ptr); | 482 testing::Mock::VerifyAndClearExpectations(context_ptr); |
472 | 483 |
473 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM()); | 484 EXPECT_CALL(*context_ptr, shallowFinishCHROMIUM()); |
474 display_->Resize(gfx::Size(250, 250)); | 485 display_->Resize(gfx::Size(250, 250)); |
475 testing::Mock::VerifyAndClearExpectations(context_ptr); | 486 testing::Mock::VerifyAndClearExpectations(context_ptr); |
476 } | 487 } |
(...skipping 19 matching lines...) Expand all Loading... |
496 // Verify DidLoseOutputSurface callback is hooked up correctly. | 507 // Verify DidLoseOutputSurface callback is hooked up correctly. |
497 EXPECT_EQ(0, client.loss_count()); | 508 EXPECT_EQ(0, client.loss_count()); |
498 output_surface_->context_provider()->ContextGL()->LoseContextCHROMIUM( | 509 output_surface_->context_provider()->ContextGL()->LoseContextCHROMIUM( |
499 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB); | 510 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB); |
500 output_surface_->context_provider()->ContextGL()->Flush(); | 511 output_surface_->context_provider()->ContextGL()->Flush(); |
501 EXPECT_EQ(1, client.loss_count()); | 512 EXPECT_EQ(1, client.loss_count()); |
502 } | 513 } |
503 | 514 |
504 } // namespace | 515 } // namespace |
505 } // namespace cc | 516 } // namespace cc |
OLD | NEW |