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 explicit BrowserGpuMemoryBufferManager(int gpu_client_id
);
26 ~BrowserGpuMemoryBufferManager() override
;
28 static BrowserGpuMemoryBufferManager
* current();
30 static uint32
GetImageTextureTarget(gfx::GpuMemoryBuffer::Format format
,
31 gfx::GpuMemoryBuffer::Usage usage
);
33 // Overridden from gpu::GpuMemoryBufferManager:
34 scoped_ptr
<gfx::GpuMemoryBuffer
> AllocateGpuMemoryBuffer(
35 const gfx::Size
& size
,
36 gfx::GpuMemoryBuffer::Format format
,
37 gfx::GpuMemoryBuffer::Usage usage
) override
;
38 gfx::GpuMemoryBuffer
* GpuMemoryBufferFromClientBuffer(
39 ClientBuffer buffer
) override
;
40 void SetDestructionSyncPoint(gfx::GpuMemoryBuffer
* buffer
,
41 uint32 sync_point
) override
;
43 // Overridden from base::trace_event::MemoryDumpProvider:
44 bool OnMemoryDump(base::trace_event::ProcessMemoryDump
* pmd
) override
;
46 // Virtual for testing.
47 virtual scoped_ptr
<gfx::GpuMemoryBuffer
> AllocateGpuMemoryBufferForScanout(
48 const gfx::Size
& size
,
49 gfx::GpuMemoryBuffer::Format format
,
52 void AllocateGpuMemoryBufferForChildProcess(
53 const gfx::Size
& size
,
54 gfx::GpuMemoryBuffer::Format format
,
55 gfx::GpuMemoryBuffer::Usage usage
,
56 base::ProcessHandle child_process_handle
,
58 const AllocationCallback
& callback
);
59 void ChildProcessDeletedGpuMemoryBuffer(
60 gfx::GpuMemoryBufferId id
,
61 base::ProcessHandle child_process_handle
,
64 void ProcessRemoved(base::ProcessHandle process_handle
, int client_id
);
69 : type(gfx::EMPTY_BUFFER
),
70 format(gfx::GpuMemoryBuffer::RGBA_8888
),
71 usage(gfx::GpuMemoryBuffer::MAP
),
73 BufferInfo(const gfx::Size
& size
,
74 gfx::GpuMemoryBufferType type
,
75 gfx::GpuMemoryBuffer::Format format
,
76 gfx::GpuMemoryBuffer::Usage usage
,
82 gpu_host_id(gpu_host_id
) {}
85 gfx::GpuMemoryBufferType type
;
86 gfx::GpuMemoryBuffer::Format format
;
87 gfx::GpuMemoryBuffer::Usage usage
;
90 struct AllocateGpuMemoryBufferRequest
;
92 scoped_ptr
<gfx::GpuMemoryBuffer
> AllocateGpuMemoryBufferForSurface(
93 const gfx::Size
& size
,
94 gfx::GpuMemoryBuffer::Format format
,
95 gfx::GpuMemoryBuffer::Usage usage
,
97 bool IsGpuMemoryBufferConfigurationSupported(
98 gfx::GpuMemoryBuffer::Format format
,
99 gfx::GpuMemoryBuffer::Usage usage
) const;
100 void AllocateGpuMemoryBufferForSurfaceOnIO(
101 AllocateGpuMemoryBufferRequest
* request
);
102 void GpuMemoryBufferAllocatedForSurfaceOnIO(
103 AllocateGpuMemoryBufferRequest
* request
,
104 const gfx::GpuMemoryBufferHandle
& handle
);
105 void AllocateGpuMemoryBufferOnIO(gfx::GpuMemoryBufferId id
,
106 const gfx::Size
& size
,
107 gfx::GpuMemoryBuffer::Format format
,
108 gfx::GpuMemoryBuffer::Usage usage
,
111 bool reused_gpu_process
,
112 const AllocationCallback
& callback
);
113 void GpuMemoryBufferAllocatedOnIO(gfx::GpuMemoryBufferId id
,
117 bool reused_gpu_process
,
118 const AllocationCallback
& callback
,
119 const gfx::GpuMemoryBufferHandle
& handle
);
120 void DestroyGpuMemoryBufferOnIO(gfx::GpuMemoryBufferId id
,
124 const gfx::GpuMemoryBufferType factory_type_
;
125 const std::vector
<GpuMemoryBufferFactory::Configuration
>
126 supported_configurations_
;
127 const int gpu_client_id_
;
129 // The GPU process host ID. This should only be accessed on the IO thread.
132 // Stores info about buffers for all clients. This should only be accessed
134 using BufferMap
= base::hash_map
<gfx::GpuMemoryBufferId
, BufferInfo
>;
135 using ClientMap
= base::hash_map
<int, BufferMap
>;
138 DISALLOW_COPY_AND_ASSIGN(BrowserGpuMemoryBufferManager
);
141 } // namespace content
143 #endif // CONTENT_BROWSER_GPU_BROWSER_GPU_MEMORY_BUFFER_MANAGER_H_