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 gfx::GpuMemoryBufferId id
,
56 const gfx::Size
& size
,
57 gfx::BufferFormat format
,
58 gfx::BufferUsage usage
,
59 base::ProcessHandle child_process_handle
,
61 const AllocationCallback
& callback
);
62 void ChildProcessDeletedGpuMemoryBuffer(
63 gfx::GpuMemoryBufferId id
,
64 base::ProcessHandle child_process_handle
,
67 void ProcessRemoved(base::ProcessHandle process_handle
, int client_id
);
72 : type(gfx::EMPTY_BUFFER
),
73 format(gfx::BufferFormat::RGBA_8888
),
74 usage(gfx::BufferUsage::MAP
),
76 BufferInfo(const gfx::Size
& size
,
77 gfx::GpuMemoryBufferType type
,
78 gfx::BufferFormat format
,
79 gfx::BufferUsage usage
,
85 gpu_host_id(gpu_host_id
) {}
88 gfx::GpuMemoryBufferType type
;
89 gfx::BufferFormat format
;
90 gfx::BufferUsage usage
;
93 struct AllocateGpuMemoryBufferRequest
;
95 scoped_ptr
<gfx::GpuMemoryBuffer
> AllocateGpuMemoryBufferForSurface(
96 const gfx::Size
& size
,
97 gfx::BufferFormat format
,
98 gfx::BufferUsage usage
,
100 bool IsGpuMemoryBufferConfigurationSupported(gfx::BufferFormat format
,
101 gfx::BufferUsage usage
) const;
102 void AllocateGpuMemoryBufferForSurfaceOnIO(
103 AllocateGpuMemoryBufferRequest
* request
);
104 void GpuMemoryBufferAllocatedForSurfaceOnIO(
105 AllocateGpuMemoryBufferRequest
* request
,
106 const gfx::GpuMemoryBufferHandle
& handle
);
107 void AllocateGpuMemoryBufferOnIO(gfx::GpuMemoryBufferId id
,
108 const gfx::Size
& size
,
109 gfx::BufferFormat format
,
110 gfx::BufferUsage usage
,
113 bool reused_gpu_process
,
114 const AllocationCallback
& callback
);
115 void GpuMemoryBufferAllocatedOnIO(gfx::GpuMemoryBufferId id
,
119 bool reused_gpu_process
,
120 const AllocationCallback
& callback
,
121 const gfx::GpuMemoryBufferHandle
& handle
);
122 void DestroyGpuMemoryBufferOnIO(gfx::GpuMemoryBufferId id
,
126 uint64_t ClientIdToTracingProcessId(int client_id
) const;
128 const gfx::GpuMemoryBufferType factory_type_
;
129 const std::vector
<GpuMemoryBufferFactory::Configuration
>
130 supported_configurations_
;
131 const int gpu_client_id_
;
132 const uint64_t gpu_client_tracing_id_
;
134 // The GPU process host ID. This should only be accessed on the IO thread.
137 // Stores info about buffers for all clients. This should only be accessed
139 using BufferMap
= base::hash_map
<gfx::GpuMemoryBufferId
, BufferInfo
>;
140 using ClientMap
= base::hash_map
<int, BufferMap
>;
143 DISALLOW_COPY_AND_ASSIGN(BrowserGpuMemoryBufferManager
);
146 } // namespace content
148 #endif // CONTENT_BROWSER_GPU_BROWSER_GPU_MEMORY_BUFFER_MANAGER_H_