Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Side by Side Diff: content/common/gpu/client/gpu_memory_buffer_impl_unittest.cc

Issue 1139903005: Add PERSISTENT_MAP usage for GpuMemoryBuffers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: persistentmap: . Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 data.get(), row_size_in_bytes), 131 data.get(), row_size_in_bytes),
132 0); 132 0);
133 } 133 }
134 } 134 }
135 135
136 buffer->Unmap(); 136 buffer->Unmap();
137 EXPECT_FALSE(buffer->IsMapped()); 137 EXPECT_FALSE(buffer->IsMapped());
138 } 138 }
139 } 139 }
140 140
141 TEST_P(GpuMemoryBufferImplTest, PersistentMap) {
142 const int kBufferId = 1;
143
144 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
145
146 for (auto configuration : supported_configurations_) {
147 if (configuration.usage != gfx::GpuMemoryBuffer::PERSISTENT_MAP)
148 continue;
149
150 scoped_ptr<GpuMemoryBufferImpl> buffer(
151 GpuMemoryBufferImpl::CreateFromHandle(
152 CreateGpuMemoryBuffer(kBufferId, buffer_size, configuration.format,
153 configuration.usage),
154 buffer_size, configuration.format,
155 base::Bind(&GpuMemoryBufferImplTest::DestroyGpuMemoryBuffer,
156 base::Unretained(this), kBufferId)));
157 ASSERT_TRUE(buffer);
158 EXPECT_FALSE(buffer->IsMapped());
159
160 size_t num_planes =
161 GpuMemoryBufferImpl::NumberOfPlanesForGpuMemoryBufferFormat(
162 configuration.format);
163
164 // Map buffer into user space.
165 scoped_ptr<void* []> mapped_buffers(new void* [num_planes]);
166 bool rv = buffer->Map(mapped_buffers.get());
167 ASSERT_TRUE(rv);
168 EXPECT_TRUE(buffer->IsMapped());
169
170 // Get strides.
171 scoped_ptr<int[]> strides(new int[num_planes]);
172 buffer->GetStride(strides.get());
173
174 scoped_ptr<size_t[]> row_sizes_in_bytes(new size_t[num_planes]);
175 for (size_t plane = 0; plane < num_planes; ++plane) {
176 EXPECT_TRUE(GpuMemoryBufferImpl::RowSizeInBytes(
177 buffer_size.width(), configuration.format, plane,
178 &row_sizes_in_bytes[plane]));
179 EXPECT_GT(row_sizes_in_bytes[plane], 0u);
180 }
181
182 // Copy and compare mapped buffers.
183 for (size_t plane = 0; plane < num_planes; ++plane) {
184 size_t row_size_in_bytes = row_sizes_in_bytes[plane];
185
186 scoped_ptr<char[]> data(new char[row_size_in_bytes]);
187 memset(data.get(), 0x2a + plane, row_size_in_bytes);
188
189 size_t height =
190 buffer_size.height() /
191 GpuMemoryBufferImpl::SubsamplingFactor(configuration.format, plane);
192 for (size_t y = 0; y < height; ++y) {
193 memcpy(static_cast<char*>(mapped_buffers[plane]) + y * strides[plane],
194 data.get(), row_size_in_bytes);
195 EXPECT_EQ(memcmp(static_cast<char*>(mapped_buffers[plane]) +
196 y * strides[plane],
197 data.get(), row_size_in_bytes),
198 0);
199 }
200 }
201
202 buffer->Unmap();
203 EXPECT_FALSE(buffer->IsMapped());
204
205 // Remap the buffer, and compare again. It should contain the same data.
206 rv = buffer->Map(mapped_buffers.get());
207 ASSERT_TRUE(rv);
208 EXPECT_TRUE(buffer->IsMapped());
209
210 scoped_ptr<int[]> remap_strides(new int[num_planes]);
211 buffer->GetStride(remap_strides.get());
212
213 for (size_t plane = 0; plane < num_planes; ++plane) {
214 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.
215 size_t row_size_in_bytes = 0;
216 EXPECT_TRUE(GpuMemoryBufferImpl::RowSizeInBytes(
217 buffer_size.width(), configuration.format, plane,
218 &row_size_in_bytes));
219 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.
220
221 scoped_ptr<char[]> data(new char[row_size_in_bytes]);
222 memset(data.get(), 0x2a + plane, row_size_in_bytes);
223
224 size_t height =
225 buffer_size.height() /
226 GpuMemoryBufferImpl::SubsamplingFactor(configuration.format, plane);
227 for (size_t y = 0; y < height; ++y) {
228 EXPECT_EQ(memcmp(static_cast<char*>(mapped_buffers[plane]) +
229 y * strides[plane],
230 data.get(), row_size_in_bytes),
231 0);
232 }
233 }
234 }
235 }
236
141 std::vector<gfx::GpuMemoryBufferType> GetSupportedGpuMemoryBufferTypes() { 237 std::vector<gfx::GpuMemoryBufferType> GetSupportedGpuMemoryBufferTypes() {
142 std::vector<gfx::GpuMemoryBufferType> supported_types; 238 std::vector<gfx::GpuMemoryBufferType> supported_types;
143 GpuMemoryBufferFactory::GetSupportedTypes(&supported_types); 239 GpuMemoryBufferFactory::GetSupportedTypes(gfx::GpuMemoryBuffer::MAP,
240 &supported_types);
241
242 std::vector<gfx::GpuMemoryBufferType> persistent_supported_types;
243 GpuMemoryBufferFactory::GetSupportedTypes(
244 gfx::GpuMemoryBuffer::PERSISTENT_MAP, &persistent_supported_types);
245 supported_types.insert(supported_types.end(),
246 persistent_supported_types.begin(),
247 persistent_supported_types.end());
248
144 return supported_types; 249 return supported_types;
145 } 250 }
146 251
147 INSTANTIATE_TEST_CASE_P( 252 INSTANTIATE_TEST_CASE_P(
148 GpuMemoryBufferImplTests, 253 GpuMemoryBufferImplTests,
149 GpuMemoryBufferImplTest, 254 GpuMemoryBufferImplTest,
150 ::testing::ValuesIn(GetSupportedGpuMemoryBufferTypes())); 255 ::testing::ValuesIn(GetSupportedGpuMemoryBufferTypes()));
151 256
152 } // namespace 257 } // namespace
153 } // namespace content 258 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698