Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / content / browser / gpu / browser_gpu_memory_buffer_manager.h
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.
4
5 #ifndef CONTENT_BROWSER_GPU_BROWSER_GPU_MEMORY_BUFFER_MANAGER_H_
6 #define CONTENT_BROWSER_GPU_BROWSER_GPU_MEMORY_BUFFER_MANAGER_H_
7
8 #include "base/callback.h"
9 #include "content/common/content_export.h"
10 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h"
11
12 namespace content {
13 class GpuMemoryBufferImpl;
14
15 class CONTENT_EXPORT BrowserGpuMemoryBufferManager
16     : public gpu::GpuMemoryBufferManager {
17  public:
18   typedef base::Callback<void(const gfx::GpuMemoryBufferHandle& handle)>
19       AllocationCallback;
20
21   explicit BrowserGpuMemoryBufferManager(int gpu_client_id);
22   ~BrowserGpuMemoryBufferManager() override;
23
24   static BrowserGpuMemoryBufferManager* current();
25
26   // Overridden from gpu::GpuMemoryBufferManager:
27   scoped_ptr<gfx::GpuMemoryBuffer> AllocateGpuMemoryBuffer(
28       const gfx::Size& size,
29       gfx::GpuMemoryBuffer::Format format,
30       gfx::GpuMemoryBuffer::Usage usage) override;
31   gfx::GpuMemoryBuffer* GpuMemoryBufferFromClientBuffer(
32       ClientBuffer buffer) override;
33   void SetDestructionSyncPoint(gfx::GpuMemoryBuffer* buffer,
34                                uint32 sync_point) override;
35
36   void AllocateGpuMemoryBufferForChildProcess(
37       const gfx::Size& size,
38       gfx::GpuMemoryBuffer::Format format,
39       gfx::GpuMemoryBuffer::Usage usage,
40       base::ProcessHandle child_process_handle,
41       int child_client_id,
42       const AllocationCallback& callback);
43   void ChildProcessDeletedGpuMemoryBuffer(
44       gfx::GpuMemoryBufferId id,
45       base::ProcessHandle child_process_handle,
46       int child_client_id,
47       uint32 sync_point);
48   void ProcessRemoved(base::ProcessHandle process_handle, int client_id);
49
50  private:
51   struct AllocateGpuMemoryBufferRequest;
52
53   void GpuMemoryBufferAllocatedForChildProcess(
54       base::ProcessHandle child_process_handle,
55       int child_client_id,
56       const AllocationCallback& callback,
57       const gfx::GpuMemoryBufferHandle& handle);
58
59   static void AllocateGpuMemoryBufferOnIO(
60       AllocateGpuMemoryBufferRequest* request);
61   static void GpuMemoryBufferCreatedOnIO(
62       AllocateGpuMemoryBufferRequest* request,
63       scoped_ptr<GpuMemoryBufferImpl> buffer);
64
65   int gpu_client_id_;
66
67   typedef base::hash_map<gfx::GpuMemoryBufferId, gfx::GpuMemoryBufferType>
68       BufferMap;
69   typedef base::hash_map<int, BufferMap> ClientMap;
70   ClientMap clients_;
71
72   DISALLOW_COPY_AND_ASSIGN(BrowserGpuMemoryBufferManager);
73 };
74
75 }  // namespace content
76
77 #endif  // CONTENT_BROWSER_GPU_BROWSER_GPU_MEMORY_BUFFER_MANAGER_H_