| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/common/gpu/client/gpu_memory_buffer_impl.h" | 5 #include "content/common/gpu/client/gpu_memory_buffer_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "content/common/gpu/gpu_memory_buffer_factory.h" | 8 #include "content/common/gpu/gpu_memory_buffer_factory.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 | 72 |
| 73 // Check if destruction callback is executed when deleting the buffer. | 73 // Check if destruction callback is executed when deleting the buffer. |
| 74 buffer.reset(); | 74 buffer.reset(); |
| 75 EXPECT_EQ(0, buffer_count_); | 75 EXPECT_EQ(0, buffer_count_); |
| 76 } | 76 } |
| 77 } | 77 } |
| 78 | 78 |
| 79 TEST_P(GpuMemoryBufferImplTest, Map) { | 79 TEST_P(GpuMemoryBufferImplTest, Map) { |
| 80 const int kBufferId = 1; | 80 const int kBufferId = 1; |
| 81 | 81 |
| 82 gfx::Size buffer_size(2, 2); | 82 // Use a multiple of 4 for both dimensions to support compressed formats. |
| 83 gfx::Size buffer_size(4, 4); |
| 83 | 84 |
| 84 for (auto configuration : supported_configurations_) { | 85 for (auto configuration : supported_configurations_) { |
| 85 if (configuration.usage != gfx::GpuMemoryBuffer::MAP) | 86 if (configuration.usage != gfx::GpuMemoryBuffer::MAP) |
| 86 continue; | 87 continue; |
| 87 | 88 |
| 88 scoped_ptr<GpuMemoryBufferImpl> buffer( | 89 scoped_ptr<GpuMemoryBufferImpl> buffer( |
| 89 GpuMemoryBufferImpl::CreateFromHandle( | 90 GpuMemoryBufferImpl::CreateFromHandle( |
| 90 CreateGpuMemoryBuffer(kBufferId, buffer_size, configuration.format, | 91 CreateGpuMemoryBuffer(kBufferId, buffer_size, configuration.format, |
| 91 configuration.usage), | 92 configuration.usage), |
| 92 buffer_size, configuration.format, | 93 buffer_size, configuration.format, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 data.get(), row_size_in_bytes), | 132 data.get(), row_size_in_bytes), |
| 132 0); | 133 0); |
| 133 } | 134 } |
| 134 } | 135 } |
| 135 | 136 |
| 136 buffer->Unmap(); | 137 buffer->Unmap(); |
| 137 EXPECT_FALSE(buffer->IsMapped()); | 138 EXPECT_FALSE(buffer->IsMapped()); |
| 138 } | 139 } |
| 139 } | 140 } |
| 140 | 141 |
| 142 TEST_P(GpuMemoryBufferImplTest, PersistentMap) { |
| 143 const int kBufferId = 1; |
| 144 |
| 145 // Use a multiple of 4 for both dimensions to support compressed formats. |
| 146 gfx::Size buffer_size(4, 4); |
| 147 |
| 148 for (auto configuration : supported_configurations_) { |
| 149 if (configuration.usage != gfx::GpuMemoryBuffer::PERSISTENT_MAP) |
| 150 continue; |
| 151 |
| 152 scoped_ptr<GpuMemoryBufferImpl> buffer( |
| 153 GpuMemoryBufferImpl::CreateFromHandle( |
| 154 CreateGpuMemoryBuffer(kBufferId, buffer_size, configuration.format, |
| 155 configuration.usage), |
| 156 buffer_size, configuration.format, |
| 157 base::Bind(&GpuMemoryBufferImplTest::DestroyGpuMemoryBuffer, |
| 158 base::Unretained(this), kBufferId))); |
| 159 ASSERT_TRUE(buffer); |
| 160 EXPECT_FALSE(buffer->IsMapped()); |
| 161 |
| 162 size_t num_planes = |
| 163 GpuMemoryBufferImpl::NumberOfPlanesForGpuMemoryBufferFormat( |
| 164 configuration.format); |
| 165 |
| 166 // Map buffer into user space. |
| 167 scoped_ptr<void* []> mapped_buffers(new void* [num_planes]); |
| 168 bool rv = buffer->Map(mapped_buffers.get()); |
| 169 ASSERT_TRUE(rv); |
| 170 EXPECT_TRUE(buffer->IsMapped()); |
| 171 |
| 172 // Get strides. |
| 173 scoped_ptr<int[]> strides(new int[num_planes]); |
| 174 buffer->GetStride(strides.get()); |
| 175 |
| 176 // Copy and compare mapped buffers. |
| 177 for (size_t plane = 0; plane < num_planes; ++plane) { |
| 178 size_t row_size_in_bytes; |
| 179 EXPECT_TRUE(GpuMemoryBufferImpl::RowSizeInBytes( |
| 180 buffer_size.width(), configuration.format, plane, |
| 181 &row_size_in_bytes)); |
| 182 |
| 183 scoped_ptr<char[]> data(new char[row_size_in_bytes]); |
| 184 memset(data.get(), 0x2a + plane, row_size_in_bytes); |
| 185 |
| 186 size_t height = |
| 187 buffer_size.height() / |
| 188 GpuMemoryBufferImpl::SubsamplingFactor(configuration.format, plane); |
| 189 for (size_t y = 0; y < height; ++y) { |
| 190 memcpy(static_cast<char*>(mapped_buffers[plane]) + y * strides[plane], |
| 191 data.get(), row_size_in_bytes); |
| 192 EXPECT_EQ(memcmp(static_cast<char*>(mapped_buffers[plane]) + |
| 193 y * strides[plane], |
| 194 data.get(), row_size_in_bytes), |
| 195 0); |
| 196 } |
| 197 } |
| 198 |
| 199 buffer->Unmap(); |
| 200 EXPECT_FALSE(buffer->IsMapped()); |
| 201 |
| 202 // Remap the buffer, and compare again. It should contain the same data. |
| 203 rv = buffer->Map(mapped_buffers.get()); |
| 204 ASSERT_TRUE(rv); |
| 205 EXPECT_TRUE(buffer->IsMapped()); |
| 206 |
| 207 buffer->GetStride(strides.get()); |
| 208 |
| 209 for (size_t plane = 0; plane < num_planes; ++plane) { |
| 210 size_t row_size_in_bytes; |
| 211 EXPECT_TRUE(GpuMemoryBufferImpl::RowSizeInBytes( |
| 212 buffer_size.width(), configuration.format, plane, |
| 213 &row_size_in_bytes)); |
| 214 |
| 215 scoped_ptr<char[]> data(new char[row_size_in_bytes]); |
| 216 memset(data.get(), 0x2a + plane, row_size_in_bytes); |
| 217 |
| 218 size_t height = |
| 219 buffer_size.height() / |
| 220 GpuMemoryBufferImpl::SubsamplingFactor(configuration.format, plane); |
| 221 for (size_t y = 0; y < height; ++y) { |
| 222 EXPECT_EQ(memcmp(static_cast<char*>(mapped_buffers[plane]) + |
| 223 y * strides[plane], |
| 224 data.get(), row_size_in_bytes), |
| 225 0); |
| 226 } |
| 227 } |
| 228 |
| 229 buffer->Unmap(); |
| 230 EXPECT_FALSE(buffer->IsMapped()); |
| 231 } |
| 232 } |
| 233 |
| 141 std::vector<gfx::GpuMemoryBufferType> GetSupportedGpuMemoryBufferTypes() { | 234 std::vector<gfx::GpuMemoryBufferType> GetSupportedGpuMemoryBufferTypes() { |
| 142 std::vector<gfx::GpuMemoryBufferType> supported_types; | 235 std::vector<gfx::GpuMemoryBufferType> supported_types; |
| 143 GpuMemoryBufferFactory::GetSupportedTypes(&supported_types); | 236 GpuMemoryBufferFactory::GetSupportedTypes(&supported_types); |
| 144 return supported_types; | 237 return supported_types; |
| 145 } | 238 } |
| 146 | 239 |
| 147 INSTANTIATE_TEST_CASE_P( | 240 INSTANTIATE_TEST_CASE_P( |
| 148 GpuMemoryBufferImplTests, | 241 GpuMemoryBufferImplTests, |
| 149 GpuMemoryBufferImplTest, | 242 GpuMemoryBufferImplTest, |
| 150 ::testing::ValuesIn(GetSupportedGpuMemoryBufferTypes())); | 243 ::testing::ValuesIn(GetSupportedGpuMemoryBufferTypes())); |
| 151 | 244 |
| 152 } // namespace | 245 } // namespace |
| 153 } // namespace content | 246 } // namespace content |
| OLD | NEW |