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

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

Issue 1166213003: content: Handle native GpuMemoryBuffer allocation failures properly. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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
« no previous file with comments | « content/browser/gpu/browser_gpu_memory_buffer_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "base/synchronization/waitable_event.h" 10 #include "base/synchronization/waitable_event.h"
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 // Note: Handling of cases where the child process is removed before the 158 // Note: Handling of cases where the child process is removed before the
159 // allocation completes is less subtle if we set the buffer type to 159 // allocation completes is less subtle if we set the buffer type to
160 // EMPTY_BUFFER here and verify that this has not changed when allocation 160 // EMPTY_BUFFER here and verify that this has not changed when allocation
161 // completes. 161 // completes.
162 buffers[new_id] = BufferInfo(size, format, gfx::EMPTY_BUFFER); 162 buffers[new_id] = BufferInfo(size, format, gfx::EMPTY_BUFFER);
163 163
164 gpu_memory_buffer_factory_host_->CreateGpuMemoryBuffer( 164 gpu_memory_buffer_factory_host_->CreateGpuMemoryBuffer(
165 new_id, size, format, usage, child_client_id, 0, 165 new_id, size, format, usage, child_client_id, 0,
166 base::Bind(&BrowserGpuMemoryBufferManager:: 166 base::Bind(&BrowserGpuMemoryBufferManager::
167 GpuMemoryBufferAllocatedForChildProcess, 167 GpuMemoryBufferAllocatedForChildProcess,
168 weak_ptr_factory_.GetWeakPtr(), child_client_id, callback)); 168 weak_ptr_factory_.GetWeakPtr(), new_id, child_client_id,
169 callback));
169 } 170 }
170 171
171 gfx::GpuMemoryBuffer* 172 gfx::GpuMemoryBuffer*
172 BrowserGpuMemoryBufferManager::GpuMemoryBufferFromClientBuffer( 173 BrowserGpuMemoryBufferManager::GpuMemoryBufferFromClientBuffer(
173 ClientBuffer buffer) { 174 ClientBuffer buffer) {
174 return GpuMemoryBufferImpl::FromClientBuffer(buffer); 175 return GpuMemoryBufferImpl::FromClientBuffer(buffer);
175 } 176 }
176 177
177 void BrowserGpuMemoryBufferManager::SetDestructionSyncPoint( 178 void BrowserGpuMemoryBufferManager::SetDestructionSyncPoint(
178 gfx::GpuMemoryBuffer* buffer, 179 gfx::GpuMemoryBuffer* buffer,
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 void BrowserGpuMemoryBufferManager::GpuMemoryBufferDeleted( 308 void BrowserGpuMemoryBufferManager::GpuMemoryBufferDeleted(
308 gfx::GpuMemoryBufferId id, 309 gfx::GpuMemoryBufferId id,
309 int client_id, 310 int client_id,
310 uint32 sync_point) { 311 uint32 sync_point) {
311 gpu_memory_buffer_factory_host_->DestroyGpuMemoryBuffer(id, 312 gpu_memory_buffer_factory_host_->DestroyGpuMemoryBuffer(id,
312 client_id, 313 client_id,
313 sync_point); 314 sync_point);
314 } 315 }
315 316
316 void BrowserGpuMemoryBufferManager::GpuMemoryBufferAllocatedForChildProcess( 317 void BrowserGpuMemoryBufferManager::GpuMemoryBufferAllocatedForChildProcess(
318 gfx::GpuMemoryBufferId id,
317 int child_client_id, 319 int child_client_id,
318 const AllocationCallback& callback, 320 const AllocationCallback& callback,
319 const gfx::GpuMemoryBufferHandle& handle) { 321 const gfx::GpuMemoryBufferHandle& handle) {
320 DCHECK_CURRENTLY_ON(BrowserThread::IO); 322 DCHECK_CURRENTLY_ON(BrowserThread::IO);
321 323
322 ClientMap::iterator client_it = clients_.find(child_client_id); 324 ClientMap::iterator client_it = clients_.find(child_client_id);
323 325
324 // This can happen if the child process is removed while the buffer is being 326 // This can happen if the child process is removed while the buffer is being
325 // allocated. 327 // allocated.
326 if (client_it == clients_.end()) { 328 if (client_it == clients_.end()) {
327 if (!handle.is_null()) { 329 if (!handle.is_null()) {
328 gpu_memory_buffer_factory_host_->DestroyGpuMemoryBuffer( 330 gpu_memory_buffer_factory_host_->DestroyGpuMemoryBuffer(
329 handle.id, child_client_id, 0); 331 handle.id, child_client_id, 0);
330 } 332 }
331 callback.Run(gfx::GpuMemoryBufferHandle()); 333 callback.Run(gfx::GpuMemoryBufferHandle());
332 return; 334 return;
333 } 335 }
334 336
335 BufferMap& buffers = client_it->second; 337 BufferMap& buffers = client_it->second;
336 338
337 BufferMap::iterator buffer_it = buffers.find(handle.id); 339 BufferMap::iterator buffer_it = buffers.find(id);
338 DCHECK(buffer_it != buffers.end()); 340 DCHECK(buffer_it != buffers.end());
339 DCHECK_EQ(buffer_it->second.type, gfx::EMPTY_BUFFER); 341 DCHECK_EQ(buffer_it->second.type, gfx::EMPTY_BUFFER);
340 342
341 if (handle.is_null()) { 343 // The factory should never return a shared memory backed buffer.
Avi (use Gerrit) 2015/06/10 17:01:47 "Should never" implies DCHECK, that it shouldn't h
reveman 2015/06/10 18:32:09 Good point. Done.
344 bool valid_handle = !handle.is_null() && handle.id == id &&
345 handle.type != gfx::SHARED_MEMORY_BUFFER;
346 if (!valid_handle) {
342 buffers.erase(buffer_it); 347 buffers.erase(buffer_it);
343 callback.Run(gfx::GpuMemoryBufferHandle()); 348 callback.Run(gfx::GpuMemoryBufferHandle());
344 return; 349 return;
345 } 350 }
346 351
347 // The factory should never return a shared memory backed buffer.
348 DCHECK_NE(handle.type, gfx::SHARED_MEMORY_BUFFER);
349
350 // Store the type of this buffer so it can be cleaned up if the child 352 // Store the type of this buffer so it can be cleaned up if the child
351 // process is removed. 353 // process is removed.
352 buffer_it->second.type = handle.type; 354 buffer_it->second.type = handle.type;
353 355
354 callback.Run(handle); 356 callback.Run(handle);
355 } 357 }
356 358
357 } // namespace content 359 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/gpu/browser_gpu_memory_buffer_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698