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>
This commit is contained in:
Robert Phillips 2018-03-07 11:59:37 -05:00 committed by Skia Commit-Bot
parent ba8726b8a3
commit af4adefd8c
5 changed files with 41 additions and 20 deletions

View File

@ -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)));

View File

@ -12,28 +12,42 @@
#include "GrGlyphCache.h"
#include "GrProxyProvider.h"
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(caps->maxTextureSize());
int log2MaxDim = 9;
for (; log2MaxDim <= log2MaxTextureSize; ++log2MaxDim) {
int maxDimTmp = 1 << log2MaxDim;
int minDimTmp = 1 << (log2MaxDim - 1);
if (maxDimTmp * minDimTmp * 4 >= maxTextureBytes) {
break;
}
}
int log2MinDim = log2MaxDim - 1;
*maxDim = 1 << log2MaxDim;
*minDim = 1 << log2MinDim;
// Plots are either 256 or 512.
*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) {
// Calculate RGBA size. Must be between 512 x 256 and MaxTextureSize x MaxTextureSize / 2
int log2MaxTextureSize = SkPrevLog2(fCaps->maxTextureSize());
int log2MaxDim = 9;
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)));
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.

View File

@ -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) {

View File

@ -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() {

View File

@ -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; }