diff options
author | Jim Van Verth <jvanverth@google.com> | 2018-02-20 11:30:10 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-02-20 16:57:08 +0000 |
commit | 06f593cd139b335956b2845b03581f72c0feb595 (patch) | |
tree | d4901bd651ba76e6961b2b5d6b17c08f163d0688 /src/gpu/GrDrawOpAtlas.cpp | |
parent | 5ab827c50b6f1e62a6346070841651278300138f (diff) |
Some more cleanup of GrDrawOpAtlas compaction
Change-Id: Ica00285d0071a31a09dc87d68d7ae7dfabab17b7
Reviewed-on: https://skia-review.googlesource.com/108522
Commit-Queue: Jim Van Verth <jvanverth@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'src/gpu/GrDrawOpAtlas.cpp')
-rw-r--r-- | src/gpu/GrDrawOpAtlas.cpp | 43 |
1 files changed, 31 insertions, 12 deletions
diff --git a/src/gpu/GrDrawOpAtlas.cpp b/src/gpu/GrDrawOpAtlas.cpp index 0f18325817..f39c001a25 100644 --- a/src/gpu/GrDrawOpAtlas.cpp +++ b/src/gpu/GrDrawOpAtlas.cpp @@ -181,7 +181,7 @@ GrDrawOpAtlas::GrDrawOpAtlas(GrContext* context, GrPixelConfig config, int width SkASSERT(fPlotWidth * numPlotsX == fTextureWidth); SkASSERT(fPlotHeight * numPlotsY == fTextureHeight); - SkDEBUGCODE(fNumPlots = numPlotsX * numPlotsY;) + fNumPlots = numPlotsX * numPlotsY; this->createNewPage(); } @@ -412,11 +412,11 @@ void GrDrawOpAtlas::compact(GrDeferredUploadToken startTokenForNextFlush) { #endif } - // Count recently used plots in the last page and evict them if there's available space - // in earlier pages. Since we prioritize uploading to the first pages, this will eventually + // Count recently used plots in the last page and evict any that are no longer in use. + // Since we prioritize uploading to the first pages, this will eventually // clear out usage of this page unless we have a large need. plotIter.init(fPages[lastPageIndex].fPlotList, PlotList::Iter::kHead_IterStart); - int usedPlots = 0; + unsigned int usedPlots = 0; #ifdef DUMP_ATLAS_DATA if (gDumpAtlasData) { SkDebugf("page %d: ", lastPageIndex); @@ -436,14 +436,6 @@ void GrDrawOpAtlas::compact(GrDeferredUploadToken startTokenForNextFlush) { // If this plot was used recently if (plot->flushesSinceLastUsed() <= kRecentlyUsedCount) { usedPlots++; - // see if there's room in an earlier page and if so evict. - // We need to be somewhat harsh here so that one plot that is consistently in use - // doesn't end up locking the page in memory. - if (availablePlots.count() > 0) { - this->processEvictionAndResetRects(plot); - this->processEvictionAndResetRects(availablePlots.back()); - availablePlots.pop_back(); - } } else if (plot->lastUseToken() != GrDeferredUploadToken::AlreadyFlushedToken()) { // otherwise if aged out just evict it. this->processEvictionAndResetRects(plot); @@ -455,6 +447,33 @@ void GrDrawOpAtlas::compact(GrDeferredUploadToken startTokenForNextFlush) { SkDebugf("\n"); } #endif + + // If recently used plots in the last page are using less than a quarter of the page, try + // to evict them if there's available space in earlier pages. Since we prioritize uploading + // to the first pages, this will eventually clear out usage of this page unless we have a + // large need. + if (availablePlots.count() && usedPlots && usedPlots <= fNumPlots / 4) { + plotIter.init(fPages[lastPageIndex].fPlotList, PlotList::Iter::kHead_IterStart); + while (Plot* plot = plotIter.get()) { + // If this plot was used recently + if (plot->flushesSinceLastUsed() <= kRecentlyUsedCount) { + // See if there's room in an earlier page and if so evict. + // We need to be somewhat harsh here so that a handful of plots that are + // consistently in use don't end up locking the page in memory. + if (availablePlots.count() > 0) { + this->processEvictionAndResetRects(plot); + this->processEvictionAndResetRects(availablePlots.back()); + availablePlots.pop_back(); + --usedPlots; + } + if (!usedPlots || !availablePlots.count()) { + break; + } + } + plotIter.next(); + } + } + // If none of the plots in the last page have been used recently, delete it. if (!usedPlots) { #ifdef DUMP_ATLAS_DATA |