diff options
author | 2016-10-12 14:08:49 -0700 | |
---|---|---|
committer | 2016-10-12 14:18:17 -0700 | |
commit | cecec702eb436ddfec1e1c68d379a4dc1ef37f63 (patch) | |
tree | 45d1abd6c290056206996c54833daa248542306f /libs/hwui/PathCache.cpp | |
parent | 21986f2ae73e9ae3395a37dd3976af55e75d4f9d (diff) |
Fatal abort on invalid state
Use mCaches.size() to track item count instead of trying
to do it manually on the side.
Bug: 31856965
Test: manual, minimal. Repro steps for bug are unknown, fix
is speculative as a result
Change-Id: Ic32f27262548a99be95440881420d224ede4db74
Diffstat (limited to 'libs/hwui/PathCache.cpp')
-rw-r--r-- | libs/hwui/PathCache.cpp | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/libs/hwui/PathCache.cpp b/libs/hwui/PathCache.cpp index eb606cb037e9..e69ea79ccfb9 100644 --- a/libs/hwui/PathCache.cpp +++ b/libs/hwui/PathCache.cpp @@ -182,8 +182,7 @@ static SkBitmap* drawPath(const SkPath* path, const SkPaint* paint, PathTexture* PathCache::PathCache() : mCache(LruCache<PathDescription, PathTexture*>::kUnlimitedCapacity) , mSize(0) - , mMaxSize(Properties::pathCacheSize) - , mTexNum(0) { + , mMaxSize(Properties::pathCacheSize) { mCache.setOnEntryRemovedListener(this); GLint maxTextureSize; @@ -239,7 +238,6 @@ void PathCache::removeTexture(PathTexture* texture) { "the cache in an inconsistent state", size); } mSize -= size; - mTexNum--; } PATH_LOGD("PathCache::delete name, size, mSize = %d, %d, %d", @@ -264,7 +262,14 @@ void PathCache::purgeCache(uint32_t width, uint32_t height) { } void PathCache::trim() { - while (mSize > mMaxSize || mTexNum > DEFAULT_PATH_TEXTURE_CAP) { + // 25 is just an arbitrary lower bound to ensure we aren't in weird edge cases + // of things like a cap of 0 or 1 as that's going to break things. + // It does not represent a reasonable minimum value + static_assert(DEFAULT_PATH_TEXTURE_CAP > 25, "Path cache texture cap is too small"); + + while (mSize > mMaxSize || mCache.size() > DEFAULT_PATH_TEXTURE_CAP) { + LOG_ALWAYS_FATAL_IF(!mCache.size(), "Inconsistent mSize! Ran out of items to remove!" + " mSize = %u, mMaxSize = %u", mSize, mMaxSize); mCache.removeOldest(); } } @@ -312,7 +317,6 @@ void PathCache::generateTexture(SkBitmap& bitmap, Texture* texture) { ATRACE_NAME("Upload Path Texture"); texture->upload(bitmap); texture->setFilter(GL_LINEAR); - mTexNum++; } /////////////////////////////////////////////////////////////////////////////// |