Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(870)

Side by Side Diff: content/browser/gpu/browser_gpu_channel_host_factory.cc

Issue 634083002: gpu: Compositor management of GpuMemoryBuffer instances. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cc-pre-chromium-image-refactor
Patch Set: rebase Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 void BrowserGpuChannelHostFactory::Terminate() { 215 void BrowserGpuChannelHostFactory::Terminate() {
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),
225 gpu_memory_buffer_manager_(
226 new BrowserGpuMemoryBufferManager(gpu_client_id_)),
247 gpu_host_id_(0) { 227 gpu_host_id_(0) {
248 } 228 }
249 229
250 BrowserGpuChannelHostFactory::~BrowserGpuChannelHostFactory() { 230 BrowserGpuChannelHostFactory::~BrowserGpuChannelHostFactory() {
251 DCHECK(IsMainThread()); 231 DCHECK(IsMainThread());
252 if (pending_request_.get()) 232 if (pending_request_.get())
253 pending_request_->Cancel(); 233 pending_request_->Cancel();
254 for (size_t n = 0; n < established_callbacks_.size(); n++) 234 for (size_t n = 0; n < established_callbacks_.size(); n++)
255 established_callbacks_[n].Run(); 235 established_callbacks_[n].Run();
256 shutdown_event_->Signal(); 236 shutdown_event_->Signal();
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 return NULL; 349 return NULL;
370 } 350 }
371 351
372 void BrowserGpuChannelHostFactory::GpuChannelEstablished() { 352 void BrowserGpuChannelHostFactory::GpuChannelEstablished() {
373 DCHECK(IsMainThread()); 353 DCHECK(IsMainThread());
374 DCHECK(pending_request_.get()); 354 DCHECK(pending_request_.get());
375 if (pending_request_->channel_handle().name.empty()) { 355 if (pending_request_->channel_handle().name.empty()) {
376 DCHECK(!gpu_channel_.get()); 356 DCHECK(!gpu_channel_.get());
377 } else { 357 } else {
378 GetContentClient()->SetGpuInfo(pending_request_->gpu_info()); 358 GetContentClient()->SetGpuInfo(pending_request_->gpu_info());
379 gpu_channel_ = GpuChannelHost::Create(this, 359 gpu_channel_ =
380 pending_request_->gpu_info(), 360 GpuChannelHost::Create(this,
381 pending_request_->channel_handle(), 361 pending_request_->gpu_info(),
382 shutdown_event_.get()); 362 pending_request_->channel_handle(),
363 shutdown_event_.get(),
364 BrowserGpuMemoryBufferManager::current());
383 } 365 }
384 gpu_host_id_ = pending_request_->gpu_host_id(); 366 gpu_host_id_ = pending_request_->gpu_host_id();
385 gpu_memory_buffer_factory_host_->set_gpu_host_id(gpu_host_id_); 367 gpu_memory_buffer_factory_host_->set_gpu_host_id(gpu_host_id_);
386 pending_request_ = NULL; 368 pending_request_ = NULL;
387 369
388 for (size_t n = 0; n < established_callbacks_.size(); n++) 370 for (size_t n = 0; n < established_callbacks_.size(); n++)
389 established_callbacks_[n].Run(); 371 established_callbacks_[n].Run();
390 372
391 established_callbacks_.clear(); 373 established_callbacks_.clear();
392 } 374 }
393 375
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 376 // static
417 void BrowserGpuChannelHostFactory::AddFilterOnIO( 377 void BrowserGpuChannelHostFactory::AddFilterOnIO(
418 int host_id, 378 int host_id,
419 scoped_refptr<IPC::MessageFilter> filter) { 379 scoped_refptr<IPC::MessageFilter> filter) {
420 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 380 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
421 381
422 GpuProcessHost* host = GpuProcessHost::FromID(host_id); 382 GpuProcessHost* host = GpuProcessHost::FromID(host_id);
423 if (host) 383 if (host)
424 host->AddFilter(filter.get()); 384 host->AddFilter(filter.get());
425 } 385 }
(...skipping 14 matching lines...) Expand all
440 target_task_runner); 400 target_task_runner);
441 filter->AddRoute(MSG_ROUTING_CONTROL, handler); 401 filter->AddRoute(MSG_ROUTING_CONTROL, handler);
442 402
443 GetIOLoopProxy()->PostTask( 403 GetIOLoopProxy()->PostTask(
444 FROM_HERE, 404 FROM_HERE,
445 base::Bind(&BrowserGpuChannelHostFactory::AddFilterOnIO, 405 base::Bind(&BrowserGpuChannelHostFactory::AddFilterOnIO,
446 gpu_host_id_, 406 gpu_host_id_,
447 filter)); 407 filter));
448 } 408 }
449 409
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 410 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/gpu/browser_gpu_channel_host_factory.h ('k') | content/browser/gpu/browser_gpu_memory_buffer_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698