diff options
author | sheu@chromium.org <sheu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-24 20:39:06 +0000 |
---|---|---|
committer | sheu@chromium.org <sheu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-24 20:39:06 +0000 |
commit | 289723b6fa3b0b0050be64880aaacaadc38ca47e (patch) | |
tree | 4547d54b284633cf65a0b002de4b2cfd5414ccd1 /cc | |
parent | 2c1d91fdf9d8bbed2b0849a7f77c0221015106d2 (diff) | |
download | chromium_src-289723b6fa3b0b0050be64880aaacaadc38ca47e.zip chromium_src-289723b6fa3b0b0050be64880aaacaadc38ca47e.tar.gz chromium_src-289723b6fa3b0b0050be64880aaacaadc38ca47e.tar.bz2 |
Fix glTexSubImage2D for non-32bpp formats (rev. 2)
The non-mapped upload path for glTexSubImage2D is assuming 32bpp
blindly, for all formats.
Native texture video frames have no CPU-side plane data to upload.
Update unit test to reflect this.
TEST=local build, run on ARM (forcing non-mapped path)
BUG=None
Change-Id: Ifefd7eacb187767e239acbea5201cf490b39715c
Review URL: https://chromiumcodereview.appspot.com/11281002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@163894 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc')
-rw-r--r-- | cc/layer_tree_host_impl_unittest.cc | 2 | ||||
-rw-r--r-- | cc/texture.cc | 23 | ||||
-rw-r--r-- | cc/texture.h | 1 | ||||
-rw-r--r-- | cc/texture_uploader.cc | 34 |
4 files changed, 34 insertions, 26 deletions
diff --git a/cc/layer_tree_host_impl_unittest.cc b/cc/layer_tree_host_impl_unittest.cc index 5817af4..68a4b7f 100644 --- a/cc/layer_tree_host_impl_unittest.cc +++ b/cc/layer_tree_host_impl_unittest.cc @@ -2540,7 +2540,7 @@ public: virtual Format format() const { return m_textureId ? FormatNativeTexture : FormatYV12; } virtual unsigned width() const { return 4; } virtual unsigned height() const { return 4; } - virtual unsigned planes() const { return 3; } + virtual unsigned planes() const { return m_textureId ? 0 : 3; } virtual int stride(unsigned plane) const { return 4; } virtual const void* data(unsigned plane) const { return m_data; } virtual unsigned textureId() const { return m_textureId; } 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(); } } diff --git a/cc/texture.h b/cc/texture.h index aecec16..af5d40b 100644 --- a/cc/texture.h +++ b/cc/texture.h @@ -28,6 +28,7 @@ public: size_t bytes() const; + static size_t bytesPerPixel(GLenum format); static size_t memorySizeBytes(const IntSize&, GLenum format); private: diff --git a/cc/texture_uploader.cc b/cc/texture_uploader.cc index 98d15bb..50e759e 100644 --- a/cc/texture_uploader.cc +++ b/cc/texture_uploader.cc @@ -12,6 +12,7 @@ #include "base/debug/alias.h" #include "base/debug/trace_event.h" #include "base/metrics/histogram.h" +#include "cc/texture.h" #include "cc/prioritized_texture.h" #include "third_party/khronos/GLES2/gl2.h" #include "third_party/khronos/GLES2/gl2ext.h" @@ -207,10 +208,12 @@ void TextureUploader::uploadWithTexSubImage(const uint8_t* image, source_rect.y() - image_rect.y()); const uint8_t* pixel_source; + unsigned int bytes_per_pixel = Texture::bytesPerPixel(format); + if (image_rect.width() == source_rect.width() && !offset.x()) { - pixel_source = &image[4 * offset.y() * image_rect.width()]; + pixel_source = &image[bytes_per_pixel * offset.y() * image_rect.width()]; } else { - size_t needed_size = source_rect.width() * source_rect.height() * 4; + size_t needed_size = source_rect.width() * source_rect.height() * bytes_per_pixel; if (m_subImageSize < needed_size) { m_subImage.reset(new uint8_t[needed_size]); m_subImageSize = needed_size; @@ -218,10 +221,10 @@ void TextureUploader::uploadWithTexSubImage(const uint8_t* image, // Strides not equal, so do a row-by-row memcpy from the // paint results into a temp buffer for uploading. for (int row = 0; row < source_rect.height(); ++row) - memcpy(&m_subImage[source_rect.width() * 4 * row], - &image[4 * (offset.x() + - (offset.y() + row) * image_rect.width())], - source_rect.width() * 4); + memcpy(&m_subImage[source_rect.width() * bytes_per_pixel * row], + &image[bytes_per_pixel * (offset.x() + + (offset.y() + row) * image_rect.width())], + source_rect.width() * bytes_per_pixel); pixel_source = &m_subImage[0]; } @@ -290,20 +293,7 @@ void TextureUploader::uploadWithMapTexSubImage(const uint8_t* image, return; } - unsigned int components_per_pixel = 0; - switch (format) { - case GL_RGBA: - case GL_BGRA_EXT: - components_per_pixel = 4; - break; - case GL_LUMINANCE: - components_per_pixel = 1; - break; - default: - NOTREACHED(); - } - unsigned int bytes_per_component = 1; - unsigned int bytes_per_pixel = components_per_pixel * bytes_per_component; + unsigned int bytes_per_pixel = Texture::bytesPerPixel(format); if (image_rect.width() == source_rect.width() && !offset.x()) { memcpy(pixel_dest, @@ -314,8 +304,8 @@ void TextureUploader::uploadWithMapTexSubImage(const uint8_t* image, // paint results into the pixelDest for (int row = 0; row < source_rect.height(); ++row) memcpy(&pixel_dest[source_rect.width() * row * bytes_per_pixel], - &image[4 * (offset.x() + - (offset.y() + row) * image_rect.width())], + &image[bytes_per_pixel * (offset.x() + + (offset.y() + row) * image_rect.width())], source_rect.width() * bytes_per_pixel); } |