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/logging.h"
9 #include "base/numerics/safe_math.h"
12 SharedMemoryBufferBacking::SharedMemoryBufferBacking(
13 scoped_ptr
<base::SharedMemory
> shared_memory
,
15 : shared_memory_(shared_memory
.Pass()), size_(size
) {}
17 SharedMemoryBufferBacking::~SharedMemoryBufferBacking() {}
19 void* SharedMemoryBufferBacking::GetMemory() const {
20 return shared_memory_
->memory();
23 size_t SharedMemoryBufferBacking::GetSize() const { return size_
; }
25 Buffer::Buffer(scoped_ptr
<BufferBacking
> backing
)
26 : backing_(backing
.Pass()),
27 memory_(backing_
->GetMemory()),
28 size_(backing_
->GetSize()) {
29 DCHECK(memory_
) << "The memory must be mapped to create a Buffer";
34 void* Buffer::GetDataAddress(uint32 data_offset
, uint32 data_size
) const {
35 base::CheckedNumeric
<uint32
> end
= data_offset
;
37 if (!end
.IsValid() || end
.ValueOrDie() > static_cast<uint32
>(size_
))
39 return static_cast<uint8
*>(memory_
) + data_offset
;