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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 private: | 52 private: |
53 ReturnedResourceArray returned_resources_; | 53 ReturnedResourceArray returned_resources_; |
54 BeginFrameSource* begin_frame_source_; | 54 BeginFrameSource* begin_frame_source_; |
55 | 55 |
56 DISALLOW_COPY_AND_ASSIGN(TestSurfaceFactoryClient); | 56 DISALLOW_COPY_AND_ASSIGN(TestSurfaceFactoryClient); |
57 }; | 57 }; |
58 | 58 |
59 class SurfaceFactoryTest : public testing::Test { | 59 class SurfaceFactoryTest : public testing::Test { |
60 public: | 60 public: |
61 SurfaceFactoryTest() | 61 SurfaceFactoryTest() |
62 : factory_(new SurfaceFactory(&manager_, &client_)), surface_id_(3) { | 62 : factory_(new SurfaceFactory(&manager_, &client_)), |
| 63 surface_id_(SurfaceId::FromUnsafeValue(3)) { |
63 factory_->Create(surface_id_); | 64 factory_->Create(surface_id_); |
64 } | 65 } |
65 | 66 |
66 ~SurfaceFactoryTest() override { | 67 ~SurfaceFactoryTest() override { |
67 if (!surface_id_.is_null()) | 68 if (!surface_id_.is_null()) |
68 factory_->Destroy(surface_id_); | 69 factory_->Destroy(surface_id_); |
69 } | 70 } |
70 | 71 |
71 void SubmitCompositorFrameWithResources(ResourceId* resource_ids, | 72 void SubmitCompositorFrameWithResources(ResourceId* resource_ids, |
72 size_t num_resource_ids) { | 73 size_t num_resource_ids) { |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 SCOPED_TRACE("fourth frame, second unref"); | 384 SCOPED_TRACE("fourth frame, second unref"); |
384 ResourceId expected_returned_ids[] = {12, 13}; | 385 ResourceId expected_returned_ids[] = {12, 13}; |
385 int expected_returned_counts[] = {2, 2}; | 386 int expected_returned_counts[] = {2, 2}; |
386 CheckReturnedResourcesMatchExpected(expected_returned_ids, | 387 CheckReturnedResourcesMatchExpected(expected_returned_ids, |
387 expected_returned_counts, | 388 expected_returned_counts, |
388 arraysize(expected_returned_counts)); | 389 arraysize(expected_returned_counts)); |
389 } | 390 } |
390 } | 391 } |
391 | 392 |
392 TEST_F(SurfaceFactoryTest, BlankNoIndexIncrement) { | 393 TEST_F(SurfaceFactoryTest, BlankNoIndexIncrement) { |
393 SurfaceId surface_id(6); | 394 SurfaceId surface_id = SurfaceId::FromUnsafeValue(6); |
394 factory_->Create(surface_id); | 395 factory_->Create(surface_id); |
395 Surface* surface = manager_.GetSurfaceForId(surface_id); | 396 Surface* surface = manager_.GetSurfaceForId(surface_id); |
396 ASSERT_NE(nullptr, surface); | 397 ASSERT_NE(nullptr, surface); |
397 EXPECT_EQ(2, surface->frame_index()); | 398 EXPECT_EQ(2, surface->frame_index()); |
398 scoped_ptr<CompositorFrame> frame(new CompositorFrame); | 399 scoped_ptr<CompositorFrame> frame(new CompositorFrame); |
399 frame->delegated_frame_data.reset(new DelegatedFrameData); | 400 frame->delegated_frame_data.reset(new DelegatedFrameData); |
400 | 401 |
401 factory_->SubmitCompositorFrame(surface_id, std::move(frame), | 402 factory_->SubmitCompositorFrame(surface_id, std::move(frame), |
402 SurfaceFactory::DrawCallback()); | 403 SurfaceFactory::DrawCallback()); |
403 EXPECT_EQ(2, surface->frame_index()); | 404 EXPECT_EQ(2, surface->frame_index()); |
404 factory_->Destroy(surface_id); | 405 factory_->Destroy(surface_id); |
405 } | 406 } |
406 | 407 |
407 void DrawCallback(uint32_t* execute_count, | 408 void DrawCallback(uint32_t* execute_count, |
408 SurfaceDrawStatus* result, | 409 SurfaceDrawStatus* result, |
409 SurfaceDrawStatus drawn) { | 410 SurfaceDrawStatus drawn) { |
410 *execute_count += 1; | 411 *execute_count += 1; |
411 *result = drawn; | 412 *result = drawn; |
412 } | 413 } |
413 | 414 |
414 // Tests doing a DestroyAll before shutting down the factory; | 415 // Tests doing a DestroyAll before shutting down the factory; |
415 TEST_F(SurfaceFactoryTest, DestroyAll) { | 416 TEST_F(SurfaceFactoryTest, DestroyAll) { |
416 SurfaceId id(7); | 417 SurfaceId id = SurfaceId::FromUnsafeValue(7); |
417 factory_->Create(id); | 418 factory_->Create(id); |
418 | 419 |
419 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); | 420 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); |
420 TransferableResource resource; | 421 TransferableResource resource; |
421 resource.id = 1; | 422 resource.id = 1; |
422 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; | 423 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; |
423 frame_data->resource_list.push_back(resource); | 424 frame_data->resource_list.push_back(resource); |
424 scoped_ptr<CompositorFrame> frame(new CompositorFrame); | 425 scoped_ptr<CompositorFrame> frame(new CompositorFrame); |
425 frame->delegated_frame_data = std::move(frame_data); | 426 frame->delegated_frame_data = std::move(frame_data); |
426 uint32_t execute_count = 0; | 427 uint32_t execute_count = 0; |
427 SurfaceDrawStatus drawn = SurfaceDrawStatus::DRAW_SKIPPED; | 428 SurfaceDrawStatus drawn = SurfaceDrawStatus::DRAW_SKIPPED; |
428 | 429 |
429 factory_->SubmitCompositorFrame( | 430 factory_->SubmitCompositorFrame( |
430 id, std::move(frame), base::Bind(&DrawCallback, &execute_count, &drawn)); | 431 id, std::move(frame), base::Bind(&DrawCallback, &execute_count, &drawn)); |
431 | 432 |
432 surface_id_ = SurfaceId(); | 433 surface_id_ = SurfaceId(); |
433 factory_->DestroyAll(); | 434 factory_->DestroyAll(); |
434 EXPECT_EQ(1u, execute_count); | 435 EXPECT_EQ(1u, execute_count); |
435 EXPECT_EQ(SurfaceDrawStatus::DRAW_SKIPPED, drawn); | 436 EXPECT_EQ(SurfaceDrawStatus::DRAW_SKIPPED, drawn); |
436 } | 437 } |
437 | 438 |
438 TEST_F(SurfaceFactoryTest, DestroySequence) { | 439 TEST_F(SurfaceFactoryTest, DestroySequence) { |
439 SurfaceId id2(5); | 440 SurfaceId id2 = SurfaceId::FromUnsafeValue(5); |
440 factory_->Create(id2); | 441 factory_->Create(id2); |
441 | 442 |
442 manager_.RegisterSurfaceIdNamespace(0); | 443 manager_.RegisterSurfaceIdNamespace(0); |
443 | 444 |
444 // Check that waiting before the sequence is satisfied works. | 445 // Check that waiting before the sequence is satisfied works. |
445 manager_.GetSurfaceForId(id2) | 446 manager_.GetSurfaceForId(id2) |
446 ->AddDestructionDependency(SurfaceSequence(0, 4)); | 447 ->AddDestructionDependency(SurfaceSequence(0, 4)); |
447 factory_->Destroy(id2); | 448 factory_->Destroy(id2); |
448 | 449 |
449 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); | 450 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); |
(...skipping 12 matching lines...) Expand all Loading... |
462 manager_.GetSurfaceForId(id2) | 463 manager_.GetSurfaceForId(id2) |
463 ->AddDestructionDependency(SurfaceSequence(0, 6)); | 464 ->AddDestructionDependency(SurfaceSequence(0, 6)); |
464 factory_->Destroy(id2); | 465 factory_->Destroy(id2); |
465 DCHECK(!manager_.GetSurfaceForId(id2)); | 466 DCHECK(!manager_.GetSurfaceForId(id2)); |
466 } | 467 } |
467 | 468 |
468 // Tests that Surface ID namespace invalidation correctly allows | 469 // Tests that Surface ID namespace invalidation correctly allows |
469 // Sequences to be ignored. | 470 // Sequences to be ignored. |
470 TEST_F(SurfaceFactoryTest, InvalidIdNamespace) { | 471 TEST_F(SurfaceFactoryTest, InvalidIdNamespace) { |
471 uint32_t id_namespace = 9u; | 472 uint32_t id_namespace = 9u; |
472 SurfaceId id(5); | 473 SurfaceId id = SurfaceId::FromUnsafeValue(5); |
473 factory_->Create(id); | 474 factory_->Create(id); |
474 | 475 |
475 manager_.RegisterSurfaceIdNamespace(id_namespace); | 476 manager_.RegisterSurfaceIdNamespace(id_namespace); |
476 manager_.GetSurfaceForId(id) | 477 manager_.GetSurfaceForId(id) |
477 ->AddDestructionDependency(SurfaceSequence(id_namespace, 4)); | 478 ->AddDestructionDependency(SurfaceSequence(id_namespace, 4)); |
478 factory_->Destroy(id); | 479 factory_->Destroy(id); |
479 | 480 |
480 // Verify the dependency has prevented the surface from getting destroyed. | 481 // Verify the dependency has prevented the surface from getting destroyed. |
481 EXPECT_TRUE(manager_.GetSurfaceForId(id)); | 482 EXPECT_TRUE(manager_.GetSurfaceForId(id)); |
482 | 483 |
483 manager_.InvalidateSurfaceIdNamespace(id_namespace); | 484 manager_.InvalidateSurfaceIdNamespace(id_namespace); |
484 | 485 |
485 // Verify that the invalidated namespace caused the unsatisfied sequence | 486 // Verify that the invalidated namespace caused the unsatisfied sequence |
486 // to be ignored. | 487 // to be ignored. |
487 EXPECT_FALSE(manager_.GetSurfaceForId(id)); | 488 EXPECT_FALSE(manager_.GetSurfaceForId(id)); |
488 } | 489 } |
489 | 490 |
490 TEST_F(SurfaceFactoryTest, DestroyCycle) { | 491 TEST_F(SurfaceFactoryTest, DestroyCycle) { |
491 SurfaceId id2(5); | 492 SurfaceId id2 = SurfaceId::FromUnsafeValue(5); |
492 factory_->Create(id2); | 493 factory_->Create(id2); |
493 | 494 |
494 manager_.RegisterSurfaceIdNamespace(0); | 495 manager_.RegisterSurfaceIdNamespace(0); |
495 | 496 |
496 manager_.GetSurfaceForId(id2) | 497 manager_.GetSurfaceForId(id2) |
497 ->AddDestructionDependency(SurfaceSequence(0, 4)); | 498 ->AddDestructionDependency(SurfaceSequence(0, 4)); |
498 | 499 |
499 // Give id2 a frame that references surface_id_. | 500 // Give id2 a frame that references surface_id_. |
500 { | 501 { |
501 scoped_ptr<RenderPass> render_pass(RenderPass::Create()); | 502 scoped_ptr<RenderPass> render_pass(RenderPass::Create()); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
620 surface_id_ = SurfaceId(); | 621 surface_id_ = SurfaceId(); |
621 factory_->DestroyAll(); | 622 factory_->DestroyAll(); |
622 | 623 |
623 EXPECT_EQ(&bfs, client_.begin_frame_source()); | 624 EXPECT_EQ(&bfs, client_.begin_frame_source()); |
624 factory_.reset(); | 625 factory_.reset(); |
625 EXPECT_EQ(nullptr, client_.begin_frame_source()); | 626 EXPECT_EQ(nullptr, client_.begin_frame_source()); |
626 } | 627 } |
627 | 628 |
628 } // namespace | 629 } // namespace |
629 } // namespace cc | 630 } // namespace cc |
OLD | NEW |