From 4c1037238c8ebcef8c75b5d43730ed308a11102c Mon Sep 17 00:00:00 2001
From: Mike Reed <reed@google.com>
Date: Wed, 14 Apr 2010 10:16:53 -0400
Subject: refresh from trunk

Change-Id: I0175ec7482f8cf85d25165da360a5352979fd7a0
---
 bench/RectBench.cpp   | 13 +++++++++----
 bench/SkBenchmark.cpp |  1 +
 bench/SkBenchmark.h   | 16 +++++++++++++++-
 bench/benchmain.cpp   | 18 ++++++++++++++++++
 4 files changed, 43 insertions(+), 5 deletions(-)

(limited to 'bench')

diff --git a/bench/RectBench.cpp b/bench/RectBench.cpp
index 6f34eb5..3874bb3 100644
--- a/bench/RectBench.cpp
+++ b/bench/RectBench.cpp
@@ -89,14 +89,20 @@ public:
 
 protected:
     virtual void onDraw(SkCanvas* canvas) {
-        static const SkScalar gSizes[] = {
+        SkScalar gSizes[] = {
             SkIntToScalar(7), 0
         };
+        size_t sizes = SK_ARRAY_COUNT(gSizes);
+
+        if (this->hasStrokeWidth()) {
+            gSizes[0] = this->getStrokeWidth();
+            sizes = 1;
+        }
 
         SkPaint paint;
         paint.setStrokeCap(SkPaint::kRound_Cap);
-        
-        for (size_t i = 0; i < SK_ARRAY_COUNT(gSizes); i++) {
+
+        for (size_t i = 0; i < sizes; i++) {
             paint.setStrokeWidth(gSizes[i]);
             this->setupPaint(&paint);
             canvas->drawPoints(fMode, N * 2,
@@ -132,4 +138,3 @@ static BenchRegistry gRRectReg2(RRectFactory2);
 static BenchRegistry gPointsReg(PointsFactory);
 static BenchRegistry gLinesReg(LinesFactory);
 static BenchRegistry gPolygonReg(PolygonFactory);
-
diff --git a/bench/SkBenchmark.cpp b/bench/SkBenchmark.cpp
index e8bea6e..230a7af 100644
--- a/bench/SkBenchmark.cpp
+++ b/bench/SkBenchmark.cpp
@@ -9,6 +9,7 @@ SkBenchmark::SkBenchmark(void* defineDict) {
     fForceAlpha = 0xFF;
     fForceAA = true;
     fDither = SkTriState::kDefault;
+    fHasStrokeWidth = false;
 }
 
 const char* SkBenchmark::getName() {
diff --git a/bench/SkBenchmark.h b/bench/SkBenchmark.h
index bc9794a..945db80 100644
--- a/bench/SkBenchmark.h
+++ b/bench/SkBenchmark.h
@@ -42,6 +42,19 @@ public:
         fDither = state;
     }
 
+    void setStrokeWidth(SkScalar width) {
+      strokeWidth = width;
+      fHasStrokeWidth = true;
+    }
+
+    SkScalar getStrokeWidth() {
+      return strokeWidth;
+    }
+
+    bool hasStrokeWidth() {
+      return fHasStrokeWidth;
+    }
+
     const char* findDefine(const char* key) const;
     bool findDefine32(const char* key, int32_t* value) const;
     bool findDefineScalar(const char* key, SkScalar* value) const;
@@ -60,9 +73,10 @@ private:
     bool    fForceAA;
     bool    fForceFilter;
     SkTriState::State  fDither;
+    bool    fHasStrokeWidth;
+    SkScalar strokeWidth;
 };
 
 typedef SkTRegistry<SkBenchmark*, void*> BenchRegistry;
 
 #endif
-
diff --git a/bench/benchmain.cpp b/bench/benchmain.cpp
index 7443604..2f8b006 100644
--- a/bench/benchmain.cpp
+++ b/bench/benchmain.cpp
@@ -201,6 +201,8 @@ int main (int argc, char * const argv[]) {
     bool doClip = false;
     bool doPict = false;
     const char* matchStr = NULL;
+    bool hasStrokeWidth = false;
+    float strokeWidth;
 
     SkString outDir;
     SkBitmap::Config outConfig = SkBitmap::kNo_Config;
@@ -260,6 +262,19 @@ int main (int argc, char * const argv[]) {
                 return -1;
             }
             forceAlpha = wantAlpha ? 0x80 : 0xFF;
+        } else if (strcmp(*argv, "-strokeWidth") == 0) {
+            argv++;
+            if (argv < stop) {
+                const char *strokeWidthStr = *argv;
+                if (sscanf(strokeWidthStr, "%f", &strokeWidth) != 1) {
+                  log_error("bad arg for -strokeWidth\n");
+                  return -1;
+                }
+                hasStrokeWidth = true;
+            } else {
+                log_error("missing arg for -strokeWidth\n");
+                return -1;
+            }
         } else if (strcmp(*argv, "-match") == 0) {
             argv++;
             if (argv < stop) {
@@ -314,6 +329,9 @@ int main (int argc, char * const argv[]) {
         bench->setForceAA(forceAA);
         bench->setForceFilter(forceFilter);
         bench->setDither(forceDither);
+        if (hasStrokeWidth) {
+            bench->setStrokeWidth(strokeWidth);
+        }
 
         // only run benchmarks if their name contains matchStr
         if (matchStr && strstr(bench->getName(), matchStr) == NULL) {
-- 
cgit v1.1