1 // Copyright 2014 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.
5 #ifndef CONTENT_BROWSER_GPU_BROWSER_GPU_MEMORY_BUFFER_MANAGER_H_
6 #define CONTENT_BROWSER_GPU_BROWSER_GPU_MEMORY_BUFFER_MANAGER_H_
10 #include "base/callback.h"
11 #include "base/trace_event/memory_dump_provider.h"
12 #include "content/common/content_export.h"
13 #include "content/common/gpu/gpu_memory_buffer_factory.h"
14 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h"
18 class CONTENT_EXPORT BrowserGpuMemoryBufferManager
19 : public gpu::GpuMemoryBufferManager
,
20 public base::trace_event::MemoryDumpProvider
{
22 typedef base::Callback
<void(const gfx::GpuMemoryBufferHandle
& handle
)>
25 BrowserGpuMemoryBufferManager(int gpu_client_id
,
26 uint64_t gpu_client_tracing_id
);
27 ~BrowserGpuMemoryBufferManager() override
;
29 static BrowserGpuMemoryBufferManager
* current();
31 static uint32
GetImageTextureTarget(gfx::BufferFormat format
,
32 gfx::BufferUsage usage
);
34 // Overridden from gpu::GpuMemoryBufferManager:
35 scoped_ptr
<gfx::GpuMemoryBuffer
> AllocateGpuMemoryBuffer(
36 const gfx::Size
& size
,
37 gfx::BufferFormat format
,
38 gfx::BufferUsage usage
) override
;
39 gfx::GpuMemoryBuffer
* GpuMemoryBufferFromClientBuffer(
40 ClientBuffer buffer
) override
;
41 void SetDestructionSyncPoint(gfx::GpuMemoryBuffer
* buffer
,
42 uint32 sync_point
) override
;
44 // Overridden from base::trace_event::MemoryDumpProvider:
45 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs
& args
,
46 base::trace_event::ProcessMemoryDump
* pmd
) override
;
48 // Virtual for testing.
49 virtual scoped_ptr
<gfx::GpuMemoryBuffer
> AllocateGpuMemoryBufferForScanout(
50 const gfx::Size
& size
,
51 gfx::BufferFormat format
,
54 void AllocateGpuMemoryBufferForChildProcess(
55 const gfx::Size
& size
,
56 gfx::BufferFormat format
,
57 gfx::BufferUsage usage
,
58 base::ProcessHandle child_process_handle
,
60 const AllocationCallback
& callback
);
61 void ChildProcessDeletedGpuMemoryBuffer(
62 gfx::GpuMemoryBufferId id
,
63 base::ProcessHandle child_process_handle
,
66 void ProcessRemoved(base::ProcessHandle process_handle
, int client_id
);
71 : type(gfx::EMPTY_BUFFER
),
72 format(gfx::BufferFormat::RGBA_8888
),
73 usage(gfx::BufferUsage::MAP
),
75 BufferInfo(const gfx::Size
& size
,
76 gfx::GpuMemoryBufferType type
,
77 gfx::BufferFormat format
,
78 gfx::BufferUsage usage
,
84 gpu_host_id(gpu_host_id
) {}
87 gfx::GpuMemoryBufferType type
;
88 gfx::BufferFormat format
;
89 gfx::BufferUsage usage
;
92 struct AllocateGpuMemoryBufferRequest
;
94 scoped_ptr
<gfx::GpuMemoryBuffer
> AllocateGpuMemoryBufferForSurface(
95 const gfx::Size
& size
,
96 gfx::BufferFormat format
,
97 gfx::BufferUsage usage
,
99 bool IsGpuMemoryBufferConfigurationSupported(gfx::BufferFormat format
,
100 gfx::BufferUsage usage
) const;
101 void AllocateGpuMemoryBufferForSurfaceOnIO(
102 AllocateGpuMemoryBufferRequest
* request
);
103 void GpuMemoryBufferAllocatedForSurfaceOnIO(
104 AllocateGpuMemoryBufferRequest
* request
,
105 const gfx::GpuMemoryBufferHandle
& handle
);
106 void AllocateGpuMemoryBufferOnIO(gfx::GpuMemoryBufferId id
,
107 const gfx::Size
& size
,
108 gfx::BufferFormat format
,
109 gfx::BufferUsage usage
,
112 bool reused_gpu_process
,
113 const AllocationCallback
& callback
);
114 void GpuMemoryBufferAllocatedOnIO(gfx::GpuMemoryBufferId id
,
118 bool reused_gpu_process
,
119 const AllocationCallback
& callback
,
120 const gfx::GpuMemoryBufferHandle
& handle
);
121 void DestroyGpuMemoryBufferOnIO(gfx::GpuMemoryBufferId id
,
125 uint64_t ClientIdToTracingProcessId(int client_id
) const;
127 const gfx::GpuMemoryBufferType factory_type_
;
128 const std::vector
<GpuMemoryBufferFactory::Configuration
>
129 supported_configurations_
;
130 const int gpu_client_id_
;
131 const uint64_t gpu_client_tracing_id_
;
133 // The GPU process host ID. This should only be accessed on the IO thread.
136 // Stores info about buffers for all clients. This should only be accessed
138 using BufferMap
= base::hash_map
<gfx::GpuMemoryBufferId
, BufferInfo
>;
139 using ClientMap
= base::hash_map
<int, BufferMap
>;
142 DISALLOW_COPY_AND_ASSIGN(BrowserGpuMemoryBufferManager
);
145 } // namespace content
147 #endif // CONTENT_BROWSER_GPU_BROWSER_GPU_MEMORY_BUFFER_MANAGER_H_