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

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: fixmandolinebetter 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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 scoped_ptr<size_t[]> row_sizes_in_bytes(new size_t[num_planes]);
177 for (size_t plane = 0; plane < num_planes; ++plane) {
178 EXPECT_TRUE(GpuMemoryBufferImpl::RowSizeInBytes(
179 buffer_size.width(), configuration.format, plane,
180 &row_sizes_in_bytes[plane]));
181 EXPECT_GT(row_sizes_in_bytes[plane], 0u);
182 }
reveman 2015/05/20 14:26:08 nit: please remove this loop and move the code int
danakj 2015/05/20 17:51:14 Done.
183
184 // Copy and compare mapped buffers.
185 for (size_t plane = 0; plane < num_planes; ++plane) {
186 size_t row_size_in_bytes = row_sizes_in_bytes[plane];
187 scoped_ptr<char[]> data(new char[row_size_in_bytes]);
188 memset(data.get(), 0x2a + plane, row_size_in_bytes);
189
190 size_t height =
191 buffer_size.height() /
192 GpuMemoryBufferImpl::SubsamplingFactor(configuration.format, plane);
193 for (size_t y = 0; y < height; ++y) {
194 memcpy(static_cast<char*>(mapped_buffers[plane]) + y * strides[plane],
195 data.get(), row_size_in_bytes);
196 EXPECT_EQ(memcmp(static_cast<char*>(mapped_buffers[plane]) +
197 y * strides[plane],
198 data.get(), row_size_in_bytes),
199 0);
200 }
201 }
202
203 buffer->Unmap();
204 EXPECT_FALSE(buffer->IsMapped());
205
206 // Remap the buffer, and compare again. It should contain the same data.
207 rv = buffer->Map(mapped_buffers.get());
208 ASSERT_TRUE(rv);
209 EXPECT_TRUE(buffer->IsMapped());
210
211 buffer->GetStride(strides.get());
212
213 for (size_t plane = 0; plane < num_planes; ++plane) {
214 size_t row_size_in_bytes = row_sizes_in_bytes[plane];
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 }
230
141 std::vector<gfx::GpuMemoryBufferType> GetSupportedGpuMemoryBufferTypes() { 231 std::vector<gfx::GpuMemoryBufferType> GetSupportedGpuMemoryBufferTypes() {
142 std::vector<gfx::GpuMemoryBufferType> supported_types; 232 std::vector<gfx::GpuMemoryBufferType> supported_types;
143 GpuMemoryBufferFactory::GetSupportedTypes(&supported_types); 233 GpuMemoryBufferFactory::GetSupportedTypes(&supported_types);
144 return supported_types; 234 return supported_types;
145 } 235 }
146 236
147 INSTANTIATE_TEST_CASE_P( 237 INSTANTIATE_TEST_CASE_P(
148 GpuMemoryBufferImplTests, 238 GpuMemoryBufferImplTests,
149 GpuMemoryBufferImplTest, 239 GpuMemoryBufferImplTest,
150 ::testing::ValuesIn(GetSupportedGpuMemoryBufferTypes())); 240 ::testing::ValuesIn(GetSupportedGpuMemoryBufferTypes()));
151 241
152 } // namespace 242 } // namespace
153 } // namespace content 243 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698