Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / components / mus / gles2 / mojo_buffer_backing.cc
blob1beadb32cda3620f0c0b9d7fd264709c32ff55e0
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 "components/mus/gles2/mojo_buffer_backing.h"
7 #include "base/logging.h"
9 namespace mus {
11 MojoBufferBacking::MojoBufferBacking(mojo::ScopedSharedBufferHandle handle,
12 void* memory,
13 size_t size)
14 : handle_(handle.Pass()), memory_(memory), size_(size) {}
16 MojoBufferBacking::~MojoBufferBacking() {
17 mojo::UnmapBuffer(memory_);
20 // static
21 scoped_ptr<gpu::BufferBacking> MojoBufferBacking::Create(
22 mojo::ScopedSharedBufferHandle handle,
23 size_t size) {
24 void* memory = NULL;
25 MojoResult result = mojo::MapBuffer(handle.get(), 0, size, &memory,
26 MOJO_MAP_BUFFER_FLAG_NONE);
27 if (result != MOJO_RESULT_OK)
28 return scoped_ptr<BufferBacking>();
29 DCHECK(memory);
30 return scoped_ptr<BufferBacking>(
31 new MojoBufferBacking(handle.Pass(), memory, size));
33 void* MojoBufferBacking::GetMemory() const {
34 return memory_;
36 size_t MojoBufferBacking::GetSize() const {
37 return size_;
40 } // namespace mus