SkQP: refatctor C++ bits.

  * C++ code moved into tools/skqp/src/.
  * State held with single SkQP class.
  * gmkb functions moved to skqp_model.{h,cpp}
  * model no longer knows about report format.
  * skqp_main and skqp_lib no longer have globals
  * jni code has fewer globals.
  * skqp_main no longer uses googletest.
  * AssetMng returns SkData, not a SkStream.
  * Add jitter tool.
  * dump GPU information into grdump.txt
  * JUnit puts report in directory with timestamp.
  * Document SkQP Render Test Algorithm.
  * GPU driver correctness workarounds always off
  * cut_release tool for assembling models
  * make_rendertests_list.py to help cut_release
  * make_gmkb.go emits a list of models

CQ_INCLUDE_TRYBOTS=skia.primary:Build-Debian9-Clang-x86-devrel-Android_SKQP

Change-Id: I7d4f0c24592b1f64be0088578a3f1a0bc366dd4d
Reviewed-on: https://skia-review.googlesource.com/c/110420
Reviewed-by: Hal Canary <halcanary@google.com>
Commit-Queue: Hal Canary <halcanary@google.com>
diff --git a/tools/skqp/src/skqp.h b/tools/skqp/src/skqp.h
new file mode 100644
index 0000000..c26928e
--- /dev/null
+++ b/tools/skqp/src/skqp.h
@@ -0,0 +1,122 @@
+/*
+ * Copyright 2018 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef skqp_DEFINED
+#define skqp_DEFINED
+
+#include <cstdint>
+#include <memory>
+#include <string>
+#include <tuple>
+#include <unordered_set>
+#include <unordered_map>
+#include <vector>
+
+class SkData;
+template <typename T> class sk_sp;
+
+namespace skiagm {
+class GM;
+}
+
+namespace skiatest {
+struct Test;
+}
+
+class SkStreamAsset;
+
+////////////////////////////////////////////////////////////////////////////////
+class SkQPAssetManager {
+public:
+    SkQPAssetManager() {}
+    virtual ~SkQPAssetManager() {}
+    virtual sk_sp<SkData> open(const char* path) = 0;
+private:
+    SkQPAssetManager(const SkQPAssetManager&) = delete;
+    SkQPAssetManager& operator=(const SkQPAssetManager&) = delete;
+};
+
+class SkQP {
+public:
+    enum class SkiaBackend {
+        kGL,
+        kGLES,
+        kVulkan,
+    };
+    using GMFactory = skiagm::GM* (*)(void*);
+    using UnitTest = const skiatest::Test*;
+
+    ////////////////////////////////////////////////////////////////////////////
+
+    /** These functions provide a descriptive name for the given value.*/
+    static std::string GetGMName(GMFactory);
+    static const char* GetUnitTestName(UnitTest);
+    static const char* GetBackendName(SkiaBackend);
+
+    SkQP();
+    ~SkQP();
+
+    /**
+        Initialize Skia and the SkQP.  Should be executed only once.
+
+        @param assetManager - provides assets for the models.  Does not take ownership.
+        @param reportDirectory - where to write out report.
+    */
+    void init(SkQPAssetManager* assetManager, const char* reportDirectory);
+
+    struct RenderOutcome {
+        // All three values will be 0 if the test passes.
+        int fMaxError = 0;        // maximum error of all pixel.
+        int fBadPixelCount = 0;   // number of pixels with non-zero error.
+        int64_t fTotalError = 0;  // sum of error for all bad pixels.
+    };
+
+    /**
+        @return render outcome and error string.  Only errors running or
+                evaluating the GM will result in a non-empty error string.
+    */
+    std::tuple<RenderOutcome, std::string> evaluateGM(SkiaBackend, GMFactory);
+
+    /** @return a (hopefully empty) list of errors produced by this unit test.  */
+    std::vector<std::string> executeTest(UnitTest);
+
+    /** Call this after running all checks to write a report into the given
+        report directory. */
+    void makeReport();
+
+    /** @return a list of backends that this version of SkQP supports.  */
+    const std::vector<SkiaBackend>& getSupportedBackends() const { return fSupportedBackends; }
+    /** @return a list of all Skia GMs in lexicographic order.  */
+    const std::vector<GMFactory>& getGMs() const { return fGMs; }
+    /** @return a list of all Skia GPU unit tests in lexicographic order.  */
+    const std::vector<UnitTest>& getUnitTests() const { return fUnitTests; }
+    ////////////////////////////////////////////////////////////////////////////
+
+private:
+    struct RenderResult {
+        SkiaBackend fBackend;
+        GMFactory fGM;
+        RenderOutcome fOutcome;
+   };
+    struct UnitTestResult {
+        UnitTest fUnitTest;
+        std::vector<std::string> fErrors;
+    };
+    std::vector<RenderResult> fRenderResults;
+    std::vector<UnitTestResult> fUnitTestResults;
+    std::vector<SkiaBackend> fSupportedBackends;
+    SkQPAssetManager* fAssetManager = nullptr;
+    std::string fReportDirectory;
+    std::vector<UnitTest> fUnitTests;
+    std::vector<GMFactory> fGMs;
+    std::unordered_map<std::string, int64_t> fGMThresholds;
+
+    SkQP(const SkQP&) = delete;
+    SkQP& operator=(const SkQP&) = delete;
+};
+#endif  // skqp_DEFINED
+