OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/memory/discardable_memory.h" | 7 #include "base/memory/discardable_memory.h" |
8 #include "base/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "content/child/child_discardable_shared_memory_manager.h" | 10 #include "content/child/child_discardable_shared_memory_manager.h" |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 DISABLED_Map) { | 151 DISABLED_Map) { |
152 gfx::BufferFormat format = ::testing::get<1>(GetParam()); | 152 gfx::BufferFormat format = ::testing::get<1>(GetParam()); |
153 gfx::Size buffer_size(4, 4); | 153 gfx::Size buffer_size(4, 4); |
154 | 154 |
155 scoped_ptr<gfx::GpuMemoryBuffer> buffer = | 155 scoped_ptr<gfx::GpuMemoryBuffer> buffer = |
156 child_gpu_memory_buffer_manager()->AllocateGpuMemoryBuffer( | 156 child_gpu_memory_buffer_manager()->AllocateGpuMemoryBuffer( |
157 buffer_size, format, gfx::BufferUsage::MAP); | 157 buffer_size, format, gfx::BufferUsage::MAP); |
158 ASSERT_TRUE(buffer); | 158 ASSERT_TRUE(buffer); |
159 EXPECT_EQ(format, buffer->GetFormat()); | 159 EXPECT_EQ(format, buffer->GetFormat()); |
160 | 160 |
161 size_t num_planes = gfx::NumberOfPlanesForBufferFormat(format); | |
162 | |
163 // Map buffer planes. | 161 // Map buffer planes. |
164 scoped_ptr<void* []> planes(new void* [num_planes]); | 162 ASSERT_TRUE(buffer->Map()); |
165 bool rv = buffer->Map(planes.get()); | |
166 ASSERT_TRUE(rv); | |
167 | |
168 // Get strides. | |
169 scoped_ptr<int[]> strides(new int[num_planes]); | |
170 buffer->GetStride(strides.get()); | |
171 | 163 |
172 // Write to buffer and check result. | 164 // Write to buffer and check result. |
| 165 size_t num_planes = gfx::NumberOfPlanesForBufferFormat(format); |
173 for (size_t plane = 0; plane < num_planes; ++plane) { | 166 for (size_t plane = 0; plane < num_planes; ++plane) { |
174 size_t row_size_in_bytes = 0; | 167 ASSERT_TRUE(buffer->memory(plane)); |
175 EXPECT_TRUE(gfx::RowSizeForBufferFormatChecked(buffer_size.width(), format, | 168 ASSERT_TRUE(buffer->stride(plane)); |
176 plane, &row_size_in_bytes)); | 169 size_t row_size_in_bytes = |
| 170 gfx::RowSizeForBufferFormat(buffer_size.width(), format, plane); |
| 171 EXPECT_GT(row_size_in_bytes, 0u); |
177 | 172 |
178 scoped_ptr<char[]> data(new char[row_size_in_bytes]); | 173 scoped_ptr<char[]> data(new char[row_size_in_bytes]); |
179 memset(data.get(), 0x2a + plane, row_size_in_bytes); | 174 memset(data.get(), 0x2a + plane, row_size_in_bytes); |
180 size_t height = buffer_size.height() / | 175 size_t height = buffer_size.height() / |
181 gfx::SubsamplingFactorForBufferFormat(format, plane); | 176 gfx::SubsamplingFactorForBufferFormat(format, plane); |
182 for (size_t y = 0; y < height; ++y) { | 177 for (size_t y = 0; y < height; ++y) { |
183 // Copy |data| to row |y| of |plane| and verify result. | 178 // Copy |data| to row |y| of |plane| and verify result. |
184 memcpy(static_cast<char*>(planes[plane]) + y * strides[plane], data.get(), | 179 memcpy( |
185 row_size_in_bytes); | 180 static_cast<char*>(buffer->memory(plane)) + y * buffer->stride(plane), |
186 EXPECT_EQ(memcmp(static_cast<char*>(planes[plane]) + y * strides[plane], | 181 data.get(), row_size_in_bytes); |
187 data.get(), row_size_in_bytes), | 182 EXPECT_EQ(0, memcmp(static_cast<char*>(buffer->memory(plane)) + |
188 0); | 183 y * buffer->stride(plane), |
| 184 data.get(), row_size_in_bytes)); |
189 } | 185 } |
190 } | 186 } |
191 | 187 |
192 buffer->Unmap(); | 188 buffer->Unmap(); |
193 } | 189 } |
194 | 190 |
195 INSTANTIATE_TEST_CASE_P( | 191 INSTANTIATE_TEST_CASE_P( |
196 ChildThreadImplGpuMemoryBufferBrowserTests, | 192 ChildThreadImplGpuMemoryBufferBrowserTests, |
197 ChildThreadImplGpuMemoryBufferBrowserTest, | 193 ChildThreadImplGpuMemoryBufferBrowserTest, |
198 ::testing::Combine(::testing::Values(kDisableNativeBuffers, | 194 ::testing::Combine(::testing::Values(kDisableNativeBuffers, |
199 kEnableNativeBuffers), | 195 kEnableNativeBuffers), |
200 // These formats are guaranteed to work on all platforms. | 196 // These formats are guaranteed to work on all platforms. |
201 ::testing::Values(gfx::BufferFormat::R_8, | 197 ::testing::Values(gfx::BufferFormat::R_8, |
202 gfx::BufferFormat::RGBA_4444, | 198 gfx::BufferFormat::RGBA_4444, |
203 gfx::BufferFormat::RGBA_8888, | 199 gfx::BufferFormat::RGBA_8888, |
204 gfx::BufferFormat::BGRA_8888, | 200 gfx::BufferFormat::BGRA_8888, |
205 gfx::BufferFormat::YUV_420))); | 201 gfx::BufferFormat::YUV_420))); |
206 | 202 |
207 } // namespace | 203 } // namespace |
208 } // namespace content | 204 } // namespace content |
OLD | NEW |