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/threading/thread_restrictions.h" | 9 #include "base/threading/thread_restrictions.h" |
10 #include "content/browser/gpu/gpu_data_manager_impl.h" | 10 #include "content/browser/gpu/gpu_data_manager_impl.h" |
11 #include "content/browser/gpu/gpu_process_host.h" | 11 #include "content/browser/gpu/gpu_process_host.h" |
12 #include "content/browser/gpu/gpu_surface_tracker.h" | 12 #include "content/browser/gpu/gpu_surface_tracker.h" |
13 #include "content/common/child_process_host_impl.h" | 13 #include "content/common/child_process_host_impl.h" |
14 #include "content/common/gpu/client/gpu_memory_buffer_impl_shm.h" | 14 #include "content/common/gpu/client/gpu_memory_buffer_impl.h" |
15 #include "content/common/gpu/gpu_messages.h" | 15 #include "content/common/gpu/gpu_messages.h" |
16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
17 #include "content/public/browser/gpu_data_manager.h" | 17 #include "content/public/browser/gpu_data_manager.h" |
18 #include "content/public/common/content_client.h" | 18 #include "content/public/common/content_client.h" |
19 #include "ipc/ipc_forwarding_message_filter.h" | 19 #include "ipc/ipc_forwarding_message_filter.h" |
20 #include "ipc/message_filter.h" | 20 #include "ipc/message_filter.h" |
21 | 21 |
22 namespace content { | 22 namespace content { |
23 | 23 |
24 BrowserGpuChannelHostFactory* BrowserGpuChannelHostFactory::instance_ = NULL; | 24 BrowserGpuChannelHostFactory* BrowserGpuChannelHostFactory::instance_ = NULL; |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 } | 376 } |
377 | 377 |
378 scoped_ptr<gfx::GpuMemoryBuffer> | 378 scoped_ptr<gfx::GpuMemoryBuffer> |
379 BrowserGpuChannelHostFactory::AllocateGpuMemoryBuffer( | 379 BrowserGpuChannelHostFactory::AllocateGpuMemoryBuffer( |
380 size_t width, | 380 size_t width, |
381 size_t height, | 381 size_t height, |
382 unsigned internalformat) { | 382 unsigned internalformat) { |
383 if (!GpuMemoryBufferImpl::IsFormatValid(internalformat)) | 383 if (!GpuMemoryBufferImpl::IsFormatValid(internalformat)) |
384 return scoped_ptr<gfx::GpuMemoryBuffer>(); | 384 return scoped_ptr<gfx::GpuMemoryBuffer>(); |
385 | 385 |
386 size_t size = width * height * | 386 return GpuMemoryBufferImpl::Create(gfx::Size(width, height), internalformat) |
387 GpuMemoryBufferImpl::BytesPerPixel(internalformat); | 387 .PassAs<gfx::GpuMemoryBuffer>(); |
388 scoped_ptr<base::SharedMemory> shm(new base::SharedMemory()); | |
389 if (!shm->CreateAnonymous(size)) | |
390 return scoped_ptr<gfx::GpuMemoryBuffer>(); | |
391 | |
392 scoped_ptr<GpuMemoryBufferImplShm> buffer( | |
393 new GpuMemoryBufferImplShm(gfx::Size(width, height), internalformat)); | |
394 if (!buffer->InitializeFromSharedMemory(shm.Pass())) | |
395 return scoped_ptr<gfx::GpuMemoryBuffer>(); | |
396 | |
397 return buffer.PassAs<gfx::GpuMemoryBuffer>(); | |
398 } | 388 } |
399 | 389 |
400 // static | 390 // static |
401 void BrowserGpuChannelHostFactory::AddFilterOnIO( | 391 void BrowserGpuChannelHostFactory::AddFilterOnIO( |
402 int host_id, | 392 int host_id, |
403 scoped_refptr<IPC::MessageFilter> filter) { | 393 scoped_refptr<IPC::MessageFilter> filter) { |
404 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 394 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
405 | 395 |
406 GpuProcessHost* host = GpuProcessHost::FromID(host_id); | 396 GpuProcessHost* host = GpuProcessHost::FromID(host_id); |
407 if (host) | 397 if (host) |
(...skipping 17 matching lines...) Expand all Loading... |
425 filter->AddRoute(MSG_ROUTING_CONTROL, handler); | 415 filter->AddRoute(MSG_ROUTING_CONTROL, handler); |
426 | 416 |
427 GetIOLoopProxy()->PostTask( | 417 GetIOLoopProxy()->PostTask( |
428 FROM_HERE, | 418 FROM_HERE, |
429 base::Bind(&BrowserGpuChannelHostFactory::AddFilterOnIO, | 419 base::Bind(&BrowserGpuChannelHostFactory::AddFilterOnIO, |
430 gpu_host_id_, | 420 gpu_host_id_, |
431 filter)); | 421 filter)); |
432 } | 422 } |
433 | 423 |
434 } // namespace content | 424 } // namespace content |
OLD | NEW |