Update GrTextBlobCache for DDL

Although, theoretically, we could update the DDLs to maintain pointers to the GrMemoryPools being used by their GrAtlasTextBlobs this method seems simpler.

Change-Id: I4835284630b9cd29eb78cf25bcdfe5c56974a8cb
Reviewed-on: https://skia-review.googlesource.com/107345
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Jim Van Verth <jvanverth@google.com>
diff --git a/src/gpu/text/GrTextBlobCache.cpp b/src/gpu/text/GrTextBlobCache.cpp
index 64941ef..88cbaeb 100644
--- a/src/gpu/text/GrTextBlobCache.cpp
+++ b/src/gpu/text/GrTextBlobCache.cpp
@@ -10,7 +10,8 @@
 DECLARE_SKMESSAGEBUS_MESSAGE(GrTextBlobCache::PurgeBlobMessage)
 
 GrTextBlobCache::~GrTextBlobCache() {
-    SkDEBUGCODE(this->freeAll();)
+    this->freeAll();
+    delete fPool;
 }
 
 void GrTextBlobCache::freeAll() {
@@ -23,7 +24,7 @@
     fBlobIDCache.reset();
 
     // There should be no allocations in the memory pool at this point
-    SkASSERT(fPool.isEmpty());
+    SkASSERT(!fPool || fPool->isEmpty());
     SkASSERT(fBlobList.isEmpty());
 }
 
@@ -53,16 +54,26 @@
     }
 }
 
+bool GrTextBlobCache::overBudget() const {
+    if (fPool) {
+        return fPool->size() > fBudget;
+    }
+
+    // When DDLs are being recorded no GrAtlasTextBlob will be deleted so the cache budget is
+    // somewhat meaningless.
+    return false;
+}
+
 void GrTextBlobCache::checkPurge(GrAtlasTextBlob* blob) {
     // First, purge all stale blob IDs.
     this->purgeStaleBlobs();
 
     // If we are still over budget, then unref until we are below budget again
-    if (fPool.size() > fBudget) {
+    if (this->overBudget()) {
         BitmapBlobList::Iter iter;
         iter.init(fBlobList, BitmapBlobList::Iter::kTail_IterStart);
         GrAtlasTextBlob* lruBlob = nullptr;
-        while (fPool.size() > fBudget && (lruBlob = iter.get()) && lruBlob != blob) {
+        while (this->overBudget() && (lruBlob = iter.get()) && lruBlob != blob) {
             // Backup the iterator before removing and unrefing the blob
             iter.prev();
 
@@ -77,7 +88,7 @@
         }
 
 #ifdef SPEW_BUDGET_MESSAGE
-        if (fPool.size() > fBudget) {
+        if (this->overBudget()) {
             SkDebugf("Single textblob is larger than our whole budget");
         }
 #endif