summaryrefslogtreecommitdiffstats
path: root/libs/hwui/TextureCache.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libs/hwui/TextureCache.cpp')
-rw-r--r--libs/hwui/TextureCache.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/libs/hwui/TextureCache.cpp b/libs/hwui/TextureCache.cpp
index 4975edb..3f9698d 100644
--- a/libs/hwui/TextureCache.cpp
+++ b/libs/hwui/TextureCache.cpp
@@ -31,6 +31,9 @@ TextureCache::TextureCache(uint32_t maxByteSize):
mCache(GenerationCache<SkBitmap*, Texture*>::kUnlimitedCapacity),
mSize(0), mMaxSize(maxByteSize) {
mCache.setOnEntryRemovedListener(this);
+
+ glGetIntegerv(GL_MAX_TEXTURE_SIZE, &mMaxTextureSize);
+ LOGD("Maximum texture dimension is %d pixels", mMaxTextureSize);
}
TextureCache::~TextureCache() {
@@ -79,6 +82,11 @@ void TextureCache::operator()(SkBitmap*& bitmap, Texture*& texture) {
Texture* TextureCache::get(SkBitmap* bitmap) {
Texture* texture = mCache.get(bitmap);
if (!texture) {
+ if (bitmap->width() > mMaxTextureSize || bitmap->height() > mMaxTextureSize) {
+ LOGW("Bitmap too large to be uploaded into a texture");
+ return NULL;
+ }
+
const uint32_t size = bitmap->rowBytes() * bitmap->height();
// Don't even try to cache a bitmap that's bigger than the cache
if (size < mMaxSize) {
@@ -93,11 +101,13 @@ Texture* TextureCache::get(SkBitmap* bitmap) {
if (size < mMaxSize) {
mSize += size;
mCache.put(bitmap, texture);
+ } else {
+ texture->cleanup = true;
}
} else if (bitmap->getGenerationID() != texture->generation) {
generateTexture(bitmap, texture, true);
}
- // TODO: Do something to destroy the texture object if it's too big for the cache
+
return texture;
}