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.
5 #include "gpu/command_buffer/common/buffer.h"
7 #include "base/format_macros.h"
8 #include "base/logging.h"
9 #include "base/numerics/safe_math.h"
10 #include "base/strings/stringprintf.h"
13 SharedMemoryBufferBacking::SharedMemoryBufferBacking(
14 scoped_ptr
<base::SharedMemory
> shared_memory
,
16 : shared_memory_(shared_memory
.Pass()), size_(size
) {}
18 SharedMemoryBufferBacking::~SharedMemoryBufferBacking() {}
20 void* SharedMemoryBufferBacking::GetMemory() const {
21 return shared_memory_
->memory();
24 size_t SharedMemoryBufferBacking::GetSize() const { return size_
; }
26 Buffer::Buffer(scoped_ptr
<BufferBacking
> backing
)
27 : backing_(backing
.Pass()),
28 memory_(backing_
->GetMemory()),
29 size_(backing_
->GetSize()) {
30 DCHECK(memory_
) << "The memory must be mapped to create a Buffer";
35 void* Buffer::GetDataAddress(uint32 data_offset
, uint32 data_size
) const {
36 base::CheckedNumeric
<uint32
> end
= data_offset
;
38 if (!end
.IsValid() || end
.ValueOrDie() > static_cast<uint32
>(size_
))
40 return static_cast<uint8
*>(memory_
) + data_offset
;
43 base::trace_event::MemoryAllocatorDumpGuid
GetBufferGUIDForTracing(
44 uint64_t tracing_process_id
,
46 return base::trace_event::MemoryAllocatorDumpGuid(base::StringPrintf(
47 "gpu-buffer-x-process/%" PRIx64
"/%d", tracing_process_id
, buffer_id
));