1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_BROWSER_GPU_BROWSER_GPU_MEMORY_BUFFER_MANAGER_H_
#define CONTENT_BROWSER_GPU_BROWSER_GPU_MEMORY_BUFFER_MANAGER_H_
#include <vector>
#include "base/callback.h"
#include "base/trace_event/memory_dump_provider.h"
#include "content/common/content_export.h"
#include "content/common/gpu/gpu_memory_buffer_factory.h"
#include "gpu/command_buffer/client/gpu_memory_buffer_manager.h"
namespace content {
class CONTENT_EXPORT BrowserGpuMemoryBufferManager
: public gpu::GpuMemoryBufferManager,
public base::trace_event::MemoryDumpProvider {
public:
typedef base::Callback<void(const gfx::GpuMemoryBufferHandle& handle)>
AllocationCallback;
BrowserGpuMemoryBufferManager(int gpu_client_id,
uint64_t gpu_client_tracing_id);
~BrowserGpuMemoryBufferManager() override;
static BrowserGpuMemoryBufferManager* current();
static uint32 GetImageTextureTarget(gfx::BufferFormat format,
gfx::BufferUsage usage);
// Overridden from gpu::GpuMemoryBufferManager:
scoped_ptr<gfx::GpuMemoryBuffer> AllocateGpuMemoryBuffer(
const gfx::Size& size,
gfx::BufferFormat format,
gfx::BufferUsage usage) override;
gfx::GpuMemoryBuffer* GpuMemoryBufferFromClientBuffer(
ClientBuffer buffer) override;
void SetDestructionSyncPoint(gfx::GpuMemoryBuffer* buffer,
uint32 sync_point) override;
// Overridden from base::trace_event::MemoryDumpProvider:
bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args,
base::trace_event::ProcessMemoryDump* pmd) override;
// Virtual for testing.
virtual scoped_ptr<gfx::GpuMemoryBuffer> AllocateGpuMemoryBufferForScanout(
const gfx::Size& size,
gfx::BufferFormat format,
int32 surface_id);
void AllocateGpuMemoryBufferForChildProcess(
gfx::GpuMemoryBufferId id,
const gfx::Size& size,
gfx::BufferFormat format,
gfx::BufferUsage usage,
base::ProcessHandle child_process_handle,
int child_client_id,
const AllocationCallback& callback);
void ChildProcessDeletedGpuMemoryBuffer(
gfx::GpuMemoryBufferId id,
base::ProcessHandle child_process_handle,
int child_client_id,
uint32 sync_point);
void ProcessRemoved(base::ProcessHandle process_handle, int client_id);
private:
struct BufferInfo {
BufferInfo()
: type(gfx::EMPTY_BUFFER),
format(gfx::BufferFormat::RGBA_8888),
usage(gfx::BufferUsage::MAP),
gpu_host_id(0) {}
BufferInfo(const gfx::Size& size,
gfx::GpuMemoryBufferType type,
gfx::BufferFormat format,
gfx::BufferUsage usage,
int gpu_host_id)
: size(size),
type(type),
format(format),
usage(usage),
gpu_host_id(gpu_host_id) {}
gfx::Size size;
gfx::GpuMemoryBufferType type;
gfx::BufferFormat format;
gfx::BufferUsage usage;
int gpu_host_id;
};
struct AllocateGpuMemoryBufferRequest;
scoped_ptr<gfx::GpuMemoryBuffer> AllocateGpuMemoryBufferForSurface(
const gfx::Size& size,
gfx::BufferFormat format,
gfx::BufferUsage usage,
int32 surface_id);
bool IsGpuMemoryBufferConfigurationSupported(gfx::BufferFormat format,
gfx::BufferUsage usage) const;
void AllocateGpuMemoryBufferForSurfaceOnIO(
AllocateGpuMemoryBufferRequest* request);
void GpuMemoryBufferAllocatedForSurfaceOnIO(
AllocateGpuMemoryBufferRequest* request,
const gfx::GpuMemoryBufferHandle& handle);
void AllocateGpuMemoryBufferOnIO(gfx::GpuMemoryBufferId id,
const gfx::Size& size,
gfx::BufferFormat format,
gfx::BufferUsage usage,
int client_id,
int surface_id,
bool reused_gpu_process,
const AllocationCallback& callback);
void GpuMemoryBufferAllocatedOnIO(gfx::GpuMemoryBufferId id,
int client_id,
int surface_id,
int gpu_host_id,
bool reused_gpu_process,
const AllocationCallback& callback,
const gfx::GpuMemoryBufferHandle& handle);
void DestroyGpuMemoryBufferOnIO(gfx::GpuMemoryBufferId id,
int client_id,
uint32 sync_point);
uint64_t ClientIdToTracingProcessId(int client_id) const;
const gfx::GpuMemoryBufferType factory_type_;
const std::vector<GpuMemoryBufferFactory::Configuration>
supported_configurations_;
const int gpu_client_id_;
const uint64_t gpu_client_tracing_id_;
// The GPU process host ID. This should only be accessed on the IO thread.
int gpu_host_id_;
// Stores info about buffers for all clients. This should only be accessed
// on the IO thread.
using BufferMap = base::hash_map<gfx::GpuMemoryBufferId, BufferInfo>;
using ClientMap = base::hash_map<int, BufferMap>;
ClientMap clients_;
DISALLOW_COPY_AND_ASSIGN(BrowserGpuMemoryBufferManager);
};
} // namespace content
#endif // CONTENT_BROWSER_GPU_BROWSER_GPU_MEMORY_BUFFER_MANAGER_H_
|