summaryrefslogtreecommitdiff
path: root/libs/hwui/renderthread/CacheManager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libs/hwui/renderthread/CacheManager.cpp')
-rw-r--r--libs/hwui/renderthread/CacheManager.cpp48
1 files changed, 26 insertions, 22 deletions
diff --git a/libs/hwui/renderthread/CacheManager.cpp b/libs/hwui/renderthread/CacheManager.cpp
index 8b02c11911ca..7cb241d22668 100644
--- a/libs/hwui/renderthread/CacheManager.cpp
+++ b/libs/hwui/renderthread/CacheManager.cpp
@@ -21,17 +21,16 @@
#include "RenderThread.h"
#include "pipeline/skia/ShaderCache.h"
#include "pipeline/skia/SkiaMemoryTracer.h"
-#include "Properties.h"
#include "renderstate/RenderState.h"
#include "thread/CommonPool.h"
#include <GrContextOptions.h>
#include <SkExecutor.h>
#include <SkGraphics.h>
+#include <SkMathPriv.h>
#include <gui/Surface.h>
#include <math.h>
#include <set>
-#include <SkMathPriv.h>
namespace android {
namespace uirenderer {
@@ -44,7 +43,21 @@ namespace renderthread {
#define SURFACE_SIZE_MULTIPLIER (12.0f * 4.0f)
#define BACKGROUND_RETENTION_PERCENTAGE (0.5f)
-CacheManager::CacheManager(const DisplayInfo& display) : mMaxSurfaceArea(display.w * display.h) {
+CacheManager::CacheManager(const DisplayInfo& display)
+ : mMaxSurfaceArea(display.w * display.h)
+ , mMaxResourceBytes(mMaxSurfaceArea * SURFACE_SIZE_MULTIPLIER)
+ , mBackgroundResourceBytes(mMaxResourceBytes * BACKGROUND_RETENTION_PERCENTAGE)
+ // 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.
+ , mMaxGpuFontAtlasBytes(GrNextSizePow2(mMaxSurfaceArea))
+ // This sets the maximum size of the CPU font cache to be at least the same size as the
+ // total number of GPU font caches (i.e. 4 separate GPU atlases).
+ , mMaxCpuFontCacheBytes(std::max(mMaxGpuFontAtlasBytes*4, SkGraphics::GetFontCacheLimit()))
+ , mBackgroundCpuFontCacheBytes(mMaxCpuFontCacheBytes * BACKGROUND_RETENTION_PERCENTAGE) {
+
+ SkGraphics::SetFontCacheLimit(mMaxCpuFontCacheBytes);
+
mVectorDrawableAtlas = new skiapipeline::VectorDrawableAtlas(
mMaxSurfaceArea / 2,
skiapipeline::VectorDrawableAtlas::StorageMode::disallowSharedSurface);
@@ -58,7 +71,7 @@ void CacheManager::reset(sk_sp<GrContext> context) {
if (context) {
mGrContext = std::move(context);
mGrContext->getResourceCacheLimits(&mMaxResources, nullptr);
- updateContextCacheSizes();
+ mGrContext->setResourceCacheLimits(mMaxResources, mMaxResourceBytes);
}
}
@@ -70,30 +83,17 @@ void CacheManager::destroy() {
skiapipeline::VectorDrawableAtlas::StorageMode::disallowSharedSurface);
}
-void CacheManager::updateContextCacheSizes() {
- mMaxResourceBytes = mMaxSurfaceArea * SURFACE_SIZE_MULTIPLIER;
- mBackgroundResourceBytes = mMaxResourceBytes * BACKGROUND_RETENTION_PERCENTAGE;
-
- mGrContext->setResourceCacheLimits(mMaxResources, mMaxResourceBytes);
-}
-
class CommonPoolExecutor : public SkExecutor {
public:
- virtual void add(std::function<void(void)> func) override {
- CommonPool::post(std::move(func));
- }
+ virtual void add(std::function<void(void)> func) override { CommonPool::post(std::move(func)); }
};
static CommonPoolExecutor sDefaultExecutor;
-void CacheManager::configureContext(GrContextOptions* contextOptions, const void* identity, ssize_t size) {
+void CacheManager::configureContext(GrContextOptions* contextOptions, const void* identity,
+ ssize_t size) {
contextOptions->fAllowPathMaskCaching = true;
-
- // 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);
-
+ contextOptions->fGlyphCacheTextureMaximumBytes = mMaxGpuFontAtlasBytes;
contextOptions->fExecutor = &sDefaultExecutor;
auto& cache = skiapipeline::ShaderCache::get();
@@ -113,6 +113,7 @@ void CacheManager::trimMemory(TrimMemoryMode mode) {
case TrimMemoryMode::Complete:
mVectorDrawableAtlas = new skiapipeline::VectorDrawableAtlas(mMaxSurfaceArea / 2);
mGrContext->freeGpuResources();
+ SkGraphics::PurgeAllCaches();
break;
case TrimMemoryMode::UiHidden:
// Here we purge all the unlocked scratch resources and then toggle the resources cache
@@ -121,6 +122,8 @@ void CacheManager::trimMemory(TrimMemoryMode mode) {
mGrContext->purgeUnlockedResources(true);
mGrContext->setResourceCacheLimits(mMaxResources, mBackgroundResourceBytes);
mGrContext->setResourceCacheLimits(mMaxResources, mMaxResourceBytes);
+ SkGraphics::SetFontCacheLimit(mBackgroundCpuFontCacheBytes);
+ SkGraphics::SetFontCacheLimit(mMaxCpuFontCacheBytes);
break;
}
}
@@ -180,7 +183,8 @@ void CacheManager::dumpMemoryUsage(String8& log, const RenderState* renderState)
}
const char* layerType = Properties::getRenderPipelineType() == RenderPipelineType::SkiaGL
- ? "GlLayer" : "VkLayer";
+ ? "GlLayer"
+ : "VkLayer";
size_t layerMemoryTotal = 0;
for (std::set<Layer*>::iterator it = renderState->mActiveLayers.begin();
it != renderState->mActiveLayers.end(); it++) {