diff options
author | 2017-01-30 14:24:48 -0800 | |
---|---|---|
committer | 2017-01-30 15:13:07 -0800 | |
commit | 00783be809c1176fa9e904b76b3d56f268dcc4da (patch) | |
tree | 01eb1305e499d8dfa5ea9d973fd5b2a90c04d65f | |
parent | df9a4f9a7c599ccd2348d429e6a6f0a5a415f780 (diff) |
Don't count hw bitmap's textures in TextureCache
Test: refactoring CL.
bug: 34751775
Change-Id: I0f7c8338817329a5c75cec4e8b944779587d7b7f
-rw-r--r-- | libs/hwui/TextureCache.cpp | 43 | ||||
-rw-r--r-- | libs/hwui/TextureCache.h | 2 |
2 files changed, 33 insertions, 12 deletions
diff --git a/libs/hwui/TextureCache.cpp b/libs/hwui/TextureCache.cpp index 14ffc85a4f68..1aeb8d684a29 100644 --- a/libs/hwui/TextureCache.cpp +++ b/libs/hwui/TextureCache.cpp @@ -101,9 +101,31 @@ bool TextureCache::canMakeTextureFromBitmap(Bitmap* bitmap) { return true; } +Texture* TextureCache::createTexture(Bitmap* bitmap) { + Texture* texture = new Texture(Caches::getInstance()); + texture->bitmapSize = bitmap->rowBytes() * bitmap->height(); + texture->generation = bitmap->getGenerationID(); + texture->upload(*bitmap); + return texture; +} + // 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(Bitmap* bitmap) { + if (bitmap->isHardware()) { + auto textureIterator = mHardwareTextures.find(bitmap->getStableID()); + if (textureIterator == mHardwareTextures.end()) { + Texture* texture = createTexture(bitmap); + mHardwareTextures.insert(std::make_pair(bitmap->getStableID(), + std::unique_ptr<Texture>(texture))); + if (mDebugEnabled) { + ALOGD("Texture created for hw bitmap size = %d", texture->bitmapSize); + } + return texture; + } + return textureIterator->second.get(); + } + Texture* texture = mCache.get(bitmap->getStableID()); if (!texture) { @@ -124,11 +146,7 @@ Texture* TextureCache::getCachedTexture(Bitmap* bitmap) { } if (canCache) { - texture = new Texture(Caches::getInstance()); - texture->bitmapSize = size; - texture->generation = bitmap->getGenerationID(); - texture->upload(*bitmap); - + texture = createTexture(bitmap); mSize += size; TEXTURE_LOGD("TextureCache::get: create texture(%p): name, size, mSize = %d, %d, %d", bitmap, texture->id, size, mSize); @@ -166,12 +184,7 @@ Texture* TextureCache::get(Bitmap* bitmap) { if (!canMakeTextureFromBitmap(bitmap)) { return nullptr; } - - const uint32_t size = bitmap->rowBytes() * bitmap->height(); - texture = new Texture(Caches::getInstance()); - texture->bitmapSize = size; - texture->upload(*bitmap); - texture->generation = bitmap->getGenerationID(); + texture = createTexture(bitmap); texture->cleanup = true; } @@ -188,7 +201,13 @@ void TextureCache::clearGarbage() { size_t count = mGarbage.size(); for (size_t i = 0; i < count; i++) { uint32_t pixelRefId = mGarbage[i]; - mCache.remove(pixelRefId); + auto hardwareIter = mHardwareTextures.find(pixelRefId); + if (hardwareIter == mHardwareTextures.end()) { + mCache.remove(pixelRefId); + } else { + hardwareIter->second->deleteTexture(); + mHardwareTextures.erase(hardwareIter); + } } mGarbage.clear(); } diff --git a/libs/hwui/TextureCache.h b/libs/hwui/TextureCache.h index 68a548bdb1ff..a55b061818a3 100644 --- a/libs/hwui/TextureCache.h +++ b/libs/hwui/TextureCache.h @@ -125,6 +125,7 @@ private: bool canMakeTextureFromBitmap(Bitmap* bitmap); Texture* getCachedTexture(Bitmap* bitmap); + Texture* createTexture(Bitmap* bitmap); LruCache<uint32_t, Texture*> mCache; @@ -137,6 +138,7 @@ private: bool mDebugEnabled; std::vector<uint32_t> mGarbage; + std::unordered_map<uint32_t, std::unique_ptr<Texture>> mHardwareTextures; mutable Mutex mLock; }; // class TextureCache |