Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 0bd00f4

Browse files
jvanverthSkia Commit-Bot
authored andcommitted
Reland "Clear out atlases if they haven't been used in a while."
This is a reland of 79007c9 Original change's description: > Clear out atlases if they haven't been used in a while. > > This will stage out atlas pages one at a time with an interval of > 256 flushes between them. Also removes the last page to help > conserve memory if text or other atlas-using systems are not in use. > > Bug: 1058905 > Change-Id: I8717621033068d0e24da944356d91b0f35e5373b > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/276764 > Commit-Queue: Jim Van Verth <[email protected]> > Reviewed-by: Herb Derby <[email protected]> Bug: 1058905 Change-Id: I25b0037cb1608ae0bda641e0d0588afaf3dd47e5 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/276960 Reviewed-by: Jim Van Verth <[email protected]> Commit-Queue: Jim Van Verth <[email protected]>
1 parent 2cdad96 commit 0bd00f4

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/gpu/GrDrawOpAtlas.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ GrDrawOpAtlas::GrDrawOpAtlas(
221221
, fGenerationCounter(generationCounter)
222222
, fAtlasGeneration(fGenerationCounter->next())
223223
, fPrevFlushToken(GrDeferredUploadToken::AlreadyFlushedToken())
224+
, fFlushesSinceLastUse(0)
224225
, fMaxPages(AllowMultitexturing::kYes == allowMultitexturing ? kMaxMultitexturePages : 1)
225226
, fNumActivePages(0) {
226227
int numPlotsX = width/plotWidth;
@@ -407,11 +408,13 @@ GrDrawOpAtlas::ErrorCode GrDrawOpAtlas::addToAtlas(GrResourceProvider* resourceP
407408
}
408409

409410
void GrDrawOpAtlas::compact(GrDeferredUploadToken startTokenForNextFlush) {
410-
if (fNumActivePages <= 1) {
411+
if (fNumActivePages < 1) {
411412
fPrevFlushToken = startTokenForNextFlush;
412413
return;
413414
}
414415

416+
++fFlushesSinceLastUse;
417+
415418
// For all plots, reset number of flushes since used if used this frame.
416419
PlotList::Iter plotIter;
417420
bool atlasUsedThisFlush = false;
@@ -428,11 +431,11 @@ void GrDrawOpAtlas::compact(GrDeferredUploadToken startTokenForNextFlush) {
428431
}
429432
}
430433

431-
// We only try to compact if the atlas was used in the recently completed flush.
434+
// We only try to compact if the atlas was used in the recently completed flush or
435+
// hasn't been used in a long time.
432436
// This is to handle the case where a lot of text or path rendering has occurred but then just
433437
// a blinking cursor is drawn.
434-
// TODO: consider if we should also do this if it's been a long time since the last atlas use
435-
if (atlasUsedThisFlush) {
438+
if (atlasUsedThisFlush || fFlushesSinceLastUse > kRecentlyUsedCount) {
436439
SkTArray<Plot*> availablePlots;
437440
uint32_t lastPageIndex = fNumActivePages - 1;
438441

@@ -537,14 +540,16 @@ void GrDrawOpAtlas::compact(GrDeferredUploadToken startTokenForNextFlush) {
537540
}
538541

539542
// If none of the plots in the last page have been used recently, delete it.
540-
if (!usedPlots) {
543+
if (!usedPlots || fFlushesSinceLastUse > kRecentlyUsedCount) {
541544
#ifdef DUMP_ATLAS_DATA
542545
if (gDumpAtlasData) {
543-
SkDebugf("delete %d\n", fNumPages-1);
546+
SkDebugf("delete %d\n", fNumActivePages-1);
544547
}
545548
#endif
546549
this->deactivateLastPage();
547550
}
551+
552+
fFlushesSinceLastUse = 0;
548553
}
549554

550555
fPrevFlushToken = startTokenForNextFlush;

src/gpu/GrDrawOpAtlas.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,9 @@ class GrDrawOpAtlas {
435435
// nextTokenToFlush() value at the end of the previous flush
436436
GrDeferredUploadToken fPrevFlushToken;
437437

438+
// the number of flushes since this atlas has been last used
439+
int fFlushesSinceLastUse;
440+
438441
std::vector<EvictionCallback*> fEvictionCallbacks;
439442

440443
struct Page {

0 commit comments

Comments
 (0)