summaryrefslogtreecommitdiff
path: root/libs/hwui/tests/unit/CacheManagerTests.cpp
diff options
context:
space:
mode:
authorDerek Sollenberger <djsollen@google.com>2018-04-02 13:36:45 -0400
committerDerek Sollenberger <djsollen@google.com>2018-04-03 11:53:43 -0400
commitb1f27aae89a9da9fbf3cb15a47f1a401db5a7974 (patch)
treeb0699bbb1fad7dc0649bfd03b1956b52834949ef /libs/hwui/tests/unit/CacheManagerTests.cpp
parent600fe676f7a164107a7501451483f5ffc2bbdd12 (diff)
Free up all scratch resources when the app's UI is hidden
Bug: 73808481 Test: hwui_unit_tests Change-Id: I9f191c776a936c1be40702ff0924c7ad054526d5
Diffstat (limited to 'libs/hwui/tests/unit/CacheManagerTests.cpp')
-rw-r--r--libs/hwui/tests/unit/CacheManagerTests.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/libs/hwui/tests/unit/CacheManagerTests.cpp b/libs/hwui/tests/unit/CacheManagerTests.cpp
index b1106f0d6a71..c235715073f5 100644
--- a/libs/hwui/tests/unit/CacheManagerTests.cpp
+++ b/libs/hwui/tests/unit/CacheManagerTests.cpp
@@ -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;
@@ -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);
@@ -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));