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

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

Issue 2535213002: [WIP] Add SharedMemoryTracker to dump base::SharedMemory usage
Patch Set: (rebase) Created 3 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
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/memory/ptr_util.h"
12 #include "base/numerics/safe_math.h" 12 #include "base/numerics/safe_math.h"
13 #include "base/process/memory.h" 13 #include "base/process/memory.h"
14 #include "ui/gfx/buffer_format_util.h" 14 #include "ui/gfx/buffer_format_util.h"
15 #include "ui/gfx/gpu_memory_buffer_tracing.h"
16 #include "ui/gl/gl_bindings.h" 15 #include "ui/gl/gl_bindings.h"
17 16
18 namespace gpu { 17 namespace gpu {
19 18
20 GpuMemoryBufferImplSharedMemory::GpuMemoryBufferImplSharedMemory( 19 GpuMemoryBufferImplSharedMemory::GpuMemoryBufferImplSharedMemory(
21 gfx::GpuMemoryBufferId id, 20 gfx::GpuMemoryBufferId id,
22 const gfx::Size& size, 21 const gfx::Size& size,
23 gfx::BufferFormat format, 22 gfx::BufferFormat format,
24 const DestructionCallback& callback, 23 const DestructionCallback& callback,
25 std::unique_ptr<base::SharedMemory> shared_memory, 24 std::unique_ptr<base::SharedMemory> shared_memory,
(...skipping 14 matching lines...) Expand all
40 const gfx::Size& size, 39 const gfx::Size& size,
41 gfx::BufferFormat format, 40 gfx::BufferFormat format,
42 const DestructionCallback& callback) { 41 const DestructionCallback& callback) {
43 size_t buffer_size = 0u; 42 size_t buffer_size = 0u;
44 if (!gfx::BufferSizeForBufferFormatChecked(size, format, &buffer_size)) 43 if (!gfx::BufferSizeForBufferFormatChecked(size, format, &buffer_size))
45 return nullptr; 44 return nullptr;
46 45
47 std::unique_ptr<base::SharedMemory> shared_memory(new base::SharedMemory()); 46 std::unique_ptr<base::SharedMemory> shared_memory(new base::SharedMemory());
48 if (!shared_memory->CreateAndMapAnonymous(buffer_size)) 47 if (!shared_memory->CreateAndMapAnonymous(buffer_size))
49 return nullptr; 48 return nullptr;
50 49 const int kImportance = 2;
50 shared_memory->set_importance(kImportance);
51 return base::WrapUnique(new GpuMemoryBufferImplSharedMemory( 51 return base::WrapUnique(new GpuMemoryBufferImplSharedMemory(
52 id, size, format, callback, std::move(shared_memory), 0, 52 id, size, format, callback, std::move(shared_memory), 0,
53 gfx::RowSizeForBufferFormat(size.width(), format, 0))); 53 gfx::RowSizeForBufferFormat(size.width(), format, 0)));
54 } 54 }
55 55
56 // static 56 // static
57 gfx::GpuMemoryBufferHandle 57 gfx::GpuMemoryBufferHandle
58 GpuMemoryBufferImplSharedMemory::CreateGpuMemoryBuffer( 58 GpuMemoryBufferImplSharedMemory::CreateGpuMemoryBuffer(
59 gfx::GpuMemoryBufferId id, 59 gfx::GpuMemoryBufferId id,
60 const gfx::Size& size, 60 const gfx::Size& size,
(...skipping 18 matching lines...) Expand all
79 79
80 // static 80 // static
81 std::unique_ptr<GpuMemoryBufferImplSharedMemory> 81 std::unique_ptr<GpuMemoryBufferImplSharedMemory>
82 GpuMemoryBufferImplSharedMemory::CreateFromHandle( 82 GpuMemoryBufferImplSharedMemory::CreateFromHandle(
83 const gfx::GpuMemoryBufferHandle& handle, 83 const gfx::GpuMemoryBufferHandle& handle,
84 const gfx::Size& size, 84 const gfx::Size& size,
85 gfx::BufferFormat format, 85 gfx::BufferFormat format,
86 gfx::BufferUsage usage, 86 gfx::BufferUsage usage,
87 const DestructionCallback& callback) { 87 const DestructionCallback& callback) {
88 DCHECK(base::SharedMemory::IsHandleValid(handle.handle)); 88 DCHECK(base::SharedMemory::IsHandleValid(handle.handle));
89 89 std::unique_ptr<base::SharedMemory> shared_memory =
90 base::MakeUnique<base::SharedMemory>(handle.handle, false);
91 const int kImportance = 2;
92 shared_memory->set_importance(kImportance);
90 return base::WrapUnique(new GpuMemoryBufferImplSharedMemory( 93 return base::WrapUnique(new GpuMemoryBufferImplSharedMemory(
91 handle.id, size, format, callback, 94 handle.id, size, format, callback, std::move(shared_memory),
92 base::MakeUnique<base::SharedMemory>(handle.handle, false), handle.offset, 95 handle.offset, handle.stride));
93 handle.stride));
94 } 96 }
95 97
96 // static 98 // static
97 bool GpuMemoryBufferImplSharedMemory::IsUsageSupported(gfx::BufferUsage usage) { 99 bool GpuMemoryBufferImplSharedMemory::IsUsageSupported(gfx::BufferUsage usage) {
98 switch (usage) { 100 switch (usage) {
99 case gfx::BufferUsage::GPU_READ: 101 case gfx::BufferUsage::GPU_READ:
100 case gfx::BufferUsage::GPU_READ_CPU_READ_WRITE: 102 case gfx::BufferUsage::GPU_READ_CPU_READ_WRITE:
101 case gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT: 103 case gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT:
102 case gfx::BufferUsage::SCANOUT_CPU_READ_WRITE: 104 case gfx::BufferUsage::SCANOUT_CPU_READ_WRITE:
103 return true; 105 return true;
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 handle.id = id_; 210 handle.id = id_;
209 handle.offset = offset_; 211 handle.offset = offset_;
210 handle.stride = stride_; 212 handle.stride = stride_;
211 handle.handle = shared_memory_->handle(); 213 handle.handle = shared_memory_->handle();
212 return handle; 214 return handle;
213 } 215 }
214 216
215 base::trace_event::MemoryAllocatorDumpGuid 217 base::trace_event::MemoryAllocatorDumpGuid
216 GpuMemoryBufferImplSharedMemory::GetGUIDForTracing( 218 GpuMemoryBufferImplSharedMemory::GetGUIDForTracing(
217 uint64_t tracing_process_id) const { 219 uint64_t tracing_process_id) const {
218 return gfx::GetSharedMemoryGUIDForTracing(tracing_process_id, id_); 220 return shared_memory_->handle().GetGUIDForTracing();
221 }
222
223 base::SharedMemory* GpuMemoryBufferImplSharedMemory::GetSharedMemory() {
224 return shared_memory_.get();
219 } 225 }
220 226
221 } // namespace gpu 227 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/ipc/client/gpu_memory_buffer_impl_shared_memory.h ('k') | gpu/ipc/service/gpu_command_buffer_stub.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698