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

Side by Side Diff: gpu/ipc/client/gpu_memory_buffer_impl_test_template.h

Issue 1859703002: convert //gpu to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase on master Created 4 years, 8 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 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 GPU_IPC_CLIENT_GPU_MEMORY_BUFFER_IMPL_TEST_TEMPLATE_H_ 8 #ifndef GPU_IPC_CLIENT_GPU_MEMORY_BUFFER_IMPL_TEST_TEMPLATE_H_
9 #define GPU_IPC_CLIENT_GPU_MEMORY_BUFFER_IMPL_TEST_TEMPLATE_H_ 9 #define GPU_IPC_CLIENT_GPU_MEMORY_BUFFER_IMPL_TEST_TEMPLATE_H_
10 10
11 #include <stddef.h> 11 #include <stddef.h>
12 #include <string.h> 12 #include <string.h>
13 13
14 #include <memory>
15
14 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
15 #include "ui/gfx/buffer_format_util.h" 17 #include "ui/gfx/buffer_format_util.h"
16 18
17 namespace gpu { 19 namespace gpu {
18 20
19 template <typename GpuMemoryBufferImplType> 21 template <typename GpuMemoryBufferImplType>
20 class GpuMemoryBufferImplTest : public testing::Test { 22 class GpuMemoryBufferImplTest : public testing::Test {
21 public: 23 public:
22 GpuMemoryBufferImpl::DestructionCallback AllocateGpuMemoryBuffer( 24 GpuMemoryBufferImpl::DestructionCallback AllocateGpuMemoryBuffer(
23 const gfx::Size& size, 25 const gfx::Size& size,
(...skipping 30 matching lines...) Expand all
54 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT}; 56 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT};
55 for (auto usage : usages) { 57 for (auto usage : usages) {
56 if (!TypeParam::IsConfigurationSupported(format, usage)) 58 if (!TypeParam::IsConfigurationSupported(format, usage))
57 continue; 59 continue;
58 60
59 bool destroyed = false; 61 bool destroyed = false;
60 gfx::GpuMemoryBufferHandle handle; 62 gfx::GpuMemoryBufferHandle handle;
61 GpuMemoryBufferImpl::DestructionCallback destroy_callback = 63 GpuMemoryBufferImpl::DestructionCallback destroy_callback =
62 TestFixture::AllocateGpuMemoryBuffer(kBufferSize, format, usage, 64 TestFixture::AllocateGpuMemoryBuffer(kBufferSize, format, usage,
63 &handle, &destroyed); 65 &handle, &destroyed);
64 scoped_ptr<TypeParam> buffer(TypeParam::CreateFromHandle( 66 std::unique_ptr<TypeParam> buffer(TypeParam::CreateFromHandle(
65 handle, kBufferSize, format, usage, destroy_callback)); 67 handle, kBufferSize, format, usage, destroy_callback));
66 ASSERT_TRUE(buffer); 68 ASSERT_TRUE(buffer);
67 EXPECT_EQ(buffer->GetFormat(), format); 69 EXPECT_EQ(buffer->GetFormat(), format);
68 70
69 // Check if destruction callback is executed when deleting the buffer. 71 // Check if destruction callback is executed when deleting the buffer.
70 buffer.reset(); 72 buffer.reset();
71 ASSERT_TRUE(destroyed); 73 ASSERT_TRUE(destroyed);
72 } 74 }
73 } 75 }
74 } 76 }
75 77
76 TYPED_TEST_P(GpuMemoryBufferImplTest, Map) { 78 TYPED_TEST_P(GpuMemoryBufferImplTest, Map) {
77 // Use a multiple of 4 for both dimensions to support compressed formats. 79 // Use a multiple of 4 for both dimensions to support compressed formats.
78 const gfx::Size kBufferSize(4, 4); 80 const gfx::Size kBufferSize(4, 4);
79 81
80 for (auto format : gfx::GetBufferFormatsForTesting()) { 82 for (auto format : gfx::GetBufferFormatsForTesting()) {
81 if (!TypeParam::IsConfigurationSupported( 83 if (!TypeParam::IsConfigurationSupported(
82 format, gfx::BufferUsage::GPU_READ_CPU_READ_WRITE)) { 84 format, gfx::BufferUsage::GPU_READ_CPU_READ_WRITE)) {
83 continue; 85 continue;
84 } 86 }
85 87
86 gfx::GpuMemoryBufferHandle handle; 88 gfx::GpuMemoryBufferHandle handle;
87 GpuMemoryBufferImpl::DestructionCallback destroy_callback = 89 GpuMemoryBufferImpl::DestructionCallback destroy_callback =
88 TestFixture::AllocateGpuMemoryBuffer( 90 TestFixture::AllocateGpuMemoryBuffer(
89 kBufferSize, format, gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, 91 kBufferSize, format, gfx::BufferUsage::GPU_READ_CPU_READ_WRITE,
90 &handle, nullptr); 92 &handle, nullptr);
91 scoped_ptr<TypeParam> buffer(TypeParam::CreateFromHandle( 93 std::unique_ptr<TypeParam> buffer(TypeParam::CreateFromHandle(
92 handle, kBufferSize, format, gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, 94 handle, kBufferSize, format, gfx::BufferUsage::GPU_READ_CPU_READ_WRITE,
93 destroy_callback)); 95 destroy_callback));
94 ASSERT_TRUE(buffer); 96 ASSERT_TRUE(buffer);
95 97
96 const size_t num_planes = gfx::NumberOfPlanesForBufferFormat(format); 98 const size_t num_planes = gfx::NumberOfPlanesForBufferFormat(format);
97 99
98 // Map buffer into user space. 100 // Map buffer into user space.
99 ASSERT_TRUE(buffer->Map()); 101 ASSERT_TRUE(buffer->Map());
100 102
101 // Copy and compare mapped buffers. 103 // Copy and compare mapped buffers.
102 for (size_t plane = 0; plane < num_planes; ++plane) { 104 for (size_t plane = 0; plane < num_planes; ++plane) {
103 const size_t row_size_in_bytes = 105 const size_t row_size_in_bytes =
104 gfx::RowSizeForBufferFormat(kBufferSize.width(), format, plane); 106 gfx::RowSizeForBufferFormat(kBufferSize.width(), format, plane);
105 EXPECT_GT(row_size_in_bytes, 0u); 107 EXPECT_GT(row_size_in_bytes, 0u);
106 108
107 scoped_ptr<char[]> data(new char[row_size_in_bytes]); 109 std::unique_ptr<char[]> data(new char[row_size_in_bytes]);
108 memset(data.get(), 0x2a + plane, row_size_in_bytes); 110 memset(data.get(), 0x2a + plane, row_size_in_bytes);
109 111
110 size_t height = kBufferSize.height() / 112 size_t height = kBufferSize.height() /
111 gfx::SubsamplingFactorForBufferFormat(format, plane); 113 gfx::SubsamplingFactorForBufferFormat(format, plane);
112 for (size_t y = 0; y < height; ++y) { 114 for (size_t y = 0; y < height; ++y) {
113 memcpy(static_cast<char*>(buffer->memory(plane)) + 115 memcpy(static_cast<char*>(buffer->memory(plane)) +
114 y * buffer->stride(plane), 116 y * buffer->stride(plane),
115 data.get(), row_size_in_bytes); 117 data.get(), row_size_in_bytes);
116 EXPECT_EQ(0, memcmp(static_cast<char*>(buffer->memory(plane)) + 118 EXPECT_EQ(0, memcmp(static_cast<char*>(buffer->memory(plane)) +
117 y * buffer->stride(plane), 119 y * buffer->stride(plane),
(...skipping 14 matching lines...) Expand all
132 format, gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT)) { 134 format, gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT)) {
133 continue; 135 continue;
134 } 136 }
135 137
136 gfx::GpuMemoryBufferHandle handle; 138 gfx::GpuMemoryBufferHandle handle;
137 GpuMemoryBufferImpl::DestructionCallback destroy_callback = 139 GpuMemoryBufferImpl::DestructionCallback destroy_callback =
138 TestFixture::AllocateGpuMemoryBuffer( 140 TestFixture::AllocateGpuMemoryBuffer(
139 kBufferSize, format, 141 kBufferSize, format,
140 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT, &handle, 142 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT, &handle,
141 nullptr); 143 nullptr);
142 scoped_ptr<TypeParam> buffer(TypeParam::CreateFromHandle( 144 std::unique_ptr<TypeParam> buffer(TypeParam::CreateFromHandle(
143 handle, kBufferSize, format, 145 handle, kBufferSize, format,
144 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT, 146 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT,
145 destroy_callback)); 147 destroy_callback));
146 ASSERT_TRUE(buffer); 148 ASSERT_TRUE(buffer);
147 149
148 // Map buffer into user space. 150 // Map buffer into user space.
149 ASSERT_TRUE(buffer->Map()); 151 ASSERT_TRUE(buffer->Map());
150 152
151 // Copy and compare mapped buffers. 153 // Copy and compare mapped buffers.
152 size_t num_planes = gfx::NumberOfPlanesForBufferFormat(format); 154 size_t num_planes = gfx::NumberOfPlanesForBufferFormat(format);
153 for (size_t plane = 0; plane < num_planes; ++plane) { 155 for (size_t plane = 0; plane < num_planes; ++plane) {
154 const size_t row_size_in_bytes = 156 const size_t row_size_in_bytes =
155 gfx::RowSizeForBufferFormat(kBufferSize.width(), format, plane); 157 gfx::RowSizeForBufferFormat(kBufferSize.width(), format, plane);
156 EXPECT_GT(row_size_in_bytes, 0u); 158 EXPECT_GT(row_size_in_bytes, 0u);
157 159
158 scoped_ptr<char[]> data(new char[row_size_in_bytes]); 160 std::unique_ptr<char[]> data(new char[row_size_in_bytes]);
159 memset(data.get(), 0x2a + plane, row_size_in_bytes); 161 memset(data.get(), 0x2a + plane, row_size_in_bytes);
160 162
161 size_t height = kBufferSize.height() / 163 size_t height = kBufferSize.height() /
162 gfx::SubsamplingFactorForBufferFormat(format, plane); 164 gfx::SubsamplingFactorForBufferFormat(format, plane);
163 for (size_t y = 0; y < height; ++y) { 165 for (size_t y = 0; y < height; ++y) {
164 memcpy(static_cast<char*>(buffer->memory(plane)) + 166 memcpy(static_cast<char*>(buffer->memory(plane)) +
165 y * buffer->stride(plane), 167 y * buffer->stride(plane),
166 data.get(), row_size_in_bytes); 168 data.get(), row_size_in_bytes);
167 EXPECT_EQ(0, memcmp(static_cast<char*>(buffer->memory(plane)) + 169 EXPECT_EQ(0, memcmp(static_cast<char*>(buffer->memory(plane)) +
168 y * buffer->stride(plane), 170 y * buffer->stride(plane),
169 data.get(), row_size_in_bytes)); 171 data.get(), row_size_in_bytes));
170 } 172 }
171 } 173 }
172 174
173 buffer->Unmap(); 175 buffer->Unmap();
174 176
175 // Remap the buffer, and compare again. It should contain the same data. 177 // Remap the buffer, and compare again. It should contain the same data.
176 ASSERT_TRUE(buffer->Map()); 178 ASSERT_TRUE(buffer->Map());
177 179
178 for (size_t plane = 0; plane < num_planes; ++plane) { 180 for (size_t plane = 0; plane < num_planes; ++plane) {
179 const size_t row_size_in_bytes = 181 const size_t row_size_in_bytes =
180 gfx::RowSizeForBufferFormat(kBufferSize.width(), format, plane); 182 gfx::RowSizeForBufferFormat(kBufferSize.width(), format, plane);
181 183
182 scoped_ptr<char[]> data(new char[row_size_in_bytes]); 184 std::unique_ptr<char[]> data(new char[row_size_in_bytes]);
183 memset(data.get(), 0x2a + plane, row_size_in_bytes); 185 memset(data.get(), 0x2a + plane, row_size_in_bytes);
184 186
185 size_t height = kBufferSize.height() / 187 size_t height = kBufferSize.height() /
186 gfx::SubsamplingFactorForBufferFormat(format, plane); 188 gfx::SubsamplingFactorForBufferFormat(format, plane);
187 for (size_t y = 0; y < height; ++y) { 189 for (size_t y = 0; y < height; ++y) {
188 EXPECT_EQ(0, memcmp(static_cast<char*>(buffer->memory(plane)) + 190 EXPECT_EQ(0, memcmp(static_cast<char*>(buffer->memory(plane)) +
189 y * buffer->stride(plane), 191 y * buffer->stride(plane),
190 data.get(), row_size_in_bytes)); 192 data.get(), row_size_in_bytes));
191 } 193 }
192 } 194 }
193 195
194 buffer->Unmap(); 196 buffer->Unmap();
195 } 197 }
196 } 198 }
197 199
198 // The GpuMemoryBufferImplTest test case verifies behavior that is expected 200 // The GpuMemoryBufferImplTest test case verifies behavior that is expected
199 // from a GpuMemoryBuffer implementation in order to be conformant. 201 // from a GpuMemoryBuffer implementation in order to be conformant.
200 REGISTER_TYPED_TEST_CASE_P(GpuMemoryBufferImplTest, 202 REGISTER_TYPED_TEST_CASE_P(GpuMemoryBufferImplTest,
201 CreateFromHandle, 203 CreateFromHandle,
202 Map, 204 Map,
203 PersistentMap); 205 PersistentMap);
204 206
205 } // namespace gpu 207 } // namespace gpu
206 208
207 #endif // GPU_IPC_CLIENT_GPU_MEMORY_BUFFER_IMPL_TEST_TEMPLATE_H_ 209 #endif // GPU_IPC_CLIENT_GPU_MEMORY_BUFFER_IMPL_TEST_TEMPLATE_H_
OLDNEW
« no previous file with comments | « gpu/ipc/client/gpu_memory_buffer_impl_surface_texture.cc ('k') | gpu/ipc/service/ca_layer_partial_damage_tree_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698