Make USB permissions work in the new permission message system
[chromium-blink-merge.git] / content / browser / gpu / browser_gpu_memory_buffer_manager.h
blob12fd082975a2c4672bdc262dde2c593f967017bb
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 <vector>
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"
16 namespace content {
18 class CONTENT_EXPORT BrowserGpuMemoryBufferManager
19 : public gpu::GpuMemoryBufferManager,
20 public base::trace_event::MemoryDumpProvider {
21 public:
22 typedef base::Callback<void(const gfx::GpuMemoryBufferHandle& handle)>
23 AllocationCallback;
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,
52 int32 surface_id);
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,
60 int child_client_id,
61 const AllocationCallback& callback);
62 void ChildProcessDeletedGpuMemoryBuffer(
63 gfx::GpuMemoryBufferId id,
64 base::ProcessHandle child_process_handle,
65 int child_client_id,
66 uint32 sync_point);
67 void ProcessRemoved(base::ProcessHandle process_handle, int client_id);
69 private:
70 struct BufferInfo {
71 BufferInfo()
72 : type(gfx::EMPTY_BUFFER),
73 format(gfx::BufferFormat::RGBA_8888),
74 usage(gfx::BufferUsage::MAP),
75 gpu_host_id(0) {}
76 BufferInfo(const gfx::Size& size,
77 gfx::GpuMemoryBufferType type,
78 gfx::BufferFormat format,
79 gfx::BufferUsage usage,
80 int gpu_host_id)
81 : size(size),
82 type(type),
83 format(format),
84 usage(usage),
85 gpu_host_id(gpu_host_id) {}
87 gfx::Size size;
88 gfx::GpuMemoryBufferType type;
89 gfx::BufferFormat format;
90 gfx::BufferUsage usage;
91 int gpu_host_id;
93 struct AllocateGpuMemoryBufferRequest;
95 scoped_ptr<gfx::GpuMemoryBuffer> AllocateGpuMemoryBufferForSurface(
96 const gfx::Size& size,
97 gfx::BufferFormat format,
98 gfx::BufferUsage usage,
99 int32 surface_id);
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,
111 int client_id,
112 int surface_id,
113 bool reused_gpu_process,
114 const AllocationCallback& callback);
115 void GpuMemoryBufferAllocatedOnIO(gfx::GpuMemoryBufferId id,
116 int client_id,
117 int surface_id,
118 int gpu_host_id,
119 bool reused_gpu_process,
120 const AllocationCallback& callback,
121 const gfx::GpuMemoryBufferHandle& handle);
122 void DestroyGpuMemoryBufferOnIO(gfx::GpuMemoryBufferId id,
123 int client_id,
124 uint32 sync_point);
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.
135 int gpu_host_id_;
137 // Stores info about buffers for all clients. This should only be accessed
138 // on the IO thread.
139 using BufferMap = base::hash_map<gfx::GpuMemoryBufferId, BufferInfo>;
140 using ClientMap = base::hash_map<int, BufferMap>;
141 ClientMap clients_;
143 DISALLOW_COPY_AND_ASSIGN(BrowserGpuMemoryBufferManager);
146 } // namespace content
148 #endif // CONTENT_BROWSER_GPU_BROWSER_GPU_MEMORY_BUFFER_MANAGER_H_