Fission GrAtlasGlyphCache in two
This CL splits the old GrAtlasGlyphCache into a GrAtlasGlyphCache and an GrAtlasManager.
The GrAtlasManager itself is split into a rather limited base class (GrRestrictedAtlasManager)
and the all powerful GrAtlasManager. The GrRestrictedAtlasManager is available at op creation
time and provides access to the proxies backing the atlases. The full GrAtlasManager is
only available at flush time and allows instantiation of the proxies and uploading to them.
In the DDL world all of the DDL Contexts will receive a GrRestrictedAtlasManager-version of the
GrAtlasManager in the main thread. This future atlas manager will have had all of its
GrDrawOpAtlases created (but not instantiated) so there should be no race conditions.
Change-Id: I9967d3a4116af50128f390c5039a712b8cd4db08
Reviewed-on: https://skia-review.googlesource.com/108001
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Jim Van Verth <jvanverth@google.com>
diff --git a/src/gpu/ops/GrAtlasTextOp.cpp b/src/gpu/ops/GrAtlasTextOp.cpp
index 952b3ba..8f0c555 100644
--- a/src/gpu/ops/GrAtlasTextOp.cpp
+++ b/src/gpu/ops/GrAtlasTextOp.cpp
@@ -16,7 +16,8 @@
#include "SkPoint3.h"
#include "effects/GrBitmapTextGeoProc.h"
#include "effects/GrDistanceFieldGeoProc.h"
-#include "text/GrAtlasGlyphCache.h"
+#include "text/GrAtlasManager.h"
+#include "text/GrGlyphCache.h"
///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -53,9 +54,12 @@
void GrAtlasTextOp::visitProxies(const VisitProxyFunc& func) const {
fProcessors.visitProxies(func);
+ // We need to visit the atlasManager's proxies because, although the atlasManager explicitly
+ // manages their lifetimes, if they fail to allocate the draws that reference them need to
+ // be dropped.
unsigned int numProxies;
- const sk_sp<GrTextureProxy>* proxies = fFontCache->getProxies(this->maskFormat(),
- &numProxies);
+ const sk_sp<GrTextureProxy>* proxies = fRestrictedAtlasManager->getProxies(
+ this->maskFormat(), &numProxies);
for (unsigned int i = 0; i < numProxies; ++i) {
if (proxies[i]) {
func(proxies[i].get());
@@ -232,10 +236,15 @@
return;
}
+ GrAtlasManager* fullAtlasManager = target->fullAtlasManager();
+ SkASSERT(fRestrictedAtlasManager == fullAtlasManager);
+ GrGlyphCache* glyphCache = target->glyphCache();
+
GrMaskFormat maskFormat = this->maskFormat();
unsigned int atlasPageCount;
- const sk_sp<GrTextureProxy>* proxies = fFontCache->getProxies(maskFormat, &atlasPageCount);
+ const sk_sp<GrTextureProxy>* proxies = fullAtlasManager->getProxies(maskFormat,
+ &atlasPageCount);
if (!proxies[0]) {
SkDebugf("Could not allocate backing texture for atlas\n");
return;
@@ -246,7 +255,7 @@
target->makePipeline(fSRGBFlags, std::move(fProcessors), target->detachAppliedClip());
SkDEBUGCODE(bool dfPerspective = false);
if (this->usesDistanceFields()) {
- flushInfo.fGeometryProcessor = this->setupDfProcessor();
+ flushInfo.fGeometryProcessor = this->setupDfProcessor(fullAtlasManager);
SkDEBUGCODE(dfPerspective = fGeoData[0].fViewMatrix.hasPerspective());
} else {
flushInfo.fGeometryProcessor = GrBitmapTextGeoProc::Make(
@@ -272,14 +281,15 @@
char* currVertex = reinterpret_cast<char*>(vertices);
- SkAutoGlyphCache glyphCache;
+ SkAutoGlyphCache autoGlyphCache;
// each of these is a SubRun
for (int i = 0; i < fGeoCount; i++) {
const Geometry& args = fGeoData[i];
Blob* blob = args.fBlob;
GrAtlasTextBlob::VertexRegenerator regenerator(
resourceProvider, blob, args.fRun, args.fSubRun, args.fViewMatrix, args.fX, args.fY,
- args.fColor, target->deferredUploadTarget(), fFontCache, &glyphCache);
+ args.fColor, target->deferredUploadTarget(), glyphCache, fullAtlasManager,
+ &autoGlyphCache);
GrAtlasTextBlob::VertexRegenerator::Result result;
do {
result = regenerator.regenerate();
@@ -319,11 +329,14 @@
}
void GrAtlasTextOp::flush(GrMeshDrawOp::Target* target, FlushInfo* flushInfo) const {
+ auto fullAtlasManager = target->fullAtlasManager();
+ SkASSERT(fRestrictedAtlasManager == fullAtlasManager);
+
GrGeometryProcessor* gp = flushInfo->fGeometryProcessor.get();
GrMaskFormat maskFormat = this->maskFormat();
unsigned int numProxies;
- const sk_sp<GrTextureProxy>* proxies = fFontCache->getProxies(maskFormat, &numProxies);
+ const sk_sp<GrTextureProxy>* proxies = fullAtlasManager->getProxies(maskFormat, &numProxies);
if (gp->numTextureSamplers() != (int) numProxies) {
// During preparation the number of atlas pages has increased.
// Update the proxies used in the GP to match.
@@ -427,9 +440,11 @@
// TODO trying to figure out why lcd is so whack
// (see comments in GrAtlasTextContext::ComputeCanonicalColor)
-sk_sp<GrGeometryProcessor> GrAtlasTextOp::setupDfProcessor() const {
+sk_sp<GrGeometryProcessor> GrAtlasTextOp::setupDfProcessor(
+ GrRestrictedAtlasManager* restrictedAtlasManager) const {
unsigned int numProxies;
- const sk_sp<GrTextureProxy>* p = fFontCache->getProxies(this->maskFormat(), &numProxies);
+ const sk_sp<GrTextureProxy>* p = restrictedAtlasManager->getProxies(this->maskFormat(),
+ &numProxies);
bool isLCD = this->isLCD();
SkMatrix localMatrix = SkMatrix::I();
diff --git a/src/gpu/ops/GrAtlasTextOp.h b/src/gpu/ops/GrAtlasTextOp.h
index dbdce38..ae1c95b 100644
--- a/src/gpu/ops/GrAtlasTextOp.h
+++ b/src/gpu/ops/GrAtlasTextOp.h
@@ -11,6 +11,7 @@
#include "ops/GrMeshDrawOp.h"
#include "text/GrAtlasTextContext.h"
#include "text/GrDistanceFieldAdjustTable.h"
+#include "text/GrGlyphCache.h"
class SkAtlasTextTarget;
@@ -39,11 +40,12 @@
GrColor fColor;
};
- static std::unique_ptr<GrAtlasTextOp> MakeBitmap(GrPaint&& paint, GrMaskFormat maskFormat,
- int glyphCount, GrAtlasGlyphCache* fontCache) {
- std::unique_ptr<GrAtlasTextOp> op(new GrAtlasTextOp(std::move(paint)));
+ static std::unique_ptr<GrAtlasTextOp> MakeBitmap(
+ GrPaint&& paint, GrMaskFormat maskFormat,
+ int glyphCount, GrRestrictedAtlasManager* restrictedAtlasManager) {
+ std::unique_ptr<GrAtlasTextOp> op(new GrAtlasTextOp(restrictedAtlasManager,
+ std::move(paint)));
- op->fFontCache = fontCache;
switch (maskFormat) {
case kA8_GrMaskFormat:
op->fMaskType = kGrayscaleCoverageMask_MaskType;
@@ -58,18 +60,17 @@
op->fNumGlyphs = glyphCount;
op->fGeoCount = 1;
op->fLuminanceColor = 0;
- op->fFontCache = fontCache;
return op;
}
static std::unique_ptr<GrAtlasTextOp> MakeDistanceField(
- GrPaint&& paint, int glyphCount, GrAtlasGlyphCache* fontCache,
+ GrPaint&& paint, int glyphCount, GrRestrictedAtlasManager* restrictedAtlasManager,
const GrDistanceFieldAdjustTable* distanceAdjustTable,
bool useGammaCorrectDistanceTable, SkColor luminanceColor, bool isLCD, bool useBGR,
bool isAntiAliased) {
- std::unique_ptr<GrAtlasTextOp> op(new GrAtlasTextOp(std::move(paint)));
+ std::unique_ptr<GrAtlasTextOp> op(new GrAtlasTextOp(restrictedAtlasManager,
+ std::move(paint)));
- op->fFontCache = fontCache;
op->fMaskType = !isAntiAliased ? kAliasedDistanceField_MaskType
: isLCD ? (useBGR ? kLCDBGRDistanceField_MaskType
: kLCDDistanceField_MaskType)
@@ -120,8 +121,9 @@
// The minimum number of Geometry we will try to allocate.
static constexpr auto kMinGeometryAllocated = 12;
- GrAtlasTextOp(GrPaint&& paint)
+ GrAtlasTextOp(GrRestrictedAtlasManager* restrictedAtlasManager, GrPaint&& paint)
: INHERITED(ClassID())
+ , fRestrictedAtlasManager(restrictedAtlasManager)
, fGeoDataAllocSize(kMinGeometryAllocated)
, fSRGBFlags(GrPipeline::SRGBFlagsFromPaint(paint))
, fProcessors(std::move(paint)) {}
@@ -174,8 +176,9 @@
bool onCombineIfPossible(GrOp* t, const GrCaps& caps) override;
- sk_sp<GrGeometryProcessor> setupDfProcessor() const;
+ sk_sp<GrGeometryProcessor> setupDfProcessor(GrRestrictedAtlasManager*) const;
+ GrRestrictedAtlasManager* fRestrictedAtlasManager;
SkAutoSTMalloc<kMinGeometryAllocated, Geometry> fGeoData;
int fGeoDataAllocSize;
uint32_t fSRGBFlags;
@@ -185,7 +188,6 @@
int fGeoCount;
int fNumGlyphs;
MaskType fMaskType;
- GrAtlasGlyphCache* fFontCache;
// Distance field properties
sk_sp<const GrDistanceFieldAdjustTable> fDistanceAdjustTable;
SkColor fLuminanceColor;
diff --git a/src/gpu/ops/GrMeshDrawOp.h b/src/gpu/ops/GrMeshDrawOp.h
index 1b8831c..766fd23 100644
--- a/src/gpu/ops/GrMeshDrawOp.h
+++ b/src/gpu/ops/GrMeshDrawOp.h
@@ -15,7 +15,9 @@
#include "SkTLList.h"
+class GrAtlasManager;
class GrCaps;
+class GrGlyphCache;
class GrOpFlushState;
/**
@@ -152,6 +154,9 @@
virtual GrResourceProvider* resourceProvider() const = 0;
+ virtual GrGlyphCache* glyphCache() const = 0;
+ virtual GrAtlasManager* fullAtlasManager() const = 0;
+
virtual const GrCaps& caps() const = 0;
virtual GrDeferredUploadTarget* deferredUploadTarget() = 0;