resolve merge conflicts of 24e38ab to stage-aosp-master

Change-Id: I25844e17d2d6371ed786833c756051d19d0abec4
diff --git a/libs/hwui/PathCache.cpp b/libs/hwui/PathCache.cpp
index 1c298b1..eb606cb 100644
--- a/libs/hwui/PathCache.cpp
+++ b/libs/hwui/PathCache.cpp
@@ -182,7 +182,8 @@
 PathCache::PathCache()
         : mCache(LruCache<PathDescription, PathTexture*>::kUnlimitedCapacity)
         , mSize(0)
-        , mMaxSize(Properties::pathCacheSize) {
+        , mMaxSize(Properties::pathCacheSize)
+        , mTexNum(0) {
     mCache.setOnEntryRemovedListener(this);
 
     GLint maxTextureSize;
@@ -238,6 +239,7 @@
                         "the cache in an inconsistent state", size);
             }
             mSize -= size;
+            mTexNum--;
         }
 
         PATH_LOGD("PathCache::delete name, size, mSize = %d, %d, %d",
@@ -262,7 +264,7 @@
 }
 
 void PathCache::trim() {
-    while (mSize > mMaxSize) {
+    while (mSize > mMaxSize || mTexNum > DEFAULT_PATH_TEXTURE_CAP) {
         mCache.removeOldest();
     }
 }
@@ -310,6 +312,7 @@
     ATRACE_NAME("Upload Path Texture");
     texture->upload(bitmap);
     texture->setFilter(GL_LINEAR);
+    mTexNum++;
 }
 
 ///////////////////////////////////////////////////////////////////////////////
diff --git a/libs/hwui/PathCache.h b/libs/hwui/PathCache.h
index 18bcc56..b45a2c5 100644
--- a/libs/hwui/PathCache.h
+++ b/libs/hwui/PathCache.h
@@ -281,6 +281,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;
 
     std::vector<uint32_t> mGarbage;
diff --git a/libs/hwui/Properties.h b/libs/hwui/Properties.h
index 133ae80..44d7010 100644
--- a/libs/hwui/Properties.h
+++ b/libs/hwui/Properties.h
@@ -224,6 +224,9 @@
 
 #define DEFAULT_TEXT_GAMMA 1.4f
 
+// cap to 256 to limite paths in the path cache
+#define DEFAULT_PATH_TEXTURE_CAP 256
+
 ///////////////////////////////////////////////////////////////////////////////
 // Misc
 ///////////////////////////////////////////////////////////////////////////////