From b1f27aae89a9da9fbf3cb15a47f1a401db5a7974 Mon Sep 17 00:00:00 2001 From: Derek Sollenberger Date: Mon, 2 Apr 2018 13:36:45 -0400 Subject: Free up all scratch resources when the app's UI is hidden Bug: 73808481 Test: hwui_unit_tests Change-Id: I9f191c776a936c1be40702ff0924c7ad054526d5 --- libs/hwui/renderthread/CacheManager.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'libs/hwui/renderthread/CacheManager.cpp') diff --git a/libs/hwui/renderthread/CacheManager.cpp b/libs/hwui/renderthread/CacheManager.cpp index 32d4c77c5fc3..3ca92953e5f7 100644 --- a/libs/hwui/renderthread/CacheManager.cpp +++ b/libs/hwui/renderthread/CacheManager.cpp @@ -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; } } @@ -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 CacheManager::acquireVectorDrawableAtlas() { -- cgit v1.2.3