Chromium Code Reviews| 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 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 617 size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format, color_space1); | 620 size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format, color_space1); |
| 618 uint8_t data1[4] = { 1, 2, 3, 4 }; | 621 uint8_t data1[4] = { 1, 2, 3, 4 }; |
| 619 child_resource_provider_->CopyToResource(id1, data1, size); | 622 child_resource_provider_->CopyToResource(id1, data1, size); |
| 620 | 623 |
| 621 ResourceId id2 = child_resource_provider_->CreateResource( | 624 ResourceId id2 = child_resource_provider_->CreateResource( |
| 622 size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format, | 625 size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format, |
| 623 gfx::ColorSpace()); | 626 gfx::ColorSpace()); |
| 624 uint8_t data2[4] = { 5, 5, 5, 5 }; | 627 uint8_t data2[4] = { 5, 5, 5, 5 }; |
| 625 child_resource_provider_->CopyToResource(id2, data2, size); | 628 child_resource_provider_->CopyToResource(id2, data2, size); |
| 626 | 629 |
| 627 ResourceId id3 = child_resource_provider_->CreateResource( | 630 ResourceId id3 = child_resource_provider_->CreateGpuMemoryBufferResource( |
| 628 size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format, | 631 size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format, |
| 629 gfx::ColorSpace()); | 632 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, gfx::ColorSpace()); |
| 630 { | 633 { |
| 631 ResourceProvider::ScopedWriteLockGpuMemoryBuffer lock( | 634 ResourceProvider::ScopedWriteLockGpuMemoryBuffer lock( |
| 632 child_resource_provider_.get(), id3); | 635 child_resource_provider_.get(), id3); |
| 633 EXPECT_TRUE(lock.GetGpuMemoryBuffer()); | 636 EXPECT_TRUE(lock.GetGpuMemoryBuffer()); |
| 634 } | 637 } |
| 635 | 638 |
| 636 GLuint external_texture_id = child_context_->createExternalTexture(); | 639 GLuint external_texture_id = child_context_->createExternalTexture(); |
| 637 | 640 |
| 638 gpu::Mailbox external_mailbox; | 641 gpu::Mailbox external_mailbox; |
| 639 child_context_->genMailboxCHROMIUM(external_mailbox.name); | 642 child_context_->genMailboxCHROMIUM(external_mailbox.name); |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 992 ResourceFormat format = RGBA_8888; | 995 ResourceFormat format = RGBA_8888; |
| 993 size_t pixel_size = TextureSizeBytes(size, format); | 996 size_t pixel_size = TextureSizeBytes(size, format); |
| 994 ASSERT_EQ(4U, pixel_size); | 997 ASSERT_EQ(4U, pixel_size); |
| 995 | 998 |
| 996 ResourceId id1 = child_resource_provider_->CreateResource( | 999 ResourceId id1 = child_resource_provider_->CreateResource( |
| 997 size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format, | 1000 size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format, |
| 998 gfx::ColorSpace()); | 1001 gfx::ColorSpace()); |
| 999 uint8_t data1[4] = {1, 2, 3, 4}; | 1002 uint8_t data1[4] = {1, 2, 3, 4}; |
| 1000 child_resource_provider_->CopyToResource(id1, data1, size); | 1003 child_resource_provider_->CopyToResource(id1, data1, size); |
| 1001 | 1004 |
| 1002 ResourceId id2 = child_resource_provider_->CreateResource( | 1005 ResourceId id2 = child_resource_provider_->CreateGpuMemoryBufferResource( |
| 1003 size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format, | 1006 size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format, |
| 1004 gfx::ColorSpace()); | 1007 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, gfx::ColorSpace()); |
| 1005 { | 1008 { |
| 1006 // Ensure locking the memory buffer doesn't create an unnecessary sync | 1009 // Ensure locking the memory buffer doesn't create an unnecessary sync |
| 1007 // point. | 1010 // point. |
| 1008 ResourceProvider::ScopedWriteLockGpuMemoryBuffer lock( | 1011 ResourceProvider::ScopedWriteLockGpuMemoryBuffer lock( |
| 1009 child_resource_provider_.get(), id2); | 1012 child_resource_provider_.get(), id2); |
| 1010 EXPECT_TRUE(lock.GetGpuMemoryBuffer()); | 1013 EXPECT_TRUE(lock.GetGpuMemoryBuffer()); |
| 1011 } | 1014 } |
| 1012 | 1015 |
| 1013 GLuint external_texture_id = child_context_->createExternalTexture(); | 1016 GLuint external_texture_id = child_context_->createExternalTexture(); |
| 1014 | 1017 |
| (...skipping 2362 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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3627 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) | 3629 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) |
| 3628 return; | 3630 return; |
| 3629 std::unique_ptr<AllocationTrackingContext3D> context_owned( | 3631 std::unique_ptr<AllocationTrackingContext3D> context_owned( |
| 3630 new StrictMock<AllocationTrackingContext3D>); | 3632 new StrictMock<AllocationTrackingContext3D>); |
| 3631 AllocationTrackingContext3D* context = context_owned.get(); | 3633 AllocationTrackingContext3D* context = context_owned.get(); |
| 3632 auto context_provider = TestContextProvider::Create(std::move(context_owned)); | 3634 auto context_provider = TestContextProvider::Create(std::move(context_owned)); |
| 3633 context_provider->BindToCurrentThread(); | 3635 context_provider->BindToCurrentThread(); |
| 3634 | 3636 |
| 3635 const int kWidth = 2; | 3637 const int kWidth = 2; |
| 3636 const int kHeight = 2; | 3638 const int kHeight = 2; |
| 3637 gfx::Size size(kWidth, kHeight); | 3639 const ResourceFormat format = RGBA_8888; |
| 3638 ResourceFormat format = RGBA_8888; | |
| 3639 ResourceId id = 0; | |
| 3640 const unsigned kTextureId = 123u; | 3640 const unsigned kTextureId = 123u; |
| 3641 const unsigned kImageId = 234u; | 3641 const unsigned kImageId = 234u; |
| 3642 | 3642 |
| 3643 std::unique_ptr<ResourceProvider> resource_provider( | 3643 std::unique_ptr<ResourceProvider> resource_provider( |
| 3644 base::MakeUnique<ResourceProvider>( | 3644 base::MakeUnique<ResourceProvider>( |
| 3645 context_provider.get(), shared_bitmap_manager_.get(), | 3645 context_provider.get(), shared_bitmap_manager_.get(), |
| 3646 gpu_memory_buffer_manager_.get(), nullptr, 1, | 3646 gpu_memory_buffer_manager_.get(), nullptr, 1, |
| 3647 kDelegatedSyncPointsRequired, kUseGpuMemoryBufferResources, | 3647 kDelegatedSyncPointsRequired, kUseGpuMemoryBufferResources, |
| 3648 kEnableColorCorrectRendering, | 3648 kEnableColorCorrectRendering, |
| 3649 DefaultBufferToTextureTargetMapForTesting())); | 3649 DefaultBufferToTextureTargetMapForTesting())); |
| 3650 | 3650 |
| 3651 id = resource_provider->CreateResource( | 3651 ResourceId id = resource_provider->CreateGpuMemoryBufferResource( |
| 3652 size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format, | 3652 gfx::Size(kWidth, kHeight), ResourceProvider::TEXTURE_HINT_IMMUTABLE, |
| 3653 gfx::ColorSpace()); | 3653 format, gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, gfx::ColorSpace()); |
| 3654 | 3654 |
| 3655 EXPECT_CALL(*context, NextTextureId()) | 3655 InSequence sequence; |
| 3656 .WillOnce(Return(kTextureId)) | 3656 |
| 3657 .RetiresOnSaturation(); | 3657 // Image is created in the lock's dtor. |
| 3658 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)) | 3658 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(kTextureId)); |
| 3659 .Times(3) | 3659 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)); |
| 3660 .RetiresOnSaturation(); | |
| 3661 EXPECT_CALL(*context, createImageCHROMIUM(_, kWidth, kHeight, GL_RGBA)) | 3660 EXPECT_CALL(*context, createImageCHROMIUM(_, kWidth, kHeight, GL_RGBA)) |
| 3662 .WillOnce(Return(kImageId)) | 3661 .WillOnce(Return(kImageId)); |
| 3663 .RetiresOnSaturation(); | |
| 3664 { | 3662 { |
| 3665 ResourceProvider::ScopedWriteLockGpuMemoryBuffer lock( | 3663 ResourceProvider::ScopedWriteLockGpuMemoryBuffer lock( |
| 3666 resource_provider.get(), id); | 3664 resource_provider.get(), id); |
| 3667 EXPECT_TRUE(lock.GetGpuMemoryBuffer()); | 3665 EXPECT_TRUE(lock.GetGpuMemoryBuffer()); |
| 3668 } | 3666 } |
| 3669 | 3667 |
| 3670 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)) | |
| 3671 .Times(1) | |
| 3672 .RetiresOnSaturation(); | |
| 3673 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId)) | |
| 3674 .Times(1) | |
| 3675 .RetiresOnSaturation(); | |
| 3676 { | 3668 { |
| 3677 ResourceProvider::ScopedSamplerGL lock_gl( | 3669 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)).Times(2); |
| 3678 resource_provider.get(), id, GL_TEXTURE_2D, GL_LINEAR); | 3670 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId)); |
| 3671 ResourceProvider::ScopedSamplerGL lock_gl(resource_provider.get(), id, | |
| 3672 GL_TEXTURE_2D, GL_LINEAR); | |
| 3679 EXPECT_EQ(kTextureId, lock_gl.texture_id()); | 3673 EXPECT_EQ(kTextureId, lock_gl.texture_id()); |
| 3680 } | 3674 } |
| 3681 | 3675 |
| 3682 { | 3676 { |
| 3683 ResourceProvider::ScopedWriteLockGpuMemoryBuffer lock( | 3677 ResourceProvider::ScopedWriteLockGpuMemoryBuffer lock( |
| 3684 resource_provider.get(), id); | 3678 resource_provider.get(), id); |
| 3685 EXPECT_TRUE(lock.GetGpuMemoryBuffer()); | 3679 EXPECT_TRUE(lock.GetGpuMemoryBuffer()); |
| 3686 } | 3680 } |
| 3687 | 3681 |
| 3688 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)).Times(1) | 3682 // Upload to GPU again since image is dirty after the write lock. |
| 3689 .RetiresOnSaturation(); | |
| 3690 EXPECT_CALL(*context, releaseTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId)) | |
| 3691 .Times(1) | |
| 3692 .RetiresOnSaturation(); | |
| 3693 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId)) | |
| 3694 .Times(1) | |
| 3695 .RetiresOnSaturation(); | |
| 3696 EXPECT_CALL(*context, RetireTextureId(kTextureId)) | |
| 3697 .Times(1) | |
| 3698 .RetiresOnSaturation(); | |
| 3699 { | 3683 { |
| 3700 ResourceProvider::ScopedSamplerGL lock_gl( | 3684 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)).Times(2); |
| 3701 resource_provider.get(), id, GL_TEXTURE_2D, GL_LINEAR); | 3685 EXPECT_CALL(*context, releaseTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId)); |
| 3686 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId)); | |
| 3687 ResourceProvider::ScopedSamplerGL lock_gl(resource_provider.get(), id, | |
| 3688 GL_TEXTURE_2D, GL_LINEAR); | |
| 3702 EXPECT_EQ(kTextureId, lock_gl.texture_id()); | 3689 EXPECT_EQ(kTextureId, lock_gl.texture_id()); |
| 3703 } | 3690 } |
| 3704 | 3691 |
| 3705 EXPECT_CALL(*context, destroyImageCHROMIUM(kImageId)) | 3692 EXPECT_CALL(*context, destroyImageCHROMIUM(kImageId)); |
| 3706 .Times(1) | 3693 EXPECT_CALL(*context, RetireTextureId(kTextureId)); |
| 3707 .RetiresOnSaturation(); | |
| 3708 } | 3694 } |
| 3709 | 3695 |
| 3710 TEST_P(ResourceProviderTest, CompressedTextureETC1Allocate) { | 3696 TEST_P(ResourceProviderTest, CompressedTextureETC1Allocate) { |
| 3711 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) | 3697 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) |
| 3712 return; | 3698 return; |
| 3713 | 3699 |
| 3714 std::unique_ptr<AllocationTrackingContext3D> context_owned( | 3700 std::unique_ptr<AllocationTrackingContext3D> context_owned( |
| 3715 new AllocationTrackingContext3D); | 3701 new AllocationTrackingContext3D); |
| 3716 AllocationTrackingContext3D* context = context_owned.get(); | 3702 AllocationTrackingContext3D* context = context_owned.get(); |
| 3717 context_owned->set_support_compressed_texture_etc1(true); | 3703 context_owned->set_support_compressed_texture_etc1(true); |
| 3718 auto context_provider = TestContextProvider::Create(std::move(context_owned)); | 3704 auto context_provider = TestContextProvider::Create(std::move(context_owned)); |
| 3719 context_provider->BindToCurrentThread(); | 3705 context_provider->BindToCurrentThread(); |
| 3720 | 3706 |
| 3721 gfx::Size size(4, 4); | 3707 gfx::Size size(4, 4); |
| 3722 std::unique_ptr<ResourceProvider> resource_provider( | 3708 std::unique_ptr<ResourceProvider> resource_provider( |
| 3723 base::MakeUnique<ResourceProvider>( | 3709 base::MakeUnique<ResourceProvider>( |
| 3724 context_provider.get(), shared_bitmap_manager_.get(), | 3710 context_provider.get(), shared_bitmap_manager_.get(), |
| 3725 gpu_memory_buffer_manager_.get(), nullptr, 1, | 3711 gpu_memory_buffer_manager_.get(), nullptr, 1, |
| 3726 kDelegatedSyncPointsRequired, kUseGpuMemoryBufferResources, | 3712 kDelegatedSyncPointsRequired, kUseGpuMemoryBufferResources, |
| 3727 kEnableColorCorrectRendering, | 3713 kEnableColorCorrectRendering, |
| 3728 DefaultBufferToTextureTargetMapForTesting())); | 3714 DefaultBufferToTextureTargetMapForTesting())); |
| 3729 int texture_id = 123; | 3715 int texture_id = 123; |
| 3730 | 3716 |
| 3731 ResourceId id = resource_provider->CreateResource( | 3717 ResourceId id = resource_provider->CreateResource( |
| 3732 size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, ETC1, gfx::ColorSpace()); | 3718 size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, ETC1, gfx::ColorSpace()); |
| 3733 EXPECT_NE(0u, id); | 3719 EXPECT_NE(0u, id); |
| 3734 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); | 3720 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); |
| 3735 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); | 3721 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(1); |
| 3736 resource_provider->AllocateForTesting(id); | 3722 resource_provider->AllocateForTesting(id); |
| 3737 | 3723 |
| 3738 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); | 3724 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); |
| 3739 resource_provider->DeleteResource(id); | 3725 resource_provider->DeleteResource(id); |
| 3740 } | 3726 } |
| 3741 | 3727 |
| 3742 TEST_P(ResourceProviderTest, CompressedTextureETC1Upload) { | 3728 TEST_P(ResourceProviderTest, CompressedTextureETC1Upload) { |
| 3743 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) | 3729 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) |
| 3744 return; | 3730 return; |
| 3745 | 3731 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 3758 kDelegatedSyncPointsRequired, kUseGpuMemoryBufferResources, | 3744 kDelegatedSyncPointsRequired, kUseGpuMemoryBufferResources, |
| 3759 kEnableColorCorrectRendering, | 3745 kEnableColorCorrectRendering, |
| 3760 DefaultBufferToTextureTargetMapForTesting())); | 3746 DefaultBufferToTextureTargetMapForTesting())); |
| 3761 int texture_id = 123; | 3747 int texture_id = 123; |
| 3762 uint8_t pixels[8]; | 3748 uint8_t pixels[8]; |
| 3763 | 3749 |
| 3764 ResourceId id = resource_provider->CreateResource( | 3750 ResourceId id = resource_provider->CreateResource( |
| 3765 size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, ETC1, gfx::ColorSpace()); | 3751 size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, ETC1, gfx::ColorSpace()); |
| 3766 EXPECT_NE(0u, id); | 3752 EXPECT_NE(0u, id); |
| 3767 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); | 3753 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); |
| 3768 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(3); | 3754 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); |
| 3769 EXPECT_CALL(*context, | 3755 EXPECT_CALL(*context, |
| 3770 compressedTexImage2D( | 3756 compressedTexImage2D( |
| 3771 _, 0, _, size.width(), size.height(), _, _, _)).Times(1); | 3757 _, 0, _, size.width(), size.height(), _, _, _)).Times(1); |
| 3772 resource_provider->CopyToResource(id, pixels, size); | 3758 resource_provider->CopyToResource(id, pixels, size); |
| 3773 | 3759 |
| 3774 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); | 3760 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); |
| 3775 resource_provider->DeleteResource(id); | 3761 resource_provider->DeleteResource(id); |
| 3776 } | 3762 } |
| 3777 | 3763 |
| 3778 INSTANTIATE_TEST_CASE_P( | 3764 INSTANTIATE_TEST_CASE_P( |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3867 token.Set(gpu::CommandBufferNamespace::INVALID, 0, gpu::CommandBufferId(), | 3853 token.Set(gpu::CommandBufferNamespace::INVALID, 0, gpu::CommandBufferId(), |
| 3868 release_counts[i]); | 3854 release_counts[i]); |
| 3869 lock.set_sync_token(token); | 3855 lock.set_sync_token(token); |
| 3870 } | 3856 } |
| 3871 | 3857 |
| 3872 gpu::SyncToken last_token = | 3858 gpu::SyncToken last_token = |
| 3873 resource_provider_->GetSyncTokenForResources(array); | 3859 resource_provider_->GetSyncTokenForResources(array); |
| 3874 EXPECT_EQ(last_token.release_count(), 10u); | 3860 EXPECT_EQ(last_token.release_count(), 10u); |
| 3875 } | 3861 } |
| 3876 | 3862 |
| 3863 TEST_P(ResourceProviderTest, ScopedWriteLockGL) { | |
| 3864 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) | |
| 3865 return; | |
| 3866 std::unique_ptr<AllocationTrackingContext3D> context_owned( | |
| 3867 new StrictMock<AllocationTrackingContext3D>); | |
| 3868 AllocationTrackingContext3D* context = context_owned.get(); | |
| 3869 auto context_provider = TestContextProvider::Create(std::move(context_owned)); | |
| 3870 context_provider->BindToCurrentThread(); | |
| 3871 | |
| 3872 const int kWidth = 2; | |
| 3873 const int kHeight = 2; | |
| 3874 const ResourceFormat format = RGBA_8888; | |
| 3875 const unsigned kTextureId = 123u; | |
| 3876 | |
| 3877 std::unique_ptr<ResourceProvider> resource_provider( | |
| 3878 base::MakeUnique<ResourceProvider>( | |
| 3879 context_provider.get(), shared_bitmap_manager_.get(), | |
| 3880 gpu_memory_buffer_manager_.get(), nullptr, 1, | |
| 3881 kDelegatedSyncPointsRequired, kUseGpuMemoryBufferResources, | |
| 3882 kEnableColorCorrectRendering, | |
| 3883 DefaultBufferToTextureTargetMapForTesting())); | |
| 3884 | |
| 3885 ResourceId id = resource_provider->CreateResource( | |
| 3886 gfx::Size(kWidth, kHeight), ResourceProvider::TEXTURE_HINT_IMMUTABLE, | |
| 3887 format, gfx::ColorSpace()); | |
| 3888 | |
| 3889 InSequence sequence; | |
| 3890 | |
| 3891 // First use will allocate lazily on creation of lock. | |
| 3892 { | |
| 3893 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(kTextureId)); | |
| 3894 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)).Times(2); | |
| 3895 EXPECT_CALL(*context, texImage2D(GL_TEXTURE_2D, 0, GLInternalFormat(format), | |
| 3896 kWidth, kHeight, 0, GLDataFormat(format), | |
| 3897 GLDataType(format), nullptr)); | |
| 3898 ResourceProvider::ScopedWriteLockGL lock(resource_provider.get(), id, | |
| 3899 false); | |
|
piman
2017/06/09 22:14:20
nit: you may want to add Mock::VerifyAndClearExpec
| |
| 3900 } | |
| 3901 | |
| 3902 // Subsequent uses will not allocate. | |
| 3903 { | |
| 3904 ResourceProvider::ScopedWriteLockGL lock(resource_provider.get(), id, | |
| 3905 false); | |
| 3906 } | |
| 3907 | |
| 3908 EXPECT_CALL(*context, RetireTextureId(kTextureId)); | |
| 3909 resource_provider->DeleteResource(id); | |
| 3910 } | |
| 3911 | |
| 3912 TEST_P(ResourceProviderTest, ScopedWriteLockGL_GpuMemoryBuffer) { | |
| 3913 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) | |
| 3914 return; | |
| 3915 std::unique_ptr<AllocationTrackingContext3D> context_owned( | |
| 3916 new StrictMock<AllocationTrackingContext3D>); | |
| 3917 AllocationTrackingContext3D* context = context_owned.get(); | |
| 3918 auto context_provider = TestContextProvider::Create(std::move(context_owned)); | |
| 3919 context_provider->BindToCurrentThread(); | |
| 3920 | |
| 3921 const int kWidth = 2; | |
| 3922 const int kHeight = 2; | |
| 3923 const ResourceFormat format = RGBA_8888; | |
| 3924 const unsigned kTextureId = 123u; | |
| 3925 const unsigned kImageId = 234u; | |
| 3926 | |
| 3927 std::unique_ptr<ResourceProvider> resource_provider( | |
| 3928 base::MakeUnique<ResourceProvider>( | |
| 3929 context_provider.get(), shared_bitmap_manager_.get(), | |
| 3930 gpu_memory_buffer_manager_.get(), nullptr, 1, | |
| 3931 kDelegatedSyncPointsRequired, kUseGpuMemoryBufferResources, | |
| 3932 kEnableColorCorrectRendering, | |
| 3933 DefaultBufferToTextureTargetMapForTesting())); | |
| 3934 | |
| 3935 ResourceId id = resource_provider->CreateGpuMemoryBufferResource( | |
| 3936 gfx::Size(kWidth, kHeight), ResourceProvider::TEXTURE_HINT_IMMUTABLE, | |
| 3937 format, gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, gfx::ColorSpace()); | |
| 3938 | |
| 3939 InSequence sequence; | |
| 3940 | |
| 3941 // First use will allocate lazily on creation of lock. | |
| 3942 { | |
| 3943 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(kTextureId)); | |
| 3944 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)); | |
| 3945 EXPECT_CALL(*context, createImageCHROMIUM(_, kWidth, kHeight, | |
| 3946 GLInternalFormat(format))) | |
| 3947 .WillOnce(Return(kImageId)); | |
| 3948 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)); | |
| 3949 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId)); | |
| 3950 ResourceProvider::ScopedWriteLockGL lock(resource_provider.get(), id, | |
| 3951 false); | |
| 3952 } | |
| 3953 | |
| 3954 // Subsequent uses will not allocate. | |
| 3955 { | |
| 3956 ResourceProvider::ScopedWriteLockGL lock(resource_provider.get(), id, | |
| 3957 false); | |
| 3958 } | |
| 3959 | |
| 3960 EXPECT_CALL(*context, destroyImageCHROMIUM(kImageId)); | |
| 3961 EXPECT_CALL(*context, RetireTextureId(kTextureId)); | |
| 3962 resource_provider->DeleteResource(id); | |
| 3963 } | |
| 3964 | |
| 3965 TEST_P(ResourceProviderTest, ScopedWriteLockGL_AsyncWorkerContext) { | |
| 3966 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) | |
| 3967 return; | |
| 3968 std::unique_ptr<AllocationTrackingContext3D> context_owned( | |
| 3969 new StrictMock<AllocationTrackingContext3D>); | |
| 3970 AllocationTrackingContext3D* context = context_owned.get(); | |
| 3971 auto context_provider = TestContextProvider::Create(std::move(context_owned)); | |
| 3972 context_provider->BindToCurrentThread(); | |
| 3973 | |
| 3974 const int kWidth = 2; | |
| 3975 const int kHeight = 2; | |
| 3976 const ResourceFormat format = RGBA_8888; | |
| 3977 const unsigned kTextureId = 123u; | |
| 3978 const unsigned kWorkerTextureId = 234u; | |
| 3979 | |
| 3980 std::unique_ptr<ResourceProvider> resource_provider( | |
| 3981 base::MakeUnique<ResourceProvider>( | |
| 3982 context_provider.get(), shared_bitmap_manager_.get(), | |
| 3983 gpu_memory_buffer_manager_.get(), nullptr, 1, | |
| 3984 kDelegatedSyncPointsRequired, kUseGpuMemoryBufferResources, | |
| 3985 kEnableColorCorrectRendering, | |
| 3986 DefaultBufferToTextureTargetMapForTesting())); | |
| 3987 | |
| 3988 ResourceId id = resource_provider->CreateResource( | |
| 3989 gfx::Size(kWidth, kHeight), ResourceProvider::TEXTURE_HINT_IMMUTABLE, | |
| 3990 format, gfx::ColorSpace()); | |
| 3991 | |
| 3992 gpu::SyncToken sync_token; | |
| 3993 context->genSyncToken(context->insertFenceSync(), sync_token.GetData()); | |
| 3994 | |
| 3995 InSequence sequence; | |
| 3996 | |
| 3997 // First use will create mailbox when lock is created and allocate lazily in | |
| 3998 // ConsumeTexture. | |
| 3999 { | |
| 4000 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(kTextureId)); | |
| 4001 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)); | |
| 4002 EXPECT_CALL(*context, | |
| 4003 produceTextureDirectCHROMIUM(kTextureId, GL_TEXTURE_2D, _)); | |
| 4004 ResourceProvider::ScopedWriteLockGL lock(resource_provider.get(), id, true); | |
| 4005 | |
| 4006 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, _)) | |
| 4007 .WillOnce(Return(kWorkerTextureId)); | |
| 4008 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kWorkerTextureId)); | |
| 4009 EXPECT_CALL(*context, texImage2D(GL_TEXTURE_2D, 0, GLInternalFormat(format), | |
| 4010 kWidth, kHeight, 0, GLDataFormat(format), | |
| 4011 GLDataType(format), nullptr)); | |
| 4012 EXPECT_EQ(kWorkerTextureId, | |
| 4013 lock.ConsumeTexture(context_provider->ContextGL())); | |
| 4014 | |
| 4015 EXPECT_CALL(*context, RetireTextureId(kWorkerTextureId)); | |
| 4016 context_provider->ContextGL()->DeleteTextures(1, &kWorkerTextureId); | |
| 4017 } | |
| 4018 | |
| 4019 // Subsequent uses will not create mailbox or allocate. | |
| 4020 { | |
| 4021 ResourceProvider::ScopedWriteLockGL lock(resource_provider.get(), id, true); | |
| 4022 | |
| 4023 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, _)) | |
| 4024 .WillOnce(Return(kWorkerTextureId)); | |
| 4025 EXPECT_EQ(kWorkerTextureId, | |
| 4026 lock.ConsumeTexture(context_provider->ContextGL())); | |
| 4027 | |
| 4028 lock.set_sync_token(sync_token); | |
| 4029 | |
| 4030 EXPECT_CALL(*context, RetireTextureId(kWorkerTextureId)); | |
| 4031 context_provider->ContextGL()->DeleteTextures(1, &kWorkerTextureId); | |
| 4032 } | |
| 4033 | |
| 4034 // Wait for worker context sync token before deleting texture. | |
| 4035 EXPECT_CALL(*context, waitSyncToken(MatchesSyncToken(sync_token))); | |
| 4036 EXPECT_CALL(*context, RetireTextureId(kTextureId)); | |
| 4037 resource_provider->DeleteResource(id); | |
| 4038 } | |
| 4039 | |
| 4040 TEST_P(ResourceProviderTest, | |
| 4041 ScopedWriteLockGL_GpuMemoryBuffer_AsyncWorkerContext) { | |
| 4042 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) | |
| 4043 return; | |
| 4044 std::unique_ptr<AllocationTrackingContext3D> context_owned( | |
| 4045 new StrictMock<AllocationTrackingContext3D>); | |
| 4046 AllocationTrackingContext3D* context = context_owned.get(); | |
| 4047 auto context_provider = TestContextProvider::Create(std::move(context_owned)); | |
| 4048 context_provider->BindToCurrentThread(); | |
| 4049 | |
| 4050 const int kWidth = 2; | |
| 4051 const int kHeight = 2; | |
| 4052 const ResourceFormat format = RGBA_8888; | |
| 4053 const unsigned kTextureId = 123u; | |
| 4054 const unsigned kWorkerTextureId = 234u; | |
| 4055 const unsigned kImageId = 345u; | |
| 4056 | |
| 4057 std::unique_ptr<ResourceProvider> resource_provider( | |
| 4058 base::MakeUnique<ResourceProvider>( | |
| 4059 context_provider.get(), shared_bitmap_manager_.get(), | |
| 4060 gpu_memory_buffer_manager_.get(), nullptr, 1, | |
| 4061 kDelegatedSyncPointsRequired, kUseGpuMemoryBufferResources, | |
| 4062 kEnableColorCorrectRendering, | |
| 4063 DefaultBufferToTextureTargetMapForTesting())); | |
| 4064 | |
| 4065 ResourceId id = resource_provider->CreateGpuMemoryBufferResource( | |
| 4066 gfx::Size(kWidth, kHeight), ResourceProvider::TEXTURE_HINT_IMMUTABLE, | |
| 4067 format, gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, gfx::ColorSpace()); | |
| 4068 | |
| 4069 gpu::SyncToken sync_token; | |
| 4070 context->genSyncToken(context->insertFenceSync(), sync_token.GetData()); | |
| 4071 | |
| 4072 InSequence sequence; | |
| 4073 | |
| 4074 // First use will create mailbox when lock is created and allocate lazily in | |
| 4075 // ConsumeTexture. | |
| 4076 { | |
| 4077 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(kTextureId)); | |
| 4078 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)); | |
| 4079 EXPECT_CALL(*context, | |
| 4080 produceTextureDirectCHROMIUM(kTextureId, GL_TEXTURE_2D, _)); | |
| 4081 ResourceProvider::ScopedWriteLockGL lock(resource_provider.get(), id, true); | |
| 4082 | |
| 4083 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, _)) | |
| 4084 .WillOnce(Return(kWorkerTextureId)); | |
| 4085 EXPECT_CALL(*context, createImageCHROMIUM(_, kWidth, kHeight, | |
| 4086 GLInternalFormat(format))) | |
| 4087 .WillOnce(Return(kImageId)); | |
| 4088 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kWorkerTextureId)); | |
| 4089 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId)); | |
| 4090 EXPECT_EQ(kWorkerTextureId, | |
| 4091 lock.ConsumeTexture(context_provider->ContextGL())); | |
| 4092 | |
| 4093 EXPECT_CALL(*context, RetireTextureId(kWorkerTextureId)); | |
| 4094 context_provider->ContextGL()->DeleteTextures(1, &kWorkerTextureId); | |
| 4095 } | |
| 4096 | |
| 4097 // Subsequent uses will not create mailbox or allocate. | |
| 4098 { | |
| 4099 ResourceProvider::ScopedWriteLockGL lock(resource_provider.get(), id, true); | |
| 4100 | |
| 4101 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, _)) | |
| 4102 .WillOnce(Return(kWorkerTextureId)); | |
| 4103 EXPECT_EQ(kWorkerTextureId, | |
| 4104 lock.ConsumeTexture(context_provider->ContextGL())); | |
| 4105 | |
| 4106 lock.set_sync_token(sync_token); | |
| 4107 | |
| 4108 EXPECT_CALL(*context, RetireTextureId(kWorkerTextureId)); | |
| 4109 context_provider->ContextGL()->DeleteTextures(1, &kWorkerTextureId); | |
| 4110 } | |
| 4111 | |
| 4112 // Wait for worker context sync token before deleting texture. | |
| 4113 EXPECT_CALL(*context, waitSyncToken(MatchesSyncToken(sync_token))); | |
| 4114 EXPECT_CALL(*context, destroyImageCHROMIUM(kImageId)); | |
| 4115 EXPECT_CALL(*context, RetireTextureId(kTextureId)); | |
| 4116 resource_provider->DeleteResource(id); | |
| 4117 } | |
| 4118 | |
| 3877 } // namespace | 4119 } // namespace |
| 3878 } // namespace cc | 4120 } // namespace cc |
| OLD | NEW |