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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/profiler/scoped_tracker.h" | 9 #include "base/profiler/scoped_tracker.h" |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 gpu_host_id(0), | 35 gpu_host_id(0), |
36 route_id(route_id), | 36 route_id(route_id), |
37 result(CREATE_COMMAND_BUFFER_FAILED) {} | 37 result(CREATE_COMMAND_BUFFER_FAILED) {} |
38 ~CreateRequest() {} | 38 ~CreateRequest() {} |
39 base::WaitableEvent event; | 39 base::WaitableEvent event; |
40 int gpu_host_id; | 40 int gpu_host_id; |
41 int32 route_id; | 41 int32 route_id; |
42 CreateCommandBufferResult result; | 42 CreateCommandBufferResult result; |
43 }; | 43 }; |
44 | 44 |
| 45 struct BrowserGpuChannelHostFactory::CreateStreamTextureRequest { |
| 46 CreateStreamTextureRequest(int32 image_id, int32 stream_id, int32 route_id) |
| 47 : event(true, false), |
| 48 image_id(image_id), |
| 49 stream_id(stream_id), |
| 50 route_id(route_id) {} |
| 51 ~CreateStreamTextureRequest() {} |
| 52 base::WaitableEvent event; |
| 53 int32 image_id; |
| 54 int32 stream_id; |
| 55 int32 route_id; |
| 56 bool result; |
| 57 }; |
| 58 |
45 class BrowserGpuChannelHostFactory::EstablishRequest | 59 class BrowserGpuChannelHostFactory::EstablishRequest |
46 : public base::RefCountedThreadSafe<EstablishRequest> { | 60 : public base::RefCountedThreadSafe<EstablishRequest> { |
47 public: | 61 public: |
48 static scoped_refptr<EstablishRequest> Create(CauseForGpuLaunch cause, | 62 static scoped_refptr<EstablishRequest> Create(CauseForGpuLaunch cause, |
49 int gpu_client_id, | 63 int gpu_client_id, |
50 int gpu_host_id); | 64 int gpu_host_id); |
51 void Wait(); | 65 void Wait(); |
52 void Cancel(); | 66 void Cancel(); |
53 | 67 |
54 int gpu_host_id() { return gpu_host_id_; } | 68 int gpu_host_id() { return gpu_host_id_; } |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 host->CreateViewCommandBuffer( | 291 host->CreateViewCommandBuffer( |
278 surface, | 292 surface, |
279 surface_id, | 293 surface_id, |
280 gpu_client_id_, | 294 gpu_client_id_, |
281 init_params, | 295 init_params, |
282 request->route_id, | 296 request->route_id, |
283 base::Bind(&BrowserGpuChannelHostFactory::CommandBufferCreatedOnIO, | 297 base::Bind(&BrowserGpuChannelHostFactory::CommandBufferCreatedOnIO, |
284 request)); | 298 request)); |
285 } | 299 } |
286 | 300 |
| 301 void BrowserGpuChannelHostFactory::CreateStreamTextureOnIO( |
| 302 CreateStreamTextureRequest* request) { |
| 303 GpuProcessHost* host = GpuProcessHost::FromID(gpu_host_id_); |
| 304 if (!host) { |
| 305 request->event.Signal(); |
| 306 return; |
| 307 } |
| 308 host->CreateStreamTexture( |
| 309 request->image_id, gpu_client_id_, request->route_id, request->stream_id, |
| 310 base::Bind(&BrowserGpuChannelHostFactory::StreamTextureCreatedOnIO, |
| 311 request)); |
| 312 } |
| 313 |
287 IPC::AttachmentBroker* BrowserGpuChannelHostFactory::GetAttachmentBroker() { | 314 IPC::AttachmentBroker* BrowserGpuChannelHostFactory::GetAttachmentBroker() { |
288 return content::ChildProcessHost::GetAttachmentBroker(); | 315 return content::ChildProcessHost::GetAttachmentBroker(); |
289 } | 316 } |
290 | 317 |
291 // static | 318 // static |
292 void BrowserGpuChannelHostFactory::CommandBufferCreatedOnIO( | 319 void BrowserGpuChannelHostFactory::CommandBufferCreatedOnIO( |
293 CreateRequest* request, CreateCommandBufferResult result) { | 320 CreateRequest* request, CreateCommandBufferResult result) { |
294 request->result = result; | 321 request->result = result; |
295 request->event.Signal(); | 322 request->event.Signal(); |
296 } | 323 } |
297 | 324 |
| 325 // static |
| 326 void BrowserGpuChannelHostFactory::StreamTextureCreatedOnIO( |
| 327 CreateStreamTextureRequest* request, |
| 328 bool result) { |
| 329 request->result = result; |
| 330 request->event.Signal(); |
| 331 } |
| 332 |
298 CreateCommandBufferResult BrowserGpuChannelHostFactory::CreateViewCommandBuffer( | 333 CreateCommandBufferResult BrowserGpuChannelHostFactory::CreateViewCommandBuffer( |
299 int32 surface_id, | 334 int32 surface_id, |
300 const GPUCreateCommandBufferConfig& init_params, | 335 const GPUCreateCommandBufferConfig& init_params, |
301 int32 route_id) { | 336 int32 route_id) { |
302 CreateRequest request(route_id); | 337 CreateRequest request(route_id); |
303 GetIOThreadTaskRunner()->PostTask( | 338 GetIOThreadTaskRunner()->PostTask( |
304 FROM_HERE, | 339 FROM_HERE, |
305 base::Bind(&BrowserGpuChannelHostFactory::CreateViewCommandBufferOnIO, | 340 base::Bind(&BrowserGpuChannelHostFactory::CreateViewCommandBufferOnIO, |
306 base::Unretained(this), &request, surface_id, init_params)); | 341 base::Unretained(this), &request, surface_id, init_params)); |
307 // TODO(vadimt): Remove ScopedTracker below once crbug.com/125248 is fixed. | 342 // TODO(vadimt): Remove ScopedTracker below once crbug.com/125248 is fixed. |
308 tracked_objects::ScopedTracker tracking_profile( | 343 tracked_objects::ScopedTracker tracking_profile( |
309 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 344 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
310 "125248 BrowserGpuChannelHostFactory::CreateViewCommandBuffer")); | 345 "125248 BrowserGpuChannelHostFactory::CreateViewCommandBuffer")); |
311 | 346 |
312 // We're blocking the UI thread, which is generally undesirable. | 347 // We're blocking the UI thread, which is generally undesirable. |
313 // In this case we need to wait for this before we can show any UI /anyway/, | 348 // In this case we need to wait for this before we can show any UI /anyway/, |
314 // so it won't cause additional jank. | 349 // so it won't cause additional jank. |
315 // TODO(piman): Make this asynchronous (http://crbug.com/125248). | 350 // TODO(piman): Make this asynchronous (http://crbug.com/125248). |
316 TRACE_EVENT0("browser", | 351 TRACE_EVENT0("browser", |
317 "BrowserGpuChannelHostFactory::CreateViewCommandBuffer"); | 352 "BrowserGpuChannelHostFactory::CreateViewCommandBuffer"); |
318 base::ThreadRestrictions::ScopedAllowWait allow_wait; | 353 base::ThreadRestrictions::ScopedAllowWait allow_wait; |
319 request.event.Wait(); | 354 request.event.Wait(); |
320 return request.result; | 355 return request.result; |
321 } | 356 } |
322 | 357 |
| 358 bool BrowserGpuChannelHostFactory::CreateStreamTexture(int32 image_id, |
| 359 int32 route_id, |
| 360 int32 stream_id) { |
| 361 CreateStreamTextureRequest request(image_id, stream_id, route_id); |
| 362 |
| 363 GetIOThreadTaskRunner()->PostTask( |
| 364 FROM_HERE, |
| 365 base::Bind(&BrowserGpuChannelHostFactory::CreateStreamTextureOnIO, |
| 366 base::Unretained(this), &request)); |
| 367 TRACE_EVENT0("browser", |
| 368 "BrowserGpuChannelHostFactory::CreateStreamTextureOnIO"); |
| 369 |
| 370 base::ThreadRestrictions::ScopedAllowWait allow_wait; |
| 371 request.event.Wait(); |
| 372 return request.result; |
| 373 } |
| 374 |
323 // Blocking the UI thread to open a GPU channel is not supported on Android. | 375 // Blocking the UI thread to open a GPU channel is not supported on Android. |
324 // (Opening the initial channel to a child process involves handling a reply | 376 // (Opening the initial channel to a child process involves handling a reply |
325 // task on the UI thread first, so we cannot block here.) | 377 // task on the UI thread first, so we cannot block here.) |
326 #if !defined(OS_ANDROID) | 378 #if !defined(OS_ANDROID) |
327 GpuChannelHost* BrowserGpuChannelHostFactory::EstablishGpuChannelSync( | 379 GpuChannelHost* BrowserGpuChannelHostFactory::EstablishGpuChannelSync( |
328 CauseForGpuLaunch cause_for_gpu_launch) { | 380 CauseForGpuLaunch cause_for_gpu_launch) { |
329 EstablishGpuChannel(cause_for_gpu_launch, base::Closure()); | 381 EstablishGpuChannel(cause_for_gpu_launch, base::Closure()); |
330 | 382 |
331 if (pending_request_.get()) | 383 if (pending_request_.get()) |
332 pending_request_->Wait(); | 384 pending_request_->Wait(); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 int host_id, | 454 int host_id, |
403 scoped_refptr<IPC::MessageFilter> filter) { | 455 scoped_refptr<IPC::MessageFilter> filter) { |
404 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 456 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
405 | 457 |
406 GpuProcessHost* host = GpuProcessHost::FromID(host_id); | 458 GpuProcessHost* host = GpuProcessHost::FromID(host_id); |
407 if (host) | 459 if (host) |
408 host->AddFilter(filter.get()); | 460 host->AddFilter(filter.get()); |
409 } | 461 } |
410 | 462 |
411 } // namespace content | 463 } // namespace content |
OLD | NEW |