From 5a66efbbab2926793a7f4dc57931253ab3046375 Mon Sep 17 00:00:00 2001 From: Robert Phillips Date: Wed, 7 Mar 2018 15:13:18 -0500 Subject: Remove GrRestrictedAtlasManager Philosophically this relies on: https://skia-review.googlesource.com/c/skia/+/111807 (Revise Text & Small Path Atlas so instantiation failure is handled at flush time) Change-Id: I4fdcf1af8c5e9ffefdfb973104045f4f5d223a4e Reviewed-on: https://skia-review.googlesource.com/112702 Reviewed-by: Jim Van Verth Commit-Queue: Robert Phillips --- src/atlastext/SkAtlasTextTarget.cpp | 9 ++- src/atlastext/SkInternalAtlasTextContext.cpp | 15 ++--- src/gpu/GrContext.cpp | 38 +++++------- src/gpu/GrContextPriv.h | 8 +-- src/gpu/GrOpFlushState.cpp | 4 +- src/gpu/GrOpFlushState.h | 2 +- src/gpu/ops/GrAtlasTextOp.cpp | 34 +++-------- src/gpu/ops/GrAtlasTextOp.h | 18 ++---- src/gpu/ops/GrMeshDrawOp.h | 2 +- src/gpu/text/GrAtlasManager.cpp | 31 ++++------ src/gpu/text/GrAtlasManager.h | 89 ++++++++++++---------------- src/gpu/text/GrAtlasTextBlob.cpp | 17 +++--- src/gpu/text/GrAtlasTextBlob.h | 7 +-- src/gpu/text/GrAtlasTextContext.cpp | 13 ++-- src/gpu/text/GrGlyphCache.cpp | 3 +- 15 files changed, 112 insertions(+), 178 deletions(-) (limited to 'src') diff --git a/src/atlastext/SkAtlasTextTarget.cpp b/src/atlastext/SkAtlasTextTarget.cpp index 4513952781..937498b826 100644 --- a/src/atlastext/SkAtlasTextTarget.cpp +++ b/src/atlastext/SkAtlasTextTarget.cpp @@ -184,14 +184,19 @@ void GrAtlasTextOp::executeForTextTarget(SkAtlasTextTarget* target) { SkAutoGlyphCache autoGlyphCache; auto& context = target->context()->internal(); auto glyphCache = context.grContext()->contextPriv().getGlyphCache(); - auto fullAtlasManager = context.grContext()->contextPriv().getFullAtlasManager(); + auto atlasManager = context.grContext()->contextPriv().getAtlasManager(); auto resourceProvider = context.grContext()->contextPriv().resourceProvider(); + unsigned int numProxies; + if (!atlasManager->getProxies(kA8_GrMaskFormat, &numProxies)) { + return; + } + for (int i = 0; i < fGeoCount; ++i) { GrAtlasTextBlob::VertexRegenerator regenerator( resourceProvider, fGeoData[i].fBlob, fGeoData[i].fRun, fGeoData[i].fSubRun, fGeoData[i].fViewMatrix, fGeoData[i].fX, fGeoData[i].fY, fGeoData[i].fColor, - &context, glyphCache, fullAtlasManager, &autoGlyphCache); + &context, glyphCache, atlasManager, &autoGlyphCache); bool done = false; while (!done) { GrAtlasTextBlob::VertexRegenerator::Result result; diff --git a/src/atlastext/SkInternalAtlasTextContext.cpp b/src/atlastext/SkInternalAtlasTextContext.cpp index 1e9cbf3079..0ff4f3e5d3 100644 --- a/src/atlastext/SkInternalAtlasTextContext.cpp +++ b/src/atlastext/SkInternalAtlasTextContext.cpp @@ -38,10 +38,12 @@ SkInternalAtlasTextContext::SkInternalAtlasTextContext(sk_spcontextPriv().getRestrictedAtlasManager(); - unsigned int numProxies; - restrictedAtlasManager->getProxies(kA8_GrMaskFormat, &numProxies); - SkASSERT(1 == numProxies); + auto atlasManager = fGrContext->contextPriv().getAtlasManager(); + if (atlasManager) { + unsigned int numProxies; + atlasManager->getProxies(kA8_GrMaskFormat, &numProxies); + SkASSERT(1 == numProxies); + } #endif fRenderer->deleteTexture(fDistanceFieldAtlas.fTextureHandle); } @@ -86,11 +88,10 @@ void SkInternalAtlasTextContext::recordDraw(const void* srcVertexData, int glyph } void SkInternalAtlasTextContext::flush() { - auto* restrictedAtlasManager = fGrContext->contextPriv().getRestrictedAtlasManager(); + auto* atlasManager = fGrContext->contextPriv().getAtlasManager(); if (!fDistanceFieldAtlas.fProxy) { unsigned int numProxies; - fDistanceFieldAtlas.fProxy = restrictedAtlasManager->getProxies(kA8_GrMaskFormat, - &numProxies)->get(); + fDistanceFieldAtlas.fProxy = atlasManager->getProxies(kA8_GrMaskFormat, &numProxies)->get(); SkASSERT(1 == numProxies); fDistanceFieldAtlas.fTextureHandle = fRenderer->createTexture(SkAtlasTextRenderer::AtlasFormat::kA8, diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index 611fe16377..ef1ce54337 100644 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -66,7 +66,7 @@ class SK_API GrDirectContext : public GrContext { public: GrDirectContext(GrBackend backend) : INHERITED(backend) - , fFullAtlasManager(nullptr) { + , fAtlasManager(nullptr) { } ~GrDirectContext() override { @@ -76,22 +76,22 @@ public: this->flush(); } - delete fFullAtlasManager; + delete fAtlasManager; } void abandonContext() override { INHERITED::abandonContext(); - fFullAtlasManager->freeAll(); + fAtlasManager->freeAll(); } void releaseResourcesAndAbandonContext() override { INHERITED::releaseResourcesAndAbandonContext(); - fFullAtlasManager->freeAll(); + fAtlasManager->freeAll(); } void freeGpuResources() override { this->flush(); - fFullAtlasManager->freeAll(); + fAtlasManager->freeAll(); INHERITED::freeGpuResources(); } @@ -120,20 +120,19 @@ protected: GrGlyphCache* glyphCache = this->contextPriv().getGlyphCache(); GrProxyProvider* proxyProvider = this->contextPriv().proxyProvider(); - fFullAtlasManager = new GrAtlasManager(proxyProvider, glyphCache, - options.fGlyphCacheTextureMaximumBytes, - allowMultitexturing); - this->contextPriv().addOnFlushCallbackObject(fFullAtlasManager); + fAtlasManager = new GrAtlasManager(proxyProvider, glyphCache, + options.fGlyphCacheTextureMaximumBytes, + allowMultitexturing); + this->contextPriv().addOnFlushCallbackObject(fAtlasManager); - SkASSERT(glyphCache->getGlyphSizeLimit() == fFullAtlasManager->getGlyphSizeLimit()); + SkASSERT(glyphCache->getGlyphSizeLimit() == fAtlasManager->getGlyphSizeLimit()); return true; } - GrRestrictedAtlasManager* onGetRestrictedAtlasManager() override { return fFullAtlasManager; } - GrAtlasManager* onGetFullAtlasManager() override { return fFullAtlasManager; } + GrAtlasManager* onGetAtlasManager() override { return fAtlasManager; } private: - GrAtlasManager* fFullAtlasManager; + GrAtlasManager* fAtlasManager; typedef GrContext INHERITED; }; @@ -145,8 +144,7 @@ private: class SK_API GrDDLContext : public GrContext { public: GrDDLContext(sk_sp proxy) - : INHERITED(proxy->fBackend, proxy->fContextUniqueID) - , fRestrictedAtlasManager(nullptr) { + : INHERITED(proxy->fBackend, proxy->fContextUniqueID) { fCaps = proxy->fCaps; fThreadSafeProxy = std::move(proxy); } @@ -179,23 +177,15 @@ protected: return false; } - // DDL TODO: in DDL-mode grab a GrRestrictedAtlasManager from the thread-proxy and - // do not add an onFlushCB return true; } - GrRestrictedAtlasManager* onGetRestrictedAtlasManager() override { - return fRestrictedAtlasManager; - } - - GrAtlasManager* onGetFullAtlasManager() override { + GrAtlasManager* onGetAtlasManager() override { SkASSERT(0); // the DDL Recorders should never invoke this return nullptr; } private: - GrRestrictedAtlasManager* fRestrictedAtlasManager; - typedef GrContext INHERITED; }; diff --git a/src/gpu/GrContextPriv.h b/src/gpu/GrContextPriv.h index ebfe51a3a5..35dc4a9ff4 100644 --- a/src/gpu/GrContextPriv.h +++ b/src/gpu/GrContextPriv.h @@ -192,13 +192,9 @@ public: GrGlyphCache* getGlyphCache() { return fContext->fGlyphCache; } GrTextBlobCache* getTextBlobCache() { return fContext->fTextBlobCache.get(); } - GrRestrictedAtlasManager* getRestrictedAtlasManager() { - return fContext->onGetRestrictedAtlasManager(); - } - // This accessor should only ever be called by the GrOpFlushState. - GrAtlasManager* getFullAtlasManager() { - return fContext->onGetFullAtlasManager(); + GrAtlasManager* getAtlasManager() { + return fContext->onGetAtlasManager(); } void moveOpListsToDDL(SkDeferredDisplayList*); diff --git a/src/gpu/GrOpFlushState.cpp b/src/gpu/GrOpFlushState.cpp index 5309be8f32..661d9aaa76 100644 --- a/src/gpu/GrOpFlushState.cpp +++ b/src/gpu/GrOpFlushState.cpp @@ -196,6 +196,6 @@ GrGlyphCache* GrOpFlushState::glyphCache() const { return fGpu->getContext()->contextPriv().getGlyphCache(); } -GrAtlasManager* GrOpFlushState::fullAtlasManager() const { - return fGpu->getContext()->contextPriv().getFullAtlasManager(); +GrAtlasManager* GrOpFlushState::atlasManager() const { + return fGpu->getContext()->contextPriv().getAtlasManager(); } diff --git a/src/gpu/GrOpFlushState.h b/src/gpu/GrOpFlushState.h index ad33a98e2d..4f210a83d2 100644 --- a/src/gpu/GrOpFlushState.h +++ b/src/gpu/GrOpFlushState.h @@ -94,7 +94,7 @@ public: // At this point we know we're flushing so full access to the GrAtlasManager is required (and // permissible). - GrAtlasManager* fullAtlasManager() const final; + GrAtlasManager* atlasManager() const final; private: /** GrMeshDrawOp::Target override. */ diff --git a/src/gpu/ops/GrAtlasTextOp.cpp b/src/gpu/ops/GrAtlasTextOp.cpp index 07e114196b..10df795021 100644 --- a/src/gpu/ops/GrAtlasTextOp.cpp +++ b/src/gpu/ops/GrAtlasTextOp.cpp @@ -53,18 +53,6 @@ void GrAtlasTextOp::init() { 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* proxies = fRestrictedAtlasManager->getProxies( - this->maskFormat(), &numProxies); - for (unsigned int i = 0; i < numProxies; ++i) { - if (proxies[i]) { - func(proxies[i].get()); - } - } } SkString GrAtlasTextOp::dumpInfo() const { @@ -236,15 +224,13 @@ void GrAtlasTextOp::onPrepareDraws(Target* target) { return; } - GrAtlasManager* fullAtlasManager = target->fullAtlasManager(); - SkASSERT(fRestrictedAtlasManager == fullAtlasManager); + GrAtlasManager* atlasManager = target->atlasManager(); GrGlyphCache* glyphCache = target->glyphCache(); GrMaskFormat maskFormat = this->maskFormat(); unsigned int atlasPageCount; - const sk_sp* proxies = fullAtlasManager->getProxies(maskFormat, - &atlasPageCount); + const sk_sp* proxies = atlasManager->getProxies(maskFormat, &atlasPageCount); if (!proxies[0]) { SkDebugf("Could not allocate backing texture for atlas\n"); return; @@ -255,7 +241,7 @@ void GrAtlasTextOp::onPrepareDraws(Target* target) { target->makePipeline(fSRGBFlags, std::move(fProcessors), target->detachAppliedClip()); SkDEBUGCODE(bool dfPerspective = false); if (this->usesDistanceFields()) { - flushInfo.fGeometryProcessor = this->setupDfProcessor(fullAtlasManager); + flushInfo.fGeometryProcessor = this->setupDfProcessor(atlasManager); SkDEBUGCODE(dfPerspective = fGeoData[0].fViewMatrix.hasPerspective()); } else { GrSamplerState samplerState = fHasScaledGlyphs ? GrSamplerState::ClampBilerp() @@ -290,7 +276,7 @@ void GrAtlasTextOp::onPrepareDraws(Target* target) { Blob* blob = args.fBlob; GrAtlasTextBlob::VertexRegenerator regenerator( resourceProvider, blob, args.fRun, args.fSubRun, args.fViewMatrix, args.fX, args.fY, - args.fColor, target->deferredUploadTarget(), glyphCache, fullAtlasManager, + args.fColor, target->deferredUploadTarget(), glyphCache, atlasManager, &autoGlyphCache); bool done = false; while (!done) { @@ -340,14 +326,13 @@ void GrAtlasTextOp::flush(GrMeshDrawOp::Target* target, FlushInfo* flushInfo) co return; } - auto fullAtlasManager = target->fullAtlasManager(); - SkASSERT(fRestrictedAtlasManager == fullAtlasManager); + auto atlasManager = target->atlasManager(); GrGeometryProcessor* gp = flushInfo->fGeometryProcessor.get(); GrMaskFormat maskFormat = this->maskFormat(); unsigned int numProxies; - const sk_sp* proxies = fullAtlasManager->getProxies(maskFormat, &numProxies); + const sk_sp* proxies = atlasManager->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. @@ -457,11 +442,10 @@ bool GrAtlasTextOp::onCombineIfPossible(GrOp* t, const GrCaps& caps) { // TODO trying to figure out why lcd is so whack // (see comments in GrAtlasTextContext::ComputeCanonicalColor) -sk_sp GrAtlasTextOp::setupDfProcessor( - GrRestrictedAtlasManager* restrictedAtlasManager) const { +sk_sp GrAtlasTextOp::setupDfProcessor(GrAtlasManager* atlasManager) const { unsigned int numProxies; - const sk_sp* proxies = restrictedAtlasManager->getProxies(this->maskFormat(), - &numProxies); + const sk_sp* proxies = atlasManager->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 9ba6c87b9c..d104af259c 100644 --- a/src/gpu/ops/GrAtlasTextOp.h +++ b/src/gpu/ops/GrAtlasTextOp.h @@ -42,10 +42,8 @@ public: static std::unique_ptr MakeBitmap( GrPaint&& paint, GrMaskFormat maskFormat, int glyphCount, - bool hasScaledGlyphs, - GrRestrictedAtlasManager* restrictedAtlasManager) { - std::unique_ptr op(new GrAtlasTextOp(restrictedAtlasManager, - std::move(paint))); + bool hasScaledGlyphs) { + std::unique_ptr op(new GrAtlasTextOp(std::move(paint))); switch (maskFormat) { case kA8_GrMaskFormat: @@ -66,12 +64,10 @@ public: } static std::unique_ptr MakeDistanceField( - GrPaint&& paint, int glyphCount, GrRestrictedAtlasManager* restrictedAtlasManager, - const GrDistanceFieldAdjustTable* distanceAdjustTable, + GrPaint&& paint, int glyphCount, const GrDistanceFieldAdjustTable* distanceAdjustTable, bool useGammaCorrectDistanceTable, SkColor luminanceColor, bool isLCD, bool useBGR, bool isAntiAliased) { - std::unique_ptr op(new GrAtlasTextOp(restrictedAtlasManager, - std::move(paint))); + std::unique_ptr op(new GrAtlasTextOp(std::move(paint))); op->fMaskType = !isAntiAliased ? kAliasedDistanceField_MaskType : isLCD ? (useBGR ? kLCDBGRDistanceField_MaskType @@ -123,9 +119,8 @@ private: // The minimum number of Geometry we will try to allocate. static constexpr auto kMinGeometryAllocated = 12; - GrAtlasTextOp(GrRestrictedAtlasManager* restrictedAtlasManager, GrPaint&& paint) + GrAtlasTextOp(GrPaint&& paint) : INHERITED(ClassID()) - , fRestrictedAtlasManager(restrictedAtlasManager) , fGeoDataAllocSize(kMinGeometryAllocated) , fSRGBFlags(GrPipeline::SRGBFlagsFromPaint(paint)) , fProcessors(std::move(paint)) {} @@ -178,9 +173,8 @@ private: bool onCombineIfPossible(GrOp* t, const GrCaps& caps) override; - sk_sp setupDfProcessor(GrRestrictedAtlasManager*) const; + sk_sp setupDfProcessor(GrAtlasManager*) const; - GrRestrictedAtlasManager* fRestrictedAtlasManager; SkAutoSTMalloc fGeoData; int fGeoDataAllocSize; uint32_t fSRGBFlags; diff --git a/src/gpu/ops/GrMeshDrawOp.h b/src/gpu/ops/GrMeshDrawOp.h index 766fd23ce5..3bf89db46d 100644 --- a/src/gpu/ops/GrMeshDrawOp.h +++ b/src/gpu/ops/GrMeshDrawOp.h @@ -155,7 +155,7 @@ public: virtual GrResourceProvider* resourceProvider() const = 0; virtual GrGlyphCache* glyphCache() const = 0; - virtual GrAtlasManager* fullAtlasManager() const = 0; + virtual GrAtlasManager* atlasManager() const = 0; virtual const GrCaps& caps() const = 0; diff --git a/src/gpu/text/GrAtlasManager.cpp b/src/gpu/text/GrAtlasManager.cpp index 208e7077d0..e9737cc045 100644 --- a/src/gpu/text/GrAtlasManager.cpp +++ b/src/gpu/text/GrAtlasManager.cpp @@ -12,12 +12,9 @@ #include "GrGlyphCache.h" #include "GrProxyProvider.h" - -void GrRestrictedAtlasManager::ComputeAtlasLimits(const GrCaps* caps, float maxTextureBytes, - int* maxDim, int* minDim, - int* maxPlot, int* minPlot) { +void GrAtlasManager::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; @@ -39,12 +36,13 @@ void GrRestrictedAtlasManager::ComputeAtlasLimits(const GrCaps* caps, float maxT *minPlot = SkTMin(512, SkTMax(256, 1 << (log2MaxDim - 3))); } -GrRestrictedAtlasManager::GrRestrictedAtlasManager( - sk_sp caps, - float maxTextureBytes, - GrDrawOpAtlas::AllowMultitexturing allowMultitexturing) - : fCaps(std::move(caps)) - , fAllowMultitexturing(allowMultitexturing) { +GrAtlasManager::GrAtlasManager(GrProxyProvider* proxyProvider, GrGlyphCache* glyphCache, + float maxTextureBytes, + GrDrawOpAtlas::AllowMultitexturing allowMultitexturing) + : fAllowMultitexturing(allowMultitexturing) + , fProxyProvider(proxyProvider) + , fGlyphCache(glyphCache) { + fCaps = fProxyProvider->refCaps(); int maxDim, minDim, maxPlot, minPlot; ComputeAtlasLimits(fCaps.get(), maxTextureBytes, &maxDim, &minDim, &maxPlot, &minPlot); @@ -70,7 +68,7 @@ GrRestrictedAtlasManager::GrRestrictedAtlasManager( fGlyphSizeLimit = minPlot; } -GrRestrictedAtlasManager::~GrRestrictedAtlasManager() { +GrAtlasManager::~GrAtlasManager() { } static GrPixelConfig mask_format_to_pixel_config(GrMaskFormat format, const GrCaps& caps) { @@ -87,15 +85,6 @@ static GrPixelConfig mask_format_to_pixel_config(GrMaskFormat format, const GrCa } } -////////////////////////////////////////////////////////////////////////////////////////////////// -GrAtlasManager::GrAtlasManager(GrProxyProvider* proxyProvider, GrGlyphCache* glyphCache, - float maxTextureBytes, - GrDrawOpAtlas::AllowMultitexturing allowMultitexturing) - : INHERITED(proxyProvider->refCaps(), maxTextureBytes, allowMultitexturing) - , fProxyProvider(proxyProvider) - , fGlyphCache(glyphCache) { -} - void GrAtlasManager::freeAll() { for (int i = 0; i < kMaskFormatCount; ++i) { fAtlases[i] = nullptr; diff --git a/src/gpu/text/GrAtlasManager.h b/src/gpu/text/GrAtlasManager.h index 4b1c6674e0..9bf03c1f40 100644 --- a/src/gpu/text/GrAtlasManager.h +++ b/src/gpu/text/GrAtlasManager.h @@ -15,19 +15,18 @@ class GrAtlasGlypCache; class GrTextStrike; struct GrGlyph; - /** The GrAtlasManager classes manage the lifetime of and access to GrDrawOpAtlases. - * The restricted version is available at op creation time and only allows basic access - * to the proxies (so the created ops can reference them). The full GrAtlasManager class - * is only available at flush time and only via the GrOpFlushState. - * - * This organization implies that all of the advanced atlasManager functionality (i.e., - * adding glyphs to the atlas) are only available at flush time. - */ -class GrRestrictedAtlasManager : public GrOnFlushCallbackObject { +////////////////////////////////////////////////////////////////////////////////////////////////// +/** The GrAtlasManager manages the lifetime of and access to GrDrawOpAtlases. + * It is only available at flush and only via the GrOpFlushState. + * + * This implies that all of the advanced atlasManager functionality (i.e., + * adding glyphs to the atlas) are only available at flush time. + */ +class GrAtlasManager : public GrOnFlushCallbackObject { public: - GrRestrictedAtlasManager(sk_sp, float maxTextureBytes, - GrDrawOpAtlas::AllowMultitexturing); - ~GrRestrictedAtlasManager() override; + GrAtlasManager(GrProxyProvider*, GrGlyphCache*, + float maxTextureBytes, GrDrawOpAtlas::AllowMultitexturing); + ~GrAtlasManager() override; // if getProxies returns nullptr, the client must not try to use other functions on the // GrGlyphCache which use the atlas. This function *must* be called first, before other @@ -46,44 +45,6 @@ public: 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) { - static const int sAtlasIndices[] = { - kA8_GrMaskFormat, - kA565_GrMaskFormat, - kARGB_GrMaskFormat, - }; - static_assert(SK_ARRAY_COUNT(sAtlasIndices) == kMaskFormatCount, "array_size_mismatch"); - - SkASSERT(sAtlasIndices[format] < kMaskFormatCount); - return sAtlasIndices[format]; - } - - GrDrawOpAtlas* getAtlas(GrMaskFormat format) const { - int atlasIndex = MaskFormatToAtlasIndex(format); - SkASSERT(fAtlases[atlasIndex]); - return fAtlases[atlasIndex].get(); - } - - sk_sp fCaps; - GrDrawOpAtlas::AllowMultitexturing fAllowMultitexturing; - std::unique_ptr fAtlases[kMaskFormatCount]; - GrDrawOpAtlasConfig fAtlasConfigs[kMaskFormatCount]; - SkScalar fGlyphSizeLimit; - -private: - virtual bool initAtlas(GrMaskFormat) = 0; - - typedef GrOnFlushCallbackObject INHERITED; -}; - -////////////////////////////////////////////////////////////////////////////////////////////////// -class GrAtlasManager : public GrRestrictedAtlasManager { -public: - GrAtlasManager(GrProxyProvider*, GrGlyphCache*, - float maxTextureBytes, GrDrawOpAtlas::AllowMultitexturing); - void freeAll(); bool hasGlyph(GrGlyph* glyph); @@ -149,12 +110,36 @@ public: void setMaxPages_TestingOnly(uint32_t maxPages); private: - bool initAtlas(GrMaskFormat) override; + bool initAtlas(GrMaskFormat); + + // There is a 1:1 mapping between GrMaskFormats and atlas indices + static int MaskFormatToAtlasIndex(GrMaskFormat format) { + static const int sAtlasIndices[] = { + kA8_GrMaskFormat, + kA565_GrMaskFormat, + kARGB_GrMaskFormat, + }; + static_assert(SK_ARRAY_COUNT(sAtlasIndices) == kMaskFormatCount, "array_size_mismatch"); + SkASSERT(sAtlasIndices[format] < kMaskFormatCount); + return sAtlasIndices[format]; + } + + GrDrawOpAtlas* getAtlas(GrMaskFormat format) const { + int atlasIndex = MaskFormatToAtlasIndex(format); + SkASSERT(fAtlases[atlasIndex]); + return fAtlases[atlasIndex].get(); + } + + sk_sp fCaps; + GrDrawOpAtlas::AllowMultitexturing fAllowMultitexturing; + std::unique_ptr fAtlases[kMaskFormatCount]; + GrDrawOpAtlasConfig fAtlasConfigs[kMaskFormatCount]; + SkScalar fGlyphSizeLimit; GrProxyProvider* fProxyProvider; GrGlyphCache* fGlyphCache; - typedef GrRestrictedAtlasManager INHERITED; + typedef GrOnFlushCallbackObject INHERITED; }; #endif // GrAtlasManager_DEFINED diff --git a/src/gpu/text/GrAtlasTextBlob.cpp b/src/gpu/text/GrAtlasTextBlob.cpp index b4404c3ef9..acb8a6d400 100644 --- a/src/gpu/text/GrAtlasTextBlob.cpp +++ b/src/gpu/text/GrAtlasTextBlob.cpp @@ -252,8 +252,7 @@ inline std::unique_ptr GrAtlasTextBlob::makeOp( const Run::SubRunInfo& info, int glyphCount, uint16_t run, uint16_t subRun, const SkMatrix& viewMatrix, SkScalar x, SkScalar y, const SkIRect& clipRect, const GrTextUtils::Paint& paint, const SkSurfaceProps& props, - const GrDistanceFieldAdjustTable* distanceAdjustTable, - GrRestrictedAtlasManager* restrictedAtlasManager, GrTextUtils::Target* target) { + const GrDistanceFieldAdjustTable* distanceAdjustTable, GrTextUtils::Target* target) { GrMaskFormat format = info.maskFormat(); GrPaint grPaint; @@ -262,12 +261,12 @@ inline std::unique_ptr GrAtlasTextBlob::makeOp( if (info.drawAsDistanceFields()) { bool useBGR = SkPixelGeometryIsBGR(props.pixelGeometry()); op = GrAtlasTextOp::MakeDistanceField( - std::move(grPaint), glyphCount, restrictedAtlasManager, distanceAdjustTable, + std::move(grPaint), glyphCount, distanceAdjustTable, target->colorSpaceInfo().isGammaCorrect(), paint.luminanceColor(), info.hasUseLCDText(), useBGR, info.isAntiAliased()); } else { op = GrAtlasTextOp::MakeBitmap(std::move(grPaint), format, glyphCount, - info.hasScaledGlyphs(), restrictedAtlasManager); + info.hasScaledGlyphs()); } GrAtlasTextOp::Geometry& geometry = op->geometry(); geometry.fViewMatrix = viewMatrix; @@ -303,8 +302,7 @@ static void calculate_translation(bool applyVM, } } -void GrAtlasTextBlob::flush(GrRestrictedAtlasManager* restrictedAtlasManager, - GrTextUtils::Target* target, const SkSurfaceProps& props, +void GrAtlasTextBlob::flush(GrTextUtils::Target* target, const SkSurfaceProps& props, const GrDistanceFieldAdjustTable* distanceAdjustTable, const GrTextUtils::Paint& paint, const GrClip& clip, const SkMatrix& viewMatrix, const SkIRect& clipBounds, @@ -380,7 +378,7 @@ void GrAtlasTextBlob::flush(GrRestrictedAtlasManager* restrictedAtlasManager, if (submitOp) { auto op = this->makeOp(info, glyphCount, runIndex, subRun, viewMatrix, x, y, clipRect, std::move(paint), props, distanceAdjustTable, - restrictedAtlasManager, target); + target); if (op) { if (skipClip) { target->addDrawOp(GrNoClip(), std::move(op)); @@ -398,12 +396,11 @@ void GrAtlasTextBlob::flush(GrRestrictedAtlasManager* restrictedAtlasManager, std::unique_ptr GrAtlasTextBlob::test_makeOp( int glyphCount, uint16_t run, uint16_t subRun, const SkMatrix& viewMatrix, SkScalar x, SkScalar y, const GrTextUtils::Paint& paint, const SkSurfaceProps& props, - const GrDistanceFieldAdjustTable* distanceAdjustTable, - GrRestrictedAtlasManager* restrictedAtlasManager, GrTextUtils::Target* target) { + const GrDistanceFieldAdjustTable* distanceAdjustTable, GrTextUtils::Target* target) { const GrAtlasTextBlob::Run::SubRunInfo& info = fRuns[run].fSubRunInfo[subRun]; SkIRect emptyRect = SkIRect::MakeEmpty(); return this->makeOp(info, glyphCount, run, subRun, viewMatrix, x, y, emptyRect, paint, props, - distanceAdjustTable, restrictedAtlasManager, target); + distanceAdjustTable, target); } void GrAtlasTextBlob::AssertEqual(const GrAtlasTextBlob& l, const GrAtlasTextBlob& r) { diff --git a/src/gpu/text/GrAtlasTextBlob.h b/src/gpu/text/GrAtlasTextBlob.h index a01041f8dc..129e7852b0 100644 --- a/src/gpu/text/GrAtlasTextBlob.h +++ b/src/gpu/text/GrAtlasTextBlob.h @@ -27,7 +27,6 @@ struct GrDistanceFieldAdjustTable; struct GrGlyph; class GrGlyphCache; class GrMemoryPool; -class GrRestrictedAtlasManager; class SkDrawFilter; class SkTextBlob; @@ -206,7 +205,7 @@ public: bool mustRegenerate(const GrTextUtils::Paint&, const SkMaskFilterBase::BlurRec& blurRec, const SkMatrix& viewMatrix, SkScalar x, SkScalar y); - void flush(GrRestrictedAtlasManager*, GrTextUtils::Target*, const SkSurfaceProps& props, + void flush(GrTextUtils::Target*, const SkSurfaceProps& props, const GrDistanceFieldAdjustTable* distanceAdjustTable, const GrTextUtils::Paint& paint, const GrClip& clip, const SkMatrix& viewMatrix, const SkIRect& clipBounds, SkScalar x, @@ -282,7 +281,7 @@ public: const SkMatrix& viewMatrix, SkScalar x, SkScalar y, const GrTextUtils::Paint&, const SkSurfaceProps&, const GrDistanceFieldAdjustTable*, - GrRestrictedAtlasManager*, GrTextUtils::Target*); + GrTextUtils::Target*); private: GrAtlasTextBlob() @@ -519,7 +518,7 @@ private: const Run::SubRunInfo& info, int glyphCount, uint16_t run, uint16_t subRun, const SkMatrix& viewMatrix, SkScalar x, SkScalar y, const SkIRect& clipRect, const GrTextUtils::Paint&, const SkSurfaceProps&, - const GrDistanceFieldAdjustTable*, GrRestrictedAtlasManager* , GrTextUtils::Target*); + const GrDistanceFieldAdjustTable*, GrTextUtils::Target*); struct StrokeInfo { SkScalar fFrameWidth; diff --git a/src/gpu/text/GrAtlasTextContext.cpp b/src/gpu/text/GrAtlasTextContext.cpp index ef71fe0613..210ad637c7 100644 --- a/src/gpu/text/GrAtlasTextContext.cpp +++ b/src/gpu/text/GrAtlasTextContext.cpp @@ -120,7 +120,6 @@ void GrAtlasTextContext::drawTextBlob(GrContext* context, GrTextUtils::Target* t SkScalerContextFlags scalerContextFlags = ComputeScalerContextFlags(target->colorSpaceInfo()); auto glyphCache = context->contextPriv().getGlyphCache(); - auto restrictedAtlasManager = context->contextPriv().getRestrictedAtlasManager(); GrTextBlobCache* textBlobCache = context->contextPriv().getTextBlobCache(); if (canCache) { @@ -182,7 +181,7 @@ void GrAtlasTextContext::drawTextBlob(GrContext* context, GrTextUtils::Target* t viewMatrix, props, blob, x, y, drawFilter); } - cacheBlob->flush(restrictedAtlasManager, target, props, fDistanceAdjustTable.get(), paint, + cacheBlob->flush(target, props, fDistanceAdjustTable.get(), paint, clip, viewMatrix, clipBounds, x, y); } @@ -323,7 +322,6 @@ void GrAtlasTextContext::drawText(GrContext* context, GrTextUtils::Target* targe } auto glyphCache = context->contextPriv().getGlyphCache(); - auto restrictedAtlasManager = context->contextPriv().getRestrictedAtlasManager(); auto textBlobCache = context->contextPriv().getTextBlobCache(); GrTextUtils::Paint paint(&skPaint, &target->colorSpaceInfo()); @@ -333,7 +331,7 @@ void GrAtlasTextContext::drawText(GrContext* context, GrTextUtils::Target* targe ComputeScalerContextFlags(target->colorSpaceInfo()), viewMatrix, props, text, byteLength, x, y)); if (blob) { - blob->flush(restrictedAtlasManager, target, props, fDistanceAdjustTable.get(), paint, + blob->flush(target, props, fDistanceAdjustTable.get(), paint, clip, viewMatrix, regionClipBounds, x, y); } } @@ -350,7 +348,6 @@ void GrAtlasTextContext::drawPosText(GrContext* context, GrTextUtils::Target* ta } auto glyphCache = context->contextPriv().getGlyphCache(); - auto restrictedAtlasManager = context->contextPriv().getRestrictedAtlasManager(); auto textBlobCache = context->contextPriv().getTextBlobCache(); sk_sp blob(this->makeDrawPosTextBlob( @@ -359,7 +356,7 @@ void GrAtlasTextContext::drawPosText(GrContext* context, GrTextUtils::Target* ta ComputeScalerContextFlags(target->colorSpaceInfo()), viewMatrix, props, text, byteLength, pos, scalarsPerPosition, offset)); if (blob) { - blob->flush(restrictedAtlasManager, target, props, fDistanceAdjustTable.get(), paint, + blob->flush(target, props, fDistanceAdjustTable.get(), paint, clip, viewMatrix, regionClipBounds, offset.fX, offset.fY); } } @@ -938,7 +935,6 @@ std::unique_ptr GrAtlasTextContext::createOp_TestingOnly( const SkMatrix& viewMatrix, const char* text, int x, int y) { auto glyphCache = context->contextPriv().getGlyphCache(); - auto restrictedAtlasManager = context->contextPriv().getRestrictedAtlasManager(); static SkSurfaceProps surfaceProps(SkSurfaceProps::kLegacyFontHost_InitType); @@ -957,8 +953,7 @@ std::unique_ptr GrAtlasTextContext::createOp_TestingOnly( SkIntToScalar(x), SkIntToScalar(y))); return blob->test_makeOp(textLen, 0, 0, viewMatrix, x, y, utilsPaint, surfaceProps, - textContext->dfAdjustTable(), restrictedAtlasManager, - rtc->textTarget()); + textContext->dfAdjustTable(), rtc->textTarget()); } GR_DRAW_OP_TEST_DEFINE(GrAtlasTextOp) { diff --git a/src/gpu/text/GrGlyphCache.cpp b/src/gpu/text/GrGlyphCache.cpp index 79f7748def..8f5e2bad77 100644 --- a/src/gpu/text/GrGlyphCache.cpp +++ b/src/gpu/text/GrGlyphCache.cpp @@ -17,8 +17,7 @@ GrGlyphCache::GrGlyphCache(const GrCaps* caps, float maxTextureBytes) , fGlyphSizeLimit(0) { int maxDim, minDim, maxPlot, minPlot; - GrRestrictedAtlasManager::ComputeAtlasLimits(caps, maxTextureBytes, - &maxDim, &minDim, &maxPlot, &minPlot); + GrAtlasManager::ComputeAtlasLimits(caps, maxTextureBytes, &maxDim, &minDim, &maxPlot, &minPlot); fGlyphSizeLimit = minPlot; } -- cgit v1.2.3