Index: bench/FSRectBench.cpp |
diff --git a/bench/FSRectBench.cpp b/bench/FSRectBench.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a4dff69de32bafdb7020e56d9bf9091a708d8cf7 |
--- /dev/null |
+++ b/bench/FSRectBench.cpp |
@@ -0,0 +1,53 @@ |
+ |
+/* |
+ * Copyright 2013 Google Inc. |
+ * |
+ * Use of this source code is governed by a BSD-style license that can be |
+ * found in the LICENSE file. |
+ */ |
+ |
+#include "SkBenchmark.h" |
+#include "SkCanvas.h" |
+#include "SkPaint.h" |
+#include "SkRandom.h" |
+ |
robertphillips
2013/08/01 17:50:14
comment r.e. what it is supposed to hit?
bsalomon
2013/08/02 19:35:10
Done.
|
+class FSRectBench : public SkBenchmark { |
+public: |
+ FSRectBench(void* param) |
+ : INHERITED(param) { |
robertphillips
2013/08/01 17:50:14
MWC?
bsalomon
2013/08/02 19:35:10
Done.
|
+ SkRandom rand; |
+ static const SkScalar kMinOffset = 0; |
robertphillips
2013/08/01 17:50:14
Move this setup out of the ctor and into onPreDraw
bsalomon
2013/08/02 19:35:10
Done.
|
+ static const SkScalar kMaxOffset = 100 * SK_Scalar1; |
+ static const SkScalar kOffsetRange = kMaxOffset - kMinOffset; |
robertphillips
2013/08/01 17:50:14
pre++?
bsalomon
2013/08/02 19:35:10
Done.
|
+ for (int i = 0; i < N; i++) { |
+ fRects[i].fLeft = -kMinOffset - SkScalarMul(rand.nextUScalar1(), kOffsetRange); |
+ fRects[i].fTop = -kMinOffset - SkScalarMul(rand.nextUScalar1(), kOffsetRange); |
+ fRects[i].fRight = W + kMinOffset + SkScalarMul(rand.nextUScalar1(), kOffsetRange); |
+ fRects[i].fBottom = H + kMinOffset + SkScalarMul(rand.nextUScalar1(), kOffsetRange); |
+ fColors[i] = rand.nextU() | 0xFF000000; |
+ } |
+ } |
+ |
+protected: |
+ virtual const char* onGetName() SK_OVERRIDE { return "fullscreen_rects"; } |
+ virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
+ SkPaint paint; |
robertphillips
2013/08/01 17:50:14
pre++?
bsalomon
2013/08/02 19:35:10
Done.
|
+ for (int i = 0; i < N; i++) { |
+ paint.setColor(fColors[i]); |
+ canvas->drawRect(fRects[i], paint); |
+ } |
+ } |
+ |
+private: |
+ enum { |
+ W = 640, |
+ H = 480, |
+ N = SkBENCHLOOP(300) |
+ }; |
+ SkRect fRects[N]; |
+ SkColor fColors[N]; |
+ |
+ typedef SkBenchmark INHERITED; |
+}; |
+ |
+DEF_BENCH( return SkNEW_ARGS(FSRectBench, (p)); ) |