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/jni_skqp.cpp b/tools/skqp/src/jni_skqp.cpp
new file mode 100644
index 0000000..1d45ffd
--- /dev/null
+++ b/tools/skqp/src/jni_skqp.cpp
@@ -0,0 +1,184 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include <mutex>
+
+#include <android/asset_manager.h>
+#include <android/asset_manager_jni.h>
+#include <jni.h>
+#include <sys/stat.h>
+
+#include "ResourceFactory.h"
+#include "SkStream.h"
+#include "SkTo.h"
+
+#include "skqp.h"
+
+////////////////////////////////////////////////////////////////////////////////
+extern "C" {
+JNIEXPORT void JNICALL Java_org_skia_skqp_SkQP_nInit(JNIEnv*, jobject, jobject, jstring);
+JNIEXPORT jlong JNICALL Java_org_skia_skqp_SkQP_nExecuteGM(JNIEnv*, jobject, jint, jint);
+JNIEXPORT jobjectArray JNICALL Java_org_skia_skqp_SkQP_nExecuteUnitTest(JNIEnv*, jobject, jint);
+JNIEXPORT void JNICALL Java_org_skia_skqp_SkQP_nMakeReport(JNIEnv*, jobject);
+}  // extern "C"
+////////////////////////////////////////////////////////////////////////////////
+
+static AAssetManager* gAAssetManager = nullptr;
+
+static sk_sp<SkData> open_asset_data(const char* path) {
+    sk_sp<SkData> data;
+    if (gAAssetManager) {
+        if (AAsset* asset = AAssetManager_open(gAAssetManager, path, AASSET_MODE_STREAMING)) {
+            if (size_t size = SkToSizeT(AAsset_getLength(asset))) {
+                data = SkData::MakeUninitialized(size);
+                int ret = AAsset_read(asset, data->writable_data(), size);
+                if (ret != SkToInt(size)) {
+                    SkDebugf("ERROR: AAsset_read != AAsset_getLength (%s)\n", path);
+                }
+            }
+            AAsset_close(asset);
+        }
+    }
+    return data;
+}
+
+namespace {
+struct AndroidAssetManager : public SkQPAssetManager {
+    sk_sp<SkData> open(const char* path) override { return open_asset_data(path); }
+};
+}
+
+// TODO(halcanary): Should not have global variables; SkQP Java object should
+// own pointers and manage concurency.
+static AndroidAssetManager gAndroidAssetManager;
+static std::mutex gMutex;
+static SkQP gSkQP;
+
+#define jassert(env, cond, ret) do { if (!(cond)) { \
+    (env)->ThrowNew((env)->FindClass("java/lang/Exception"), \
+                    __FILE__ ": assert(" #cond ") failed."); \
+    return ret; } } while (0)
+
+static void set_string_array_element(JNIEnv* env, jobjectArray a, const char* s, unsigned i) {
+    jstring jstr = env->NewStringUTF(s);
+    jassert(env, jstr != nullptr,);
+    env->SetObjectArrayElement(a, (jsize)i, jstr);
+    env->DeleteLocalRef(jstr);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+sk_sp<SkData> get_resource(const char* resource) {
+    return open_asset_data((std::string("resources/")  + resource).c_str());
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+template <typename T, typename F>
+jobjectArray to_java_string_array(JNIEnv* env,
+                                  const std::vector<T>& array,
+                                  F toString) {
+    jclass stringClass = env->FindClass("java/lang/String");
+    jassert(env, stringClass, nullptr);
+    jobjectArray jarray = env->NewObjectArray((jint)array.size(), stringClass, nullptr);
+    jassert(env, jarray != nullptr, nullptr);
+    for (unsigned i = 0; i < array.size(); ++i) {
+        set_string_array_element(env, jarray, std::string(toString(array[i])).c_str(), i);
+    }
+    return jarray;
+}
+
+static std::string to_string(JNIEnv* env, jstring jString) {
+    const char* utf8String = env->GetStringUTFChars(jString, nullptr);
+    jassert(env, utf8String && utf8String[0], "");
+    std::string sString(utf8String);
+    env->ReleaseStringUTFChars(jString, utf8String);
+    return sString;
+}
+
+void Java_org_skia_skqp_SkQP_nInit(JNIEnv* env, jobject object, jobject assetManager,
+                                   jstring dataDir) {
+    jclass SkQP_class = env->GetObjectClass(object);
+
+    // tools/Resources
+    gResourceFactory = &get_resource;
+
+    std::string reportDirectory = to_string(env, dataDir);
+
+    jassert(env, assetManager,);
+    // This global must be set before using AndroidAssetManager
+    gAAssetManager = AAssetManager_fromJava(env, assetManager);
+    jassert(env, gAAssetManager,);
+
+    std::lock_guard<std::mutex> lock(gMutex);
+    gSkQP.init(&gAndroidAssetManager, reportDirectory.c_str());
+
+    auto backends = gSkQP.getSupportedBackends();
+    jassert(env, backends.size() > 0,);
+    auto gms = gSkQP.getGMs();
+    jassert(env, gms.size() > 0,);
+    auto unitTests = gSkQP.getUnitTests();
+    jassert(env, unitTests.size() > 0,);
+
+    constexpr char kStringArrayType[] = "[Ljava/lang/String;";
+    env->SetObjectField(object, env->GetFieldID(SkQP_class, "mBackends", kStringArrayType),
+                        to_java_string_array(env, backends, SkQP::GetBackendName));
+    env->SetObjectField(object, env->GetFieldID(SkQP_class, "mUnitTests", kStringArrayType),
+                        to_java_string_array(env, unitTests, SkQP::GetUnitTestName));
+    env->SetObjectField(object, env->GetFieldID(SkQP_class, "mGMs", kStringArrayType),
+                        to_java_string_array(env, gms, SkQP::GetGMName));
+}
+
+jlong Java_org_skia_skqp_SkQP_nExecuteGM(JNIEnv* env,
+                                          jobject object,
+                                          jint gmIndex,
+                                          jint backendIndex) {
+    SkQP::RenderOutcome outcome;
+    std::string except;
+    {
+        std::lock_guard<std::mutex> lock(gMutex);
+        jassert(env, backendIndex < (jint)gSkQP.getSupportedBackends().size(), -1);
+        jassert(env, gmIndex < (jint)gSkQP.getGMs().size(), -1);
+        SkQP::SkiaBackend backend = gSkQP.getSupportedBackends()[backendIndex];
+        SkQP::GMFactory gm = gSkQP.getGMs()[gmIndex];
+        std::tie(outcome, except) = gSkQP.evaluateGM(backend, gm);
+    }
+
+    if (!except.empty()) {
+        (void)env->ThrowNew(env->FindClass("org/skia/skqp/SkQPException"), except.c_str());
+    }
+    return (jlong)outcome.fTotalError;
+}
+
+jobjectArray Java_org_skia_skqp_SkQP_nExecuteUnitTest(JNIEnv* env,
+                                                      jobject object,
+                                                      jint index) {
+    std::vector<std::string> errors;
+    {
+        jassert(env, index < (jint)gSkQP.getUnitTests().size(), nullptr);
+        std::lock_guard<std::mutex> lock(gMutex);
+        errors = gSkQP.executeTest(gSkQP.getUnitTests()[index]);
+    }
+    if (errors.size() == 0) {
+        return nullptr;
+    }
+    jclass stringClass = env->FindClass("java/lang/String");
+    jassert(env, stringClass, nullptr);
+    jobjectArray array = env->NewObjectArray(errors.size(), stringClass, nullptr);
+    for (unsigned i = 0; i < errors.size(); ++i) {
+        set_string_array_element(env, array, errors[i].c_str(), i);
+    }
+    return (jobjectArray)env->NewGlobalRef(array);
+}
+
+void Java_org_skia_skqp_SkQP_nMakeReport(JNIEnv*, jobject) {
+    std::lock_guard<std::mutex> lock(gMutex);
+    gSkQP.makeReport();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
diff --git a/tools/skqp/src/skqp.cpp b/tools/skqp/src/skqp.cpp
new file mode 100644
index 0000000..7c41a99
--- /dev/null
+++ b/tools/skqp/src/skqp.cpp
@@ -0,0 +1,494 @@
+/*
+ * Copyright 2018 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "skqp.h"
+
+#include "../../../src/core/SkStreamPriv.h"
+#include "../../tools/fonts/SkTestFontMgr.h"
+#include "GrContext.h"
+#include "GrContextOptions.h"
+#include "GrContextPriv.h"
+#include "SkFontMgrPriv.h"
+#include "SkFontStyle.h"
+#include "SkGraphics.h"
+#include "SkImageInfoPriv.h"
+#include "SkOSFile.h"
+#include "SkOSPath.h"
+#include "SkPngEncoder.h"
+#include "SkStream.h"
+#include "SkSurface.h"
+#include "Test.h"
+#include "gl/GLTestContext.h"
+#include "gm.h"
+#include "vk/VkTestContext.h"
+
+#include <algorithm>
+#include <cinttypes>
+#include <sstream>
+
+#include "skqp_model.h"
+
+#define IMAGES_DIRECTORY_PATH "images"
+#define PATH_MAX_PNG "max.png"
+#define PATH_MIN_PNG "min.png"
+#define PATH_IMG_PNG "image.png"
+#define PATH_ERR_PNG "errors.png"
+#define PATH_MODEL "model"
+
+static constexpr char kRenderTestCSVReport[] = "out.csv";
+static constexpr char kRenderTestReportPath[] = "report.html";
+static constexpr char kRenderTestsPath[] = "skqp/rendertests.txt";
+static constexpr char kUnitTestReportPath[] = "unit_tests.txt";
+static constexpr char kUnitTestsPath[]   = "skqp/unittests.txt";
+
+// Kind of like Python's readlines(), but without any allocation.
+// Calls f() on each line.
+// F is [](const char*, size_t) -> void
+template <typename F>
+static void readlines(const void* data, size_t size, F f) {
+    const char* start = (const char*)data;
+    const char* end = start + size;
+    const char* ptr = start;
+    while (ptr < end) {
+        while (*ptr++ != '\n' && ptr < end) {}
+        size_t len = ptr - start;
+        f(start, len);
+        start = ptr;
+    }
+}
+
+static void get_unit_tests(SkQPAssetManager* mgr, std::vector<SkQP::UnitTest>* unitTests) {
+    std::unordered_set<std::string> testset;
+    auto insert = [&testset](const char* s, size_t l) {
+        SkASSERT(l > 1) ;
+        if (l > 0 && s[l - 1] == '\n') {  // strip line endings.
+            --l;
+        }
+        if (l > 0) {  // only add non-empty strings.
+            testset.insert(std::string(s, l));
+        }
+    };
+    if (sk_sp<SkData> dat = mgr->open(kUnitTestsPath)) {
+        readlines(dat->data(), dat->size(), insert);
+    }
+    for (const skiatest::Test& test : skiatest::TestRegistry::Range()) {
+        if ((testset.empty() || testset.count(std::string(test.name)) > 0) && test.needsGpu) {
+            unitTests->push_back(&test);
+        }
+    }
+    auto lt = [](SkQP::UnitTest u, SkQP::UnitTest v) { return strcmp(u->name, v->name) < 0; };
+    std::sort(unitTests->begin(), unitTests->end(), lt);
+}
+
+static void get_render_tests(SkQPAssetManager* mgr,
+                             std::vector<SkQP::GMFactory>* gmlist,
+                             std::unordered_map<std::string, int64_t>* gmThresholds) {
+    auto insert = [gmThresholds](const char* s, size_t l) {
+        SkASSERT(l > 1) ;
+        if (l > 0 && s[l - 1] == '\n') {  // strip line endings.
+            --l;
+        }
+        if (l == 0) {
+            return;
+        }
+        const char* end = s + l;
+        const char* ptr = s;
+        constexpr char kDelimeter = ',';
+        while (ptr < end && *ptr != kDelimeter) { ++ptr; }
+        if (ptr + 1 >= end) {
+            SkASSERT(false);  // missing delimeter
+            return;
+        }
+        std::string key(s, ptr - s);
+        ++ptr;  // skip delimeter
+        std::string number(ptr, end - ptr);  // null-terminated copy.
+        int64_t value = 0;
+        if (1 != sscanf(number.c_str(), "%" SCNd64 , &value)) {
+            SkASSERT(false);  // Not a number
+            return;
+        }
+        gmThresholds->insert({std::move(key), value});  // (*gmThresholds)[s] = value;
+    };
+    if (sk_sp<SkData> dat = mgr->open(kRenderTestsPath)) {
+        readlines(dat->data(), dat->size(), insert);
+    }
+    using GmAndName = std::pair<SkQP::GMFactory, std::string>;
+    std::vector<GmAndName> gmsWithNames;
+    for (skiagm::GMFactory f : skiagm::GMRegistry::Range()) {
+        std::string name = SkQP::GetGMName(f);
+        if ((gmThresholds->empty() || gmThresholds->count(name) > 0)) {
+            gmsWithNames.push_back(std::make_pair(f, std::move(name)));
+        }
+    }
+    std::sort(gmsWithNames.begin(), gmsWithNames.end(),
+              [](GmAndName u, GmAndName v) { return u.second < v.second; });
+    gmlist->reserve(gmsWithNames.size());
+    for (const GmAndName& gmn : gmsWithNames) {
+        gmlist->push_back(gmn.first);
+    }
+}
+
+static std::unique_ptr<sk_gpu_test::TestContext> make_test_context(SkQP::SkiaBackend backend) {
+    using U = std::unique_ptr<sk_gpu_test::TestContext>;
+    switch (backend) {
+        case SkQP::SkiaBackend::kGL:
+            return U(sk_gpu_test::CreatePlatformGLTestContext(kGL_GrGLStandard, nullptr));
+        case SkQP::SkiaBackend::kGLES:
+            return U(sk_gpu_test::CreatePlatformGLTestContext(kGLES_GrGLStandard, nullptr));
+#ifdef SK_VULKAN
+        case SkQP::SkiaBackend::kVulkan:
+            return U(sk_gpu_test::CreatePlatformVkTestContext(nullptr));
+#endif
+        default:
+            return nullptr;
+    }
+}
+
+static GrContextOptions context_options(skiagm::GM* gm = nullptr) {
+    GrContextOptions grContextOptions;
+    grContextOptions.fAllowPathMaskCaching = true;
+    grContextOptions.fSuppressPathRendering = true;
+    grContextOptions.fDisableDriverCorrectnessWorkarounds = true;
+    if (gm) {
+        gm->modifyGrContextOptions(&grContextOptions);
+    }
+    return grContextOptions;
+}
+
+static std::vector<SkQP::SkiaBackend> get_backends() {
+    std::vector<SkQP::SkiaBackend> result;
+    SkQP::SkiaBackend backends[] = {
+        #ifndef SK_BUILD_FOR_ANDROID
+        SkQP::SkiaBackend::kGL,  // Used for testing on desktop machines.
+        #endif
+        SkQP::SkiaBackend::kGLES,
+        #ifdef SK_VULKAN
+        SkQP::SkiaBackend::kVulkan,
+        #endif
+    };
+    for (SkQP::SkiaBackend backend : backends) {
+        std::unique_ptr<sk_gpu_test::TestContext> testCtx = make_test_context(backend);
+        if (testCtx) {
+            testCtx->makeCurrent();
+            if (nullptr != testCtx->makeGrContext(context_options())) {
+                result.push_back(backend);
+            }
+        }
+    }
+    SkASSERT_RELEASE(result.size() > 0);
+    return result;
+}
+
+static void print_backend_info(const char* dstPath,
+                               const std::vector<SkQP::SkiaBackend>& backends) {
+#ifdef SK_ENABLE_DUMP_GPU
+    SkFILEWStream out(dstPath);
+    out.writeText("[\n");
+    for (SkQP::SkiaBackend backend : backends) {
+        if (std::unique_ptr<sk_gpu_test::TestContext> testCtx = make_test_context(backend)) {
+            testCtx->makeCurrent();
+            if (sk_sp<GrContext> ctx = testCtx->makeGrContext(context_options())) {
+                SkString info = ctx->contextPriv().dump();
+                // remove null
+                out.write(info.c_str(), info.size());
+                out.writeText(",\n");
+            }
+        }
+    }
+    out.writeText("]\n");
+#endif
+}
+
+static void encode_png(const SkBitmap& src, const std::string& dst) {
+    SkFILEWStream wStream(dst.c_str());
+    SkPngEncoder::Options options;
+    bool success = wStream.isValid() && SkPngEncoder::Encode(&wStream, src.pixmap(), options);
+    SkASSERT_RELEASE(success);
+}
+
+static void write_to_file(const sk_sp<SkData>& src, const std::string& dst) {
+    SkFILEWStream wStream(dst.c_str());
+    bool success = wStream.isValid() && wStream.write(src->data(), src->size());
+    SkASSERT_RELEASE(success);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+const char* SkQP::GetBackendName(SkQP::SkiaBackend b) {
+    switch (b) {
+        case SkQP::SkiaBackend::kGL:     return "gl";
+        case SkQP::SkiaBackend::kGLES:   return "gles";
+        case SkQP::SkiaBackend::kVulkan: return "vk";
+    }
+    return "";
+}
+
+std::string SkQP::GetGMName(SkQP::GMFactory f) {
+    std::unique_ptr<skiagm::GM> gm(f ? f(nullptr) : nullptr);
+    return std::string(gm ? gm->getName() : "");
+}
+
+const char* SkQP::GetUnitTestName(SkQP::UnitTest t) { return t->name; }
+
+SkQP::SkQP() {}
+
+SkQP::~SkQP() {}
+
+void SkQP::init(SkQPAssetManager* am, const char* reportDirectory) {
+    SkASSERT_RELEASE(!fAssetManager);
+    SkASSERT_RELEASE(am);
+    fAssetManager = am;
+    fReportDirectory = reportDirectory;
+
+    SkGraphics::Init();
+    gSkFontMgr_DefaultFactory = &sk_tool_utils::MakePortableFontMgr;
+
+    /* If the file "skqp/rendertests.txt" does not exist or is empty, run all
+       render tests.  Otherwise only run tests mentioned in that file.  */
+    get_render_tests(fAssetManager, &fGMs, &fGMThresholds);
+    /* If the file "skqp/unittests.txt" does not exist or is empty, run all gpu
+       unit tests.  Otherwise only run tests mentioned in that file.  */
+    get_unit_tests(fAssetManager, &fUnitTests);
+    fSupportedBackends = get_backends();
+
+    print_backend_info((fReportDirectory + "/grdump.txt").c_str(), fSupportedBackends);
+}
+
+std::tuple<SkQP::RenderOutcome, std::string> SkQP::evaluateGM(SkQP::SkiaBackend backend,
+                                                              SkQP::GMFactory gmFact) {
+    SkASSERT_RELEASE(fAssetManager);
+    static constexpr SkQP::RenderOutcome kError = {INT_MAX, INT_MAX, INT64_MAX};
+    static constexpr SkQP::RenderOutcome kPass = {0, 0, 0};
+
+    SkASSERT(gmFact);
+    std::unique_ptr<skiagm::GM> gm(gmFact(nullptr));
+    SkASSERT(gm);
+    const char* const name = gm->getName();
+    const SkISize size = gm->getISize();
+    const int w = size.width();
+    const int h = size.height();
+    const SkImageInfo info =
+        SkImageInfo::Make(w, h, skqp::kColorType, kPremul_SkAlphaType, nullptr);
+    const SkSurfaceProps props(0, SkSurfaceProps::kLegacyFontHost_InitType);
+
+    std::unique_ptr<sk_gpu_test::TestContext> testCtx = make_test_context(backend);
+    if (!testCtx) {
+        return std::make_tuple(kError, "Skia Failure: test context");
+    }
+    testCtx->makeCurrent();
+    sk_sp<SkSurface> surf = SkSurface::MakeRenderTarget(
+            testCtx->makeGrContext(context_options(gm.get())).get(),
+            SkBudgeted::kNo, info, 0, &props);
+    if (!surf) {
+        return std::make_tuple(kError, "Skia Failure: gr-context");
+    }
+    gm->draw(surf->getCanvas());
+
+    SkBitmap image;
+    image.allocPixels(SkImageInfo::Make(w, h, skqp::kColorType, skqp::kAlphaType));
+
+    // SkColorTypeBytesPerPixel should be constexpr, but is not.
+    SkASSERT(SkColorTypeBytesPerPixel(skqp::kColorType) == sizeof(uint32_t));
+    // Call readPixels because we need to compare pixels.
+    if (!surf->readPixels(image.pixmap(), 0, 0)) {
+        return std::make_tuple(kError, "Skia Failure: read pixels");
+    }
+    int64_t passingThreshold = fGMThresholds.empty() ? -1 : fGMThresholds[std::string(name)];
+
+    if (-1 == passingThreshold) {
+        return std::make_tuple(kPass, "");
+    }
+    skqp::ModelResult modelResult =
+        skqp::CheckAgainstModel(name, image.pixmap(), fAssetManager);
+
+    if (!modelResult.fErrorString.empty()) {
+        return std::make_tuple(kError, std::move(modelResult.fErrorString));
+    }
+    fRenderResults.push_back(SkQP::RenderResult{backend, gmFact, modelResult.fOutcome});
+    if (modelResult.fOutcome.fMaxError <= passingThreshold) {
+        return std::make_tuple(kPass, "");
+    }
+    std::string imagesDirectory = fReportDirectory + "/" IMAGES_DIRECTORY_PATH;
+    if (!sk_mkdir(imagesDirectory.c_str())) {
+        SkDebugf("ERROR: sk_mkdir('%s');\n", imagesDirectory.c_str());
+        return std::make_tuple(modelResult.fOutcome, "");
+    }
+    std::ostringstream tmp;
+    tmp << imagesDirectory << '/' << SkQP::GetBackendName(backend) << '_' << name << '_';
+    std::string imagesPathPrefix1 = tmp.str();
+    tmp = std::ostringstream();
+    tmp << imagesDirectory << '/' << PATH_MODEL << '_' << name << '_';
+    std::string imagesPathPrefix2 = tmp.str();
+    encode_png(image,                  imagesPathPrefix1 + PATH_IMG_PNG);
+    encode_png(modelResult.fErrors,    imagesPathPrefix1 + PATH_ERR_PNG);
+    write_to_file(modelResult.fMaxPng, imagesPathPrefix2 + PATH_MAX_PNG);
+    write_to_file(modelResult.fMinPng, imagesPathPrefix2 + PATH_MIN_PNG);
+    return std::make_tuple(modelResult.fOutcome, "");
+}
+
+std::vector<std::string> SkQP::executeTest(SkQP::UnitTest test) {
+    SkASSERT_RELEASE(fAssetManager);
+    struct : public skiatest::Reporter {
+        std::vector<std::string> fErrors;
+        void reportFailed(const skiatest::Failure& failure) override {
+            SkString desc = failure.toString();
+            fErrors.push_back(std::string(desc.c_str(), desc.size()));
+        }
+    } r;
+    GrContextOptions options;
+    options.fDisableDriverCorrectnessWorkarounds = true;
+    if (test->fContextOptionsProc) {
+        test->fContextOptionsProc(&options);
+    }
+    test->proc(&r, options);
+    fUnitTestResults.push_back(UnitTestResult{test, r.fErrors});
+    return r.fErrors;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+static constexpr char kDocHead[] =
+    "<!doctype html>\n"
+    "<html lang=\"en\">\n"
+    "<head>\n"
+    "<meta charset=\"UTF-8\">\n"
+    "<title>SkQP Report</title>\n"
+    "<style>\n"
+    "img { max-width:48%; border:1px green solid;\n"
+    "      image-rendering: pixelated;\n"
+    "      background-image:url('data:image/png;base64,iVBORw0KGgoA"
+    "AAANSUhEUgAAABAAAAAQCAAAAAA6mKC9AAAAAXNSR0IArs4c6QAAAAJiS0dEAP+H"
+    "j8y/AAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAB3RJTUUH3gUBEi4DGRAQYgAAAB1J"
+    "REFUGNNjfMoAAVJQmokBDdBHgPE/lPFsYN0BABdaAwN6tehMAAAAAElFTkSuQmCC"
+    "'); }\n"
+    "</style>\n"
+    "<script>\n"
+    "function ce(t) { return document.createElement(t); }\n"
+    "function ct(n) { return document.createTextNode(n); }\n"
+    "function ac(u,v) { return u.appendChild(v); }\n"
+    "function br(u) { ac(u, ce(\"br\")); }\n"
+    "function ma(s, c) { var a = ce(\"a\"); a.href = s; ac(a, c); return a; }\n"
+    "function f(backend, gm, e1, e2, e3) {\n"
+    "  var b = ce(\"div\");\n"
+    "  var x = ce(\"h2\");\n"
+    "  var t = backend + \"_\" + gm;\n"
+    "  ac(x, ct(t));\n"
+    "  ac(b, x);\n"
+    "  ac(b, ct(\"backend: \" + backend));\n"
+    "  br(b);\n"
+    "  ac(b, ct(\"gm name: \" + gm));\n"
+    "  br(b);\n"
+    "  ac(b, ct(\"maximum error: \" + e1));\n"
+    "  br(b);\n"
+    "  ac(b, ct(\"bad pixel counts: \" + e2));\n"
+    "  br(b);\n"
+    "  ac(b, ct(\"total error: \" + e3));\n"
+    "  br(b);\n"
+    "  var q = \"" IMAGES_DIRECTORY_PATH "/\" + backend + \"_\" + gm + \"_\";\n"
+    "  var p = \"" IMAGES_DIRECTORY_PATH "/"   PATH_MODEL  "_\" + gm + \"_\";\n"
+    "  var i = ce(\"img\");\n"
+    "  i.src = q + \"" PATH_IMG_PNG "\";\n"
+    "  i.alt = \"img\";\n"
+    "  ac(b, ma(i.src, i));\n"
+    "  i = ce(\"img\");\n"
+    "  i.src = q + \"" PATH_ERR_PNG "\";\n"
+    "  i.alt = \"err\";\n"
+    "  ac(b, ma(i.src, i));\n"
+    "  br(b);\n"
+    "  ac(b, ct(\"Expectation: \"));\n"
+    "  ac(b, ma(p + \"" PATH_MAX_PNG "\", ct(\"max\")));\n"
+    "  ac(b, ct(\" | \"));\n"
+    "  ac(b, ma(p + \"" PATH_MIN_PNG "\", ct(\"min\")));\n"
+    "  ac(b, ce(\"hr\"));\n"
+    "  b.id = backend + \":\" + gm;\n"
+    "  ac(document.body, b);\n"
+    "  l = ce(\"li\");\n"
+    "  ac(l, ct(\"[\" + e3 + \"] \"));\n"
+    "  ac(l, ma(\"#\" + backend +\":\"+ gm , ct(t)));\n"
+    "  ac(document.getElementById(\"toc\"), l);\n"
+    "}\n"
+    "function main() {\n";
+
+static constexpr char kDocMiddle[] =
+    "}\n"
+    "</script>\n"
+    "</head>\n"
+    "<body onload=\"main()\">\n"
+    "<h1>SkQP Report</h1>\n";
+
+static constexpr char kDocTail[] =
+    "<ul id=\"toc\"></ul>\n"
+    "<hr>\n"
+    "<p>Left image: test result<br>\n"
+    "Right image: errors (white = no error, black = smallest error, red = biggest error; "
+    "other errors are a color between black and red.)</p>\n"
+    "<hr>\n"
+    "</body>\n"
+    "</html>\n";
+
+template <typename T>
+inline void write(SkWStream* wStream, const T& text) {
+    wStream->write(text.c_str(), text.size());
+}
+
+void SkQP::makeReport() {
+    SkASSERT_RELEASE(fAssetManager);
+    int glesErrorCount = 0, vkErrorCount = 0, gles = 0, vk = 0;
+
+    if (!sk_isdir(fReportDirectory.c_str())) {
+        SkDebugf("Report destination does not exist: '%s'\n", fReportDirectory.c_str());
+        return;
+    }
+    SkFILEWStream csvOut(SkOSPath::Join(fReportDirectory.c_str(), kRenderTestCSVReport).c_str());
+    SkFILEWStream htmOut(SkOSPath::Join(fReportDirectory.c_str(), kRenderTestReportPath).c_str());
+    SkASSERT_RELEASE(csvOut.isValid() && htmOut.isValid());
+    htmOut.writeText(kDocHead);
+    for (const SkQP::RenderResult& run : fRenderResults) {
+        switch (run.fBackend) {
+            case SkQP::SkiaBackend::kGLES: ++gles; break;
+            case SkQP::SkiaBackend::kVulkan: ++vk; break;
+            default: break;
+        }
+        const char* backendName = SkQP::GetBackendName(run.fBackend);
+        std::string gmName = SkQP::GetGMName(run.fGM);
+        SkQP::RenderOutcome outcome;
+        auto str = SkStringPrintf("\"%s\",\"%s\",%d,%d,%" PRId64, backendName, gmName.c_str(),
+                                  outcome.fMaxError, outcome.fBadPixelCount, outcome.fTotalError);
+        write(&csvOut, SkStringPrintf("%s\n", str.c_str()));
+
+        int64_t passingThreshold = fGMThresholds.empty() ? 0 : fGMThresholds[gmName];
+        if (passingThreshold == -1 || outcome.fMaxError <= passingThreshold) {
+            continue;
+        }
+        write(&htmOut, SkStringPrintf("  f(%s);\n", str.c_str()));
+        switch (run.fBackend) {
+            case SkQP::SkiaBackend::kGLES: ++glesErrorCount; break;
+            case SkQP::SkiaBackend::kVulkan: ++vkErrorCount; break;
+            default: break;
+        }
+    }
+    htmOut.writeText(kDocMiddle);
+    write(&htmOut, SkStringPrintf("<p>gles errors: %d (of %d)</br>\n"
+                                  "vk errors: %d (of %d)</p>\n",
+                                  glesErrorCount, gles, vkErrorCount, vk));
+    htmOut.writeText(kDocTail);
+    SkFILEWStream unitOut(SkOSPath::Join(fReportDirectory.c_str(), kUnitTestReportPath).c_str());
+    SkASSERT_RELEASE(unitOut.isValid());
+    for (const SkQP::UnitTestResult& result : fUnitTestResults) {
+        unitOut.writeText(GetUnitTestName(result.fUnitTest));
+        if (result.fErrors.empty()) {
+            unitOut.writeText(" PASSED\n* * *\n");
+        } else {
+            write(&unitOut, SkStringPrintf(" FAILED (%u errors)\n", result.fErrors.size()));
+            for (const std::string& err : result.fErrors) {
+                write(&unitOut, err);
+                unitOut.newline();
+            }
+            unitOut.writeText("* * *\n");
+        }
+    }
+}
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
+
diff --git a/tools/skqp/src/skqp_main.cpp b/tools/skqp/src/skqp_main.cpp
new file mode 100644
index 0000000..2737a9a
--- /dev/null
+++ b/tools/skqp/src/skqp_main.cpp
@@ -0,0 +1,145 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include <iostream>
+#include <sys/stat.h>
+
+#include "skqp.h"
+
+#include "Resources.h"
+#include "SkData.h"
+#include "SkOSFile.h"
+
+////////////////////////////////////////////////////////////////////////////////
+
+namespace {
+class StdAssetManager : public SkQPAssetManager {
+public:
+    StdAssetManager(const char* p) : fPrefix(p) {
+        SkASSERT(!fPrefix.empty());
+        //TODO(halcanary): does this need to be changed if I run SkQP in Windows?
+        fPrefix += "/";
+    }
+    sk_sp<SkData> open(const char* path) override {
+        return SkData::MakeFromFileName((fPrefix + path).c_str());
+    }
+private:
+    std::string fPrefix;
+};
+}
+
+static constexpr char kSkipUsage[] =
+    " TEST_MATCH_RULES:"
+    "    [~][^]substring[$] [...] of name to run.\n"
+    "    Multiple matches may be separated by spaces.\n"
+    "    ~ causes a matching name to always be skipped\n"
+    "    ^ requires the start of the name to match\n"
+    "    $ requires the end of the name to match\n"
+    "    ^ and $ requires an exact match\n"
+    "    If a name does not match any list entry,\n"
+    "    it is skipped unless some list entry starts with ~\n";
+
+static bool should_skip(const char* const* rules, size_t count, const char* name) {
+    size_t testLen = strlen(name);
+    bool anyExclude = count == 0;
+    for (size_t i = 0; i < count; ++i) {
+        const char* matchName = rules[i];
+        size_t matchLen = strlen(matchName);
+        bool matchExclude, matchStart, matchEnd;
+        if ((matchExclude = matchName[0] == '~')) {
+            anyExclude = true;
+            matchName++;
+            matchLen--;
+        }
+        if ((matchStart = matchName[0] == '^')) {
+            matchName++;
+            matchLen--;
+        }
+        if ((matchEnd = matchName[matchLen - 1] == '$')) {
+            matchLen--;
+        }
+        if (matchStart ? (!matchEnd || matchLen == testLen)
+                && strncmp(name, matchName, matchLen) == 0
+                : matchEnd ? matchLen <= testLen
+                && strncmp(name + testLen - matchLen, matchName, matchLen) == 0
+                : strstr(name, matchName) != nullptr) {
+            return matchExclude;
+        }
+    }
+    return !anyExclude;
+}
+
+int main(int argc, char** argv) {
+    if (argc < 3) {
+        std::cerr << "Usage:\n  " << argv[0]
+                  << " ASSET_DIRECTORY_PATH SKQP_REPORT_PATH [TEST_MATCH_RULES]\n"
+                  << kSkipUsage << '\n';
+        return 1;
+    }
+    SetResourcePath((std::string(argv[1]) + "/resources").c_str());
+    if (!sk_mkdir(argv[2])) {
+        std::cerr << "sk_mkdir(" << argv[2] << ") failed.\n";
+        return 2;
+    }
+    StdAssetManager mgr(argv[1]);
+    SkQP skqp;
+    skqp.init(&mgr, argv[2]);
+    int ret = 0;
+
+    const char* const* matchRules = &argv[3];
+    size_t matchRulesCount = (size_t)(argc - 3);
+
+    // Rendering Tests
+    std::ostream& out = std::cout;
+    for (auto backend : skqp.getSupportedBackends()) {
+        auto testPrefix = std::string(SkQP::GetBackendName(backend)) + "_";
+        for (auto gmFactory : skqp.getGMs()) {
+            auto testName = testPrefix + SkQP::GetGMName(gmFactory);
+            if (should_skip(matchRules, matchRulesCount, testName.c_str())) {
+                continue;
+            }
+            out << "Starting: " << testName << std::endl;
+            SkQP::RenderOutcome outcome;
+            std::string except;
+
+            std::tie(outcome, except) = skqp.evaluateGM(backend, gmFactory);
+            if (!except.empty()) {
+                out << "ERROR:    " << testName << " (" << except << ")\n";
+                ret = 1;
+            } else if (outcome.fMaxError != 0) {
+                out << "FAILED:   " << testName << " (" << outcome.fMaxError << ")\n";
+                ret = 1;
+            } else {
+                out << "Passed:   " << testName << "\n";
+            }
+            out.flush();
+        }
+    }
+
+    // Unit Tests
+    for (auto test : skqp.getUnitTests()) {
+        auto testName = std::string("unitTest_") +  SkQP::GetUnitTestName(test);
+        if (should_skip(matchRules, matchRulesCount, testName.c_str())) {
+            continue;
+        }
+        out << "Starting test: " << testName << std::endl;
+        std::vector<std::string> errors = skqp.executeTest(test);
+        if (!errors.empty()) {
+            out << "TEST FAILED (" << errors.size() << "): " << testName << "\n";
+            for (const std::string& error : errors) {
+                out << error << "\n";
+            }
+            ret = 1;
+        } else {
+            out << "Test passed:   " << testName << "\n";
+        }
+        out.flush();
+    }
+    skqp.makeReport();
+
+    return ret;
+}
diff --git a/tools/skqp/src/skqp_model.cpp b/tools/skqp/src/skqp_model.cpp
new file mode 100644
index 0000000..79fd2dc
--- /dev/null
+++ b/tools/skqp/src/skqp_model.cpp
@@ -0,0 +1,144 @@
+/*
+ * Copyright 2018 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "skqp_model.h"
+#include "skqp.h"
+
+#include "SkBitmap.h"
+#include "SkCodec.h"
+#include "SkOSPath.h"
+#include "SkStream.h"
+
+#ifndef SK_SKQP_GLOBAL_ERROR_TOLERANCE
+#define SK_SKQP_GLOBAL_ERROR_TOLERANCE 0
+#endif
+
+////////////////////////////////////////////////////////////////////////////////
+
+static inline uint32_t color(const SkPixmap& pm, SkIPoint p) {
+    return *pm.addr32(p.x(), p.y());
+}
+
+static inline bool inside(SkIPoint point, SkISize dimensions) {
+    return (unsigned)point.x() < (unsigned)dimensions.width() &&
+           (unsigned)point.y() < (unsigned)dimensions.height();
+}
+
+SkQP::RenderOutcome skqp::Check(const SkPixmap& minImg,
+                                const SkPixmap& maxImg,
+                                const SkPixmap& img,
+                                unsigned tolerance,
+                                SkBitmap* errorOut) {
+    SkQP::RenderOutcome result;
+    SkISize dim = img.info().dimensions();
+    SkASSERT(minImg.info().dimensions() == dim);
+    SkASSERT(maxImg.info().dimensions() == dim);
+    static const SkIPoint kNeighborhood[9] = {
+        { 0,  0}, // ordered by closest pixels first.
+        {-1,  0}, { 1,  0}, { 0, -1}, { 0,  1},
+        {-1, -1}, { 1, -1}, {-1,  1}, { 1,  1},
+    };
+    for (int y = 0; y < dim.height(); ++y) {
+        for (int x = 0; x < dim.width(); ++x) {
+            const SkIPoint xy{x, y};
+            const uint32_t c = color(img, xy);
+            int error = INT_MAX;
+            // loop over neighborhood (halo);
+            for (SkIPoint delta : kNeighborhood) {
+                SkIPoint point = xy + delta;
+                if (inside(point, dim)) {  // skip out of pixmap bounds.
+                    int err = 0;
+                    // loop over four color channels.
+                    // Return Manhattan distance in channel-space.
+                    for (int component : {0, 8, 16, 24}) {
+                        uint8_t v    = (c                    >> component) & 0xFF,
+                                vmin = (color(minImg, point) >> component) & 0xFF,
+                                vmax = (color(maxImg, point) >> component) & 0xFF;
+                        err = SkMax32(err, SkMax32((int)v - (int)vmax, (int)vmin - (int)v));
+                    }
+                    error = SkMin32(error, err);
+                }
+            }
+            if (error > (int)tolerance) {
+                ++result.fBadPixelCount;
+                result.fTotalError += error;
+                result.fMaxError = SkMax32(error, result.fMaxError);
+                if (errorOut) {
+                    if (!errorOut->getPixels()) {
+                        errorOut->allocPixels(SkImageInfo::Make(
+                                    dim.width(), dim.height(),
+                                    kBGRA_8888_SkColorType,
+                                    kOpaque_SkAlphaType));
+                        errorOut->eraseColor(SK_ColorWHITE);
+                    }
+                    SkASSERT((unsigned)error < 256);
+                    *(errorOut->getAddr32(x, y)) = SkColorSetARGB(0xFF, (uint8_t)error, 0, 0);
+                }
+            }
+        }
+    }
+    return result;
+}
+
+static SkBitmap decode(sk_sp<SkData> data) {
+    SkBitmap bitmap;
+    if (auto codec = SkCodec::MakeFromData(std::move(data))) {
+        SkISize size = codec->getInfo().dimensions();
+        SkASSERT(!size.isEmpty());
+        SkImageInfo info = SkImageInfo::Make(size.width(), size.height(),
+                                             skqp::kColorType, skqp::kAlphaType);
+        bitmap.allocPixels(info);
+        if (SkCodec::kSuccess != codec->getPixels(bitmap.pixmap())) {
+            bitmap.reset();
+        }
+    }
+    return bitmap;
+}
+
+skqp::ModelResult skqp::CheckAgainstModel(const char* name,
+                                          const SkPixmap& pm,
+                                          SkQPAssetManager* mgr) {
+    skqp::ModelResult result;
+    if (pm.colorType() != kColorType || pm.alphaType() != kAlphaType) {
+        result.fErrorString = "Model failed: source image format.";
+        return result;
+    }
+    if (pm.info().isEmpty()) {
+        result.fErrorString = "Model failed: empty source image";
+        return result;
+    }
+    constexpr char PATH_ROOT[] = "gmkb";
+    SkString img_path = SkOSPath::Join(PATH_ROOT, name);
+    SkString max_path = SkOSPath::Join(img_path.c_str(), kMaxPngPath);
+    SkString min_path = SkOSPath::Join(img_path.c_str(), kMinPngPath);
+
+    result.fMaxPng = mgr->open(max_path.c_str());
+    result.fMinPng = mgr->open(min_path.c_str());
+
+    SkBitmap max_image = decode(result.fMaxPng);
+    SkBitmap min_image = decode(result.fMinPng);
+
+    if (max_image.isNull() || min_image.isNull()) {
+        result.fErrorString = "Model missing";
+        return result;
+    }
+    if (max_image.info().dimensions() != min_image.info().dimensions()) {
+        result.fErrorString = "Model has mismatched data.";
+        return result;
+    }
+
+    if (max_image.info().dimensions() != pm.info().dimensions()) {
+        result.fErrorString = "Model data does not match source size.";
+        return result;
+    }
+    result.fOutcome = Check(min_image.pixmap(),
+                            max_image.pixmap(),
+                            pm,
+                            SK_SKQP_GLOBAL_ERROR_TOLERANCE,
+                            &result.fErrors);
+    return result;
+}
diff --git a/tools/skqp/src/skqp_model.h b/tools/skqp/src/skqp_model.h
new file mode 100644
index 0000000..d807cde
--- /dev/null
+++ b/tools/skqp/src/skqp_model.h
@@ -0,0 +1,58 @@
+/*
+ * 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_model_DEFINED
+#define skqp_model_DEFINED
+
+#include <cstdint>
+#include <string>
+
+#include "SkBitmap.h"
+
+#include "skqp.h"
+
+class SkQPAssetManager;
+class SkStreamAsset;
+
+namespace skqp {
+
+/** Prefered colortype for comparing test outcomes. */
+constexpr SkColorType kColorType = kRGBA_8888_SkColorType;
+
+/** Prefered alphatype for comparing test outcomes. */
+constexpr SkAlphaType kAlphaType = kUnpremul_SkAlphaType;
+
+/** Where to find the maximum and minimum of the model. */
+constexpr char kMaxPngPath[] = "max.png";
+constexpr char kMinPngPath[] = "min.png";
+
+struct ModelResult {
+    SkBitmap fErrors; // Correct pixels are white, failing pixels scale from black
+                      // (1 value off) to red (255 off in some channel).
+    sk_sp<SkData> fMinPng;  // original model data, PNG encoded image.
+    sk_sp<SkData> fMaxPng;  // original model data, PNG encoded image.
+    SkQP::RenderOutcome fOutcome;
+    std::string fErrorString;  // if non-empty, an error occured.
+};
+
+SkQP::RenderOutcome Check(const SkPixmap& minImg,
+                          const SkPixmap& maxImg,
+                          const SkPixmap& img,
+                          unsigned tolerance,
+                          SkBitmap* errorOut);
+
+/** Check if the given test image matches the expected results.
+
+    @param name          the name of the rendering test that produced the image
+    @param image         the image to be tested.  Should be kRGBA_8888_SkColorType
+                         and kUnpremul_SkAlphaType.
+    @param assetManager  provides model data files
+*/
+
+ModelResult CheckAgainstModel(const char* name, const SkPixmap& image,
+                              SkQPAssetManager* assetManager);
+}
+#endif  // skqp_model_DEFINED