aboutsummaryrefslogtreecommitdiffhomepage
path: root/bench/RectBench.cpp
diff options
context:
space:
mode:
authorGravatar mtklein@google.com <mtklein@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-09-10 19:23:38 +0000
committerGravatar mtklein@google.com <mtklein@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-09-10 19:23:38 +0000
commitc289743864e2ab926a95e617a5cd1d29b26d1825 (patch)
tree2c559da19185181efd8bd92791fb758af5969800 /bench/RectBench.cpp
parent55ebe8eca0063ab1f3979d629749bc41ec409ac1 (diff)
Major bench refactoring.
- Use FLAGS_. - Remove outer repeat loop. - Tune inner loop automatically. BUG=skia:1590 R=epoger@google.com, scroggo@google.com Review URL: https://codereview.chromium.org/23478013 git-svn-id: http://skia.googlecode.com/svn/trunk@11187 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'bench/RectBench.cpp')
-rw-r--r--bench/RectBench.cpp111
1 files changed, 60 insertions, 51 deletions
diff --git a/bench/RectBench.cpp b/bench/RectBench.cpp
index 99ff0a94f1..ebf270d8e3 100644
--- a/bench/RectBench.cpp
+++ b/bench/RectBench.cpp
@@ -7,10 +7,13 @@
*/
#include "SkBenchmark.h"
#include "SkCanvas.h"
+#include "SkCommandLineFlags.h"
#include "SkPaint.h"
#include "SkRandom.h"
-#include "SkString.h"
#include "SkShader.h"
+#include "SkString.h"
+
+DEFINE_double(strokeWidth, -1.0, "If set, use this stroke width in RectBench.");
class RectBench : public SkBenchmark {
public:
@@ -18,7 +21,7 @@ public:
enum {
W = 640,
H = 480,
- N = SkBENCHLOOP(300)
+ N = 300,
};
SkRect fRects[N];
SkColor fColors[N];
@@ -66,10 +69,10 @@ protected:
paint.setStyle(SkPaint::kStroke_Style);
paint.setStrokeWidth(SkIntToScalar(fStroke));
}
- for (int i = 0; i < N; i++) {
- paint.setColor(fColors[i]);
+ for (int i = 0; i < this->getLoops(); i++) {
+ paint.setColor(fColors[i % N]);
this->setupPaint(&paint);
- this->drawThisRect(canvas, fRects[i], paint);
+ this->drawThisRect(canvas, fRects[i % N], paint);
}
}
private:
@@ -144,19 +147,21 @@ protected:
};
size_t sizes = SK_ARRAY_COUNT(gSizes);
- if (this->hasStrokeWidth()) {
- gSizes[0] = this->getStrokeWidth();
+ if (FLAGS_strokeWidth >= 0) {
+ gSizes[0] = FLAGS_strokeWidth;
sizes = 1;
}
SkPaint paint;
paint.setStrokeCap(SkPaint::kRound_Cap);
- for (size_t i = 0; i < sizes; i++) {
- paint.setStrokeWidth(gSizes[i]);
- this->setupPaint(&paint);
- canvas->drawPoints(fMode, N * 2, SkTCast<SkPoint*>(fRects), paint);
- paint.setColor(fColors[i]);
+ for (int loop = 0; loop < this->getLoops(); loop++) {
+ for (size_t i = 0; i < sizes; i++) {
+ paint.setStrokeWidth(gSizes[i]);
+ this->setupPaint(&paint);
+ canvas->drawPoints(fMode, N * 2, SkTCast<SkPoint*>(fRects), paint);
+ paint.setColor(fColors[i % N]);
+ }
}
}
virtual const char* onGetName() { return fName; }
@@ -190,21 +195,23 @@ protected:
SkRect r = { -kHalfRectSize, -kHalfRectSize, kHalfRectSize, kHalfRectSize };
int rot = 0;
- // Draw small aa rects in a grid across the screen
- for (SkScalar y = kHalfRectSize+SK_Scalar1; y < H; y += 2*kHalfRectSize+2) {
- for (SkScalar x = kHalfRectSize+SK_Scalar1; x < W; x += 2*kHalfRectSize+2) {
- canvas->save();
- canvas->translate(x, y);
-
- if (fRotate) {
- SkMatrix rotate;
- rotate.setRotate(SkIntToScalar(rot));
- canvas->concat(rotate);
- rot += 10;
+ for (int i = 0; i < this->getLoops(); i++) {
+ // Draw small aa rects in a grid across the screen
+ for (SkScalar y = kHalfRectSize+SK_Scalar1; y < H; y += 2*kHalfRectSize+2) {
+ for (SkScalar x = kHalfRectSize+SK_Scalar1; x < W; x += 2*kHalfRectSize+2) {
+ canvas->save();
+ canvas->translate(x, y);
+
+ if (fRotate) {
+ SkMatrix rotate;
+ rotate.setRotate(SkIntToScalar(rot));
+ canvas->concat(rotate);
+ rot += 10;
+ }
+
+ canvas->drawRect(r, paint);
+ canvas->restore();
}
-
- canvas->drawRect(r, paint);
- canvas->restore();
}
}
@@ -242,8 +249,8 @@ protected:
};
size_t sizes = SK_ARRAY_COUNT(gSizes);
- if (this->hasStrokeWidth()) {
- gSizes[0] = this->getStrokeWidth();
+ if (FLAGS_strokeWidth >= 0) {
+ gSizes[0] = FLAGS_strokeWidth;
sizes = 1;
}
SkRandom rand;
@@ -262,29 +269,31 @@ protected:
SkShader::kClamp_TileMode);
paint.setShader(s)->unref();
}
- for (size_t i = 0; i < sizes; i++) {
- switch (_type) {
- case kMaskOpaque:
- color = fColors[i];
- alpha = 0xFF;
- break;
- case kMaskBlack:
- alpha = 0xFF;
- color = 0xFF000000;
- break;
- case kMaskColor:
- color = fColors[i];
- alpha = rand.nextU() & 255;
- break;
- case KMaskShader:
- break;
- }
- paint.setStrokeWidth(gSizes[i]);
- this->setupPaint(&paint);
- paint.setColor(color);
- paint.setAlpha(alpha);
- canvas->drawPoints(fMode, N * 2, SkTCast<SkPoint*>(fRects), paint);
- }
+ for (int loop = 0; loop < this->getLoops(); loop++) {
+ for (size_t i = 0; i < sizes; i++) {
+ switch (_type) {
+ case kMaskOpaque:
+ color = fColors[i];
+ alpha = 0xFF;
+ break;
+ case kMaskBlack:
+ alpha = 0xFF;
+ color = 0xFF000000;
+ break;
+ case kMaskColor:
+ color = fColors[i];
+ alpha = rand.nextU() & 255;
+ break;
+ case KMaskShader:
+ break;
+ }
+ paint.setStrokeWidth(gSizes[i]);
+ this->setupPaint(&paint);
+ paint.setColor(color);
+ paint.setAlpha(alpha);
+ canvas->drawPoints(fMode, N * 2, SkTCast<SkPoint*>(fRects), paint);
+ }
+ }
}
virtual const char* onGetName() { return fName; }
private: