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

Side by Side Diff: cc/resources/resource_provider.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
« no previous file with comments | « cc/raster/staging_buffer_pool.cc ('k') | cc/resources/shared_bitmap.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
26 #include "cc/resources/resource_util.h" 27 #include "cc/resources/resource_util.h"
27 #include "cc/resources/returned_resource.h" 28 #include "cc/resources/returned_resource.h"
28 #include "cc/resources/shared_bitmap_manager.h" 29 #include "cc/resources/shared_bitmap_manager.h"
29 #include "cc/resources/transferable_resource.h" 30 #include "cc/resources/transferable_resource.h"
30 #include "gpu/GLES2/gl2extchromium.h" 31 #include "gpu/GLES2/gl2extchromium.h"
31 #include "gpu/command_buffer/client/context_support.h" 32 #include "gpu/command_buffer/client/context_support.h"
32 #include "gpu/command_buffer/client/gles2_interface.h" 33 #include "gpu/command_buffer/client/gles2_interface.h"
33 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" 34 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h"
34 #include "skia/ext/texture_handle.h" 35 #include "skia/ext/texture_handle.h"
35 #include "third_party/khronos/GLES2/gl2.h" 36 #include "third_party/khronos/GLES2/gl2.h"
36 #include "third_party/khronos/GLES2/gl2ext.h" 37 #include "third_party/khronos/GLES2/gl2ext.h"
37 #include "third_party/skia/include/core/SkCanvas.h" 38 #include "third_party/skia/include/core/SkCanvas.h"
38 #include "third_party/skia/include/core/SkSurface.h" 39 #include "third_party/skia/include/core/SkSurface.h"
39 #include "third_party/skia/include/gpu/GrContext.h" 40 #include "third_party/skia/include/gpu/GrContext.h"
40 #include "third_party/skia/include/gpu/gl/GrGLTypes.h" 41 #include "third_party/skia/include/gpu/gl/GrGLTypes.h"
41 #include "ui/gfx/geometry/rect.h" 42 #include "ui/gfx/geometry/rect.h"
42 #include "ui/gfx/geometry/vector2d.h" 43 #include "ui/gfx/geometry/vector2d.h"
43 #include "ui/gfx/gpu_memory_buffer_tracing.h"
44 #include "ui/gfx/icc_profile.h" 44 #include "ui/gfx/icc_profile.h"
45 #include "ui/gl/trace_util.h" 45 #include "ui/gl/trace_util.h"
46 46
47 using gpu::gles2::GLES2Interface; 47 using gpu::gles2::GLES2Interface;
48 48
49 namespace cc { 49 namespace cc {
50 50
51 class TextureIdAllocator { 51 class TextureIdAllocator {
52 public: 52 public:
53 TextureIdAllocator(GLES2Interface* gl, 53 TextureIdAllocator(GLES2Interface* gl,
(...skipping 2108 matching lines...) Expand 10 before | Expand all | Expand 10 after
2162 tracing_id_, resource_entry.first); 2162 tracing_id_, resource_entry.first);
2163 base::trace_event::MemoryAllocatorDump* dump = 2163 base::trace_event::MemoryAllocatorDump* dump =
2164 pmd->CreateAllocatorDump(dump_name); 2164 pmd->CreateAllocatorDump(dump_name);
2165 2165
2166 uint64_t total_bytes = ResourceUtil::UncheckedSizeInBytesAligned<size_t>( 2166 uint64_t total_bytes = ResourceUtil::UncheckedSizeInBytesAligned<size_t>(
2167 resource.size, resource.format); 2167 resource.size, resource.format);
2168 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, 2168 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
2169 base::trace_event::MemoryAllocatorDump::kUnitsBytes, 2169 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
2170 static_cast<uint64_t>(total_bytes)); 2170 static_cast<uint64_t>(total_bytes));
2171 2171
2172 // Resources may be shared across processes and require a shared GUID to 2172 if (resource.type == RESOURCE_TYPE_GL_TEXTURE ||
2173 // prevent double counting the memory. 2173 (resource.type == RESOURCE_TYPE_GPU_MEMORY_BUFFER &&
2174 base::trace_event::MemoryAllocatorDumpGuid guid; 2174 !resource.gpu_memory_buffer->GetSharedMemory())) {
2175 switch (resource.type) { 2175 // Resources may be shared across processes and require a shared GUID to
2176 case RESOURCE_TYPE_GPU_MEMORY_BUFFER: 2176 // prevent double counting the memory.
2177 guid = 2177 base::trace_event::MemoryAllocatorDumpGuid guid;
2178 resource.gpu_memory_buffer->GetGUIDForTracing(tracing_process_id); 2178 switch (resource.type) {
2179 break; 2179 case RESOURCE_TYPE_GPU_MEMORY_BUFFER:
2180 case RESOURCE_TYPE_GL_TEXTURE: 2180 guid =
2181 DCHECK(resource.gl_id); 2181 resource.gpu_memory_buffer->GetGUIDForTracing(tracing_process_id);
2182 guid = gl::GetGLTextureClientGUIDForTracing( 2182 break;
2183 compositor_context_provider_->ContextSupport() 2183 case RESOURCE_TYPE_GL_TEXTURE:
2184 ->ShareGroupTracingGUID(), 2184 DCHECK(resource.gl_id);
2185 resource.gl_id); 2185 guid = gl::GetGLTextureClientGUIDForTracing(
2186 break; 2186 compositor_context_provider_->ContextSupport()
2187 case RESOURCE_TYPE_BITMAP: 2187 ->ShareGroupTracingGUID(),
2188 DCHECK(resource.has_shared_bitmap_id); 2188 resource.gl_id);
2189 guid = GetSharedBitmapGUIDForTracing(resource.shared_bitmap_id); 2189 break;
2190 break; 2190 case RESOURCE_TYPE_BITMAP:
2191 NOTREACHED();
2192 break;
2193 }
2194 DCHECK(!guid.empty());
2195
2196 const int kImportance = 2;
2197 pmd->CreateSharedGlobalAllocatorDump(guid);
2198 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance);
2199 } else {
2200 base::SharedMemory* shared_memory = nullptr;
2201 switch (resource.type) {
2202 case RESOURCE_TYPE_GPU_MEMORY_BUFFER:
2203 shared_memory = resource.gpu_memory_buffer->GetSharedMemory();
2204 DCHECK(shared_memory);
2205 break;
2206 case RESOURCE_TYPE_GL_TEXTURE:
2207 NOTREACHED();
2208 break;
2209 case RESOURCE_TYPE_BITMAP:
2210 if (!resource.shared_bitmap)
2211 break;
2212 shared_memory = resource.shared_bitmap->GetSharedMemory();
2213 break;
2214 }
2215 if (shared_memory) {
2216 base::SharedMemoryTracker::AddOwnershipEdges(pmd, dump->guid(),
2217 *shared_memory);
2218 }
2191 } 2219 }
2192
2193 DCHECK(!guid.empty());
2194
2195 const int kImportance = 2;
2196 pmd->CreateSharedGlobalAllocatorDump(guid);
2197 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance);
2198 } 2220 }
2199 2221
2200 return true; 2222 return true;
2201 } 2223 }
2202 2224
2203 } // namespace cc 2225 } // namespace cc
OLDNEW
« no previous file with comments | « cc/raster/staging_buffer_pool.cc ('k') | cc/resources/shared_bitmap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698