OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "gpu/command_buffer/common/buffer.h" | 5 #include "gpu/command_buffer/common/buffer.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 | 8 |
9 #include "base/numerics/safe_math.h" | 9 #include "base/numerics/safe_math.h" |
10 | 10 |
11 namespace gpu { | 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) {} |
12 | 16 |
13 Buffer::Buffer(scoped_ptr<base::SharedMemory> shared_memory, size_t size) | 17 SharedMemoryBufferBacking::~SharedMemoryBufferBacking() {} |
14 : shared_memory_(shared_memory.Pass()), | 18 |
15 memory_(shared_memory_->memory()), | 19 void* SharedMemoryBufferBacking::GetMemory() const { |
16 size_(size) { | 20 return shared_memory_->memory(); |
| 21 } |
| 22 |
| 23 size_t SharedMemoryBufferBacking::GetSize() const { return size_; } |
| 24 |
| 25 Buffer::Buffer(scoped_ptr<BufferBacking> backing) |
| 26 : backing_(backing.Pass()), |
| 27 memory_(backing_->GetMemory()), |
| 28 size_(backing_->GetSize()) { |
17 DCHECK(memory_) << "The memory must be mapped to create a Buffer"; | 29 DCHECK(memory_) << "The memory must be mapped to create a Buffer"; |
18 } | 30 } |
19 | 31 |
20 Buffer::~Buffer() {} | 32 Buffer::~Buffer() {} |
21 | 33 |
22 void* Buffer::GetDataAddress(uint32 data_offset, uint32 data_size) const { | 34 void* Buffer::GetDataAddress(uint32 data_offset, uint32 data_size) const { |
23 base::CheckedNumeric<uint32> end = data_offset; | 35 base::CheckedNumeric<uint32> end = data_offset; |
24 end += data_size; | 36 end += data_size; |
25 if (!end.IsValid() || end.ValueOrDie() > static_cast<uint32>(size_)) | 37 if (!end.IsValid() || end.ValueOrDie() > static_cast<uint32>(size_)) |
26 return NULL; | 38 return NULL; |
27 return static_cast<uint8*>(memory_) + data_offset; | 39 return static_cast<uint8*>(memory_) + data_offset; |
28 } | 40 } |
29 | 41 |
30 } // namespace gpu | 42 } // namespace gpu |
OLD | NEW |