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

Side by Side Diff: src/gpu/GrLayerCache.cpp

Issue 703643002: Fix layer cache memory leak (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "GrAtlas.h" 8 #include "GrAtlas.h"
9 #include "GrGpu.h" 9 #include "GrGpu.h"
10 #include "GrLayerCache.h" 10 #include "GrLayerCache.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 GrLayerCache::~GrLayerCache() { 87 GrLayerCache::~GrLayerCache() {
88 88
89 SkTDynamicHash<GrCachedLayer, GrCachedLayer::Key>::Iter iter(&fLayerHash); 89 SkTDynamicHash<GrCachedLayer, GrCachedLayer::Key>::Iter iter(&fLayerHash);
90 for (; !iter.done(); ++iter) { 90 for (; !iter.done(); ++iter) {
91 GrCachedLayer* layer = &(*iter); 91 GrCachedLayer* layer = &(*iter);
92 SkASSERT(0 == layer->uses()); 92 SkASSERT(0 == layer->uses());
93 this->unlock(layer); 93 this->unlock(layer);
94 SkDELETE(layer); 94 SkDELETE(layer);
95 } 95 }
96 96
97 SkASSERT(0 == fPictureHash.count());
98
97 // The atlas only lets go of its texture when the atlas is deleted. 99 // The atlas only lets go of its texture when the atlas is deleted.
98 fAtlas.free(); 100 fAtlas.free();
99 } 101 }
100 102
101 void GrLayerCache::initAtlas() { 103 void GrLayerCache::initAtlas() {
102 SkASSERT(NULL == fAtlas.get()); 104 SkASSERT(NULL == fAtlas.get());
103 GR_STATIC_ASSERT(kNumPlotsX*kNumPlotsX == GrPictureInfo::kNumPlots); 105 GR_STATIC_ASSERT(kNumPlotsX*kNumPlotsX == GrPictureInfo::kNumPlots);
104 106
105 SkISize textureSize = SkISize::Make(kAtlasTextureWidth, kAtlasTextureHeight) ; 107 SkISize textureSize = SkISize::Make(kAtlasTextureWidth, kAtlasTextureHeight) ;
106 fAtlas.reset(SkNEW_ARGS(GrAtlas, (fContext->getGpu(), kSkia8888_GrPixelConfi g, 108 fAtlas.reset(SkNEW_ARGS(GrAtlas, (fContext->getGpu(), kSkia8888_GrPixelConfi g,
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 // This testing code aggressively removes the atlased layers. This 268 // This testing code aggressively removes the atlased layers. This
267 // can be used to separate the performance contribution of less 269 // can be used to separate the performance contribution of less
268 // render target pingponging from that due to the re-use of cached layer s 270 // render target pingponging from that due to the re-use of cached layer s
269 GrPictureInfo* pictInfo = fPictureHash.find(layer->pictureID()); 271 GrPictureInfo* pictInfo = fPictureHash.find(layer->pictureID());
270 SkASSERT(pictInfo); 272 SkASSERT(pictInfo);
271 273
272 pictInfo->decPlotUsage(plotID); 274 pictInfo->decPlotUsage(plotID);
273 275
274 if (0 == pictInfo->plotUsage(plotID)) { 276 if (0 == pictInfo->plotUsage(plotID)) {
275 GrAtlas::RemovePlot(&pictInfo->fPlotUsage, layer->plot()); 277 GrAtlas::RemovePlot(&pictInfo->fPlotUsage, layer->plot());
278
279 if (pictInfo->fPlotUsage.isEmpty()) {
280 fPictureHash.remove(pictInfo->fPictureID);
281 SkDELETE(pictInfo);
282 }
276 } 283 }
277 284
278 layer->setPlot(NULL); 285 layer->setPlot(NULL);
279 layer->setTexture(NULL, GrIRect16::MakeEmpty()); 286 layer->setTexture(NULL, GrIRect16::MakeEmpty());
280 #endif 287 #endif
281 288
282 } else { 289 } else {
283 layer->setTexture(NULL, GrIRect16::MakeEmpty()); 290 layer->setTexture(NULL, GrIRect16::MakeEmpty());
284 } 291 }
285 292
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 GrAtlas::PlotIter iter; 442 GrAtlas::PlotIter iter;
436 GrPlot* plot; 443 GrPlot* plot;
437 for (plot = fAtlas->iterInit(&iter, GrAtlas::kLRUFirst_IterOrder); 444 for (plot = fAtlas->iterInit(&iter, GrAtlas::kLRUFirst_IterOrder);
438 plot; 445 plot;
439 plot = iter.prev()) { 446 plot = iter.prev()) {
440 SkASSERT(0 == fPlotLocks[plot->id()]); 447 SkASSERT(0 == fPlotLocks[plot->id()]);
441 448
442 this->purgePlot(plot); 449 this->purgePlot(plot);
443 } 450 }
444 451
452 SkASSERT(0 == fPictureHash.count());
453
445 fContext->discardRenderTarget(fAtlas->getTexture()->asRenderTarget()); 454 fContext->discardRenderTarget(fAtlas->getTexture()->asRenderTarget());
446 } 455 }
447 #endif 456 #endif
448 457
449 class GrPictureDeletionListener : public SkPicture::DeletionListener { 458 class GrPictureDeletionListener : public SkPicture::DeletionListener {
450 virtual void onDeletion(uint32_t pictureID) SK_OVERRIDE{ 459 virtual void onDeletion(uint32_t pictureID) SK_OVERRIDE{
451 const GrPictureDeletedMessage message = { pictureID }; 460 const GrPictureDeletedMessage message = { pictureID };
452 SkMessageBus<GrPictureDeletedMessage>::Post(message); 461 SkMessageBus<GrPictureDeletedMessage>::Post(message);
453 } 462 }
454 }; 463 };
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 continue; 500 continue;
492 } 501 }
493 502
494 SkString fileName(dirName); 503 SkString fileName(dirName);
495 fileName.appendf("\\%d-%d.png", layer->fKey.pictureID(), layer->fKey.sta rt()); 504 fileName.appendf("\\%d-%d.png", layer->fKey.pictureID(), layer->fKey.sta rt());
496 505
497 layer->texture()->surfacePriv().savePixels(fileName.c_str()); 506 layer->texture()->surfacePriv().savePixels(fileName.c_str());
498 } 507 }
499 } 508 }
500 #endif 509 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698