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/android/resources/resource_manager_impl.h" | 5 #include "ui/android/resources/resource_manager_impl.h" |
6 | 6 |
7 #include <inttypes.h> | 7 #include <inttypes.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <utility> | 10 #include <utility> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/android/jni_array.h" | 13 #include "base/android/jni_array.h" |
14 #include "base/android/jni_string.h" | 14 #include "base/android/jni_string.h" |
15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
17 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/thread_task_runner_handle.h" |
| 18 #include "base/trace_event/estimate_memory_usage.h" |
18 #include "base/trace_event/memory_dump_manager.h" | 19 #include "base/trace_event/memory_dump_manager.h" |
19 #include "base/trace_event/process_memory_dump.h" | 20 #include "base/trace_event/process_memory_dump.h" |
20 #include "base/trace_event/trace_event.h" | 21 #include "base/trace_event/trace_event.h" |
21 #include "cc/resources/scoped_ui_resource.h" | 22 #include "cc/resources/scoped_ui_resource.h" |
22 #include "cc/resources/ui_resource_manager.h" | 23 #include "cc/resources/ui_resource_manager.h" |
23 #include "jni/ResourceManager_jni.h" | 24 #include "jni/ResourceManager_jni.h" |
24 #include "third_party/skia/include/core/SkBitmap.h" | 25 #include "third_party/skia/include/core/SkBitmap.h" |
25 #include "third_party/skia/include/core/SkCanvas.h" | 26 #include "third_party/skia/include/core/SkCanvas.h" |
26 #include "third_party/skia/include/core/SkColorFilter.h" | 27 #include "third_party/skia/include/core/SkColorFilter.h" |
27 #include "ui/android/resources/ui_resource_provider.h" | 28 #include "ui/android/resources/ui_resource_provider.h" |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 sprite_rect_source, sprite_rect_destination)); | 294 sprite_rect_source, sprite_rect_destination)); |
294 } | 295 } |
295 src_dst_rects.push_back(frame_src_dst_rects); | 296 src_dst_rects.push_back(frame_src_dst_rects); |
296 } | 297 } |
297 return src_dst_rects; | 298 return src_dst_rects; |
298 } | 299 } |
299 | 300 |
300 bool ResourceManagerImpl::OnMemoryDump( | 301 bool ResourceManagerImpl::OnMemoryDump( |
301 const base::trace_event::MemoryDumpArgs& args, | 302 const base::trace_event::MemoryDumpArgs& args, |
302 base::trace_event::ProcessMemoryDump* pmd) { | 303 base::trace_event::ProcessMemoryDump* pmd) { |
303 size_t size = 0; | 304 using base::trace_event::EstimateMemoryUsage; |
304 for (const auto& resource_map : resources_) { | 305 size_t memory_usage = EstimateMemoryUsage(resources_) + |
305 for (const auto& id_and_resource : resource_map) { | 306 EstimateMemoryUsage(crushed_sprite_resources_) + |
306 if (id_and_resource.second && id_and_resource.second->ui_resource) | 307 EstimateMemoryUsage(tinted_resources_); |
307 size += id_and_resource.second->ui_resource->GetAllocatedSizeInBytes(); | |
308 } | |
309 } | |
310 for (const auto& id_and_resource : crushed_sprite_resources_) { | |
311 if (id_and_resource.second) | |
312 size += id_and_resource.second->GetAllocatedSizeInBytes(); | |
313 } | |
314 for (const auto& color_and_resources : tinted_resources_) { | |
315 for (const auto& id_and_resource : *color_and_resources.second) { | |
316 if (id_and_resource.second && id_and_resource.second->ui_resource) | |
317 size += id_and_resource.second->ui_resource->GetAllocatedSizeInBytes(); | |
318 } | |
319 } | |
320 | 308 |
321 base::trace_event::MemoryAllocatorDump* dump = pmd->CreateAllocatorDump( | 309 base::trace_event::MemoryAllocatorDump* dump = pmd->CreateAllocatorDump( |
322 base::StringPrintf("ui/resource_manager_0x%" PRIXPTR, | 310 base::StringPrintf("ui/resource_manager_0x%" PRIXPTR, |
323 reinterpret_cast<uintptr_t>(this))); | 311 reinterpret_cast<uintptr_t>(this))); |
324 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | 312 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, |
325 base::trace_event::MemoryAllocatorDump::kUnitsBytes, size); | 313 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
| 314 memory_usage); |
326 | 315 |
327 // Bitmaps are allocated from malloc. | |
328 const char* system_allocator_name = | 316 const char* system_allocator_name = |
329 base::trace_event::MemoryDumpManager::GetInstance() | 317 base::trace_event::MemoryDumpManager::GetInstance() |
330 ->system_allocator_pool_name(); | 318 ->system_allocator_pool_name(); |
331 if (system_allocator_name) { | 319 if (system_allocator_name) { |
332 pmd->AddSuballocation(dump->guid(), system_allocator_name); | 320 pmd->AddSuballocation(dump->guid(), system_allocator_name); |
333 } | 321 } |
334 | 322 |
335 return true; | 323 return true; |
336 } | 324 } |
337 | 325 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 TRACE_EVENT2("ui", | 367 TRACE_EVENT2("ui", |
380 "ResourceManagerImpl::RequestCrushedSpriteResourceFromJava", | 368 "ResourceManagerImpl::RequestCrushedSpriteResourceFromJava", |
381 "bitmap_res_id", bitmap_res_id, | 369 "bitmap_res_id", bitmap_res_id, |
382 "metadata_res_id", metadata_res_id); | 370 "metadata_res_id", metadata_res_id); |
383 Java_ResourceManager_crushedSpriteResourceRequested( | 371 Java_ResourceManager_crushedSpriteResourceRequested( |
384 base::android::AttachCurrentThread(), java_obj_, bitmap_res_id, | 372 base::android::AttachCurrentThread(), java_obj_, bitmap_res_id, |
385 metadata_res_id, reloading); | 373 metadata_res_id, reloading); |
386 } | 374 } |
387 | 375 |
388 } // namespace ui | 376 } // namespace ui |
OLD | NEW |