Chromium Code Reviews| Index: content/common/gpu/client/gpu_memory_buffer_impl_unittest.cc |
| diff --git a/content/common/gpu/client/gpu_memory_buffer_impl_unittest.cc b/content/common/gpu/client/gpu_memory_buffer_impl_unittest.cc |
| index 94046f1cf15cbc09d4e95e51149342423fdb161b..072aa8cdb8481ada766b3ad0cfb22f2be781b941 100644 |
| --- a/content/common/gpu/client/gpu_memory_buffer_impl_unittest.cc |
| +++ b/content/common/gpu/client/gpu_memory_buffer_impl_unittest.cc |
| @@ -138,9 +138,114 @@ TEST_P(GpuMemoryBufferImplTest, Map) { |
| } |
| } |
| +TEST_P(GpuMemoryBufferImplTest, PersistentMap) { |
| + const int kBufferId = 1; |
| + |
| + gfx::Size buffer_size(2, 2); |
|
reveman
2015/05/19 16:12:12
Fyi, nothing new with this patch so I don't mind i
danakj
2015/05/19 22:19:43
Do you want me to change both tests to 4? I'll do
|
| + |
| + for (auto configuration : supported_configurations_) { |
| + if (configuration.usage != gfx::GpuMemoryBuffer::PERSISTENT_MAP) |
| + continue; |
| + |
| + scoped_ptr<GpuMemoryBufferImpl> buffer( |
| + GpuMemoryBufferImpl::CreateFromHandle( |
| + CreateGpuMemoryBuffer(kBufferId, buffer_size, configuration.format, |
| + configuration.usage), |
| + buffer_size, configuration.format, |
| + base::Bind(&GpuMemoryBufferImplTest::DestroyGpuMemoryBuffer, |
| + base::Unretained(this), kBufferId))); |
| + ASSERT_TRUE(buffer); |
| + EXPECT_FALSE(buffer->IsMapped()); |
| + |
| + size_t num_planes = |
| + GpuMemoryBufferImpl::NumberOfPlanesForGpuMemoryBufferFormat( |
| + configuration.format); |
| + |
| + // Map buffer into user space. |
| + scoped_ptr<void* []> mapped_buffers(new void* [num_planes]); |
| + bool rv = buffer->Map(mapped_buffers.get()); |
| + ASSERT_TRUE(rv); |
| + EXPECT_TRUE(buffer->IsMapped()); |
| + |
| + // Get strides. |
| + scoped_ptr<int[]> strides(new int[num_planes]); |
| + buffer->GetStride(strides.get()); |
| + |
| + scoped_ptr<size_t[]> row_sizes_in_bytes(new size_t[num_planes]); |
| + for (size_t plane = 0; plane < num_planes; ++plane) { |
| + EXPECT_TRUE(GpuMemoryBufferImpl::RowSizeInBytes( |
| + buffer_size.width(), configuration.format, plane, |
| + &row_sizes_in_bytes[plane])); |
| + EXPECT_GT(row_sizes_in_bytes[plane], 0u); |
| + } |
| + |
| + // Copy and compare mapped buffers. |
| + for (size_t plane = 0; plane < num_planes; ++plane) { |
| + size_t row_size_in_bytes = row_sizes_in_bytes[plane]; |
| + |
| + scoped_ptr<char[]> data(new char[row_size_in_bytes]); |
| + memset(data.get(), 0x2a + plane, row_size_in_bytes); |
| + |
| + size_t height = |
| + buffer_size.height() / |
| + GpuMemoryBufferImpl::SubsamplingFactor(configuration.format, plane); |
| + for (size_t y = 0; y < height; ++y) { |
| + memcpy(static_cast<char*>(mapped_buffers[plane]) + y * strides[plane], |
| + data.get(), row_size_in_bytes); |
| + EXPECT_EQ(memcmp(static_cast<char*>(mapped_buffers[plane]) + |
| + y * strides[plane], |
| + data.get(), row_size_in_bytes), |
| + 0); |
| + } |
| + } |
| + |
| + buffer->Unmap(); |
| + EXPECT_FALSE(buffer->IsMapped()); |
| + |
| + // Remap the buffer, and compare again. It should contain the same data. |
| + rv = buffer->Map(mapped_buffers.get()); |
| + ASSERT_TRUE(rv); |
| + EXPECT_TRUE(buffer->IsMapped()); |
| + |
| + scoped_ptr<int[]> remap_strides(new int[num_planes]); |
| + buffer->GetStride(remap_strides.get()); |
| + |
| + for (size_t plane = 0; plane < num_planes; ++plane) { |
| + EXPECT_EQ(strides[plane], remap_strides[plane]); |
|
reveman
2015/05/19 16:12:12
I don't think we should expect this to be true. An
danakj
2015/05/19 22:19:44
OK, done.
|
| + size_t row_size_in_bytes = 0; |
| + EXPECT_TRUE(GpuMemoryBufferImpl::RowSizeInBytes( |
| + buffer_size.width(), configuration.format, plane, |
| + &row_size_in_bytes)); |
| + EXPECT_EQ(row_sizes_in_bytes[plane], row_size_in_bytes); |
|
reveman
2015/05/19 16:12:12
Why are you checking this? row_size_in_bytes can't
danakj
2015/05/19 22:19:43
I see, right. Removed.
|
| + |
| + scoped_ptr<char[]> data(new char[row_size_in_bytes]); |
| + memset(data.get(), 0x2a + plane, row_size_in_bytes); |
| + |
| + size_t height = |
| + buffer_size.height() / |
| + GpuMemoryBufferImpl::SubsamplingFactor(configuration.format, plane); |
| + for (size_t y = 0; y < height; ++y) { |
| + EXPECT_EQ(memcmp(static_cast<char*>(mapped_buffers[plane]) + |
| + y * strides[plane], |
| + data.get(), row_size_in_bytes), |
| + 0); |
| + } |
| + } |
| + } |
| +} |
| + |
| std::vector<gfx::GpuMemoryBufferType> GetSupportedGpuMemoryBufferTypes() { |
| std::vector<gfx::GpuMemoryBufferType> supported_types; |
| - GpuMemoryBufferFactory::GetSupportedTypes(&supported_types); |
| + GpuMemoryBufferFactory::GetSupportedTypes(gfx::GpuMemoryBuffer::MAP, |
| + &supported_types); |
| + |
| + std::vector<gfx::GpuMemoryBufferType> persistent_supported_types; |
| + GpuMemoryBufferFactory::GetSupportedTypes( |
| + gfx::GpuMemoryBuffer::PERSISTENT_MAP, &persistent_supported_types); |
| + supported_types.insert(supported_types.end(), |
| + persistent_supported_types.begin(), |
| + persistent_supported_types.end()); |
| + |
| return supported_types; |
| } |