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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/location.h" | |
10 #include "base/single_thread_task_runner.h" | |
11 #include "base/thread_task_runner_handle.h" | |
12 #include "content/common/gpu/gpu_channel.h" | 9 #include "content/common/gpu/gpu_channel.h" |
13 #include "content/common/gpu/gpu_memory_buffer_factory.h" | 10 #include "content/common/gpu/gpu_memory_buffer_factory.h" |
14 #include "content/common/gpu/gpu_memory_manager.h" | 11 #include "content/common/gpu/gpu_memory_manager.h" |
15 #include "content/common/gpu/gpu_messages.h" | 12 #include "content/common/gpu/gpu_messages.h" |
16 #include "content/common/message_router.h" | 13 #include "content/common/message_router.h" |
17 #include "gpu/command_buffer/common/value_state.h" | 14 #include "gpu/command_buffer/common/value_state.h" |
18 #include "gpu/command_buffer/service/feature_info.h" | 15 #include "gpu/command_buffer/service/feature_info.h" |
19 #include "gpu/command_buffer/service/gpu_switches.h" | 16 #include "gpu/command_buffer/service/gpu_switches.h" |
20 #include "gpu/command_buffer/service/mailbox_manager_impl.h" | 17 #include "gpu/command_buffer/service/mailbox_manager_impl.h" |
21 #include "gpu/command_buffer/service/memory_program_cache.h" | 18 #include "gpu/command_buffer/service/memory_program_cache.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 | 78 |
82 gfx::GpuMemoryBufferType GetGpuMemoryBufferFactoryType() { | 79 gfx::GpuMemoryBufferType GetGpuMemoryBufferFactoryType() { |
83 std::vector<gfx::GpuMemoryBufferType> supported_types; | 80 std::vector<gfx::GpuMemoryBufferType> supported_types; |
84 GpuMemoryBufferFactory::GetSupportedTypes(&supported_types); | 81 GpuMemoryBufferFactory::GetSupportedTypes(&supported_types); |
85 DCHECK(!supported_types.empty()); | 82 DCHECK(!supported_types.empty()); |
86 return supported_types[0]; | 83 return supported_types[0]; |
87 } | 84 } |
88 | 85 |
89 } // namespace | 86 } // namespace |
90 | 87 |
91 GpuChannelManager::GpuChannelManager( | 88 GpuChannelManager::GpuChannelManager(MessageRouter* router, |
92 MessageRouter* router, | 89 GpuWatchdog* watchdog, |
93 GpuWatchdog* watchdog, | 90 base::MessageLoopProxy* io_message_loop, |
94 base::SingleThreadTaskRunner* io_task_runner, | 91 base::WaitableEvent* shutdown_event, |
95 base::WaitableEvent* shutdown_event, | 92 IPC::SyncChannel* channel) |
96 IPC::SyncChannel* channel) | 93 : io_message_loop_(io_message_loop), |
97 : io_task_runner_(io_task_runner), | |
98 shutdown_event_(shutdown_event), | 94 shutdown_event_(shutdown_event), |
99 router_(router), | 95 router_(router), |
100 gpu_memory_manager_( | 96 gpu_memory_manager_( |
101 this, | 97 this, |
102 GpuMemoryManager::kDefaultMaxSurfacesWithFrontbufferSoftLimit), | 98 GpuMemoryManager::kDefaultMaxSurfacesWithFrontbufferSoftLimit), |
103 watchdog_(watchdog), | 99 watchdog_(watchdog), |
104 sync_point_manager_(gpu::SyncPointManager::Create(false)), | 100 sync_point_manager_(gpu::SyncPointManager::Create(false)), |
105 gpu_memory_buffer_factory_( | 101 gpu_memory_buffer_factory_( |
106 GpuMemoryBufferFactory::Create(GetGpuMemoryBufferFactoryType())), | 102 GpuMemoryBufferFactory::Create(GetGpuMemoryBufferFactoryType())), |
107 channel_(channel), | 103 channel_(channel), |
108 filter_( | 104 filter_( |
109 new GpuChannelManagerMessageFilter(gpu_memory_buffer_factory_.get())), | 105 new GpuChannelManagerMessageFilter(gpu_memory_buffer_factory_.get())), |
110 relinquish_resources_pending_(false), | 106 relinquish_resources_pending_(false), |
111 weak_factory_(this) { | 107 weak_factory_(this) { |
112 DCHECK(router_); | 108 DCHECK(router_); |
113 DCHECK(io_task_runner); | 109 DCHECK(io_message_loop); |
114 DCHECK(shutdown_event); | 110 DCHECK(shutdown_event); |
115 channel_->AddFilter(filter_.get()); | 111 channel_->AddFilter(filter_.get()); |
116 } | 112 } |
117 | 113 |
118 GpuChannelManager::~GpuChannelManager() { | 114 GpuChannelManager::~GpuChannelManager() { |
119 gpu_channels_.clear(); | 115 gpu_channels_.clear(); |
120 if (default_offscreen_surface_.get()) { | 116 if (default_offscreen_surface_.get()) { |
121 default_offscreen_surface_->Destroy(); | 117 default_offscreen_surface_->Destroy(); |
122 default_offscreen_surface_ = NULL; | 118 default_offscreen_surface_ = NULL; |
123 } | 119 } |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 mailbox_manager = mailbox_manager_.get(); | 199 mailbox_manager = mailbox_manager_.get(); |
204 } | 200 } |
205 | 201 |
206 scoped_ptr<GpuChannel> channel(new GpuChannel(this, | 202 scoped_ptr<GpuChannel> channel(new GpuChannel(this, |
207 watchdog_, | 203 watchdog_, |
208 share_group, | 204 share_group, |
209 mailbox_manager, | 205 mailbox_manager, |
210 client_id, | 206 client_id, |
211 false, | 207 false, |
212 allow_future_sync_points)); | 208 allow_future_sync_points)); |
213 channel->Init(io_task_runner_.get(), shutdown_event_); | 209 channel->Init(io_message_loop_.get(), shutdown_event_); |
214 channel_handle.name = channel->GetChannelName(); | 210 channel_handle.name = channel->GetChannelName(); |
215 | 211 |
216 #if defined(OS_POSIX) | 212 #if defined(OS_POSIX) |
217 // On POSIX, pass the renderer-side FD. Also mark it as auto-close so | 213 // On POSIX, pass the renderer-side FD. Also mark it as auto-close so |
218 // that it gets closed after it has been sent. | 214 // that it gets closed after it has been sent. |
219 base::ScopedFD renderer_fd = channel->TakeRendererFileDescriptor(); | 215 base::ScopedFD renderer_fd = channel->TakeRendererFileDescriptor(); |
220 DCHECK(renderer_fd.is_valid()); | 216 DCHECK(renderer_fd.is_valid()); |
221 channel_handle.socket = base::FileDescriptor(renderer_fd.Pass()); | 217 channel_handle.socket = base::FileDescriptor(renderer_fd.Pass()); |
222 #endif | 218 #endif |
223 | 219 |
(...skipping 28 matching lines...) Expand all Loading... |
252 result = iter->second->CreateViewCommandBuffer( | 248 result = iter->second->CreateViewCommandBuffer( |
253 window, surface_id, init_params, route_id); | 249 window, surface_id, init_params, route_id); |
254 } | 250 } |
255 | 251 |
256 Send(new GpuHostMsg_CommandBufferCreated(result)); | 252 Send(new GpuHostMsg_CommandBufferCreated(result)); |
257 } | 253 } |
258 | 254 |
259 void GpuChannelManager::DestroyGpuMemoryBuffer( | 255 void GpuChannelManager::DestroyGpuMemoryBuffer( |
260 gfx::GpuMemoryBufferId id, | 256 gfx::GpuMemoryBufferId id, |
261 int client_id) { | 257 int client_id) { |
262 io_task_runner_->PostTask( | 258 io_message_loop_->PostTask( |
263 FROM_HERE, base::Bind(&GpuChannelManager::DestroyGpuMemoryBufferOnIO, | 259 FROM_HERE, |
264 base::Unretained(this), id, client_id)); | 260 base::Bind(&GpuChannelManager::DestroyGpuMemoryBufferOnIO, |
| 261 base::Unretained(this), |
| 262 id, |
| 263 client_id)); |
265 } | 264 } |
266 | 265 |
267 void GpuChannelManager::DestroyGpuMemoryBufferOnIO( | 266 void GpuChannelManager::DestroyGpuMemoryBufferOnIO( |
268 gfx::GpuMemoryBufferId id, | 267 gfx::GpuMemoryBufferId id, |
269 int client_id) { | 268 int client_id) { |
270 gpu_memory_buffer_factory_->DestroyGpuMemoryBuffer(id, client_id); | 269 gpu_memory_buffer_factory_->DestroyGpuMemoryBuffer(id, client_id); |
271 } | 270 } |
272 | 271 |
273 void GpuChannelManager::OnDestroyGpuMemoryBuffer( | 272 void GpuChannelManager::OnDestroyGpuMemoryBuffer( |
274 gfx::GpuMemoryBufferId id, | 273 gfx::GpuMemoryBufferId id, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 messages_processed += iter->second->messages_processed(); | 317 messages_processed += iter->second->messages_processed(); |
319 } | 318 } |
320 return messages_processed; | 319 return messages_processed; |
321 } | 320 } |
322 | 321 |
323 void GpuChannelManager::LoseAllContexts() { | 322 void GpuChannelManager::LoseAllContexts() { |
324 for (GpuChannelMap::iterator iter = gpu_channels_.begin(); | 323 for (GpuChannelMap::iterator iter = gpu_channels_.begin(); |
325 iter != gpu_channels_.end(); ++iter) { | 324 iter != gpu_channels_.end(); ++iter) { |
326 iter->second->MarkAllContextsLost(); | 325 iter->second->MarkAllContextsLost(); |
327 } | 326 } |
328 base::ThreadTaskRunnerHandle::Get()->PostTask( | 327 base::MessageLoop::current()->PostTask( |
329 FROM_HERE, base::Bind(&GpuChannelManager::OnLoseAllContexts, | 328 FROM_HERE, |
330 weak_factory_.GetWeakPtr())); | 329 base::Bind(&GpuChannelManager::OnLoseAllContexts, |
| 330 weak_factory_.GetWeakPtr())); |
331 } | 331 } |
332 | 332 |
333 void GpuChannelManager::OnLoseAllContexts() { | 333 void GpuChannelManager::OnLoseAllContexts() { |
334 gpu_channels_.clear(); | 334 gpu_channels_.clear(); |
335 CheckRelinquishGpuResources(); | 335 CheckRelinquishGpuResources(); |
336 } | 336 } |
337 | 337 |
338 gfx::GLSurface* GpuChannelManager::GetDefaultOffscreenSurface() { | 338 gfx::GLSurface* GpuChannelManager::GetDefaultOffscreenSurface() { |
339 if (!default_offscreen_surface_.get()) { | 339 if (!default_offscreen_surface_.get()) { |
340 default_offscreen_surface_ = | 340 default_offscreen_surface_ = |
(...skipping 24 matching lines...) Expand all Loading... |
365 OnResourcesRelinquished(); | 365 OnResourcesRelinquished(); |
366 #endif | 366 #endif |
367 } | 367 } |
368 } | 368 } |
369 | 369 |
370 void GpuChannelManager::OnResourcesRelinquished() { | 370 void GpuChannelManager::OnResourcesRelinquished() { |
371 Send(new GpuHostMsg_ResourcesRelinquished()); | 371 Send(new GpuHostMsg_ResourcesRelinquished()); |
372 } | 372 } |
373 | 373 |
374 } // namespace content | 374 } // namespace content |
OLD | NEW |