| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef COMPONENTS_VIZ_COMMON_SERVER_GPU_MEMORY_BUFFER_MANAGER_H_ | |
| 6 #define COMPONENTS_VIZ_COMMON_SERVER_GPU_MEMORY_BUFFER_MANAGER_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 | |
| 10 #include "base/macros.h" | |
| 11 #include "base/memory/weak_ptr.h" | |
| 12 #include "base/sequenced_task_runner.h" | |
| 13 #include "base/synchronization/waitable_event.h" | |
| 14 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" | |
| 15 #include "gpu/ipc/host/gpu_memory_buffer_support.h" | |
| 16 | |
| 17 namespace ui { | |
| 18 namespace mojom { | |
| 19 class GpuService; | |
| 20 } | |
| 21 } | |
| 22 | |
| 23 namespace viz { | |
| 24 | |
| 25 // This GpuMemoryBufferManager implementation is for [de]allocating gpu memory | |
| 26 // from the gpu process over the mojom.GpuService api. | |
| 27 // Note that |CreateGpuMemoryBuffer()| can be called on any thread. All the rest | |
| 28 // of the functions must be called on the thread this object is created on. | |
| 29 class ServerGpuMemoryBufferManager : public gpu::GpuMemoryBufferManager { | |
| 30 public: | |
| 31 ServerGpuMemoryBufferManager(ui::mojom::GpuService* gpu_service, | |
| 32 int client_id); | |
| 33 ~ServerGpuMemoryBufferManager() override; | |
| 34 | |
| 35 void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, | |
| 36 int client_id, | |
| 37 const gpu::SyncToken& sync_token); | |
| 38 | |
| 39 void DestroyAllGpuMemoryBufferForClient(int client_id); | |
| 40 | |
| 41 void AllocateGpuMemoryBuffer( | |
| 42 gfx::GpuMemoryBufferId id, | |
| 43 int client_id, | |
| 44 const gfx::Size& size, | |
| 45 gfx::BufferFormat format, | |
| 46 gfx::BufferUsage usage, | |
| 47 gpu::SurfaceHandle surface_handle, | |
| 48 base::OnceCallback<void(const gfx::GpuMemoryBufferHandle&)> callback); | |
| 49 | |
| 50 // Overridden from gpu::GpuMemoryBufferManager: | |
| 51 std::unique_ptr<gfx::GpuMemoryBuffer> CreateGpuMemoryBuffer( | |
| 52 const gfx::Size& size, | |
| 53 gfx::BufferFormat format, | |
| 54 gfx::BufferUsage usage, | |
| 55 gpu::SurfaceHandle surface_handle) override; | |
| 56 void SetDestructionSyncToken(gfx::GpuMemoryBuffer* buffer, | |
| 57 const gpu::SyncToken& sync_token) override; | |
| 58 | |
| 59 private: | |
| 60 void OnGpuMemoryBufferAllocated( | |
| 61 int client_id, | |
| 62 base::OnceCallback<void(const gfx::GpuMemoryBufferHandle&)> callback, | |
| 63 const gfx::GpuMemoryBufferHandle& handle); | |
| 64 | |
| 65 ui::mojom::GpuService* gpu_service_; | |
| 66 const int client_id_; | |
| 67 int next_gpu_memory_id_ = 1; | |
| 68 | |
| 69 using NativeBuffers = | |
| 70 std::unordered_set<gfx::GpuMemoryBufferId, | |
| 71 BASE_HASH_NAMESPACE::hash<gfx::GpuMemoryBufferId>>; | |
| 72 std::unordered_map<int, NativeBuffers> native_buffers_; | |
| 73 std::unordered_set<int> pending_buffers_; | |
| 74 | |
| 75 const gpu::GpuMemoryBufferConfigurationSet native_configurations_; | |
| 76 scoped_refptr<base::SequencedTaskRunner> task_runner_; | |
| 77 base::WeakPtrFactory<ServerGpuMemoryBufferManager> weak_factory_; | |
| 78 | |
| 79 DISALLOW_COPY_AND_ASSIGN(ServerGpuMemoryBufferManager); | |
| 80 }; | |
| 81 | |
| 82 } // namespace viz | |
| 83 | |
| 84 #endif // COMPONENTS_VIZ_COMMON_SERVER_GPU_MEMORY_BUFFER_MANAGER_H_ | |
| OLD | NEW |