We started redesigning GpuMemoryBuffer interface to handle multiple buffers [0].
[chromium-blink-merge.git] / gpu / command_buffer / common / buffer.cc
blob3b3da4345d766cc484f5a5c53419db61e0538839
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"
11 namespace gpu {
12 SharedMemoryBufferBacking::SharedMemoryBufferBacking(
13 scoped_ptr<base::SharedMemory> shared_memory,
14 size_t size)
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";
32 Buffer::~Buffer() {}
34 void* Buffer::GetDataAddress(uint32 data_offset, uint32 data_size) const {
35 base::CheckedNumeric<uint32> end = data_offset;
36 end += data_size;
37 if (!end.IsValid() || end.ValueOrDie() > static_cast<uint32>(size_))
38 return NULL;
39 return static_cast<uint8*>(memory_) + data_offset;
42 } // namespace gpu