Adds gpu stats for program cache

With the addition of the DDL program pre-compilation we need to know how it is working.

This CL also fixes some threading bugs.

Bug: skia:9455
Change-Id: I20da58a7f1b19685687fae1d159d4e0db8a4964d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/273001
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
diff --git a/tools/DDLTileHelper.cpp b/tools/DDLTileHelper.cpp
index 913f2e7..45ca86d 100644
--- a/tools/DDLTileHelper.cpp
+++ b/tools/DDLTileHelper.cpp
@@ -18,14 +18,15 @@
 #include "src/image/SkImage_Gpu.h"
 #include "tools/DDLPromiseImageHelper.h"
 
-void DDLTileHelper::TileData::init(int id, sk_sp<SkSurface> dstSurface, const SkIRect& clip) {
+void DDLTileHelper::TileData::init(int id,
+                                   sk_sp<SkSurface> dstSurface,
+                                   const SkSurfaceCharacterization& dstSurfaceCharacterization,
+                                   const SkIRect& clip) {
     fID = id;
     fDstSurface = dstSurface;
     fClip = clip;
 
-    SkSurfaceCharacterization tmp;
-    SkAssertResult(fDstSurface->characterize(&tmp));
-    fCharacterization = tmp.createResized(clip.width(), clip.height());
+    fCharacterization = dstSurfaceCharacterization.createResized(clip.width(), clip.height());
     SkASSERT(fCharacterization.isValid());
 }
 
@@ -115,6 +116,7 @@
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
 DDLTileHelper::DDLTileHelper(sk_sp<SkSurface> dstSurface,
+                             const SkSurfaceCharacterization& dstChar,
                              const SkIRect& viewport,
                              int numDivisions)
         : fNumDivisions(numDivisions) {
@@ -135,7 +137,7 @@
 
             SkASSERT(viewport.contains(clip));
 
-            fTiles[y*fNumDivisions+x].init(y*fNumDivisions+x, dstSurface, clip);
+            fTiles[y*fNumDivisions+x].init(y*fNumDivisions+x, dstSurface, dstChar, clip);
         }
     }
 }