[Sync] Fix invalidations on Android.
[chromium-blink-merge.git] / mojo / services / gles2 / mojo_buffer_backing.cc
blob3e6c38e99d17699d351d056cb7fad2a61273470e
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 "mojo/services/gles2/mojo_buffer_backing.h"
7 #include "base/logging.h"
9 namespace gles2 {
11 MojoBufferBacking::MojoBufferBacking(mojo::ScopedSharedBufferHandle handle,
12 void* memory,
13 size_t size)
14 : handle_(handle.Pass()), memory_(memory), size_(size) {}
16 MojoBufferBacking::~MojoBufferBacking() { mojo::UnmapBuffer(memory_); }
18 // static
19 scoped_ptr<gpu::BufferBacking> MojoBufferBacking::Create(
20 mojo::ScopedSharedBufferHandle handle,
21 size_t size) {
22 void* memory = NULL;
23 MojoResult result = mojo::MapBuffer(
24 handle.get(), 0, size, &memory, MOJO_MAP_BUFFER_FLAG_NONE);
25 if (result != MOJO_RESULT_OK)
26 return scoped_ptr<BufferBacking>();
27 DCHECK(memory);
28 return scoped_ptr<BufferBacking>(
29 new MojoBufferBacking(handle.Pass(), memory, size));
31 void* MojoBufferBacking::GetMemory() const { return memory_; }
32 size_t MojoBufferBacking::GetSize() const { return size_; }
34 } // namespace gles2