Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 const gfx::Size size(10, 20); | |
| 219 // SCANOUT cannot be used if native gpu memory buffer is not supported. | |
| 220 struct { | |
| 221 gfx::BufferUsage usage; | |
| 222 gfx::BufferFormat format; | |
| 223 bool expect_null_handle; | |
| 224 } configs[] = { | |
| 225 {gfx::BufferUsage::SCANOUT, gfx::BufferFormat::YVU_420, true}, | |
| 226 {gfx::BufferUsage::GPU_READ, gfx::BufferFormat::YVU_420, false}, | |
| 227 }; | |
| 228 for (const auto& config : configs) { | |
| 229 gfx::GpuMemoryBufferHandle allocated_handle; | |
| 230 base::RunLoop runloop; | |
| 231 manager.AllocateGpuMemoryBuffer( | |
| 232 buffer_id, client_id, size, config.format, config.usage, | |
| 233 gpu::kNullSurfaceHandle, | |
| 234 base::BindOnce( | |
| 235 [](gfx::GpuMemoryBufferHandle* allocated_handle, | |
| 236 const base::Closure& callback, | |
| 237 const gfx::GpuMemoryBufferHandle& handle) { | |
| 238 *allocated_handle = handle; | |
| 239 callback.Run(); | |
| 240 }, | |
| 241 &allocated_handle, runloop.QuitClosure())); | |
| 242 // Since native gpu memory buffers are not supported, the mojom.GpuService | |
| 243 // should not receive any allocation requests. | |
| 244 EXPECT_FALSE(gpu_service.HasAllocationRequest(buffer_id, client_id)); | |
| 245 runloop.Run(); | |
| 246 if (config.expect_null_handle) { | |
| 247 EXPECT_TRUE(allocated_handle.is_null()); | |
| 248 } else { | |
| 249 EXPECT_FALSE(allocated_handle.is_null()); | |
| 250 EXPECT_EQ(gfx::GpuMemoryBufferType::SHARED_MEMORY_BUFFER, | |
| 251 allocated_handle.type); | |
| 252 } | |
| 253 } | |
|
danakj
2017/06/26 15:43:42
Can you add something that shows we actually hit b
sadrul
2017/06/26 21:48:58
Good point. Done.
| |
| 254 } | |
| 255 | |
| 211 } // namespace viz | 256 } // namespace viz |
| OLD | NEW |