Fix native memory leak caused by small HWUI path cache creation
HWUI calculates the texture size as w*h*bpp. In some cases, the
calculated path cache is small, but the actual memory allocated
in driver is 4k/8k/16k, much bigger than HWUI calculates.
Example: a 5*65 alpha texture, HWUI think it is 5*65*1 = 325 bytes,
but driver allocates 8K. An app can allocates up to 32M path textures,
which actually consumes 32M*(8*1024/325) = 806M memory.
Here we limit the number of path texture in the cache to 256, it
should be a pretty generous global limit.
Change-Id: I890819b73bb0b7f63e96bc3d9d0ff9469c16838c
diff --git a/libs/hwui/PathCache.h b/libs/hwui/PathCache.h
index 86c59b5..b361424 100644
--- a/libs/hwui/PathCache.h
+++ b/libs/hwui/PathCache.h
@@ -306,6 +306,12 @@
bool mDebugEnabled;
+ /**
+ * Driver allocated 4k/8k/16k memory for small path cache,
+ * limit the number of PathTexture in case occupy too much memory in hardware.
+ */
+ uint32_t mTexNum;
+
sp<PathProcessor> mProcessor;
Vector<uint32_t> mGarbage;