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

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

Issue 1859703002: convert //gpu to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase on master Created 4 years, 8 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
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"
11 #include "base/memory/ptr_util.h"
11 #include "base/numerics/safe_math.h" 12 #include "base/numerics/safe_math.h"
12 #include "base/process/memory.h" 13 #include "base/process/memory.h"
13 #include "ui/gfx/buffer_format_util.h" 14 #include "ui/gfx/buffer_format_util.h"
14 #include "ui/gl/gl_bindings.h" 15 #include "ui/gl/gl_bindings.h"
15 16
16 namespace gpu { 17 namespace gpu {
17 namespace { 18 namespace {
18 19
19 void Noop() {} 20 void Noop() {}
20 21
21 } // namespace 22 } // namespace
22 23
23 GpuMemoryBufferImplSharedMemory::GpuMemoryBufferImplSharedMemory( 24 GpuMemoryBufferImplSharedMemory::GpuMemoryBufferImplSharedMemory(
24 gfx::GpuMemoryBufferId id, 25 gfx::GpuMemoryBufferId id,
25 const gfx::Size& size, 26 const gfx::Size& size,
26 gfx::BufferFormat format, 27 gfx::BufferFormat format,
27 const DestructionCallback& callback, 28 const DestructionCallback& callback,
28 scoped_ptr<base::SharedMemory> shared_memory, 29 std::unique_ptr<base::SharedMemory> shared_memory,
29 size_t offset, 30 size_t offset,
30 int stride) 31 int stride)
31 : GpuMemoryBufferImpl(id, size, format, callback), 32 : GpuMemoryBufferImpl(id, size, format, callback),
32 shared_memory_(std::move(shared_memory)), 33 shared_memory_(std::move(shared_memory)),
33 offset_(offset), 34 offset_(offset),
34 stride_(stride) { 35 stride_(stride) {
35 DCHECK(IsSizeValidForFormat(size, format)); 36 DCHECK(IsSizeValidForFormat(size, format));
36 } 37 }
37 38
38 GpuMemoryBufferImplSharedMemory::~GpuMemoryBufferImplSharedMemory() {} 39 GpuMemoryBufferImplSharedMemory::~GpuMemoryBufferImplSharedMemory() {}
39 40
40 // static 41 // static
41 scoped_ptr<GpuMemoryBufferImplSharedMemory> 42 std::unique_ptr<GpuMemoryBufferImplSharedMemory>
42 GpuMemoryBufferImplSharedMemory::Create(gfx::GpuMemoryBufferId id, 43 GpuMemoryBufferImplSharedMemory::Create(gfx::GpuMemoryBufferId id,
43 const gfx::Size& size, 44 const gfx::Size& size,
44 gfx::BufferFormat format, 45 gfx::BufferFormat format,
45 const DestructionCallback& callback) { 46 const DestructionCallback& callback) {
46 size_t buffer_size = 0u; 47 size_t buffer_size = 0u;
47 if (!gfx::BufferSizeForBufferFormatChecked(size, format, &buffer_size)) 48 if (!gfx::BufferSizeForBufferFormatChecked(size, format, &buffer_size))
48 return nullptr; 49 return nullptr;
49 50
50 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory()); 51 std::unique_ptr<base::SharedMemory> shared_memory(new base::SharedMemory());
51 if (!shared_memory->CreateAndMapAnonymous(buffer_size)) 52 if (!shared_memory->CreateAndMapAnonymous(buffer_size))
52 return nullptr; 53 return nullptr;
53 54
54 return make_scoped_ptr(new GpuMemoryBufferImplSharedMemory( 55 return base::WrapUnique(new GpuMemoryBufferImplSharedMemory(
55 id, size, format, callback, std::move(shared_memory), 0, 56 id, size, format, callback, std::move(shared_memory), 0,
56 gfx::RowSizeForBufferFormat(size.width(), format, 0))); 57 gfx::RowSizeForBufferFormat(size.width(), format, 0)));
57 } 58 }
58 59
59 // static 60 // static
60 gfx::GpuMemoryBufferHandle 61 gfx::GpuMemoryBufferHandle
61 GpuMemoryBufferImplSharedMemory::AllocateForChildProcess( 62 GpuMemoryBufferImplSharedMemory::AllocateForChildProcess(
62 gfx::GpuMemoryBufferId id, 63 gfx::GpuMemoryBufferId id,
63 const gfx::Size& size, 64 const gfx::Size& size,
64 gfx::BufferFormat format, 65 gfx::BufferFormat format,
(...skipping 10 matching lines...) Expand all
75 handle.type = gfx::SHARED_MEMORY_BUFFER; 76 handle.type = gfx::SHARED_MEMORY_BUFFER;
76 handle.id = id; 77 handle.id = id;
77 handle.offset = 0; 78 handle.offset = 0;
78 handle.stride = static_cast<int32_t>( 79 handle.stride = static_cast<int32_t>(
79 gfx::RowSizeForBufferFormat(size.width(), format, 0)); 80 gfx::RowSizeForBufferFormat(size.width(), format, 0));
80 shared_memory.GiveToProcess(child_process, &handle.handle); 81 shared_memory.GiveToProcess(child_process, &handle.handle);
81 return handle; 82 return handle;
82 } 83 }
83 84
84 // static 85 // static
85 scoped_ptr<GpuMemoryBufferImplSharedMemory> 86 std::unique_ptr<GpuMemoryBufferImplSharedMemory>
86 GpuMemoryBufferImplSharedMemory::CreateFromHandle( 87 GpuMemoryBufferImplSharedMemory::CreateFromHandle(
87 const gfx::GpuMemoryBufferHandle& handle, 88 const gfx::GpuMemoryBufferHandle& handle,
88 const gfx::Size& size, 89 const gfx::Size& size,
89 gfx::BufferFormat format, 90 gfx::BufferFormat format,
90 gfx::BufferUsage usage, 91 gfx::BufferUsage usage,
91 const DestructionCallback& callback) { 92 const DestructionCallback& callback) {
92 DCHECK(base::SharedMemory::IsHandleValid(handle.handle)); 93 DCHECK(base::SharedMemory::IsHandleValid(handle.handle));
93 94
94 return make_scoped_ptr(new GpuMemoryBufferImplSharedMemory( 95 return base::WrapUnique(new GpuMemoryBufferImplSharedMemory(
95 handle.id, size, format, callback, 96 handle.id, size, format, callback,
96 make_scoped_ptr(new base::SharedMemory(handle.handle, false)), 97 base::WrapUnique(new base::SharedMemory(handle.handle, false)),
97 handle.offset, handle.stride)); 98 handle.offset, handle.stride));
98 } 99 }
99 100
100 // static 101 // static
101 bool GpuMemoryBufferImplSharedMemory::IsUsageSupported(gfx::BufferUsage usage) { 102 bool GpuMemoryBufferImplSharedMemory::IsUsageSupported(gfx::BufferUsage usage) {
102 switch (usage) { 103 switch (usage) {
103 case gfx::BufferUsage::GPU_READ: 104 case gfx::BufferUsage::GPU_READ:
104 case gfx::BufferUsage::GPU_READ_CPU_READ_WRITE: 105 case gfx::BufferUsage::GPU_READ_CPU_READ_WRITE:
105 case gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT: 106 case gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT:
106 return true; 107 return true;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 gfx::GpuMemoryBufferHandle handle; 215 gfx::GpuMemoryBufferHandle handle;
215 handle.type = gfx::SHARED_MEMORY_BUFFER; 216 handle.type = gfx::SHARED_MEMORY_BUFFER;
216 handle.id = id_; 217 handle.id = id_;
217 handle.offset = offset_; 218 handle.offset = offset_;
218 handle.stride = stride_; 219 handle.stride = stride_;
219 handle.handle = shared_memory_->handle(); 220 handle.handle = shared_memory_->handle();
220 return handle; 221 return handle;
221 } 222 }
222 223
223 } // namespace gpu 224 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/ipc/client/gpu_memory_buffer_impl_shared_memory.h ('k') | gpu/ipc/client/gpu_memory_buffer_impl_shared_memory_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698