SkQP: skia_skqp_global_error_tolerance

Change-Id: I991f6a5a6fde3815cd5487227f22014570cfb5d5
Reviewed-on: https://skia-review.googlesource.com/102681
Reviewed-by: Hal Canary <halcanary@google.com>
Commit-Queue: Hal Canary <halcanary@google.com>
diff --git a/BUILD.gn b/BUILD.gn
index f48c62e..3d3a9bf 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -53,6 +53,7 @@
   skia_jumper_ccache = ""
 
   skia_skqp_enable_driver_correctness_workarounds = false
+  skia_skqp_global_error_tolerance = 0
 }
 declare_args() {
   skia_use_dng_sdk = !is_fuchsia && skia_use_libjpeg_turbo && skia_use_zlib
@@ -1793,7 +1794,9 @@
   if (!is_win && skia_enable_gpu) {
     test_lib("skqp_lib") {
       public_include_dirs = [ "tools/skqp" ]
-      defines = []
+      defines = [
+        "SK_SKQP_GLOBAL_ERROR_TOLERANCE=$skia_skqp_global_error_tolerance"
+      ]
       if (skia_skqp_enable_driver_correctness_workarounds) {
         defines += [ "SK_SKQP_ENABLE_DRIVER_CORRECTNESS_WORKAROUNDS" ]
       }
diff --git a/tools/skqp/generate_gn_args b/tools/skqp/generate_gn_args
index 21009a0..c527208 100755
--- a/tools/skqp/generate_gn_args
+++ b/tools/skqp/generate_gn_args
@@ -8,19 +8,20 @@
 import sys
 
 fmt = '''
-target_cpu                = "{arch}"
-is_debug                  = false
-ndk                       = "{ndk}"
-ndk_api                   = 26
-skia_enable_fontmgr_empty = true
-skia_enable_pdf           = false
-skia_use_dng_sdk          = false
-skia_use_expat            = false
-skia_use_icu              = false
-skia_use_libheif          = false
-skia_use_lua              = false
-skia_use_piex             = false
-skia_use_skcms            = false
+target_cpu                       = "{arch}"
+is_debug                         = false
+ndk                              = "{ndk}"
+ndk_api                          = 26
+skia_enable_fontmgr_empty        = true
+skia_enable_pdf                  = false
+skia_skqp_global_error_tolerance = 4
+skia_use_dng_sdk                 = false
+skia_use_expat                   = false
+skia_use_icu                     = false
+skia_use_libheif                 = false
+skia_use_lua                     = false
+skia_use_piex                    = false
+skia_use_skcms                   = false
 '''
 
 def make_args_gn(out_dir, ndk, arch):
diff --git a/tools/skqp/gm_knowledge.cpp b/tools/skqp/gm_knowledge.cpp
index 581f7e4..d5be03b 100644
--- a/tools/skqp/gm_knowledge.cpp
+++ b/tools/skqp/gm_knowledge.cpp
@@ -33,6 +33,10 @@
 #define PATH_REPORT  "report.html"
 #define PATH_CSV      "out.csv"
 
+#ifndef SK_SKQP_GLOBAL_ERROR_TOLERANCE
+#define SK_SKQP_GLOBAL_ERROR_TOLERANCE 0
+#endif
+
 ////////////////////////////////////////////////////////////////////////////////
 
 static int get_error(uint32_t value, uint32_t value_max, uint32_t value_min) {
@@ -47,7 +51,7 @@
             error = std::max(vmin - v, error);
         }
     }
-    return error;
+    return std::max(0, error - SK_SKQP_GLOBAL_ERROR_TOLERANCE);
 }
 
 static int get_error_with_nearby(int x, int y, const SkPixmap& pm,