Log fuzzer linear gradient params in verbose mode
authorFlorin Malita <fmalita@chromium.org>
Thu, 9 Feb 2017 16:31:32 +0000 (11:31 -0500)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Thu, 9 Feb 2017 17:09:58 +0000 (17:09 +0000)
Useful for quickly importing the data into regression tests.

Change-Id: Icf4fa03f26dcc7f707dbdaf19be8cdc057aabb55
Reviewed-on: https://skia-review.googlesource.com/8255
Commit-Queue: Florin Malita <fmalita@chromium.org>
Reviewed-by: Kevin Lubick <kjlubick@google.com>
fuzz/FuzzGradients.cpp

index 90d4066..8539f5a 100644 (file)
@@ -7,6 +7,7 @@
 
 #include "Fuzz.h"
 #include "SkCanvas.h"
+#include "SkCommonFlags.h"
 #include "SkGradientShader.h"
 #include "SkSurface.h"
 #include "SkTLazy.h"
@@ -50,6 +51,58 @@ void initGradientParams(Fuzz* fuzz, std::vector<SkColor>* colors,
     }
 }
 
+static void logOptionalMatrix(const char* label, const SkMatrix* m) {
+    if (!m) {
+        return;
+    }
+
+    SkDebugf("  %s: [ ", label);
+    for (int i = 0; i < 9; ++i) {
+        SkDebugf("%.9g ", m->get(i));
+    }
+    SkDebugf("]\n");
+}
+
+static void logLinearGradient(const SkPoint pts[2],
+                              const std::vector<SkColor>& colors,
+                              const std::vector<SkScalar> pos,
+                              SkShader::TileMode mode,
+                              uint32_t flags,
+                              const SkMatrix* localMatrix,
+                              const SkMatrix* globalMatrix) {
+    if (!FLAGS_verbose) {
+        return;
+    }
+
+    SkDebugf("--- fuzzLinearGradient ---\n");
+    SkDebugf("  pts:\t\t[ (%f %f) (%f %f) ]\n",
+             pts[0].x(), pts[0].y(), pts[1].x(), pts[1].y());
+    SkDebugf("  colors:\t[ ");
+    for (auto color : colors) {
+        SkDebugf("0x%x ", color);
+    }
+
+    SkDebugf("]\n  pos:\t\t");
+    if (pos.empty()) {
+        SkDebugf("nullptr");
+    } else {
+        SkDebugf("[ ");
+        for (auto p : pos) {
+            SkDebugf("%f ", p);
+        }
+    }
+    SkDebugf("]\n");
+
+    static const char* gModeName[] = {
+        "kClamp_TileMode", "kRepeat_TileMode", "kMirror_TileMode"
+    };
+    SkASSERT(mode < SK_ARRAY_COUNT(gModeName));
+    SkDebugf("  mode:\t\t%s\n", gModeName[mode]);
+    SkDebugf("  flags:\t0x%x\n", flags);
+    logOptionalMatrix("local matrix", localMatrix);
+    logOptionalMatrix("global matrix", globalMatrix);
+}
+
 void fuzzLinearGradient(Fuzz* fuzz) {
     SkPoint pts[2];
     fuzz->next(&pts[0].fX, &pts[0].fY, &pts[1].fX, &pts[1].fY);
@@ -76,10 +129,12 @@ void fuzzLinearGradient(Fuzz* fuzz) {
     if (useGlobalMatrix) {
         SkMatrix gm;
         makeMatrix(fuzz, &gm);
+        logLinearGradient(pts, colors, pos, mode, flags, localMatrix.getMaybeNull(), &gm);
         SkCanvas* c = surface->getCanvas();
         c->setMatrix(gm);
         c->drawPaint(p);
     } else {
+        logLinearGradient(pts, colors, pos, mode, flags, localMatrix.getMaybeNull(), nullptr);
         surface->getCanvas()->drawPaint(p);
     }
 }