OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "cc/resources/resource_provider.h" | 5 #include "cc/resources/resource_provider.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
11 #include <limits> | 11 #include <limits> |
12 #include <unordered_map> | 12 #include <unordered_map> |
13 | 13 |
14 #include "base/atomic_sequence_num.h" | 14 #include "base/atomic_sequence_num.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/shared_memory_tracker.h" |
16 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
17 #include "base/numerics/safe_math.h" | 18 #include "base/numerics/safe_math.h" |
18 #include "base/stl_util.h" | 19 #include "base/stl_util.h" |
19 #include "base/strings/string_split.h" | 20 #include "base/strings/string_split.h" |
20 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
21 #include "base/strings/stringprintf.h" | 22 #include "base/strings/stringprintf.h" |
22 #include "base/threading/thread_task_runner_handle.h" | 23 #include "base/threading/thread_task_runner_handle.h" |
23 #include "base/trace_event/memory_dump_manager.h" | 24 #include "base/trace_event/memory_dump_manager.h" |
24 #include "base/trace_event/trace_event.h" | 25 #include "base/trace_event/trace_event.h" |
25 #include "cc/resources/platform_color.h" | 26 #include "cc/resources/platform_color.h" |
(...skipping 2094 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2120 | 2121 |
2121 uint64_t total_bytes = ResourceUtil::UncheckedSizeInBytesAligned<size_t>( | 2122 uint64_t total_bytes = ResourceUtil::UncheckedSizeInBytesAligned<size_t>( |
2122 resource.size, resource.format); | 2123 resource.size, resource.format); |
2123 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | 2124 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, |
2124 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | 2125 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
2125 static_cast<uint64_t>(total_bytes)); | 2126 static_cast<uint64_t>(total_bytes)); |
2126 | 2127 |
2127 // Resources may be shared across processes and require a shared GUID to | 2128 // Resources may be shared across processes and require a shared GUID to |
2128 // prevent double counting the memory. | 2129 // prevent double counting the memory. |
2129 base::trace_event::MemoryAllocatorDumpGuid guid; | 2130 base::trace_event::MemoryAllocatorDumpGuid guid; |
| 2131 base::SharedMemoryHandle shared_memory_handle; |
2130 switch (resource.type) { | 2132 switch (resource.type) { |
2131 case RESOURCE_TYPE_GPU_MEMORY_BUFFER: | 2133 case RESOURCE_TYPE_GPU_MEMORY_BUFFER: |
2132 guid = gfx::GetGpuMemoryBufferGUIDForTracing( | 2134 guid = gfx::GetGpuMemoryBufferGUIDForTracing( |
2133 tracing_process_id, resource.gpu_memory_buffer->GetHandle().id); | 2135 tracing_process_id, resource.gpu_memory_buffer->GetHandle().id); |
| 2136 shared_memory_handle = resource.gpu_memory_buffer->GetHandle().handle; |
2134 break; | 2137 break; |
2135 case RESOURCE_TYPE_GL_TEXTURE: | 2138 case RESOURCE_TYPE_GL_TEXTURE: |
2136 DCHECK(resource.gl_id); | 2139 DCHECK(resource.gl_id); |
2137 guid = gl::GetGLTextureClientGUIDForTracing( | 2140 guid = gl::GetGLTextureClientGUIDForTracing( |
2138 compositor_context_provider_->ContextSupport() | 2141 compositor_context_provider_->ContextSupport() |
2139 ->ShareGroupTracingGUID(), | 2142 ->ShareGroupTracingGUID(), |
2140 resource.gl_id); | 2143 resource.gl_id); |
2141 break; | 2144 break; |
2142 case RESOURCE_TYPE_BITMAP: | 2145 case RESOURCE_TYPE_BITMAP: |
2143 DCHECK(resource.has_shared_bitmap_id); | 2146 DCHECK(resource.has_shared_bitmap_id); |
2144 guid = GetSharedBitmapGUIDForTracing(resource.shared_bitmap_id); | 2147 guid = GetSharedBitmapGUIDForTracing(resource.shared_bitmap_id); |
| 2148 auto shared_memory = resource.shared_bitmap->shared_memory(); |
| 2149 if (shared_memory) |
| 2150 shared_memory_handle = shared_memory->handle(); |
2145 break; | 2151 break; |
2146 } | 2152 } |
2147 | 2153 |
2148 DCHECK(!guid.empty()); | 2154 DCHECK(!guid.empty()); |
2149 | 2155 |
2150 const int kImportance = 2; | 2156 const int kImportance = 2; |
2151 pmd->CreateSharedGlobalAllocatorDump(guid); | 2157 pmd->CreateSharedGlobalAllocatorDump(guid); |
2152 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); | 2158 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); |
| 2159 if (shared_memory_handle != base::SharedMemory::NULLHandle()) { |
| 2160 base::SharedMemoryTracker::AddOwnershipEdgeToSharedGlobalDump( |
| 2161 pmd, guid, shared_memory_handle, total_bytes); |
| 2162 } |
2153 } | 2163 } |
2154 | 2164 |
2155 return true; | 2165 return true; |
2156 } | 2166 } |
2157 | 2167 |
2158 } // namespace cc | 2168 } // namespace cc |
OLD | NEW |