1 // Copyright 2013 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 "content/common/gpu/client/gpu_memory_buffer_impl.h"
7 #include "ui/gl/gl_bindings.h"
11 GpuMemoryBufferImpl::GpuMemoryBufferImpl(
12 scoped_ptr<base::SharedMemory> shared_memory,
15 unsigned internalformat)
16 : shared_memory_(shared_memory.Pass()),
17 size_(gfx::Size(width, height)),
18 internalformat_(internalformat),
20 DCHECK(!shared_memory_->memory());
21 DCHECK(IsFormatValid(internalformat));
24 GpuMemoryBufferImpl::~GpuMemoryBufferImpl() {
27 void GpuMemoryBufferImpl::Map(AccessMode mode, void** vaddr) {
30 if (!shared_memory_->Map(size_.GetArea() * BytesPerPixel(internalformat_)))
32 *vaddr = shared_memory_->memory();
36 void GpuMemoryBufferImpl::Unmap() {
38 shared_memory_->Unmap();
42 bool GpuMemoryBufferImpl::IsMapped() const {
46 uint32 GpuMemoryBufferImpl::GetStride() const {
47 return size_.width() * BytesPerPixel(internalformat_);
50 gfx::GpuMemoryBufferHandle GpuMemoryBufferImpl::GetHandle() const {
51 gfx::GpuMemoryBufferHandle handle;
52 handle.type = gfx::SHARED_MEMORY_BUFFER;
53 handle.handle = shared_memory_->handle();
58 bool GpuMemoryBufferImpl::IsFormatValid(unsigned internalformat) {
59 // GL_RGBA8_OES is the only supported format at the moment.
60 switch (internalformat) {
69 size_t GpuMemoryBufferImpl::BytesPerPixel(unsigned internalformat) {
70 // GL_RGBA_OES has 4 bytes per pixel.
71 switch (internalformat) {
80 } // namespace content