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 3704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3715 ResourceFormat format = RGBA_8888; | 3715 ResourceFormat format = RGBA_8888; |
3716 size_t pixel_size = TextureSizeBytes(size, format); | 3716 size_t pixel_size = TextureSizeBytes(size, format); |
3717 ASSERT_EQ(4U, pixel_size); | 3717 ASSERT_EQ(4U, pixel_size); |
3718 | 3718 |
3719 ResourceId id = resource_provider_->CreateResource( | 3719 ResourceId id = resource_provider_->CreateResource( |
3720 size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format); | 3720 size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format); |
3721 resource_provider_->AllocateForTesting(id); | 3721 resource_provider_->AllocateForTesting(id); |
3722 { | 3722 { |
3723 ResourceProvider::ScopedReadLockGpuMemoryBuffer lock( | 3723 ResourceProvider::ScopedReadLockGpuMemoryBuffer lock( |
3724 resource_provider_.get(), id); | 3724 resource_provider_.get(), id); |
3725 EXPECT_FALSE(lock.GetGpuMemoryBuffer()); | 3725 EXPECT_FALSE(lock.gpu_memory_buffer()); |
3726 } | 3726 } |
3727 } | 3727 } |
3728 | 3728 |
3729 TEST_P(ResourceProviderTest, GpuMemoryBufferReadLockSucceed) { | 3729 TEST_P(ResourceProviderTest, GpuMemoryBufferReadLockSucceed) { |
3730 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) | 3730 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) |
3731 return; | 3731 return; |
3732 | 3732 |
3733 gfx::Size size(1, 1); | 3733 gfx::Size size(1, 1); |
3734 ResourceFormat format = RGBA_8888; | 3734 ResourceFormat format = RGBA_8888; |
3735 size_t pixel_size = TextureSizeBytes(size, format); | 3735 size_t pixel_size = TextureSizeBytes(size, format); |
3736 ASSERT_EQ(4U, pixel_size); | 3736 ASSERT_EQ(4U, pixel_size); |
3737 | 3737 |
3738 ResourceId id = resource_provider_->CreateResource( | 3738 ResourceId id = resource_provider_->CreateResource( |
3739 size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format); | 3739 size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format); |
3740 gfx::GpuMemoryBuffer* gpu_memory_buffer = nullptr; | 3740 gfx::GpuMemoryBuffer* gpu_memory_buffer = nullptr; |
3741 { | 3741 { |
3742 ResourceProvider::ScopedWriteLockGpuMemoryBuffer lock( | 3742 ResourceProvider::ScopedWriteLockGpuMemoryBuffer lock( |
3743 resource_provider_.get(), id); | 3743 resource_provider_.get(), id); |
3744 gpu_memory_buffer = lock.GetGpuMemoryBuffer(); | 3744 gpu_memory_buffer = lock.GetGpuMemoryBuffer(); |
3745 EXPECT_TRUE(lock.GetGpuMemoryBuffer()); | 3745 EXPECT_TRUE(lock.GetGpuMemoryBuffer()); |
3746 } | 3746 } |
3747 { | 3747 { |
3748 ResourceProvider::ScopedReadLockGpuMemoryBuffer lock( | 3748 ResourceProvider::ScopedReadLockGpuMemoryBuffer lock( |
3749 resource_provider_.get(), id); | 3749 resource_provider_.get(), id); |
3750 EXPECT_EQ(gpu_memory_buffer, lock.GetGpuMemoryBuffer()); | 3750 EXPECT_EQ(gpu_memory_buffer, lock.gpu_memory_buffer()); |
3751 } | 3751 } |
3752 } | 3752 } |
3753 | 3753 |
3754 TEST_P(ResourceProviderTest, ChildGpuMemoryBufferReadLock) { | 3754 TEST_P(ResourceProviderTest, ChildGpuMemoryBufferReadLock) { |
3755 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) | 3755 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) |
3756 return; | 3756 return; |
3757 | 3757 |
3758 gfx::Size size(1, 1); | 3758 gfx::Size size(1, 1); |
3759 ResourceFormat format = RGBA_8888; | 3759 ResourceFormat format = RGBA_8888; |
3760 size_t pixel_size = TextureSizeBytes(size, format); | 3760 size_t pixel_size = TextureSizeBytes(size, format); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3797 &list); | 3797 &list); |
3798 resource_provider_->ReceiveFromChild(child_id, list); | 3798 resource_provider_->ReceiveFromChild(child_id, list); |
3799 resource_provider_->WaitSyncTokenIfNeeded(list[0].id); | 3799 resource_provider_->WaitSyncTokenIfNeeded(list[0].id); |
3800 resource_provider_->WaitSyncTokenIfNeeded(list[1].id); | 3800 resource_provider_->WaitSyncTokenIfNeeded(list[1].id); |
3801 } | 3801 } |
3802 | 3802 |
3803 // The non-gmb resource should not have a GpuMemoryBuffer when locked. | 3803 // The non-gmb resource should not have a GpuMemoryBuffer when locked. |
3804 { | 3804 { |
3805 ResourceProvider::ScopedReadLockGpuMemoryBuffer lock( | 3805 ResourceProvider::ScopedReadLockGpuMemoryBuffer lock( |
3806 resource_provider_.get(), list[0].id); | 3806 resource_provider_.get(), list[0].id); |
3807 EXPECT_FALSE(lock.GetGpuMemoryBuffer()); | 3807 EXPECT_FALSE(lock.gpu_memory_buffer()); |
3808 } | 3808 } |
3809 | 3809 |
3810 // The gmb resource should have a GpuMemoryBuffer when locked | 3810 // The gmb resource should have a GpuMemoryBuffer when locked |
3811 { | 3811 { |
3812 ResourceProvider::ScopedReadLockGpuMemoryBuffer lock( | 3812 ResourceProvider::ScopedReadLockGpuMemoryBuffer lock( |
3813 resource_provider_.get(), list[1].id); | 3813 resource_provider_.get(), list[1].id); |
3814 gfx::GpuMemoryBuffer* parent_gmb = lock.GetGpuMemoryBuffer(); | 3814 gfx::GpuMemoryBuffer* parent_gmb = lock.gpu_memory_buffer(); |
3815 EXPECT_TRUE(parent_gmb); | 3815 EXPECT_TRUE(parent_gmb); |
3816 EXPECT_NE(child_gmb, parent_gmb); | 3816 EXPECT_NE(child_gmb, parent_gmb); |
3817 | 3817 |
3818 // Verify that the IsInUseByMacOSWindowServer signal is shared between | 3818 // Verify that the IsInUseByMacOSWindowServer signal is shared between |
3819 // parent and child. | 3819 // parent and child. |
3820 EXPECT_FALSE(parent_gmb->IsInUseByMacOSWindowServer()); | 3820 EXPECT_FALSE(parent_gmb->IsInUseByMacOSWindowServer()); |
3821 child_gpu_memory_buffer_manager_ | 3821 child_gpu_memory_buffer_manager_ |
3822 ->SetGpuMemoryBufferIsInUseByMacOSWindowServer(child_gmb, true); | 3822 ->SetGpuMemoryBufferIsInUseByMacOSWindowServer(child_gmb, true); |
3823 EXPECT_TRUE(parent_gmb->IsInUseByMacOSWindowServer()); | 3823 EXPECT_TRUE(parent_gmb->IsInUseByMacOSWindowServer()); |
3824 child_gpu_memory_buffer_manager_ | 3824 child_gpu_memory_buffer_manager_ |
3825 ->SetGpuMemoryBufferIsInUseByMacOSWindowServer(child_gmb, false); | 3825 ->SetGpuMemoryBufferIsInUseByMacOSWindowServer(child_gmb, false); |
3826 EXPECT_FALSE(parent_gmb->IsInUseByMacOSWindowServer()); | 3826 EXPECT_FALSE(parent_gmb->IsInUseByMacOSWindowServer()); |
3827 } | 3827 } |
3828 | 3828 |
3829 // Transfer back to the child.{ | 3829 // Transfer back to the child.{ |
3830 { | 3830 { |
3831 ResourceProvider::ResourceIdSet resource_ids_to_receive; | 3831 ResourceProvider::ResourceIdSet resource_ids_to_receive; |
3832 resource_ids_to_receive.insert(child_resource); | 3832 resource_ids_to_receive.insert(child_resource); |
3833 resource_ids_to_receive.insert(child_gmb_resource); | 3833 resource_ids_to_receive.insert(child_gmb_resource); |
3834 resource_provider_->DeclareUsedResourcesFromChild(child_id, | 3834 resource_provider_->DeclareUsedResourcesFromChild(child_id, |
3835 resource_ids_to_receive); | 3835 resource_ids_to_receive); |
3836 } | 3836 } |
3837 resource_provider_->DestroyChild(child_id); | 3837 resource_provider_->DestroyChild(child_id); |
3838 | 3838 |
3839 EXPECT_EQ(0u, resource_provider_->num_resources()); | 3839 EXPECT_EQ(0u, resource_provider_->num_resources()); |
3840 } | 3840 } |
3841 | 3841 |
3842 } // namespace | 3842 } // namespace |
3843 } // namespace cc | 3843 } // namespace cc |
OLD | NEW |