OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/common/gpu/gpu_channel_manager.h" | 5 #include "content/common/gpu/gpu_channel_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/location.h" | 12 #include "base/location.h" |
13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
14 #include "base/thread_task_runner_handle.h" | 14 #include "base/thread_task_runner_handle.h" |
15 #include "build/build_config.h" | 15 #include "build/build_config.h" |
16 #include "content/common/gpu/establish_channel_params.h" | |
16 #include "content/common/gpu/gpu_channel.h" | 17 #include "content/common/gpu/gpu_channel.h" |
18 #include "content/common/gpu/gpu_channel_manager_delegate.h" | |
17 #include "content/common/gpu/gpu_memory_buffer_factory.h" | 19 #include "content/common/gpu/gpu_memory_buffer_factory.h" |
18 #include "content/common/gpu/gpu_memory_manager.h" | 20 #include "content/common/gpu/gpu_memory_manager.h" |
19 #include "content/common/gpu/gpu_messages.h" | |
20 #include "content/common/message_router.h" | 21 #include "content/common/message_router.h" |
21 #include "content/public/common/content_switches.h" | 22 #include "content/public/common/content_switches.h" |
23 #include "gpu/command_buffer/common/sync_token.h" | |
22 #include "gpu/command_buffer/common/value_state.h" | 24 #include "gpu/command_buffer/common/value_state.h" |
23 #include "gpu/command_buffer/service/feature_info.h" | 25 #include "gpu/command_buffer/service/feature_info.h" |
24 #include "gpu/command_buffer/service/gpu_switches.h" | 26 #include "gpu/command_buffer/service/gpu_switches.h" |
25 #include "gpu/command_buffer/service/mailbox_manager.h" | 27 #include "gpu/command_buffer/service/mailbox_manager.h" |
26 #include "gpu/command_buffer/service/memory_program_cache.h" | 28 #include "gpu/command_buffer/service/memory_program_cache.h" |
27 #include "gpu/command_buffer/service/shader_translator_cache.h" | 29 #include "gpu/command_buffer/service/shader_translator_cache.h" |
28 #include "gpu/command_buffer/service/sync_point_manager.h" | 30 #include "gpu/command_buffer/service/sync_point_manager.h" |
29 #include "ipc/message_filter.h" | 31 #include "ipc/message_filter.h" |
30 #include "ui/gl/gl_bindings.h" | 32 #include "ui/gl/gl_bindings.h" |
31 #include "ui/gl/gl_share_group.h" | 33 #include "ui/gl/gl_share_group.h" |
32 | 34 |
33 namespace content { | 35 namespace content { |
34 | 36 |
35 namespace { | 37 namespace { |
36 #if defined(OS_ANDROID) | 38 #if defined(OS_ANDROID) |
37 // Amount of time we expect the GPU to stay powered up without being used. | 39 // Amount of time we expect the GPU to stay powered up without being used. |
38 const int kMaxGpuIdleTimeMs = 40; | 40 const int kMaxGpuIdleTimeMs = 40; |
39 // Maximum amount of time we keep pinging the GPU waiting for the client to | 41 // Maximum amount of time we keep pinging the GPU waiting for the client to |
40 // draw. | 42 // draw. |
41 const int kMaxKeepAliveTimeMs = 200; | 43 const int kMaxKeepAliveTimeMs = 200; |
42 #endif | 44 #endif |
43 | 45 |
44 } | 46 } |
45 | 47 |
46 GpuChannelManager::GpuChannelManager( | 48 GpuChannelManager::GpuChannelManager( |
49 GpuChannelManagerDelegate* delegate, | |
47 IPC::SyncChannel* channel, | 50 IPC::SyncChannel* channel, |
48 GpuWatchdog* watchdog, | 51 GpuWatchdog* watchdog, |
49 base::SingleThreadTaskRunner* task_runner, | 52 base::SingleThreadTaskRunner* task_runner, |
50 base::SingleThreadTaskRunner* io_task_runner, | 53 base::SingleThreadTaskRunner* io_task_runner, |
51 base::WaitableEvent* shutdown_event, | 54 base::WaitableEvent* shutdown_event, |
52 gpu::SyncPointManager* sync_point_manager, | 55 gpu::SyncPointManager* sync_point_manager, |
53 GpuMemoryBufferFactory* gpu_memory_buffer_factory) | 56 GpuMemoryBufferFactory* gpu_memory_buffer_factory) |
54 : task_runner_(task_runner), | 57 : task_runner_(task_runner), |
55 io_task_runner_(io_task_runner), | 58 io_task_runner_(io_task_runner), |
59 delegate_(delegate), | |
56 channel_(channel), | 60 channel_(channel), |
57 watchdog_(watchdog), | 61 watchdog_(watchdog), |
58 shutdown_event_(shutdown_event), | 62 shutdown_event_(shutdown_event), |
59 share_group_(new gfx::GLShareGroup), | 63 share_group_(new gfx::GLShareGroup), |
60 mailbox_manager_(gpu::gles2::MailboxManager::Create()), | 64 mailbox_manager_(gpu::gles2::MailboxManager::Create()), |
61 gpu_memory_manager_(this), | 65 gpu_memory_manager_(this), |
62 sync_point_manager_(sync_point_manager), | 66 sync_point_manager_(sync_point_manager), |
63 sync_point_client_waiter_( | 67 sync_point_client_waiter_( |
64 sync_point_manager->CreateSyncPointClientWaiter()), | 68 sync_point_manager->CreateSyncPointClientWaiter()), |
65 gpu_memory_buffer_factory_(gpu_memory_buffer_factory), | 69 gpu_memory_buffer_factory_(gpu_memory_buffer_factory), |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
101 | 105 |
102 gpu::gles2::FramebufferCompletenessCache* | 106 gpu::gles2::FramebufferCompletenessCache* |
103 GpuChannelManager::framebuffer_completeness_cache() { | 107 GpuChannelManager::framebuffer_completeness_cache() { |
104 if (!framebuffer_completeness_cache_.get()) | 108 if (!framebuffer_completeness_cache_.get()) |
105 framebuffer_completeness_cache_ = | 109 framebuffer_completeness_cache_ = |
106 new gpu::gles2::FramebufferCompletenessCache; | 110 new gpu::gles2::FramebufferCompletenessCache; |
107 return framebuffer_completeness_cache_.get(); | 111 return framebuffer_completeness_cache_.get(); |
108 } | 112 } |
109 | 113 |
110 void GpuChannelManager::RemoveChannel(int client_id) { | 114 void GpuChannelManager::RemoveChannel(int client_id) { |
111 Send(new GpuHostMsg_DestroyChannel(client_id)); | 115 delegate_->DestroyChannel(client_id); |
112 gpu_channels_.erase(client_id); | 116 gpu_channels_.erase(client_id); |
113 } | 117 } |
114 | 118 |
115 int GpuChannelManager::GenerateRouteID() { | 119 int GpuChannelManager::GenerateRouteID() { |
116 static int last_id = 0; | 120 static int last_id = 0; |
117 return ++last_id; | 121 return ++last_id; |
118 } | 122 } |
119 | 123 |
120 void GpuChannelManager::AddRoute(int32_t routing_id, IPC::Listener* listener) { | 124 void GpuChannelManager::AddRoute(int32_t routing_id, IPC::Listener* listener) { |
121 router_.AddRoute(routing_id, listener); | 125 router_.AddRoute(routing_id, listener); |
122 } | 126 } |
123 | 127 |
124 void GpuChannelManager::RemoveRoute(int32_t routing_id) { | 128 void GpuChannelManager::RemoveRoute(int32_t routing_id) { |
125 router_.RemoveRoute(routing_id); | 129 router_.RemoveRoute(routing_id); |
126 } | 130 } |
127 | 131 |
128 GpuChannel* GpuChannelManager::LookupChannel(int32_t client_id) const { | 132 GpuChannel* GpuChannelManager::LookupChannel(int32_t client_id) const { |
129 const auto& it = gpu_channels_.find(client_id); | 133 const auto& it = gpu_channels_.find(client_id); |
130 return it != gpu_channels_.end() ? it->second : nullptr; | 134 return it != gpu_channels_.end() ? it->second : nullptr; |
131 } | 135 } |
132 | 136 |
133 bool GpuChannelManager::OnControlMessageReceived(const IPC::Message& msg) { | |
134 bool handled = true; | |
135 IPC_BEGIN_MESSAGE_MAP(GpuChannelManager, msg) | |
136 IPC_MESSAGE_HANDLER(GpuMsg_EstablishChannel, OnEstablishChannel) | |
137 IPC_MESSAGE_HANDLER(GpuMsg_CloseChannel, OnCloseChannel) | |
138 IPC_MESSAGE_HANDLER(GpuMsg_DestroyGpuMemoryBuffer, OnDestroyGpuMemoryBuffer) | |
139 IPC_MESSAGE_HANDLER(GpuMsg_LoadedShader, OnLoadedShader) | |
140 IPC_MESSAGE_HANDLER(GpuMsg_UpdateValueState, OnUpdateValueState) | |
141 #if defined(OS_ANDROID) | |
142 IPC_MESSAGE_HANDLER(GpuMsg_WakeUpGpu, OnWakeUpGpu); | |
143 #endif | |
144 IPC_MESSAGE_UNHANDLED(handled = false) | |
145 IPC_END_MESSAGE_MAP() | |
146 return handled; | |
147 } | |
148 | |
149 bool GpuChannelManager::OnMessageReceived(const IPC::Message& msg) { | 137 bool GpuChannelManager::OnMessageReceived(const IPC::Message& msg) { |
150 if (msg.routing_id() == MSG_ROUTING_CONTROL) | 138 DCHECK_NE(MSG_ROUTING_CONTROL, msg.routing_id()); |
151 return OnControlMessageReceived(msg); | |
152 | |
153 return router_.RouteMessage(msg); | 139 return router_.RouteMessage(msg); |
154 } | 140 } |
155 | 141 |
156 bool GpuChannelManager::Send(IPC::Message* msg) { | |
157 return channel_->Send(msg); | |
158 } | |
159 | |
160 scoped_ptr<GpuChannel> GpuChannelManager::CreateGpuChannel( | 142 scoped_ptr<GpuChannel> GpuChannelManager::CreateGpuChannel( |
161 int client_id, | 143 int client_id, |
162 uint64_t client_tracing_id, | 144 uint64_t client_tracing_id, |
163 bool preempts, | 145 bool preempts, |
164 bool allow_view_command_buffers, | 146 bool allow_view_command_buffers, |
165 bool allow_real_time_streams) { | 147 bool allow_real_time_streams) { |
166 return make_scoped_ptr(new GpuChannel( | 148 return make_scoped_ptr(new GpuChannel( |
167 this, sync_point_manager(), watchdog_, share_group(), mailbox_manager(), | 149 this, sync_point_manager(), watchdog_, share_group(), mailbox_manager(), |
168 preempts ? preemption_flag() : nullptr, task_runner_.get(), | 150 preempts ? preemption_flag() : nullptr, task_runner_.get(), |
169 io_task_runner_.get(), client_id, client_tracing_id, | 151 io_task_runner_.get(), client_id, client_tracing_id, |
170 allow_view_command_buffers, allow_real_time_streams)); | 152 allow_view_command_buffers, allow_real_time_streams)); |
171 } | 153 } |
172 | 154 |
173 void GpuChannelManager::OnEstablishChannel( | 155 void GpuChannelManager::EstablishChannel(const EstablishChannelParams& params) { |
174 const GpuMsg_EstablishChannel_Params& params) { | |
175 scoped_ptr<GpuChannel> channel(CreateGpuChannel( | 156 scoped_ptr<GpuChannel> channel(CreateGpuChannel( |
176 params.client_id, params.client_tracing_id, params.preempts, | 157 params.client_id, params.client_tracing_id, params.preempts, |
177 params.allow_view_command_buffers, params.allow_real_time_streams)); | 158 params.allow_view_command_buffers, params.allow_real_time_streams)); |
178 if (!params.preempts) | 159 if (!params.preempts) |
179 channel->SetPreemptByFlag(preemption_flag_.get()); | 160 channel->SetPreemptByFlag(preemption_flag_.get()); |
180 IPC::ChannelHandle channel_handle = channel->Init(shutdown_event_); | 161 IPC::ChannelHandle channel_handle = channel->Init(shutdown_event_); |
181 | 162 |
182 gpu_channels_.set(params.client_id, std::move(channel)); | 163 gpu_channels_.set(params.client_id, std::move(channel)); |
183 | 164 |
184 Send(new GpuHostMsg_ChannelEstablished(channel_handle)); | 165 delegate_->ChannelEstablished(channel_handle); |
185 } | 166 } |
186 | 167 |
187 void GpuChannelManager::OnCloseChannel( | 168 void GpuChannelManager::CloseChannel(const IPC::ChannelHandle& channel_handle) { |
188 const IPC::ChannelHandle& channel_handle) { | |
189 for (auto it = gpu_channels_.begin(); it != gpu_channels_.end(); ++it) { | 169 for (auto it = gpu_channels_.begin(); it != gpu_channels_.end(); ++it) { |
190 if (it->second->channel_id() == channel_handle.name) { | 170 if (it->second->channel_id() == channel_handle.name) { |
191 gpu_channels_.erase(it); | 171 gpu_channels_.erase(it); |
192 return; | 172 return; |
193 } | 173 } |
194 } | 174 } |
195 } | 175 } |
196 | 176 |
197 void GpuChannelManager::DestroyGpuMemoryBuffer( | 177 void GpuChannelManager::InternalDestroyGpuMemoryBuffer( |
198 gfx::GpuMemoryBufferId id, | 178 gfx::GpuMemoryBufferId id, |
199 int client_id) { | 179 int client_id) { |
200 io_task_runner_->PostTask( | 180 io_task_runner_->PostTask( |
201 FROM_HERE, base::Bind(&GpuChannelManager::DestroyGpuMemoryBufferOnIO, | 181 FROM_HERE, |
202 base::Unretained(this), id, client_id)); | 182 base::Bind(&GpuChannelManager::InternalDestroyGpuMemoryBufferOnIO, |
183 base::Unretained(this), id, client_id)); | |
203 } | 184 } |
204 | 185 |
205 void GpuChannelManager::DestroyGpuMemoryBufferOnIO( | 186 void GpuChannelManager::InternalDestroyGpuMemoryBufferOnIO( |
206 gfx::GpuMemoryBufferId id, | 187 gfx::GpuMemoryBufferId id, |
207 int client_id) { | 188 int client_id) { |
208 gpu_memory_buffer_factory_->DestroyGpuMemoryBuffer(id, client_id); | 189 gpu_memory_buffer_factory_->DestroyGpuMemoryBuffer(id, client_id); |
209 } | 190 } |
210 | 191 |
211 void GpuChannelManager::OnDestroyGpuMemoryBuffer( | 192 void GpuChannelManager::DestroyGpuMemoryBuffer( |
212 gfx::GpuMemoryBufferId id, | 193 gfx::GpuMemoryBufferId id, |
213 int client_id, | 194 int client_id, |
214 const gpu::SyncToken& sync_token) { | 195 const gpu::SyncToken& sync_token) { |
215 if (sync_token.HasData()) { | 196 if (sync_token.HasData()) { |
216 scoped_refptr<gpu::SyncPointClientState> release_state = | 197 scoped_refptr<gpu::SyncPointClientState> release_state = |
217 sync_point_manager()->GetSyncPointClientState( | 198 sync_point_manager()->GetSyncPointClientState( |
218 sync_token.namespace_id(), sync_token.command_buffer_id()); | 199 sync_token.namespace_id(), sync_token.command_buffer_id()); |
219 if (release_state) { | 200 if (release_state) { |
220 sync_point_client_waiter_->WaitOutOfOrder( | 201 sync_point_client_waiter_->WaitOutOfOrder( |
221 release_state.get(), sync_token.release_count(), | 202 release_state.get(), sync_token.release_count(), |
222 base::Bind(&GpuChannelManager::DestroyGpuMemoryBuffer, | 203 base::Bind(&GpuChannelManager::InternalDestroyGpuMemoryBuffer, |
223 base::Unretained(this), id, client_id)); | 204 base::Unretained(this), id, client_id)); |
224 return; | 205 return; |
225 } | 206 } |
226 } | 207 } |
227 | 208 |
228 // No sync token or invalid sync token, destroy immediately. | 209 // No sync token or invalid sync token, destroy immediately. |
229 DestroyGpuMemoryBuffer(id, client_id); | 210 InternalDestroyGpuMemoryBuffer(id, client_id); |
230 } | 211 } |
231 | 212 |
232 void GpuChannelManager::OnUpdateValueState( | 213 void GpuChannelManager::UpdateValueState(int client_id, |
233 int client_id, unsigned int target, const gpu::ValueState& state) { | 214 unsigned int target, |
215 const gpu::ValueState& state) { | |
234 // Only pass updated state to the channel corresponding to the | 216 // Only pass updated state to the channel corresponding to the |
235 // render_widget_host where the event originated. | 217 // render_widget_host where the event originated. |
236 auto it = gpu_channels_.find(client_id); | 218 auto it = gpu_channels_.find(client_id); |
237 if (it != gpu_channels_.end()) | 219 if (it != gpu_channels_.end()) |
238 it->second->HandleUpdateValueState(target, state); | 220 it->second->HandleUpdateValueState(target, state); |
239 } | 221 } |
240 | 222 |
241 void GpuChannelManager::OnLoadedShader(const std::string& program_proto) { | 223 void GpuChannelManager::LoadedShader(const std::string& program_proto) { |
no sievers
2016/02/19 00:19:24
nit: PopulateShaderCache(), CacheShaderProgram() m
Fady Samuel
2016/02/19 01:13:10
Done.
| |
242 if (program_cache()) | 224 if (program_cache()) |
243 program_cache()->LoadProgram(program_proto); | 225 program_cache()->LoadProgram(program_proto); |
244 } | 226 } |
245 | 227 |
246 uint32_t GpuChannelManager::GetUnprocessedOrderNum() const { | 228 uint32_t GpuChannelManager::GetUnprocessedOrderNum() const { |
247 uint32_t unprocessed_order_num = 0; | 229 uint32_t unprocessed_order_num = 0; |
248 for (auto& kv : gpu_channels_) { | 230 for (auto& kv : gpu_channels_) { |
249 unprocessed_order_num = | 231 unprocessed_order_num = |
250 std::max(unprocessed_order_num, kv.second->GetUnprocessedOrderNum()); | 232 std::max(unprocessed_order_num, kv.second->GetUnprocessedOrderNum()); |
251 } | 233 } |
252 return unprocessed_order_num; | 234 return unprocessed_order_num; |
253 } | 235 } |
254 | 236 |
255 uint32_t GpuChannelManager::GetProcessedOrderNum() const { | 237 uint32_t GpuChannelManager::GetProcessedOrderNum() const { |
256 uint32_t processed_order_num = 0; | 238 uint32_t processed_order_num = 0; |
257 for (auto& kv : gpu_channels_) { | 239 for (auto& kv : gpu_channels_) { |
258 processed_order_num = | 240 processed_order_num = |
259 std::max(processed_order_num, kv.second->GetProcessedOrderNum()); | 241 std::max(processed_order_num, kv.second->GetProcessedOrderNum()); |
260 } | 242 } |
261 return processed_order_num; | 243 return processed_order_num; |
262 } | 244 } |
263 | 245 |
264 void GpuChannelManager::LoseAllContexts() { | 246 void GpuChannelManager::LoseAllContexts() { |
265 for (auto& kv : gpu_channels_) { | 247 for (auto& kv : gpu_channels_) { |
266 kv.second->MarkAllContextsLost(); | 248 kv.second->MarkAllContextsLost(); |
267 } | 249 } |
268 task_runner_->PostTask(FROM_HERE, | 250 task_runner_->PostTask(FROM_HERE, |
269 base::Bind(&GpuChannelManager::OnLoseAllContexts, | 251 base::Bind(&GpuChannelManager::ClearAllChannels, |
270 weak_factory_.GetWeakPtr())); | 252 weak_factory_.GetWeakPtr())); |
271 } | 253 } |
272 | 254 |
273 void GpuChannelManager::OnLoseAllContexts() { | 255 void GpuChannelManager::ClearAllChannels() { |
no sievers
2016/02/19 00:19:24
nit: DestroyAllChannels?
Fady Samuel
2016/02/19 01:13:10
Done.
| |
274 gpu_channels_.clear(); | 256 gpu_channels_.clear(); |
275 } | 257 } |
276 | 258 |
277 gfx::GLSurface* GpuChannelManager::GetDefaultOffscreenSurface() { | 259 gfx::GLSurface* GpuChannelManager::GetDefaultOffscreenSurface() { |
278 if (!default_offscreen_surface_.get()) { | 260 if (!default_offscreen_surface_.get()) { |
279 default_offscreen_surface_ = | 261 default_offscreen_surface_ = |
280 gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size()); | 262 gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size()); |
281 } | 263 } |
282 return default_offscreen_surface_.get(); | 264 return default_offscreen_surface_.get(); |
283 } | 265 } |
284 | 266 |
285 #if defined(OS_ANDROID) | 267 #if defined(OS_ANDROID) |
286 void GpuChannelManager::DidAccessGpu() { | 268 void GpuChannelManager::DidAccessGpu() { |
287 last_gpu_access_time_ = base::TimeTicks::Now(); | 269 last_gpu_access_time_ = base::TimeTicks::Now(); |
288 } | 270 } |
289 | 271 |
290 void GpuChannelManager::OnWakeUpGpu() { | 272 void GpuChannelManager::WakeUpGpu() { |
291 begin_wake_up_time_ = base::TimeTicks::Now(); | 273 begin_wake_up_time_ = base::TimeTicks::Now(); |
292 ScheduleWakeUpGpu(); | 274 ScheduleWakeUpGpu(); |
293 } | 275 } |
294 | 276 |
295 void GpuChannelManager::ScheduleWakeUpGpu() { | 277 void GpuChannelManager::ScheduleWakeUpGpu() { |
296 base::TimeTicks now = base::TimeTicks::Now(); | 278 base::TimeTicks now = base::TimeTicks::Now(); |
297 TRACE_EVENT2("gpu", "GpuChannelManager::ScheduleWakeUp", | 279 TRACE_EVENT2("gpu", "GpuChannelManager::ScheduleWakeUp", |
298 "idle_time", (now - last_gpu_access_time_).InMilliseconds(), | 280 "idle_time", (now - last_gpu_access_time_).InMilliseconds(), |
299 "keep_awake_time", (now - begin_wake_up_time_).InMilliseconds()); | 281 "keep_awake_time", (now - begin_wake_up_time_).InMilliseconds()); |
300 if (now - last_gpu_access_time_ < | 282 if (now - last_gpu_access_time_ < |
(...skipping 22 matching lines...) Expand all Loading... | |
323 } | 305 } |
324 } | 306 } |
325 if (!stub || !stub->decoder()->MakeCurrent()) | 307 if (!stub || !stub->decoder()->MakeCurrent()) |
326 return; | 308 return; |
327 glFinish(); | 309 glFinish(); |
328 DidAccessGpu(); | 310 DidAccessGpu(); |
329 } | 311 } |
330 #endif | 312 #endif |
331 | 313 |
332 } // namespace content | 314 } // namespace content |
OLD | NEW |