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

Unified Diff: src/gpu/GrLayerCache.cpp

Issue 678403002: Discard atlas after every MultiPictureDraw::draw (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix rebase error 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.h » ('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 d897c9dea55a558a646e94b35684280834bce351..a24c9e040b70bb7ecd3581e48cd9dacc4cd4c617 100644
--- a/src/gpu/GrLayerCache.cpp
+++ b/src/gpu/GrLayerCache.cpp
@@ -81,7 +81,6 @@ private:
GrLayerCache::GrLayerCache(GrContext* context)
: fContext(context) {
- this->initAtlas();
memset(fPlotLocks, 0, sizeof(fPlotLocks));
}
@@ -120,11 +119,6 @@ void GrLayerCache::freeAll() {
// The atlas only lets go of its texture when the atlas is deleted.
fAtlas.free();
- // GrLayerCache always assumes an atlas exists so recreate it. The atlas
- // lazily allocates a replacement texture so reallocating a new
- // atlas here won't disrupt a GrContext::abandonContext or freeGpuResources.
- // TODO: Make GrLayerCache lazily allocate the atlas manager?
- this->initAtlas();
}
GrCachedLayer* GrLayerCache::createLayer(uint32_t pictureID,
@@ -164,12 +158,13 @@ GrCachedLayer* GrLayerCache::findLayerOrCreate(uint32_t pictureID,
bool GrLayerCache::tryToAtlas(GrCachedLayer* layer,
const GrSurfaceDesc& desc,
bool* needsRendering) {
- SkDEBUGCODE(GrAutoValidateLayer avl(fAtlas->getTexture(), layer);)
+ SkDEBUGCODE(GrAutoValidateLayer avl(fAtlas ? fAtlas->getTexture() : NULL, layer);)
SkASSERT(PlausiblyAtlasable(desc.fWidth, desc.fHeight));
if (layer->locked()) {
// This layer is already locked
+ SkASSERT(fAtlas);
SkASSERT(layer->isAtlased());
SkASSERT(layer->rect().width() == desc.fWidth);
SkASSERT(layer->rect().height() == desc.fHeight);
@@ -178,12 +173,19 @@ bool GrLayerCache::tryToAtlas(GrCachedLayer* layer,
}
if (layer->isAtlased()) {
+ SkASSERT(fAtlas);
// Hooray it is still in the atlas - make sure it stays there
layer->setLocked(true);
this->incPlotLock(layer->plot()->id());
*needsRendering = false;
return true;
} else {
+ if (!fAtlas) {
+ this->initAtlas();
+ if (!fAtlas) {
+ return false;
+ }
+ }
// Not in the atlas - will it fit?
GrPictureInfo* pictInfo = fPictureHash.find(layer->pictureID());
if (NULL == pictInfo) {
@@ -243,7 +245,7 @@ bool GrLayerCache::lock(GrCachedLayer* layer, const GrSurfaceDesc& desc, bool* n
}
void GrLayerCache::unlock(GrCachedLayer* layer) {
- SkDEBUGCODE(GrAutoValidateLayer avl(fAtlas->getTexture(), layer);)
+ SkDEBUGCODE(GrAutoValidateLayer avl(fAtlas ? fAtlas->getTexture() : NULL, layer);)
if (NULL == layer || !layer->locked()) {
// invalid or not locked
@@ -256,7 +258,7 @@ void GrLayerCache::unlock(GrCachedLayer* layer) {
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
+#if !GR_CACHE_HOISTED_LAYERS
// This testing code aggressively removes the atlased layers. This
// can be used to separate the performance contribution of less
// render target pingponging from that due to the re-use of cached layers
@@ -285,7 +287,7 @@ void GrLayerCache::validate() const {
for (; !iter.done(); ++iter) {
const GrCachedLayer* layer = &(*iter);
- layer->validate(fAtlas->getTexture());
+ layer->validate(fAtlas.get() ? fAtlas->getTexture() : NULL);
const GrPictureInfo* pictInfo = fPictureHash.find(layer->pictureID());
if (!pictInfo) {
@@ -355,6 +357,7 @@ void GrLayerCache::purge(uint32_t pictureID) {
bool GrLayerCache::purgePlot() {
SkDEBUGCODE(GrAutoValidateCache avc(this);)
+ SkASSERT(fAtlas);
GrAtlas::PlotIter iter;
GrPlot* plot;
@@ -409,7 +412,12 @@ void GrLayerCache::purgePlot(GrPlot* plot) {
plot->resetRects();
}
+#if !GR_CACHE_HOISTED_LAYERS
void GrLayerCache::purgeAll() {
+ if (!fAtlas) {
+ return;
+ }
+
GrAtlas::PlotIter iter;
GrPlot* plot;
for (plot = fAtlas->iterInit(&iter, GrAtlas::kLRUFirst_IterOrder);
@@ -419,7 +427,10 @@ void GrLayerCache::purgeAll() {
this->purgePlot(plot);
}
+
+ fContext->discardRenderTarget(fAtlas->getTexture()->asRenderTarget());
}
+#endif
class GrPictureDeletionListener : public SkPicture::DeletionListener {
virtual void onDeletion(uint32_t pictureID) SK_OVERRIDE{
@@ -448,12 +459,14 @@ void GrLayerCache::processDeletedPictures() {
#ifdef SK_DEVELOPER
void GrLayerCache::writeLayersToDisk(const SkString& dirName) {
- GrTexture* atlasTexture = fAtlas->getTexture();
- if (NULL != atlasTexture) {
- SkString fileName(dirName);
- fileName.append("\\atlas.png");
+ if (fAtlas) {
+ GrTexture* atlasTexture = fAtlas->getTexture();
+ if (NULL != atlasTexture) {
+ SkString fileName(dirName);
+ fileName.append("\\atlas.png");
- atlasTexture->surfacePriv().savePixels(fileName.c_str());
+ atlasTexture->surfacePriv().savePixels(fileName.c_str());
+ }
}
SkTDynamicHash<GrCachedLayer, GrCachedLayer::Key>::Iter iter(&fLayerHash);
« no previous file with comments | « src/gpu/GrLayerCache.h ('k') | src/gpu/GrLayerHoister.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698