Fix DDL reattachment of uniquely keyed proxies

This fix has three parts:
   No longer clear all proxy unique keys in DDL mode
   Handle unique keys appropriately in lazy proxy instantiation
   Handle attaching to cached surfaces for non-lazy proxies

Change-Id: I86b0422a784acaf8c5f9b67cb981b440e08352de
Reviewed-on: https://skia-review.googlesource.com/154502
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
diff --git a/src/gpu/GrTextureProxy.cpp b/src/gpu/GrTextureProxy.cpp
index 88b00e9..a65f241 100644
--- a/src/gpu/GrTextureProxy.cpp
+++ b/src/gpu/GrTextureProxy.cpp
@@ -66,7 +66,11 @@
     // Due to the order of cleanup the GrSurface this proxy may have wrapped may have gone away
     // at this point. Zero out the pointer so the cache invalidation code doesn't try to use it.
     fTarget = nullptr;
-    if (fUniqueKey.isValid()) {
+
+    // In DDL-mode, uniquely keyed proxies keep their key even after their originating
+    // proxy provider has gone away. In that case there is noone to send the invalid key
+    // message to (Note: in this case we don't want to remove its cached resource).
+    if (fUniqueKey.isValid() && fProxyProvider) {
         fProxyProvider->processInvalidProxyUniqueKey(fUniqueKey, this, false);
     } else {
         SkASSERT(!fProxyProvider);