diff options
author | 2018-03-07 11:59:37 -0500 | |
---|---|---|
committer | 2018-03-07 19:53:30 +0000 | |
commit | af4adefd8ccb46c148f7a16b54afc226b86c0fcc (patch) | |
tree | da5ce6ae00e7fed1fa2544be658cffe89f5f5d9e /src | |
parent | ba8726b8a33603b1352019123edb82ed199b26d2 (diff) |
Have GrGlyphCache and GrAtlasManager compute the atlas limits independently
DDL contexts will have a GrGlyphCache but not a GrAtlasManager. This CL
disentangles the computation of the atlas limits so the GrGlyphCache
can function independently.
Change-Id: Ia698c7d1ec625d1a0d1f0b5521b56731cfeafde9
Reviewed-on: https://skia-review.googlesource.com/112708
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/gpu/GrContext.cpp | 4 | ||||
-rw-r--r-- | src/gpu/text/GrAtlasManager.cpp | 42 | ||||
-rw-r--r-- | src/gpu/text/GrAtlasManager.h | 3 | ||||
-rw-r--r-- | src/gpu/text/GrGlyphCache.cpp | 7 | ||||
-rw-r--r-- | src/gpu/text/GrGlyphCache.h | 3 |
5 files changed, 40 insertions, 19 deletions
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index d29a173e4a..16dfab35cd 100644 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -125,7 +125,7 @@ protected: allowMultitexturing); this->contextPriv().addOnFlushCallbackObject(fFullAtlasManager); - glyphCache->setGlyphSizeLimit(fFullAtlasManager->getGlyphSizeLimit()); + SkASSERT(glyphCache->getGlyphSizeLimit() == fFullAtlasManager->getGlyphSizeLimit()); return true; } @@ -396,7 +396,7 @@ bool GrContext::initCommon(const GrContextOptions& options) { fDrawingManager.reset(new GrDrawingManager(this, prcOptions, atlasTextContextOptions, &fSingleOwner, options.fSortRenderTargets)); - fGlyphCache = new GrGlyphCache; + fGlyphCache = new GrGlyphCache(fCaps.get(), options.fGlyphCacheTextureMaximumBytes); fTextBlobCache.reset(new GrTextBlobCache(TextBlobCacheOverBudgetCB, this, this->uniqueID(), SkToBool(fGpu))); diff --git a/src/gpu/text/GrAtlasManager.cpp b/src/gpu/text/GrAtlasManager.cpp index b688c1cce5..208e7077d0 100644 --- a/src/gpu/text/GrAtlasManager.cpp +++ b/src/gpu/text/GrAtlasManager.cpp @@ -12,28 +12,42 @@ #include "GrGlyphCache.h" #include "GrProxyProvider.h" -GrRestrictedAtlasManager::GrRestrictedAtlasManager( - sk_sp<const GrCaps> caps, - float maxTextureBytes, - GrDrawOpAtlas::AllowMultitexturing allowMultitexturing) - : fCaps(std::move(caps)) - , fAllowMultitexturing(allowMultitexturing) { + +void GrRestrictedAtlasManager::ComputeAtlasLimits(const GrCaps* caps, float maxTextureBytes, + int* maxDim, int* minDim, + int* maxPlot, int* minPlot) { + SkASSERT(maxDim && minDim && maxPlot && minPlot); + // Calculate RGBA size. Must be between 512 x 256 and MaxTextureSize x MaxTextureSize / 2 - int log2MaxTextureSize = SkPrevLog2(fCaps->maxTextureSize()); + int log2MaxTextureSize = SkPrevLog2(caps->maxTextureSize()); int log2MaxDim = 9; for (; log2MaxDim <= log2MaxTextureSize; ++log2MaxDim) { - int maxDim = 1 << log2MaxDim; - int minDim = 1 << (log2MaxDim - 1); + int maxDimTmp = 1 << log2MaxDim; + int minDimTmp = 1 << (log2MaxDim - 1); - if (maxDim * minDim * 4 >= maxTextureBytes) break; + if (maxDimTmp * minDimTmp * 4 >= maxTextureBytes) { + break; + } } + int log2MinDim = log2MaxDim - 1; - int maxDim = 1 << log2MaxDim; - int minDim = 1 << log2MinDim; + *maxDim = 1 << log2MaxDim; + *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))); + *maxPlot = SkTMin(512, SkTMax(256, 1 << (log2MaxDim - 2))); + *minPlot = SkTMin(512, SkTMax(256, 1 << (log2MaxDim - 3))); +} + +GrRestrictedAtlasManager::GrRestrictedAtlasManager( + sk_sp<const GrCaps> caps, + float maxTextureBytes, + GrDrawOpAtlas::AllowMultitexturing allowMultitexturing) + : fCaps(std::move(caps)) + , fAllowMultitexturing(allowMultitexturing) { + + int maxDim, minDim, maxPlot, minPlot; + ComputeAtlasLimits(fCaps.get(), maxTextureBytes, &maxDim, &minDim, &maxPlot, &minPlot); // Setup default atlas configs. The A8 atlas uses maxDim for both width and height, as the A8 // format is already very compact. diff --git a/src/gpu/text/GrAtlasManager.h b/src/gpu/text/GrAtlasManager.h index 924119397e..4b1c6674e0 100644 --- a/src/gpu/text/GrAtlasManager.h +++ b/src/gpu/text/GrAtlasManager.h @@ -43,6 +43,9 @@ public: SkScalar getGlyphSizeLimit() const { return fGlyphSizeLimit; } + static void ComputeAtlasLimits(const GrCaps* caps, float maxTextureBytes, + int* maxDim, int* minDim, int* maxPlot, int* minPlot); + protected: // There is a 1:1 mapping between GrMaskFormats and atlas indices static int MaskFormatToAtlasIndex(GrMaskFormat format) { diff --git a/src/gpu/text/GrGlyphCache.cpp b/src/gpu/text/GrGlyphCache.cpp index 49e24b8b8c..79f7748def 100644 --- a/src/gpu/text/GrGlyphCache.cpp +++ b/src/gpu/text/GrGlyphCache.cpp @@ -12,9 +12,14 @@ #include "SkAutoMalloc.h" #include "SkDistanceFieldGen.h" -GrGlyphCache::GrGlyphCache() +GrGlyphCache::GrGlyphCache(const GrCaps* caps, float maxTextureBytes) : fPreserveStrike(nullptr) , fGlyphSizeLimit(0) { + + int maxDim, minDim, maxPlot, minPlot; + GrRestrictedAtlasManager::ComputeAtlasLimits(caps, maxTextureBytes, + &maxDim, &minDim, &maxPlot, &minPlot); + fGlyphSizeLimit = minPlot; } GrGlyphCache::~GrGlyphCache() { diff --git a/src/gpu/text/GrGlyphCache.h b/src/gpu/text/GrGlyphCache.h index bbc199fac1..cff309501d 100644 --- a/src/gpu/text/GrGlyphCache.h +++ b/src/gpu/text/GrGlyphCache.h @@ -108,10 +108,9 @@ private: */ class GrGlyphCache { public: - GrGlyphCache(); + GrGlyphCache(const GrCaps* caps, float maxTextureBytes); ~GrGlyphCache(); - void setGlyphSizeLimit(SkScalar sizeLimit) { fGlyphSizeLimit = sizeLimit; } SkScalar getGlyphSizeLimit() const { return fGlyphSizeLimit; } void setStrikeToPreserve(GrTextStrike* strike) { fPreserveStrike = strike; } |