From ebd52610cfeff6e557fde284a7e1efc5e6438285 Mon Sep 17 00:00:00 2001 From: John Reck Date: Wed, 10 Dec 2014 16:47:36 -0800 Subject: Don't preload textures for AssetAtlas Bug: 18317479 RenderNode::prepareSubTree calls prefetchAndMarkInUse on every bitmapResoruce in the DisplayList. However, this resulted in textures being uploaded for bitmaps that would be drawn from the AssetAtlas instead. To fix this we teach TextureCache about the AssetAtlas so that calls to TextureCache return the Texture from AssetAtlas if it exists. Thus usage of AssetAtlas is now purely to allow for further optimizations via draw merging instead of a requirement to get any benefit at all. Change-Id: I65282fa05bac46f4e93822b3467ffa0261ccf200 --- libs/hwui/TextureCache.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'libs/hwui/TextureCache.cpp') diff --git a/libs/hwui/TextureCache.cpp b/libs/hwui/TextureCache.cpp index 5bad2fc43e6f..63454d8ef7c9 100644 --- a/libs/hwui/TextureCache.cpp +++ b/libs/hwui/TextureCache.cpp @@ -24,6 +24,7 @@ #include +#include "AssetAtlas.h" #include "Caches.h" #include "TextureCache.h" #include "Properties.h" @@ -39,7 +40,7 @@ namespace uirenderer { TextureCache::TextureCache(): mCache(LruCache::kUnlimitedCapacity), mSize(0), mMaxSize(MB(DEFAULT_TEXTURE_CACHE_SIZE)), - mFlushRate(DEFAULT_TEXTURE_CACHE_FLUSH_RATE) { + mFlushRate(DEFAULT_TEXTURE_CACHE_FLUSH_RATE), mAssetAtlas(0) { char property[PROPERTY_VALUE_MAX]; if (property_get(PROPERTY_TEXTURE_CACHE_SIZE, property, NULL) > 0) { INIT_LOGD(" Setting texture cache size to %sMB", property); @@ -62,7 +63,7 @@ TextureCache::TextureCache(): TextureCache::TextureCache(uint32_t maxByteSize): mCache(LruCache::kUnlimitedCapacity), - mSize(0), mMaxSize(maxByteSize) { + mSize(0), mMaxSize(maxByteSize), mAssetAtlas(0) { init(); } @@ -124,6 +125,10 @@ void TextureCache::operator()(uint32_t&, Texture*& texture) { // Caching /////////////////////////////////////////////////////////////////////////////// +void TextureCache::setAssetAtlas(AssetAtlas* assetAtlas) { + mAssetAtlas = assetAtlas; +} + void TextureCache::resetMarkInUse() { LruCache::Iterator iter(mCache); while (iter.next()) { @@ -143,6 +148,13 @@ bool TextureCache::canMakeTextureFromBitmap(const SkBitmap* bitmap) { // Returns a prepared Texture* that either is already in the cache or can fit // in the cache (and is thus added to the cache) Texture* TextureCache::getCachedTexture(const SkBitmap* bitmap) { + if (CC_LIKELY(mAssetAtlas)) { + AssetAtlas::Entry* entry = mAssetAtlas->getEntry(bitmap); + if (CC_UNLIKELY(entry)) { + return entry->texture; + } + } + Texture* texture = mCache.get(bitmap->pixelRef()->getStableID()); if (!texture) { -- cgit v1.2.3-59-g8ed1b