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/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
12 #include "base/numerics/safe_math.h" | 12 #include "base/numerics/safe_math.h" |
13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
14 #include "base/strings/string_split.h" | 14 #include "base/strings/string_split.h" |
15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
16 #include "base/strings/stringprintf.h" | |
17 #include "base/thread_task_runner_handle.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" |
26 #include "third_party/khronos/GLES2/gl2ext.h" | 29 #include "third_party/khronos/GLES2/gl2ext.h" |
27 #include "third_party/skia/include/core/SkSurface.h" | 30 #include "third_party/skia/include/core/SkSurface.h" |
28 #include "third_party/skia/include/gpu/GrContext.h" | 31 #include "third_party/skia/include/gpu/GrContext.h" |
29 #include "third_party/skia/include/gpu/GrTextureProvider.h" | 32 #include "third_party/skia/include/gpu/GrTextureProvider.h" |
30 #include "ui/gfx/geometry/rect.h" | 33 #include "ui/gfx/geometry/rect.h" |
31 #include "ui/gfx/geometry/vector2d.h" | 34 #include "ui/gfx/geometry/vector2d.h" |
32 #include "ui/gfx/gpu_memory_buffer.h" | 35 #include "ui/gfx/gpu_memory_buffer.h" |
36 #include "ui/gl/trace_util.h" | |
33 | 37 |
34 using gpu::gles2::GLES2Interface; | 38 using gpu::gles2::GLES2Interface; |
35 | 39 |
36 namespace cc { | 40 namespace cc { |
37 | 41 |
38 class IdAllocator { | 42 class IdAllocator { |
39 public: | 43 public: |
40 virtual ~IdAllocator() {} | 44 virtual ~IdAllocator() {} |
41 | 45 |
42 virtual GLuint NextId() = 0; | 46 virtual GLuint NextId() = 0; |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
397 scoped_ptr<ResourceProvider> resource_provider(new ResourceProvider( | 401 scoped_ptr<ResourceProvider> resource_provider(new ResourceProvider( |
398 output_surface, shared_bitmap_manager, gpu_memory_buffer_manager, | 402 output_surface, shared_bitmap_manager, gpu_memory_buffer_manager, |
399 blocking_main_thread_task_runner, highp_threshold_min, | 403 blocking_main_thread_task_runner, highp_threshold_min, |
400 use_rgba_4444_texture_format, id_allocation_chunk_size, | 404 use_rgba_4444_texture_format, id_allocation_chunk_size, |
401 use_persistent_map_for_gpu_memory_buffers)); | 405 use_persistent_map_for_gpu_memory_buffers)); |
402 resource_provider->Initialize(); | 406 resource_provider->Initialize(); |
403 return resource_provider; | 407 return resource_provider; |
404 } | 408 } |
405 | 409 |
406 ResourceProvider::~ResourceProvider() { | 410 ResourceProvider::~ResourceProvider() { |
411 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( | |
412 this); | |
413 | |
407 while (!children_.empty()) | 414 while (!children_.empty()) |
408 DestroyChildInternal(children_.begin(), FOR_SHUTDOWN); | 415 DestroyChildInternal(children_.begin(), FOR_SHUTDOWN); |
409 while (!resources_.empty()) | 416 while (!resources_.empty()) |
410 DeleteResourceInternal(resources_.begin(), FOR_SHUTDOWN); | 417 DeleteResourceInternal(resources_.begin(), FOR_SHUTDOWN); |
411 | 418 |
412 GLES2Interface* gl = ContextGL(); | 419 GLES2Interface* gl = ContextGL(); |
413 if (default_resource_type_ != RESOURCE_TYPE_GL_TEXTURE) { | 420 if (default_resource_type_ != RESOURCE_TYPE_GL_TEXTURE) { |
414 // We are not in GL mode, but double check before returning. | 421 // We are not in GL mode, but double check before returning. |
415 DCHECK(!gl); | 422 DCHECK(!gl); |
416 return; | 423 return; |
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1110 use_sync_query_(false), | 1117 use_sync_query_(false), |
1111 use_persistent_map_for_gpu_memory_buffers_( | 1118 use_persistent_map_for_gpu_memory_buffers_( |
1112 use_persistent_map_for_gpu_memory_buffers) { | 1119 use_persistent_map_for_gpu_memory_buffers) { |
1113 DCHECK(output_surface_->HasClient()); | 1120 DCHECK(output_surface_->HasClient()); |
1114 DCHECK(id_allocation_chunk_size_); | 1121 DCHECK(id_allocation_chunk_size_); |
1115 } | 1122 } |
1116 | 1123 |
1117 void ResourceProvider::Initialize() { | 1124 void ResourceProvider::Initialize() { |
1118 DCHECK(thread_checker_.CalledOnValidThread()); | 1125 DCHECK(thread_checker_.CalledOnValidThread()); |
1119 | 1126 |
1127 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( | |
1128 this, base::ThreadTaskRunnerHandle::Get()); | |
1129 | |
1120 GLES2Interface* gl = ContextGL(); | 1130 GLES2Interface* gl = ContextGL(); |
1121 if (!gl) { | 1131 if (!gl) { |
1122 default_resource_type_ = RESOURCE_TYPE_BITMAP; | 1132 default_resource_type_ = RESOURCE_TYPE_BITMAP; |
1123 // Pick an arbitrary limit here similar to what hardware might. | 1133 // Pick an arbitrary limit here similar to what hardware might. |
1124 max_texture_size_ = 16 * 1024; | 1134 max_texture_size_ = 16 * 1024; |
1125 best_texture_format_ = RGBA_8888; | 1135 best_texture_format_ = RGBA_8888; |
1126 return; | 1136 return; |
1127 } | 1137 } |
1128 | 1138 |
1129 DCHECK(!texture_id_allocator_); | 1139 DCHECK(!texture_id_allocator_); |
(...skipping 821 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1951 return context_provider ? context_provider->ContextGL() : NULL; | 1961 return context_provider ? context_provider->ContextGL() : NULL; |
1952 } | 1962 } |
1953 | 1963 |
1954 class GrContext* ResourceProvider::GrContext(bool worker_context) const { | 1964 class GrContext* ResourceProvider::GrContext(bool worker_context) const { |
1955 ContextProvider* context_provider = | 1965 ContextProvider* context_provider = |
1956 worker_context ? output_surface_->worker_context_provider() | 1966 worker_context ? output_surface_->worker_context_provider() |
1957 : output_surface_->context_provider(); | 1967 : output_surface_->context_provider(); |
1958 return context_provider ? context_provider->GrContext() : NULL; | 1968 return context_provider ? context_provider->GrContext() : NULL; |
1959 } | 1969 } |
1960 | 1970 |
1971 base::trace_event::MemoryAllocatorDump* ResourceProvider::DumpForResource( | |
1972 base::trace_event::ProcessMemoryDump* pmd, | |
1973 const ResourceId& id, | |
1974 const Resource& resource) const { | |
1975 std::string dump_name = | |
1976 base::StringPrintf("CC/resource_memory/resource_%d", id); | |
reveman
2015/07/28 21:38:49
nit: I'm using lower case "cc/..." in one-copy dum
ericrk
2015/07/29 18:46:45
Done.
| |
1977 base::trace_event::MemoryAllocatorDump* dump = | |
1978 pmd->CreateAllocatorDump(dump_name); | |
1979 | |
1980 // Calculate the size of the current resource. | |
1981 // TODO(ericrk): Replace this with helper fn once crrev.com/1202843008 | |
1982 // goes in. | |
1983 unsigned bytes_per_pixel = BitsPerPixel(resource.format) / 8; | |
1984 uint32_t total_bytes = | |
1985 resource.size.height() * | |
1986 MathUtil::RoundUp(bytes_per_pixel * resource.size.width(), 4u); | |
1987 | |
1988 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | |
1989 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | |
1990 static_cast<uint64_t>(total_bytes)); | |
1991 | |
1992 return dump; | |
1993 } | |
1994 | |
1995 bool ResourceProvider::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd) { | |
1996 DCHECK(thread_checker_.CalledOnValidThread()); | |
1997 | |
1998 const uint64 tracing_process_id = | |
1999 base::trace_event::MemoryDumpManager::GetInstance()->tracing_process_id(); | |
2000 | |
2001 for (const auto& resource_entry : resources_) { | |
2002 const auto& resource = resource_entry.second; | |
2003 | |
2004 // Only log INTERNAL resources - other resources are owned by (and will be | |
2005 // logged by) another ResourceProvider. | |
2006 if (resource.origin != Resource::INTERNAL) | |
2007 continue; | |
2008 | |
2009 if (resource.gpu_memory_buffer) { | |
2010 auto dump = | |
2011 DumpForResource(pmd, resource_entry.first, resource_entry.second); | |
2012 | |
2013 // Generate a global GUID used to share this allocation with the GPU | |
2014 // process. | |
reveman
2015/07/28 21:38:49
Not just the GPU process but also the browser proc
ericrk
2015/07/29 18:46:46
Done.
| |
2015 auto guid = gfx::GetSharedBitmapGUIDForTracing( | |
reveman
2015/07/28 21:38:49
SharedBitmap? shouldn't this be gfx::GetGpuMemoryB
ssid
2015/07/29 11:17:43
+1
ericrk
2015/07/29 18:46:46
my bad, did a re-name right at the end and replace
| |
2016 tracing_process_id, resource.gpu_memory_buffer->GetHandle().id); | |
2017 const int kImportance = 2; | |
petrcermak
2015/07/29 16:13:34
This constant is defined three times within this f
ericrk
2015/07/29 18:46:46
refactored this section - should be a lot nicer no
| |
2018 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); | |
petrcermak
2015/07/29 16:13:34
This call is also repeated three times withing thi
ericrk
2015/07/29 18:46:45
refactored.
| |
2019 } else if (resource.shared_bitmap) { | |
2020 auto dump = | |
2021 DumpForResource(pmd, resource_entry.first, resource_entry.second); | |
ssid
2015/07/29 11:17:43
This can be moved out of the if/else. It seems com
ericrk
2015/07/29 18:46:46
Done.
| |
2022 | |
2023 // Generate a global GUID used to share this allocation with the GPU | |
2024 // process. | |
reveman
2015/07/28 21:38:49
Not the GPU process. Only the browser process in c
ericrk
2015/07/29 18:46:46
refactored.
| |
2025 auto guid = | |
2026 GetSharedMemoryBufferGUIDForTracing(resource.shared_bitmap->id()); | |
reveman
2015/07/28 21:38:49
what's GetSharedMemoryBufferGUIDForTracing? is thi
ssid
2015/07/29 11:17:43
I can't find this function?
ericrk
2015/07/29 18:46:45
meant to replace this via rename, replaced the wro
| |
2027 const int kImportance = 2; | |
2028 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); | |
2029 } else if (resource.gl_id && resource.allocated) { | |
2030 auto dump = | |
2031 DumpForResource(pmd, resource_entry.first, resource_entry.second); | |
2032 | |
2033 // Generate a global GUID used to share this allocation with the GPU | |
2034 // process. | |
2035 auto guid = | |
2036 gfx::GetGLTextureGUIDForTracing(tracing_process_id, resource.gl_id); | |
ssid
2015/07/29 11:17:43
Am i missing a dependent cl?
ericrk
2015/07/29 18:46:46
added missing files.
| |
2037 const int kImportance = 2; | |
2038 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); | |
ssid
2015/07/29 11:17:43
I think this memory is shared between processes. I
ericrk
2015/07/29 18:46:45
Interestingly, this was working - probably because
| |
2039 } | |
2040 } | |
2041 | |
2042 return true; | |
2043 } | |
2044 | |
1961 } // namespace cc | 2045 } // namespace cc |
OLD | NEW |