add mutex to GrTextBlobCache

This should be the bulk of the work. The next part is getting it to live
in a common place, and wiring up the callbacks properly.

The callback points are fPurgeMore and fMessageBusID.

Change-Id: Ibabe285ace8a0b6531572b755a6c4f7bd41b1f6c
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/298400
Commit-Queue: Herb Derby <herb@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
diff --git a/src/gpu/text/GrTextBlobCache.cpp b/src/gpu/text/GrTextBlobCache.cpp
index f981b59..8a329c4 100644
--- a/src/gpu/text/GrTextBlobCache.cpp
+++ b/src/gpu/text/GrTextBlobCache.cpp
@@ -27,17 +27,20 @@
                                 const SkMatrix& viewMatrix) {
     sk_sp<GrTextBlob> cacheBlob(GrTextBlob::Make(glyphRunList, viewMatrix));
     cacheBlob->setupKey(key, blurRec, glyphRunList.paint());
+    SkAutoMutexExclusive lock{fMutex};
     this->internalAdd(cacheBlob);
     glyphRunList.temporaryShuntBlobNotifyAddedToCache(fMessageBusID);
     return cacheBlob;
 }
 
 sk_sp<GrTextBlob> GrTextBlobCache::find(const GrTextBlob::Key& key) const {
+    SkAutoMutexExclusive lock{fMutex};
     const auto* idEntry = fBlobIDCache.find(key.fUniqueID);
     return idEntry ? idEntry->find(key) : nullptr;
 }
 
 void GrTextBlobCache::remove(GrTextBlob* blob) {
+    SkAutoMutexExclusive lock{fMutex};
     this->internalRemove(blob);
 }
 
@@ -55,6 +58,7 @@
 }
 
 void GrTextBlobCache::makeMRU(GrTextBlob* blob) {
+    SkAutoMutexExclusive lock{fMutex};
     if (fBlobList.head() == blob) {
         return;
     }
@@ -64,12 +68,14 @@
 }
 
 void GrTextBlobCache::freeAll() {
+    SkAutoMutexExclusive lock{fMutex};
     fBlobIDCache.reset();
     fBlobList.reset();
     fCurrentSize = 0;
 }
 
 void GrTextBlobCache::setBudget(size_t budget) {
+    SkAutoMutexExclusive lock{fMutex};
     fSizeBudget = budget;
     this->internalCheckPurge();
 }
@@ -80,6 +86,7 @@
 }
 
 void GrTextBlobCache::purgeStaleBlobs() {
+    SkAutoMutexExclusive lock{fMutex};
     this->internalPurgeStaleBlobs();
 }
 
@@ -106,6 +113,7 @@
 }
 
 size_t GrTextBlobCache::usedBytes() const {
+    SkAutoMutexExclusive lock{fMutex};
     return fCurrentSize;
 }