Move non-trivial work in RectBench() to onPreDraw.
Saw this on a profile where rects was filtered out. ಠ_ಠ
BUG=
R=reed@google.com
Author: mtklein@google.com
Review URL: https://codereview.chromium.org/93703003
git-svn-id: http://skia.googlecode.com/svn/trunk@12500 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/bench/RectBench.cpp b/bench/RectBench.cpp
index ee0f76b..9013044 100644
--- a/bench/RectBench.cpp
+++ b/bench/RectBench.cpp
@@ -28,24 +28,7 @@
RectBench(int shift, int stroke = 0)
: fShift(shift)
- , fStroke(stroke) {
- SkRandom rand;
- const SkScalar offset = SK_Scalar1/3;
- for (int i = 0; i < N; i++) {
- int x = rand.nextU() % W;
- int y = rand.nextU() % H;
- int w = rand.nextU() % W;
- int h = rand.nextU() % H;
- w >>= shift;
- h >>= shift;
- x -= w/2;
- y -= h/2;
- fRects[i].set(SkIntToScalar(x), SkIntToScalar(y),
- SkIntToScalar(x+w), SkIntToScalar(y+h));
- fRects[i].offset(offset, offset);
- fColors[i] = rand.nextU() | 0xFF808080;
- }
- }
+ , fStroke(stroke) {}
SkString fName;
const char* computeName(const char root[]) {
@@ -62,6 +45,26 @@
}
virtual const char* onGetName() { return computeName("rects"); }
+
+ virtual void onPreDraw() {
+ SkRandom rand;
+ const SkScalar offset = SK_Scalar1/3;
+ for (int i = 0; i < N; i++) {
+ int x = rand.nextU() % W;
+ int y = rand.nextU() % H;
+ int w = rand.nextU() % W;
+ int h = rand.nextU() % H;
+ w >>= fShift;
+ h >>= fShift;
+ x -= w/2;
+ y -= h/2;
+ fRects[i].set(SkIntToScalar(x), SkIntToScalar(y),
+ SkIntToScalar(x+w), SkIntToScalar(y+h));
+ fRects[i].offset(offset, offset);
+ fColors[i] = rand.nextU() | 0xFF808080;
+ }
+ }
+
virtual void onDraw(const int loops, SkCanvas* canvas) {
SkPaint paint;
if (fStroke > 0) {