Paramaterize and adjust the glyph cache sizes

Add new parameters for the texture size used for the larger, fallback caches.
Bump up the defaults in some situations.

Issue #7045164 Adjust cache sizes for manta

Change-Id: I562118ce785d7f8b6e445178878672e9709d25f2
diff --git a/libs/hwui/FontRenderer.cpp b/libs/hwui/FontRenderer.cpp
index 6b08e7f..95ccdfc 100644
--- a/libs/hwui/FontRenderer.cpp
+++ b/libs/hwui/FontRenderer.cpp
@@ -34,9 +34,10 @@
 // Defines
 ///////////////////////////////////////////////////////////////////////////////
 
-#define DEFAULT_TEXT_CACHE_WIDTH 1024
-#define DEFAULT_TEXT_CACHE_HEIGHT 256
-#define MAX_TEXT_CACHE_WIDTH 2048
+#define DEFAULT_TEXT_SMALL_CACHE_WIDTH 1024
+#define DEFAULT_TEXT_SMALL_CACHE_HEIGHT 256
+#define DEFAULT_TEXT_LARGE_CACHE_WIDTH 2048
+#define DEFAULT_TEXT_LARGE_CACHE_HEIGHT 512
 #define CACHE_BLOCK_ROUNDING_SIZE 4
 
 #define AUTO_KERN(prev, next) (((next) - (prev) + 32) >> 6 << 16)
@@ -626,30 +627,35 @@
 
     mIndexBufferID = 0;
 
-    mSmallCacheWidth = DEFAULT_TEXT_CACHE_WIDTH;
-    mSmallCacheHeight = DEFAULT_TEXT_CACHE_HEIGHT;
+    mSmallCacheWidth = DEFAULT_TEXT_SMALL_CACHE_WIDTH;
+    mSmallCacheHeight = DEFAULT_TEXT_SMALL_CACHE_HEIGHT;
+    mLargeCacheWidth = DEFAULT_TEXT_LARGE_CACHE_WIDTH;
+    mLargeCacheHeight = DEFAULT_TEXT_LARGE_CACHE_HEIGHT;
 
     char property[PROPERTY_VALUE_MAX];
