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. 4 5#include "content/common/gpu/client/gpu_memory_buffer_impl.h" 6 7#include "ui/gl/gl_bindings.h" 8 9namespace content { 10 11GpuMemoryBufferImpl::GpuMemoryBufferImpl( 12 gfx::Size size, unsigned internalformat) 13 : size_(size), 14 internalformat_(internalformat), 15 mapped_(false) { 16 DCHECK(IsFormatValid(internalformat)); 17} 18 19GpuMemoryBufferImpl::~GpuMemoryBufferImpl() { 20} 21 22// static 23bool GpuMemoryBufferImpl::IsFormatValid(unsigned internalformat) { 24 switch (internalformat) { 25 case GL_BGRA8_EXT: 26 case GL_RGBA8_OES: 27 return true; 28 default: 29 return false; 30 } 31} 32 33// static 34size_t GpuMemoryBufferImpl::BytesPerPixel(unsigned internalformat) { 35 switch (internalformat) { 36 case GL_BGRA8_EXT: 37 case GL_RGBA8_OES: 38 return 4; 39 default: 40 NOTREACHED(); 41 return 0; 42 } 43} 44 45bool GpuMemoryBufferImpl::IsMapped() const { 46 return mapped_; 47} 48 49uint32 GpuMemoryBufferImpl::GetStride() const { 50 return size_.width() * BytesPerPixel(internalformat_); 51} 52 53} // namespace content 54