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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "cc/output/compositor_frame.h" | 6 #include "cc/output/compositor_frame.h" |
7 #include "cc/output/delegated_frame_data.h" | 7 #include "cc/output/delegated_frame_data.h" |
8 #include "cc/resources/resource_provider.h" | 8 #include "cc/resources/resource_provider.h" |
9 #include "cc/surfaces/surface.h" | 9 #include "cc/surfaces/surface.h" |
10 #include "cc/surfaces/surface_factory.h" | 10 #include "cc/surfaces/surface_factory.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 private: | 43 private: |
44 ReturnedResourceArray returned_resources_; | 44 ReturnedResourceArray returned_resources_; |
45 BeginFrameSource* begin_frame_source_; | 45 BeginFrameSource* begin_frame_source_; |
46 | 46 |
47 DISALLOW_COPY_AND_ASSIGN(TestSurfaceFactoryClient); | 47 DISALLOW_COPY_AND_ASSIGN(TestSurfaceFactoryClient); |
48 }; | 48 }; |
49 | 49 |
50 class SurfaceFactoryTest : public testing::Test { | 50 class SurfaceFactoryTest : public testing::Test { |
51 public: | 51 public: |
52 SurfaceFactoryTest() | 52 SurfaceFactoryTest() |
53 : factory_(new SurfaceFactory(&manager_, &client_)), surface_id_(3) { | 53 : factory_(new SurfaceFactory(&manager_, &client_)), |
| 54 surface_id_(SurfaceId::FromUnsafeValue(3)) { |
54 factory_->Create(surface_id_); | 55 factory_->Create(surface_id_); |
55 } | 56 } |
56 | 57 |
57 ~SurfaceFactoryTest() override { | 58 ~SurfaceFactoryTest() override { |
58 if (!surface_id_.is_null()) | 59 if (!surface_id_.is_null()) |
59 factory_->Destroy(surface_id_); | 60 factory_->Destroy(surface_id_); |
60 } | 61 } |
61 | 62 |
62 void SubmitCompositorFrameWithResources(ResourceId* resource_ids, | 63 void SubmitCompositorFrameWithResources(ResourceId* resource_ids, |
63 size_t num_resource_ids) { | 64 size_t num_resource_ids) { |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 SCOPED_TRACE("fourth frame, second unref"); | 375 SCOPED_TRACE("fourth frame, second unref"); |
375 ResourceId expected_returned_ids[] = {12, 13}; | 376 ResourceId expected_returned_ids[] = {12, 13}; |
376 int expected_returned_counts[] = {2, 2}; | 377 int expected_returned_counts[] = {2, 2}; |
377 CheckReturnedResourcesMatchExpected(expected_returned_ids, | 378 CheckReturnedResourcesMatchExpected(expected_returned_ids, |
378 expected_returned_counts, | 379 expected_returned_counts, |
379 arraysize(expected_returned_counts)); | 380 arraysize(expected_returned_counts)); |
380 } | 381 } |
381 } | 382 } |
382 | 383 |
383 TEST_F(SurfaceFactoryTest, BlankNoIndexIncrement) { | 384 TEST_F(SurfaceFactoryTest, BlankNoIndexIncrement) { |
384 SurfaceId surface_id(6); | 385 SurfaceId surface_id = SurfaceId::FromUnsafeValue(6); |
385 factory_->Create(surface_id); | 386 factory_->Create(surface_id); |
386 Surface* surface = manager_.GetSurfaceForId(surface_id); | 387 Surface* surface = manager_.GetSurfaceForId(surface_id); |
387 ASSERT_NE(nullptr, surface); | 388 ASSERT_NE(nullptr, surface); |
388 EXPECT_EQ(2, surface->frame_index()); | 389 EXPECT_EQ(2, surface->frame_index()); |
389 scoped_ptr<CompositorFrame> frame(new CompositorFrame); | 390 scoped_ptr<CompositorFrame> frame(new CompositorFrame); |
390 frame->delegated_frame_data.reset(new DelegatedFrameData); | 391 frame->delegated_frame_data.reset(new DelegatedFrameData); |
391 | 392 |
392 factory_->SubmitCompositorFrame(surface_id, std::move(frame), | 393 factory_->SubmitCompositorFrame(surface_id, std::move(frame), |
393 SurfaceFactory::DrawCallback()); | 394 SurfaceFactory::DrawCallback()); |
394 EXPECT_EQ(2, surface->frame_index()); | 395 EXPECT_EQ(2, surface->frame_index()); |
395 factory_->Destroy(surface_id); | 396 factory_->Destroy(surface_id); |
396 } | 397 } |
397 | 398 |
398 void DrawCallback(uint32* execute_count, | 399 void DrawCallback(uint32* execute_count, |
399 SurfaceDrawStatus* result, | 400 SurfaceDrawStatus* result, |
400 SurfaceDrawStatus drawn) { | 401 SurfaceDrawStatus drawn) { |
401 *execute_count += 1; | 402 *execute_count += 1; |
402 *result = drawn; | 403 *result = drawn; |
403 } | 404 } |
404 | 405 |
405 // Tests doing a DestroyAll before shutting down the factory; | 406 // Tests doing a DestroyAll before shutting down the factory; |
406 TEST_F(SurfaceFactoryTest, DestroyAll) { | 407 TEST_F(SurfaceFactoryTest, DestroyAll) { |
407 SurfaceId id(7); | 408 SurfaceId id = SurfaceId::FromUnsafeValue(7); |
408 factory_->Create(id); | 409 factory_->Create(id); |
409 | 410 |
410 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); | 411 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); |
411 TransferableResource resource; | 412 TransferableResource resource; |
412 resource.id = 1; | 413 resource.id = 1; |
413 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; | 414 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; |
414 frame_data->resource_list.push_back(resource); | 415 frame_data->resource_list.push_back(resource); |
415 scoped_ptr<CompositorFrame> frame(new CompositorFrame); | 416 scoped_ptr<CompositorFrame> frame(new CompositorFrame); |
416 frame->delegated_frame_data = std::move(frame_data); | 417 frame->delegated_frame_data = std::move(frame_data); |
417 uint32 execute_count = 0; | 418 uint32 execute_count = 0; |
418 SurfaceDrawStatus drawn = SurfaceDrawStatus::DRAW_SKIPPED; | 419 SurfaceDrawStatus drawn = SurfaceDrawStatus::DRAW_SKIPPED; |
419 | 420 |
420 factory_->SubmitCompositorFrame( | 421 factory_->SubmitCompositorFrame( |
421 id, std::move(frame), base::Bind(&DrawCallback, &execute_count, &drawn)); | 422 id, std::move(frame), base::Bind(&DrawCallback, &execute_count, &drawn)); |
422 | 423 |
423 surface_id_ = SurfaceId(); | 424 surface_id_ = SurfaceId(); |
424 factory_->DestroyAll(); | 425 factory_->DestroyAll(); |
425 EXPECT_EQ(1u, execute_count); | 426 EXPECT_EQ(1u, execute_count); |
426 EXPECT_EQ(SurfaceDrawStatus::DRAW_SKIPPED, drawn); | 427 EXPECT_EQ(SurfaceDrawStatus::DRAW_SKIPPED, drawn); |
427 } | 428 } |
428 | 429 |
429 TEST_F(SurfaceFactoryTest, DestroySequence) { | 430 TEST_F(SurfaceFactoryTest, DestroySequence) { |
430 SurfaceId id2(5); | 431 SurfaceId id2 = SurfaceId::FromUnsafeValue(5); |
431 factory_->Create(id2); | 432 factory_->Create(id2); |
432 | 433 |
433 manager_.RegisterSurfaceIdNamespace(0); | 434 manager_.RegisterSurfaceIdNamespace(0); |
434 | 435 |
435 // Check that waiting before the sequence is satisfied works. | 436 // Check that waiting before the sequence is satisfied works. |
436 manager_.GetSurfaceForId(id2) | 437 manager_.GetSurfaceForId(id2) |
437 ->AddDestructionDependency(SurfaceSequence(0, 4)); | 438 ->AddDestructionDependency(SurfaceSequence(0, 4)); |
438 factory_->Destroy(id2); | 439 factory_->Destroy(id2); |
439 | 440 |
440 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); | 441 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); |
(...skipping 12 matching lines...) Expand all Loading... |
453 manager_.GetSurfaceForId(id2) | 454 manager_.GetSurfaceForId(id2) |
454 ->AddDestructionDependency(SurfaceSequence(0, 6)); | 455 ->AddDestructionDependency(SurfaceSequence(0, 6)); |
455 factory_->Destroy(id2); | 456 factory_->Destroy(id2); |
456 DCHECK(!manager_.GetSurfaceForId(id2)); | 457 DCHECK(!manager_.GetSurfaceForId(id2)); |
457 } | 458 } |
458 | 459 |
459 // Tests that Surface ID namespace invalidation correctly allows | 460 // Tests that Surface ID namespace invalidation correctly allows |
460 // Sequences to be ignored. | 461 // Sequences to be ignored. |
461 TEST_F(SurfaceFactoryTest, InvalidIdNamespace) { | 462 TEST_F(SurfaceFactoryTest, InvalidIdNamespace) { |
462 uint32_t id_namespace = 9u; | 463 uint32_t id_namespace = 9u; |
463 SurfaceId id(5); | 464 SurfaceId id = SurfaceId::FromUnsafeValue(5); |
464 factory_->Create(id); | 465 factory_->Create(id); |
465 | 466 |
466 manager_.RegisterSurfaceIdNamespace(id_namespace); | 467 manager_.RegisterSurfaceIdNamespace(id_namespace); |
467 manager_.GetSurfaceForId(id) | 468 manager_.GetSurfaceForId(id) |
468 ->AddDestructionDependency(SurfaceSequence(id_namespace, 4)); | 469 ->AddDestructionDependency(SurfaceSequence(id_namespace, 4)); |
469 factory_->Destroy(id); | 470 factory_->Destroy(id); |
470 | 471 |
471 // Verify the dependency has prevented the surface from getting destroyed. | 472 // Verify the dependency has prevented the surface from getting destroyed. |
472 EXPECT_TRUE(manager_.GetSurfaceForId(id)); | 473 EXPECT_TRUE(manager_.GetSurfaceForId(id)); |
473 | 474 |
474 manager_.InvalidateSurfaceIdNamespace(id_namespace); | 475 manager_.InvalidateSurfaceIdNamespace(id_namespace); |
475 | 476 |
476 // Verify that the invalidated namespace caused the unsatisfied sequence | 477 // Verify that the invalidated namespace caused the unsatisfied sequence |
477 // to be ignored. | 478 // to be ignored. |
478 EXPECT_FALSE(manager_.GetSurfaceForId(id)); | 479 EXPECT_FALSE(manager_.GetSurfaceForId(id)); |
479 } | 480 } |
480 | 481 |
481 TEST_F(SurfaceFactoryTest, DestroyCycle) { | 482 TEST_F(SurfaceFactoryTest, DestroyCycle) { |
482 SurfaceId id2(5); | 483 SurfaceId id2 = SurfaceId::FromUnsafeValue(5); |
483 factory_->Create(id2); | 484 factory_->Create(id2); |
484 | 485 |
485 manager_.RegisterSurfaceIdNamespace(0); | 486 manager_.RegisterSurfaceIdNamespace(0); |
486 | 487 |
487 manager_.GetSurfaceForId(id2) | 488 manager_.GetSurfaceForId(id2) |
488 ->AddDestructionDependency(SurfaceSequence(0, 4)); | 489 ->AddDestructionDependency(SurfaceSequence(0, 4)); |
489 | 490 |
490 // Give id2 a frame that references surface_id_. | 491 // Give id2 a frame that references surface_id_. |
491 { | 492 { |
492 scoped_ptr<RenderPass> render_pass(RenderPass::Create()); | 493 scoped_ptr<RenderPass> render_pass(RenderPass::Create()); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 surface_id_ = SurfaceId(); | 556 surface_id_ = SurfaceId(); |
556 factory_->DestroyAll(); | 557 factory_->DestroyAll(); |
557 | 558 |
558 EXPECT_EQ(&bfs, client_.begin_frame_source()); | 559 EXPECT_EQ(&bfs, client_.begin_frame_source()); |
559 factory_.reset(); | 560 factory_.reset(); |
560 EXPECT_EQ(nullptr, client_.begin_frame_source()); | 561 EXPECT_EQ(nullptr, client_.begin_frame_source()); |
561 } | 562 } |
562 | 563 |
563 } // namespace | 564 } // namespace |
564 } // namespace cc | 565 } // namespace cc |
OLD | NEW |