add optional --forceBWtext to gm, forcing all text to BW to ease
comparisons between platform variations (e.g. mac 10.5,6,7)

probably only make sense in conjunction with some flag on GM allowing
the slide to opt in-or-out, so we only hack text labels, and not GMs
that are explicitly trying to test text rendering.



git-svn-id: http://skia.googlecode.com/svn/trunk@2938 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gm/gmmain.cpp b/gm/gmmain.cpp
index 8f78c41..0c41418 100644
--- a/gm/gmmain.cpp
+++ b/gm/gmmain.cpp
@@ -23,6 +23,8 @@
 #include "SkStream.h"
 #include "SkRefCnt.h"
 
+static bool gForceBWtext;
+
 extern bool gSkSuppressFontCachePurgeSpew;
 
 #ifdef SK_SUPPORT_PDF
@@ -240,6 +242,29 @@
     bitmap->eraseColor(0);
 }
 
+#include "SkDrawFilter.h"
+class BWTextDrawFilter : public SkDrawFilter {
+public:
+    virtual void filter(SkPaint*, Type) SK_OVERRIDE;
+};
+void BWTextDrawFilter::filter(SkPaint* p, Type t) {
+    if (kText_Type == t) {
+        p->setAntiAlias(false);
+    }
+}
+
+static void installFilter(SkCanvas* canvas) {
+    if (gForceBWtext) {
+        canvas->setDrawFilter(new BWTextDrawFilter)->unref();
+    }
+}
+
+static void invokeGM(GM* gm, SkCanvas* canvas) {
+    installFilter(canvas);
+    gm->draw(canvas);
+    canvas->setDrawFilter(NULL);
+}
+
 static ErrorBitfield generate_image(GM* gm, const ConfigData& gRec,
                                     GrContext* context,
                                     GrRenderTarget* rt,
@@ -249,14 +274,14 @@
     SkCanvas canvas(*bitmap);
 
     if (gRec.fBackend == kRaster_Backend) {
-        gm->draw(&canvas);
+        invokeGM(gm, &canvas);
     } else {  // GPU
         if (NULL == context) {
             return ERROR_NO_GPU_CONTEXT;
         }
         SkGpuCanvas gc(context, rt);
         gc.setDevice(new SkGpuDevice(context, rt))->unref();
-        gm->draw(&gc);
+        invokeGM(gm, &gc);
         // the device is as large as the current rendertarget, so we explicitly
         // only readback the amount we expect (in size)
         // overwrite our previous allocation
@@ -272,6 +297,7 @@
     SkISize size = gm->getISize();
     setup_bitmap(gRec, size, bitmap);
     SkCanvas canvas(*bitmap);
+    installFilter(&canvas);
     canvas.drawPicture(*pict);
 }
 
@@ -284,7 +310,7 @@
     SkAutoUnref aur(dev);
 
     SkCanvas c(dev);
-    gm->draw(&c);
+    invokeGM(gm, &c);
 
     SkPDFDocument doc;
     doc.appendPage(dev);
@@ -312,7 +338,7 @@
     SkCanvas c(dev);
     dev->beginPortfolio(&xps);
     dev->beginSheet(unitsPerMeter, pixelsPerMeter, trimSize);
-    gm->draw(&c);
+    invokeGM(gm, &c);
     dev->endSheet();
     dev->endPortfolio();
 
@@ -420,7 +446,7 @@
     // Pictures are refcounted so must be on heap
     SkPicture* pict = new SkPicture;
     SkCanvas* cv = pict->beginRecording(1000, 1000);
-    gm->draw(cv);
+    invokeGM(gm, cv);
     pict->endRecording();
 
     return pict;
@@ -607,6 +633,8 @@
             if (argv < stop && **argv) {
                 diffPath = *argv;
             }
+        } else if (strcmp(*argv, "--forceBWtext") == 0) {
+            gForceBWtext = true;
         } else if (strcmp(*argv, "--noreplay") == 0) {
             doReplay = false;
         } else if (strcmp(*argv, "--nopdf") == 0) {