OLD | NEW |
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 "ui/gl/gl_image_shared_memory.h" | 5 #include "ui/gl/gl_image_shared_memory.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/shared_memory.h" | 8 #include "base/memory/shared_memory.h" |
9 #include "base/numerics/safe_math.h" | 9 #include "base/numerics/safe_math.h" |
10 #include "base/process/process_handle.h" | 10 #include "base/process/process_handle.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 // Minimize the amount of adress space we use but make sure offset is a | 54 // Minimize the amount of adress space we use but make sure offset is a |
55 // multiple of page size as required by MapAt(). | 55 // multiple of page size as required by MapAt(). |
56 size_t memory_offset = offset % base::SysInfo::VMAllocationGranularity(); | 56 size_t memory_offset = offset % base::SysInfo::VMAllocationGranularity(); |
57 size_t map_offset = base::SysInfo::VMAllocationGranularity() * | 57 size_t map_offset = base::SysInfo::VMAllocationGranularity() * |
58 (offset / base::SysInfo::VMAllocationGranularity()); | 58 (offset / base::SysInfo::VMAllocationGranularity()); |
59 | 59 |
60 checked_size += memory_offset; | 60 checked_size += memory_offset; |
61 if (!checked_size.IsValid()) | 61 if (!checked_size.IsValid()) |
62 return false; | 62 return false; |
63 | 63 |
64 scoped_ptr<base::SharedMemory> duped_shared_memory( | 64 std::unique_ptr<base::SharedMemory> duped_shared_memory( |
65 new base::SharedMemory(duped_shared_memory_handle, true)); | 65 new base::SharedMemory(duped_shared_memory_handle, true)); |
66 if (!duped_shared_memory->MapAt(static_cast<off_t>(map_offset), | 66 if (!duped_shared_memory->MapAt(static_cast<off_t>(map_offset), |
67 checked_size.ValueOrDie())) { | 67 checked_size.ValueOrDie())) { |
68 DVLOG(0) << "Failed to map shared memory."; | 68 DVLOG(0) << "Failed to map shared memory."; |
69 return false; | 69 return false; |
70 } | 70 } |
71 | 71 |
72 if (!GLImageMemory::Initialize( | 72 if (!GLImageMemory::Initialize( |
73 static_cast<uint8_t*>(duped_shared_memory->memory()) + memory_offset, | 73 static_cast<uint8_t*>(duped_shared_memory->memory()) + memory_offset, |
74 format, stride)) { | 74 format, stride)) { |
(...skipping 28 matching lines...) Expand all Loading... |
103 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | 103 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
104 static_cast<uint64_t>(size_in_bytes)); | 104 static_cast<uint64_t>(size_in_bytes)); |
105 | 105 |
106 auto guid = GetGenericSharedMemoryGUIDForTracing(process_tracing_id, | 106 auto guid = GetGenericSharedMemoryGUIDForTracing(process_tracing_id, |
107 shared_memory_id_); | 107 shared_memory_id_); |
108 pmd->CreateSharedGlobalAllocatorDump(guid); | 108 pmd->CreateSharedGlobalAllocatorDump(guid); |
109 pmd->AddOwnershipEdge(dump->guid(), guid); | 109 pmd->AddOwnershipEdge(dump->guid(), guid); |
110 } | 110 } |
111 | 111 |
112 } // namespace gl | 112 } // namespace gl |
OLD | NEW |