Work around un-safe downcast in PromiseLazyInstantiateCallback destructor after a context abandon

90% of this CL is just renaming. The only two substantive changes are:
   holding a GrTexture* (rather than a GrGpuResource*) in the GrTextureFreedMessage (this avoids the downcast)
   adding the abandoned() checks to the two GrContext::purgeUnlockedResources methods (this prevents accesses of the message queue)

Bug: 1011368, 1014993
Change-Id: Ifff3842f7802add6b7cd34595578369543698ba1
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/249001
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
diff --git a/src/image/SkImage_GpuBase.cpp b/src/image/SkImage_GpuBase.cpp
index 7d906f0..58d0eb8 100644
--- a/src/image/SkImage_GpuBase.cpp
+++ b/src/image/SkImage_GpuBase.cpp
@@ -395,8 +395,15 @@
 
         ~PromiseLazyInstantiateCallback() {
             // Our destructor can run on any thread. We trigger the unref of fTexture by message.
+            // This unreffed texture pointer is a real problem! When the context has been
+            // abandoned, the GrTexture pointed to by this pointer is deleted! Due to virtual
+            // inheritance any manipulation of this pointer at that point will cause a crash.
+            // For now we "work around" the problem by just passing it, untouched, into the
+            // message bus but this very fragile.
+            // In the future the GrSurface class hierarchy refactoring should eliminate this
+            // difficulty by removing the virtual inheritance.
             if (fTexture) {
-                SkMessageBus<GrGpuResourceFreedMessage>::Post({fTexture, fTextureContextID});
+                SkMessageBus<GrTextureFreedMessage>::Post({fTexture, fTextureContextID});
             }
         }
 
@@ -471,7 +478,7 @@
             // let the cache know it is waiting on an unref message. We will send that message from
             // our destructor.
             GrContext* context = fTexture->getContext();
-            context->priv().getResourceCache()->insertDelayedResourceUnref(fTexture);
+            context->priv().getResourceCache()->insertDelayedTextureUnref(fTexture);
             fTextureContextID = context->priv().contextID();
             return {std::move(tex), kReleaseCallbackOnInstantiation, kKeySyncMode};
         }