From 7cc3ee7091d9bcbc83879c0f84f9e5174716f285 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Mon, 14 Aug 2017 14:22:56 -0700 Subject: [PATCH] Adjust font texture cache based on device density. The main purpose of this CL is reducing font cache size of low-density device. The memory usage for the small RGBA texture will be Nexus 6P: 7,928,856 bytes (1408x1408) Nexus 5X: 4,734,976 bytes (1088x1088) These used to be 4,194,304 bytes Test: manually checked Bug: 64400885 Change-Id: Ied064a6d59909ad7fbeff74332973206436fbd34 --- libs/hwui/FontRenderer.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/libs/hwui/FontRenderer.cpp b/libs/hwui/FontRenderer.cpp index bc41810753194..8b0346867cbcf 100644 --- a/libs/hwui/FontRenderer.cpp +++ b/libs/hwui/FontRenderer.cpp @@ -99,13 +99,22 @@ FontRenderer::FontRenderer(const uint8_t* gammaTable) } auto deviceInfo = DeviceInfo::get(); + auto displayInfo = deviceInfo->displayInfo(); int maxTextureSize = deviceInfo->maxTextureSize(); + // Adjust cache size based on Pixel's desnsity. + constexpr float PIXEL_DENSITY = 2.6; + const float densityRatio = displayInfo.density / PIXEL_DENSITY; + // TODO: Most devices are hardcoded with this configuration, does it need to be dynamic? - mSmallCacheWidth = std::min(1024, maxTextureSize); - mSmallCacheHeight = std::min(1024, maxTextureSize); - mLargeCacheWidth = std::min(2048, maxTextureSize); - mLargeCacheHeight = std::min(1024, maxTextureSize); + mSmallCacheWidth = + OffscreenBuffer::computeIdealDimension(std::min(1024, maxTextureSize) * densityRatio); + mSmallCacheHeight = + OffscreenBuffer::computeIdealDimension(std::min(1024, maxTextureSize) * densityRatio); + mLargeCacheWidth = + OffscreenBuffer::computeIdealDimension(std::min(2048, maxTextureSize) * densityRatio); + mLargeCacheHeight = + OffscreenBuffer::computeIdealDimension(std::min(1024, maxTextureSize) * densityRatio); if (sLogFontRendererCreate) { INIT_LOGD(" Text cache sizes, in pixels: %i x %i, %i x %i, %i x %i, %i x %i",