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

Side by Side Diff: components/viz/common/server_gpu_memory_buffer_manager_unittest.cc

Issue 2955813002: viz: Replace a DCHECK with proper error handling. (Closed)
Patch Set: . Created 3 years, 5 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
« no previous file with comments | « components/viz/common/server_gpu_memory_buffer_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "components/viz/common/server_gpu_memory_buffer_manager.h" 5 #include "components/viz/common/server_gpu_memory_buffer_manager.h"
6 6
7 #include "base/test/scoped_task_environment.h" 7 #include "base/test/scoped_task_environment.h"
8 #include "gpu/ipc/host/gpu_memory_buffer_support.h" 8 #include "gpu/ipc/host/gpu_memory_buffer_support.h"
9 #include "services/ui/gpu/interfaces/gpu_service.mojom.h" 9 #include "services/ui/gpu/interfaces/gpu_service.mojom.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 EXPECT_TRUE(gpu_service.HasAllocationRequest(buffer_id, client_id)); 201 EXPECT_TRUE(gpu_service.HasAllocationRequest(buffer_id, client_id));
202 EXPECT_FALSE(gpu_service.HasDestructionRequest(buffer_id, client_id)); 202 EXPECT_FALSE(gpu_service.HasDestructionRequest(buffer_id, client_id));
203 203
204 // When the host receives the allocated memory for the destroyed client, it 204 // When the host receives the allocated memory for the destroyed client, it
205 // should request the allocated memory to be freed. 205 // should request the allocated memory to be freed.
206 gpu_service.SatisfyAllocationRequest(buffer_id, client_id); 206 gpu_service.SatisfyAllocationRequest(buffer_id, client_id);
207 EXPECT_TRUE(gpu_service.HasDestructionRequest(buffer_id, client_id)); 207 EXPECT_TRUE(gpu_service.HasDestructionRequest(buffer_id, client_id));
208 #endif 208 #endif
209 } 209 }
210 210
211 TEST_F(ServerGpuMemoryBufferManagerTest,
212 RequestsFromUntrustedClientsValidated) {
213 gfx::ClientNativePixmapFactory::ResetInstance();
214 TestGpuService gpu_service;
215 ServerGpuMemoryBufferManager manager(&gpu_service, 1);
216 const auto buffer_id = static_cast<gfx::GpuMemoryBufferId>(1);
217 const int client_id = 2;
218 // SCANOUT cannot be used if native gpu memory buffer is not supported.
219 // When ATC is used, both width and height should be multiples of 4.
220 struct {
221 gfx::BufferUsage usage;
222 gfx::BufferFormat format;
223 gfx::Size size;
224 bool expect_null_handle;
225 } configs[] = {
226 {gfx::BufferUsage::SCANOUT, gfx::BufferFormat::YVU_420, {10, 20}, true},
227 {gfx::BufferUsage::GPU_READ, gfx::BufferFormat::ATC, {10, 20}, true},
228 {gfx::BufferUsage::GPU_READ, gfx::BufferFormat::YVU_420, {10, 20}, false},
229 };
230 for (const auto& config : configs) {
231 gfx::GpuMemoryBufferHandle allocated_handle;
232 base::RunLoop runloop;
233 manager.AllocateGpuMemoryBuffer(
234 buffer_id, client_id, config.size, config.format, config.usage,
235 gpu::kNullSurfaceHandle,
236 base::BindOnce(
237 [](gfx::GpuMemoryBufferHandle* allocated_handle,
238 const base::Closure& callback,
239 const gfx::GpuMemoryBufferHandle& handle) {
240 *allocated_handle = handle;
241 callback.Run();
242 },
243 &allocated_handle, runloop.QuitClosure()));
244 // Since native gpu memory buffers are not supported, the mojom.GpuService
245 // should not receive any allocation requests.
246 EXPECT_FALSE(gpu_service.HasAllocationRequest(buffer_id, client_id));
247 runloop.Run();
248 if (config.expect_null_handle) {
249 EXPECT_TRUE(allocated_handle.is_null());
250 } else {
251 EXPECT_FALSE(allocated_handle.is_null());
252 EXPECT_EQ(gfx::GpuMemoryBufferType::SHARED_MEMORY_BUFFER,
253 allocated_handle.type);
254 }
255 }
256 }
257
211 } // namespace viz 258 } // namespace viz
OLDNEW
« no previous file with comments | « components/viz/common/server_gpu_memory_buffer_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698