From 7adaf3d1aa18c7e521f7154e545fe52d329763c3 Mon Sep 17 00:00:00 2001 From: Romain Guy Date: Tue, 5 Oct 2010 14:58:09 -0700 Subject: Add support for paletted textures. Change-Id: I36e6069bd58f78c609cdd1f3e4560c98f128f48e --- libs/hwui/TextureCache.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'libs/hwui/TextureCache.cpp') diff --git a/libs/hwui/TextureCache.cpp b/libs/hwui/TextureCache.cpp index adf6ee2757b0..701df8358964 100644 --- a/libs/hwui/TextureCache.cpp +++ b/libs/hwui/TextureCache.cpp @@ -18,6 +18,8 @@ #include +#include + #include #include "TextureCache.h" @@ -192,8 +194,12 @@ void TextureCache::generateTexture(SkBitmap* bitmap, Texture* texture, bool rege // decoding happened texture->blend = !bitmap->isOpaque(); break; + case SkBitmap::kIndex8_Config: + uploadPalettedTexture(resize, bitmap, texture->width, texture->height); + texture->blend = false; + break; default: - LOGW("Unsupported bitmap config"); + LOGW("Unsupported bitmap config: %d", bitmap->getConfig()); break; } @@ -204,6 +210,20 @@ void TextureCache::generateTexture(SkBitmap* bitmap, Texture* texture, bool rege glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); } +void TextureCache::uploadPalettedTexture(bool resize, SkBitmap* bitmap, + uint32_t width, uint32_t height) { + SkBitmap rgbaBitmap; + rgbaBitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); + rgbaBitmap.allocPixels(); + rgbaBitmap.eraseColor(0); + + SkCanvas canvas(rgbaBitmap); + canvas.drawBitmap(*bitmap, 0.0f, 0.0f, NULL); + + uploadToTexture(resize, GL_RGBA, rgbaBitmap.rowBytesAsPixels(), height, + GL_UNSIGNED_BYTE, rgbaBitmap.getPixels()); +} + void TextureCache::uploadToTexture(bool resize, GLenum format, GLsizei width, GLsizei height, GLenum type, const GLvoid * data) { if (resize) { -- cgit v1.2.3-59-g8ed1b