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/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
10 #include "base/threading/thread_restrictions.h" | 10 #include "base/threading/thread_restrictions.h" |
11 #include "base/tracked_objects.h" | 11 #include "base/tracked_objects.h" |
12 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" | |
12 #include "content/browser/gpu/gpu_data_manager_impl.h" | 13 #include "content/browser/gpu/gpu_data_manager_impl.h" |
13 #include "content/browser/gpu/gpu_memory_buffer_factory_host_impl.h" | 14 #include "content/browser/gpu/gpu_memory_buffer_factory_host_impl.h" |
14 #include "content/browser/gpu/gpu_process_host.h" | 15 #include "content/browser/gpu/gpu_process_host.h" |
15 #include "content/browser/gpu/gpu_surface_tracker.h" | 16 #include "content/browser/gpu/gpu_surface_tracker.h" |
16 #include "content/common/child_process_host_impl.h" | 17 #include "content/common/child_process_host_impl.h" |
17 #include "content/common/gpu/client/gpu_memory_buffer_impl.h" | |
18 #include "content/common/gpu/gpu_messages.h" | 18 #include "content/common/gpu/gpu_messages.h" |
19 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
20 #include "content/public/browser/gpu_data_manager.h" | 20 #include "content/public/browser/gpu_data_manager.h" |
21 #include "content/public/common/content_client.h" | 21 #include "content/public/common/content_client.h" |
22 #include "ipc/ipc_channel_handle.h" | 22 #include "ipc/ipc_channel_handle.h" |
23 #include "ipc/ipc_forwarding_message_filter.h" | 23 #include "ipc/ipc_forwarding_message_filter.h" |
24 #include "ipc/message_filter.h" | 24 #include "ipc/message_filter.h" |
25 | 25 |
26 namespace content { | 26 namespace content { |
27 | 27 |
28 BrowserGpuChannelHostFactory* BrowserGpuChannelHostFactory::instance_ = NULL; | 28 BrowserGpuChannelHostFactory* BrowserGpuChannelHostFactory::instance_ = NULL; |
29 | 29 |
30 struct BrowserGpuChannelHostFactory::CreateRequest { | 30 struct BrowserGpuChannelHostFactory::CreateRequest { |
31 CreateRequest(int32 route_id) | 31 CreateRequest(int32 route_id) |
32 : event(true, false), | 32 : event(true, false), |
33 gpu_host_id(0), | 33 gpu_host_id(0), |
34 route_id(route_id), | 34 route_id(route_id), |
35 result(CREATE_COMMAND_BUFFER_FAILED) {} | 35 result(CREATE_COMMAND_BUFFER_FAILED) {} |
36 ~CreateRequest() {} | 36 ~CreateRequest() {} |
37 base::WaitableEvent event; | 37 base::WaitableEvent event; |
38 int gpu_host_id; | 38 int gpu_host_id; |
39 int32 route_id; | 39 int32 route_id; |
40 CreateCommandBufferResult result; | 40 CreateCommandBufferResult result; |
41 }; | 41 }; |
42 | 42 |
43 struct BrowserGpuChannelHostFactory::AllocateGpuMemoryBufferRequest { | |
44 AllocateGpuMemoryBufferRequest(size_t width, | |
45 size_t height, | |
46 unsigned internalformat, | |
47 unsigned usage, | |
48 int client_id) | |
49 : event(true, false), | |
50 width(width), | |
51 height(height), | |
52 internalformat(internalformat), | |
53 usage(usage), | |
54 client_id(client_id) {} | |
55 ~AllocateGpuMemoryBufferRequest() {} | |
56 base::WaitableEvent event; | |
57 size_t width; | |
58 size_t height; | |
59 unsigned internalformat; | |
60 unsigned usage; | |
61 int client_id; | |
62 scoped_ptr<gfx::GpuMemoryBuffer> result; | |
63 }; | |
64 | |
65 class BrowserGpuChannelHostFactory::EstablishRequest | 43 class BrowserGpuChannelHostFactory::EstablishRequest |
66 : public base::RefCountedThreadSafe<EstablishRequest> { | 44 : public base::RefCountedThreadSafe<EstablishRequest> { |
67 public: | 45 public: |
68 static scoped_refptr<EstablishRequest> Create(CauseForGpuLaunch cause, | 46 static scoped_refptr<EstablishRequest> Create(CauseForGpuLaunch cause, |
69 int gpu_client_id, | 47 int gpu_client_id, |
70 int gpu_host_id); | 48 int gpu_host_id); |
71 void Wait(); | 49 void Wait(); |
72 void Cancel(); | 50 void Cancel(); |
73 | 51 |
74 int gpu_host_id() { return gpu_host_id_; } | 52 int gpu_host_id() { return gpu_host_id_; } |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
238 DCHECK(instance_); | 216 DCHECK(instance_); |
239 delete instance_; | 217 delete instance_; |
240 instance_ = NULL; | 218 instance_ = NULL; |
241 } | 219 } |
242 | 220 |
243 BrowserGpuChannelHostFactory::BrowserGpuChannelHostFactory() | 221 BrowserGpuChannelHostFactory::BrowserGpuChannelHostFactory() |
244 : gpu_client_id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()), | 222 : gpu_client_id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()), |
245 shutdown_event_(new base::WaitableEvent(true, false)), | 223 shutdown_event_(new base::WaitableEvent(true, false)), |
246 gpu_memory_buffer_factory_host_(new GpuMemoryBufferFactoryHostImpl), | 224 gpu_memory_buffer_factory_host_(new GpuMemoryBufferFactoryHostImpl), |
247 gpu_host_id_(0) { | 225 gpu_host_id_(0) { |
226 BrowserGpuMemoryBufferManager::current()->set_gpu_client_id(gpu_client_id_); | |
piman
2014/10/09 21:33:02
Can BrowserGpuChannelHostFactory simply own the Br
reveman
2014/10/10 02:20:16
Done.
I kept the static BrowserGpuMemoryBufferMan
| |
248 } | 227 } |
249 | 228 |
250 BrowserGpuChannelHostFactory::~BrowserGpuChannelHostFactory() { | 229 BrowserGpuChannelHostFactory::~BrowserGpuChannelHostFactory() { |
251 DCHECK(IsMainThread()); | 230 DCHECK(IsMainThread()); |
252 if (pending_request_.get()) | 231 if (pending_request_.get()) |
253 pending_request_->Cancel(); | 232 pending_request_->Cancel(); |
254 for (size_t n = 0; n < established_callbacks_.size(); n++) | 233 for (size_t n = 0; n < established_callbacks_.size(); n++) |
255 established_callbacks_[n].Run(); | 234 established_callbacks_[n].Run(); |
256 shutdown_event_->Signal(); | 235 shutdown_event_->Signal(); |
257 } | 236 } |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
369 return NULL; | 348 return NULL; |
370 } | 349 } |
371 | 350 |
372 void BrowserGpuChannelHostFactory::GpuChannelEstablished() { | 351 void BrowserGpuChannelHostFactory::GpuChannelEstablished() { |
373 DCHECK(IsMainThread()); | 352 DCHECK(IsMainThread()); |
374 DCHECK(pending_request_.get()); | 353 DCHECK(pending_request_.get()); |
375 if (pending_request_->channel_handle().name.empty()) { | 354 if (pending_request_->channel_handle().name.empty()) { |
376 DCHECK(!gpu_channel_.get()); | 355 DCHECK(!gpu_channel_.get()); |
377 } else { | 356 } else { |
378 GetContentClient()->SetGpuInfo(pending_request_->gpu_info()); | 357 GetContentClient()->SetGpuInfo(pending_request_->gpu_info()); |
379 gpu_channel_ = GpuChannelHost::Create(this, | 358 gpu_channel_ = |
380 pending_request_->gpu_info(), | 359 GpuChannelHost::Create(this, |
381 pending_request_->channel_handle(), | 360 pending_request_->gpu_info(), |
382 shutdown_event_.get()); | 361 pending_request_->channel_handle(), |
362 shutdown_event_.get(), | |
363 BrowserGpuMemoryBufferManager::current()); | |
383 } | 364 } |
384 gpu_host_id_ = pending_request_->gpu_host_id(); | 365 gpu_host_id_ = pending_request_->gpu_host_id(); |
385 gpu_memory_buffer_factory_host_->set_gpu_host_id(gpu_host_id_); | 366 gpu_memory_buffer_factory_host_->set_gpu_host_id(gpu_host_id_); |
386 pending_request_ = NULL; | 367 pending_request_ = NULL; |
387 | 368 |
388 for (size_t n = 0; n < established_callbacks_.size(); n++) | 369 for (size_t n = 0; n < established_callbacks_.size(); n++) |
389 established_callbacks_[n].Run(); | 370 established_callbacks_[n].Run(); |
390 | 371 |
391 established_callbacks_.clear(); | 372 established_callbacks_.clear(); |
392 } | 373 } |
393 | 374 |
394 scoped_ptr<gfx::GpuMemoryBuffer> | |
395 BrowserGpuChannelHostFactory::AllocateGpuMemoryBuffer(size_t width, | |
396 size_t height, | |
397 unsigned internalformat, | |
398 unsigned usage) { | |
399 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
400 | |
401 AllocateGpuMemoryBufferRequest request( | |
402 width, height, internalformat, usage, gpu_client_id_); | |
403 GetIOLoopProxy()->PostTask( | |
404 FROM_HERE, | |
405 base::Bind(&BrowserGpuChannelHostFactory::AllocateGpuMemoryBufferOnIO, | |
406 base::Unretained(&request))); | |
407 | |
408 // We're blocking the UI thread, which is generally undesirable. | |
409 TRACE_EVENT0("browser", | |
410 "BrowserGpuChannelHostFactory::AllocateGpuMemoryBuffer"); | |
411 base::ThreadRestrictions::ScopedAllowWait allow_wait; | |
412 request.event.Wait(); | |
413 return request.result.Pass(); | |
414 } | |
415 | |
416 // static | 375 // static |
417 void BrowserGpuChannelHostFactory::AddFilterOnIO( | 376 void BrowserGpuChannelHostFactory::AddFilterOnIO( |
418 int host_id, | 377 int host_id, |
419 scoped_refptr<IPC::MessageFilter> filter) { | 378 scoped_refptr<IPC::MessageFilter> filter) { |
420 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 379 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
421 | 380 |
422 GpuProcessHost* host = GpuProcessHost::FromID(host_id); | 381 GpuProcessHost* host = GpuProcessHost::FromID(host_id); |
423 if (host) | 382 if (host) |
424 host->AddFilter(filter.get()); | 383 host->AddFilter(filter.get()); |
425 } | 384 } |
(...skipping 14 matching lines...) Expand all Loading... | |
440 target_task_runner); | 399 target_task_runner); |
441 filter->AddRoute(MSG_ROUTING_CONTROL, handler); | 400 filter->AddRoute(MSG_ROUTING_CONTROL, handler); |
442 | 401 |
443 GetIOLoopProxy()->PostTask( | 402 GetIOLoopProxy()->PostTask( |
444 FROM_HERE, | 403 FROM_HERE, |
445 base::Bind(&BrowserGpuChannelHostFactory::AddFilterOnIO, | 404 base::Bind(&BrowserGpuChannelHostFactory::AddFilterOnIO, |
446 gpu_host_id_, | 405 gpu_host_id_, |
447 filter)); | 406 filter)); |
448 } | 407 } |
449 | 408 |
450 // static | |
451 void BrowserGpuChannelHostFactory::AllocateGpuMemoryBufferOnIO( | |
452 AllocateGpuMemoryBufferRequest* request) { | |
453 if (!GpuMemoryBufferImpl::IsFormatValid(request->internalformat) || | |
454 !GpuMemoryBufferImpl::IsUsageValid(request->usage)) { | |
455 request->result = scoped_ptr<gfx::GpuMemoryBuffer>(); | |
456 request->event.Signal(); | |
457 return; | |
458 } | |
459 | |
460 GpuMemoryBufferImpl::Create( | |
461 gfx::Size(request->width, request->height), | |
462 request->internalformat, | |
463 request->usage, | |
464 request->client_id, | |
465 base::Bind(&BrowserGpuChannelHostFactory::OnGpuMemoryBufferCreated, | |
466 base::Unretained(request))); | |
467 } | |
468 | |
469 // static | |
470 void BrowserGpuChannelHostFactory::OnGpuMemoryBufferCreated( | |
471 AllocateGpuMemoryBufferRequest* request, | |
472 scoped_ptr<GpuMemoryBufferImpl> buffer) { | |
473 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
474 | |
475 request->result = buffer.PassAs<gfx::GpuMemoryBuffer>(); | |
476 request->event.Signal(); | |
477 } | |
478 | |
479 } // namespace content | 409 } // namespace content |
OLD | NEW |