Index: src/gpu/GrLayerCache.cpp |
diff --git a/src/gpu/GrLayerCache.cpp b/src/gpu/GrLayerCache.cpp |
index 105ee04e53cd1a26f6ab78238211229bc3916225..9af89a34665664e42499623bab05e46cc60cd156 100644 |
--- a/src/gpu/GrLayerCache.cpp |
+++ b/src/gpu/GrLayerCache.cpp |
@@ -27,11 +27,9 @@ |
SkASSERT(fRect.isEmpty()); |
SkASSERT(nullptr == fPlot); |
SkASSERT(!fLocked); // layers without a texture cannot be locked |
- SkASSERT(!fAtlased); // can't be atlased if it doesn't have a texture |
} |
if (fPlot) { |
- SkASSERT(fAtlased); |
// If a layer has a plot (i.e., is atlased) then it must point to |
// the backing texture. Additionally, its rect should be non-empty. |
SkASSERT(fTexture && backingTexture == fTexture); |
@@ -121,10 +119,8 @@ |
} |
fLayerHash.rewind(); |
- if (fAtlas) { |
- fAtlas->resetPlots(); |
- fAtlas->detachBackingTexture(); |
- } |
+ // The atlas only lets go of its texture when the atlas is deleted. |
+ fAtlas.free(); |
} |
GrCachedLayer* GrLayerCache::createLayer(uint32_t pictureID, |
@@ -171,7 +167,7 @@ |
bool GrLayerCache::tryToAtlas(GrCachedLayer* layer, |
const GrSurfaceDesc& desc, |
bool* needsRendering) { |
- SkDEBUGCODE(GrAutoValidateLayer avl(fAtlas ? fAtlas->getTextureOrNull() : nullptr, layer);) |
+ SkDEBUGCODE(GrAutoValidateLayer avl(fAtlas ? fAtlas->getTexture() : nullptr, layer);) |
SkASSERT(PlausiblyAtlasable(desc.fWidth, desc.fHeight)); |
SkASSERT(0 == desc.fSampleCnt); |
@@ -221,7 +217,7 @@ |
// The layer was successfully added to the atlas |
const SkIRect bounds = SkIRect::MakeXYWH(loc.fX, loc.fY, |
desc.fWidth, desc.fHeight); |
- layer->setTexture(fAtlas->getTexture(), bounds, true); |
+ layer->setTexture(fAtlas->getTexture(), bounds); |
layer->setPlot(plot); |
layer->setLocked(true); |
this->incPlotLock(layer->plot()->id()); |
@@ -231,7 +227,7 @@ |
// The layer was rejected by the atlas (even though we know it is |
// plausibly atlas-able). See if a plot can be purged and try again. |
- if (!this->purgePlots(true)) { |
+ if (!this->purgePlot()) { |
break; // We weren't able to purge any plots |
} |
} |
@@ -264,14 +260,14 @@ |
return false; |
} |
- layer->setTexture(tex, SkIRect::MakeWH(desc.fWidth, desc.fHeight), false); |
+ layer->setTexture(tex, SkIRect::MakeWH(desc.fWidth, desc.fHeight)); |
layer->setLocked(true); |
*needsRendering = true; |
return true; |
} |
void GrLayerCache::unlock(GrCachedLayer* layer) { |
- SkDEBUGCODE(GrAutoValidateLayer avl(fAtlas ? fAtlas->getTextureOrNull() : nullptr, layer);) |
+ SkDEBUGCODE(GrAutoValidateLayer avl(fAtlas ? fAtlas->getTexture() : nullptr, layer);) |
if (nullptr == layer || !layer->locked()) { |
// invalid or not locked |
@@ -303,11 +299,11 @@ |
} |
layer->setPlot(nullptr); |
- layer->setTexture(nullptr, SkIRect::MakeEmpty(), false); |
+ layer->setTexture(nullptr, SkIRect::MakeEmpty()); |
#endif |
} else { |
- layer->setTexture(nullptr, SkIRect::MakeEmpty(), false); |
+ layer->setTexture(nullptr, SkIRect::MakeEmpty()); |
} |
layer->setLocked(false); |
@@ -322,7 +318,7 @@ |
for (; !iter.done(); ++iter) { |
const GrCachedLayer* layer = &(*iter); |
- layer->validate(fAtlas.get() ? fAtlas->getTextureOrNull() : nullptr); |
+ layer->validate(fAtlas.get() ? fAtlas->getTexture() : nullptr); |
const GrPictureInfo* pictInfo = fPictureHash.find(layer->pictureID()); |
if (!pictInfo) { |
@@ -393,11 +389,10 @@ |
} |
} |
-bool GrLayerCache::purgePlots(bool justOne) { |
+bool GrLayerCache::purgePlot() { |
SkDEBUGCODE(GrAutoValidateCache avc(this);) |
SkASSERT(fAtlas); |
- bool anyPurged = false; |
GrLayerAtlas::PlotIter iter; |
GrLayerAtlas::Plot* plot; |
for (plot = fAtlas->iterInit(&iter, GrLayerAtlas::kLRUFirst_IterOrder); |
@@ -407,14 +402,11 @@ |
continue; |
} |
- anyPurged = true; |
this->purgePlot(plot); |
- if (justOne) { |
- break; |
- } |
- } |
- |
- return anyPurged; |
+ return true; |
+ } |
+ |
+ return false; |
} |
void GrLayerCache::purgePlot(GrLayerAtlas::Plot* plot) { |
@@ -463,56 +455,26 @@ |
return; |
} |
- this->purgePlots(false); // clear them all out |
+ GrLayerAtlas::PlotIter iter; |
+ GrLayerAtlas::Plot* plot; |
+ for (plot = fAtlas->iterInit(&iter, GrLayerAtlas::kLRUFirst_IterOrder); |
+ plot; |
+ plot = iter.prev()) { |
+ SkASSERT(0 == fPlotLocks[plot->id()]); |
+ |
+ this->purgePlot(plot); |
+ } |
SkASSERT(0 == fPictureHash.count()); |
- if (fAtlas->getTextureOrNull()) { |
- SkAutoTUnref<GrDrawContext> drawContext( |
- fContext->drawContext(fAtlas->getTexture()->asRenderTarget())); |
- |
- if (drawContext) { |
- drawContext->discard(); |
- } |
- } |
-} |
-#endif |
- |
-void GrLayerCache::begin() { |
- if (!fAtlas) { |
- return; |
- } |
- |
- if (!fAtlas->reattachBackingTexture()) { |
- // We weren't able to re-attach. Clear out all the atlased layers. |
- this->purgePlots(false); |
- SkASSERT(0 == fPictureHash.count()); |
- } |
-#ifdef SK_DEBUG |
- else { |
- // we've reattached - everything had better make sense |
- SkTDynamicHash<GrCachedLayer, GrCachedLayer::Key>::Iter iter(&fLayerHash); |
- for (; !iter.done(); ++iter) { |
- GrCachedLayer* layer = &(*iter); |
- |
- if (layer->isAtlased()) { |
- SkASSERT(fAtlas->getTexture() == layer->texture()); |
- } |
- } |
- } |
-#endif |
-} |
- |
-void GrLayerCache::end() { |
- if (!fAtlas) { |
- return; |
- } |
- |
- // Adding this call will clear out all the layers in the atlas |
- //this->purgePlots(false); |
- |
- fAtlas->detachBackingTexture(); |
-} |
+ SkAutoTUnref<GrDrawContext> drawContext( |
+ fContext->drawContext(fAtlas->getTexture()->asRenderTarget())); |
+ |
+ if (drawContext) { |
+ drawContext->discard(); |
+ } |
+} |
+#endif |
void GrLayerCache::processDeletedPictures() { |
SkTArray<SkPicture::DeletionMessage> deletedPictures; |
@@ -527,7 +489,7 @@ |
void GrLayerCache::writeLayersToDisk(const SkString& dirName) { |
if (fAtlas) { |
- GrTexture* atlasTexture = fAtlas->getTextureOrNull(); |
+ GrTexture* atlasTexture = fAtlas->getTexture(); |
if (nullptr != atlasTexture) { |
SkString fileName(dirName); |
fileName.append("\\atlas.png"); |