| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_memory_buffer_manager.h" | 5 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
| 11 #include "base/threading/thread_restrictions.h" | 11 #include "base/threading/thread_restrictions.h" |
| 12 #include "base/trace_event/process_memory_dump.h" | 12 #include "base/trace_event/process_memory_dump.h" |
| 13 #include "base/trace_event/trace_event.h" | 13 #include "base/trace_event/trace_event.h" |
| 14 #include "build/build_config.h" |
| 14 #include "content/browser/gpu/gpu_process_host.h" | 15 #include "content/browser/gpu/gpu_process_host.h" |
| 15 #include "content/common/child_process_host_impl.h" | 16 #include "content/common/child_process_host_impl.h" |
| 16 #include "content/common/generic_shared_memory_id_generator.h" | 17 #include "content/common/generic_shared_memory_id_generator.h" |
| 17 #include "content/common/gpu/client/gpu_memory_buffer_impl.h" | 18 #include "content/common/gpu/client/gpu_memory_buffer_impl.h" |
| 18 #include "content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.h" | 19 #include "content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.h" |
| 19 #include "content/common/gpu/gpu_memory_buffer_factory.h" | 20 #include "content/common/gpu/gpu_memory_buffer_factory.h" |
| 20 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 21 #include "content/public/common/content_switches.h" | 22 #include "content/public/common/content_switches.h" |
| 22 #include "gpu/GLES2/gl2extchromium.h" | 23 #include "gpu/GLES2/gl2extchromium.h" |
| 23 #include "ui/gfx/buffer_format_util.h" | 24 #include "ui/gfx/buffer_format_util.h" |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 #if defined(OS_MACOSX) | 220 #if defined(OS_MACOSX) |
| 220 return !base::CommandLine::ForCurrentProcess()->HasSwitch( | 221 return !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 221 switches::kDisableNativeGpuMemoryBuffers); | 222 switches::kDisableNativeGpuMemoryBuffers); |
| 222 #else | 223 #else |
| 223 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 224 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 224 switches::kEnableNativeGpuMemoryBuffers); | 225 switches::kEnableNativeGpuMemoryBuffers); |
| 225 #endif | 226 #endif |
| 226 } | 227 } |
| 227 | 228 |
| 228 // static | 229 // static |
| 229 uint32 BrowserGpuMemoryBufferManager::GetImageTextureTarget( | 230 uint32_t BrowserGpuMemoryBufferManager::GetImageTextureTarget( |
| 230 gfx::BufferFormat format, | 231 gfx::BufferFormat format, |
| 231 gfx::BufferUsage usage) { | 232 gfx::BufferUsage usage) { |
| 232 GpuMemoryBufferConfigurationSet native_configurations = | 233 GpuMemoryBufferConfigurationSet native_configurations = |
| 233 GetNativeGpuMemoryBufferConfigurations(); | 234 GetNativeGpuMemoryBufferConfigurations(); |
| 234 if (native_configurations.find(std::make_pair(format, usage)) == | 235 if (native_configurations.find(std::make_pair(format, usage)) == |
| 235 native_configurations.end()) { | 236 native_configurations.end()) { |
| 236 return GL_TEXTURE_2D; | 237 return GL_TEXTURE_2D; |
| 237 } | 238 } |
| 238 | 239 |
| 239 switch (GpuMemoryBufferFactory::GetNativeType()) { | 240 switch (GpuMemoryBufferFactory::GetNativeType()) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 "BrowserGpuMemoryBufferManager::CreateGpuMemoryBufferFromHandle"); | 286 "BrowserGpuMemoryBufferManager::CreateGpuMemoryBufferFromHandle"); |
| 286 base::ThreadRestrictions::ScopedAllowWait allow_wait; | 287 base::ThreadRestrictions::ScopedAllowWait allow_wait; |
| 287 request.event.Wait(); | 288 request.event.Wait(); |
| 288 return request.result.Pass(); | 289 return request.result.Pass(); |
| 289 } | 290 } |
| 290 | 291 |
| 291 scoped_ptr<gfx::GpuMemoryBuffer> | 292 scoped_ptr<gfx::GpuMemoryBuffer> |
| 292 BrowserGpuMemoryBufferManager::AllocateGpuMemoryBufferForScanout( | 293 BrowserGpuMemoryBufferManager::AllocateGpuMemoryBufferForScanout( |
| 293 const gfx::Size& size, | 294 const gfx::Size& size, |
| 294 gfx::BufferFormat format, | 295 gfx::BufferFormat format, |
| 295 int32 surface_id) { | 296 int32_t surface_id) { |
| 296 DCHECK_GT(surface_id, 0); | 297 DCHECK_GT(surface_id, 0); |
| 297 return AllocateGpuMemoryBufferForSurface( | 298 return AllocateGpuMemoryBufferForSurface( |
| 298 size, format, gfx::BufferUsage::SCANOUT, surface_id); | 299 size, format, gfx::BufferUsage::SCANOUT, surface_id); |
| 299 } | 300 } |
| 300 | 301 |
| 301 void BrowserGpuMemoryBufferManager::AllocateGpuMemoryBufferForChildProcess( | 302 void BrowserGpuMemoryBufferManager::AllocateGpuMemoryBufferForChildProcess( |
| 302 gfx::GpuMemoryBufferId id, | 303 gfx::GpuMemoryBufferId id, |
| 303 const gfx::Size& size, | 304 const gfx::Size& size, |
| 304 gfx::BufferFormat format, | 305 gfx::BufferFormat format, |
| 305 gfx::BufferUsage usage, | 306 gfx::BufferUsage usage, |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 size_t buffer_size_in_bytes = gfx::BufferSizeForBufferFormat( | 375 size_t buffer_size_in_bytes = gfx::BufferSizeForBufferFormat( |
| 375 buffer.second.size, buffer.second.format); | 376 buffer.second.size, buffer.second.format); |
| 376 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | 377 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, |
| 377 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | 378 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
| 378 buffer_size_in_bytes); | 379 buffer_size_in_bytes); |
| 379 | 380 |
| 380 // Create the cross-process ownership edge. If the client creates a | 381 // Create the cross-process ownership edge. If the client creates a |
| 381 // corresponding dump for the same buffer, this will avoid to | 382 // corresponding dump for the same buffer, this will avoid to |
| 382 // double-count them in tracing. If, instead, no other process will emit a | 383 // double-count them in tracing. If, instead, no other process will emit a |
| 383 // dump with the same guid, the segment will be accounted to the browser. | 384 // dump with the same guid, the segment will be accounted to the browser. |
| 384 uint64 client_tracing_process_id = ClientIdToTracingProcessId(client_id); | 385 uint64_t client_tracing_process_id = |
| 386 ClientIdToTracingProcessId(client_id); |
| 385 | 387 |
| 386 base::trace_event::MemoryAllocatorDumpGuid shared_buffer_guid = | 388 base::trace_event::MemoryAllocatorDumpGuid shared_buffer_guid = |
| 387 gfx::GetGpuMemoryBufferGUIDForTracing(client_tracing_process_id, | 389 gfx::GetGpuMemoryBufferGUIDForTracing(client_tracing_process_id, |
| 388 buffer_id); | 390 buffer_id); |
| 389 pmd->CreateSharedGlobalAllocatorDump(shared_buffer_guid); | 391 pmd->CreateSharedGlobalAllocatorDump(shared_buffer_guid); |
| 390 pmd->AddOwnershipEdge(dump->guid(), shared_buffer_guid); | 392 pmd->AddOwnershipEdge(dump->guid(), shared_buffer_guid); |
| 391 } | 393 } |
| 392 } | 394 } |
| 393 | 395 |
| 394 return true; | 396 return true; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 gfx::BufferUsage usage) const { | 435 gfx::BufferUsage usage) const { |
| 434 return native_configurations_.find(std::make_pair(format, usage)) != | 436 return native_configurations_.find(std::make_pair(format, usage)) != |
| 435 native_configurations_.end(); | 437 native_configurations_.end(); |
| 436 } | 438 } |
| 437 | 439 |
| 438 scoped_ptr<gfx::GpuMemoryBuffer> | 440 scoped_ptr<gfx::GpuMemoryBuffer> |
| 439 BrowserGpuMemoryBufferManager::AllocateGpuMemoryBufferForSurface( | 441 BrowserGpuMemoryBufferManager::AllocateGpuMemoryBufferForSurface( |
| 440 const gfx::Size& size, | 442 const gfx::Size& size, |
| 441 gfx::BufferFormat format, | 443 gfx::BufferFormat format, |
| 442 gfx::BufferUsage usage, | 444 gfx::BufferUsage usage, |
| 443 int32 surface_id) { | 445 int32_t surface_id) { |
| 444 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); | 446 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 445 | 447 |
| 446 CreateGpuMemoryBufferRequest request(size, format, usage, gpu_client_id_, | 448 CreateGpuMemoryBufferRequest request(size, format, usage, gpu_client_id_, |
| 447 surface_id); | 449 surface_id); |
| 448 BrowserThread::PostTask( | 450 BrowserThread::PostTask( |
| 449 BrowserThread::IO, FROM_HERE, | 451 BrowserThread::IO, FROM_HERE, |
| 450 base::Bind( | 452 base::Bind( |
| 451 &BrowserGpuMemoryBufferManager::HandleCreateGpuMemoryBufferOnIO, | 453 &BrowserGpuMemoryBufferManager::HandleCreateGpuMemoryBufferOnIO, |
| 452 base::Unretained(this), // Safe as we wait for result below. | 454 base::Unretained(this), // Safe as we wait for result below. |
| 453 base::Unretained(&request))); | 455 base::Unretained(&request))); |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 743 return gpu_client_tracing_id_; | 745 return gpu_client_tracing_id_; |
| 744 } | 746 } |
| 745 | 747 |
| 746 // In normal cases, |client_id| is a child process id, so we can perform | 748 // In normal cases, |client_id| is a child process id, so we can perform |
| 747 // the standard conversion. | 749 // the standard conversion. |
| 748 return ChildProcessHostImpl::ChildProcessUniqueIdToTracingProcessId( | 750 return ChildProcessHostImpl::ChildProcessUniqueIdToTracingProcessId( |
| 749 client_id); | 751 client_id); |
| 750 } | 752 } |
| 751 | 753 |
| 752 } // namespace content | 754 } // namespace content |
| OLD | NEW |