aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Eric Karl <ericrk@chromium.org>2017-05-03 17:08:42 -0700
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-05-05 21:07:51 +0000
commit6d342285a4546b54cb17570aae7eeb8a123c81ae (patch)
tree6b43170dabb28a38f699edc67eedf21738c4bcb8 /src
parent8d1e0ac9989c4caa537930e352bfc2dfe375c69b (diff)
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>
Diffstat (limited to 'src')
-rw-r--r--src/gpu/GrContext.cpp2
-rw-r--r--src/gpu/text/GrAtlasGlyphCache.cpp67
-rw-r--r--src/gpu/text/GrAtlasGlyphCache.h2
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.