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

Side by Side Diff: content/test/gpu_memory_buffer_impl_test_template.h

Issue 1412223009: Reland: GpuMemoryBuffer interface change: Map(**) to Map() and memory(plane); stride(plane) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Win X64 compile fix Created 5 years, 1 month 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 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 // This file defines tests that implementations of GpuMemoryBufferFactory should 5 // This file defines tests that implementations of GpuMemoryBufferFactory should
6 // pass in order to be conformant. 6 // pass in order to be conformant.
7 7
8 #ifndef CONTENT_TEST_GPU_MEMORY_BUFFER_IMPL_TEST_TEMPLATE_H_ 8 #ifndef CONTENT_TEST_GPU_MEMORY_BUFFER_IMPL_TEST_TEMPLATE_H_
9 #define CONTENT_TEST_GPU_MEMORY_BUFFER_IMPL_TEST_TEMPLATE_H_ 9 #define CONTENT_TEST_GPU_MEMORY_BUFFER_IMPL_TEST_TEMPLATE_H_
10 10
(...skipping 24 matching lines...) Expand all
35 uint32 sync_point) { 35 uint32 sync_point) {
36 free_callback.Run(); 36 free_callback.Run();
37 if (destroyed) 37 if (destroyed)
38 *destroyed = true; 38 *destroyed = true;
39 } 39 }
40 }; 40 };
41 41
42 TYPED_TEST_CASE_P(GpuMemoryBufferImplTest); 42 TYPED_TEST_CASE_P(GpuMemoryBufferImplTest);
43 43
44 TYPED_TEST_P(GpuMemoryBufferImplTest, CreateFromHandle) { 44 TYPED_TEST_P(GpuMemoryBufferImplTest, CreateFromHandle) {
45 gfx::Size buffer_size(8, 8); 45 const gfx::Size kBufferSize(8, 8);
46 46
47 for (auto format : gfx::GetBufferFormats()) { 47 for (auto format : gfx::GetBufferFormatsForTesting()) {
48 gfx::BufferUsage usages[] = {gfx::BufferUsage::MAP, 48 gfx::BufferUsage usages[] = {gfx::BufferUsage::MAP,
49 gfx::BufferUsage::PERSISTENT_MAP, 49 gfx::BufferUsage::PERSISTENT_MAP,
50 gfx::BufferUsage::SCANOUT}; 50 gfx::BufferUsage::SCANOUT};
51 for (auto usage : usages) { 51 for (auto usage : usages) {
52 if (!TypeParam::IsConfigurationSupported(format, usage)) 52 if (!TypeParam::IsConfigurationSupported(format, usage))
53 continue; 53 continue;
54 54
55 bool destroyed = false; 55 bool destroyed = false;
56 gfx::GpuMemoryBufferHandle handle; 56 gfx::GpuMemoryBufferHandle handle;
57 GpuMemoryBufferImpl::DestructionCallback destroy_callback = 57 GpuMemoryBufferImpl::DestructionCallback destroy_callback =
58 TestFixture::AllocateGpuMemoryBuffer( 58 TestFixture::AllocateGpuMemoryBuffer(
59 buffer_size, format, gfx::BufferUsage::MAP, &handle, &destroyed); 59 kBufferSize, format, gfx::BufferUsage::MAP, &handle, &destroyed);
60 scoped_ptr<TypeParam> buffer(TypeParam::CreateFromHandle( 60 scoped_ptr<TypeParam> buffer(TypeParam::CreateFromHandle(
61 handle, buffer_size, format, usage, destroy_callback)); 61 handle, kBufferSize, format, usage, destroy_callback));
62 ASSERT_TRUE(buffer); 62 ASSERT_TRUE(buffer);
63 EXPECT_EQ(buffer->GetFormat(), format); 63 EXPECT_EQ(buffer->GetFormat(), format);
64 64
65 // Check if destruction callback is executed when deleting the buffer. 65 // Check if destruction callback is executed when deleting the buffer.
66 buffer.reset(); 66 buffer.reset();
67 ASSERT_TRUE(destroyed); 67 ASSERT_TRUE(destroyed);
68 } 68 }
69 } 69 }
70 } 70 }
71 71
72 TYPED_TEST_P(GpuMemoryBufferImplTest, Map) { 72 TYPED_TEST_P(GpuMemoryBufferImplTest, Map) {
73 // Use a multiple of 4 for both dimensions to support compressed formats. 73 // Use a multiple of 4 for both dimensions to support compressed formats.
74 gfx::Size buffer_size(4, 4); 74 const gfx::Size kBufferSize(4, 4);
75 75
76 for (auto format : gfx::GetBufferFormats()) { 76 for (auto format : gfx::GetBufferFormatsForTesting()) {
77 if (!TypeParam::IsConfigurationSupported(format, gfx::BufferUsage::MAP)) 77 if (!TypeParam::IsConfigurationSupported(format, gfx::BufferUsage::MAP))
78 continue; 78 continue;
79 79
80 gfx::GpuMemoryBufferHandle handle; 80 gfx::GpuMemoryBufferHandle handle;
81 GpuMemoryBufferImpl::DestructionCallback destroy_callback = 81 GpuMemoryBufferImpl::DestructionCallback destroy_callback =
82 TestFixture::AllocateGpuMemoryBuffer( 82 TestFixture::AllocateGpuMemoryBuffer(
83 buffer_size, format, gfx::BufferUsage::MAP, &handle, nullptr); 83 kBufferSize, format, gfx::BufferUsage::MAP, &handle, nullptr);
84 scoped_ptr<TypeParam> buffer(TypeParam::CreateFromHandle( 84 scoped_ptr<TypeParam> buffer(TypeParam::CreateFromHandle(
85 handle, buffer_size, format, gfx::BufferUsage::MAP, destroy_callback)); 85 handle, kBufferSize, format, gfx::BufferUsage::MAP, destroy_callback));
86 ASSERT_TRUE(buffer); 86 ASSERT_TRUE(buffer);
87 87
88 size_t num_planes = gfx::NumberOfPlanesForBufferFormat(format); 88 const size_t num_planes = gfx::NumberOfPlanesForBufferFormat(format);
89 89
90 // Map buffer into user space. 90 // Map buffer into user space.
91 scoped_ptr<void* []> mapped_buffers(new void*[num_planes]); 91 ASSERT_TRUE(buffer->Map());
92 bool rv = buffer->Map(mapped_buffers.get());
93 ASSERT_TRUE(rv);
94
95 // Get strides.
96 scoped_ptr<int[]> strides(new int[num_planes]);
97 buffer->GetStride(strides.get());
98 92
99 // Copy and compare mapped buffers. 93 // Copy and compare mapped buffers.
100 for (size_t plane = 0; plane < num_planes; ++plane) { 94 for (size_t plane = 0; plane < num_planes; ++plane) {
101 size_t row_size_in_bytes = 0; 95 const size_t row_size_in_bytes =
102 EXPECT_TRUE(gfx::RowSizeForBufferFormatChecked( 96 gfx::RowSizeForBufferFormat(kBufferSize.width(), format, plane);
103 buffer_size.width(), format, plane, &row_size_in_bytes));
104 EXPECT_GT(row_size_in_bytes, 0u); 97 EXPECT_GT(row_size_in_bytes, 0u);
105 98
106 scoped_ptr<char[]> data(new char[row_size_in_bytes]); 99 scoped_ptr<char[]> data(new char[row_size_in_bytes]);
107 memset(data.get(), 0x2a + plane, row_size_in_bytes); 100 memset(data.get(), 0x2a + plane, row_size_in_bytes);
108 101
109 size_t height = buffer_size.height() / 102 size_t height = kBufferSize.height() /
110 gfx::SubsamplingFactorForBufferFormat(format, plane); 103 gfx::SubsamplingFactorForBufferFormat(format, plane);
111 for (size_t y = 0; y < height; ++y) { 104 for (size_t y = 0; y < height; ++y) {
112 memcpy(static_cast<char*>(mapped_buffers[plane]) + y * strides[plane], 105 memcpy(static_cast<char*>(buffer->memory(plane)) +
106 y * buffer->stride(plane),
113 data.get(), row_size_in_bytes); 107 data.get(), row_size_in_bytes);
114 EXPECT_EQ(memcmp(static_cast<char*>(mapped_buffers[plane]) + 108 EXPECT_EQ(0, memcmp(static_cast<char*>(buffer->memory(plane)) +
115 y * strides[plane], 109 y * buffer->stride(plane),
116 data.get(), row_size_in_bytes), 110 data.get(), row_size_in_bytes));
117 0);
118 } 111 }
119 } 112 }
120 113
121 buffer->Unmap(); 114 buffer->Unmap();
122 } 115 }
123 } 116 }
124 117
125 TYPED_TEST_P(GpuMemoryBufferImplTest, PersistentMap) { 118 TYPED_TEST_P(GpuMemoryBufferImplTest, PersistentMap) {
126 // Use a multiple of 4 for both dimensions to support compressed formats. 119 // Use a multiple of 4 for both dimensions to support compressed formats.
127 gfx::Size buffer_size(4, 4); 120 const gfx::Size kBufferSize(4, 4);
128 121
129 for (auto format : gfx::GetBufferFormats()) { 122 for (auto format : gfx::GetBufferFormatsForTesting()) {
130 if (!TypeParam::IsConfigurationSupported( 123 if (!TypeParam::IsConfigurationSupported(
131 format, gfx::BufferUsage::PERSISTENT_MAP)) { 124 format, gfx::BufferUsage::PERSISTENT_MAP)) {
132 continue; 125 continue;
133 } 126 }
134 127
135 gfx::GpuMemoryBufferHandle handle; 128 gfx::GpuMemoryBufferHandle handle;
136 GpuMemoryBufferImpl::DestructionCallback destroy_callback = 129 GpuMemoryBufferImpl::DestructionCallback destroy_callback =
137 TestFixture::AllocateGpuMemoryBuffer(buffer_size, format, 130 TestFixture::AllocateGpuMemoryBuffer(kBufferSize, format,
138 gfx::BufferUsage::PERSISTENT_MAP, 131 gfx::BufferUsage::PERSISTENT_MAP,
139 &handle, nullptr); 132 &handle, nullptr);
140 scoped_ptr<TypeParam> buffer(TypeParam::CreateFromHandle( 133 scoped_ptr<TypeParam> buffer(TypeParam::CreateFromHandle(
141 handle, buffer_size, format, gfx::BufferUsage::PERSISTENT_MAP, 134 handle, kBufferSize, format, gfx::BufferUsage::PERSISTENT_MAP,
142 destroy_callback)); 135 destroy_callback));
143 ASSERT_TRUE(buffer); 136 ASSERT_TRUE(buffer);
144 137
145 size_t num_planes = gfx::NumberOfPlanesForBufferFormat(format);
146
147 // Map buffer into user space. 138 // Map buffer into user space.
148 scoped_ptr<void* []> mapped_buffers(new void*[num_planes]); 139 ASSERT_TRUE(buffer->Map());
149 bool rv = buffer->Map(mapped_buffers.get());
150 ASSERT_TRUE(rv);
151
152 // Get strides.
153 scoped_ptr<int[]> strides(new int[num_planes]);
154 buffer->GetStride(strides.get());
155 140
156 // Copy and compare mapped buffers. 141 // Copy and compare mapped buffers.
142 size_t num_planes = gfx::NumberOfPlanesForBufferFormat(format);
157 for (size_t plane = 0; plane < num_planes; ++plane) { 143 for (size_t plane = 0; plane < num_planes; ++plane) {
158 size_t row_size_in_bytes; 144 const size_t row_size_in_bytes =
159 EXPECT_TRUE(gfx::RowSizeForBufferFormatChecked( 145 gfx::RowSizeForBufferFormat(kBufferSize.width(), format, plane);
160 buffer_size.width(), format, plane, &row_size_in_bytes));
161 EXPECT_GT(row_size_in_bytes, 0u); 146 EXPECT_GT(row_size_in_bytes, 0u);
162 147
163 scoped_ptr<char[]> data(new char[row_size_in_bytes]); 148 scoped_ptr<char[]> data(new char[row_size_in_bytes]);
164 memset(data.get(), 0x2a + plane, row_size_in_bytes); 149 memset(data.get(), 0x2a + plane, row_size_in_bytes);
165 150
166 size_t height = buffer_size.height() / 151 size_t height = kBufferSize.height() /
167 gfx::SubsamplingFactorForBufferFormat(format, plane); 152 gfx::SubsamplingFactorForBufferFormat(format, plane);
168 for (size_t y = 0; y < height; ++y) { 153 for (size_t y = 0; y < height; ++y) {
169 memcpy(static_cast<char*>(mapped_buffers[plane]) + y * strides[plane], 154 memcpy(static_cast<char*>(buffer->memory(plane)) +
155 y * buffer->stride(plane),
170 data.get(), row_size_in_bytes); 156 data.get(), row_size_in_bytes);
171 EXPECT_EQ(memcmp(static_cast<char*>(mapped_buffers[plane]) + 157 EXPECT_EQ(0, memcmp(static_cast<char*>(buffer->memory(plane)) +
172 y * strides[plane], 158 y * buffer->stride(plane),
173 data.get(), row_size_in_bytes), 159 data.get(), row_size_in_bytes));
174 0);
175 } 160 }
176 } 161 }
177 162
178 buffer->Unmap(); 163 buffer->Unmap();
179 164
180 // Remap the buffer, and compare again. It should contain the same data. 165 // Remap the buffer, and compare again. It should contain the same data.
181 rv = buffer->Map(mapped_buffers.get()); 166 ASSERT_TRUE(buffer->Map());
182 ASSERT_TRUE(rv);
183
184 buffer->GetStride(strides.get());
185 167
186 for (size_t plane = 0; plane < num_planes; ++plane) { 168 for (size_t plane = 0; plane < num_planes; ++plane) {
187 size_t row_size_in_bytes; 169 const size_t row_size_in_bytes =
188 EXPECT_TRUE(gfx::RowSizeForBufferFormatChecked( 170 gfx::RowSizeForBufferFormat(kBufferSize.width(), format, plane);
189 buffer_size.width(), format, plane, &row_size_in_bytes));
190 171
191 scoped_ptr<char[]> data(new char[row_size_in_bytes]); 172 scoped_ptr<char[]> data(new char[row_size_in_bytes]);
192 memset(data.get(), 0x2a + plane, row_size_in_bytes); 173 memset(data.get(), 0x2a + plane, row_size_in_bytes);
193 174
194 size_t height = buffer_size.height() / 175 size_t height = kBufferSize.height() /
195 gfx::SubsamplingFactorForBufferFormat(format, plane); 176 gfx::SubsamplingFactorForBufferFormat(format, plane);
196 for (size_t y = 0; y < height; ++y) { 177 for (size_t y = 0; y < height; ++y) {
197 EXPECT_EQ(memcmp(static_cast<char*>(mapped_buffers[plane]) + 178 EXPECT_EQ(0, memcmp(static_cast<char*>(buffer->memory(plane)) +
198 y * strides[plane], 179 y * buffer->stride(plane),
199 data.get(), row_size_in_bytes), 180 data.get(), row_size_in_bytes));
200 0);
201 } 181 }
202 } 182 }
203 183
204 buffer->Unmap(); 184 buffer->Unmap();
205 } 185 }
206 } 186 }
207 187
208 // The GpuMemoryBufferImplTest test case verifies behavior that is expected 188 // The GpuMemoryBufferImplTest test case verifies behavior that is expected
209 // from a GpuMemoryBuffer implementation in order to be conformant. 189 // from a GpuMemoryBuffer implementation in order to be conformant.
210 REGISTER_TYPED_TEST_CASE_P(GpuMemoryBufferImplTest, 190 REGISTER_TYPED_TEST_CASE_P(GpuMemoryBufferImplTest,
211 CreateFromHandle, 191 CreateFromHandle,
212 Map, 192 Map,
213 PersistentMap); 193 PersistentMap);
214 194
215 } // namespace content 195 } // namespace content
216 196
217 #endif // CONTENT_TEST_GPU_MEMORY_BUFFER_IMPL_TEST_TEMPLATE_H_ 197 #endif // CONTENT_TEST_GPU_MEMORY_BUFFER_IMPL_TEST_TEMPLATE_H_
OLDNEW
« no previous file with comments | « content/test/gpu_memory_buffer_factory_test_template.h ('k') | gpu/command_buffer/tests/gl_gpu_memory_buffer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698