diff --git a/src/gpu/GrDrawOpAtlas.cpp b/src/gpu/GrDrawOpAtlas.cpp index 6106828c4f..bc1b789378 100644 --- a/src/gpu/GrDrawOpAtlas.cpp +++ b/src/gpu/GrDrawOpAtlas.cpp @@ -69,7 +69,7 @@ GrDrawOpAtlas::Plot::Plot(int pageIndex, int plotIndex, uint64_t genID, int offX , fPageIndex(pageIndex) , fPlotIndex(plotIndex) , fGenID(genID) - , fID(CreateId(fPageIndex, fPlotIndex, fGenID)) + , fPlotLocator(CreatePlotLocator(fPageIndex, fPlotIndex, fGenID)) , fData(nullptr) , fWidth(width) , fHeight(height) @@ -162,7 +162,7 @@ void GrDrawOpAtlas::Plot::resetRects() { fRectanizer.reset(); fGenID++; - fID = CreateId(fPageIndex, fPlotIndex, fGenID); + fPlotLocator = CreatePlotLocator(fPageIndex, fPlotIndex, fGenID); fLastUpload = GrDeferredUploadToken::AlreadyFlushedToken(); fLastUse = GrDeferredUploadToken::AlreadyFlushedToken(); @@ -201,16 +201,17 @@ GrDrawOpAtlas::GrDrawOpAtlas(GrProxyProvider* proxyProvider, const GrBackendForm this->createPages(proxyProvider); } -inline void GrDrawOpAtlas::processEviction(AtlasID id) { +inline void GrDrawOpAtlas::processEviction(PlotLocator plotLocator) { for (auto evictor : fEvictionCallbacks) { - evictor->evict(id); + evictor->evict(plotLocator); } ++fAtlasGeneration; } -inline bool GrDrawOpAtlas::updatePlot(GrDeferredUploadTarget* target, AtlasID* id, Plot* plot) { - int pageIdx = GetPageIndexFromID(plot->id()); +inline bool GrDrawOpAtlas::updatePlot(GrDeferredUploadTarget* target, + PlotLocator* plotLocator, Plot* plot) { + int pageIdx = GetPageIndexFromID(plot->plotLocator()); this->makeMRU(plot, pageIdx); // If our most recent upload has already occurred then we have to insert a new @@ -229,11 +230,11 @@ inline bool GrDrawOpAtlas::updatePlot(GrDeferredUploadTarget* target, AtlasID* i }); plot->setLastUploadToken(lastUploadToken); } - *id = plot->id(); + *plotLocator = plot->plotLocator(); return true; } -bool GrDrawOpAtlas::uploadToPage(const GrCaps& caps, unsigned int pageIdx, AtlasID* id, +bool GrDrawOpAtlas::uploadToPage(const GrCaps& caps, unsigned int pageIdx, PlotLocator* plotLocator, GrDeferredUploadTarget* target, int width, int height, const void* image, SkIPoint16* loc) { SkASSERT(fViews[pageIdx].proxy() && fViews[pageIdx].proxy()->isInstantiated()); @@ -246,7 +247,7 @@ bool GrDrawOpAtlas::uploadToPage(const GrCaps& caps, unsigned int pageIdx, Atlas SkASSERT(caps.bytesPerPixel(fViews[pageIdx].proxy()->backendFormat()) == plot->bpp()); if (plot->addSubImage(width, height, image, loc)) { - return this->updatePlot(target, id, plot); + return this->updatePlot(target, plotLocator, plot); } } @@ -262,7 +263,8 @@ bool GrDrawOpAtlas::uploadToPage(const GrCaps& caps, unsigned int pageIdx, Atlas static constexpr auto kRecentlyUsedCount = 256; GrDrawOpAtlas::ErrorCode GrDrawOpAtlas::addToAtlas(GrResourceProvider* resourceProvider, - AtlasID* id, GrDeferredUploadTarget* target, + PlotLocator* plotLocator, + GrDeferredUploadTarget* target, int width, int height, const void* image, SkIPoint16* loc) { if (width > fPlotWidth || height > fPlotHeight) { @@ -275,7 +277,7 @@ GrDrawOpAtlas::ErrorCode GrDrawOpAtlas::addToAtlas(GrResourceProvider* resourceP // We prioritize this upload to the first pages, not the most recently used, to make it easier // to remove unused pages in reverse page order. for (unsigned int pageIdx = 0; pageIdx < fNumActivePages; ++pageIdx) { - if (this->uploadToPage(caps, pageIdx, id, target, width, height, image, loc)) { + if (this->uploadToPage(caps, pageIdx, plotLocator, target, width, height, image, loc)) { return ErrorCode::kSucceeded; } } @@ -295,7 +297,7 @@ GrDrawOpAtlas::ErrorCode GrDrawOpAtlas::addToAtlas(GrResourceProvider* resourceP plot->bpp()); SkDEBUGCODE(bool verify = )plot->addSubImage(width, height, image, loc); SkASSERT(verify); - if (!this->updatePlot(target, id, plot)) { + if (!this->updatePlot(target, plotLocator, plot)) { return ErrorCode::kError; } return ErrorCode::kSucceeded; @@ -307,7 +309,8 @@ GrDrawOpAtlas::ErrorCode GrDrawOpAtlas::addToAtlas(GrResourceProvider* resourceP return ErrorCode::kError; } - if (this->uploadToPage(caps, fNumActivePages-1, id, target, width, height, image, loc)) { + if (this->uploadToPage( + caps, fNumActivePages-1, plotLocator, target, width, height, image, loc)) { return ErrorCode::kSucceeded; } else { // If we fail to upload to a newly activated page then something has gone terribly @@ -340,8 +343,8 @@ GrDrawOpAtlas::ErrorCode GrDrawOpAtlas::addToAtlas(GrResourceProvider* resourceP return ErrorCode::kTryAgain; } - this->processEviction(plot->id()); - int pageIdx = GetPageIndexFromID(plot->id()); + this->processEviction(plot->plotLocator()); + int pageIdx = GetPageIndexFromID(plot->plotLocator()); fPages[pageIdx].fPlotList.remove(plot); sk_sp& newPlot = fPages[pageIdx].fPlotArray[plot->index()]; newPlot.reset(plot->clone()); @@ -365,7 +368,7 @@ GrDrawOpAtlas::ErrorCode GrDrawOpAtlas::addToAtlas(GrResourceProvider* resourceP }); newPlot->setLastUploadToken(lastUploadToken); - *id = newPlot->id(); + *plotLocator = newPlot->plotLocator(); return ErrorCode::kSucceeded; } diff --git a/src/gpu/GrDrawOpAtlas.h b/src/gpu/GrDrawOpAtlas.h index 0caebe424e..c88b720f7d 100644 --- a/src/gpu/GrDrawOpAtlas.h +++ b/src/gpu/GrDrawOpAtlas.h @@ -60,22 +60,25 @@ public: // in BulkUseTokenUpdater /** - * An AtlasID is an opaque handle which callers can use to determine if the atlas contains - * a specific piece of data. + * A PlotLocator specifies the plot and is analogous to a directory path: + * page/plot/plotGeneration + * + * In fact PlotLocator is a portion of a glyph image location in the atlas fully specified by: + * format/atlasGeneration/page/plot/plotGeneration/(u,v) */ - typedef uint64_t AtlasID; - static const uint32_t kInvalidAtlasID = 0; + typedef uint64_t PlotLocator; + static const uint64_t kInvalidPlotLocator = 0; static const uint64_t kInvalidAtlasGeneration = 0; /** * An interface for eviction callbacks. Whenever GrDrawOpAtlas evicts a - * specific AtlasID, it will call all of the registered listeners so they can process the + * specific PlotLocator, it will call all of the registered listeners so they can process the * eviction. */ class EvictionCallback { public: virtual ~EvictionCallback() = default; - virtual void evict(AtlasID id) = 0; + virtual void evict(PlotLocator plotLocator) = 0; }; /** @@ -123,7 +126,7 @@ public: kTryAgain }; - ErrorCode addToAtlas(GrResourceProvider*, AtlasID*, GrDeferredUploadTarget*, + ErrorCode addToAtlas(GrResourceProvider*, PlotLocator*, GrDeferredUploadTarget*, int width, int height, const void* image, SkIPoint16* loc); @@ -131,23 +134,24 @@ public: uint64_t atlasGeneration() const { return fAtlasGeneration; } - bool hasID(AtlasID id) { - if (kInvalidAtlasID == id) { + bool hasID(PlotLocator plotLocator) { + if (kInvalidPlotLocator == plotLocator) { return false; } - uint32_t plot = GetPlotIndexFromID(id); + + uint32_t plot = GetPlotIndexFromID(plotLocator); SkASSERT(plot < fNumPlots); - uint32_t page = GetPageIndexFromID(id); + uint32_t page = GetPageIndexFromID(plotLocator); SkASSERT(page < fNumActivePages); - return fPages[page].fPlotArray[plot]->genID() == GetGenerationFromID(id); + return fPages[page].fPlotArray[plot]->genID() == GetGenerationFromID(plotLocator); } /** To ensure the atlas does not evict a given entry, the client must set the last use token. */ - void setLastUseToken(AtlasID id, GrDeferredUploadToken token) { - SkASSERT(this->hasID(id)); - uint32_t plotIdx = GetPlotIndexFromID(id); + void setLastUseToken(PlotLocator plotLocator, GrDeferredUploadToken token) { + SkASSERT(this->hasID(plotLocator)); + uint32_t plotIdx = GetPlotIndexFromID(plotLocator); SkASSERT(plotIdx < fNumPlots); - uint32_t pageIdx = GetPageIndexFromID(id); + uint32_t pageIdx = GetPageIndexFromID(plotLocator); SkASSERT(pageIdx < fNumActivePages); Plot* plot = fPages[pageIdx].fPlotArray[plotIdx].get(); this->makeMRU(plot, pageIdx); @@ -171,9 +175,9 @@ public: memcpy(fPlotAlreadyUpdated, that.fPlotAlreadyUpdated, sizeof(fPlotAlreadyUpdated)); } - bool add(AtlasID id) { - int index = GrDrawOpAtlas::GetPlotIndexFromID(id); - int pageIdx = GrDrawOpAtlas::GetPageIndexFromID(id); + bool add(PlotLocator plotLocator) { + int index = GrDrawOpAtlas::GetPlotIndexFromID(plotLocator); + int pageIdx = GrDrawOpAtlas::GetPageIndexFromID(plotLocator); if (this->find(pageIdx, index)) { return false; } @@ -228,8 +232,8 @@ public: void compact(GrDeferredUploadToken startTokenForNextFlush); - static uint32_t GetPageIndexFromID(AtlasID id) { - return id & 0xff; + static uint32_t GetPageIndexFromID(PlotLocator plotLocator) { + return plotLocator & 0xff; } void instantiate(GrOnFlushResourceProvider*); @@ -264,9 +268,9 @@ private: * if a particular subimage is still present in the atlas. */ uint64_t genID() const { return fGenID; } - GrDrawOpAtlas::AtlasID id() const { - SkASSERT(GrDrawOpAtlas::kInvalidAtlasID != fID); - return fID; + GrDrawOpAtlas::PlotLocator plotLocator() const { + SkASSERT(GrDrawOpAtlas::kInvalidPlotLocator != fPlotLocator); + return fPlotLocator; } SkDEBUGCODE(size_t bpp() const { return fBytesPerPixel; }) @@ -306,8 +310,8 @@ private: fColorType); } - static GrDrawOpAtlas::AtlasID CreateId(uint32_t pageIdx, uint32_t plotIdx, - uint64_t generation) { + static GrDrawOpAtlas::PlotLocator CreatePlotLocator( + uint32_t pageIdx, uint32_t plotIdx, uint64_t generation) { SkASSERT(pageIdx < (1 << 8)); SkASSERT(pageIdx < kMaxMultitexturePages); SkASSERT(plotIdx < (1 << 8)); @@ -325,7 +329,7 @@ private: const uint32_t fPlotIndex : 16; }; uint64_t fGenID; - GrDrawOpAtlas::AtlasID fID; + GrDrawOpAtlas::PlotLocator fPlotLocator; unsigned char* fData; const int fWidth; const int fHeight; @@ -345,16 +349,16 @@ private: typedef SkTInternalLList PlotList; - static uint32_t GetPlotIndexFromID(AtlasID id) { - return (id >> 8) & 0xff; + static uint32_t GetPlotIndexFromID(PlotLocator plotLocator) { + return (plotLocator >> 8) & 0xff; } // top 48 bits are reserved for the generation ID - static uint64_t GetGenerationFromID(AtlasID id) { - return (id >> 16) & 0xffffffffffff; + static uint64_t GetGenerationFromID(PlotLocator plotLocator) { + return (plotLocator >> 16) & 0xffffffffffff; } - inline bool updatePlot(GrDeferredUploadTarget*, AtlasID*, Plot*); + inline bool updatePlot(GrDeferredUploadTarget*, PlotLocator*, Plot*); inline void makeMRU(Plot* plot, int pageIdx) { if (fPages[pageIdx].fPlotList.head() == plot) { @@ -368,7 +372,7 @@ private: // the front and remove from the back there is no need for MRU. } - bool uploadToPage(const GrCaps&, unsigned int pageIdx, AtlasID* id, + bool uploadToPage(const GrCaps&, unsigned int pageIdx, PlotLocator* plotLocator, GrDeferredUploadTarget* target, int width, int height, const void* image, SkIPoint16* loc); @@ -376,9 +380,9 @@ private: bool activateNewPage(GrResourceProvider*); void deactivateLastPage(); - void processEviction(AtlasID); + void processEviction(PlotLocator); inline void processEvictionAndResetRects(Plot* plot) { - this->processEviction(plot->id()); + this->processEviction(plot->plotLocator()); plot->resetRects(); } diff --git a/src/gpu/GrGlyph.h b/src/gpu/GrGlyph.h index 45cfb61046..a49fa337a9 100644 --- a/src/gpu/GrGlyph.h +++ b/src/gpu/GrGlyph.h @@ -80,15 +80,15 @@ struct GrGlyph { int width() const { return fBounds.width(); } int height() const { return fBounds.height(); } - uint32_t pageIndex() const { return GrDrawOpAtlas::GetPageIndexFromID(fID); } + uint32_t pageIndex() const { return GrDrawOpAtlas::GetPageIndexFromID(fPlotLocator); } MaskStyle maskStyle() const { return fMaskStyle; } - const SkPackedGlyphID fPackedID; - const GrMaskFormat fMaskFormat; - const MaskStyle fMaskStyle; - const GrIRect16 fBounds; - SkIPoint16 fAtlasLocation{0, 0}; - GrDrawOpAtlas::AtlasID fID{GrDrawOpAtlas::kInvalidAtlasID}; + const SkPackedGlyphID fPackedID; + const GrMaskFormat fMaskFormat; + const MaskStyle fMaskStyle; + const GrIRect16 fBounds; + SkIPoint16 fAtlasLocation{0, 0}; + GrDrawOpAtlas::PlotLocator fPlotLocator{GrDrawOpAtlas::kInvalidPlotLocator}; }; #endif diff --git a/src/gpu/ops/GrSmallPathRenderer.cpp b/src/gpu/ops/GrSmallPathRenderer.cpp index 7527e39f6c..5d6e1e3852 100644 --- a/src/gpu/ops/GrSmallPathRenderer.cpp +++ b/src/gpu/ops/GrSmallPathRenderer.cpp @@ -116,10 +116,10 @@ private: class ShapeData { public: - ShapeDataKey fKey; - GrDrawOpAtlas::AtlasID fID; - SkRect fBounds; - GrIRect16 fTextureCoords; + ShapeDataKey fKey; + GrDrawOpAtlas::PlotLocator fPlotLocator; + SkRect fBounds; + GrIRect16 fTextureCoords; SK_DECLARE_INTERNAL_LLIST_INTERFACE(ShapeData); static inline const ShapeDataKey& GetKey(const ShapeData& data) { @@ -134,14 +134,14 @@ public: // Callback to clear out internal path cache when eviction occurs -void GrSmallPathRenderer::evict(GrDrawOpAtlas::AtlasID id) { +void GrSmallPathRenderer::evict(GrDrawOpAtlas::PlotLocator plotLocator) { // remove any paths that use this plot ShapeDataList::Iter iter; iter.init(fShapeList, ShapeDataList::Iter::kHead_IterStart); ShapeData* shapeData; while ((shapeData = iter.get())) { iter.next(); - if (id == shapeData->fID) { + if (plotLocator == shapeData->fPlotLocator) { fShapeCache.remove(shapeData->fKey); fShapeList.remove(shapeData); delete shapeData; @@ -437,7 +437,7 @@ private: // check to see if df path is cached ShapeDataKey key(args.fShape, SkScalarCeilToInt(desiredDimension)); shapeData = fShapeCache->find(key); - if (nullptr == shapeData || !fAtlas->hasID(shapeData->fID)) { + if (nullptr == shapeData || !fAtlas->hasID(shapeData->fPlotLocator)) { // Remove the stale cache entry if (shapeData) { fShapeCache->remove(shapeData->fKey); @@ -462,7 +462,7 @@ private: // check to see if bitmap path is cached ShapeDataKey key(args.fShape, args.fViewMatrix); shapeData = fShapeCache->find(key); - if (nullptr == shapeData || !fAtlas->hasID(shapeData->fID)) { + if (nullptr == shapeData || !fAtlas->hasID(shapeData->fPlotLocator)) { // Remove the stale cache entry if (shapeData) { fShapeCache->remove(shapeData->fKey); @@ -484,7 +484,8 @@ private: } auto uploadTarget = target->deferredUploadTarget(); - fAtlas->setLastUseToken(shapeData->fID, uploadTarget->tokenTracker()->nextDrawToken()); + fAtlas->setLastUseToken( + shapeData->fPlotLocator, uploadTarget->tokenTracker()->nextDrawToken()); this->writePathVertices(fAtlas, vertices, GrVertexColor(args.fColor, fWideColor), args.fViewMatrix, shapeData); @@ -496,11 +497,11 @@ private: bool addToAtlas(GrMeshDrawOp::Target* target, FlushInfo* flushInfo, GrDrawOpAtlas* atlas, int width, int height, const void* image, - GrDrawOpAtlas::AtlasID* id, SkIPoint16* atlasLocation) const { + GrDrawOpAtlas::PlotLocator* plotLocator, SkIPoint16* atlasLocation) const { auto resourceProvider = target->resourceProvider(); auto uploadTarget = target->deferredUploadTarget(); - GrDrawOpAtlas::ErrorCode code = atlas->addToAtlas(resourceProvider, id, + GrDrawOpAtlas::ErrorCode code = atlas->addToAtlas(resourceProvider, plotLocator, uploadTarget, width, height, image, atlasLocation); if (GrDrawOpAtlas::ErrorCode::kError == code) { @@ -510,7 +511,7 @@ private: if (GrDrawOpAtlas::ErrorCode::kTryAgain == code) { this->flush(target, flushInfo); - code = atlas->addToAtlas(resourceProvider, id, uploadTarget, width, height, + code = atlas->addToAtlas(resourceProvider, plotLocator, uploadTarget, width, height, image, atlasLocation); } @@ -602,16 +603,16 @@ private: // add to atlas SkIPoint16 atlasLocation; - GrDrawOpAtlas::AtlasID id; + GrDrawOpAtlas::PlotLocator plotLocator; if (!this->addToAtlas(target, flushInfo, atlas, - width, height, dfStorage.get(), &id, &atlasLocation)) { + width, height, dfStorage.get(), &plotLocator, &atlasLocation)) { return false; } // add to cache shapeData->fKey.set(shape, dimension); - shapeData->fID = id; + shapeData->fPlotLocator = plotLocator; shapeData->fBounds = SkRect::Make(devPathBounds); shapeData->fBounds.offset(-translateX, -translateY); @@ -621,7 +622,7 @@ private: shapeData->fBounds.fBottom /= scale; // We pack the 2bit page index in the low bit of the u and v texture coords - uint16_t pageIndex = GrDrawOpAtlas::GetPageIndexFromID(id); + uint16_t pageIndex = GrDrawOpAtlas::GetPageIndexFromID(plotLocator); SkASSERT(pageIndex < 4); uint16_t uBit = (pageIndex >> 1) & 0x1; uint16_t vBit = pageIndex & 0x1; @@ -704,22 +705,22 @@ private: // add to atlas SkIPoint16 atlasLocation; - GrDrawOpAtlas::AtlasID id; + GrDrawOpAtlas::PlotLocator plotLocator; - if (!this->addToAtlas(target, flushInfo, atlas, - dst.width(), dst.height(), dst.addr(), &id, &atlasLocation)) { + if (!this->addToAtlas(target, flushInfo, atlas, dst.width(), dst.height(), + dst.addr(), &plotLocator, &atlasLocation)) { return false; } // add to cache shapeData->fKey.set(shape, ctm); - shapeData->fID = id; + shapeData->fPlotLocator = plotLocator; shapeData->fBounds = SkRect::Make(devPathBounds); shapeData->fBounds.offset(-translateX, -translateY); // We pack the 2bit page index in the low bit of the u and v texture coords - uint16_t pageIndex = GrDrawOpAtlas::GetPageIndexFromID(id); + uint16_t pageIndex = GrDrawOpAtlas::GetPageIndexFromID(plotLocator); SkASSERT(pageIndex < 4); uint16_t uBit = (pageIndex >> 1) & 0x1; uint16_t vBit = pageIndex & 0x1; @@ -925,14 +926,14 @@ struct GrSmallPathRenderer::PathTestStruct : public GrDrawOpAtlas::EvictionCallb fShapeCache.reset(); } - void evict(GrDrawOpAtlas::AtlasID id) override { + void evict(GrDrawOpAtlas::PlotLocator plotLocator) override { // remove any paths that use this plot ShapeDataList::Iter iter; iter.init(fShapeList, ShapeDataList::Iter::kHead_IterStart); ShapeData* shapeData; while ((shapeData = iter.get())) { iter.next(); - if (id == shapeData->fID) { + if (plotLocator == shapeData->fPlotLocator) { fShapeCache.remove(shapeData->fKey); fShapeList.remove(shapeData); delete shapeData; diff --git a/src/gpu/ops/GrSmallPathRenderer.h b/src/gpu/ops/GrSmallPathRenderer.h index 4d86f8c7f9..d135b24330 100644 --- a/src/gpu/ops/GrSmallPathRenderer.h +++ b/src/gpu/ops/GrSmallPathRenderer.h @@ -73,7 +73,7 @@ private: bool onDrawPath(const DrawPathArgs&) override; - void evict(GrDrawOpAtlas::AtlasID) override; + void evict(GrDrawOpAtlas::PlotLocator) override; std::unique_ptr fAtlas; ShapeCache fShapeCache; diff --git a/src/gpu/text/GrAtlasManager.cpp b/src/gpu/text/GrAtlasManager.cpp index 26dad6b1d0..8a96c961cc 100644 --- a/src/gpu/text/GrAtlasManager.cpp +++ b/src/gpu/text/GrAtlasManager.cpp @@ -30,27 +30,27 @@ void GrAtlasManager::freeAll() { bool GrAtlasManager::hasGlyph(GrGlyph* glyph) { SkASSERT(glyph); - return this->getAtlas(glyph->fMaskFormat)->hasID(glyph->fID); + return this->getAtlas(glyph->fMaskFormat)->hasID(glyph->fPlotLocator); } // add to texture atlas that matches this format GrDrawOpAtlas::ErrorCode GrAtlasManager::addToAtlas( GrResourceProvider* resourceProvider, GrStrikeCache* glyphCache, - GrTextStrike* strike, GrDrawOpAtlas::AtlasID* id, + GrTextStrike* strike, GrDrawOpAtlas::PlotLocator* plotLocator, GrDeferredUploadTarget* target, GrMaskFormat format, int width, int height, const void* image, SkIPoint16* loc) { glyphCache->setStrikeToPreserve(strike); - return this->getAtlas(format)->addToAtlas(resourceProvider, id, target, width, height, - image, loc); + return this->getAtlas(format)->addToAtlas( + resourceProvider, plotLocator, target, width, height, image, loc); } void GrAtlasManager::addGlyphToBulkAndSetUseToken(GrDrawOpAtlas::BulkUseTokenUpdater* updater, GrGlyph* glyph, GrDeferredUploadToken token) { SkASSERT(glyph); - if (updater->add(glyph->fID)) { - this->getAtlas(glyph->fMaskFormat)->setLastUseToken(glyph->fID, token); + if (updater->add(glyph->fPlotLocator)) { + this->getAtlas(glyph->fMaskFormat)->setLastUseToken(glyph->fPlotLocator, token); } } diff --git a/src/gpu/text/GrAtlasManager.h b/src/gpu/text/GrAtlasManager.h index f21f35a2da..2e4252a042 100644 --- a/src/gpu/text/GrAtlasManager.h +++ b/src/gpu/text/GrAtlasManager.h @@ -75,9 +75,9 @@ public: // add to texture atlas that matches this format GrDrawOpAtlas::ErrorCode addToAtlas( - GrResourceProvider*, GrStrikeCache*, GrTextStrike*, - GrDrawOpAtlas::AtlasID*, GrDeferredUploadTarget*, GrMaskFormat, - int width, int height, const void* image, SkIPoint16* loc); + GrResourceProvider*, GrStrikeCache*, GrTextStrike*, + GrDrawOpAtlas::PlotLocator*, GrDeferredUploadTarget*, GrMaskFormat, + int width, int height, const void* image, SkIPoint16* loc); // Some clients may wish to verify the integrity of the texture backing store of the // GrDrawOpAtlas. The atlasGeneration returned below is a monotonically increasing number which diff --git a/src/gpu/text/GrStrikeCache.cpp b/src/gpu/text/GrStrikeCache.cpp index 6ef2415a75..3f0fc6e15f 100644 --- a/src/gpu/text/GrStrikeCache.cpp +++ b/src/gpu/text/GrStrikeCache.cpp @@ -33,10 +33,10 @@ void GrStrikeCache::freeAll() { fCache.reset(); } -void GrStrikeCache::evict(GrDrawOpAtlas::AtlasID id) { - fCache.mutate([this, id](sk_sp* cacheSlot){ +void GrStrikeCache::evict(GrDrawOpAtlas::PlotLocator plotLocator) { + fCache.mutate([this, plotLocator](sk_sp* cacheSlot){ GrTextStrike* strike = cacheSlot->get(); - strike->removeID(id); + strike->removeID(plotLocator); // clear out any empty strikes. We will preserve the strike whose call to addToAtlas // triggered the eviction @@ -158,10 +158,10 @@ static void get_packed_glyph_image(const SkGlyph* glyph, int width, GrTextStrike::GrTextStrike(const SkDescriptor& key) : fFontScalerKey(key) {} -void GrTextStrike::removeID(GrDrawOpAtlas::AtlasID id) { - fCache.foreach([this, id](GrGlyph** glyph){ - if ((*glyph)->fID == id) { - (*glyph)->fID = GrDrawOpAtlas::kInvalidAtlasID; +void GrTextStrike::removeID(GrDrawOpAtlas::PlotLocator plotLocator) { + fCache.foreach([this, plotLocator](GrGlyph** glyph){ + if ((*glyph)->fPlotLocator == plotLocator) { + (*glyph)->fPlotLocator = GrDrawOpAtlas::kInvalidPlotLocator; fAtlasedGlyphs--; SkASSERT(fAtlasedGlyphs >= 0); } @@ -208,16 +208,16 @@ GrDrawOpAtlas::ErrorCode GrTextStrike::addGlyphToAtlas( rowBytes, expectedMaskFormat, dataPtr, glyphCache->getMasks()); GrDrawOpAtlas::ErrorCode result = fullAtlasManager->addToAtlas( - resourceProvider, glyphCache, this, - &glyph->fID, target, expectedMaskFormat, - width, height, - storage.get(), &glyph->fAtlasLocation); + resourceProvider, glyphCache, this, + &glyph->fPlotLocator, target, expectedMaskFormat, + width, height, + storage.get(), &glyph->fAtlasLocation); if (GrDrawOpAtlas::ErrorCode::kSucceeded == result) { if (addPad) { glyph->fAtlasLocation.fX += 1; glyph->fAtlasLocation.fY += 1; } - SkASSERT(GrDrawOpAtlas::kInvalidAtlasID != glyph->fID); + SkASSERT(GrDrawOpAtlas::kInvalidPlotLocator != glyph->fPlotLocator); fAtlasedGlyphs++; } return result; diff --git a/src/gpu/text/GrStrikeCache.h b/src/gpu/text/GrStrikeCache.h index af09357610..cb80ac11f2 100644 --- a/src/gpu/text/GrStrikeCache.h +++ b/src/gpu/text/GrStrikeCache.h @@ -54,7 +54,7 @@ public: int countGlyphs() const { return fCache.count(); } // remove any references to this plot - void removeID(GrDrawOpAtlas::AtlasID); + void removeID(GrDrawOpAtlas::PlotLocator); // If a TextStrike is abandoned by the cache, then the caller must get a new strike bool isAbandoned() const { return fIsAbandoned; } @@ -106,7 +106,7 @@ public: void freeAll(); - void evict(GrDrawOpAtlas::AtlasID id) override; + void evict(GrDrawOpAtlas::PlotLocator plotLocator) override; private: sk_sp generateStrike(const SkDescriptor& desc) { diff --git a/tests/DrawOpAtlasTest.cpp b/tests/DrawOpAtlasTest.cpp index 51834ad5e8..6786306d38 100644 --- a/tests/DrawOpAtlasTest.cpp +++ b/tests/DrawOpAtlasTest.cpp @@ -74,7 +74,7 @@ void GrDrawOpAtlas::setMaxPages_TestingOnly(uint32_t maxPages) { class DummyEvict : public GrDrawOpAtlas::EvictionCallback { public: - void evict(GrDrawOpAtlas::AtlasID id) override { + void evict(GrDrawOpAtlas::PlotLocator plotLocator) override { SkASSERT(0); // The unit test shouldn't exercise this code path } }; @@ -114,7 +114,7 @@ private: static bool fill_plot(GrDrawOpAtlas* atlas, GrResourceProvider* resourceProvider, GrDeferredUploadTarget* target, - GrDrawOpAtlas::AtlasID* atlasID, + GrDrawOpAtlas::PlotLocator* plotLocator, int alpha) { SkImageInfo ii = SkImageInfo::MakeA8(kPlotSize, kPlotSize); @@ -124,7 +124,7 @@ static bool fill_plot(GrDrawOpAtlas* atlas, SkIPoint16 loc; GrDrawOpAtlas::ErrorCode code; - code = atlas->addToAtlas(resourceProvider, atlasID, target, kPlotSize, kPlotSize, + code = atlas->addToAtlas(resourceProvider, plotLocator, target, kPlotSize, kPlotSize, data.getAddr(0, 0), &loc); return GrDrawOpAtlas::ErrorCode::kSucceeded == code; } @@ -158,9 +158,10 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(BasicDrawOpAtlas, reporter, ctxInfo) { check(reporter, atlas.get(), 0, 4, 0); // Fill up the first level - GrDrawOpAtlas::AtlasID atlasIDs[kNumPlots * kNumPlots]; + GrDrawOpAtlas::PlotLocator plotLocators[kNumPlots * kNumPlots]; for (int i = 0; i < kNumPlots * kNumPlots; ++i) { - bool result = fill_plot(atlas.get(), resourceProvider, &uploadTarget, &atlasIDs[i], i*32); + bool result = fill_plot( + atlas.get(), resourceProvider, &uploadTarget, &plotLocators[i], i * 32); REPORTER_ASSERT(reporter, result); check(reporter, atlas.get(), 1, 4, 1); } @@ -169,14 +170,14 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(BasicDrawOpAtlas, reporter, ctxInfo) { check(reporter, atlas.get(), 1, 4, 1); // Force allocation of a second level - GrDrawOpAtlas::AtlasID atlasID; - bool result = fill_plot(atlas.get(), resourceProvider, &uploadTarget, &atlasID, 4*32); + GrDrawOpAtlas::PlotLocator plotLocator; + bool result = fill_plot(atlas.get(), resourceProvider, &uploadTarget, &plotLocator, 4 * 32); REPORTER_ASSERT(reporter, result); check(reporter, atlas.get(), 2, 4, 2); // Simulate a lot of draws using only the first plot. The last texture should be compacted. for (int i = 0; i < 512; ++i) { - atlas->setLastUseToken(atlasIDs[0], uploadTarget.tokenTracker()->nextDrawToken()); + atlas->setLastUseToken(plotLocators[0], uploadTarget.tokenTracker()->nextDrawToken()); uploadTarget.issueDrawToken(); uploadTarget.flushToken(); atlas->compact(uploadTarget.tokenTracker()->nextTokenToFlush());