| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/resources/resource_provider.h" | 5 #include "cc/resources/resource_provider.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 case ResourceProvider::InvalidType: | 359 case ResourceProvider::InvalidType: |
| 360 NOTREACHED(); | 360 NOTREACHED(); |
| 361 break; | 361 break; |
| 362 } | 362 } |
| 363 } | 363 } |
| 364 | 364 |
| 365 class ResourceProviderTest | 365 class ResourceProviderTest |
| 366 : public testing::TestWithParam<ResourceProvider::ResourceType> { | 366 : public testing::TestWithParam<ResourceProvider::ResourceType> { |
| 367 public: | 367 public: |
| 368 ResourceProviderTest() | 368 ResourceProviderTest() |
| 369 : shared_data_(ContextSharedData::Create()) { | 369 : shared_data_(ContextSharedData::Create()), |
| 370 context3d_(NULL) { |
| 370 switch (GetParam()) { | 371 switch (GetParam()) { |
| 371 case ResourceProvider::GLTexture: | 372 case ResourceProvider::GLTexture: { |
| 372 output_surface_ = | 373 scoped_ptr<ResourceProviderContext> context3d( |
| 373 FakeOutputSurface::Create3d(ResourceProviderContext::Create( | 374 ResourceProviderContext::Create(shared_data_.get())); |
| 374 shared_data_.get()).PassAs<WebKit::WebGraphicsContext3D>()); | 375 context3d_ = context3d.get(); |
| 376 |
| 377 scoped_refptr<TestContextProvider> context_provider = |
| 378 TestContextProvider::Create( |
| 379 context3d.PassAs<TestWebGraphicsContext3D>()); |
| 380 |
| 381 output_surface_ = FakeOutputSurface::Create3d(context_provider); |
| 375 break; | 382 break; |
| 383 } |
| 376 case ResourceProvider::Bitmap: | 384 case ResourceProvider::Bitmap: |
| 377 output_surface_ = FakeOutputSurface::CreateSoftware( | 385 output_surface_ = FakeOutputSurface::CreateSoftware( |
| 378 make_scoped_ptr(new SoftwareOutputDevice)); | 386 make_scoped_ptr(new SoftwareOutputDevice)); |
| 379 break; | 387 break; |
| 380 case ResourceProvider::InvalidType: | 388 case ResourceProvider::InvalidType: |
| 381 NOTREACHED(); | 389 NOTREACHED(); |
| 382 break; | 390 break; |
| 383 } | 391 } |
| 392 CHECK(output_surface_->BindToClient(&output_surface_client_)); |
| 384 resource_provider_ = ResourceProvider::Create(output_surface_.get(), 0); | 393 resource_provider_ = ResourceProvider::Create(output_surface_.get(), 0); |
| 385 } | 394 } |
| 386 | 395 |
| 387 ResourceProviderContext* context() { | |
| 388 return static_cast<ResourceProviderContext*>(output_surface_->context3d()); | |
| 389 } | |
| 390 | |
| 391 void SetResourceFilter(ResourceProvider* resource_provider, | 396 void SetResourceFilter(ResourceProvider* resource_provider, |
| 392 ResourceProvider::ResourceId id, | 397 ResourceProvider::ResourceId id, |
| 393 WGC3Denum filter) { | 398 WGC3Denum filter) { |
| 394 ResourceProvider::ScopedSamplerGL sampler( | 399 ResourceProvider::ScopedSamplerGL sampler( |
| 395 resource_provider, id, GL_TEXTURE_2D, filter); | 400 resource_provider, id, GL_TEXTURE_2D, filter); |
| 396 } | 401 } |
| 397 | 402 |
| 398 WGC3Denum GetResourceFilter(ResourceProvider* resource_provider, | 403 WGC3Denum GetResourceFilter(ResourceProvider* resource_provider, |
| 404 ResourceProviderContext* context, |
| 399 ResourceProvider::ResourceId id) { | 405 ResourceProvider::ResourceId id) { |
| 400 DCHECK_EQ(GetParam(), ResourceProvider::GLTexture); | 406 DCHECK_EQ(GetParam(), ResourceProvider::GLTexture); |
| 401 ResourceProvider::ScopedReadLockGL lock_gl(resource_provider, id); | 407 ResourceProvider::ScopedReadLockGL lock_gl(resource_provider, id); |
| 402 EXPECT_NE(0u, lock_gl.texture_id()); | 408 EXPECT_NE(0u, lock_gl.texture_id()); |
| 403 ResourceProviderContext* context = static_cast<ResourceProviderContext*>( | |
| 404 resource_provider->GraphicsContext3D()); | |
| 405 context->bindTexture(GL_TEXTURE_2D, lock_gl.texture_id()); | 409 context->bindTexture(GL_TEXTURE_2D, lock_gl.texture_id()); |
| 406 return context->GetTextureFilter(); | 410 return context->GetTextureFilter(); |
| 407 } | 411 } |
| 408 | 412 |
| 413 ResourceProviderContext* context() { return context3d_; } |
| 414 |
| 409 protected: | 415 protected: |
| 410 scoped_ptr<ContextSharedData> shared_data_; | 416 scoped_ptr<ContextSharedData> shared_data_; |
| 417 ResourceProviderContext* context3d_; |
| 418 FakeOutputSurfaceClient output_surface_client_; |
| 411 scoped_ptr<OutputSurface> output_surface_; | 419 scoped_ptr<OutputSurface> output_surface_; |
| 412 scoped_ptr<ResourceProvider> resource_provider_; | 420 scoped_ptr<ResourceProvider> resource_provider_; |
| 413 }; | 421 }; |
| 414 | 422 |
| 415 void CheckCreateResource(ResourceProvider::ResourceType expected_default_type, | 423 void CheckCreateResource(ResourceProvider::ResourceType expected_default_type, |
| 416 ResourceProvider* resource_provider, | 424 ResourceProvider* resource_provider, |
| 417 ResourceProviderContext* context) { | 425 ResourceProviderContext* context) { |
| 418 DCHECK_EQ(expected_default_type, resource_provider->default_resource_type()); | 426 DCHECK_EQ(expected_default_type, resource_provider->default_resource_type()); |
| 419 | 427 |
| 420 gfx::Size size(1, 1); | 428 gfx::Size size(1, 1); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 } | 521 } |
| 514 | 522 |
| 515 resource_provider_->DeleteResource(id); | 523 resource_provider_->DeleteResource(id); |
| 516 } | 524 } |
| 517 | 525 |
| 518 TEST_P(ResourceProviderTest, TransferResources) { | 526 TEST_P(ResourceProviderTest, TransferResources) { |
| 519 // Resource transfer is only supported with GL textures for now. | 527 // Resource transfer is only supported with GL textures for now. |
| 520 if (GetParam() != ResourceProvider::GLTexture) | 528 if (GetParam() != ResourceProvider::GLTexture) |
| 521 return; | 529 return; |
| 522 | 530 |
| 523 scoped_ptr<OutputSurface> child_output_surface(FakeOutputSurface::Create3d( | 531 scoped_ptr<ResourceProviderContext> child_context_owned( |
| 524 ResourceProviderContext::Create(shared_data_.get()) | 532 ResourceProviderContext::Create(shared_data_.get())); |
| 525 .PassAs<WebKit::WebGraphicsContext3D>())); | 533 ResourceProviderContext* child_context = child_context_owned.get(); |
| 534 |
| 535 FakeOutputSurfaceClient child_output_surface_client; |
| 536 scoped_ptr<OutputSurface> child_output_surface( |
| 537 FakeOutputSurface::Create3d( |
| 538 child_context_owned.PassAs<TestWebGraphicsContext3D>())); |
| 539 CHECK(child_output_surface->BindToClient(&child_output_surface_client)); |
| 540 |
| 526 scoped_ptr<ResourceProvider> child_resource_provider( | 541 scoped_ptr<ResourceProvider> child_resource_provider( |
| 527 ResourceProvider::Create(child_output_surface.get(), 0)); | 542 ResourceProvider::Create(child_output_surface.get(), 0)); |
| 528 | 543 |
| 529 gfx::Size size(1, 1); | 544 gfx::Size size(1, 1); |
| 530 WGC3Denum format = GL_RGBA; | 545 WGC3Denum format = GL_RGBA; |
| 531 size_t pixel_size = TextureSize(size, format); | 546 size_t pixel_size = TextureSize(size, format); |
| 532 ASSERT_EQ(4U, pixel_size); | 547 ASSERT_EQ(4U, pixel_size); |
| 533 | 548 |
| 534 ResourceProvider::ResourceId id1 = child_resource_provider->CreateResource( | 549 ResourceProvider::ResourceId id1 = child_resource_provider->CreateResource( |
| 535 size, format, ResourceProvider::TextureUsageAny); | 550 size, format, ResourceProvider::TextureUsageAny); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 resource_provider_->PrepareSendToChild( | 611 resource_provider_->PrepareSendToChild( |
| 597 child_id, resource_ids_to_transfer, &list); | 612 child_id, resource_ids_to_transfer, &list); |
| 598 ASSERT_EQ(2u, list.size()); | 613 ASSERT_EQ(2u, list.size()); |
| 599 EXPECT_NE(0u, list[0].sync_point); | 614 EXPECT_NE(0u, list[0].sync_point); |
| 600 EXPECT_NE(0u, list[1].sync_point); | 615 EXPECT_NE(0u, list[1].sync_point); |
| 601 child_resource_provider->ReceiveFromParent(list); | 616 child_resource_provider->ReceiveFromParent(list); |
| 602 } | 617 } |
| 603 EXPECT_FALSE(child_resource_provider->InUseByConsumer(id1)); | 618 EXPECT_FALSE(child_resource_provider->InUseByConsumer(id1)); |
| 604 EXPECT_FALSE(child_resource_provider->InUseByConsumer(id2)); | 619 EXPECT_FALSE(child_resource_provider->InUseByConsumer(id2)); |
| 605 | 620 |
| 606 ResourceProviderContext* child_context = | |
| 607 static_cast<ResourceProviderContext*>(child_output_surface->context3d()); | |
| 608 { | 621 { |
| 609 ResourceProvider::ScopedReadLockGL lock(child_resource_provider.get(), id1); | 622 ResourceProvider::ScopedReadLockGL lock(child_resource_provider.get(), id1); |
| 610 ASSERT_NE(0U, lock.texture_id()); | 623 ASSERT_NE(0U, lock.texture_id()); |
| 611 child_context->bindTexture(GL_TEXTURE_2D, lock.texture_id()); | 624 child_context->bindTexture(GL_TEXTURE_2D, lock.texture_id()); |
| 612 child_context->GetPixels(size, format, result); | 625 child_context->GetPixels(size, format, result); |
| 613 EXPECT_EQ(0, memcmp(data1, result, pixel_size)); | 626 EXPECT_EQ(0, memcmp(data1, result, pixel_size)); |
| 614 } | 627 } |
| 615 { | 628 { |
| 616 ResourceProvider::ScopedReadLockGL lock(child_resource_provider.get(), id2); | 629 ResourceProvider::ScopedReadLockGL lock(child_resource_provider.get(), id2); |
| 617 ASSERT_NE(0U, lock.texture_id()); | 630 ASSERT_NE(0U, lock.texture_id()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 638 EXPECT_EQ(2u, resource_provider_->num_resources()); | 651 EXPECT_EQ(2u, resource_provider_->num_resources()); |
| 639 resource_provider_->DestroyChild(child_id); | 652 resource_provider_->DestroyChild(child_id); |
| 640 EXPECT_EQ(0u, resource_provider_->num_resources()); | 653 EXPECT_EQ(0u, resource_provider_->num_resources()); |
| 641 } | 654 } |
| 642 | 655 |
| 643 TEST_P(ResourceProviderTest, DeleteTransferredResources) { | 656 TEST_P(ResourceProviderTest, DeleteTransferredResources) { |
| 644 // Resource transfer is only supported with GL textures for now. | 657 // Resource transfer is only supported with GL textures for now. |
| 645 if (GetParam() != ResourceProvider::GLTexture) | 658 if (GetParam() != ResourceProvider::GLTexture) |
| 646 return; | 659 return; |
| 647 | 660 |
| 648 scoped_ptr<OutputSurface> child_output_surface(FakeOutputSurface::Create3d( | 661 scoped_ptr<ResourceProviderContext> child_context_owned( |
| 649 ResourceProviderContext::Create(shared_data_.get()) | 662 ResourceProviderContext::Create(shared_data_.get())); |
| 650 .PassAs<WebKit::WebGraphicsContext3D>())); | 663 |
| 664 FakeOutputSurfaceClient child_output_surface_client; |
| 665 scoped_ptr<OutputSurface> child_output_surface( |
| 666 FakeOutputSurface::Create3d( |
| 667 child_context_owned.PassAs<TestWebGraphicsContext3D>())); |
| 668 CHECK(child_output_surface->BindToClient(&child_output_surface_client)); |
| 669 |
| 651 scoped_ptr<ResourceProvider> child_resource_provider( | 670 scoped_ptr<ResourceProvider> child_resource_provider( |
| 652 ResourceProvider::Create(child_output_surface.get(), 0)); | 671 ResourceProvider::Create(child_output_surface.get(), 0)); |
| 653 | 672 |
| 654 gfx::Size size(1, 1); | 673 gfx::Size size(1, 1); |
| 655 WGC3Denum format = GL_RGBA; | 674 WGC3Denum format = GL_RGBA; |
| 656 size_t pixel_size = TextureSize(size, format); | 675 size_t pixel_size = TextureSize(size, format); |
| 657 ASSERT_EQ(4U, pixel_size); | 676 ASSERT_EQ(4U, pixel_size); |
| 658 | 677 |
| 659 ResourceProvider::ResourceId id = child_resource_provider->CreateResource( | 678 ResourceProvider::ResourceId id = child_resource_provider->CreateResource( |
| 660 size, format, ResourceProvider::TextureUsageAny); | 679 size, format, ResourceProvider::TextureUsageAny); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 695 child_resource_provider->ReceiveFromParent(list); | 714 child_resource_provider->ReceiveFromParent(list); |
| 696 } | 715 } |
| 697 EXPECT_EQ(0u, child_resource_provider->num_resources()); | 716 EXPECT_EQ(0u, child_resource_provider->num_resources()); |
| 698 } | 717 } |
| 699 | 718 |
| 700 TEST_P(ResourceProviderTest, TextureFilters) { | 719 TEST_P(ResourceProviderTest, TextureFilters) { |
| 701 // Resource transfer is only supported with GL textures for now. | 720 // Resource transfer is only supported with GL textures for now. |
| 702 if (GetParam() != ResourceProvider::GLTexture) | 721 if (GetParam() != ResourceProvider::GLTexture) |
| 703 return; | 722 return; |
| 704 | 723 |
| 724 scoped_ptr<ResourceProviderContext> child_context_owned( |
| 725 ResourceProviderContext::Create(shared_data_.get())); |
| 726 ResourceProviderContext* child_context = child_context_owned.get(); |
| 727 |
| 728 FakeOutputSurfaceClient child_output_surface_client; |
| 705 scoped_ptr<OutputSurface> child_output_surface(FakeOutputSurface::Create3d( | 729 scoped_ptr<OutputSurface> child_output_surface(FakeOutputSurface::Create3d( |
| 706 ResourceProviderContext::Create(shared_data_.get()) | 730 child_context_owned.PassAs<TestWebGraphicsContext3D>())); |
| 707 .PassAs<WebKit::WebGraphicsContext3D>())); | 731 CHECK(child_output_surface->BindToClient(&child_output_surface_client)); |
| 732 |
| 708 scoped_ptr<ResourceProvider> child_resource_provider( | 733 scoped_ptr<ResourceProvider> child_resource_provider( |
| 709 ResourceProvider::Create(child_output_surface.get(), 0)); | 734 ResourceProvider::Create(child_output_surface.get(), 0)); |
| 710 | 735 |
| 711 gfx::Size size(1, 1); | 736 gfx::Size size(1, 1); |
| 712 WGC3Denum format = GL_RGBA; | 737 WGC3Denum format = GL_RGBA; |
| 713 size_t pixel_size = TextureSize(size, format); | 738 size_t pixel_size = TextureSize(size, format); |
| 714 ASSERT_EQ(4U, pixel_size); | 739 ASSERT_EQ(4U, pixel_size); |
| 715 | 740 |
| 716 ResourceProvider::ResourceId id = child_resource_provider->CreateResource( | 741 ResourceProvider::ResourceId id = child_resource_provider->CreateResource( |
| 717 size, format, ResourceProvider::TextureUsageAny); | 742 size, format, ResourceProvider::TextureUsageAny); |
| 718 uint8_t data[4] = { 1, 2, 3, 4 }; | 743 uint8_t data[4] = { 1, 2, 3, 4 }; |
| 719 gfx::Rect rect(size); | 744 gfx::Rect rect(size); |
| 720 child_resource_provider->SetPixels(id, data, rect, rect, gfx::Vector2d()); | 745 child_resource_provider->SetPixels(id, data, rect, rect, gfx::Vector2d()); |
| 721 EXPECT_EQ(static_cast<unsigned>(GL_LINEAR), | 746 EXPECT_EQ(static_cast<unsigned>(GL_LINEAR), |
| 722 GetResourceFilter(child_resource_provider.get(), id)); | 747 GetResourceFilter(child_resource_provider.get(), |
| 748 child_context, |
| 749 id)); |
| 723 SetResourceFilter(child_resource_provider.get(), id, GL_NEAREST); | 750 SetResourceFilter(child_resource_provider.get(), id, GL_NEAREST); |
| 724 EXPECT_EQ(static_cast<unsigned>(GL_NEAREST), | 751 EXPECT_EQ(static_cast<unsigned>(GL_NEAREST), |
| 725 GetResourceFilter(child_resource_provider.get(), id)); | 752 GetResourceFilter(child_resource_provider.get(), |
| 753 child_context, |
| 754 id)); |
| 726 | 755 |
| 727 int child_id = resource_provider_->CreateChild(); | 756 int child_id = resource_provider_->CreateChild(); |
| 728 { | 757 { |
| 729 // Transfer some resource to the parent. | 758 // Transfer some resource to the parent. |
| 730 ResourceProvider::ResourceIdArray resource_ids_to_transfer; | 759 ResourceProvider::ResourceIdArray resource_ids_to_transfer; |
| 731 resource_ids_to_transfer.push_back(id); | 760 resource_ids_to_transfer.push_back(id); |
| 732 TransferableResourceArray list; | 761 TransferableResourceArray list; |
| 733 child_resource_provider->PrepareSendToParent(resource_ids_to_transfer, | 762 child_resource_provider->PrepareSendToParent(resource_ids_to_transfer, |
| 734 &list); | 763 &list); |
| 735 ASSERT_EQ(1u, list.size()); | 764 ASSERT_EQ(1u, list.size()); |
| 736 EXPECT_EQ(static_cast<unsigned>(GL_NEAREST), list[0].filter); | 765 EXPECT_EQ(static_cast<unsigned>(GL_NEAREST), list[0].filter); |
| 737 resource_provider_->ReceiveFromChild(child_id, list); | 766 resource_provider_->ReceiveFromChild(child_id, list); |
| 738 } | 767 } |
| 739 ResourceProvider::ResourceIdMap resource_map = | 768 ResourceProvider::ResourceIdMap resource_map = |
| 740 resource_provider_->GetChildToParentMap(child_id); | 769 resource_provider_->GetChildToParentMap(child_id); |
| 741 ResourceProvider::ResourceId mapped_id = resource_map[id]; | 770 ResourceProvider::ResourceId mapped_id = resource_map[id]; |
| 742 EXPECT_NE(0u, mapped_id); | 771 EXPECT_NE(0u, mapped_id); |
| 743 EXPECT_EQ(static_cast<unsigned>(GL_NEAREST), | 772 EXPECT_EQ(static_cast<unsigned>(GL_NEAREST), |
| 744 GetResourceFilter(resource_provider_.get(), mapped_id)); | 773 GetResourceFilter(resource_provider_.get(), context(), mapped_id)); |
| 745 SetResourceFilter(resource_provider_.get(), mapped_id, GL_LINEAR); | 774 SetResourceFilter(resource_provider_.get(), mapped_id, GL_LINEAR); |
| 746 EXPECT_EQ(static_cast<unsigned>(GL_LINEAR), | 775 EXPECT_EQ(static_cast<unsigned>(GL_LINEAR), |
| 747 GetResourceFilter(resource_provider_.get(), mapped_id)); | 776 GetResourceFilter(resource_provider_.get(), context(), mapped_id)); |
| 748 { | 777 { |
| 749 // Transfer resources back from the parent to the child. | 778 // Transfer resources back from the parent to the child. |
| 750 ResourceProvider::ResourceIdArray resource_ids_to_transfer; | 779 ResourceProvider::ResourceIdArray resource_ids_to_transfer; |
| 751 resource_ids_to_transfer.push_back(mapped_id); | 780 resource_ids_to_transfer.push_back(mapped_id); |
| 752 TransferableResourceArray list; | 781 TransferableResourceArray list; |
| 753 resource_provider_->PrepareSendToChild( | 782 resource_provider_->PrepareSendToChild( |
| 754 child_id, resource_ids_to_transfer, &list); | 783 child_id, resource_ids_to_transfer, &list); |
| 755 ASSERT_EQ(1u, list.size()); | 784 ASSERT_EQ(1u, list.size()); |
| 756 EXPECT_EQ(static_cast<unsigned>(GL_LINEAR), list[0].filter); | 785 EXPECT_EQ(static_cast<unsigned>(GL_LINEAR), list[0].filter); |
| 757 child_resource_provider->ReceiveFromParent(list); | 786 child_resource_provider->ReceiveFromParent(list); |
| 758 } | 787 } |
| 759 EXPECT_EQ(static_cast<unsigned>(GL_LINEAR), | 788 EXPECT_EQ(static_cast<unsigned>(GL_LINEAR), |
| 760 GetResourceFilter(child_resource_provider.get(), id)); | 789 GetResourceFilter(child_resource_provider.get(), |
| 790 child_context, |
| 791 id)); |
| 761 SetResourceFilter(child_resource_provider.get(), id, GL_NEAREST); | 792 SetResourceFilter(child_resource_provider.get(), id, GL_NEAREST); |
| 762 EXPECT_EQ(static_cast<unsigned>(GL_NEAREST), | 793 EXPECT_EQ(static_cast<unsigned>(GL_NEAREST), |
| 763 GetResourceFilter(child_resource_provider.get(), id)); | 794 GetResourceFilter(child_resource_provider.get(), |
| 795 child_context, |
| 796 id)); |
| 764 } | 797 } |
| 765 | 798 |
| 766 void ReleaseTextureMailbox(unsigned* release_sync_point, | 799 void ReleaseTextureMailbox(unsigned* release_sync_point, |
| 767 bool* release_lost_resource, | 800 bool* release_lost_resource, |
| 768 unsigned sync_point, | 801 unsigned sync_point, |
| 769 bool lost_resource) { | 802 bool lost_resource) { |
| 770 *release_sync_point = sync_point; | 803 *release_sync_point = sync_point; |
| 771 *release_lost_resource = lost_resource; | 804 *release_lost_resource = lost_resource; |
| 772 } | 805 } |
| 773 | 806 |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1028 | 1061 |
| 1029 // Force all textures to be "1" so we can test for them. | 1062 // Force all textures to be "1" so we can test for them. |
| 1030 virtual WebKit::WebGLId NextTextureId() OVERRIDE { return 1; } | 1063 virtual WebKit::WebGLId NextTextureId() OVERRIDE { return 1; } |
| 1031 }; | 1064 }; |
| 1032 | 1065 |
| 1033 TEST_P(ResourceProviderTest, ScopedSampler) { | 1066 TEST_P(ResourceProviderTest, ScopedSampler) { |
| 1034 // Sampling is only supported for GL textures. | 1067 // Sampling is only supported for GL textures. |
| 1035 if (GetParam() != ResourceProvider::GLTexture) | 1068 if (GetParam() != ResourceProvider::GLTexture) |
| 1036 return; | 1069 return; |
| 1037 | 1070 |
| 1038 scoped_ptr<OutputSurface> output_surface( | 1071 scoped_ptr<TextureStateTrackingContext> context_owned( |
| 1039 FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>( | 1072 new TextureStateTrackingContext); |
| 1040 new TextureStateTrackingContext))); | 1073 TextureStateTrackingContext* context = context_owned.get(); |
| 1041 TextureStateTrackingContext* context = | 1074 |
| 1042 static_cast<TextureStateTrackingContext*>(output_surface->context3d()); | 1075 FakeOutputSurfaceClient output_surface_client; |
| 1076 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( |
| 1077 context_owned.PassAs<TestWebGraphicsContext3D>())); |
| 1078 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 1079 |
| 1043 scoped_ptr<ResourceProvider> resource_provider( | 1080 scoped_ptr<ResourceProvider> resource_provider( |
| 1044 ResourceProvider::Create(output_surface.get(), 0)); | 1081 ResourceProvider::Create(output_surface.get(), 0)); |
| 1045 | 1082 |
| 1046 gfx::Size size(1, 1); | 1083 gfx::Size size(1, 1); |
| 1047 WGC3Denum format = GL_RGBA; | 1084 WGC3Denum format = GL_RGBA; |
| 1048 int texture_id = 1; | 1085 int texture_id = 1; |
| 1049 | 1086 |
| 1050 // Check that the texture gets created with the right sampler settings. | 1087 // Check that the texture gets created with the right sampler settings. |
| 1051 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)) | 1088 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)) |
| 1052 .Times(2); // Once to create and once to allocate. | 1089 .Times(2); // Once to create and once to allocate. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1101 } | 1138 } |
| 1102 | 1139 |
| 1103 Mock::VerifyAndClearExpectations(context); | 1140 Mock::VerifyAndClearExpectations(context); |
| 1104 } | 1141 } |
| 1105 | 1142 |
| 1106 TEST_P(ResourceProviderTest, ManagedResource) { | 1143 TEST_P(ResourceProviderTest, ManagedResource) { |
| 1107 // Sampling is only supported for GL textures. | 1144 // Sampling is only supported for GL textures. |
| 1108 if (GetParam() != ResourceProvider::GLTexture) | 1145 if (GetParam() != ResourceProvider::GLTexture) |
| 1109 return; | 1146 return; |
| 1110 | 1147 |
| 1111 scoped_ptr<OutputSurface> output_surface( | 1148 scoped_ptr<TextureStateTrackingContext> context_owned( |
| 1112 FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>( | 1149 new TextureStateTrackingContext); |
| 1113 new TextureStateTrackingContext))); | 1150 TextureStateTrackingContext* context = context_owned.get(); |
| 1114 TextureStateTrackingContext* context = | 1151 |
| 1115 static_cast<TextureStateTrackingContext*>(output_surface->context3d()); | 1152 FakeOutputSurfaceClient output_surface_client; |
| 1153 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( |
| 1154 context_owned.PassAs<TestWebGraphicsContext3D>())); |
| 1155 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 1156 |
| 1116 scoped_ptr<ResourceProvider> resource_provider( | 1157 scoped_ptr<ResourceProvider> resource_provider( |
| 1117 ResourceProvider::Create(output_surface.get(), 0)); | 1158 ResourceProvider::Create(output_surface.get(), 0)); |
| 1118 | 1159 |
| 1119 gfx::Size size(1, 1); | 1160 gfx::Size size(1, 1); |
| 1120 WGC3Denum format = GL_RGBA; | 1161 WGC3Denum format = GL_RGBA; |
| 1121 int texture_id = 1; | 1162 int texture_id = 1; |
| 1122 | 1163 |
| 1123 // Check that the texture gets created with the right sampler settings. | 1164 // Check that the texture gets created with the right sampler settings. |
| 1124 ResourceProvider::ResourceId id = resource_provider->CreateManagedResource( | 1165 ResourceProvider::ResourceId id = resource_provider->CreateManagedResource( |
| 1125 size, format, ResourceProvider::TextureUsageAny); | 1166 size, format, ResourceProvider::TextureUsageAny); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1148 | 1189 |
| 1149 TEST_P(ResourceProviderTest, TextureMailbox_SharedMemory) { | 1190 TEST_P(ResourceProviderTest, TextureMailbox_SharedMemory) { |
| 1150 if (GetParam() != ResourceProvider::Bitmap) | 1191 if (GetParam() != ResourceProvider::Bitmap) |
| 1151 return; | 1192 return; |
| 1152 | 1193 |
| 1153 gfx::Size size(64, 64); | 1194 gfx::Size size(64, 64); |
| 1154 const uint32_t kBadBeef = 0xbadbeef; | 1195 const uint32_t kBadBeef = 0xbadbeef; |
| 1155 scoped_ptr<base::SharedMemory> shared_memory( | 1196 scoped_ptr<base::SharedMemory> shared_memory( |
| 1156 CreateAndFillSharedMemory(size, kBadBeef)); | 1197 CreateAndFillSharedMemory(size, kBadBeef)); |
| 1157 | 1198 |
| 1199 FakeOutputSurfaceClient output_surface_client; |
| 1158 scoped_ptr<OutputSurface> output_surface( | 1200 scoped_ptr<OutputSurface> output_surface( |
| 1159 FakeOutputSurface::CreateSoftware(make_scoped_ptr( | 1201 FakeOutputSurface::CreateSoftware(make_scoped_ptr( |
| 1160 new SoftwareOutputDevice))); | 1202 new SoftwareOutputDevice))); |
| 1203 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 1204 |
| 1161 scoped_ptr<ResourceProvider> resource_provider( | 1205 scoped_ptr<ResourceProvider> resource_provider( |
| 1162 ResourceProvider::Create(output_surface.get(), 0)); | 1206 ResourceProvider::Create(output_surface.get(), 0)); |
| 1163 | 1207 |
| 1164 TextureMailbox::ReleaseCallback callback = base::Bind(&EmptyReleaseCallback); | 1208 TextureMailbox::ReleaseCallback callback = base::Bind(&EmptyReleaseCallback); |
| 1165 TextureMailbox mailbox(shared_memory.get(), size, callback); | 1209 TextureMailbox mailbox(shared_memory.get(), size, callback); |
| 1166 | 1210 |
| 1167 ResourceProvider::ResourceId id = | 1211 ResourceProvider::ResourceId id = |
| 1168 resource_provider->CreateResourceFromTextureMailbox(mailbox); | 1212 resource_provider->CreateResourceFromTextureMailbox(mailbox); |
| 1169 EXPECT_NE(0u, id); | 1213 EXPECT_NE(0u, id); |
| 1170 | 1214 |
| 1171 { | 1215 { |
| 1172 ResourceProvider::ScopedReadLockSoftware lock(resource_provider.get(), id); | 1216 ResourceProvider::ScopedReadLockSoftware lock(resource_provider.get(), id); |
| 1173 const SkBitmap* sk_bitmap = lock.sk_bitmap(); | 1217 const SkBitmap* sk_bitmap = lock.sk_bitmap(); |
| 1174 EXPECT_EQ(sk_bitmap->width(), size.width()); | 1218 EXPECT_EQ(sk_bitmap->width(), size.width()); |
| 1175 EXPECT_EQ(sk_bitmap->height(), size.height()); | 1219 EXPECT_EQ(sk_bitmap->height(), size.height()); |
| 1176 EXPECT_EQ(*sk_bitmap->getAddr32(16, 16), kBadBeef); | 1220 EXPECT_EQ(*sk_bitmap->getAddr32(16, 16), kBadBeef); |
| 1177 } | 1221 } |
| 1178 } | 1222 } |
| 1179 | 1223 |
| 1180 TEST_P(ResourceProviderTest, TextureMailbox_GLTexture2D) { | 1224 TEST_P(ResourceProviderTest, TextureMailbox_GLTexture2D) { |
| 1181 // Mailboxing is only supported for GL textures. | 1225 // Mailboxing is only supported for GL textures. |
| 1182 if (GetParam() != ResourceProvider::GLTexture) | 1226 if (GetParam() != ResourceProvider::GLTexture) |
| 1183 return; | 1227 return; |
| 1184 | 1228 |
| 1185 scoped_ptr<OutputSurface> output_surface( | 1229 scoped_ptr<TextureStateTrackingContext> context_owned( |
| 1186 FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>( | 1230 new TextureStateTrackingContext); |
| 1187 new TextureStateTrackingContext))); | 1231 TextureStateTrackingContext* context = context_owned.get(); |
| 1188 TextureStateTrackingContext* context = | 1232 |
| 1189 static_cast<TextureStateTrackingContext*>(output_surface->context3d()); | 1233 FakeOutputSurfaceClient output_surface_client; |
| 1234 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( |
| 1235 context_owned.PassAs<TestWebGraphicsContext3D>())); |
| 1236 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 1237 |
| 1190 scoped_ptr<ResourceProvider> resource_provider( | 1238 scoped_ptr<ResourceProvider> resource_provider( |
| 1191 ResourceProvider::Create(output_surface.get(), 0)); | 1239 ResourceProvider::Create(output_surface.get(), 0)); |
| 1192 | 1240 |
| 1193 unsigned texture_id = 1; | 1241 unsigned texture_id = 1; |
| 1194 unsigned sync_point = 30; | 1242 unsigned sync_point = 30; |
| 1195 unsigned target = GL_TEXTURE_2D; | 1243 unsigned target = GL_TEXTURE_2D; |
| 1196 | 1244 |
| 1197 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); | 1245 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); |
| 1198 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); | 1246 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); |
| 1199 EXPECT_CALL(*context, insertSyncPoint()).Times(0); | 1247 EXPECT_CALL(*context, insertSyncPoint()).Times(0); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1235 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); | 1283 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); |
| 1236 EXPECT_CALL(*context, consumeTextureCHROMIUM(_, _)).Times(0); | 1284 EXPECT_CALL(*context, consumeTextureCHROMIUM(_, _)).Times(0); |
| 1237 } | 1285 } |
| 1238 } | 1286 } |
| 1239 | 1287 |
| 1240 TEST_P(ResourceProviderTest, TextureMailbox_GLTextureExternalOES) { | 1288 TEST_P(ResourceProviderTest, TextureMailbox_GLTextureExternalOES) { |
| 1241 // Mailboxing is only supported for GL textures. | 1289 // Mailboxing is only supported for GL textures. |
| 1242 if (GetParam() != ResourceProvider::GLTexture) | 1290 if (GetParam() != ResourceProvider::GLTexture) |
| 1243 return; | 1291 return; |
| 1244 | 1292 |
| 1245 scoped_ptr<OutputSurface> output_surface( | 1293 scoped_ptr<TextureStateTrackingContext> context_owned( |
| 1246 FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>( | 1294 new TextureStateTrackingContext); |
| 1247 new TextureStateTrackingContext))); | 1295 TextureStateTrackingContext* context = context_owned.get(); |
| 1248 TextureStateTrackingContext* context = | 1296 |
| 1249 static_cast<TextureStateTrackingContext*>(output_surface->context3d()); | 1297 FakeOutputSurfaceClient output_surface_client; |
| 1298 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( |
| 1299 context_owned.PassAs<TestWebGraphicsContext3D>())); |
| 1300 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 1301 |
| 1250 scoped_ptr<ResourceProvider> resource_provider( | 1302 scoped_ptr<ResourceProvider> resource_provider( |
| 1251 ResourceProvider::Create(output_surface.get(), 0)); | 1303 ResourceProvider::Create(output_surface.get(), 0)); |
| 1252 | 1304 |
| 1253 unsigned texture_id = 1; | 1305 unsigned texture_id = 1; |
| 1254 unsigned sync_point = 30; | 1306 unsigned sync_point = 30; |
| 1255 unsigned target = GL_TEXTURE_EXTERNAL_OES; | 1307 unsigned target = GL_TEXTURE_EXTERNAL_OES; |
| 1256 | 1308 |
| 1257 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); | 1309 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); |
| 1258 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); | 1310 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); |
| 1259 EXPECT_CALL(*context, insertSyncPoint()).Times(0); | 1311 EXPECT_CALL(*context, insertSyncPoint()).Times(0); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1352 GLint*)); | 1404 GLint*)); |
| 1353 MOCK_METHOD1(unmapImageCHROMIUM, void(WGC3Duint)); | 1405 MOCK_METHOD1(unmapImageCHROMIUM, void(WGC3Duint)); |
| 1354 MOCK_METHOD2(bindTexImage2DCHROMIUM, void(WGC3Denum, WGC3Dint)); | 1406 MOCK_METHOD2(bindTexImage2DCHROMIUM, void(WGC3Denum, WGC3Dint)); |
| 1355 MOCK_METHOD2(releaseTexImage2DCHROMIUM, void(WGC3Denum, WGC3Dint)); | 1407 MOCK_METHOD2(releaseTexImage2DCHROMIUM, void(WGC3Denum, WGC3Dint)); |
| 1356 }; | 1408 }; |
| 1357 | 1409 |
| 1358 TEST_P(ResourceProviderTest, TextureAllocation) { | 1410 TEST_P(ResourceProviderTest, TextureAllocation) { |
| 1359 // Only for GL textures. | 1411 // Only for GL textures. |
| 1360 if (GetParam() != ResourceProvider::GLTexture) | 1412 if (GetParam() != ResourceProvider::GLTexture) |
| 1361 return; | 1413 return; |
| 1362 scoped_ptr<WebKit::WebGraphicsContext3D> mock_context( | 1414 scoped_ptr<AllocationTrackingContext3D> context_owned( |
| 1363 static_cast<WebKit::WebGraphicsContext3D*>( | 1415 new StrictMock<AllocationTrackingContext3D>); |
| 1364 new StrictMock<AllocationTrackingContext3D>)); | 1416 AllocationTrackingContext3D* context = context_owned.get(); |
| 1365 scoped_ptr<OutputSurface> output_surface( | 1417 |
| 1366 FakeOutputSurface::Create3d(mock_context.Pass())); | 1418 FakeOutputSurfaceClient output_surface_client; |
| 1419 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( |
| 1420 context_owned.PassAs<TestWebGraphicsContext3D>())); |
| 1421 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 1422 |
| 1423 scoped_ptr<ResourceProvider> resource_provider( |
| 1424 ResourceProvider::Create(output_surface.get(), 0)); |
| 1367 | 1425 |
| 1368 gfx::Size size(2, 2); | 1426 gfx::Size size(2, 2); |
| 1369 gfx::Vector2d offset(0, 0); | 1427 gfx::Vector2d offset(0, 0); |
| 1370 gfx::Rect rect(0, 0, 2, 2); | 1428 gfx::Rect rect(0, 0, 2, 2); |
| 1371 WGC3Denum format = GL_RGBA; | 1429 WGC3Denum format = GL_RGBA; |
| 1372 ResourceProvider::ResourceId id = 0; | 1430 ResourceProvider::ResourceId id = 0; |
| 1373 uint8_t pixels[16] = { 0 }; | 1431 uint8_t pixels[16] = { 0 }; |
| 1374 int texture_id = 123; | 1432 int texture_id = 123; |
| 1375 | 1433 |
| 1376 AllocationTrackingContext3D* context = | |
| 1377 static_cast<AllocationTrackingContext3D*>(output_surface->context3d()); | |
| 1378 scoped_ptr<ResourceProvider> resource_provider( | |
| 1379 ResourceProvider::Create(output_surface.get(), 0)); | |
| 1380 | |
| 1381 // Lazy allocation. Don't allocate when creating the resource. | 1434 // Lazy allocation. Don't allocate when creating the resource. |
| 1382 id = resource_provider->CreateResource( | 1435 id = resource_provider->CreateResource( |
| 1383 size, format, ResourceProvider::TextureUsageAny); | 1436 size, format, ResourceProvider::TextureUsageAny); |
| 1384 | 1437 |
| 1385 EXPECT_CALL(*context, createTexture()).WillOnce(Return(texture_id)); | 1438 EXPECT_CALL(*context, createTexture()).WillOnce(Return(texture_id)); |
| 1386 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(1); | 1439 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(1); |
| 1387 resource_provider->CreateForTesting(id); | 1440 resource_provider->CreateForTesting(id); |
| 1388 | 1441 |
| 1389 EXPECT_CALL(*context, deleteTexture(texture_id)).Times(1); | 1442 EXPECT_CALL(*context, deleteTexture(texture_id)).Times(1); |
| 1390 resource_provider->DeleteResource(id); | 1443 resource_provider->DeleteResource(id); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1422 | 1475 |
| 1423 EXPECT_CALL(*context, deleteTexture(texture_id)).Times(1); | 1476 EXPECT_CALL(*context, deleteTexture(texture_id)).Times(1); |
| 1424 resource_provider->DeleteResource(id); | 1477 resource_provider->DeleteResource(id); |
| 1425 | 1478 |
| 1426 Mock::VerifyAndClearExpectations(context); | 1479 Mock::VerifyAndClearExpectations(context); |
| 1427 } | 1480 } |
| 1428 | 1481 |
| 1429 TEST_P(ResourceProviderTest, PixelBuffer_GLTexture) { | 1482 TEST_P(ResourceProviderTest, PixelBuffer_GLTexture) { |
| 1430 if (GetParam() != ResourceProvider::GLTexture) | 1483 if (GetParam() != ResourceProvider::GLTexture) |
| 1431 return; | 1484 return; |
| 1432 scoped_ptr<WebKit::WebGraphicsContext3D> mock_context( | 1485 scoped_ptr<AllocationTrackingContext3D> context_owned( |
| 1433 static_cast<WebKit::WebGraphicsContext3D*>( | 1486 new StrictMock<AllocationTrackingContext3D>); |
| 1434 new StrictMock<AllocationTrackingContext3D>)); | 1487 AllocationTrackingContext3D* context = context_owned.get(); |
| 1435 scoped_ptr<OutputSurface> output_surface( | 1488 |
| 1436 FakeOutputSurface::Create3d(mock_context.Pass())); | 1489 FakeOutputSurfaceClient output_surface_client; |
| 1490 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( |
| 1491 context_owned.PassAs<TestWebGraphicsContext3D>())); |
| 1492 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 1437 | 1493 |
| 1438 gfx::Size size(2, 2); | 1494 gfx::Size size(2, 2); |
| 1439 WGC3Denum format = GL_RGBA; | 1495 WGC3Denum format = GL_RGBA; |
| 1440 ResourceProvider::ResourceId id = 0; | 1496 ResourceProvider::ResourceId id = 0; |
| 1441 int texture_id = 123; | 1497 int texture_id = 123; |
| 1442 | 1498 |
| 1443 AllocationTrackingContext3D* context = | |
| 1444 static_cast<AllocationTrackingContext3D*>(output_surface->context3d()); | |
| 1445 scoped_ptr<ResourceProvider> resource_provider( | 1499 scoped_ptr<ResourceProvider> resource_provider( |
| 1446 ResourceProvider::Create(output_surface.get(), 0)); | 1500 ResourceProvider::Create(output_surface.get(), 0)); |
| 1447 | 1501 |
| 1448 id = resource_provider->CreateResource( | 1502 id = resource_provider->CreateResource( |
| 1449 size, format, ResourceProvider::TextureUsageAny); | 1503 size, format, ResourceProvider::TextureUsageAny); |
| 1450 resource_provider->AcquirePixelBuffer(id); | 1504 resource_provider->AcquirePixelBuffer(id); |
| 1451 | 1505 |
| 1452 EXPECT_CALL(*context, createTexture()).WillOnce(Return(texture_id)); | 1506 EXPECT_CALL(*context, createTexture()).WillOnce(Return(texture_id)); |
| 1453 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); | 1507 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); |
| 1454 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) | 1508 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) |
| 1455 .Times(1); | 1509 .Times(1); |
| 1456 resource_provider->BeginSetPixels(id); | 1510 resource_provider->BeginSetPixels(id); |
| 1457 | 1511 |
| 1458 EXPECT_TRUE(resource_provider->DidSetPixelsComplete(id)); | 1512 EXPECT_TRUE(resource_provider->DidSetPixelsComplete(id)); |
| 1459 | 1513 |
| 1460 resource_provider->ReleasePixelBuffer(id); | 1514 resource_provider->ReleasePixelBuffer(id); |
| 1461 | 1515 |
| 1462 EXPECT_CALL(*context, deleteTexture(texture_id)).Times(1); | 1516 EXPECT_CALL(*context, deleteTexture(texture_id)).Times(1); |
| 1463 resource_provider->DeleteResource(id); | 1517 resource_provider->DeleteResource(id); |
| 1464 | 1518 |
| 1465 Mock::VerifyAndClearExpectations(context); | 1519 Mock::VerifyAndClearExpectations(context); |
| 1466 } | 1520 } |
| 1467 | 1521 |
| 1468 TEST_P(ResourceProviderTest, PixelBuffer_Bitmap) { | 1522 TEST_P(ResourceProviderTest, PixelBuffer_Bitmap) { |
| 1469 if (GetParam() != ResourceProvider::Bitmap) | 1523 if (GetParam() != ResourceProvider::Bitmap) |
| 1470 return; | 1524 return; |
| 1525 FakeOutputSurfaceClient output_surface_client; |
| 1471 scoped_ptr<OutputSurface> output_surface( | 1526 scoped_ptr<OutputSurface> output_surface( |
| 1472 FakeOutputSurface::CreateSoftware(make_scoped_ptr( | 1527 FakeOutputSurface::CreateSoftware(make_scoped_ptr( |
| 1473 new SoftwareOutputDevice))); | 1528 new SoftwareOutputDevice))); |
| 1529 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 1474 | 1530 |
| 1475 gfx::Size size(1, 1); | 1531 gfx::Size size(1, 1); |
| 1476 WGC3Denum format = GL_RGBA; | 1532 WGC3Denum format = GL_RGBA; |
| 1477 ResourceProvider::ResourceId id = 0; | 1533 ResourceProvider::ResourceId id = 0; |
| 1478 const uint32_t kBadBeef = 0xbadbeef; | 1534 const uint32_t kBadBeef = 0xbadbeef; |
| 1479 | 1535 |
| 1480 scoped_ptr<ResourceProvider> resource_provider( | 1536 scoped_ptr<ResourceProvider> resource_provider( |
| 1481 ResourceProvider::Create(output_surface.get(), 0)); | 1537 ResourceProvider::Create(output_surface.get(), 0)); |
| 1482 | 1538 |
| 1483 id = resource_provider->CreateResource( | 1539 id = resource_provider->CreateResource( |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1502 EXPECT_EQ(*sk_bitmap->getAddr32(0, 0), kBadBeef); | 1558 EXPECT_EQ(*sk_bitmap->getAddr32(0, 0), kBadBeef); |
| 1503 } | 1559 } |
| 1504 | 1560 |
| 1505 resource_provider->DeleteResource(id); | 1561 resource_provider->DeleteResource(id); |
| 1506 } | 1562 } |
| 1507 | 1563 |
| 1508 TEST_P(ResourceProviderTest, ForcingAsyncUploadToComplete) { | 1564 TEST_P(ResourceProviderTest, ForcingAsyncUploadToComplete) { |
| 1509 // Only for GL textures. | 1565 // Only for GL textures. |
| 1510 if (GetParam() != ResourceProvider::GLTexture) | 1566 if (GetParam() != ResourceProvider::GLTexture) |
| 1511 return; | 1567 return; |
| 1512 scoped_ptr<WebKit::WebGraphicsContext3D> mock_context( | 1568 scoped_ptr<AllocationTrackingContext3D> context_owned( |
| 1513 static_cast<WebKit::WebGraphicsContext3D*>( | 1569 new StrictMock<AllocationTrackingContext3D>); |
| 1514 new StrictMock<AllocationTrackingContext3D>)); | 1570 AllocationTrackingContext3D* context = context_owned.get(); |
| 1515 scoped_ptr<OutputSurface> output_surface( | 1571 |
| 1516 FakeOutputSurface::Create3d(mock_context.Pass())); | 1572 FakeOutputSurfaceClient output_surface_client; |
| 1573 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( |
| 1574 context_owned.PassAs<TestWebGraphicsContext3D>())); |
| 1575 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 1517 | 1576 |
| 1518 gfx::Size size(2, 2); | 1577 gfx::Size size(2, 2); |
| 1519 WGC3Denum format = GL_RGBA; | 1578 WGC3Denum format = GL_RGBA; |
| 1520 ResourceProvider::ResourceId id = 0; | 1579 ResourceProvider::ResourceId id = 0; |
| 1521 int texture_id = 123; | 1580 int texture_id = 123; |
| 1522 | 1581 |
| 1523 AllocationTrackingContext3D* context = | |
| 1524 static_cast<AllocationTrackingContext3D*>(output_surface->context3d()); | |
| 1525 scoped_ptr<ResourceProvider> resource_provider( | 1582 scoped_ptr<ResourceProvider> resource_provider( |
| 1526 ResourceProvider::Create(output_surface.get(), 0)); | 1583 ResourceProvider::Create(output_surface.get(), 0)); |
| 1527 | 1584 |
| 1528 id = resource_provider->CreateResource( | 1585 id = resource_provider->CreateResource( |
| 1529 size, format, ResourceProvider::TextureUsageAny); | 1586 size, format, ResourceProvider::TextureUsageAny); |
| 1530 resource_provider->AcquirePixelBuffer(id); | 1587 resource_provider->AcquirePixelBuffer(id); |
| 1531 | 1588 |
| 1532 EXPECT_CALL(*context, createTexture()).WillOnce(Return(texture_id)); | 1589 EXPECT_CALL(*context, createTexture()).WillOnce(Return(texture_id)); |
| 1533 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); | 1590 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); |
| 1534 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) | 1591 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) |
| 1535 .Times(1); | 1592 .Times(1); |
| 1536 resource_provider->BeginSetPixels(id); | 1593 resource_provider->BeginSetPixels(id); |
| 1537 | 1594 |
| 1538 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(1); | 1595 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(1); |
| 1539 EXPECT_CALL(*context, waitAsyncTexImage2DCHROMIUM(GL_TEXTURE_2D)).Times(1); | 1596 EXPECT_CALL(*context, waitAsyncTexImage2DCHROMIUM(GL_TEXTURE_2D)).Times(1); |
| 1540 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, 0)).Times(1); | 1597 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, 0)).Times(1); |
| 1541 resource_provider->ForceSetPixelsToComplete(id); | 1598 resource_provider->ForceSetPixelsToComplete(id); |
| 1542 | 1599 |
| 1543 resource_provider->ReleasePixelBuffer(id); | 1600 resource_provider->ReleasePixelBuffer(id); |
| 1544 | 1601 |
| 1545 EXPECT_CALL(*context, deleteTexture(texture_id)).Times(1); | 1602 EXPECT_CALL(*context, deleteTexture(texture_id)).Times(1); |
| 1546 resource_provider->DeleteResource(id); | 1603 resource_provider->DeleteResource(id); |
| 1547 | 1604 |
| 1548 Mock::VerifyAndClearExpectations(context); | 1605 Mock::VerifyAndClearExpectations(context); |
| 1549 } | 1606 } |
| 1550 | 1607 |
| 1551 TEST_P(ResourceProviderTest, PixelBufferLostContext) { | 1608 TEST_P(ResourceProviderTest, PixelBufferLostContext) { |
| 1552 scoped_ptr<WebKit::WebGraphicsContext3D> mock_context( | 1609 scoped_ptr<AllocationTrackingContext3D> context_owned( |
| 1553 static_cast<WebKit::WebGraphicsContext3D*>( | 1610 new NiceMock<AllocationTrackingContext3D>); |
| 1554 new NiceMock<AllocationTrackingContext3D>)); | 1611 AllocationTrackingContext3D* context = context_owned.get(); |
| 1555 scoped_ptr<OutputSurface> output_surface( | 1612 |
| 1556 FakeOutputSurface::Create3d(mock_context.Pass())); | 1613 FakeOutputSurfaceClient output_surface_client; |
| 1614 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( |
| 1615 context_owned.PassAs<TestWebGraphicsContext3D>())); |
| 1616 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 1557 | 1617 |
| 1558 gfx::Size size(2, 2); | 1618 gfx::Size size(2, 2); |
| 1559 WGC3Denum format = GL_RGBA; | 1619 WGC3Denum format = GL_RGBA; |
| 1560 ResourceProvider::ResourceId id = 0; | 1620 ResourceProvider::ResourceId id = 0; |
| 1561 int texture_id = 123; | 1621 int texture_id = 123; |
| 1562 | 1622 |
| 1563 AllocationTrackingContext3D* context = | |
| 1564 static_cast<AllocationTrackingContext3D*>(output_surface->context3d()); | |
| 1565 scoped_ptr<ResourceProvider> resource_provider( | 1623 scoped_ptr<ResourceProvider> resource_provider( |
| 1566 ResourceProvider::Create(output_surface.get(), 0)); | 1624 ResourceProvider::Create(output_surface.get(), 0)); |
| 1567 | 1625 |
| 1568 EXPECT_CALL(*context, createTexture()).WillRepeatedly(Return(texture_id)); | 1626 EXPECT_CALL(*context, createTexture()).WillRepeatedly(Return(texture_id)); |
| 1569 | 1627 |
| 1570 id = resource_provider->CreateResource( | 1628 id = resource_provider->CreateResource( |
| 1571 size, format, ResourceProvider::TextureUsageAny); | 1629 size, format, ResourceProvider::TextureUsageAny); |
| 1572 context->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, | 1630 context->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, |
| 1573 GL_INNOCENT_CONTEXT_RESET_ARB); | 1631 GL_INNOCENT_CONTEXT_RESET_ARB); |
| 1574 resource_provider->AcquirePixelBuffer(id); | 1632 resource_provider->AcquirePixelBuffer(id); |
| 1575 uint8_t* buffer = resource_provider->MapPixelBuffer(id); | 1633 uint8_t* buffer = resource_provider->MapPixelBuffer(id); |
| 1576 EXPECT_TRUE(buffer == NULL); | 1634 EXPECT_TRUE(buffer == NULL); |
| 1577 resource_provider->UnmapPixelBuffer(id); | 1635 resource_provider->UnmapPixelBuffer(id); |
| 1578 resource_provider->ReleasePixelBuffer(id); | 1636 resource_provider->ReleasePixelBuffer(id); |
| 1579 Mock::VerifyAndClearExpectations(context); | 1637 Mock::VerifyAndClearExpectations(context); |
| 1580 } | 1638 } |
| 1581 | 1639 |
| 1582 TEST_P(ResourceProviderTest, Image_GLTexture) { | 1640 TEST_P(ResourceProviderTest, Image_GLTexture) { |
| 1583 // Only for GL textures. | 1641 // Only for GL textures. |
| 1584 if (GetParam() != ResourceProvider::GLTexture) | 1642 if (GetParam() != ResourceProvider::GLTexture) |
| 1585 return; | 1643 return; |
| 1586 scoped_ptr<WebKit::WebGraphicsContext3D> mock_context( | 1644 scoped_ptr<AllocationTrackingContext3D> context_owned( |
| 1587 static_cast<WebKit::WebGraphicsContext3D*>( | 1645 new StrictMock<AllocationTrackingContext3D>); |
| 1588 new StrictMock<AllocationTrackingContext3D>)); | 1646 AllocationTrackingContext3D* context = context_owned.get(); |
| 1589 scoped_ptr<OutputSurface> output_surface( | 1647 |
| 1590 FakeOutputSurface::Create3d(mock_context.Pass())); | 1648 FakeOutputSurfaceClient output_surface_client; |
| 1649 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( |
| 1650 context_owned.PassAs<TestWebGraphicsContext3D>())); |
| 1651 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 1591 | 1652 |
| 1592 const int kWidth = 2; | 1653 const int kWidth = 2; |
| 1593 const int kHeight = 2; | 1654 const int kHeight = 2; |
| 1594 gfx::Size size(kWidth, kHeight); | 1655 gfx::Size size(kWidth, kHeight); |
| 1595 WGC3Denum format = GL_RGBA; | 1656 WGC3Denum format = GL_RGBA; |
| 1596 ResourceProvider::ResourceId id = 0; | 1657 ResourceProvider::ResourceId id = 0; |
| 1597 const unsigned kTextureId = 123u; | 1658 const unsigned kTextureId = 123u; |
| 1598 const unsigned kImageId = 234u; | 1659 const unsigned kImageId = 234u; |
| 1599 | 1660 |
| 1600 AllocationTrackingContext3D* context = | |
| 1601 static_cast<AllocationTrackingContext3D*>(output_surface->context3d()); | |
| 1602 scoped_ptr<ResourceProvider> resource_provider( | 1661 scoped_ptr<ResourceProvider> resource_provider( |
| 1603 ResourceProvider::Create(output_surface.get(), 0)); | 1662 ResourceProvider::Create(output_surface.get(), 0)); |
| 1604 | 1663 |
| 1605 id = resource_provider->CreateResource( | 1664 id = resource_provider->CreateResource( |
| 1606 size, format, ResourceProvider::TextureUsageAny); | 1665 size, format, ResourceProvider::TextureUsageAny); |
| 1607 EXPECT_CALL(*context, createImageCHROMIUM(kWidth, kHeight, GL_RGBA8_OES)) | 1666 EXPECT_CALL(*context, createImageCHROMIUM(kWidth, kHeight, GL_RGBA8_OES)) |
| 1608 .WillOnce(Return(kImageId)) | 1667 .WillOnce(Return(kImageId)) |
| 1609 .RetiresOnSaturation(); | 1668 .RetiresOnSaturation(); |
| 1610 resource_provider->AcquireImage(id); | 1669 resource_provider->AcquireImage(id); |
| 1611 | 1670 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1652 | 1711 |
| 1653 EXPECT_CALL(*context, destroyImageCHROMIUM(kImageId)) | 1712 EXPECT_CALL(*context, destroyImageCHROMIUM(kImageId)) |
| 1654 .Times(1) | 1713 .Times(1) |
| 1655 .RetiresOnSaturation(); | 1714 .RetiresOnSaturation(); |
| 1656 resource_provider->ReleaseImage(id); | 1715 resource_provider->ReleaseImage(id); |
| 1657 } | 1716 } |
| 1658 | 1717 |
| 1659 TEST_P(ResourceProviderTest, Image_Bitmap) { | 1718 TEST_P(ResourceProviderTest, Image_Bitmap) { |
| 1660 if (GetParam() != ResourceProvider::Bitmap) | 1719 if (GetParam() != ResourceProvider::Bitmap) |
| 1661 return; | 1720 return; |
| 1721 FakeOutputSurfaceClient output_surface_client; |
| 1662 scoped_ptr<OutputSurface> output_surface( | 1722 scoped_ptr<OutputSurface> output_surface( |
| 1663 FakeOutputSurface::CreateSoftware(make_scoped_ptr( | 1723 FakeOutputSurface::CreateSoftware(make_scoped_ptr( |
| 1664 new SoftwareOutputDevice))); | 1724 new SoftwareOutputDevice))); |
| 1725 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 1665 | 1726 |
| 1666 gfx::Size size(1, 1); | 1727 gfx::Size size(1, 1); |
| 1667 WGC3Denum format = GL_RGBA; | 1728 WGC3Denum format = GL_RGBA; |
| 1668 ResourceProvider::ResourceId id = 0; | 1729 ResourceProvider::ResourceId id = 0; |
| 1669 const uint32_t kBadBeef = 0xbadbeef; | 1730 const uint32_t kBadBeef = 0xbadbeef; |
| 1670 | 1731 |
| 1671 scoped_ptr<ResourceProvider> resource_provider( | 1732 scoped_ptr<ResourceProvider> resource_provider( |
| 1672 ResourceProvider::Create(output_surface.get(), 0)); | 1733 ResourceProvider::Create(output_surface.get(), 0)); |
| 1673 | 1734 |
| 1674 id = resource_provider->CreateResource( | 1735 id = resource_provider->CreateResource( |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1692 EXPECT_EQ(*sk_bitmap->getAddr32(0, 0), kBadBeef); | 1753 EXPECT_EQ(*sk_bitmap->getAddr32(0, 0), kBadBeef); |
| 1693 } | 1754 } |
| 1694 | 1755 |
| 1695 resource_provider->ReleaseImage(id); | 1756 resource_provider->ReleaseImage(id); |
| 1696 resource_provider->DeleteResource(id); | 1757 resource_provider->DeleteResource(id); |
| 1697 } | 1758 } |
| 1698 | 1759 |
| 1699 void InitializeGLAndCheck(ContextSharedData* shared_data, | 1760 void InitializeGLAndCheck(ContextSharedData* shared_data, |
| 1700 ResourceProvider* resource_provider, | 1761 ResourceProvider* resource_provider, |
| 1701 FakeOutputSurface* output_surface) { | 1762 FakeOutputSurface* output_surface) { |
| 1702 scoped_ptr<ResourceProviderContext> context = | 1763 scoped_ptr<ResourceProviderContext> context_owned = |
| 1703 ResourceProviderContext::Create(shared_data); | 1764 ResourceProviderContext::Create(shared_data); |
| 1704 output_surface->SetAndInitializeContext3D( | 1765 ResourceProviderContext* context = context_owned.get(); |
| 1705 context.PassAs<WebKit::WebGraphicsContext3D>()); | 1766 |
| 1767 scoped_refptr<TestContextProvider> context_provider = |
| 1768 TestContextProvider::Create( |
| 1769 context_owned.PassAs<TestWebGraphicsContext3D>()); |
| 1770 output_surface->InitializeAndSetContext3d(context_provider, NULL); |
| 1706 EXPECT_TRUE(resource_provider->InitializeGL()); | 1771 EXPECT_TRUE(resource_provider->InitializeGL()); |
| 1707 CheckCreateResource( | 1772 |
| 1708 ResourceProvider::GLTexture, | 1773 CheckCreateResource(ResourceProvider::GLTexture, resource_provider, context); |
| 1709 resource_provider, | |
| 1710 static_cast<ResourceProviderContext*>(output_surface->context3d())); | |
| 1711 } | 1774 } |
| 1712 | 1775 |
| 1713 TEST(ResourceProviderTest, BasicInitializeGLSoftware) { | 1776 TEST(ResourceProviderTest, BasicInitializeGLSoftware) { |
| 1714 scoped_ptr<ContextSharedData> shared_data = ContextSharedData::Create(); | 1777 scoped_ptr<ContextSharedData> shared_data = ContextSharedData::Create(); |
| 1715 FakeOutputSurfaceClient client; | 1778 FakeOutputSurfaceClient client; |
| 1716 scoped_ptr<FakeOutputSurface> output_surface( | 1779 scoped_ptr<FakeOutputSurface> output_surface( |
| 1717 FakeOutputSurface::CreateDeferredGL( | 1780 FakeOutputSurface::CreateDeferredGL( |
| 1718 scoped_ptr<SoftwareOutputDevice>(new SoftwareOutputDevice))); | 1781 scoped_ptr<SoftwareOutputDevice>(new SoftwareOutputDevice))); |
| 1719 EXPECT_TRUE(output_surface->BindToClient(&client)); | 1782 EXPECT_TRUE(output_surface->BindToClient(&client)); |
| 1720 scoped_ptr<ResourceProvider> resource_provider( | 1783 scoped_ptr<ResourceProvider> resource_provider( |
| 1721 ResourceProvider::Create(output_surface.get(), 0)); | 1784 ResourceProvider::Create(output_surface.get(), 0)); |
| 1722 | 1785 |
| 1723 CheckCreateResource(ResourceProvider::Bitmap, resource_provider.get(), NULL); | 1786 CheckCreateResource(ResourceProvider::Bitmap, resource_provider.get(), NULL); |
| 1724 | 1787 |
| 1725 InitializeGLAndCheck(shared_data.get(), | 1788 InitializeGLAndCheck(shared_data.get(), |
| 1726 resource_provider.get(), | 1789 resource_provider.get(), |
| 1727 output_surface.get()); | 1790 output_surface.get()); |
| 1728 | 1791 |
| 1729 resource_provider->InitializeSoftware(); | 1792 resource_provider->InitializeSoftware(); |
| 1793 output_surface->ReleaseGL(); |
| 1730 CheckCreateResource(ResourceProvider::Bitmap, resource_provider.get(), NULL); | 1794 CheckCreateResource(ResourceProvider::Bitmap, resource_provider.get(), NULL); |
| 1731 | 1795 |
| 1732 InitializeGLAndCheck(shared_data.get(), | 1796 InitializeGLAndCheck(shared_data.get(), |
| 1733 resource_provider.get(), | 1797 resource_provider.get(), |
| 1734 output_surface.get()); | 1798 output_surface.get()); |
| 1735 } | 1799 } |
| 1736 | 1800 |
| 1737 INSTANTIATE_TEST_CASE_P( | 1801 INSTANTIATE_TEST_CASE_P( |
| 1738 ResourceProviderTests, | 1802 ResourceProviderTests, |
| 1739 ResourceProviderTest, | 1803 ResourceProviderTest, |
| 1740 ::testing::Values(ResourceProvider::GLTexture, ResourceProvider::Bitmap)); | 1804 ::testing::Values(ResourceProvider::GLTexture, ResourceProvider::Bitmap)); |
| 1741 | 1805 |
| 1742 } // namespace | 1806 } // namespace |
| 1743 } // namespace cc | 1807 } // namespace cc |
| OLD | NEW |