Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(244)

Unified Diff: src/gpu/GrLayerCache.cpp

Issue 640323002: Fix bug in GrCachedLayer reuse (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Improve comment Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/GrLayerCache.h ('k') | src/gpu/GrLayerHoister.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrLayerCache.cpp
diff --git a/src/gpu/GrLayerCache.cpp b/src/gpu/GrLayerCache.cpp
index 0481d144e585aa45758bfaa347446befbd2030dc..570b2d6eafef15a8558532aa2f785f869786d463 100644
--- a/src/gpu/GrLayerCache.cpp
+++ b/src/gpu/GrLayerCache.cpp
@@ -16,7 +16,6 @@ void GrCachedLayer::validate(const GrTexture* backingTexture) const {
SkASSERT(SK_InvalidGenID != fKey.pictureID());
SkASSERT(fKey.start() >= 0);
-
if (fTexture) {
// If the layer is in some texture then it must occupy some rectangle
SkASSERT(!fRect.isEmpty());
@@ -43,6 +42,15 @@ void GrCachedLayer::validate(const GrTexture* backingTexture) const {
SkASSERT(fTexture);
SkASSERT(!fRect.isEmpty());
}
+
+ // Unfortunately there is a brief time where a layer can be locked
+ // but not used, so we can only check the "used implies locked"
+ // invariant.
+ if (fUses > 0) {
+ SkASSERT(fLocked);
+ } else {
+ SkASSERT(0 == fUses);
+ }
}
class GrAutoValidateLayer : ::SkNoncopyable {
@@ -81,6 +89,7 @@ GrLayerCache::~GrLayerCache() {
SkTDynamicHash<GrCachedLayer, GrCachedLayer::Key>::Iter iter(&fLayerHash);
for (; !iter.done(); ++iter) {
GrCachedLayer* layer = &(*iter);
+ SkASSERT(0 == layer->uses());
this->unlock(layer);
SkDELETE(layer);
}
@@ -168,7 +177,7 @@ bool GrLayerCache::lock(GrCachedLayer* layer, const GrTextureDesc& desc, bool do
// Hooray it is still in the atlas - make sure it stays there
SkASSERT(!dontAtlas);
layer->setLocked(true);
- fPlotLocks[layer->plot()->id()]++;
+ this->incPlotLock(layer->plot()->id());
return false;
} else if (!dontAtlas && PlausiblyAtlasable(desc.fWidth, desc.fHeight)) {
// Not in the atlas - will it fit?
@@ -193,7 +202,7 @@ bool GrLayerCache::lock(GrCachedLayer* layer, const GrTextureDesc& desc, bool do
layer->setTexture(fAtlas->getTexture(), bounds);
layer->setPlot(plot);
layer->setLocked(true);
- fPlotLocks[layer->plot()->id()]++;
+ this->incPlotLock(layer->plot()->id());
return true;
}
@@ -227,8 +236,7 @@ void GrLayerCache::unlock(GrCachedLayer* layer) {
if (layer->isAtlased()) {
const int plotID = layer->plot()->id();
- SkASSERT(fPlotLocks[plotID] > 0);
- fPlotLocks[plotID]--;
+ this->decPlotLock(plotID);
// At this point we could aggressively clear out un-locked plots but
// by delaying we may be able to reuse some of the atlased layers later.
#if DISABLE_CACHING
@@ -270,7 +278,7 @@ void GrLayerCache::validate() const {
SkASSERT(!pictInfo->fPlotUsage.isEmpty());
#endif
} else {
- // If there is no picture info for this layer then all of its
+ // If there is no picture info for this picture then all of its
// layers should be non-atlased.
SkASSERT(!layer->isAtlased());
}
@@ -321,6 +329,7 @@ void GrLayerCache::purge(uint32_t pictureID) {
}
for (int i = 0; i < toBeRemoved.count(); ++i) {
+ SkASSERT(0 == toBeRemoved[i]->uses());
this->unlock(toBeRemoved[i]);
fLayerHash.remove(GrCachedLayer::GetKey(*toBeRemoved[i]));
SkDELETE(toBeRemoved[i]);
@@ -366,6 +375,7 @@ void GrLayerCache::purgePlot(GrPlot* plot) {
}
for (int i = 0; i < toBeRemoved.count(); ++i) {
+ SkASSERT(0 == toBeRemoved[i]->uses());
SkASSERT(!toBeRemoved[i]->locked());
uint32_t pictureIDToRemove = toBeRemoved[i]->pictureID();
« no previous file with comments | « src/gpu/GrLayerCache.h ('k') | src/gpu/GrLayerHoister.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698