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

Side by Side Diff: content/common/gpu/client/gpu_memory_buffer_impl_shm.cc

Issue 290573011: Delay the response to ChildProcessHostMsg_SyncAllocateGpuMemoryBuffer via a callback to allow for b… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nits Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/common/gpu/client/gpu_memory_buffer_impl_shm.h" 5 #include "content/common/gpu/client/gpu_memory_buffer_impl_shm.h"
6 6
7 #include "base/numerics/safe_math.h" 7 #include "base/numerics/safe_math.h"
8 #include "ui/gl/gl_bindings.h" 8 #include "ui/gl/gl_bindings.h"
9 9
10 namespace content { 10 namespace content {
11 11
12 GpuMemoryBufferImplShm::GpuMemoryBufferImplShm(const gfx::Size& size, 12 GpuMemoryBufferImplShm::GpuMemoryBufferImplShm(const gfx::Size& size,
13 unsigned internalformat) 13 unsigned internalformat)
14 : GpuMemoryBufferImpl(size, internalformat) {} 14 : GpuMemoryBufferImpl(size, internalformat) {}
15 15
16 GpuMemoryBufferImplShm::~GpuMemoryBufferImplShm() {} 16 GpuMemoryBufferImplShm::~GpuMemoryBufferImplShm() {}
17 17
18 // static 18 // static
19 void GpuMemoryBufferImplShm::AllocateSharedMemoryForChildProcess( 19 void GpuMemoryBufferImplShm::AllocateSharedMemoryForChildProcess(
20 const gfx::Size& size, 20 const gfx::Size& size,
21 unsigned internalformat, 21 unsigned internalformat,
22 base::ProcessHandle child_process, 22 base::ProcessHandle child_process,
23 gfx::GpuMemoryBufferHandle* handle) { 23 const AllocationCallback& callback) {
24 DCHECK(IsLayoutSupported(size, internalformat)); 24 DCHECK(IsLayoutSupported(size, internalformat));
25 gfx::GpuMemoryBufferHandle handle;
25 base::SharedMemory shared_memory; 26 base::SharedMemory shared_memory;
26 if (!shared_memory.CreateAnonymous(size.GetArea() * 27 if (!shared_memory.CreateAnonymous(size.GetArea() *
27 BytesPerPixel(internalformat))) { 28 BytesPerPixel(internalformat))) {
28 handle->type = gfx::EMPTY_BUFFER; 29 handle.type = gfx::EMPTY_BUFFER;
29 return; 30 return;
30 } 31 }
31 handle->type = gfx::SHARED_MEMORY_BUFFER; 32 handle.type = gfx::SHARED_MEMORY_BUFFER;
32 shared_memory.GiveToProcess(child_process, &handle->handle); 33 shared_memory.GiveToProcess(child_process, &handle.handle);
34 callback.Run(handle);
33 } 35 }
34 36
35 // static 37 // static
36 bool GpuMemoryBufferImplShm::IsLayoutSupported(const gfx::Size& size, 38 bool GpuMemoryBufferImplShm::IsLayoutSupported(const gfx::Size& size,
37 unsigned internalformat) { 39 unsigned internalformat) {
38 base::CheckedNumeric<int> buffer_size = size.width(); 40 base::CheckedNumeric<int> buffer_size = size.width();
39 buffer_size *= size.height(); 41 buffer_size *= size.height();
40 buffer_size *= BytesPerPixel(internalformat); 42 buffer_size *= BytesPerPixel(internalformat);
41 return buffer_size.IsValid(); 43 return buffer_size.IsValid();
42 } 44 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 } 100 }
99 101
100 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplShm::GetHandle() const { 102 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplShm::GetHandle() const {
101 gfx::GpuMemoryBufferHandle handle; 103 gfx::GpuMemoryBufferHandle handle;
102 handle.type = gfx::SHARED_MEMORY_BUFFER; 104 handle.type = gfx::SHARED_MEMORY_BUFFER;
103 handle.handle = shared_memory_->handle(); 105 handle.handle = shared_memory_->handle();
104 return handle; 106 return handle;
105 } 107 }
106 108
107 } // namespace content 109 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698