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" | 21 #include "content/common/gpu/gpu_messages.h" |
22 #include "content/common/gpu/image_transport_surface.h" | |
20 #include "content/public/common/content_switches.h" | 23 #include "content/public/common/content_switches.h" |
24 #include "gpu/command_buffer/common/sync_token.h" | |
21 #include "gpu/command_buffer/common/value_state.h" | 25 #include "gpu/command_buffer/common/value_state.h" |
22 #include "gpu/command_buffer/service/feature_info.h" | 26 #include "gpu/command_buffer/service/feature_info.h" |
23 #include "gpu/command_buffer/service/gpu_switches.h" | 27 #include "gpu/command_buffer/service/gpu_switches.h" |
24 #include "gpu/command_buffer/service/mailbox_manager.h" | 28 #include "gpu/command_buffer/service/mailbox_manager.h" |
25 #include "gpu/command_buffer/service/memory_program_cache.h" | 29 #include "gpu/command_buffer/service/memory_program_cache.h" |
26 #include "gpu/command_buffer/service/shader_translator_cache.h" | 30 #include "gpu/command_buffer/service/shader_translator_cache.h" |
27 #include "gpu/command_buffer/service/sync_point_manager.h" | 31 #include "gpu/command_buffer/service/sync_point_manager.h" |
28 #include "ipc/message_filter.h" | 32 #include "ipc/message_filter.h" |
29 #include "ipc/message_router.h" | 33 #include "ipc/message_router.h" |
30 #include "ui/gl/gl_bindings.h" | 34 #include "ui/gl/gl_bindings.h" |
31 #include "ui/gl/gl_share_group.h" | 35 #include "ui/gl/gl_share_group.h" |
32 | 36 |
33 namespace content { | 37 namespace content { |
34 | 38 |
35 namespace { | 39 namespace { |
36 #if defined(OS_ANDROID) | 40 #if defined(OS_ANDROID) |
37 // Amount of time we expect the GPU to stay powered up without being used. | 41 // Amount of time we expect the GPU to stay powered up without being used. |
38 const int kMaxGpuIdleTimeMs = 40; | 42 const int kMaxGpuIdleTimeMs = 40; |
39 // Maximum amount of time we keep pinging the GPU waiting for the client to | 43 // Maximum amount of time we keep pinging the GPU waiting for the client to |
40 // draw. | 44 // draw. |
41 const int kMaxKeepAliveTimeMs = 200; | 45 const int kMaxKeepAliveTimeMs = 200; |
42 #endif | 46 #endif |
43 | 47 |
44 } | 48 } |
45 | 49 |
46 GpuChannelManager::GpuChannelManager( | 50 GpuChannelManager::GpuChannelManager( |
47 IPC::SyncChannel* channel, | 51 GpuChannelManagerDelegate* delegate, |
48 GpuWatchdog* watchdog, | 52 GpuWatchdog* watchdog, |
49 base::SingleThreadTaskRunner* task_runner, | 53 base::SingleThreadTaskRunner* task_runner, |
50 base::SingleThreadTaskRunner* io_task_runner, | 54 base::SingleThreadTaskRunner* io_task_runner, |
51 base::WaitableEvent* shutdown_event, | 55 base::WaitableEvent* shutdown_event, |
52 gpu::SyncPointManager* sync_point_manager, | 56 gpu::SyncPointManager* sync_point_manager, |
53 GpuMemoryBufferFactory* gpu_memory_buffer_factory) | 57 GpuMemoryBufferFactory* gpu_memory_buffer_factory) |
54 : task_runner_(task_runner), | 58 : task_runner_(task_runner), |
55 io_task_runner_(io_task_runner), | 59 io_task_runner_(io_task_runner), |
56 channel_(channel), | 60 delegate_(delegate), |
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), |
66 weak_factory_(this) { | 70 weak_factory_(this) { |
(...skipping 34 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_->DidDestroyChannel(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::AddImageTransportSurface( |
121 router_.AddRoute(routing_id, listener); | 125 int32_t routing_id, |
no sievers
2016/02/22 21:57:42
If this doesn't use AddRoute() can you rename it?
Fady Samuel
2016/02/23 04:45:26
Done.
| |
126 ImageTransportHelper* image_transport_helper) { | |
127 image_transport_map_.AddWithID(image_transport_helper, routing_id); | |
122 } | 128 } |
123 | 129 |
124 void GpuChannelManager::RemoveRoute(int32_t routing_id) { | 130 void GpuChannelManager::RemoveImageTransportSurface(int32_t routing_id) { |
125 router_.RemoveRoute(routing_id); | 131 image_transport_map_.Remove(routing_id); |
126 } | 132 } |
127 | 133 |
134 #if defined(OS_MACOSX) | |
135 void GpuChannelManager::BufferPresented(int32_t routing_id, | |
136 const BufferPresentedParams& params) { | |
137 ImageTransportHelper* helper = image_transport_map_.Lookup(routing_id); | |
138 if (helper) | |
139 helper->BufferPresented(params); | |
140 } | |
141 #endif | |
142 | |
128 GpuChannel* GpuChannelManager::LookupChannel(int32_t client_id) const { | 143 GpuChannel* GpuChannelManager::LookupChannel(int32_t client_id) const { |
129 const auto& it = gpu_channels_.find(client_id); | 144 const auto& it = gpu_channels_.find(client_id); |
130 return it != gpu_channels_.end() ? it->second : nullptr; | 145 return it != gpu_channels_.end() ? it->second : nullptr; |
131 } | 146 } |
132 | 147 |
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) { | |
150 if (msg.routing_id() == MSG_ROUTING_CONTROL) | |
151 return OnControlMessageReceived(msg); | |
152 | |
153 return router_.RouteMessage(msg); | |
154 } | |
155 | |
156 bool GpuChannelManager::Send(IPC::Message* msg) { | |
157 return channel_->Send(msg); | |
158 } | |
159 | |
160 scoped_ptr<GpuChannel> GpuChannelManager::CreateGpuChannel( | 148 scoped_ptr<GpuChannel> GpuChannelManager::CreateGpuChannel( |
161 int client_id, | 149 int client_id, |
162 uint64_t client_tracing_id, | 150 uint64_t client_tracing_id, |
163 bool preempts, | 151 bool preempts, |
164 bool allow_view_command_buffers, | 152 bool allow_view_command_buffers, |
165 bool allow_real_time_streams) { | 153 bool allow_real_time_streams) { |
166 return make_scoped_ptr(new GpuChannel( | 154 return make_scoped_ptr(new GpuChannel( |
167 this, sync_point_manager(), watchdog_, share_group(), mailbox_manager(), | 155 this, sync_point_manager(), watchdog_, share_group(), mailbox_manager(), |
168 preempts ? preemption_flag() : nullptr, task_runner_.get(), | 156 preempts ? preemption_flag() : nullptr, task_runner_.get(), |
169 io_task_runner_.get(), client_id, client_tracing_id, | 157 io_task_runner_.get(), client_id, client_tracing_id, |
170 allow_view_command_buffers, allow_real_time_streams)); | 158 allow_view_command_buffers, allow_real_time_streams)); |
171 } | 159 } |
172 | 160 |
173 void GpuChannelManager::OnEstablishChannel( | 161 void GpuChannelManager::EstablishChannel(const EstablishChannelParams& params) { |
174 const GpuMsg_EstablishChannel_Params& params) { | |
175 scoped_ptr<GpuChannel> channel(CreateGpuChannel( | 162 scoped_ptr<GpuChannel> channel(CreateGpuChannel( |
176 params.client_id, params.client_tracing_id, params.preempts, | 163 params.client_id, params.client_tracing_id, params.preempts, |
177 params.allow_view_command_buffers, params.allow_real_time_streams)); | 164 params.allow_view_command_buffers, params.allow_real_time_streams)); |
178 if (!params.preempts) | 165 if (!params.preempts) |
179 channel->SetPreemptByFlag(preemption_flag_.get()); | 166 channel->SetPreemptByFlag(preemption_flag_.get()); |
180 IPC::ChannelHandle channel_handle = channel->Init(shutdown_event_); | 167 IPC::ChannelHandle channel_handle = channel->Init(shutdown_event_); |
181 | 168 |
182 gpu_channels_.set(params.client_id, std::move(channel)); | 169 gpu_channels_.set(params.client_id, std::move(channel)); |
183 | 170 |
184 Send(new GpuHostMsg_ChannelEstablished(channel_handle)); | 171 delegate_->ChannelEstablished(channel_handle); |
185 } | 172 } |
186 | 173 |
187 void GpuChannelManager::OnCloseChannel( | 174 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) { | 175 for (auto it = gpu_channels_.begin(); it != gpu_channels_.end(); ++it) { |
190 if (it->second->channel_id() == channel_handle.name) { | 176 if (it->second->channel_id() == channel_handle.name) { |
191 gpu_channels_.erase(it); | 177 gpu_channels_.erase(it); |
192 return; | 178 return; |
193 } | 179 } |
194 } | 180 } |
195 } | 181 } |
196 | 182 |
197 void GpuChannelManager::DestroyGpuMemoryBuffer( | 183 void GpuChannelManager::InternalDestroyGpuMemoryBuffer( |
198 gfx::GpuMemoryBufferId id, | 184 gfx::GpuMemoryBufferId id, |
199 int client_id) { | 185 int client_id) { |
200 io_task_runner_->PostTask( | 186 io_task_runner_->PostTask( |
201 FROM_HERE, base::Bind(&GpuChannelManager::DestroyGpuMemoryBufferOnIO, | 187 FROM_HERE, |
202 base::Unretained(this), id, client_id)); | 188 base::Bind(&GpuChannelManager::InternalDestroyGpuMemoryBufferOnIO, |
189 base::Unretained(this), id, client_id)); | |
203 } | 190 } |
204 | 191 |
205 void GpuChannelManager::DestroyGpuMemoryBufferOnIO( | 192 void GpuChannelManager::InternalDestroyGpuMemoryBufferOnIO( |
206 gfx::GpuMemoryBufferId id, | 193 gfx::GpuMemoryBufferId id, |
207 int client_id) { | 194 int client_id) { |
208 gpu_memory_buffer_factory_->DestroyGpuMemoryBuffer(id, client_id); | 195 gpu_memory_buffer_factory_->DestroyGpuMemoryBuffer(id, client_id); |
209 } | 196 } |
210 | 197 |
211 void GpuChannelManager::OnDestroyGpuMemoryBuffer( | 198 void GpuChannelManager::DestroyGpuMemoryBuffer( |
212 gfx::GpuMemoryBufferId id, | 199 gfx::GpuMemoryBufferId id, |
213 int client_id, | 200 int client_id, |
214 const gpu::SyncToken& sync_token) { | 201 const gpu::SyncToken& sync_token) { |
215 if (sync_token.HasData()) { | 202 if (sync_token.HasData()) { |
216 scoped_refptr<gpu::SyncPointClientState> release_state = | 203 scoped_refptr<gpu::SyncPointClientState> release_state = |
217 sync_point_manager()->GetSyncPointClientState( | 204 sync_point_manager()->GetSyncPointClientState( |
218 sync_token.namespace_id(), sync_token.command_buffer_id()); | 205 sync_token.namespace_id(), sync_token.command_buffer_id()); |
219 if (release_state) { | 206 if (release_state) { |
220 sync_point_client_waiter_->WaitOutOfOrder( | 207 sync_point_client_waiter_->WaitOutOfOrder( |
221 release_state.get(), sync_token.release_count(), | 208 release_state.get(), sync_token.release_count(), |
222 base::Bind(&GpuChannelManager::DestroyGpuMemoryBuffer, | 209 base::Bind(&GpuChannelManager::InternalDestroyGpuMemoryBuffer, |
223 base::Unretained(this), id, client_id)); | 210 base::Unretained(this), id, client_id)); |
224 return; | 211 return; |
225 } | 212 } |
226 } | 213 } |
227 | 214 |
228 // No sync token or invalid sync token, destroy immediately. | 215 // No sync token or invalid sync token, destroy immediately. |
229 DestroyGpuMemoryBuffer(id, client_id); | 216 InternalDestroyGpuMemoryBuffer(id, client_id); |
230 } | 217 } |
231 | 218 |
232 void GpuChannelManager::OnUpdateValueState( | 219 void GpuChannelManager::UpdateValueState(int client_id, |
233 int client_id, unsigned int target, const gpu::ValueState& state) { | 220 unsigned int target, |
221 const gpu::ValueState& state) { | |
234 // Only pass updated state to the channel corresponding to the | 222 // Only pass updated state to the channel corresponding to the |
235 // render_widget_host where the event originated. | 223 // render_widget_host where the event originated. |
236 auto it = gpu_channels_.find(client_id); | 224 auto it = gpu_channels_.find(client_id); |
237 if (it != gpu_channels_.end()) | 225 if (it != gpu_channels_.end()) |
238 it->second->HandleUpdateValueState(target, state); | 226 it->second->HandleUpdateValueState(target, state); |
239 } | 227 } |
240 | 228 |
241 void GpuChannelManager::OnLoadedShader(const std::string& program_proto) { | 229 void GpuChannelManager::PopulateShaderCache(const std::string& program_proto) { |
242 if (program_cache()) | 230 if (program_cache()) |
243 program_cache()->LoadProgram(program_proto); | 231 program_cache()->LoadProgram(program_proto); |
244 } | 232 } |
245 | 233 |
246 uint32_t GpuChannelManager::GetUnprocessedOrderNum() const { | 234 uint32_t GpuChannelManager::GetUnprocessedOrderNum() const { |
247 uint32_t unprocessed_order_num = 0; | 235 uint32_t unprocessed_order_num = 0; |
248 for (auto& kv : gpu_channels_) { | 236 for (auto& kv : gpu_channels_) { |
249 unprocessed_order_num = | 237 unprocessed_order_num = |
250 std::max(unprocessed_order_num, kv.second->GetUnprocessedOrderNum()); | 238 std::max(unprocessed_order_num, kv.second->GetUnprocessedOrderNum()); |
251 } | 239 } |
252 return unprocessed_order_num; | 240 return unprocessed_order_num; |
253 } | 241 } |
254 | 242 |
255 uint32_t GpuChannelManager::GetProcessedOrderNum() const { | 243 uint32_t GpuChannelManager::GetProcessedOrderNum() const { |
256 uint32_t processed_order_num = 0; | 244 uint32_t processed_order_num = 0; |
257 for (auto& kv : gpu_channels_) { | 245 for (auto& kv : gpu_channels_) { |
258 processed_order_num = | 246 processed_order_num = |
259 std::max(processed_order_num, kv.second->GetProcessedOrderNum()); | 247 std::max(processed_order_num, kv.second->GetProcessedOrderNum()); |
260 } | 248 } |
261 return processed_order_num; | 249 return processed_order_num; |
262 } | 250 } |
263 | 251 |
264 void GpuChannelManager::LoseAllContexts() { | 252 void GpuChannelManager::LoseAllContexts() { |
265 for (auto& kv : gpu_channels_) { | 253 for (auto& kv : gpu_channels_) { |
266 kv.second->MarkAllContextsLost(); | 254 kv.second->MarkAllContextsLost(); |
267 } | 255 } |
268 task_runner_->PostTask(FROM_HERE, | 256 task_runner_->PostTask(FROM_HERE, |
269 base::Bind(&GpuChannelManager::OnLoseAllContexts, | 257 base::Bind(&GpuChannelManager::DestroyAllChannels, |
270 weak_factory_.GetWeakPtr())); | 258 weak_factory_.GetWeakPtr())); |
271 } | 259 } |
272 | 260 |
273 void GpuChannelManager::OnLoseAllContexts() { | 261 void GpuChannelManager::DestroyAllChannels() { |
274 gpu_channels_.clear(); | 262 gpu_channels_.clear(); |
275 } | 263 } |
276 | 264 |
277 gfx::GLSurface* GpuChannelManager::GetDefaultOffscreenSurface() { | 265 gfx::GLSurface* GpuChannelManager::GetDefaultOffscreenSurface() { |
278 if (!default_offscreen_surface_.get()) { | 266 if (!default_offscreen_surface_.get()) { |
279 default_offscreen_surface_ = | 267 default_offscreen_surface_ = |
280 gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size()); | 268 gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size()); |
281 } | 269 } |
282 return default_offscreen_surface_.get(); | 270 return default_offscreen_surface_.get(); |
283 } | 271 } |
284 | 272 |
285 #if defined(OS_ANDROID) | 273 #if defined(OS_ANDROID) |
286 void GpuChannelManager::DidAccessGpu() { | 274 void GpuChannelManager::DidAccessGpu() { |
287 last_gpu_access_time_ = base::TimeTicks::Now(); | 275 last_gpu_access_time_ = base::TimeTicks::Now(); |
288 } | 276 } |
289 | 277 |
290 void GpuChannelManager::OnWakeUpGpu() { | 278 void GpuChannelManager::WakeUpGpu() { |
291 begin_wake_up_time_ = base::TimeTicks::Now(); | 279 begin_wake_up_time_ = base::TimeTicks::Now(); |
292 ScheduleWakeUpGpu(); | 280 ScheduleWakeUpGpu(); |
293 } | 281 } |
294 | 282 |
295 void GpuChannelManager::ScheduleWakeUpGpu() { | 283 void GpuChannelManager::ScheduleWakeUpGpu() { |
296 base::TimeTicks now = base::TimeTicks::Now(); | 284 base::TimeTicks now = base::TimeTicks::Now(); |
297 TRACE_EVENT2("gpu", "GpuChannelManager::ScheduleWakeUp", | 285 TRACE_EVENT2("gpu", "GpuChannelManager::ScheduleWakeUp", |
298 "idle_time", (now - last_gpu_access_time_).InMilliseconds(), | 286 "idle_time", (now - last_gpu_access_time_).InMilliseconds(), |
299 "keep_awake_time", (now - begin_wake_up_time_).InMilliseconds()); | 287 "keep_awake_time", (now - begin_wake_up_time_).InMilliseconds()); |
300 if (now - last_gpu_access_time_ < | 288 if (now - last_gpu_access_time_ < |
(...skipping 22 matching lines...) Expand all Loading... | |
323 } | 311 } |
324 } | 312 } |
325 if (!stub || !stub->decoder()->MakeCurrent()) | 313 if (!stub || !stub->decoder()->MakeCurrent()) |
326 return; | 314 return; |
327 glFinish(); | 315 glFinish(); |
328 DidAccessGpu(); | 316 DidAccessGpu(); |
329 } | 317 } |
330 #endif | 318 #endif |
331 | 319 |
332 } // namespace content | 320 } // namespace content |
OLD | NEW |