Fix crash in SpeechRecognizerImpl introduced in AudioParams refactor.
[chromium-blink-merge.git] / gpu / command_buffer / common / buffer.cc
blobe402886f9e38654d670bbb5f51b91a7ee5ed131b
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"
12 namespace gpu {
13 SharedMemoryBufferBacking::SharedMemoryBufferBacking(
14 scoped_ptr<base::SharedMemory> shared_memory,
15 size_t size)
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";
33 Buffer::~Buffer() {}
35 void* Buffer::GetDataAddress(uint32 data_offset, uint32 data_size) const {
36 base::CheckedNumeric<uint32> end = data_offset;
37 end += data_size;
38 if (!end.IsValid() || end.ValueOrDie() > static_cast<uint32>(size_))
39 return NULL;
40 return static_cast<uint8*>(memory_) + data_offset;
43 base::trace_event::MemoryAllocatorDumpGuid GetBufferGUIDForTracing(
44 uint64_t tracing_process_id,
45 int32_t buffer_id) {
46 return base::trace_event::MemoryAllocatorDumpGuid(base::StringPrintf(
47 "gpu-buffer-x-process/%" PRIx64 "/%d", tracing_process_id, buffer_id));
50 } // namespace gpu