Allow custom GrAtlasGlyphCache texture sizes

A single glyph cache size doesn't make sense across the hardware Skia
runs on. This change allows a custom size to be specified (via a byte
limit), allowing cache size to be customized at context creation time.

Bug: 717178
Change-Id: I4f7baddd1897b2eac4f6d6e4fff1f805e1cdd250
Reviewed-on: https://skia-review.googlesource.com/15135
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Commit-Queue: Jim Van Verth <jvanverth@google.com>
This commit is contained in:
Eric Karl 2017-05-03 17:08:42 -07:00 committed by Skia Commit-Bot
parent 8d1e0ac998
commit 6d342285a4
4 changed files with 46 additions and 24 deletions

View File

@ -105,6 +105,11 @@ struct GrContextOptions {
};
GpuPathRenderers fGpuPathRenderers = GpuPathRenderers::kAll;
/**
* The maximum size of cache textures used for Skia's Glyph cache.
*/
float fGlyphCacheTextureMaximumBytes = 2048 * 1024 * 4;
};
GR_MAKE_BITFIELD_CLASS_OPS(GrContextOptions::GpuPathRenderers)

View File

@ -109,7 +109,7 @@ void GrContext::initCommon(const GrContextOptions& options) {
fDrawingManager.reset(new GrDrawingManager(this, prcOptions,
options.fImmediateMode, &fSingleOwner));
fAtlasGlyphCache = new GrAtlasGlyphCache(this);
fAtlasGlyphCache = new GrAtlasGlyphCache(this, options.fGlyphCacheTextureMaximumBytes);
fTextBlobCache.reset(new GrTextBlobCache(TextBlobCacheOverBudgetCB, this));
}

View File

@ -36,31 +36,48 @@ bool GrAtlasGlyphCache::initAtlas(GrMaskFormat format) {
return true;
}
GrAtlasGlyphCache::GrAtlasGlyphCache(GrContext* context)
: fContext(context)
, fPreserveStrike(nullptr) {
GrAtlasGlyphCache::GrAtlasGlyphCache(GrContext* context, float maxTextureBytes)
: fContext(context), fPreserveStrike(nullptr) {
// Calculate RGBA size. Must be between 1024 x 512 and MaxTextureSize x MaxTextureSize / 2
int log2MaxTextureSize = log2(context->caps()->maxTextureSize());
int log2MaxDim = 10;
for (; log2MaxDim <= log2MaxTextureSize; ++log2MaxDim) {
int maxDim = 1 << log2MaxDim;
int minDim = 1 << (log2MaxDim - 1);
// setup default atlas configs
fAtlasConfigs[kA8_GrMaskFormat].fWidth = 2048;
fAtlasConfigs[kA8_GrMaskFormat].fHeight = 2048;
fAtlasConfigs[kA8_GrMaskFormat].fLog2Width = 11;
fAtlasConfigs[kA8_GrMaskFormat].fLog2Height = 11;
fAtlasConfigs[kA8_GrMaskFormat].fPlotWidth = 512;
fAtlasConfigs[kA8_GrMaskFormat].fPlotHeight = 256;
if (maxDim * minDim * 4 >= maxTextureBytes) break;
}
fAtlasConfigs[kA565_GrMaskFormat].fWidth = 1024;
fAtlasConfigs[kA565_GrMaskFormat].fHeight = 2048;
fAtlasConfigs[kA565_GrMaskFormat].fLog2Width = 10;
fAtlasConfigs[kA565_GrMaskFormat].fLog2Height = 11;
fAtlasConfigs[kA565_GrMaskFormat].fPlotWidth = 256;
fAtlasConfigs[kA565_GrMaskFormat].fPlotHeight = 256;
int log2MinDim = log2MaxDim - 1;
int maxDim = 1 << log2MaxDim;
int minDim = 1 << log2MinDim;
// Plots are either 256 or 512.
int maxPlot = SkTMin(512, SkTMax(256, 1 << (log2MaxDim - 2)));
int minPlot = SkTMin(512, SkTMax(256, 1 << (log2MaxDim - 3)));
fAtlasConfigs[kARGB_GrMaskFormat].fWidth = 1024;
fAtlasConfigs[kARGB_GrMaskFormat].fHeight = 2048;
fAtlasConfigs[kARGB_GrMaskFormat].fLog2Width = 10;
fAtlasConfigs[kARGB_GrMaskFormat].fLog2Height = 11;
fAtlasConfigs[kARGB_GrMaskFormat].fPlotWidth = 256;
fAtlasConfigs[kARGB_GrMaskFormat].fPlotHeight = 256;
// Setup default atlas configs. The A8 atlas uses maxDim for both width and height, as the A8
// format is already very compact.
fAtlasConfigs[kA8_GrMaskFormat].fWidth = maxDim;
fAtlasConfigs[kA8_GrMaskFormat].fHeight = maxDim;
fAtlasConfigs[kA8_GrMaskFormat].fLog2Width = log2MaxDim;
fAtlasConfigs[kA8_GrMaskFormat].fLog2Height = log2MaxDim;
fAtlasConfigs[kA8_GrMaskFormat].fPlotWidth = maxPlot;
fAtlasConfigs[kA8_GrMaskFormat].fPlotHeight = minPlot;
// A565 and ARGB use maxDim x minDim.
fAtlasConfigs[kA565_GrMaskFormat].fWidth = minDim;
fAtlasConfigs[kA565_GrMaskFormat].fHeight = maxDim;
fAtlasConfigs[kA565_GrMaskFormat].fLog2Width = log2MinDim;
fAtlasConfigs[kA565_GrMaskFormat].fLog2Height = log2MaxDim;
fAtlasConfigs[kA565_GrMaskFormat].fPlotWidth = minPlot;
fAtlasConfigs[kA565_GrMaskFormat].fPlotHeight = minPlot;
fAtlasConfigs[kARGB_GrMaskFormat].fWidth = minDim;
fAtlasConfigs[kARGB_GrMaskFormat].fHeight = maxDim;
fAtlasConfigs[kARGB_GrMaskFormat].fLog2Width = log2MinDim;
fAtlasConfigs[kARGB_GrMaskFormat].fLog2Height = log2MaxDim;
fAtlasConfigs[kARGB_GrMaskFormat].fPlotWidth = minPlot;
fAtlasConfigs[kARGB_GrMaskFormat].fPlotHeight = minPlot;
}
GrAtlasGlyphCache::~GrAtlasGlyphCache() {

View File

@ -110,7 +110,7 @@ private:
*/
class GrAtlasGlyphCache {
public:
GrAtlasGlyphCache(GrContext*);
GrAtlasGlyphCache(GrContext*, float maxTextureBytes);
~GrAtlasGlyphCache();
// The user of the cache may hold a long-lived ref to the returned strike. However, actions by
// another client of the cache may cause the strike to be purged while it is still reffed.