Add long running gmail memory benchmark for background tab.
[chromium-blink-merge.git] / content / browser / gpu / browser_gpu_memory_buffer_manager.h
blob6a3d13bb278f9209811d489e2c020d159e16fd10
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 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,
50 int32 surface_id);
52 void AllocateGpuMemoryBufferForChildProcess(
53 const gfx::Size& size,
54 gfx::GpuMemoryBuffer::Format format,
55 gfx::GpuMemoryBuffer::Usage usage,
56 base::ProcessHandle child_process_handle,
57 int child_client_id,
58 const AllocationCallback& callback);
59 void ChildProcessDeletedGpuMemoryBuffer(
60 gfx::GpuMemoryBufferId id,
61 base::ProcessHandle child_process_handle,
62 int child_client_id,
63 uint32 sync_point);
64 void ProcessRemoved(base::ProcessHandle process_handle, int client_id);
66 private:
67 struct BufferInfo {
68 BufferInfo()
69 : type(gfx::EMPTY_BUFFER),
70 format(gfx::GpuMemoryBuffer::RGBA_8888),
71 usage(gfx::GpuMemoryBuffer::MAP),
72 gpu_host_id(0) {}
73 BufferInfo(const gfx::Size& size,
74 gfx::GpuMemoryBufferType type,
75 gfx::GpuMemoryBuffer::Format format,
76 gfx::GpuMemoryBuffer::Usage usage,
77 int gpu_host_id)
78 : size(size),
79 type(type),
80 format(format),
81 usage(usage),
82 gpu_host_id(gpu_host_id) {}
84 gfx::Size size;
85 gfx::GpuMemoryBufferType type;
86 gfx::GpuMemoryBuffer::Format format;
87 gfx::GpuMemoryBuffer::Usage usage;
88 int gpu_host_id;
90 struct AllocateGpuMemoryBufferRequest;
92 scoped_ptr<gfx::GpuMemoryBuffer> AllocateGpuMemoryBufferForSurface(
93 const gfx::Size& size,
94 gfx::GpuMemoryBuffer::Format format,
95 gfx::GpuMemoryBuffer::Usage usage,
96 int32 surface_id);
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,
109 int client_id,
110 int surface_id,
111 bool reused_gpu_process,
112 const AllocationCallback& callback);
113 void GpuMemoryBufferAllocatedOnIO(gfx::GpuMemoryBufferId id,
114 int client_id,
115 int surface_id,
116 int gpu_host_id,
117 bool reused_gpu_process,
118 const AllocationCallback& callback,
119 const gfx::GpuMemoryBufferHandle& handle);
120 void DestroyGpuMemoryBufferOnIO(gfx::GpuMemoryBufferId id,
121 int client_id,
122 uint32 sync_point);
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.
130 int gpu_host_id_;
132 // Stores info about buffers for all clients. This should only be accessed
133 // on the IO thread.
134 using BufferMap = base::hash_map<gfx::GpuMemoryBufferId, BufferInfo>;
135 using ClientMap = base::hash_map<int, BufferMap>;
136 ClientMap clients_;
138 DISALLOW_COPY_AND_ASSIGN(BrowserGpuMemoryBufferManager);
141 } // namespace content
143 #endif // CONTENT_BROWSER_GPU_BROWSER_GPU_MEMORY_BUFFER_MANAGER_H_