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_
8 #include "base/callback.h"
9 #include "base/memory/weak_ptr.h"
10 #include "content/common/content_export.h"
11 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h"
14 class GpuMemoryBufferFactoryHost
;
15 class GpuMemoryBufferImpl
;
17 class CONTENT_EXPORT BrowserGpuMemoryBufferManager
18 : public gpu::GpuMemoryBufferManager
{
20 typedef base::Callback
<void(const gfx::GpuMemoryBufferHandle
& handle
)>
23 BrowserGpuMemoryBufferManager(
24 GpuMemoryBufferFactoryHost
* gpu_memory_buffer_factory_host
,
26 ~BrowserGpuMemoryBufferManager() override
;
28 static BrowserGpuMemoryBufferManager
* current();
30 // Overridden from gpu::GpuMemoryBufferManager:
31 scoped_ptr
<gfx::GpuMemoryBuffer
> AllocateGpuMemoryBuffer(
32 const gfx::Size
& size
,
33 gfx::GpuMemoryBuffer::Format format
,
34 gfx::GpuMemoryBuffer::Usage usage
) override
;
35 gfx::GpuMemoryBuffer
* GpuMemoryBufferFromClientBuffer(
36 ClientBuffer buffer
) override
;
37 void SetDestructionSyncPoint(gfx::GpuMemoryBuffer
* buffer
,
38 uint32 sync_point
) override
;
40 // Virtual for testing.
41 virtual scoped_ptr
<gfx::GpuMemoryBuffer
> AllocateGpuMemoryBufferForScanout(
42 const gfx::Size
& size
,
43 gfx::GpuMemoryBuffer::Format format
,
45 void AllocateGpuMemoryBufferForChildProcess(
46 const gfx::Size
& size
,
47 gfx::GpuMemoryBuffer::Format format
,
48 gfx::GpuMemoryBuffer::Usage usage
,
49 base::ProcessHandle child_process_handle
,
51 const AllocationCallback
& callback
);
52 void ChildProcessDeletedGpuMemoryBuffer(
53 gfx::GpuMemoryBufferId id
,
54 base::ProcessHandle child_process_handle
,
57 void ProcessRemoved(base::ProcessHandle process_handle
, int client_id
);
60 struct AllocateGpuMemoryBufferRequest
;
62 scoped_ptr
<gfx::GpuMemoryBuffer
> AllocateGpuMemoryBufferCommon(
63 const gfx::Size
& size
,
64 gfx::GpuMemoryBuffer::Format format
,
65 gfx::GpuMemoryBuffer::Usage usage
,
67 void AllocateGpuMemoryBufferOnIO(AllocateGpuMemoryBufferRequest
* request
);
68 void GpuMemoryBufferAllocatedOnIO(AllocateGpuMemoryBufferRequest
* request
,
69 const gfx::GpuMemoryBufferHandle
& handle
);
70 void GpuMemoryBufferDeleted(gfx::GpuMemoryBufferId id
,
73 void GpuMemoryBufferAllocatedForChildProcess(
75 const AllocationCallback
& callback
,
76 const gfx::GpuMemoryBufferHandle
& handle
);
78 GpuMemoryBufferFactoryHost
* gpu_memory_buffer_factory_host_
;
81 typedef base::hash_map
<gfx::GpuMemoryBufferId
, gfx::GpuMemoryBufferType
>
83 typedef base::hash_map
<int, BufferMap
> ClientMap
;
86 base::WeakPtrFactory
<BrowserGpuMemoryBufferManager
> weak_ptr_factory_
;
88 DISALLOW_COPY_AND_ASSIGN(BrowserGpuMemoryBufferManager
);
91 } // namespace content
93 #endif // CONTENT_BROWSER_GPU_BROWSER_GPU_MEMORY_BUFFER_MANAGER_H_