Loading libs/hwui/renderthread/CacheManager.cpp +10 −2 Original line number Diff line number Diff line Loading @@ -151,7 +151,12 @@ void CacheManager::trimMemory(TrimMemoryMode mode) { mGrContext->freeGpuResources(); break; case TrimMemoryMode::UiHidden: mGrContext->purgeUnlockedResources(mMaxResourceBytes - mBackgroundResourceBytes, true); // Here we purge all the unlocked scratch resources and then toggle the resources cache // limits between the background and max amounts. This causes the unlocked resources // that have persistent data to be purged in LRU order. mGrContext->purgeUnlockedResources(true); mGrContext->setResourceCacheLimits(mMaxResources, mBackgroundResourceBytes); mGrContext->setResourceCacheLimits(mMaxResources, mMaxResourceBytes); break; } } Loading @@ -161,7 +166,10 @@ void CacheManager::trimStaleResources() { return; } mGrContext->flush(); mGrContext->purgeResourcesNotUsedInMs(std::chrono::seconds(30)); // Here we purge all the unlocked scratch resources (leaving those resources w/ persistent data) // and then purge those w/ persistent data based on age. mGrContext->purgeUnlockedResources(true); mGrContext->purgeResourcesNotUsedInMs(std::chrono::seconds(10)); } sp<skiapipeline::VectorDrawableAtlas> CacheManager::acquireVectorDrawableAtlas() { Loading libs/hwui/tests/unit/CacheManagerTests.cpp +12 −2 Original line number Diff line number Diff line Loading @@ -20,6 +20,8 @@ #include "renderthread/EglManager.h" #include "tests/common/TestUtils.h" #include <SkImagePriv.h> using namespace android; using namespace android::uirenderer; using namespace android::uirenderer::renderthread; Loading Loading @@ -49,7 +51,12 @@ RENDERTHREAD_SKIA_PIPELINE_TEST(CacheManager, trimMemory) { surfaces.push_back(surface); } ASSERT_TRUE(1 < surfaces.size()); // create an image and pin it so that we have something with a unique key in the cache sk_sp<Bitmap> bitmap = Bitmap::allocateHeapBitmap(SkImageInfo::MakeA8(displayInfo.w, displayInfo.h)); sk_sp<SkColorFilter> filter; sk_sp<SkImage> image = bitmap->makeImage(&filter); ASSERT_TRUE(SkImage_pinAsTexture(image.get(), grContext)); // attempt to trim all memory while we still hold strong refs renderThread.cacheManager().trimMemory(CacheManager::TrimMemoryMode::Complete); Loading @@ -61,11 +68,14 @@ RENDERTHREAD_SKIA_PIPELINE_TEST(CacheManager, trimMemory) { surfaces[i].reset(); } // unpin the image which should add a unique purgeable key to the cache SkImage_unpinAsTexture(image.get(), grContext); // verify that we have enough purgeable bytes const size_t purgeableBytes = grContext->getResourceCachePurgeableBytes(); ASSERT_TRUE(renderThread.cacheManager().getBackgroundCacheSize() < purgeableBytes); // UI hidden and make sure only some got purged // UI hidden and make sure only some got purged (unique should remain) renderThread.cacheManager().trimMemory(CacheManager::TrimMemoryMode::UiHidden); ASSERT_TRUE(0 < grContext->getResourceCachePurgeableBytes()); ASSERT_TRUE(renderThread.cacheManager().getBackgroundCacheSize() > getCacheUsage(grContext)); Loading Loading
libs/hwui/renderthread/CacheManager.cpp +10 −2 Original line number Diff line number Diff line Loading @@ -151,7 +151,12 @@ void CacheManager::trimMemory(TrimMemoryMode mode) { mGrContext->freeGpuResources(); break; case TrimMemoryMode::UiHidden: mGrContext->purgeUnlockedResources(mMaxResourceBytes - mBackgroundResourceBytes, true); // Here we purge all the unlocked scratch resources and then toggle the resources cache // limits between the background and max amounts. This causes the unlocked resources // that have persistent data to be purged in LRU order. mGrContext->purgeUnlockedResources(true); mGrContext->setResourceCacheLimits(mMaxResources, mBackgroundResourceBytes); mGrContext->setResourceCacheLimits(mMaxResources, mMaxResourceBytes); break; } } Loading @@ -161,7 +166,10 @@ void CacheManager::trimStaleResources() { return; } mGrContext->flush(); mGrContext->purgeResourcesNotUsedInMs(std::chrono::seconds(30)); // Here we purge all the unlocked scratch resources (leaving those resources w/ persistent data) // and then purge those w/ persistent data based on age. mGrContext->purgeUnlockedResources(true); mGrContext->purgeResourcesNotUsedInMs(std::chrono::seconds(10)); } sp<skiapipeline::VectorDrawableAtlas> CacheManager::acquireVectorDrawableAtlas() { Loading
libs/hwui/tests/unit/CacheManagerTests.cpp +12 −2 Original line number Diff line number Diff line Loading @@ -20,6 +20,8 @@ #include "renderthread/EglManager.h" #include "tests/common/TestUtils.h" #include <SkImagePriv.h> using namespace android; using namespace android::uirenderer; using namespace android::uirenderer::renderthread; Loading Loading @@ -49,7 +51,12 @@ RENDERTHREAD_SKIA_PIPELINE_TEST(CacheManager, trimMemory) { surfaces.push_back(surface); } ASSERT_TRUE(1 < surfaces.size()); // create an image and pin it so that we have something with a unique key in the cache sk_sp<Bitmap> bitmap = Bitmap::allocateHeapBitmap(SkImageInfo::MakeA8(displayInfo.w, displayInfo.h)); sk_sp<SkColorFilter> filter; sk_sp<SkImage> image = bitmap->makeImage(&filter); ASSERT_TRUE(SkImage_pinAsTexture(image.get(), grContext)); // attempt to trim all memory while we still hold strong refs renderThread.cacheManager().trimMemory(CacheManager::TrimMemoryMode::Complete); Loading @@ -61,11 +68,14 @@ RENDERTHREAD_SKIA_PIPELINE_TEST(CacheManager, trimMemory) { surfaces[i].reset(); } // unpin the image which should add a unique purgeable key to the cache SkImage_unpinAsTexture(image.get(), grContext); // verify that we have enough purgeable bytes const size_t purgeableBytes = grContext->getResourceCachePurgeableBytes(); ASSERT_TRUE(renderThread.cacheManager().getBackgroundCacheSize() < purgeableBytes); // UI hidden and make sure only some got purged // UI hidden and make sure only some got purged (unique should remain) renderThread.cacheManager().trimMemory(CacheManager::TrimMemoryMode::UiHidden); ASSERT_TRUE(0 < grContext->getResourceCachePurgeableBytes()); ASSERT_TRUE(renderThread.cacheManager().getBackgroundCacheSize() > getCacheUsage(grContext)); Loading