| // Copyright 2013 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #include "gpu/ipc/common/gpu_memory_buffer_impl.h" |
| |
| #include "base/trace_event/memory_allocator_dump_guid.h" |
| #include "base/trace_event/process_memory_dump.h" |
| |
| namespace gpu { |
| |
| GpuMemoryBufferImpl::GpuMemoryBufferImpl(gfx::GpuMemoryBufferId id, |
| const gfx::Size& size, |
| gfx::BufferFormat format, |
| DestructionCallback callback) |
| : id_(id), |
| size_(size), |
| format_(format), |
| callback_(std::move(callback)), |
| mapped_(false) {} |
| |
| GpuMemoryBufferImpl::~GpuMemoryBufferImpl() { |
| DCHECK(!mapped_); |
| if (!callback_.is_null()) |
| std::move(callback_).Run(destruction_sync_token_); |
| } |
| |
| gfx::Size GpuMemoryBufferImpl::GetSize() const { |
| return size_; |
| } |
| |
| gfx::BufferFormat GpuMemoryBufferImpl::GetFormat() const { |
| return format_; |
| } |
| |
| gfx::GpuMemoryBufferId GpuMemoryBufferImpl::GetId() const { |
| return id_; |
| } |
| |
| ClientBuffer GpuMemoryBufferImpl::AsClientBuffer() { |
| return reinterpret_cast<ClientBuffer>(this); |
| } |
| |
| void GpuMemoryBufferImpl::OnMemoryDump( |
| base::trace_event::ProcessMemoryDump* pmd, |
| const base::trace_event::MemoryAllocatorDumpGuid& buffer_dump_guid, |
| uint64_t tracing_process_id, |
| int importance) const { |
| auto shared_buffer_guid = |
| gfx::GetGenericSharedGpuMemoryGUIDForTracing(tracing_process_id, GetId()); |
| pmd->CreateSharedGlobalAllocatorDump(shared_buffer_guid); |
| pmd->AddOwnershipEdge(buffer_dump_guid, shared_buffer_guid, importance); |
| } |
| |
| } // namespace gpu |