From c289743864e2ab926a95e617a5cd1d29b26d1825 Mon Sep 17 00:00:00 2001 From: "mtklein@google.com" Date: Tue, 10 Sep 2013 19:23:38 +0000 Subject: 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 --- bench/RectBench.cpp | 111 ++++++++++++++++++++++++++++------------------------ 1 file changed, 60 insertions(+), 51 deletions(-) (limited to 'bench/RectBench.cpp') 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(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(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(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(fRects), paint); + } + } } virtual const char* onGetName() { return fName; } private: -- cgit v1.2.3