Add check that the PlotLocator's plotIndex is consistent w/ the glyph rect

This verifies that the redundant information w/in the AtlasLocator stays consistent.

Bug: 1056730
Change-Id: Ic76d831c3086cfa85979771e1611853d99031f60
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/282614
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Herb Derby <herb@google.com>
This commit is contained in:
Robert Phillips 2020-04-09 14:21:33 -04:00 committed by Skia Commit-Bot
parent 6c8314efa1
commit e87106df32
2 changed files with 19 additions and 2 deletions

View File

@ -38,6 +38,19 @@ std::array<uint16_t, 4> GrDrawOpAtlas::AtlasLocator::getUVs(int padding) const {
return { left, top, right, bottom };
}
#ifdef SK_DEBUG
void GrDrawOpAtlas::AtlasLocator::validate(const GrDrawOpAtlas* drawOpAtlas) const {
// Verify that the plotIndex stored in the PlotLocator is consistent with the glyph rectangle
int numPlotsX = drawOpAtlas->fTextureWidth / drawOpAtlas->fPlotWidth;
int numPlotsY = drawOpAtlas->fTextureHeight / drawOpAtlas->fPlotHeight;
int plotIndex = this->plotIndex();
int plotX = fRect.fLeft / drawOpAtlas->fPlotWidth;
int plotY = fRect.fTop / drawOpAtlas->fPlotHeight;
SkASSERT(plotIndex == (numPlotsY - plotY - 1) * numPlotsX + (numPlotsX - plotX - 1));
}
#endif
// When proxy allocation is deferred until flush time the proxies acting as atlases require
// special handling. This is because the usage that can be determined from the ops themselves
// isn't sufficient. Independent of the ops there will be ASAP and inline uploads to the
@ -281,6 +294,7 @@ inline bool GrDrawOpAtlas::updatePlot(GrDeferredUploadTarget* target,
plot->setLastUploadToken(lastUploadToken);
}
atlasLocator->fPlotLocator = plot->plotLocator();
SkDEBUGCODE(atlasLocator->validate(this);)
return true;
}
@ -407,7 +421,7 @@ GrDrawOpAtlas::ErrorCode GrDrawOpAtlas::addToAtlas(GrResourceProvider* resourceP
// Note that this plot will be uploaded inline with the draws whereas the
// one it displaced most likely was uploaded ASAP.
// With c+14 we could move sk_sp into lambda to only ref once.
// With c++14 we could move sk_sp into lambda to only ref once.
sk_sp<Plot> plotsp(SkRef(newPlot.get()));
GrTextureProxy* proxy = fViews[pageIdx].asTextureProxy();
@ -420,6 +434,7 @@ GrDrawOpAtlas::ErrorCode GrDrawOpAtlas::addToAtlas(GrResourceProvider* resourceP
newPlot->setLastUploadToken(lastUploadToken);
atlasLocator->fPlotLocator = newPlot->plotLocator();
SkDEBUGCODE(atlasLocator->validate(this);)
return ErrorCode::kSucceeded;
}

View File

@ -99,6 +99,8 @@ public:
private:
friend class GrDrawOpAtlas;
SkDEBUGCODE(void validate(const GrDrawOpAtlas*) const;)
PlotLocator fPlotLocator{GrDrawOpAtlas::kInvalidPlotLocator};
GrIRect16 fRect{0, 0, 0, 0};
@ -204,7 +206,7 @@ public:
uint64_t atlasGeneration() const { return fAtlasGeneration; }
bool hasID(const AtlasLocator& atlasLocator) {
if (kInvalidPlotLocator == atlasLocator.fPlotLocator) {
if (kInvalidPlotLocator == atlasLocator.plotLocator()) {
return false;
}