-    if (property_get(PROPERTY_TEXT_CACHE_WIDTH, property, NULL) > 0) {
-        if (sLogFontRendererCreate) {
-            INIT_LOGD("  Setting text cache width to %s pixels", property);
-        }
+    if (property_get(PROPERTY_TEXT_SMALL_CACHE_WIDTH, property, NULL) > 0) {
         mSmallCacheWidth = atoi(property);
-    } else {
-        if (sLogFontRendererCreate) {
-            INIT_LOGD("  Using default text cache width of %i pixels", mSmallCacheWidth);
-        }
     }
-
-    if (property_get(PROPERTY_TEXT_CACHE_HEIGHT, property, NULL) > 0) {
-        if (sLogFontRendererCreate) {
-            INIT_LOGD("  Setting text cache width to %s pixels", property);
-        }
+    if (property_get(PROPERTY_TEXT_SMALL_CACHE_HEIGHT, property, NULL) > 0) {
         mSmallCacheHeight = atoi(property);
-    } else {
-        if (sLogFontRendererCreate) {
-            INIT_LOGD("  Using default text cache height of %i pixels", mSmallCacheHeight);
-        }
+    }
+    if (property_get(PROPERTY_TEXT_LARGE_CACHE_WIDTH, property, NULL) > 0) {
+        mLargeCacheWidth = atoi(property);
+    }
+    if (property_get(PROPERTY_TEXT_LARGE_CACHE_HEIGHT, property, NULL) > 0) {
+        mLargeCacheHeight = atoi(property);
+    }
+    GLint maxTextureSize = Caches::getInstance().maxTextureSize;
+    mSmallCacheWidth = (mSmallCacheWidth > maxTextureSize) ? maxTextureSize : mSmallCacheWidth;
+    mSmallCacheHeight = (mSmallCacheHeight > maxTextureSize) ? maxTextureSize : mSmallCacheHeight;
+    mLargeCacheWidth = (mLargeCacheWidth > maxTextureSize) ? maxTextureSize : mLargeCacheWidth;
+    mLargeCacheHeight = (mLargeCacheHeight > maxTextureSize) ? maxTextureSize : mLargeCacheHeight;
+    if (sLogFontRendererCreate) {
+        INIT_LOGD("  Text cache sizes, in pixels: %i x %i, %i x %i, %i x %i, %i x %i",
+                mSmallCacheWidth, mSmallCacheHeight,
+                mLargeCacheWidth, mLargeCacheHeight >> 1,
+                mLargeCacheWidth, mLargeCacheHeight >> 1,
+                mLargeCacheWidth, mLargeCacheHeight);
     }
 
     sLogFontRendererCreate = false;
@@ -861,21 +867,11 @@
     }
     mCacheTextures.clear();
 
-    // Next, use other, separate caches for large glyphs.
-    uint16_t maxWidth = 0;
-    if (Caches::hasInstance()) {
-        maxWidth = Caches::getInstance().maxTextureSize;
-    }
-
-    if (maxWidth > MAX_TEXT_CACHE_WIDTH || maxWidth == 0) {
-        maxWidth = MAX_TEXT_CACHE_WIDTH;
-    }
-
     mUploadTexture = false;
     mCacheTextures.push(createCacheTexture(mSmallCacheWidth, mSmallCacheHeight, true));
-    mCacheTextures.push(createCacheTexture(maxWidth, 256, false));
-    mCacheTextures.push(createCacheTexture(maxWidth, 256, false));
-    mCacheTextures.push(createCacheTexture(maxWidth, 512, false));
+    mCacheTextures.push(createCacheTexture(mLargeCacheWidth, mLargeCacheHeight >> 1, false));
+    mCacheTextures.push(createCacheTexture(mLargeCacheWidth, mLargeCacheHeight >> 1, false));
+    mCacheTextures.push(createCacheTexture(mLargeCacheWidth, mLargeCacheHeight, false));
     mCurrentCacheTexture = mCacheTextures[0];
 }
 
diff --git a/libs/hwui/FontRenderer.h b/libs/hwui/FontRenderer.h
index 8d0d21d..241b73e 100644
--- a/libs/hwui/FontRenderer.h
+++ b/libs/hwui/FontRenderer.h
@@ -391,6 +391,8 @@
 
     uint32_t mSmallCacheWidth;
     uint32_t mSmallCacheHeight;
+    uint32_t mLargeCacheWidth;
+    uint32_t mLargeCacheHeight;
 
     Vector<CacheTexture*> mCacheTextures;
 
diff --git a/libs/hwui/Properties.h b/libs/hwui/Properties.h
index 6b6dc9e..0e3268e 100644
--- a/libs/hwui/Properties.h
+++ b/libs/hwui/Properties.h
@@ -74,8 +74,10 @@
 #define PROPERTY_TEXTURE_CACHE_FLUSH_RATE "ro.hwui.texture_cache_flush_rate"
 
 // These properties are defined in pixels
-#define PROPERTY_TEXT_CACHE_WIDTH "ro.hwui.text_cache_width"
-#define PROPERTY_TEXT_CACHE_HEIGHT "ro.hwui.text_cache_height"
+#define PROPERTY_TEXT_SMALL_CACHE_WIDTH "ro.hwui.text_small_cache_width"
+#define PROPERTY_TEXT_SMALL_CACHE_HEIGHT "ro.hwui.text_small_cache_height"
+#define PROPERTY_TEXT_LARGE_CACHE_WIDTH "ro.hwui.text_large_cache_width"
+#define PROPERTY_TEXT_LARGE_CACHE_HEIGHT "ro.hwui.text_large_cache_height"
 
 // Indicates whether gamma correction should be applied in the shaders
 // or in lookup tables. Accepted values: