diff options
Diffstat (limited to 'libs/hwui/TextureCache.cpp')
| -rw-r--r-- | libs/hwui/TextureCache.cpp | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/libs/hwui/TextureCache.cpp b/libs/hwui/TextureCache.cpp index 2378eb5..ed0a79a 100644 --- a/libs/hwui/TextureCache.cpp +++ b/libs/hwui/TextureCache.cpp @@ -112,7 +112,7 @@ void TextureCache::operator()(SkBitmap*& bitmap, Texture*& texture) { if (mDebugEnabled) { ALOGD("Texture deleted, size = %d", texture->bitmapSize); } - glDeleteTextures(1, &texture->id); + texture->deleteTexture(); delete texture; } } @@ -139,7 +139,7 @@ Texture* TextureCache::get(SkBitmap* bitmap) { } } - texture = new Texture; + texture = new Texture(); texture->bitmapSize = size; generateTexture(bitmap, texture, false); @@ -162,7 +162,7 @@ Texture* TextureCache::get(SkBitmap* bitmap) { } Texture* TextureCache::getTransient(SkBitmap* bitmap) { - Texture* texture = new Texture; + Texture* texture = new Texture(); texture->bitmapSize = bitmap->rowBytes() * bitmap->height(); texture->cleanup = true; @@ -235,25 +235,25 @@ void TextureCache::generateTexture(SkBitmap* bitmap, Texture* texture, bool rege texture->width = bitmap->width(); texture->height = bitmap->height(); - glBindTexture(GL_TEXTURE_2D, texture->id); + Caches::getInstance().bindTexture(texture->id); switch (bitmap->getConfig()) { case SkBitmap::kA8_Config: glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - uploadToTexture(resize, GL_ALPHA, bitmap->rowBytesAsPixels(), texture->height, - GL_UNSIGNED_BYTE, bitmap->getPixels()); + uploadToTexture(resize, GL_ALPHA, bitmap->rowBytesAsPixels(), + texture->width, texture->height, GL_UNSIGNED_BYTE, bitmap->getPixels()); texture->blend = true; break; case SkBitmap::kRGB_565_Config: glPixelStorei(GL_UNPACK_ALIGNMENT, bitmap->bytesPerPixel()); - uploadToTexture(resize, GL_RGB, bitmap->rowBytesAsPixels(), texture->height, - GL_UNSIGNED_SHORT_5_6_5, bitmap->getPixels()); + uploadToTexture(resize, GL_RGB, bitmap->rowBytesAsPixels(), + texture->width, texture->height, GL_UNSIGNED_SHORT_5_6_5, bitmap->getPixels()); texture->blend = false; break; case SkBitmap::kARGB_8888_Config: glPixelStorei(GL_UNPACK_ALIGNMENT, bitmap->bytesPerPixel()); - uploadToTexture(resize, GL_RGBA, bitmap->rowBytesAsPixels(), texture->height, - GL_UNSIGNED_BYTE, bitmap->getPixels()); + uploadToTexture(resize, GL_RGBA, bitmap->rowBytesAsPixels(), + texture->width, texture->height, GL_UNSIGNED_BYTE, bitmap->getPixels()); // Do this after calling getPixels() to make sure Skia's deferred // decoding happened texture->blend = !bitmap->isOpaque(); @@ -293,17 +293,28 @@ void TextureCache::uploadLoFiTexture(bool resize, SkBitmap* bitmap, SkCanvas canvas(rgbaBitmap); canvas.drawBitmap(*bitmap, 0.0f, 0.0f, NULL); - uploadToTexture(resize, GL_RGBA, rgbaBitmap.rowBytesAsPixels(), height, + uploadToTexture(resize, GL_RGBA, rgbaBitmap.rowBytesAsPixels(), width, height, GL_UNSIGNED_BYTE, rgbaBitmap.getPixels()); } -void TextureCache::uploadToTexture(bool resize, GLenum format, GLsizei width, GLsizei height, - GLenum type, const GLvoid * data) { +void TextureCache::uploadToTexture(bool resize, GLenum format, GLsizei stride, + GLsizei width, GLsizei height, GLenum type, const GLvoid * data) { + // TODO: With OpenGL ES 2.0 we need to copy the bitmap in a temporary buffer + // if the stride doesn't match the width + const bool useStride = stride != width && Extensions::getInstance().hasUnpackRowLength(); + if (useStride) { + glPixelStorei(GL_UNPACK_ROW_LENGTH, stride); + } + if (resize) { glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, type, data); } else { glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, format, type, data); } + + if (useStride) { + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + } } }; // namespace uirenderer |
