| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #include "cc/test/test_web_graphics_context_3d.h" | 29 #include "cc/test/test_web_graphics_context_3d.h" |
| 30 #include "cc/trees/blocking_task_runner.h" | 30 #include "cc/trees/blocking_task_runner.h" |
| 31 #include "gpu/GLES2/gl2extchromium.h" | 31 #include "gpu/GLES2/gl2extchromium.h" |
| 32 #include "testing/gmock/include/gmock/gmock.h" | 32 #include "testing/gmock/include/gmock/gmock.h" |
| 33 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
| 34 #include "third_party/khronos/GLES2/gl2.h" | 34 #include "third_party/khronos/GLES2/gl2.h" |
| 35 #include "third_party/khronos/GLES2/gl2ext.h" | 35 #include "third_party/khronos/GLES2/gl2ext.h" |
| 36 #include "ui/gfx/geometry/rect.h" | 36 #include "ui/gfx/geometry/rect.h" |
| 37 #include "ui/gfx/gpu_memory_buffer.h" | 37 #include "ui/gfx/gpu_memory_buffer.h" |
| 38 | 38 |
| 39 using testing::InSequence; |
| 39 using testing::Mock; | 40 using testing::Mock; |
| 40 using testing::NiceMock; | 41 using testing::NiceMock; |
| 42 using testing::Pointee; |
| 41 using testing::Return; | 43 using testing::Return; |
| 42 using testing::StrictMock; | 44 using testing::StrictMock; |
| 45 using testing::TypedEq; |
| 43 using testing::_; | 46 using testing::_; |
| 44 | 47 |
| 45 namespace cc { | 48 namespace cc { |
| 46 namespace { | 49 namespace { |
| 47 | 50 |
| 48 static const bool kUseGpuMemoryBufferResources = false; | 51 static const bool kUseGpuMemoryBufferResources = false; |
| 49 static const bool kEnableColorCorrectRendering = false; | 52 static const bool kEnableColorCorrectRendering = false; |
| 50 static const bool kDelegatedSyncPointsRequired = true; | 53 static const bool kDelegatedSyncPointsRequired = true; |
| 51 | 54 |
| 52 MATCHER_P(MatchesSyncToken, sync_token, "") { | 55 MATCHER_P(MatchesSyncToken, sync_token, "") { |
| (...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format, color_space1); | 631 size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format, color_space1); |
| 629 uint8_t data1[4] = { 1, 2, 3, 4 }; | 632 uint8_t data1[4] = { 1, 2, 3, 4 }; |
| 630 child_resource_provider_->CopyToResource(id1, data1, size); | 633 child_resource_provider_->CopyToResource(id1, data1, size); |
| 631 | 634 |
| 632 ResourceId id2 = child_resource_provider_->CreateResource( | 635 ResourceId id2 = child_resource_provider_->CreateResource( |
| 633 size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format, | 636 size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format, |
| 634 gfx::ColorSpace()); | 637 gfx::ColorSpace()); |
| 635 uint8_t data2[4] = { 5, 5, 5, 5 }; | 638 uint8_t data2[4] = { 5, 5, 5, 5 }; |
| 636 child_resource_provider_->CopyToResource(id2, data2, size); | 639 child_resource_provider_->CopyToResource(id2, data2, size); |
| 637 | 640 |
| 638 ResourceId id3 = child_resource_provider_->CreateResource( | 641 ResourceId id3 = child_resource_provider_->CreateGpuMemoryBufferResource( |
| 639 size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format, | 642 size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format, |
| 640 gfx::ColorSpace()); | 643 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, gfx::ColorSpace()); |
| 641 { | 644 { |
| 642 ResourceProvider::ScopedWriteLockGpuMemoryBuffer lock( | 645 ResourceProvider::ScopedWriteLockGpuMemoryBuffer lock( |
| 643 child_resource_provider_.get(), id3); | 646 child_resource_provider_.get(), id3); |
| 644 EXPECT_TRUE(lock.GetGpuMemoryBuffer()); | 647 EXPECT_TRUE(lock.GetGpuMemoryBuffer()); |
| 645 } | 648 } |
| 646 | 649 |
| 647 GLuint external_texture_id = child_context_->createExternalTexture(); | 650 GLuint external_texture_id = child_context_->createExternalTexture(); |
| 648 | 651 |
| 649 gpu::Mailbox external_mailbox; | 652 gpu::Mailbox external_mailbox; |
| 650 child_context_->genMailboxCHROMIUM(external_mailbox.name); | 653 child_context_->genMailboxCHROMIUM(external_mailbox.name); |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1003 ResourceFormat format = RGBA_8888; | 1006 ResourceFormat format = RGBA_8888; |
| 1004 size_t pixel_size = TextureSizeBytes(size, format); | 1007 size_t pixel_size = TextureSizeBytes(size, format); |
| 1005 ASSERT_EQ(4U, pixel_size); | 1008 ASSERT_EQ(4U, pixel_size); |
| 1006 | 1009 |
| 1007 ResourceId id1 = child_resource_provider_->CreateResource( | 1010 ResourceId id1 = child_resource_provider_->CreateResource( |
| 1008 size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format, | 1011 size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format, |
| 1009 gfx::ColorSpace()); | 1012 gfx::ColorSpace()); |
| 1010 uint8_t data1[4] = {1, 2, 3, 4}; | 1013 uint8_t data1[4] = {1, 2, 3, 4}; |
| 1011 child_resource_provider_->CopyToResource(id1, data1, size); | 1014 child_resource_provider_->CopyToResource(id1, data1, size); |
| 1012 | 1015 |
| 1013 ResourceId id2 = child_resource_provider_->CreateResource( | 1016 ResourceId id2 = child_resource_provider_->CreateGpuMemoryBufferResource( |
| 1014 size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format, | 1017 size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format, |
| 1015 gfx::ColorSpace()); | 1018 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, gfx::ColorSpace()); |
| 1016 { | 1019 { |
| 1017 // Ensure locking the memory buffer doesn't create an unnecessary sync | 1020 // Ensure locking the memory buffer doesn't create an unnecessary sync |
| 1018 // point. | 1021 // point. |
| 1019 ResourceProvider::ScopedWriteLockGpuMemoryBuffer lock( | 1022 ResourceProvider::ScopedWriteLockGpuMemoryBuffer lock( |
| 1020 child_resource_provider_.get(), id2); | 1023 child_resource_provider_.get(), id2); |
| 1021 EXPECT_TRUE(lock.GetGpuMemoryBuffer()); | 1024 EXPECT_TRUE(lock.GetGpuMemoryBuffer()); |
| 1022 } | 1025 } |
| 1023 | 1026 |
| 1024 GLuint external_texture_id = child_context_->createExternalTexture(); | 1027 GLuint external_texture_id = child_context_->createExternalTexture(); |
| 1025 | 1028 |
| (...skipping 2351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3377 Mock::VerifyAndClearExpectations(context); | 3380 Mock::VerifyAndClearExpectations(context); |
| 3378 | 3381 |
| 3379 { | 3382 { |
| 3380 // WaitSyncTokenIfNeeded with empty sync_token shouldn't call waitSyncToken. | 3383 // WaitSyncTokenIfNeeded with empty sync_token shouldn't call waitSyncToken. |
| 3381 EXPECT_CALL(*context, waitSyncToken(_)).Times(0); | 3384 EXPECT_CALL(*context, waitSyncToken(_)).Times(0); |
| 3382 resource_provider->WaitSyncTokenIfNeeded(id); | 3385 resource_provider->WaitSyncTokenIfNeeded(id); |
| 3383 Mock::VerifyAndClearExpectations(context); | 3386 Mock::VerifyAndClearExpectations(context); |
| 3384 } | 3387 } |
| 3385 } | 3388 } |
| 3386 | 3389 |
| 3387 class AllocationTrackingContext3D : public TestWebGraphicsContext3D { | 3390 class AllocationTrackingContext3D : public TextureStateTrackingContext { |
| 3388 public: | 3391 public: |
| 3389 MOCK_METHOD0(NextTextureId, GLuint()); | 3392 MOCK_METHOD0(NextTextureId, GLuint()); |
| 3390 MOCK_METHOD1(RetireTextureId, void(GLuint id)); | 3393 MOCK_METHOD1(RetireTextureId, void(GLuint id)); |
| 3391 MOCK_METHOD2(bindTexture, void(GLenum target, GLuint texture)); | |
| 3392 MOCK_METHOD5(texStorage2DEXT, | 3394 MOCK_METHOD5(texStorage2DEXT, |
| 3393 void(GLenum target, | 3395 void(GLenum target, |
| 3394 GLint levels, | 3396 GLint levels, |
| 3395 GLuint internalformat, | 3397 GLuint internalformat, |
| 3396 GLint width, | 3398 GLint width, |
| 3397 GLint height)); | 3399 GLint height)); |
| 3398 MOCK_METHOD9(texImage2D, | 3400 MOCK_METHOD9(texImage2D, |
| 3399 void(GLenum target, | 3401 void(GLenum target, |
| 3400 GLint level, | 3402 GLint level, |
| 3401 GLenum internalformat, | 3403 GLenum internalformat, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3447 MOCK_METHOD1(waitAsyncTexImage2DCHROMIUM, void(GLenum)); | 3449 MOCK_METHOD1(waitAsyncTexImage2DCHROMIUM, void(GLenum)); |
| 3448 MOCK_METHOD4(createImageCHROMIUM, | 3450 MOCK_METHOD4(createImageCHROMIUM, |
| 3449 GLuint(ClientBuffer, GLsizei, GLsizei, GLenum)); | 3451 GLuint(ClientBuffer, GLsizei, GLsizei, GLenum)); |
| 3450 MOCK_METHOD1(destroyImageCHROMIUM, void(GLuint)); | 3452 MOCK_METHOD1(destroyImageCHROMIUM, void(GLuint)); |
| 3451 MOCK_METHOD2(bindTexImage2DCHROMIUM, void(GLenum, GLint)); | 3453 MOCK_METHOD2(bindTexImage2DCHROMIUM, void(GLenum, GLint)); |
| 3452 MOCK_METHOD2(releaseTexImage2DCHROMIUM, void(GLenum, GLint)); | 3454 MOCK_METHOD2(releaseTexImage2DCHROMIUM, void(GLenum, GLint)); |
| 3453 | 3455 |
| 3454 // We're mocking bindTexture, so we override | 3456 // We're mocking bindTexture, so we override |
| 3455 // TestWebGraphicsContext3D::texParameteri to avoid assertions related to the | 3457 // TestWebGraphicsContext3D::texParameteri to avoid assertions related to the |
| 3456 // currently bound texture. | 3458 // currently bound texture. |
| 3457 virtual void texParameteri(GLenum target, GLenum pname, GLint param) {} | 3459 void texParameteri(GLenum target, GLenum pname, GLint param) override {} |
| 3458 }; | 3460 }; |
| 3459 | 3461 |
| 3460 TEST_P(ResourceProviderTest, TextureAllocation) { | 3462 TEST_P(ResourceProviderTest, TextureAllocation) { |
| 3461 // Only for GL textures. | 3463 // Only for GL textures. |
| 3462 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) | 3464 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) |
| 3463 return; | 3465 return; |
| 3464 std::unique_ptr<AllocationTrackingContext3D> context_owned( | 3466 std::unique_ptr<AllocationTrackingContext3D> context_owned( |
| 3465 new StrictMock<AllocationTrackingContext3D>); | 3467 new StrictMock<AllocationTrackingContext3D>); |
| 3466 AllocationTrackingContext3D* context = context_owned.get(); | 3468 AllocationTrackingContext3D* context = context_owned.get(); |
| 3467 auto context_provider = TestContextProvider::Create(std::move(context_owned)); | 3469 auto context_provider = TestContextProvider::Create(std::move(context_owned)); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3624 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) | 3626 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) |
| 3625 return; | 3627 return; |
| 3626 std::unique_ptr<AllocationTrackingContext3D> context_owned( | 3628 std::unique_ptr<AllocationTrackingContext3D> context_owned( |
| 3627 new StrictMock<AllocationTrackingContext3D>); | 3629 new StrictMock<AllocationTrackingContext3D>); |
| 3628 AllocationTrackingContext3D* context = context_owned.get(); | 3630 AllocationTrackingContext3D* context = context_owned.get(); |
| 3629 auto context_provider = TestContextProvider::Create(std::move(context_owned)); | 3631 auto context_provider = TestContextProvider::Create(std::move(context_owned)); |
| 3630 context_provider->BindToCurrentThread(); | 3632 context_provider->BindToCurrentThread(); |
| 3631 | 3633 |
| 3632 const int kWidth = 2; | 3634 const int kWidth = 2; |
| 3633 const int kHeight = 2; | 3635 const int kHeight = 2; |
| 3634 gfx::Size size(kWidth, kHeight); | 3636 const ResourceFormat format = RGBA_8888; |
| 3635 ResourceFormat format = RGBA_8888; | |
| 3636 ResourceId id = 0; | |
| 3637 const unsigned kTextureId = 123u; | 3637 const unsigned kTextureId = 123u; |
| 3638 const unsigned kImageId = 234u; | 3638 const unsigned kImageId = 234u; |
| 3639 | 3639 |
| 3640 std::unique_ptr<ResourceProvider> resource_provider( | 3640 std::unique_ptr<ResourceProvider> resource_provider( |
| 3641 base::MakeUnique<ResourceProvider>( | 3641 base::MakeUnique<ResourceProvider>( |
| 3642 context_provider.get(), shared_bitmap_manager_.get(), | 3642 context_provider.get(), shared_bitmap_manager_.get(), |
| 3643 gpu_memory_buffer_manager_.get(), nullptr, | 3643 gpu_memory_buffer_manager_.get(), nullptr, |
| 3644 kDelegatedSyncPointsRequired, kEnableColorCorrectRendering, | 3644 kDelegatedSyncPointsRequired, kEnableColorCorrectRendering, |
| 3645 CreateResourceSettings())); | 3645 CreateResourceSettings())); |
| 3646 | 3646 |
| 3647 id = resource_provider->CreateResource( | 3647 ResourceId id = resource_provider->CreateGpuMemoryBufferResource( |
| 3648 size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format, | 3648 gfx::Size(kWidth, kHeight), ResourceProvider::TEXTURE_HINT_IMMUTABLE, |
| 3649 gfx::ColorSpace()); | 3649 format, gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, gfx::ColorSpace()); |
| 3650 | 3650 |
| 3651 EXPECT_CALL(*context, NextTextureId()) | 3651 InSequence sequence; |
| 3652 .WillOnce(Return(kTextureId)) | 3652 |
| 3653 .RetiresOnSaturation(); | 3653 // Image is created in the lock's dtor. |
| 3654 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)) | 3654 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(kTextureId)); |
| 3655 .Times(3) | 3655 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)); |
| 3656 .RetiresOnSaturation(); | |
| 3657 EXPECT_CALL(*context, createImageCHROMIUM(_, kWidth, kHeight, GL_RGBA)) | 3656 EXPECT_CALL(*context, createImageCHROMIUM(_, kWidth, kHeight, GL_RGBA)) |
| 3658 .WillOnce(Return(kImageId)) | 3657 .WillOnce(Return(kImageId)); |
| 3659 .RetiresOnSaturation(); | |
| 3660 { | 3658 { |
| 3661 ResourceProvider::ScopedWriteLockGpuMemoryBuffer lock( | 3659 ResourceProvider::ScopedWriteLockGpuMemoryBuffer lock( |
| 3662 resource_provider.get(), id); | 3660 resource_provider.get(), id); |
| 3663 EXPECT_TRUE(lock.GetGpuMemoryBuffer()); | 3661 EXPECT_TRUE(lock.GetGpuMemoryBuffer()); |
| 3664 } | 3662 } |
| 3665 | 3663 |
| 3666 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)) | |
| 3667 .Times(1) | |
| 3668 .RetiresOnSaturation(); | |
| 3669 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId)) | |
| 3670 .Times(1) | |
| 3671 .RetiresOnSaturation(); | |
| 3672 { | 3664 { |
| 3673 ResourceProvider::ScopedSamplerGL lock_gl( | 3665 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)).Times(2); |
| 3674 resource_provider.get(), id, GL_TEXTURE_2D, GL_LINEAR); | 3666 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId)); |
| 3667 ResourceProvider::ScopedSamplerGL lock_gl(resource_provider.get(), id, |
| 3668 GL_TEXTURE_2D, GL_LINEAR); |
| 3675 EXPECT_EQ(kTextureId, lock_gl.texture_id()); | 3669 EXPECT_EQ(kTextureId, lock_gl.texture_id()); |
| 3676 } | 3670 } |
| 3677 | 3671 |
| 3678 { | 3672 { |
| 3679 ResourceProvider::ScopedWriteLockGpuMemoryBuffer lock( | 3673 ResourceProvider::ScopedWriteLockGpuMemoryBuffer lock( |
| 3680 resource_provider.get(), id); | 3674 resource_provider.get(), id); |
| 3681 EXPECT_TRUE(lock.GetGpuMemoryBuffer()); | 3675 EXPECT_TRUE(lock.GetGpuMemoryBuffer()); |
| 3682 } | 3676 } |
| 3683 | 3677 |
| 3684 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)).Times(1) | 3678 // Upload to GPU again since image is dirty after the write lock. |
| 3685 .RetiresOnSaturation(); | |
| 3686 EXPECT_CALL(*context, releaseTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId)) | |
| 3687 .Times(1) | |
| 3688 .RetiresOnSaturation(); | |
| 3689 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId)) | |
| 3690 .Times(1) | |
| 3691 .RetiresOnSaturation(); | |
| 3692 EXPECT_CALL(*context, RetireTextureId(kTextureId)) | |
| 3693 .Times(1) | |
| 3694 .RetiresOnSaturation(); | |
| 3695 { | 3679 { |
| 3696 ResourceProvider::ScopedSamplerGL lock_gl( | 3680 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)).Times(2); |
| 3697 resource_provider.get(), id, GL_TEXTURE_2D, GL_LINEAR); | 3681 EXPECT_CALL(*context, releaseTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId)); |
| 3682 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId)); |
| 3683 ResourceProvider::ScopedSamplerGL lock_gl(resource_provider.get(), id, |
| 3684 GL_TEXTURE_2D, GL_LINEAR); |
| 3698 EXPECT_EQ(kTextureId, lock_gl.texture_id()); | 3685 EXPECT_EQ(kTextureId, lock_gl.texture_id()); |
| 3699 } | 3686 } |
| 3700 | 3687 |
| 3701 EXPECT_CALL(*context, destroyImageCHROMIUM(kImageId)) | 3688 EXPECT_CALL(*context, destroyImageCHROMIUM(kImageId)); |
| 3702 .Times(1) | 3689 EXPECT_CALL(*context, RetireTextureId(kTextureId)); |
| 3703 .RetiresOnSaturation(); | |
| 3704 } | 3690 } |
| 3705 | 3691 |
| 3706 TEST_P(ResourceProviderTest, CompressedTextureETC1Allocate) { | 3692 TEST_P(ResourceProviderTest, CompressedTextureETC1Allocate) { |
| 3707 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) | 3693 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) |
| 3708 return; | 3694 return; |
| 3709 | 3695 |
| 3710 std::unique_ptr<AllocationTrackingContext3D> context_owned( | 3696 std::unique_ptr<AllocationTrackingContext3D> context_owned( |
| 3711 new AllocationTrackingContext3D); | 3697 new AllocationTrackingContext3D); |
| 3712 AllocationTrackingContext3D* context = context_owned.get(); | 3698 AllocationTrackingContext3D* context = context_owned.get(); |
| 3713 context_owned->set_support_compressed_texture_etc1(true); | 3699 context_owned->set_support_compressed_texture_etc1(true); |
| 3714 auto context_provider = TestContextProvider::Create(std::move(context_owned)); | 3700 auto context_provider = TestContextProvider::Create(std::move(context_owned)); |
| 3715 context_provider->BindToCurrentThread(); | 3701 context_provider->BindToCurrentThread(); |
| 3716 | 3702 |
| 3717 gfx::Size size(4, 4); | 3703 gfx::Size size(4, 4); |
| 3718 std::unique_ptr<ResourceProvider> resource_provider( | 3704 std::unique_ptr<ResourceProvider> resource_provider( |
| 3719 base::MakeUnique<ResourceProvider>( | 3705 base::MakeUnique<ResourceProvider>( |
| 3720 context_provider.get(), shared_bitmap_manager_.get(), | 3706 context_provider.get(), shared_bitmap_manager_.get(), |
| 3721 gpu_memory_buffer_manager_.get(), nullptr, | 3707 gpu_memory_buffer_manager_.get(), nullptr, |
| 3722 kDelegatedSyncPointsRequired, kEnableColorCorrectRendering, | 3708 kDelegatedSyncPointsRequired, kEnableColorCorrectRendering, |
| 3723 CreateResourceSettings())); | 3709 CreateResourceSettings())); |
| 3724 int texture_id = 123; | 3710 int texture_id = 123; |
| 3725 | 3711 |
| 3726 ResourceId id = resource_provider->CreateResource( | 3712 ResourceId id = resource_provider->CreateResource( |
| 3727 size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, ETC1, gfx::ColorSpace()); | 3713 size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, ETC1, gfx::ColorSpace()); |
| 3728 EXPECT_NE(0u, id); | 3714 EXPECT_NE(0u, id); |
| 3729 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); | 3715 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); |
| 3730 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); | 3716 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(1); |
| 3731 resource_provider->AllocateForTesting(id); | 3717 resource_provider->AllocateForTesting(id); |
| 3732 | 3718 |
| 3733 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); | 3719 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); |
| 3734 resource_provider->DeleteResource(id); | 3720 resource_provider->DeleteResource(id); |
| 3735 } | 3721 } |
| 3736 | 3722 |
| 3737 TEST_P(ResourceProviderTest, CompressedTextureETC1Upload) { | 3723 TEST_P(ResourceProviderTest, CompressedTextureETC1Upload) { |
| 3738 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) | 3724 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) |
| 3739 return; | 3725 return; |
| 3740 | 3726 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 3752 gpu_memory_buffer_manager_.get(), nullptr, | 3738 gpu_memory_buffer_manager_.get(), nullptr, |
| 3753 kDelegatedSyncPointsRequired, kEnableColorCorrectRendering, | 3739 kDelegatedSyncPointsRequired, kEnableColorCorrectRendering, |
| 3754 CreateResourceSettings())); | 3740 CreateResourceSettings())); |
| 3755 int texture_id = 123; | 3741 int texture_id = 123; |
| 3756 uint8_t pixels[8]; | 3742 uint8_t pixels[8]; |
| 3757 | 3743 |
| 3758 ResourceId id = resource_provider->CreateResource( | 3744 ResourceId id = resource_provider->CreateResource( |
| 3759 size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, ETC1, gfx::ColorSpace()); | 3745 size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, ETC1, gfx::ColorSpace()); |
| 3760 EXPECT_NE(0u, id); | 3746 EXPECT_NE(0u, id); |
| 3761 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); | 3747 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); |
| 3762 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(3); | 3748 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); |
| 3763 EXPECT_CALL(*context, | 3749 EXPECT_CALL(*context, |
| 3764 compressedTexImage2D( | 3750 compressedTexImage2D( |
| 3765 _, 0, _, size.width(), size.height(), _, _, _)).Times(1); | 3751 _, 0, _, size.width(), size.height(), _, _, _)).Times(1); |
| 3766 resource_provider->CopyToResource(id, pixels, size); | 3752 resource_provider->CopyToResource(id, pixels, size); |
| 3767 | 3753 |
| 3768 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); | 3754 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); |
| 3769 resource_provider->DeleteResource(id); | 3755 resource_provider->DeleteResource(id); |
| 3770 } | 3756 } |
| 3771 | 3757 |
| 3772 INSTANTIATE_TEST_CASE_P( | 3758 INSTANTIATE_TEST_CASE_P( |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3859 token.Set(gpu::CommandBufferNamespace::INVALID, 0, gpu::CommandBufferId(), | 3845 token.Set(gpu::CommandBufferNamespace::INVALID, 0, gpu::CommandBufferId(), |
| 3860 release_counts[i]); | 3846 release_counts[i]); |
| 3861 lock.set_sync_token(token); | 3847 lock.set_sync_token(token); |
| 3862 } | 3848 } |
| 3863 | 3849 |
| 3864 gpu::SyncToken last_token = | 3850 gpu::SyncToken last_token = |
| 3865 resource_provider_->GetSyncTokenForResources(array); | 3851 resource_provider_->GetSyncTokenForResources(array); |
| 3866 EXPECT_EQ(last_token.release_count(), 10u); | 3852 EXPECT_EQ(last_token.release_count(), 10u); |
| 3867 } | 3853 } |
| 3868 | 3854 |
| 3855 TEST_P(ResourceProviderTest, ScopedWriteLockGL) { |
| 3856 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) |
| 3857 return; |
| 3858 std::unique_ptr<AllocationTrackingContext3D> context_owned( |
| 3859 new StrictMock<AllocationTrackingContext3D>); |
| 3860 AllocationTrackingContext3D* context = context_owned.get(); |
| 3861 auto context_provider = TestContextProvider::Create(std::move(context_owned)); |
| 3862 context_provider->BindToCurrentThread(); |
| 3863 |
| 3864 const int kWidth = 2; |
| 3865 const int kHeight = 2; |
| 3866 const ResourceFormat format = RGBA_8888; |
| 3867 const unsigned kTextureId = 123u; |
| 3868 |
| 3869 std::unique_ptr<ResourceProvider> resource_provider( |
| 3870 base::MakeUnique<ResourceProvider>( |
| 3871 context_provider.get(), shared_bitmap_manager_.get(), |
| 3872 gpu_memory_buffer_manager_.get(), nullptr, 1, |
| 3873 kDelegatedSyncPointsRequired, kUseGpuMemoryBufferResources, |
| 3874 kEnableColorCorrectRendering, |
| 3875 DefaultBufferToTextureTargetMapForTesting())); |
| 3876 |
| 3877 ResourceId id = resource_provider->CreateResource( |
| 3878 gfx::Size(kWidth, kHeight), ResourceProvider::TEXTURE_HINT_IMMUTABLE, |
| 3879 format, gfx::ColorSpace()); |
| 3880 |
| 3881 InSequence sequence; |
| 3882 |
| 3883 // First use will allocate lazily on creation of lock. |
| 3884 { |
| 3885 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(kTextureId)); |
| 3886 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)).Times(2); |
| 3887 EXPECT_CALL(*context, texImage2D(GL_TEXTURE_2D, 0, GLInternalFormat(format), |
| 3888 kWidth, kHeight, 0, GLDataFormat(format), |
| 3889 GLDataType(format), nullptr)); |
| 3890 ResourceProvider::ScopedWriteLockGL lock(resource_provider.get(), id, |
| 3891 false); |
| 3892 } |
| 3893 |
| 3894 // Subsequent uses will not allocate. |
| 3895 { |
| 3896 ResourceProvider::ScopedWriteLockGL lock(resource_provider.get(), id, |
| 3897 false); |
| 3898 } |
| 3899 |
| 3900 EXPECT_CALL(*context, RetireTextureId(kTextureId)); |
| 3901 resource_provider->DeleteResource(id); |
| 3902 } |
| 3903 |
| 3904 TEST_P(ResourceProviderTest, ScopedWriteLockGL_GpuMemoryBuffer) { |
| 3905 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) |
| 3906 return; |
| 3907 std::unique_ptr<AllocationTrackingContext3D> context_owned( |
| 3908 new StrictMock<AllocationTrackingContext3D>); |
| 3909 AllocationTrackingContext3D* context = context_owned.get(); |
| 3910 auto context_provider = TestContextProvider::Create(std::move(context_owned)); |
| 3911 context_provider->BindToCurrentThread(); |
| 3912 |
| 3913 const int kWidth = 2; |
| 3914 const int kHeight = 2; |
| 3915 const ResourceFormat format = RGBA_8888; |
| 3916 const unsigned kTextureId = 123u; |
| 3917 const unsigned kImageId = 234u; |
| 3918 |
| 3919 std::unique_ptr<ResourceProvider> resource_provider( |
| 3920 base::MakeUnique<ResourceProvider>( |
| 3921 context_provider.get(), shared_bitmap_manager_.get(), |
| 3922 gpu_memory_buffer_manager_.get(), nullptr, 1, |
| 3923 kDelegatedSyncPointsRequired, kUseGpuMemoryBufferResources, |
| 3924 kEnableColorCorrectRendering, |
| 3925 DefaultBufferToTextureTargetMapForTesting())); |
| 3926 |
| 3927 ResourceId id = resource_provider->CreateGpuMemoryBufferResource( |
| 3928 gfx::Size(kWidth, kHeight), ResourceProvider::TEXTURE_HINT_IMMUTABLE, |
| 3929 format, gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, gfx::ColorSpace()); |
| 3930 |
| 3931 InSequence sequence; |
| 3932 |
| 3933 // First use will allocate lazily on creation of lock. |
| 3934 { |
| 3935 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(kTextureId)); |
| 3936 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)); |
| 3937 EXPECT_CALL(*context, createImageCHROMIUM(_, kWidth, kHeight, |
| 3938 GLInternalFormat(format))) |
| 3939 .WillOnce(Return(kImageId)); |
| 3940 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)); |
| 3941 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId)); |
| 3942 ResourceProvider::ScopedWriteLockGL lock(resource_provider.get(), id, |
| 3943 false); |
| 3944 } |
| 3945 |
| 3946 // Subsequent uses will not allocate. |
| 3947 { |
| 3948 ResourceProvider::ScopedWriteLockGL lock(resource_provider.get(), id, |
| 3949 false); |
| 3950 } |
| 3951 |
| 3952 EXPECT_CALL(*context, destroyImageCHROMIUM(kImageId)); |
| 3953 EXPECT_CALL(*context, RetireTextureId(kTextureId)); |
| 3954 resource_provider->DeleteResource(id); |
| 3955 } |
| 3956 |
| 3957 TEST_P(ResourceProviderTest, ScopedWriteLockGL_AsyncWorkerContext) { |
| 3958 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) |
| 3959 return; |
| 3960 std::unique_ptr<AllocationTrackingContext3D> context_owned( |
| 3961 new StrictMock<AllocationTrackingContext3D>); |
| 3962 AllocationTrackingContext3D* context = context_owned.get(); |
| 3963 auto context_provider = TestContextProvider::Create(std::move(context_owned)); |
| 3964 context_provider->BindToCurrentThread(); |
| 3965 |
| 3966 const int kWidth = 2; |
| 3967 const int kHeight = 2; |
| 3968 const ResourceFormat format = RGBA_8888; |
| 3969 const unsigned kTextureId = 123u; |
| 3970 const unsigned kWorkerTextureId = 234u; |
| 3971 |
| 3972 std::unique_ptr<ResourceProvider> resource_provider( |
| 3973 base::MakeUnique<ResourceProvider>( |
| 3974 context_provider.get(), shared_bitmap_manager_.get(), |
| 3975 gpu_memory_buffer_manager_.get(), nullptr, 1, |
| 3976 kDelegatedSyncPointsRequired, kUseGpuMemoryBufferResources, |
| 3977 kEnableColorCorrectRendering, |
| 3978 DefaultBufferToTextureTargetMapForTesting())); |
| 3979 |
| 3980 ResourceId id = resource_provider->CreateResource( |
| 3981 gfx::Size(kWidth, kHeight), ResourceProvider::TEXTURE_HINT_IMMUTABLE, |
| 3982 format, gfx::ColorSpace()); |
| 3983 |
| 3984 gpu::SyncToken sync_token; |
| 3985 context->genSyncToken(context->insertFenceSync(), sync_token.GetData()); |
| 3986 |
| 3987 InSequence sequence; |
| 3988 |
| 3989 // First use will create mailbox when lock is created and allocate lazily in |
| 3990 // ConsumeTexture. |
| 3991 { |
| 3992 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(kTextureId)); |
| 3993 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)); |
| 3994 EXPECT_CALL(*context, |
| 3995 produceTextureDirectCHROMIUM(kTextureId, GL_TEXTURE_2D, _)); |
| 3996 ResourceProvider::ScopedWriteLockGL lock(resource_provider.get(), id, true); |
| 3997 |
| 3998 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, _)) |
| 3999 .WillOnce(Return(kWorkerTextureId)); |
| 4000 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kWorkerTextureId)); |
| 4001 EXPECT_CALL(*context, texImage2D(GL_TEXTURE_2D, 0, GLInternalFormat(format), |
| 4002 kWidth, kHeight, 0, GLDataFormat(format), |
| 4003 GLDataType(format), nullptr)); |
| 4004 EXPECT_EQ(kWorkerTextureId, |
| 4005 lock.ConsumeTexture(context_provider->ContextGL())); |
| 4006 |
| 4007 EXPECT_CALL(*context, RetireTextureId(kWorkerTextureId)); |
| 4008 context_provider->ContextGL()->DeleteTextures(1, &kWorkerTextureId); |
| 4009 } |
| 4010 |
| 4011 // Subsequent uses will not create mailbox or allocate. |
| 4012 { |
| 4013 ResourceProvider::ScopedWriteLockGL lock(resource_provider.get(), id, true); |
| 4014 |
| 4015 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, _)) |
| 4016 .WillOnce(Return(kWorkerTextureId)); |
| 4017 EXPECT_EQ(kWorkerTextureId, |
| 4018 lock.ConsumeTexture(context_provider->ContextGL())); |
| 4019 |
| 4020 lock.set_sync_token(sync_token); |
| 4021 |
| 4022 EXPECT_CALL(*context, RetireTextureId(kWorkerTextureId)); |
| 4023 context_provider->ContextGL()->DeleteTextures(1, &kWorkerTextureId); |
| 4024 } |
| 4025 |
| 4026 // Wait for worker context sync token before deleting texture. |
| 4027 EXPECT_CALL(*context, waitSyncToken(MatchesSyncToken(sync_token))); |
| 4028 EXPECT_CALL(*context, RetireTextureId(kTextureId)); |
| 4029 resource_provider->DeleteResource(id); |
| 4030 } |
| 4031 |
| 4032 TEST_P(ResourceProviderTest, |
| 4033 ScopedWriteLockGL_GpuMemoryBuffer_AsyncWorkerContext) { |
| 4034 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) |
| 4035 return; |
| 4036 std::unique_ptr<AllocationTrackingContext3D> context_owned( |
| 4037 new StrictMock<AllocationTrackingContext3D>); |
| 4038 AllocationTrackingContext3D* context = context_owned.get(); |
| 4039 auto context_provider = TestContextProvider::Create(std::move(context_owned)); |
| 4040 context_provider->BindToCurrentThread(); |
| 4041 |
| 4042 const int kWidth = 2; |
| 4043 const int kHeight = 2; |
| 4044 const ResourceFormat format = RGBA_8888; |
| 4045 const unsigned kTextureId = 123u; |
| 4046 const unsigned kWorkerTextureId = 234u; |
| 4047 const unsigned kImageId = 345u; |
| 4048 |
| 4049 std::unique_ptr<ResourceProvider> resource_provider( |
| 4050 base::MakeUnique<ResourceProvider>( |
| 4051 context_provider.get(), shared_bitmap_manager_.get(), |
| 4052 gpu_memory_buffer_manager_.get(), nullptr, 1, |
| 4053 kDelegatedSyncPointsRequired, kUseGpuMemoryBufferResources, |
| 4054 kEnableColorCorrectRendering, |
| 4055 DefaultBufferToTextureTargetMapForTesting())); |
| 4056 |
| 4057 ResourceId id = resource_provider->CreateGpuMemoryBufferResource( |
| 4058 gfx::Size(kWidth, kHeight), ResourceProvider::TEXTURE_HINT_IMMUTABLE, |
| 4059 format, gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, gfx::ColorSpace()); |
| 4060 |
| 4061 gpu::SyncToken sync_token; |
| 4062 context->genSyncToken(context->insertFenceSync(), sync_token.GetData()); |
| 4063 |
| 4064 InSequence sequence; |
| 4065 |
| 4066 // First use will create mailbox when lock is created and allocate lazily in |
| 4067 // ConsumeTexture. |
| 4068 { |
| 4069 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(kTextureId)); |
| 4070 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)); |
| 4071 EXPECT_CALL(*context, |
| 4072 produceTextureDirectCHROMIUM(kTextureId, GL_TEXTURE_2D, _)); |
| 4073 ResourceProvider::ScopedWriteLockGL lock(resource_provider.get(), id, true); |
| 4074 |
| 4075 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, _)) |
| 4076 .WillOnce(Return(kWorkerTextureId)); |
| 4077 EXPECT_CALL(*context, createImageCHROMIUM(_, kWidth, kHeight, |
| 4078 GLInternalFormat(format))) |
| 4079 .WillOnce(Return(kImageId)); |
| 4080 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kWorkerTextureId)); |
| 4081 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId)); |
| 4082 EXPECT_EQ(kWorkerTextureId, |
| 4083 lock.ConsumeTexture(context_provider->ContextGL())); |
| 4084 |
| 4085 EXPECT_CALL(*context, RetireTextureId(kWorkerTextureId)); |
| 4086 context_provider->ContextGL()->DeleteTextures(1, &kWorkerTextureId); |
| 4087 } |
| 4088 |
| 4089 // Subsequent uses will not create mailbox or allocate. |
| 4090 { |
| 4091 ResourceProvider::ScopedWriteLockGL lock(resource_provider.get(), id, true); |
| 4092 |
| 4093 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, _)) |
| 4094 .WillOnce(Return(kWorkerTextureId)); |
| 4095 EXPECT_EQ(kWorkerTextureId, |
| 4096 lock.ConsumeTexture(context_provider->ContextGL())); |
| 4097 |
| 4098 lock.set_sync_token(sync_token); |
| 4099 |
| 4100 EXPECT_CALL(*context, RetireTextureId(kWorkerTextureId)); |
| 4101 context_provider->ContextGL()->DeleteTextures(1, &kWorkerTextureId); |
| 4102 } |
| 4103 |
| 4104 // Wait for worker context sync token before deleting texture. |
| 4105 EXPECT_CALL(*context, waitSyncToken(MatchesSyncToken(sync_token))); |
| 4106 EXPECT_CALL(*context, destroyImageCHROMIUM(kImageId)); |
| 4107 EXPECT_CALL(*context, RetireTextureId(kTextureId)); |
| 4108 resource_provider->DeleteResource(id); |
| 4109 } |
| 4110 |
| 3869 } // namespace | 4111 } // namespace |
| 3870 } // namespace cc | 4112 } // namespace cc |
| OLD | NEW |