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