Chromium Code Reviews| 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/atomic_sequence_num.h" | 7 #include "base/atomic_sequence_num.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 11 #include "base/synchronization/waitable_event.h" | 11 #include "base/synchronization/waitable_event.h" |
| 12 #include "base/threading/thread_restrictions.h" | 12 #include "base/threading/thread_restrictions.h" |
| 13 #include "content/common/gpu/client/gpu_memory_buffer_impl.h" | 13 #include "content/common/gpu/client/gpu_memory_buffer_impl.h" |
| 14 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 15 | 15 |
| 16 namespace content { | 16 namespace content { |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 // Note: To keep things simple this function will only return one out of two | |
| 20 // types; the preferred GPU memory buffer type or the shared memory type. | |
| 21 gfx::GpuMemoryBufferType GetPreferredGpuMemoryBufferTypeForConfiguration( | |
| 22 gfx::GpuMemoryBuffer::Format format, | |
| 23 gfx::GpuMemoryBuffer::Usage usage) { | |
| 24 // First check if this configuration is supported by the preferred type. | |
| 25 if (GpuMemoryBufferImpl::IsConfigurationSupported( | |
| 26 GpuMemoryBufferImpl::GetPreferredType(), format, usage)) { | |
| 27 return GpuMemoryBufferImpl::GetPreferredType(); | |
| 28 } | |
| 29 | |
| 30 // If configuration is not supported by the preferred type, use shared | |
| 31 // memory type if it supports this configuration. | |
| 32 if (GpuMemoryBufferImpl::IsConfigurationSupported( | |
| 33 gfx::SHARED_MEMORY_BUFFER, format, usage)) { | |
| 34 return gfx::SHARED_MEMORY_BUFFER; | |
| 35 } | |
| 36 | |
| 37 return gfx::EMPTY_BUFFER; | |
| 38 } | |
| 39 | |
| 19 BrowserGpuMemoryBufferManager* g_gpu_memory_buffer_manager = nullptr; | 40 BrowserGpuMemoryBufferManager* g_gpu_memory_buffer_manager = nullptr; |
| 20 | 41 |
| 21 // Global atomic to generate gpu memory buffer unique IDs. | 42 // Global atomic to generate gpu memory buffer unique IDs. |
| 22 base::StaticAtomicSequenceNumber g_next_gpu_memory_buffer_id; | 43 base::StaticAtomicSequenceNumber g_next_gpu_memory_buffer_id; |
| 23 | 44 |
| 24 } // namespace | 45 } // namespace |
| 25 | 46 |
| 26 struct BrowserGpuMemoryBufferManager::AllocateGpuMemoryBufferRequest { | 47 struct BrowserGpuMemoryBufferManager::AllocateGpuMemoryBufferRequest { |
| 27 AllocateGpuMemoryBufferRequest(const gfx::Size& size, | 48 AllocateGpuMemoryBufferRequest(const gfx::Size& size, |
| 28 gfx::GpuMemoryBuffer::Format format, | 49 gfx::GpuMemoryBuffer::Format format, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 81 | 102 |
| 82 void BrowserGpuMemoryBufferManager::AllocateGpuMemoryBufferForChildProcess( | 103 void BrowserGpuMemoryBufferManager::AllocateGpuMemoryBufferForChildProcess( |
| 83 const gfx::Size& size, | 104 const gfx::Size& size, |
| 84 gfx::GpuMemoryBuffer::Format format, | 105 gfx::GpuMemoryBuffer::Format format, |
| 85 gfx::GpuMemoryBuffer::Usage usage, | 106 gfx::GpuMemoryBuffer::Usage usage, |
| 86 base::ProcessHandle child_process_handle, | 107 base::ProcessHandle child_process_handle, |
| 87 int child_client_id, | 108 int child_client_id, |
| 88 const AllocationCallback& callback) { | 109 const AllocationCallback& callback) { |
| 89 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 110 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 90 | 111 |
| 112 // Determine what GPU memory buffer type to use and early out if |format| and | |
| 113 // |usage| configuration is not supported. | |
| 114 gfx::GpuMemoryBufferType type = | |
| 115 GetPreferredGpuMemoryBufferTypeForConfiguration(format, usage); | |
| 116 if (type == gfx::EMPTY_BUFFER) { | |
| 117 callback.Run(gfx::GpuMemoryBufferHandle()); | |
| 118 return; | |
| 119 } | |
| 120 | |
| 91 gfx::GpuMemoryBufferId new_id = g_next_gpu_memory_buffer_id.GetNext(); | 121 gfx::GpuMemoryBufferId new_id = g_next_gpu_memory_buffer_id.GetNext(); |
| 92 | 122 |
| 93 BufferMap& buffers = clients_[child_client_id]; | 123 BufferMap& buffers = clients_[child_client_id]; |
| 94 DCHECK(buffers.find(new_id) == buffers.end()); | 124 DCHECK(buffers.find(new_id) == buffers.end()); |
| 95 | 125 |
| 96 // Note: Handling of cases where the child process is removed before the | 126 // Note: Handling of cases where the child process is removed before the |
| 97 // allocation completes is less subtle if we set the buffer type to | 127 // allocation completes is less subtle if we set the buffer type to |
| 98 // EMPTY_BUFFER here and verify that this has not changed when allocation | 128 // EMPTY_BUFFER here and verify that this has not changed when allocation |
| 99 // completes. | 129 // completes. |
| 100 buffers[new_id] = gfx::EMPTY_BUFFER; | 130 buffers[new_id] = gfx::EMPTY_BUFFER; |
| 101 | 131 |
| 102 GpuMemoryBufferImpl::AllocateForChildProcess( | 132 GpuMemoryBufferImpl::AllocateForChildProcess( |
| 133 type, | |
| 103 new_id, | 134 new_id, |
| 104 size, | 135 size, |
| 105 format, | 136 format, |
| 106 usage, | 137 usage, |
| 107 child_process_handle, | 138 child_process_handle, |
| 108 child_client_id, | 139 child_client_id, |
| 109 base::Bind(&BrowserGpuMemoryBufferManager:: | 140 base::Bind(&BrowserGpuMemoryBufferManager:: |
| 110 GpuMemoryBufferAllocatedForChildProcess, | 141 GpuMemoryBufferAllocatedForChildProcess, |
| 111 base::Unretained(this), | 142 base::Unretained(this), |
| 112 child_process_handle, | 143 child_process_handle, |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 // Store the type for this buffer so it can be cleaned up if the child | 251 // Store the type for this buffer so it can be cleaned up if the child |
| 221 // process is removed. | 252 // process is removed. |
| 222 buffer_it->second = handle.type; | 253 buffer_it->second = handle.type; |
| 223 | 254 |
| 224 callback.Run(handle); | 255 callback.Run(handle); |
| 225 } | 256 } |
| 226 | 257 |
| 227 // static | 258 // static |
| 228 void BrowserGpuMemoryBufferManager::AllocateGpuMemoryBufferOnIO( | 259 void BrowserGpuMemoryBufferManager::AllocateGpuMemoryBufferOnIO( |
| 229 AllocateGpuMemoryBufferRequest* request) { | 260 AllocateGpuMemoryBufferRequest* request) { |
| 261 | |
|
reveman
2014/11/11 19:07:45
hm, this blank line should not be here.
| |
| 230 GpuMemoryBufferImpl::Create( | 262 GpuMemoryBufferImpl::Create( |
| 263 GetPreferredGpuMemoryBufferTypeForConfiguration( | |
|
alexst (slow to review)
2014/11/11 18:49:23
Should this early out in BrowserGpuMemoryBufferMan
reveman
2014/11/11 19:07:44
I think we should consider it a browser bug if thi
| |
| 264 request->format, request->usage), | |
| 231 g_next_gpu_memory_buffer_id.GetNext(), | 265 g_next_gpu_memory_buffer_id.GetNext(), |
| 232 request->size, | 266 request->size, |
| 233 request->format, | 267 request->format, |
| 234 request->usage, | 268 request->usage, |
| 235 request->client_id, | 269 request->client_id, |
| 236 base::Bind(&BrowserGpuMemoryBufferManager::GpuMemoryBufferCreatedOnIO, | 270 base::Bind(&BrowserGpuMemoryBufferManager::GpuMemoryBufferCreatedOnIO, |
| 237 base::Unretained(request))); | 271 base::Unretained(request))); |
| 238 } | 272 } |
| 239 | 273 |
| 240 // static | 274 // static |
| 241 void BrowserGpuMemoryBufferManager::GpuMemoryBufferCreatedOnIO( | 275 void BrowserGpuMemoryBufferManager::GpuMemoryBufferCreatedOnIO( |
| 242 AllocateGpuMemoryBufferRequest* request, | 276 AllocateGpuMemoryBufferRequest* request, |
| 243 scoped_ptr<GpuMemoryBufferImpl> buffer) { | 277 scoped_ptr<GpuMemoryBufferImpl> buffer) { |
| 244 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 278 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 245 | 279 |
| 246 request->result = buffer.Pass(); | 280 request->result = buffer.Pass(); |
| 247 request->event.Signal(); | 281 request->event.Signal(); |
| 248 } | 282 } |
| 249 | 283 |
| 250 } // namespace content | 284 } // namespace content |
| OLD | NEW |