Improve time to texture destruction
Eliminate textureCache.mGarbage which is only cleared
in a trimMemory. Instead when we hit ~Bitmap post a
message to RenderThread to release the texture immediately
Bug: 38258699
Test: manual
Change-Id: I962ba275e89afb628ba02f74769287edbab9fed4
diff --git a/libs/hwui/TextureCache.cpp b/libs/hwui/TextureCache.cpp
index 63a6a2c..710cdd9 100644
--- a/libs/hwui/TextureCache.cpp
+++ b/libs/hwui/TextureCache.cpp
@@ -191,25 +191,14 @@
return texture;
}
-void TextureCache::releaseTexture(uint32_t pixelRefStableID) {
- Mutex::Autolock _l(mLock);
- mGarbage.push_back(pixelRefStableID);
-}
-
-void TextureCache::clearGarbage() {
- Mutex::Autolock _l(mLock);
- size_t count = mGarbage.size();
- for (size_t i = 0; i < count; i++) {
- uint32_t pixelRefId = mGarbage[i];
- auto hardwareIter = mHardwareTextures.find(pixelRefId);
- if (hardwareIter == mHardwareTextures.end()) {
- mCache.remove(pixelRefId);
- } else {
- hardwareIter->second->deleteTexture();
- mHardwareTextures.erase(hardwareIter);
- }
+bool TextureCache::destroyTexture(uint32_t pixelRefStableID) {
+ auto hardwareIter = mHardwareTextures.find(pixelRefStableID);
+ if (hardwareIter != mHardwareTextures.end()) {
+ hardwareIter->second->deleteTexture();
+ mHardwareTextures.erase(hardwareIter);
+ return true;
}
- mGarbage.clear();
+ return mCache.remove(pixelRefStableID);
}
void TextureCache::clear() {