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 <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
11 #include "base/format_macros.h" | |
11 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
12 #include "base/numerics/safe_math.h" | 13 #include "base/numerics/safe_math.h" |
13 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
14 #include "base/strings/string_split.h" | 15 #include "base/strings/string_split.h" |
15 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
17 #include "base/strings/stringprintf.h" | |
18 #include "base/trace_event/memory_dump_manager.h" | |
16 #include "base/trace_event/trace_event.h" | 19 #include "base/trace_event/trace_event.h" |
17 #include "cc/base/math_util.h" | 20 #include "cc/base/math_util.h" |
18 #include "cc/resources/platform_color.h" | 21 #include "cc/resources/platform_color.h" |
19 #include "cc/resources/returned_resource.h" | 22 #include "cc/resources/returned_resource.h" |
20 #include "cc/resources/shared_bitmap_manager.h" | 23 #include "cc/resources/shared_bitmap_manager.h" |
21 #include "cc/resources/transferable_resource.h" | 24 #include "cc/resources/transferable_resource.h" |
22 #include "gpu/GLES2/gl2extchromium.h" | 25 #include "gpu/GLES2/gl2extchromium.h" |
23 #include "gpu/command_buffer/client/gles2_interface.h" | 26 #include "gpu/command_buffer/client/gles2_interface.h" |
24 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" | 27 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" |
25 #include "third_party/khronos/GLES2/gl2.h" | 28 #include "third_party/khronos/GLES2/gl2.h" |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
397 scoped_ptr<ResourceProvider> resource_provider(new ResourceProvider( | 400 scoped_ptr<ResourceProvider> resource_provider(new ResourceProvider( |
398 output_surface, shared_bitmap_manager, gpu_memory_buffer_manager, | 401 output_surface, shared_bitmap_manager, gpu_memory_buffer_manager, |
399 blocking_main_thread_task_runner, highp_threshold_min, | 402 blocking_main_thread_task_runner, highp_threshold_min, |
400 use_rgba_4444_texture_format, id_allocation_chunk_size, | 403 use_rgba_4444_texture_format, id_allocation_chunk_size, |
401 use_persistent_map_for_gpu_memory_buffers)); | 404 use_persistent_map_for_gpu_memory_buffers)); |
402 resource_provider->Initialize(); | 405 resource_provider->Initialize(); |
403 return resource_provider; | 406 return resource_provider; |
404 } | 407 } |
405 | 408 |
406 ResourceProvider::~ResourceProvider() { | 409 ResourceProvider::~ResourceProvider() { |
410 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( | |
411 this); | |
412 | |
407 while (!children_.empty()) | 413 while (!children_.empty()) |
408 DestroyChildInternal(children_.begin(), FOR_SHUTDOWN); | 414 DestroyChildInternal(children_.begin(), FOR_SHUTDOWN); |
409 while (!resources_.empty()) | 415 while (!resources_.empty()) |
410 DeleteResourceInternal(resources_.begin(), FOR_SHUTDOWN); | 416 DeleteResourceInternal(resources_.begin(), FOR_SHUTDOWN); |
411 | 417 |
412 GLES2Interface* gl = ContextGL(); | 418 GLES2Interface* gl = ContextGL(); |
413 if (default_resource_type_ != RESOURCE_TYPE_GL_TEXTURE) { | 419 if (default_resource_type_ != RESOURCE_TYPE_GL_TEXTURE) { |
414 // We are not in GL mode, but double check before returning. | 420 // We are not in GL mode, but double check before returning. |
415 DCHECK(!gl); | 421 DCHECK(!gl); |
416 return; | 422 return; |
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1139 best_texture_format_ = | 1145 best_texture_format_ = |
1140 PlatformColor::BestTextureFormat(use_texture_format_bgra_); | 1146 PlatformColor::BestTextureFormat(use_texture_format_bgra_); |
1141 | 1147 |
1142 best_render_buffer_format_ = | 1148 best_render_buffer_format_ = |
1143 PlatformColor::BestTextureFormat(caps.gpu.render_buffer_format_bgra8888); | 1149 PlatformColor::BestTextureFormat(caps.gpu.render_buffer_format_bgra8888); |
1144 | 1150 |
1145 texture_id_allocator_.reset( | 1151 texture_id_allocator_.reset( |
1146 new TextureIdAllocator(gl, id_allocation_chunk_size_)); | 1152 new TextureIdAllocator(gl, id_allocation_chunk_size_)); |
1147 buffer_id_allocator_.reset( | 1153 buffer_id_allocator_.reset( |
1148 new BufferIdAllocator(gl, id_allocation_chunk_size_)); | 1154 new BufferIdAllocator(gl, id_allocation_chunk_size_)); |
1155 | |
1156 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( | |
1157 this); | |
reveman
2015/07/24 21:16:35
You'll need to provide a ThreadTaskRunnerHandle he
ericrk
2015/07/28 21:02:32
Done. Also moved this above (we were skipping regi
| |
1149 } | 1158 } |
1150 | 1159 |
1151 int ResourceProvider::CreateChild(const ReturnCallback& return_callback) { | 1160 int ResourceProvider::CreateChild(const ReturnCallback& return_callback) { |
1152 DCHECK(thread_checker_.CalledOnValidThread()); | 1161 DCHECK(thread_checker_.CalledOnValidThread()); |
1153 | 1162 |
1154 Child child_info; | 1163 Child child_info; |
1155 child_info.return_callback = return_callback; | 1164 child_info.return_callback = return_callback; |
1156 | 1165 |
1157 int child = next_child_++; | 1166 int child = next_child_++; |
1158 children_[child] = child_info; | 1167 children_[child] = child_info; |
(...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1945 return context_provider ? context_provider->ContextGL() : NULL; | 1954 return context_provider ? context_provider->ContextGL() : NULL; |
1946 } | 1955 } |
1947 | 1956 |
1948 class GrContext* ResourceProvider::GrContext(bool worker_context) const { | 1957 class GrContext* ResourceProvider::GrContext(bool worker_context) const { |
1949 ContextProvider* context_provider = | 1958 ContextProvider* context_provider = |
1950 worker_context ? output_surface_->worker_context_provider() | 1959 worker_context ? output_surface_->worker_context_provider() |
1951 : output_surface_->context_provider(); | 1960 : output_surface_->context_provider(); |
1952 return context_provider ? context_provider->GrContext() : NULL; | 1961 return context_provider ? context_provider->GrContext() : NULL; |
1953 } | 1962 } |
1954 | 1963 |
1964 bool ResourceProvider::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd) { | |
1965 DCHECK(thread_checker_.CalledOnValidThread()); | |
1966 | |
1967 // We currently only support memory dumping GL resources. | |
reveman
2015/07/24 21:16:36
FYI, we should dump memory usage of shared bitmaps
ericrk
2015/07/28 21:02:32
Added this for Shared Bitmaps and for GPU Memory B
| |
1968 if (default_resource_type_ == RESOURCE_TYPE_GL_TEXTURE) { | |
reveman
2015/07/24 21:16:36
is the resource.gl_id check below not enough? what
ericrk
2015/07/28 21:02:32
True - now that we log all types this no longer ap
| |
1969 const uint64 tracing_process_id = | |
1970 base::trace_event::MemoryDumpManager::GetInstance() | |
1971 ->tracing_process_id(); | |
1972 | |
1973 for (const auto& resource_entry : resources_) { | |
1974 const auto& resource = resource_entry.second; | |
1975 | |
1976 // Only log memory if we find an internal GL resource with an allocated | |
1977 // ID. | |
1978 if (resource.gl_id && resource.allocated && | |
1979 resource.origin == Resource::INTERNAL) { | |
1980 std::string dump_name = | |
1981 base::StringPrintf("gl/CC/textures/%d", resource.gl_id); | |
reveman
2015/07/24 21:16:36
I think the naming convention I used in my one-cop
ericrk
2015/07/28 21:02:32
Makes sense.
| |
1982 base::trace_event::MemoryAllocatorDump* dump = | |
1983 pmd->CreateAllocatorDump(dump_name); | |
1984 | |
1985 // Calculate the size of the current resource. | |
1986 // TODO(ericrk): Replace this with helper fn once crrev.org/1202843008 | |
1987 // goes in. | |
1988 unsigned bytes_per_pixel = BitsPerPixel(resource.format) / 8; | |
1989 uint32_t total_bytes = | |
1990 resource.size.height() * | |
1991 MathUtil::RoundUp(bytes_per_pixel * resource.size.width(), 4u); | |
1992 | |
1993 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | |
1994 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | |
1995 static_cast<uint64_t>(total_bytes)); | |
1996 | |
1997 // Generate a global GUID used to share this allocation with the GPU | |
1998 // process. | |
1999 auto guid = base::trace_event::MemoryAllocatorDumpGuid( | |
2000 base::StringPrintf("gl-x-process/%" PRIx64 "/texture_%d", | |
2001 tracing_process_id, resource.gl_id)); | |
reveman
2015/07/24 21:16:36
This is not going to be correct if the resource is
ericrk
2015/07/28 21:02:32
Done.
| |
2002 const int kImportance = 2; | |
2003 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); | |
2004 } | |
2005 } | |
2006 } | |
2007 | |
2008 return true; | |
2009 } | |
2010 | |
1955 } // namespace cc | 2011 } // namespace cc |
OLD | NEW |