Chromium Code Reviews| Index: bench/RotatedRectBench.cpp |
| diff --git a/bench/RotatedRectBench.cpp b/bench/RotatedRectBench.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a28982f96f544b44d0097639f0e354af13619cb2 |
| --- /dev/null |
| +++ b/bench/RotatedRectBench.cpp |
| @@ -0,0 +1,93 @@ |
| +/* |
| + * Copyright 2014 Google Inc. |
| + * |
| + * Use of this source code is governed by a BSD-style license that can be |
| + * found in the LICENSE file. |
| + */ |
| + |
| +#include "Benchmark.h" |
| +#include "SkCanvas.h" |
| +#include "SkPaint.h" |
| + |
| +/** This benchmark tests rendering rotated rectangles. It can optionally apply AA and/or change the |
| + paint color between each rect. */ |
| +class RotRectBench: public Benchmark { |
| +public: |
| + RotRectBench(bool aa, bool changeColor) |
| + : fAA(aa) |
| + , fChangeColor(changeColor) { |
| + this->makeName(); |
| + } |
| + |
| +protected: |
| + virtual const char* onGetName() SK_OVERRIDE { return fName.c_str(); } |
| + |
| + virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
| + SkPaint paint; |
| + paint.setAntiAlias(fAA); |
| + SkColor color = 0xFF000000; |
| + |
| + int w = canvas->getBaseLayerSize().width(); |
| + int h = canvas->getBaseLayerSize().height(); |
| + |
| + static const SkScalar kRectW = 25.1f; |
| + static const SkScalar kRectH = 25.9f; |
| + |
| + SkMatrix rotate; |
| + // This value was chosen so that we frequently hit the axis-aligned case. |
| + rotate.setRotate(30.f, kRectW / 2, kRectH / 2); |
| + SkMatrix m = rotate; |
| + |
|
robertphillips
2014/07/30 14:55:22
offX, offY ? transX, transY ?
bsalomon
2014/07/30 15:46:39
Done.
|
| + SkScalar x = 0, y = 0; |
| + |
|
robertphillips
2014/07/30 14:55:22
++i ?
bsalomon
2014/07/30 15:46:39
Done.
|
| + for (int i = 0; i < loops; i++) { |
| + canvas->save(); |
| + canvas->translate(x, y); |
| + canvas->concat(m); |
| + paint.setColor(color); |
| + if (fChangeColor) { |
| + color += 0x010203; |
| + color |= 0xFF000000; |
| + } |
| + canvas->drawRect(SkRect::MakeWH(kRectW, kRectH), paint); |
| + canvas->restore(); |
| + |
| + x += kRectW + 2; |
| + if (x > w) { |
| + x = 0; |
| + y += kRectH + 2; |
| + if (y > h) { |
| + y = 0; |
| + } |
| + } |
| + |
| + m.postConcat(rotate); |
| + } |
| + } |
| + |
| +private: |
| + void makeName() { |
| + fName = "rotated_rects"; |
| + if (fAA) { |
| + fName.append("_aa"); |
| + } else { |
| + fName.append("_bw"); |
| + } |
| + if (fChangeColor) { |
| + fName.append("_change_color"); |
| + } else { |
| + fName.append("_same_color"); |
| + } |
| + } |
| + |
| + bool fAA; |
| + bool fChangeColor; |
| + SkString fName; |
| + |
| + typedef Benchmark INHERITED; |
| +}; |
| + |
| +DEF_BENCH(return new RotRectBench(true, true);) |
| +DEF_BENCH(return new RotRectBench(true, false);) |
| +DEF_BENCH(return new RotRectBench(false, true);) |
| +DEF_BENCH(return new RotRectBench(false, false);) |