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

Side by Side Diff: gpu/ipc/client/gpu_memory_buffer_impl_shared_memory.cc

Issue 2496783002: gpu: Reuse existing code for shared memory allocation. (Closed)
Patch Set: . Created 4 years, 1 month 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
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 "gpu/ipc/client/gpu_memory_buffer_impl_shared_memory.h" 5 #include "gpu/ipc/client/gpu_memory_buffer_impl_shared_memory.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 return base::WrapUnique(new GpuMemoryBufferImplSharedMemory( 55 return base::WrapUnique(new GpuMemoryBufferImplSharedMemory(
56 id, size, format, callback, std::move(shared_memory), 0, 56 id, size, format, callback, std::move(shared_memory), 0,
57 gfx::RowSizeForBufferFormat(size.width(), format, 0))); 57 gfx::RowSizeForBufferFormat(size.width(), format, 0)));
58 } 58 }
59 59
60 // static 60 // static
61 gfx::GpuMemoryBufferHandle 61 gfx::GpuMemoryBufferHandle
62 GpuMemoryBufferImplSharedMemory::AllocateForChildProcess( 62 GpuMemoryBufferImplSharedMemory::AllocateForChildProcess(
63 gfx::GpuMemoryBufferId id, 63 gfx::GpuMemoryBufferId id,
64 const gfx::Size& size, 64 const gfx::Size& size,
65 gfx::BufferFormat format, 65 gfx::BufferFormat format) {
66 base::ProcessHandle child_process) {
67 size_t buffer_size = 0u; 66 size_t buffer_size = 0u;
68 if (!gfx::BufferSizeForBufferFormatChecked(size, format, &buffer_size)) 67 if (!gfx::BufferSizeForBufferFormatChecked(size, format, &buffer_size))
69 return gfx::GpuMemoryBufferHandle(); 68 return gfx::GpuMemoryBufferHandle();
70 69
71 base::SharedMemory shared_memory; 70 base::SharedMemory shared_memory;
72 if (!shared_memory.CreateAnonymous(buffer_size)) 71 if (!shared_memory.CreateAnonymous(buffer_size))
73 return gfx::GpuMemoryBufferHandle(); 72 return gfx::GpuMemoryBufferHandle();
74 73
75 gfx::GpuMemoryBufferHandle handle; 74 gfx::GpuMemoryBufferHandle handle;
76 handle.type = gfx::SHARED_MEMORY_BUFFER; 75 handle.type = gfx::SHARED_MEMORY_BUFFER;
77 handle.id = id; 76 handle.id = id;
78 handle.offset = 0; 77 handle.offset = 0;
79 handle.stride = static_cast<int32_t>( 78 handle.stride = static_cast<int32_t>(
80 gfx::RowSizeForBufferFormat(size.width(), format, 0)); 79 gfx::RowSizeForBufferFormat(size.width(), format, 0));
81 shared_memory.GiveToProcess(child_process, &handle.handle); 80 handle.handle = shared_memory.TakeHandle();
82 return handle; 81 return handle;
83 } 82 }
84 83
85 // static 84 // static
86 std::unique_ptr<GpuMemoryBufferImplSharedMemory> 85 std::unique_ptr<GpuMemoryBufferImplSharedMemory>
87 GpuMemoryBufferImplSharedMemory::CreateFromHandle( 86 GpuMemoryBufferImplSharedMemory::CreateFromHandle(
88 const gfx::GpuMemoryBufferHandle& handle, 87 const gfx::GpuMemoryBufferHandle& handle,
89 const gfx::Size& size, 88 const gfx::Size& size,
90 gfx::BufferFormat format, 89 gfx::BufferFormat format,
91 gfx::BufferUsage usage, 90 gfx::BufferUsage usage,
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 gfx::GpuMemoryBufferHandle handle; 216 gfx::GpuMemoryBufferHandle handle;
218 handle.type = gfx::SHARED_MEMORY_BUFFER; 217 handle.type = gfx::SHARED_MEMORY_BUFFER;
219 handle.id = id_; 218 handle.id = id_;
220 handle.offset = offset_; 219 handle.offset = offset_;
221 handle.stride = stride_; 220 handle.stride = stride_;
222 handle.handle = shared_memory_->handle(); 221 handle.handle = shared_memory_->handle();
223 return handle; 222 return handle;
224 } 223 }
225 224
226 } // namespace gpu 225 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698