gl_image_ref_counted_memory.cc 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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
  3. // found in the LICENSE file.
  4. #include "ui/gl/gl_image_ref_counted_memory.h"
  5. #include <stddef.h>
  6. #include "base/check.h"
  7. #include "base/memory/ref_counted_memory.h"
  8. #include "base/trace_event/memory_allocator_dump.h"
  9. #include "base/trace_event/memory_dump_manager.h"
  10. #include "base/trace_event/process_memory_dump.h"
  11. #include "ui/gfx/buffer_format_util.h"
  12. namespace gl {
  13. GLImageRefCountedMemory::GLImageRefCountedMemory(const gfx::Size& size)
  14. : GLImageMemory(size) {}
  15. GLImageRefCountedMemory::~GLImageRefCountedMemory() {}
  16. bool GLImageRefCountedMemory::Initialize(
  17. base::RefCountedMemory* ref_counted_memory,
  18. gfx::BufferFormat format) {
  19. if (!GLImageMemory::Initialize(
  20. ref_counted_memory->front(), format,
  21. gfx::RowSizeForBufferFormat(GetSize().width(), format, 0))) {
  22. return false;
  23. }
  24. DCHECK(!ref_counted_memory_.get());
  25. ref_counted_memory_ = ref_counted_memory;
  26. return true;
  27. }
  28. void GLImageRefCountedMemory::OnMemoryDump(
  29. base::trace_event::ProcessMemoryDump* pmd,
  30. uint64_t process_tracing_id,
  31. const std::string& dump_name) {
  32. // Log size 0 if |ref_counted_memory_| has been released.
  33. size_t size_in_bytes = ref_counted_memory_ ? ref_counted_memory_->size() : 0;
  34. // Dump under "/private_memory", as the base class may also dump to
  35. // "/texture_memory".
  36. base::trace_event::MemoryAllocatorDump* dump =
  37. pmd->CreateAllocatorDump(dump_name + "/private_memory");
  38. dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
  39. base::trace_event::MemoryAllocatorDump::kUnitsBytes,
  40. static_cast<uint64_t>(size_in_bytes));
  41. pmd->AddSuballocation(dump->guid(),
  42. base::trace_event::MemoryDumpManager::GetInstance()
  43. ->system_allocator_pool_name());
  44. }
  45. } // namespace gl