From a43c3b27bc86bd9611fcfefa95b37843f8608f89 Mon Sep 17 00:00:00 2001 From: "sheu@chromium.org" Date: Tue, 23 Oct 2012 02:03:33 +0000 Subject: Fix glTexSubImage2D for non-32bpp formats. The non-mapped upload path for glTexSubImage2D is assuming 32bpp blindly, for all formats. TEST=local build, run on ARM (forcing non-mapped path) BUG=None Change-Id: Ib8ac46646b27faeeb8c19ebb519d321e25c1a8cb Review URL: https://chromiumcodereview.appspot.com/11229040 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@163477 0039d316-1c4b-4281-b951-d872f2087c98 --- cc/texture.cc | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'cc/texture.cc') diff --git a/cc/texture.cc b/cc/texture.cc index 9fd8ebe..f6400eb 100644 --- a/cc/texture.cc +++ b/cc/texture.cc @@ -5,6 +5,7 @@ #include "config.h" #include "cc/texture.h" +#include "third_party/khronos/GLES2/gl2ext.h" namespace cc { @@ -22,11 +23,27 @@ size_t Texture::bytes() const return memorySizeBytes(m_size, m_format); } -size_t Texture::memorySizeBytes(const IntSize& size, GLenum format) +size_t Texture::bytesPerPixel(GLenum format) { - unsigned int componentsPerPixel = 4; + unsigned int componentsPerPixel = 0; unsigned int bytesPerComponent = 1; - return componentsPerPixel * bytesPerComponent * size.width() * size.height(); + switch (format) { + case GL_RGBA: + case GL_BGRA_EXT: + componentsPerPixel = 4; + break; + case GL_LUMINANCE: + componentsPerPixel = 1; + break; + default: + NOTREACHED(); + } + return componentsPerPixel * bytesPerComponent; +} + +size_t Texture::memorySizeBytes(const IntSize& size, GLenum format) +{ + return bytesPerPixel(format) * size.width() * size.height(); } } -- cgit v1.1