Merge "Update the CPU text cache sizes to be the same as their GPU equivalents" into qt-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
21a4210022
@@ -43,7 +43,21 @@ namespace renderthread {
|
|||||||
#define SURFACE_SIZE_MULTIPLIER (12.0f * 4.0f)
|
#define SURFACE_SIZE_MULTIPLIER (12.0f * 4.0f)
|
||||||
#define BACKGROUND_RETENTION_PERCENTAGE (0.5f)
|
#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(
|
mVectorDrawableAtlas = new skiapipeline::VectorDrawableAtlas(
|
||||||
mMaxSurfaceArea / 2,
|
mMaxSurfaceArea / 2,
|
||||||
skiapipeline::VectorDrawableAtlas::StorageMode::disallowSharedSurface);
|
skiapipeline::VectorDrawableAtlas::StorageMode::disallowSharedSurface);
|
||||||
@@ -57,7 +71,7 @@ void CacheManager::reset(sk_sp<GrContext> context) {
|
|||||||
if (context) {
|
if (context) {
|
||||||
mGrContext = std::move(context);
|
mGrContext = std::move(context);
|
||||||
mGrContext->getResourceCacheLimits(&mMaxResources, nullptr);
|
mGrContext->getResourceCacheLimits(&mMaxResources, nullptr);
|
||||||
updateContextCacheSizes();
|
mGrContext->setResourceCacheLimits(mMaxResources, mMaxResourceBytes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,13 +83,6 @@ void CacheManager::destroy() {
|
|||||||
skiapipeline::VectorDrawableAtlas::StorageMode::disallowSharedSurface);
|
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 {
|
class CommonPoolExecutor : public SkExecutor {
|
||||||
public:
|
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)); }
|
||||||
@@ -86,12 +93,7 @@ static CommonPoolExecutor sDefaultExecutor;
|
|||||||
void CacheManager::configureContext(GrContextOptions* contextOptions, const void* identity,
|
void CacheManager::configureContext(GrContextOptions* contextOptions, const void* identity,
|
||||||
ssize_t size) {
|
ssize_t size) {
|
||||||
contextOptions->fAllowPathMaskCaching = true;
|
contextOptions->fAllowPathMaskCaching = true;
|
||||||
|
contextOptions->fGlyphCacheTextureMaximumBytes = mMaxGpuFontAtlasBytes;
|
||||||
// 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->fExecutor = &sDefaultExecutor;
|
contextOptions->fExecutor = &sDefaultExecutor;
|
||||||
|
|
||||||
auto& cache = skiapipeline::ShaderCache::get();
|
auto& cache = skiapipeline::ShaderCache::get();
|
||||||
@@ -111,6 +113,7 @@ void CacheManager::trimMemory(TrimMemoryMode mode) {
|
|||||||
case TrimMemoryMode::Complete:
|
case TrimMemoryMode::Complete:
|
||||||
mVectorDrawableAtlas = new skiapipeline::VectorDrawableAtlas(mMaxSurfaceArea / 2);
|
mVectorDrawableAtlas = new skiapipeline::VectorDrawableAtlas(mMaxSurfaceArea / 2);
|
||||||
mGrContext->freeGpuResources();
|
mGrContext->freeGpuResources();
|
||||||
|
SkGraphics::PurgeAllCaches();
|
||||||
break;
|
break;
|
||||||
case TrimMemoryMode::UiHidden:
|
case TrimMemoryMode::UiHidden:
|
||||||
// Here we purge all the unlocked scratch resources and then toggle the resources cache
|
// Here we purge all the unlocked scratch resources and then toggle the resources cache
|
||||||
@@ -119,6 +122,8 @@ void CacheManager::trimMemory(TrimMemoryMode mode) {
|
|||||||
mGrContext->purgeUnlockedResources(true);
|
mGrContext->purgeUnlockedResources(true);
|
||||||
mGrContext->setResourceCacheLimits(mMaxResources, mBackgroundResourceBytes);
|
mGrContext->setResourceCacheLimits(mMaxResources, mBackgroundResourceBytes);
|
||||||
mGrContext->setResourceCacheLimits(mMaxResources, mMaxResourceBytes);
|
mGrContext->setResourceCacheLimits(mMaxResources, mMaxResourceBytes);
|
||||||
|
SkGraphics::SetFontCacheLimit(mBackgroundCpuFontCacheBytes);
|
||||||
|
SkGraphics::SetFontCacheLimit(mMaxCpuFontCacheBytes);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,14 +59,17 @@ private:
|
|||||||
|
|
||||||
void reset(sk_sp<GrContext> grContext);
|
void reset(sk_sp<GrContext> grContext);
|
||||||
void destroy();
|
void destroy();
|
||||||
void updateContextCacheSizes();
|
|
||||||
|
|
||||||
const size_t mMaxSurfaceArea;
|
const size_t mMaxSurfaceArea;
|
||||||
sk_sp<GrContext> mGrContext;
|
sk_sp<GrContext> mGrContext;
|
||||||
|
|
||||||
int mMaxResources = 0;
|
int mMaxResources = 0;
|
||||||
size_t mMaxResourceBytes = 0;
|
const size_t mMaxResourceBytes;
|
||||||
size_t mBackgroundResourceBytes = 0;
|
const size_t mBackgroundResourceBytes;
|
||||||
|
|
||||||
|
const size_t mMaxGpuFontAtlasBytes;
|
||||||
|
const size_t mMaxCpuFontCacheBytes;
|
||||||
|
const size_t mBackgroundCpuFontCacheBytes;
|
||||||
|
|
||||||
struct PipelineProps {
|
struct PipelineProps {
|
||||||
const void* pipelineKey = nullptr;
|
const void* pipelineKey = nullptr;
|
||||||
|
|||||||
Reference in New Issue
Block a user