HWUI: calculate used memory in FontCache for gfxinfo
bug:30427106
Change-Id: I653571d6a4e974e975fb0dc03fc2364eecbf2f84
diff --git a/libs/hwui/font/CacheTexture.cpp b/libs/hwui/font/CacheTexture.cpp
index 8ba4761..4b13814 100644
--- a/libs/hwui/font/CacheTexture.cpp
+++ b/libs/hwui/font/CacheTexture.cpp
@@ -324,5 +324,17 @@
return false;
}
+uint32_t CacheTexture::calculateFreeMemory() const {
+ CacheBlock* cacheBlock = mCacheBlocks;
+ uint32_t free = 0;
+ // currently only two formats are supported: GL_ALPHA or GL_RGBA;
+ uint32_t bpp = mFormat == GL_RGBA ? 4 : 1;
+ while (cacheBlock) {
+ free += bpp * cacheBlock->mWidth * cacheBlock->mHeight;
+ cacheBlock = cacheBlock->mNext;
+ }
+ return free;
+}
+
}; // namespace uirenderer
}; // namespace android
diff --git a/libs/hwui/font/CacheTexture.h b/libs/hwui/font/CacheTexture.h
index 4dfb41d..6750a8a 100644
--- a/libs/hwui/font/CacheTexture.h
+++ b/libs/hwui/font/CacheTexture.h
@@ -178,6 +178,8 @@
return mCurrentQuad == mMaxQuadCount;
}
+ uint32_t calculateFreeMemory() const;
+
private:
void setDirty(bool dirty);