SkQP:  allow small errors in a small number of pixels

b/80423218

Change-Id: Ied9cb7c72cddb19430b1475bd436bbc8c3ebd3fd
Reviewed-on: https://skia-review.googlesource.com/130541
Reviewed-by: Derek Sollenberger <djsollen@google.com>
diff --git a/platform_tools/android/apps/skqp/src/main/java/org/skia/skqp/SkQP.java b/platform_tools/android/apps/skqp/src/main/java/org/skia/skqp/SkQP.java
index 58e09ec..886d06d 100644
--- a/platform_tools/android/apps/skqp/src/main/java/org/skia/skqp/SkQP.java
+++ b/platform_tools/android/apps/skqp/src/main/java/org/skia/skqp/SkQP.java
@@ -61,7 +61,7 @@
               } else if (value != 0) {
                 // Record failure and carry on.
                   // SkQPRunner.Fail(desc, notifier, String.format(
-                  //             "Image mismatch: max channel diff = %f", value));
+                  //             "Image mismatch: error metric = %f", value));
               } else {
                 // Record success for this test.
               }
diff --git a/platform_tools/android/apps/skqp/src/main/java/org/skia/skqp/SkQPRunner.java b/platform_tools/android/apps/skqp/src/main/java/org/skia/skqp/SkQPRunner.java
index 0c6008c..b2ec2de 100644
--- a/platform_tools/android/apps/skqp/src/main/java/org/skia/skqp/SkQPRunner.java
+++ b/platform_tools/android/apps/skqp/src/main/java/org/skia/skqp/SkQPRunner.java
@@ -130,7 +130,7 @@
                     Log.w(TAG, String.format("[ERROR] '%s': %s", name, error));
                 } else if (value != 0) {
                     SkQPRunner.Fail(desc, notifier, String.format(
-                                "Image mismatch: max channel diff = %f", value));
+                                "Image mismatch: error metric = %f", value));
                     Log.w(TAG, String.format("[FAIL] '%s': %f > 0", name, value));
                 } else {
                     Log.i(TAG, String.format("Rendering Test '%s' passed", name));
diff --git a/tools/skqp/gm_knowledge.cpp b/tools/skqp/gm_knowledge.cpp
index a2416c9..9441dad 100644
--- a/tools/skqp/gm_knowledge.cpp
+++ b/tools/skqp/gm_knowledge.cpp
@@ -38,6 +38,11 @@
 #define SK_SKQP_GLOBAL_ERROR_TOLERANCE 0
 #endif
 
+#ifndef SK_SKQP_BADNESS_TOLERANCE
+#define SK_SKQP_BADNESS_TOLERANCE 100
+#endif
+
+
 ////////////////////////////////////////////////////////////////////////////////
 
 static int get_error(uint32_t value, uint32_t value_max, uint32_t value_min) {
@@ -230,15 +235,16 @@
             }
         }
     }
-
-    if (badness == 0) {
+    int64_t badnessMetric = badness * badPixelCount;
+    if (badnessMetric < SK_SKQP_BADNESS_TOLERANCE) {
         std::lock_guard<std::mutex> lock(gMutex);
         gErrors.push_back(Run{SkString(backend), SkString(name), 0, 0});
-    }
-    if (report_directory_path && badness > 0 && report_directory_path[0] != '\0') {
-        if (!backend) {
-            backend = "skia";
+        if (error_out) {
+            *error_out = Error::kNone;
         }
+        return 0;
+    }
+    if (report_directory_path && report_directory_path[0] != '\0') {
         SkString images_directory = SkOSPath::Join(report_directory_path, IMAGES_DIRECTORY_PATH);
         sk_mkdir(images_directory.c_str());
 
@@ -270,7 +276,7 @@
     if (error_out) {
         *error_out = Error::kNone;
     }
-    return (float)badness;
+    return (float)badnessMetric;
 }
 
 static constexpr char kDocHead[] =