add benchType deserial to time deserializing pictures

Piece of the larger effort to merge readbuffer and validatingreadbuffer

Bug: skia:
Change-Id: I79305e27c4712c3b91d213d09d6c2ef24b86e671
Reviewed-on: https://skia-review.googlesource.com/81120
Commit-Queue: Mike Reed <reed@google.com>
Commit-Queue: Mike Klein <mtklein@chromium.org>
Reviewed-by: Mike Klein <mtklein@chromium.org>
diff --git a/bench/RecordingBench.cpp b/bench/RecordingBench.cpp
index c8142ee..dc82655 100644
--- a/bench/RecordingBench.cpp
+++ b/bench/RecordingBench.cpp
@@ -85,3 +85,30 @@
         stream.reset();
     }
 }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+#include "SkSerialProcs.h"
+
+DeserializePictureBench::DeserializePictureBench(const char* name, sk_sp<SkData> data)
+    : fName(name)
+    , fEncodedPicture(std::move(data))
+{}
+
+const char* DeserializePictureBench::onGetName() {
+    return fName.c_str();
+}
+
+bool DeserializePictureBench::isSuitableFor(Backend backend) {
+    return backend == kNonRendering_Backend;
+}
+
+SkIPoint DeserializePictureBench::onGetSize() {
+    return SkIPoint::Make(128, 128);
+}
+
+void DeserializePictureBench::onDraw(int loops, SkCanvas*) {
+    SkDeserialProcs procs;
+    for (int i = 0; i < loops; ++i) {
+        SkPicture::MakeFromData(fEncodedPicture, procs);
+    }
+}
diff --git a/bench/RecordingBench.h b/bench/RecordingBench.h
index beaea3e..751223d 100644
--- a/bench/RecordingBench.h
+++ b/bench/RecordingBench.h
@@ -53,4 +53,21 @@
     typedef PictureCentricBench INHERITED;
 };
 
+class DeserializePictureBench : public Benchmark {
+public:
+    DeserializePictureBench(const char* name, sk_sp<SkData> encodedPicture);
+
+protected:
+    const char* onGetName() override;
+    bool isSuitableFor(Backend) override;
+    SkIPoint onGetSize() override;
+    void onDraw(int loops, SkCanvas*) override;
+
+private:
+    SkString      fName;
+    sk_sp<SkData> fEncodedPicture;
+
+    typedef Benchmark INHERITED;
+};
+
 #endif//RecordingBench_DEFINED
diff --git a/bench/nanobench.cpp b/bench/nanobench.cpp
index 550e0b7..d475e16 100644
--- a/bench/nanobench.cpp
+++ b/bench/nanobench.cpp
@@ -607,6 +607,7 @@
                       , fGMs(skiagm::GMRegistry::Head())
                       , fCurrentRecording(0)
                       , fCurrentPiping(0)
+                      , fCurrentDeserialPicture(0)
                       , fCurrentScale(0)
                       , fCurrentSKP(0)
                       , fCurrentSVG(0)
@@ -765,6 +766,21 @@
             return new PipingBench(name.c_str(), pic.get());
         }
 
+        // Add all .skps as DeserializePictureBenchs.
+        while (fCurrentDeserialPicture < fSKPs.count()) {
+            const SkString& path = fSKPs[fCurrentDeserialPicture++];
+            sk_sp<SkData> data = SkData::MakeFromFileName(path.c_str());
+            if (!data) {
+                continue;
+            }
+            SkString name = SkOSPath::Basename(path.c_str());
+            fSourceType = "skp";
+            fBenchType  = "deserial";
+            fSKPBytes = static_cast<double>(data->size());
+            fSKPOps   = 0;
+            return new DeserializePictureBench(name.c_str(), std::move(data));
+        }
+
         // Then once each for each scale as SKPBenches (playback).
         while (fCurrentScale < fScales.count()) {
             while (fCurrentSKP < fSKPs.count()) {
@@ -1091,6 +1107,7 @@
     const char* fBenchType;   // How we bench it: micro, recording, playback, ...
     int fCurrentRecording;
     int fCurrentPiping;
+    int fCurrentDeserialPicture;
     int fCurrentScale;
     int fCurrentSKP;
     int fCurrentSVG;