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

Side by Side Diff: components/viz/host/server_gpu_memory_buffer_manager.h

Issue 2971903003: mus-gpu: Add support for tracking allocated gpu memory. (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/host/DEPS ('k') | components/viz/host/server_gpu_memory_buffer_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 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 #ifndef COMPONENTS_VIZ_HOST_SERVER_GPU_MEMORY_BUFFER_MANAGER_H_ 5 #ifndef COMPONENTS_VIZ_HOST_SERVER_GPU_MEMORY_BUFFER_MANAGER_H_
6 #define COMPONENTS_VIZ_HOST_SERVER_GPU_MEMORY_BUFFER_MANAGER_H_ 6 #define COMPONENTS_VIZ_HOST_SERVER_GPU_MEMORY_BUFFER_MANAGER_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
12 #include "base/sequenced_task_runner.h" 12 #include "base/sequenced_task_runner.h"
13 #include "base/synchronization/waitable_event.h" 13 #include "base/synchronization/waitable_event.h"
14 #include "base/trace_event/memory_dump_provider.h"
14 #include "components/viz/host/viz_host_export.h" 15 #include "components/viz/host/viz_host_export.h"
15 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" 16 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h"
16 #include "gpu/ipc/host/gpu_memory_buffer_support.h" 17 #include "gpu/ipc/host/gpu_memory_buffer_support.h"
17 18
18 namespace ui { 19 namespace ui {
19 namespace mojom { 20 namespace mojom {
20 class GpuService; 21 class GpuService;
21 } 22 }
22 } // namespace ui 23 } // namespace ui
23 24
24 namespace viz { 25 namespace viz {
25 26
26 // This GpuMemoryBufferManager implementation is for [de]allocating gpu memory 27 // This GpuMemoryBufferManager implementation is for [de]allocating gpu memory
27 // from the gpu process over the mojom.GpuService api. 28 // from the gpu process over the mojom.GpuService api.
28 // Note that |CreateGpuMemoryBuffer()| can be called on any thread. All the rest 29 // Note that |CreateGpuMemoryBuffer()| can be called on any thread. All the rest
29 // of the functions must be called on the thread this object is created on. 30 // of the functions must be called on the thread this object is created on.
30 class VIZ_HOST_EXPORT ServerGpuMemoryBufferManager 31 class VIZ_HOST_EXPORT ServerGpuMemoryBufferManager
31 : public gpu::GpuMemoryBufferManager { 32 : public gpu::GpuMemoryBufferManager,
33 public base::trace_event::MemoryDumpProvider {
32 public: 34 public:
33 ServerGpuMemoryBufferManager(ui::mojom::GpuService* gpu_service, 35 ServerGpuMemoryBufferManager(ui::mojom::GpuService* gpu_service,
34 int client_id); 36 int client_id);
35 ~ServerGpuMemoryBufferManager() override; 37 ~ServerGpuMemoryBufferManager() override;
36 38
37 void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, 39 void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id,
38 int client_id, 40 int client_id,
39 const gpu::SyncToken& sync_token); 41 const gpu::SyncToken& sync_token);
40 42
41 void DestroyAllGpuMemoryBufferForClient(int client_id); 43 void DestroyAllGpuMemoryBufferForClient(int client_id);
42 44
43 void AllocateGpuMemoryBuffer( 45 void AllocateGpuMemoryBuffer(
44 gfx::GpuMemoryBufferId id, 46 gfx::GpuMemoryBufferId id,
45 int client_id, 47 int client_id,
46 const gfx::Size& size, 48 const gfx::Size& size,
47 gfx::BufferFormat format, 49 gfx::BufferFormat format,
48 gfx::BufferUsage usage, 50 gfx::BufferUsage usage,
49 gpu::SurfaceHandle surface_handle, 51 gpu::SurfaceHandle surface_handle,
50 base::OnceCallback<void(const gfx::GpuMemoryBufferHandle&)> callback); 52 base::OnceCallback<void(const gfx::GpuMemoryBufferHandle&)> callback);
51 53
52 // Overridden from gpu::GpuMemoryBufferManager: 54 // Overridden from gpu::GpuMemoryBufferManager:
53 std::unique_ptr<gfx::GpuMemoryBuffer> CreateGpuMemoryBuffer( 55 std::unique_ptr<gfx::GpuMemoryBuffer> CreateGpuMemoryBuffer(
54 const gfx::Size& size, 56 const gfx::Size& size,
55 gfx::BufferFormat format, 57 gfx::BufferFormat format,
56 gfx::BufferUsage usage, 58 gfx::BufferUsage usage,
57 gpu::SurfaceHandle surface_handle) override; 59 gpu::SurfaceHandle surface_handle) override;
58 void SetDestructionSyncToken(gfx::GpuMemoryBuffer* buffer, 60 void SetDestructionSyncToken(gfx::GpuMemoryBuffer* buffer,
59 const gpu::SyncToken& sync_token) override; 61 const gpu::SyncToken& sync_token) override;
60 62
63 // Overridden from base::trace_event::MemoryDumpProvider:
64 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args,
65 base::trace_event::ProcessMemoryDump* pmd) override;
66
61 private: 67 private:
68 uint64_t ClientIdToTracingId(int client_id) const;
62 void OnGpuMemoryBufferAllocated( 69 void OnGpuMemoryBufferAllocated(
63 int client_id, 70 int client_id,
71 size_t buffer_size_in_bytes,
64 base::OnceCallback<void(const gfx::GpuMemoryBufferHandle&)> callback, 72 base::OnceCallback<void(const gfx::GpuMemoryBufferHandle&)> callback,
65 const gfx::GpuMemoryBufferHandle& handle); 73 const gfx::GpuMemoryBufferHandle& handle);
66 74
67 ui::mojom::GpuService* gpu_service_; 75 ui::mojom::GpuService* gpu_service_;
68 const int client_id_; 76 const int client_id_;
69 int next_gpu_memory_id_ = 1; 77 int next_gpu_memory_id_ = 1;
70 78
71 using NativeBuffers = 79 struct BufferInfo {
72 std::unordered_set<gfx::GpuMemoryBufferId, 80 BufferInfo();
81 ~BufferInfo();
82 gfx::GpuMemoryBufferType type = gfx::EMPTY_BUFFER;
83 size_t buffer_size_in_bytes = 0;
84 base::UnguessableToken shared_memory_guid;
85 };
86
87 using AllocatedBuffers =
88 std::unordered_map<gfx::GpuMemoryBufferId,
89 BufferInfo,
73 BASE_HASH_NAMESPACE::hash<gfx::GpuMemoryBufferId>>; 90 BASE_HASH_NAMESPACE::hash<gfx::GpuMemoryBufferId>>;
74 std::unordered_map<int, NativeBuffers> native_buffers_; 91 std::unordered_map<int, AllocatedBuffers> allocated_buffers_;
75 std::unordered_set<int> pending_buffers_; 92 std::unordered_set<int> pending_buffers_;
76 93
77 const gpu::GpuMemoryBufferConfigurationSet native_configurations_; 94 const gpu::GpuMemoryBufferConfigurationSet native_configurations_;
78 scoped_refptr<base::SequencedTaskRunner> task_runner_; 95 scoped_refptr<base::SequencedTaskRunner> task_runner_;
79 base::WeakPtrFactory<ServerGpuMemoryBufferManager> weak_factory_; 96 base::WeakPtrFactory<ServerGpuMemoryBufferManager> weak_factory_;
80 97
81 DISALLOW_COPY_AND_ASSIGN(ServerGpuMemoryBufferManager); 98 DISALLOW_COPY_AND_ASSIGN(ServerGpuMemoryBufferManager);
82 }; 99 };
83 100
84 } // namespace viz 101 } // namespace viz
85 102
86 #endif // COMPONENTS_VIZ_HOST_SERVER_GPU_MEMORY_BUFFER_MANAGER_H_ 103 #endif // COMPONENTS_VIZ_HOST_SERVER_GPU_MEMORY_BUFFER_MANAGER_H_
OLDNEW
« no previous file with comments | « components/viz/host/DEPS ('k') | components/viz/host/server_gpu_memory_buffer_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698