diff options
Diffstat (limited to 'libs/hwui/renderthread/CacheManager.cpp')
-rw-r--r-- | libs/hwui/renderthread/CacheManager.cpp | 42 |
1 files changed, 12 insertions, 30 deletions
diff --git a/libs/hwui/renderthread/CacheManager.cpp b/libs/hwui/renderthread/CacheManager.cpp index f510a2055309..6da80628be60 100644 --- a/libs/hwui/renderthread/CacheManager.cpp +++ b/libs/hwui/renderthread/CacheManager.cpp @@ -21,6 +21,7 @@ #include "RenderThread.h" #include "pipeline/skia/ShaderCache.h" #include "pipeline/skia/SkiaMemoryTracer.h" +#include "Properties.h" #include "renderstate/RenderState.h" #include <GrContextOptions.h> @@ -29,6 +30,7 @@ #include <gui/Surface.h> #include <math.h> #include <set> +#include <SkMathPriv.h> namespace android { namespace uirenderer { @@ -41,18 +43,10 @@ namespace renderthread { #define SURFACE_SIZE_MULTIPLIER (12.0f * 4.0f) #define BACKGROUND_RETENTION_PERCENTAGE (0.5f) -// for super large fonts we will draw them as paths so no need to keep linearly -// increasing the font cache size. -#define FONT_CACHE_MIN_MB (0.5f) -#define FONT_CACHE_MAX_MB (4.0f) - CacheManager::CacheManager(const DisplayInfo& display) : mMaxSurfaceArea(display.w * display.h) { mVectorDrawableAtlas = new skiapipeline::VectorDrawableAtlas( mMaxSurfaceArea / 2, skiapipeline::VectorDrawableAtlas::StorageMode::disallowSharedSurface); - if (Properties::isSkiaEnabled()) { - skiapipeline::ShaderCache::get().initShaderDiskCache(); - } } void CacheManager::reset(sk_sp<GrContext> context) { @@ -105,28 +99,13 @@ public: } }; -void CacheManager::configureContext(GrContextOptions* contextOptions) { +void CacheManager::configureContext(GrContextOptions* contextOptions, const void* identity, ssize_t size) { contextOptions->fAllowPathMaskCaching = true; - float screenMP = mMaxSurfaceArea / 1024.0f / 1024.0f; - float fontCacheMB = 0; - float decimalVal = std::modf(screenMP, &fontCacheMB); - - // This is a basic heuristic to size the cache to a multiple of 512 KB - if (decimalVal > 0.8f) { - fontCacheMB += 1.0f; - } else if (decimalVal > 0.5f) { - fontCacheMB += 0.5f; - } - - // set limits on min/max size of the cache - fontCacheMB = std::max(FONT_CACHE_MIN_MB, std::min(FONT_CACHE_MAX_MB, fontCacheMB)); - - // We must currently set the size of the text cache based on the size of the - // display even though we like to be dynamicallysizing it to the size of the window. - // Skia's implementation doesn't provide a mechanism to resize the font cache due to - // the potential cost of recreating the glyphs. - contextOptions->fGlyphCacheTextureMaximumBytes = fontCacheMB * 1024 * 1024; + // This sets the maximum size for a single texture atlas in the GPU font cache. If necessary, + // the cache can allocate additional textures that are counted against the total cache limits + // provided to Skia. + contextOptions->fGlyphCacheTextureMaximumBytes = GrNextSizePow2(mMaxSurfaceArea); if (mTaskManager.canRunTasks()) { if (!mTaskProcessor.get()) { @@ -135,7 +114,9 @@ void CacheManager::configureContext(GrContextOptions* contextOptions) { contextOptions->fExecutor = mTaskProcessor.get(); } - contextOptions->fPersistentCache = &skiapipeline::ShaderCache::get(); + auto& cache = skiapipeline::ShaderCache::get(); + cache.initShaderDiskCache(identity, size); + contextOptions->fPersistentCache = &cache; } void CacheManager::trimMemory(TrimMemoryMode mode) { @@ -215,11 +196,12 @@ void CacheManager::dumpMemoryUsage(String8& log, const RenderState* renderState) log.appendFormat(" Layer Info:\n"); } + const char* layerType = Properties::getRenderPipelineType() == RenderPipelineType::SkiaGL + ? "GlLayer" : "VkLayer"; size_t layerMemoryTotal = 0; for (std::set<Layer*>::iterator it = renderState->mActiveLayers.begin(); it != renderState->mActiveLayers.end(); it++) { const Layer* layer = *it; - const char* layerType = layer->getApi() == Layer::Api::OpenGL ? "GlLayer" : "VkLayer"; log.appendFormat(" %s size %dx%d\n", layerType, layer->getWidth(), layer->getHeight()); layerMemoryTotal += layer->getWidth() * layer->getHeight() * 4; |