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/browser/gpu/browser_gpu_channel_host_factory.h" | 5 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" |
10 #include "base/profiler/scoped_tracker.h" | 11 #include "base/profiler/scoped_tracker.h" |
| 12 #include "base/single_thread_task_runner.h" |
11 #include "base/synchronization/waitable_event.h" | 13 #include "base/synchronization/waitable_event.h" |
| 14 #include "base/thread_task_runner_handle.h" |
12 #include "base/threading/thread_restrictions.h" | 15 #include "base/threading/thread_restrictions.h" |
13 #include "base/trace_event/trace_event.h" | 16 #include "base/trace_event/trace_event.h" |
14 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" | 17 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" |
15 #include "content/browser/gpu/gpu_data_manager_impl.h" | 18 #include "content/browser/gpu/gpu_data_manager_impl.h" |
16 #include "content/browser/gpu/gpu_process_host.h" | 19 #include "content/browser/gpu/gpu_process_host.h" |
17 #include "content/browser/gpu/gpu_surface_tracker.h" | 20 #include "content/browser/gpu/gpu_surface_tracker.h" |
18 #include "content/common/child_process_host_impl.h" | 21 #include "content/common/child_process_host_impl.h" |
19 #include "content/common/gpu/gpu_memory_buffer_factory.h" | 22 #include "content/common/gpu/gpu_memory_buffer_factory.h" |
20 #include "content/common/gpu/gpu_messages.h" | 23 #include "content/common/gpu/gpu_messages.h" |
21 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 void FinishOnMain(); | 119 void FinishOnMain(); |
117 | 120 |
118 base::WaitableEvent event_; | 121 base::WaitableEvent event_; |
119 CauseForGpuLaunch cause_for_gpu_launch_; | 122 CauseForGpuLaunch cause_for_gpu_launch_; |
120 const int gpu_client_id_; | 123 const int gpu_client_id_; |
121 int gpu_host_id_; | 124 int gpu_host_id_; |
122 bool reused_gpu_process_; | 125 bool reused_gpu_process_; |
123 IPC::ChannelHandle channel_handle_; | 126 IPC::ChannelHandle channel_handle_; |
124 gpu::GPUInfo gpu_info_; | 127 gpu::GPUInfo gpu_info_; |
125 bool finished_; | 128 bool finished_; |
126 scoped_refptr<base::MessageLoopProxy> main_loop_; | 129 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
127 }; | 130 }; |
128 | 131 |
129 scoped_refptr<BrowserGpuChannelHostFactory::EstablishRequest> | 132 scoped_refptr<BrowserGpuChannelHostFactory::EstablishRequest> |
130 BrowserGpuChannelHostFactory::EstablishRequest::Create(CauseForGpuLaunch cause, | 133 BrowserGpuChannelHostFactory::EstablishRequest::Create(CauseForGpuLaunch cause, |
131 int gpu_client_id, | 134 int gpu_client_id, |
132 int gpu_host_id) { | 135 int gpu_host_id) { |
133 scoped_refptr<EstablishRequest> establish_request = | 136 scoped_refptr<EstablishRequest> establish_request = |
134 new EstablishRequest(cause, gpu_client_id, gpu_host_id); | 137 new EstablishRequest(cause, gpu_client_id, gpu_host_id); |
135 scoped_refptr<base::MessageLoopProxy> loop = | 138 scoped_refptr<base::SingleThreadTaskRunner> task_runner = |
136 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); | 139 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); |
137 // PostTask outside the constructor to ensure at least one reference exists. | 140 // PostTask outside the constructor to ensure at least one reference exists. |
138 loop->PostTask( | 141 task_runner->PostTask( |
139 FROM_HERE, | 142 FROM_HERE, |
140 base::Bind(&BrowserGpuChannelHostFactory::EstablishRequest::EstablishOnIO, | 143 base::Bind(&BrowserGpuChannelHostFactory::EstablishRequest::EstablishOnIO, |
141 establish_request)); | 144 establish_request)); |
142 return establish_request; | 145 return establish_request; |
143 } | 146 } |
144 | 147 |
145 BrowserGpuChannelHostFactory::EstablishRequest::EstablishRequest( | 148 BrowserGpuChannelHostFactory::EstablishRequest::EstablishRequest( |
146 CauseForGpuLaunch cause, | 149 CauseForGpuLaunch cause, |
147 int gpu_client_id, | 150 int gpu_client_id, |
148 int gpu_host_id) | 151 int gpu_host_id) |
149 : event_(false, false), | 152 : event_(false, false), |
150 cause_for_gpu_launch_(cause), | 153 cause_for_gpu_launch_(cause), |
151 gpu_client_id_(gpu_client_id), | 154 gpu_client_id_(gpu_client_id), |
152 gpu_host_id_(gpu_host_id), | 155 gpu_host_id_(gpu_host_id), |
153 reused_gpu_process_(false), | 156 reused_gpu_process_(false), |
154 finished_(false), | 157 finished_(false), |
155 main_loop_(base::MessageLoopProxy::current()) { | 158 main_task_runner_(base::ThreadTaskRunnerHandle::Get()) { |
156 } | 159 } |
157 | 160 |
158 void BrowserGpuChannelHostFactory::EstablishRequest::EstablishOnIO() { | 161 void BrowserGpuChannelHostFactory::EstablishRequest::EstablishOnIO() { |
159 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed. | 162 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed. |
160 tracked_objects::ScopedTracker tracking_profile( | 163 tracked_objects::ScopedTracker tracking_profile( |
161 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 164 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
162 "477117 " | 165 "477117 " |
163 "BrowserGpuChannelHostFactory::EstablishRequest::EstablishOnIO")); | 166 "BrowserGpuChannelHostFactory::EstablishRequest::EstablishOnIO")); |
164 GpuProcessHost* host = GpuProcessHost::FromID(gpu_host_id_); | 167 GpuProcessHost* host = GpuProcessHost::FromID(gpu_host_id_); |
165 if (!host) { | 168 if (!host) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 EstablishOnIO(); | 208 EstablishOnIO(); |
206 } else { | 209 } else { |
207 channel_handle_ = channel_handle; | 210 channel_handle_ = channel_handle; |
208 gpu_info_ = gpu_info; | 211 gpu_info_ = gpu_info; |
209 FinishOnIO(); | 212 FinishOnIO(); |
210 } | 213 } |
211 } | 214 } |
212 | 215 |
213 void BrowserGpuChannelHostFactory::EstablishRequest::FinishOnIO() { | 216 void BrowserGpuChannelHostFactory::EstablishRequest::FinishOnIO() { |
214 event_.Signal(); | 217 event_.Signal(); |
215 main_loop_->PostTask( | 218 main_task_runner_->PostTask( |
216 FROM_HERE, | 219 FROM_HERE, |
217 base::Bind(&BrowserGpuChannelHostFactory::EstablishRequest::FinishOnMain, | 220 base::Bind(&BrowserGpuChannelHostFactory::EstablishRequest::FinishOnMain, |
218 this)); | 221 this)); |
219 } | 222 } |
220 | 223 |
221 void BrowserGpuChannelHostFactory::EstablishRequest::FinishOnMain() { | 224 void BrowserGpuChannelHostFactory::EstablishRequest::FinishOnMain() { |
222 if (!finished_) { | 225 if (!finished_) { |
223 BrowserGpuChannelHostFactory* factory = | 226 BrowserGpuChannelHostFactory* factory = |
224 BrowserGpuChannelHostFactory::instance(); | 227 BrowserGpuChannelHostFactory::instance(); |
225 factory->GpuChannelEstablished(); | 228 factory->GpuChannelEstablished(); |
226 finished_ = true; | 229 finished_ = true; |
227 } | 230 } |
228 } | 231 } |
229 | 232 |
230 void BrowserGpuChannelHostFactory::EstablishRequest::Wait() { | 233 void BrowserGpuChannelHostFactory::EstablishRequest::Wait() { |
231 DCHECK(main_loop_->BelongsToCurrentThread()); | 234 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
232 { | 235 { |
233 // TODO(vadimt): Remove ScopedTracker below once crbug.com/125248 is fixed. | 236 // TODO(vadimt): Remove ScopedTracker below once crbug.com/125248 is fixed. |
234 tracked_objects::ScopedTracker tracking_profile( | 237 tracked_objects::ScopedTracker tracking_profile( |
235 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 238 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
236 "125248 BrowserGpuChannelHostFactory::EstablishRequest::Wait")); | 239 "125248 BrowserGpuChannelHostFactory::EstablishRequest::Wait")); |
237 | 240 |
238 // We're blocking the UI thread, which is generally undesirable. | 241 // We're blocking the UI thread, which is generally undesirable. |
239 // In this case we need to wait for this before we can show any UI | 242 // In this case we need to wait for this before we can show any UI |
240 // /anyway/, so it won't cause additional jank. | 243 // /anyway/, so it won't cause additional jank. |
241 // TODO(piman): Make this asynchronous (http://crbug.com/125248). | 244 // TODO(piman): Make this asynchronous (http://crbug.com/125248). |
242 TRACE_EVENT0("browser", | 245 TRACE_EVENT0("browser", |
243 "BrowserGpuChannelHostFactory::EstablishGpuChannelSync"); | 246 "BrowserGpuChannelHostFactory::EstablishGpuChannelSync"); |
244 base::ThreadRestrictions::ScopedAllowWait allow_wait; | 247 base::ThreadRestrictions::ScopedAllowWait allow_wait; |
245 event_.Wait(); | 248 event_.Wait(); |
246 } | 249 } |
247 FinishOnMain(); | 250 FinishOnMain(); |
248 } | 251 } |
249 | 252 |
250 void BrowserGpuChannelHostFactory::EstablishRequest::Cancel() { | 253 void BrowserGpuChannelHostFactory::EstablishRequest::Cancel() { |
251 DCHECK(main_loop_->BelongsToCurrentThread()); | 254 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
252 finished_ = true; | 255 finished_ = true; |
253 } | 256 } |
254 | 257 |
255 bool BrowserGpuChannelHostFactory::CanUseForTesting() { | 258 bool BrowserGpuChannelHostFactory::CanUseForTesting() { |
256 return GpuDataManager::GetInstance()->GpuAccessAllowed(NULL); | 259 return GpuDataManager::GetInstance()->GpuAccessAllowed(NULL); |
257 } | 260 } |
258 | 261 |
259 void BrowserGpuChannelHostFactory::Initialize(bool establish_gpu_channel) { | 262 void BrowserGpuChannelHostFactory::Initialize(bool establish_gpu_channel) { |
260 DCHECK(!instance_); | 263 DCHECK(!instance_); |
261 instance_ = new BrowserGpuChannelHostFactory(); | 264 instance_ = new BrowserGpuChannelHostFactory(); |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 579 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
577 | 580 |
578 CreateGpuMemoryBufferCallbackMap::iterator iter = | 581 CreateGpuMemoryBufferCallbackMap::iterator iter = |
579 create_gpu_memory_buffer_requests_.find(request_id); | 582 create_gpu_memory_buffer_requests_.find(request_id); |
580 DCHECK(iter != create_gpu_memory_buffer_requests_.end()); | 583 DCHECK(iter != create_gpu_memory_buffer_requests_.end()); |
581 iter->second.Run(handle); | 584 iter->second.Run(handle); |
582 create_gpu_memory_buffer_requests_.erase(iter); | 585 create_gpu_memory_buffer_requests_.erase(iter); |
583 } | 586 } |
584 | 587 |
585 } // namespace content | 588 } // namespace content |
OLD | NEW |