OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/surface_factory.h" | 5 #include "cc/surfaces/surface_factory.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <utility> | 10 #include <utility> |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 gpu::SyncToken token; | 59 gpu::SyncToken token; |
60 token.Set(gpu::CommandBufferNamespace::GPU_IO, 0, | 60 token.Set(gpu::CommandBufferNamespace::GPU_IO, 0, |
61 gpu::CommandBufferId::FromUnsafeValue(id), 1); | 61 gpu::CommandBufferId::FromUnsafeValue(id), 1); |
62 return token; | 62 return token; |
63 } | 63 } |
64 | 64 |
65 class SurfaceFactoryTest : public testing::Test, public SurfaceDamageObserver { | 65 class SurfaceFactoryTest : public testing::Test, public SurfaceDamageObserver { |
66 public: | 66 public: |
67 SurfaceFactoryTest() | 67 SurfaceFactoryTest() |
68 : factory_(new SurfaceFactory(&manager_, &client_)), | 68 : factory_(new SurfaceFactory(&manager_, &client_)), |
69 surface_id_(3), | 69 surface_id_(0, 3, 0), |
70 frame_sync_token_(GenTestSyncToken(4)), | 70 frame_sync_token_(GenTestSyncToken(4)), |
71 consumer_sync_token_(GenTestSyncToken(5)) { | 71 consumer_sync_token_(GenTestSyncToken(5)) { |
72 manager_.AddObserver(this); | 72 manager_.AddObserver(this); |
73 factory_->Create(surface_id_); | 73 factory_->Create(surface_id_); |
74 } | 74 } |
75 | 75 |
76 // SurfaceDamageObserver implementation. | 76 // SurfaceDamageObserver implementation. |
77 void OnSurfaceDamaged(SurfaceId id, bool* changed) override { | 77 void OnSurfaceDamaged(SurfaceId id, bool* changed) override { |
78 *changed = true; | 78 *changed = true; |
79 } | 79 } |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 SCOPED_TRACE("fourth frame, second unref"); | 412 SCOPED_TRACE("fourth frame, second unref"); |
413 ResourceId expected_returned_ids[] = {12, 13}; | 413 ResourceId expected_returned_ids[] = {12, 13}; |
414 int expected_returned_counts[] = {2, 2}; | 414 int expected_returned_counts[] = {2, 2}; |
415 CheckReturnedResourcesMatchExpected( | 415 CheckReturnedResourcesMatchExpected( |
416 expected_returned_ids, expected_returned_counts, | 416 expected_returned_ids, expected_returned_counts, |
417 arraysize(expected_returned_counts), consumer_sync_token_); | 417 arraysize(expected_returned_counts), consumer_sync_token_); |
418 } | 418 } |
419 } | 419 } |
420 | 420 |
421 TEST_F(SurfaceFactoryTest, BlankNoIndexIncrement) { | 421 TEST_F(SurfaceFactoryTest, BlankNoIndexIncrement) { |
422 SurfaceId surface_id(6); | 422 SurfaceId surface_id(0, 6, 0); |
423 factory_->Create(surface_id); | 423 factory_->Create(surface_id); |
424 Surface* surface = manager_.GetSurfaceForId(surface_id); | 424 Surface* surface = manager_.GetSurfaceForId(surface_id); |
425 ASSERT_NE(nullptr, surface); | 425 ASSERT_NE(nullptr, surface); |
426 EXPECT_EQ(2, surface->frame_index()); | 426 EXPECT_EQ(2, surface->frame_index()); |
427 std::unique_ptr<CompositorFrame> frame(new CompositorFrame); | 427 std::unique_ptr<CompositorFrame> frame(new CompositorFrame); |
428 frame->delegated_frame_data.reset(new DelegatedFrameData); | 428 frame->delegated_frame_data.reset(new DelegatedFrameData); |
429 | 429 |
430 factory_->SubmitCompositorFrame(surface_id, std::move(frame), | 430 factory_->SubmitCompositorFrame(surface_id, std::move(frame), |
431 SurfaceFactory::DrawCallback()); | 431 SurfaceFactory::DrawCallback()); |
432 EXPECT_EQ(2, surface->frame_index()); | 432 EXPECT_EQ(2, surface->frame_index()); |
433 factory_->Destroy(surface_id); | 433 factory_->Destroy(surface_id); |
434 } | 434 } |
435 | 435 |
436 void CreateSurfaceDrawCallback(SurfaceFactory* factory, | 436 void CreateSurfaceDrawCallback(SurfaceFactory* factory, |
437 uint32_t* execute_count, | 437 uint32_t* execute_count, |
438 SurfaceDrawStatus* result, | 438 SurfaceDrawStatus* result, |
439 SurfaceDrawStatus drawn) { | 439 SurfaceDrawStatus drawn) { |
440 SurfaceId new_id(7); | 440 SurfaceId new_id(0, 7, 0); |
441 factory->Create(new_id); | 441 factory->Create(new_id); |
442 factory->Destroy(new_id); | 442 factory->Destroy(new_id); |
443 *execute_count += 1; | 443 *execute_count += 1; |
444 *result = drawn; | 444 *result = drawn; |
445 } | 445 } |
446 | 446 |
447 TEST_F(SurfaceFactoryTest, AddDuringDestroy) { | 447 TEST_F(SurfaceFactoryTest, AddDuringDestroy) { |
448 SurfaceId surface_id(6); | 448 SurfaceId surface_id(0, 6, 0); |
449 factory_->Create(surface_id); | 449 factory_->Create(surface_id); |
450 std::unique_ptr<CompositorFrame> frame(new CompositorFrame); | 450 std::unique_ptr<CompositorFrame> frame(new CompositorFrame); |
451 frame->delegated_frame_data.reset(new DelegatedFrameData); | 451 frame->delegated_frame_data.reset(new DelegatedFrameData); |
452 | 452 |
453 uint32_t execute_count = 0; | 453 uint32_t execute_count = 0; |
454 SurfaceDrawStatus drawn = SurfaceDrawStatus::DRAW_SKIPPED; | 454 SurfaceDrawStatus drawn = SurfaceDrawStatus::DRAW_SKIPPED; |
455 factory_->SubmitCompositorFrame( | 455 factory_->SubmitCompositorFrame( |
456 surface_id, std::move(frame), | 456 surface_id, std::move(frame), |
457 base::Bind(&CreateSurfaceDrawCallback, base::Unretained(factory_.get()), | 457 base::Bind(&CreateSurfaceDrawCallback, base::Unretained(factory_.get()), |
458 &execute_count, &drawn)); | 458 &execute_count, &drawn)); |
459 EXPECT_EQ(0u, execute_count); | 459 EXPECT_EQ(0u, execute_count); |
460 factory_->Destroy(surface_id); | 460 factory_->Destroy(surface_id); |
461 EXPECT_EQ(1u, execute_count); | 461 EXPECT_EQ(1u, execute_count); |
462 EXPECT_EQ(SurfaceDrawStatus::DRAW_SKIPPED, drawn); | 462 EXPECT_EQ(SurfaceDrawStatus::DRAW_SKIPPED, drawn); |
463 } | 463 } |
464 | 464 |
465 void DrawCallback(uint32_t* execute_count, | 465 void DrawCallback(uint32_t* execute_count, |
466 SurfaceDrawStatus* result, | 466 SurfaceDrawStatus* result, |
467 SurfaceDrawStatus drawn) { | 467 SurfaceDrawStatus drawn) { |
468 *execute_count += 1; | 468 *execute_count += 1; |
469 *result = drawn; | 469 *result = drawn; |
470 } | 470 } |
471 | 471 |
472 // Tests doing a DestroyAll before shutting down the factory; | 472 // Tests doing a DestroyAll before shutting down the factory; |
473 TEST_F(SurfaceFactoryTest, DestroyAll) { | 473 TEST_F(SurfaceFactoryTest, DestroyAll) { |
474 SurfaceId id(7); | 474 SurfaceId id(0, 7, 0); |
475 factory_->Create(id); | 475 factory_->Create(id); |
476 | 476 |
477 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); | 477 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); |
478 TransferableResource resource; | 478 TransferableResource resource; |
479 resource.id = 1; | 479 resource.id = 1; |
480 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; | 480 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; |
481 frame_data->resource_list.push_back(resource); | 481 frame_data->resource_list.push_back(resource); |
482 std::unique_ptr<CompositorFrame> frame(new CompositorFrame); | 482 std::unique_ptr<CompositorFrame> frame(new CompositorFrame); |
483 frame->delegated_frame_data = std::move(frame_data); | 483 frame->delegated_frame_data = std::move(frame_data); |
484 uint32_t execute_count = 0; | 484 uint32_t execute_count = 0; |
485 SurfaceDrawStatus drawn = SurfaceDrawStatus::DRAW_SKIPPED; | 485 SurfaceDrawStatus drawn = SurfaceDrawStatus::DRAW_SKIPPED; |
486 | 486 |
487 factory_->SubmitCompositorFrame( | 487 factory_->SubmitCompositorFrame( |
488 id, std::move(frame), base::Bind(&DrawCallback, &execute_count, &drawn)); | 488 id, std::move(frame), base::Bind(&DrawCallback, &execute_count, &drawn)); |
489 | 489 |
490 surface_id_ = SurfaceId(); | 490 surface_id_ = SurfaceId(); |
491 factory_->DestroyAll(); | 491 factory_->DestroyAll(); |
492 EXPECT_EQ(1u, execute_count); | 492 EXPECT_EQ(1u, execute_count); |
493 EXPECT_EQ(SurfaceDrawStatus::DRAW_SKIPPED, drawn); | 493 EXPECT_EQ(SurfaceDrawStatus::DRAW_SKIPPED, drawn); |
494 } | 494 } |
495 | 495 |
496 TEST_F(SurfaceFactoryTest, DestroySequence) { | 496 TEST_F(SurfaceFactoryTest, DestroySequence) { |
497 SurfaceId id2(5); | 497 SurfaceId id2(0, 5, 0); |
498 factory_->Create(id2); | 498 factory_->Create(id2); |
499 | 499 |
500 manager_.RegisterSurfaceIdNamespace(0); | 500 manager_.RegisterSurfaceIdNamespace(0); |
501 | 501 |
502 // Check that waiting before the sequence is satisfied works. | 502 // Check that waiting before the sequence is satisfied works. |
503 manager_.GetSurfaceForId(id2) | 503 manager_.GetSurfaceForId(id2) |
504 ->AddDestructionDependency(SurfaceSequence(0, 4)); | 504 ->AddDestructionDependency(SurfaceSequence(0, 4)); |
505 factory_->Destroy(id2); | 505 factory_->Destroy(id2); |
506 | 506 |
507 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); | 507 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); |
(...skipping 12 matching lines...) Expand all Loading... |
520 manager_.GetSurfaceForId(id2) | 520 manager_.GetSurfaceForId(id2) |
521 ->AddDestructionDependency(SurfaceSequence(0, 6)); | 521 ->AddDestructionDependency(SurfaceSequence(0, 6)); |
522 factory_->Destroy(id2); | 522 factory_->Destroy(id2); |
523 DCHECK(!manager_.GetSurfaceForId(id2)); | 523 DCHECK(!manager_.GetSurfaceForId(id2)); |
524 } | 524 } |
525 | 525 |
526 // Tests that Surface ID namespace invalidation correctly allows | 526 // Tests that Surface ID namespace invalidation correctly allows |
527 // Sequences to be ignored. | 527 // Sequences to be ignored. |
528 TEST_F(SurfaceFactoryTest, InvalidIdNamespace) { | 528 TEST_F(SurfaceFactoryTest, InvalidIdNamespace) { |
529 uint32_t id_namespace = 9u; | 529 uint32_t id_namespace = 9u; |
530 SurfaceId id(5); | 530 SurfaceId id(id_namespace, 5, 0); |
531 factory_->Create(id); | 531 factory_->Create(id); |
532 | 532 |
533 manager_.RegisterSurfaceIdNamespace(id_namespace); | 533 manager_.RegisterSurfaceIdNamespace(id_namespace); |
534 manager_.GetSurfaceForId(id) | 534 manager_.GetSurfaceForId(id) |
535 ->AddDestructionDependency(SurfaceSequence(id_namespace, 4)); | 535 ->AddDestructionDependency(SurfaceSequence(id_namespace, 4)); |
536 factory_->Destroy(id); | 536 factory_->Destroy(id); |
537 | 537 |
538 // Verify the dependency has prevented the surface from getting destroyed. | 538 // Verify the dependency has prevented the surface from getting destroyed. |
539 EXPECT_TRUE(manager_.GetSurfaceForId(id)); | 539 EXPECT_TRUE(manager_.GetSurfaceForId(id)); |
540 | 540 |
541 manager_.InvalidateSurfaceIdNamespace(id_namespace); | 541 manager_.InvalidateSurfaceIdNamespace(id_namespace); |
542 | 542 |
543 // Verify that the invalidated namespace caused the unsatisfied sequence | 543 // Verify that the invalidated namespace caused the unsatisfied sequence |
544 // to be ignored. | 544 // to be ignored. |
545 EXPECT_FALSE(manager_.GetSurfaceForId(id)); | 545 EXPECT_FALSE(manager_.GetSurfaceForId(id)); |
546 } | 546 } |
547 | 547 |
548 TEST_F(SurfaceFactoryTest, DestroyCycle) { | 548 TEST_F(SurfaceFactoryTest, DestroyCycle) { |
549 SurfaceId id2(5); | 549 SurfaceId id2(0, 5, 0); |
550 factory_->Create(id2); | 550 factory_->Create(id2); |
551 | 551 |
552 manager_.RegisterSurfaceIdNamespace(0); | 552 manager_.RegisterSurfaceIdNamespace(0); |
553 | 553 |
554 manager_.GetSurfaceForId(id2) | 554 manager_.GetSurfaceForId(id2) |
555 ->AddDestructionDependency(SurfaceSequence(0, 4)); | 555 ->AddDestructionDependency(SurfaceSequence(0, 4)); |
556 | 556 |
557 // Give id2 a frame that references surface_id_. | 557 // Give id2 a frame that references surface_id_. |
558 { | 558 { |
559 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); | 559 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 | 647 |
648 factory_->Destroy(surface_id_); | 648 factory_->Destroy(surface_id_); |
649 surface_id_ = SurfaceId(); | 649 surface_id_ = SurfaceId(); |
650 EXPECT_TRUE(called1); | 650 EXPECT_TRUE(called1); |
651 EXPECT_TRUE(called2); | 651 EXPECT_TRUE(called2); |
652 EXPECT_TRUE(called3); | 652 EXPECT_TRUE(called3); |
653 } | 653 } |
654 | 654 |
655 } // namespace | 655 } // namespace |
656 } // namespace cc | 656 } // namespace cc |
OLD | NEW |