diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gpu/GrContext.cpp | 2 | ||||
-rw-r--r-- | src/gpu/text/GrAtlasGlyphCache.cpp | 67 | ||||
-rw-r--r-- | src/gpu/text/GrAtlasGlyphCache.h | 2 |
3 files changed, 44 insertions, 27 deletions
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index 2d46b5c02b..fc38dfa9b8 100644 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -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)); } diff --git a/src/gpu/text/GrAtlasGlyphCache.cpp b/src/gpu/text/GrAtlasGlyphCache.cpp index 0b364f43fe..39c3e10ca5 100644 --- a/src/gpu/text/GrAtlasGlyphCache.cpp +++ b/src/gpu/text/GrAtlasGlyphCache.cpp @@ -36,31 +36,48 @@ bool GrAtlasGlyphCache::initAtlas(GrMaskFormat format) { return true; } -GrAtlasGlyphCache::GrAtlasGlyphCache(GrContext* context) - : fContext(context) - , fPreserveStrike(nullptr) { - - // 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; - - 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; - - 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; +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); + + if (maxDim * minDim * 4 >= maxTextureBytes) break; + } + + 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))); + + // 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() { diff --git a/src/gpu/text/GrAtlasGlyphCache.h b/src/gpu/text/GrAtlasGlyphCache.h index a75600b615..3ebea2b72b 100644 --- a/src/gpu/text/GrAtlasGlyphCache.h +++ b/src/gpu/text/GrAtlasGlyphCache.h @@ -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. |