aboutsummaryrefslogtreecommitdiffhomepage
path: root/bench/AAClipBench.cpp
diff options
context:
space:
mode:
authorGravatar robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-05-09 15:48:31 +0000
committerGravatar robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-05-09 15:48:31 +0000
commit6bb99e36ca9ff27320d6a349d2639f362400db0c (patch)
tree4a9a73e51bd429623f6bc738d88332936776f022 /bench/AAClipBench.cpp
parentde3613273bc01d3f78f03ebbea2b8c8e7031d316 (diff)
Added new bench test for nested clips
Diffstat (limited to 'bench/AAClipBench.cpp')
-rw-r--r--bench/AAClipBench.cpp105
1 files changed, 101 insertions, 4 deletions
diff --git a/bench/AAClipBench.cpp b/bench/AAClipBench.cpp
index ea4f6da5ac..ca77082168 100644
--- a/bench/AAClipBench.cpp
+++ b/bench/AAClipBench.cpp
@@ -11,7 +11,7 @@
#include "SkRegion.h"
#include "SkString.h"
#include "SkCanvas.h"
-
+#include "SkRandom.h"
////////////////////////////////////////////////////////////////////////////////
// This bench tests out AA/BW clipping via canvas' clipPath and clipRect calls
@@ -29,9 +29,9 @@ class AAClipBench : public SkBenchmark {
public:
AAClipBench(void* param, bool doPath, bool doAA)
- : INHERITED(param) {
- fDoPath = doPath;
- fDoAA = doAA;
+ : INHERITED(param)
+ , fDoPath(doPath)
+ , fDoAA(doAA) {
fName.printf("aaclip_%s_%s",
doPath ? "path" : "rect",
@@ -88,6 +88,98 @@ private:
};
////////////////////////////////////////////////////////////////////////////////
+// This bench tests out nested clip stacks. It is intended to simulate
+// how WebKit nests clips.
+class NestedAAClipBench : public SkBenchmark {
+ SkString fName;
+ bool fDoAA;
+ SkRect fDrawRect;
+ SkRandom fRandom;
+
+ static const int kNumDraws = SkBENCHLOOP(200);
+ static const int kNestingDepth = 4;
+ static const int kImageSize = 400;
+
+ SkPoint fSizes[kNestingDepth+1];
+
+public:
+ NestedAAClipBench(void* param, bool doAA)
+ : INHERITED(param)
+ , fDoAA(doAA) {
+
+ fName.printf("nested_aaclip_%s", doAA ? "AA" : "BW");
+
+ fDrawRect = SkRect::MakeLTRB(0, 0,
+ SkIntToScalar(kImageSize),
+ SkIntToScalar(kImageSize));
+
+ fSizes[0].set(SkIntToScalar(kImageSize), SkIntToScalar(kImageSize));
+
+ for (int i = 1; i < kNestingDepth+1; ++i) {
+ fSizes[i].set(fSizes[i-1].fX/2, fSizes[i-1].fY/2);
+ }
+ }
+
+protected:
+ virtual const char* onGetName() { return fName.c_str(); }
+
+
+ void recurse(SkCanvas* canvas,
+ int depth,
+ const SkPoint& offset) {
+
+ canvas->save();
+
+ SkRect temp = SkRect::MakeLTRB(0, 0,
+ fSizes[depth].fX, fSizes[depth].fY);
+ temp.offset(offset);
+
+ SkPath path;
+ path.addRoundRect(temp, SkIntToScalar(3), SkIntToScalar(3));
+ SkASSERT(path.isConvex());
+
+ canvas->clipPath(path,
+ 0 == depth ? SkRegion::kReplace_Op :
+ SkRegion::kIntersect_Op,
+ fDoAA);
+
+ if (kNestingDepth == depth) {
+ // we only draw the draw rect at the lowest nesting level
+ SkPaint paint;
+ paint.setColor(0xff000000 | fRandom.nextU());
+ canvas->drawRect(fDrawRect, paint);
+ } else {
+ SkPoint childOffset = offset;
+ this->recurse(canvas, depth+1, childOffset);
+
+ childOffset += fSizes[depth+1];
+ this->recurse(canvas, depth+1, childOffset);
+
+ childOffset.fX = offset.fX + fSizes[depth+1].fX;
+ childOffset.fY = offset.fY;
+ this->recurse(canvas, depth+1, childOffset);
+
+ childOffset.fX = offset.fX;
+ childOffset.fY = offset.fY + fSizes[depth+1].fY;
+ this->recurse(canvas, depth+1, childOffset);
+ }
+
+ canvas->restore();
+ }
+
+ virtual void onDraw(SkCanvas* canvas) {
+
+ for (int i = 0; i < kNumDraws; ++i) {
+ SkPoint offset = SkPoint::Make(0, 0);
+ this->recurse(canvas, 0, offset);
+ }
+ }
+
+private:
+ typedef SkBenchmark INHERITED;
+};
+
+////////////////////////////////////////////////////////////////////////////////
class AAClipBuilderBench : public SkBenchmark {
SkString fName;
SkPath fPath;
@@ -191,3 +283,8 @@ static BenchRegistry gReg001(Fact001);
static BenchRegistry gReg002(Fact002);
static BenchRegistry gReg003(Fact003);
+static SkBenchmark* Fact004(void* p) { return SkNEW_ARGS(NestedAAClipBench, (p, false)); }
+static SkBenchmark* Fact005(void* p) { return SkNEW_ARGS(NestedAAClipBench, (p, true)); }
+
+static BenchRegistry gReg004(Fact004);
+static BenchRegistry gReg005(Fact005);