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
|
// Copyright (c) 2012 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_CHANNEL_HOST_FACTORY_H_
#define CONTENT_BROWSER_GPU_BROWSER_GPU_CHANNEL_HOST_FACTORY_H_
#include <vector>
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/process/process.h"
#include "base/synchronization/waitable_event.h"
#include "content/common/gpu/client/gpu_channel_host.h"
#include "ipc/ipc_channel_handle.h"
#include "ipc/message_filter.h"
namespace content {
class CONTENT_EXPORT BrowserGpuChannelHostFactory
: public GpuChannelHostFactory {
public:
static void Initialize(bool establish_gpu_channel);
static void Terminate();
static BrowserGpuChannelHostFactory* instance() { return instance_; }
// GpuChannelHostFactory implementation.
virtual bool IsMainThread() OVERRIDE;
virtual base::MessageLoop* GetMainLoop() OVERRIDE;
virtual scoped_refptr<base::MessageLoopProxy> GetIOLoopProxy() OVERRIDE;
virtual scoped_ptr<base::SharedMemory> AllocateSharedMemory(
size_t size) OVERRIDE;
virtual bool CreateViewCommandBuffer(
int32 surface_id,
const GPUCreateCommandBufferConfig& init_params,
int32 route_id) OVERRIDE;
virtual void CreateImage(
gfx::PluginWindowHandle window,
int32 image_id,
const CreateImageCallback& callback) OVERRIDE;
virtual void DeleteImage(int32 image_idu, int32 sync_point) OVERRIDE;
virtual scoped_ptr<gfx::GpuMemoryBuffer> AllocateGpuMemoryBuffer(
size_t width,
size_t height,
unsigned internalformat,
unsigned usage) OVERRIDE;
// Specify a task runner and callback to be used for a set of messages. The
// callback will be set up on the current GpuProcessHost, identified by
// GpuProcessHostId().
virtual void SetHandlerForControlMessages(
const uint32* message_ids,
size_t num_messages,
const base::Callback<void(const IPC::Message&)>& handler,
base::TaskRunner* target_task_runner);
int GpuProcessHostId() { return gpu_host_id_; }
GpuChannelHost* EstablishGpuChannelSync(
CauseForGpuLaunch cause_for_gpu_launch);
void EstablishGpuChannel(CauseForGpuLaunch cause_for_gpu_launch,
const base::Closure& callback);
GpuChannelHost* GetGpuChannel();
int GetGpuChannelId() { return gpu_client_id_; }
// Used to skip GpuChannelHost tests when there can be no GPU process.
static bool CanUseForTesting();
private:
struct CreateRequest {
CreateRequest();
~CreateRequest();
base::WaitableEvent event;
int gpu_host_id;
int32 route_id;
bool succeeded;
};
class EstablishRequest : public base::RefCountedThreadSafe<EstablishRequest> {
public:
explicit EstablishRequest(CauseForGpuLaunch cause,
int gpu_client_id,
int gpu_host_id);
void Wait();
void Cancel();
int gpu_host_id() { return gpu_host_id_; }
IPC::ChannelHandle& channel_handle() { return channel_handle_; }
gpu::GPUInfo gpu_info() { return gpu_info_; }
private:
friend class base::RefCountedThreadSafe<EstablishRequest>;
~EstablishRequest();
void EstablishOnIO();
void OnEstablishedOnIO(const IPC::ChannelHandle& channel_handle,
const gpu::GPUInfo& gpu_info);
void FinishOnIO();
void FinishOnMain();
base::WaitableEvent event_;
CauseForGpuLaunch cause_for_gpu_launch_;
const int gpu_client_id_;
int gpu_host_id_;
bool reused_gpu_process_;
IPC::ChannelHandle channel_handle_;
gpu::GPUInfo gpu_info_;
bool finished_;
scoped_refptr<base::MessageLoopProxy> main_loop_;
};
explicit BrowserGpuChannelHostFactory(bool establish_gpu_channel);
virtual ~BrowserGpuChannelHostFactory();
void GpuChannelEstablished();
void CreateViewCommandBufferOnIO(
CreateRequest* request,
int32 surface_id,
const GPUCreateCommandBufferConfig& init_params);
static void CommandBufferCreatedOnIO(CreateRequest* request, bool succeeded);
void CreateImageOnIO(
gfx::PluginWindowHandle window,
int32 image_id,
const CreateImageCallback& callback);
static void ImageCreatedOnIO(
const CreateImageCallback& callback, const gfx::Size size);
static void OnImageCreated(
const CreateImageCallback& callback, const gfx::Size size);
void DeleteImageOnIO(int32 image_id, int32 sync_point);
static void AddFilterOnIO(int gpu_host_id,
scoped_refptr<IPC::MessageFilter> filter);
const int gpu_client_id_;
scoped_ptr<base::WaitableEvent> shutdown_event_;
scoped_refptr<GpuChannelHost> gpu_channel_;
int gpu_host_id_;
scoped_refptr<EstablishRequest> pending_request_;
std::vector<base::Closure> established_callbacks_;
static BrowserGpuChannelHostFactory* instance_;
DISALLOW_COPY_AND_ASSIGN(BrowserGpuChannelHostFactory);
};
} // namespace content
#endif // CONTENT_BROWSER_GPU_BROWSER_GPU_CHANNEL_HOST_FACTORY_H_
|