summaryrefslogtreecommitdiff
path: root/libs/hwui/TextureCache.cpp
diff options
context:
space:
mode:
author Romain Guy <romainguy@google.com> 2010-06-30 17:56:19 -0700
committer Romain Guy <romainguy@google.com> 2010-06-30 17:56:19 -0700
commitc1396e93b6a5286a5183c00c781b62e940a12c1f (patch)
tree41da22a7756936c8cbc4687286e9b854235cd3f5 /libs/hwui/TextureCache.cpp
parentefcd77407b321498a43ca380c8f67b84eb5a2d6e (diff)
Add implementation for drawBitmap().
Change-Id: Iada9325f3c5642b61c2e0c4cd80bcfbc92cb491e
Diffstat (limited to 'libs/hwui/TextureCache.cpp')
-rw-r--r--libs/hwui/TextureCache.cpp30
1 files changed, 20 insertions, 10 deletions
diff --git a/libs/hwui/TextureCache.cpp b/libs/hwui/TextureCache.cpp
index c3b146306124..4e1650771310 100644
--- a/libs/hwui/TextureCache.cpp
+++ b/libs/hwui/TextureCache.cpp
@@ -41,7 +41,7 @@ Texture* TextureCache::get(SkBitmap* bitmap) {
Texture* texture = mCache.get(bitmap);
if (!texture) {
texture = new Texture;
- generateTexture(bitmap, texture);
+ generateTexture(bitmap, texture, false);
mCache.put(bitmap, texture);
} else if (bitmap->getGenerationID() != texture->generation) {
generateTexture(bitmap, texture, true);
@@ -58,7 +58,14 @@ void TextureCache::clear() {
}
void TextureCache::generateTexture(SkBitmap* bitmap, Texture* texture, bool regenerate) {
+ SkAutoLockPixels alp(*bitmap);
+ if (!bitmap->readyToDraw()) {
+ LOGE("Cannot generate texture from bitmap");
+ return;
+ }
+
if (!regenerate) {
+ texture->generation = bitmap->getGenerationID();
texture->width = bitmap->width();
texture->height = bitmap->height();
@@ -66,25 +73,28 @@ void TextureCache::generateTexture(SkBitmap* bitmap, Texture* texture, bool rege
}
glBindTexture(GL_TEXTURE_2D, texture->id);
-
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ glPixelStorei(GL_UNPACK_ALIGNMENT, bitmap->bytesPerPixel());
switch (bitmap->getConfig()) {
case SkBitmap::kRGB_565_Config:
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB565, texture->width, texture->height,
- 0, GL_RGB565, GL_UNSIGNED_SHORT_5_6_5, bitmap->getPixels());
+ texture->blend = false;
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, bitmap->rowBytesAsPixels(), texture->height, 0,
+ GL_RGB, GL_UNSIGNED_SHORT_5_6_5, bitmap->getPixels());
break;
case SkBitmap::kARGB_8888_Config:
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture->width, texture->height,
- 0, GL_RGBA, GL_UNSIGNED_BYTE, bitmap->getPixels());
+ texture->blend = true;
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bitmap->rowBytesAsPixels(), texture->height, 0,
+ GL_RGBA, GL_UNSIGNED_BYTE, bitmap->getPixels());
break;
default:
break;
}
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+
glBindTexture(GL_TEXTURE_2D, 0);
}