aboutsummaryrefslogtreecommitdiffhomepage
path: root/bench
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2015-05-13 11:54:00 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-05-13 11:54:00 -0700
commitd0a1088bf747a9291a178cb08e162d2c84a9aa7c (patch)
tree2ed266106341594ac9226ae1f475686175bf3086 /bench
parent19e4c02a4112f9a9c63247613c201dbba84110b4 (diff)
Add _aa variants of Xfermode benches.
Also, allow multiple DEF_BENCH() per line by using __COUNTER__ instead of __LINE__. BUG=skia: Review URL: https://codereview.chromium.org/1140643004
Diffstat (limited to 'bench')
-rw-r--r--bench/Benchmark.h9
-rw-r--r--bench/XfermodeBench.cpp59
2 files changed, 39 insertions, 29 deletions
diff --git a/bench/Benchmark.h b/bench/Benchmark.h
index 5ba6e91108..22b52ab4e8 100644
--- a/bench/Benchmark.h
+++ b/bench/Benchmark.h
@@ -13,11 +13,10 @@
#include "SkString.h"
#include "SkTRegistry.h"
-#define DEF_BENCH(code) \
-namespace { \
-static Benchmark* SK_MACRO_APPEND_LINE(factory)(void*) { code; } \
-BenchRegistry SK_MACRO_APPEND_LINE(g_R_)(SK_MACRO_APPEND_LINE(factory)); \
-}
+#define DEF_BENCH3(code, N) \
+ static BenchRegistry gBench##N([](void*) -> Benchmark* { code; });
+#define DEF_BENCH2(code, N) DEF_BENCH3(code, N)
+#define DEF_BENCH(code) DEF_BENCH2(code, __COUNTER__)
/*
* With the above macros, you can register benches as follows (at the bottom
diff --git a/bench/XfermodeBench.cpp b/bench/XfermodeBench.cpp
index 1dddd87430..7e61826c79 100644
--- a/bench/XfermodeBench.cpp
+++ b/bench/XfermodeBench.cpp
@@ -13,52 +13,65 @@
#include "SkString.h"
#include "SkXfermode.h"
-// Benchmark that draws non-AA rects with an SkXfermode::Mode
+// Benchmark that draws non-AA rects or AA text with an SkXfermode::Mode.
class XfermodeBench : public Benchmark {
public:
- XfermodeBench(SkXfermode::Mode mode) {
+ XfermodeBench(SkXfermode::Mode mode, bool aa) {
fXfermode.reset(SkXfermode::Create(mode));
+ fAA = aa;
SkASSERT(fXfermode.get() || SkXfermode::kSrcOver_Mode == mode);
- fName.printf("Xfermode_%s", SkXfermode::ModeName(mode));
+ fName.printf("Xfermode_%s%s", SkXfermode::ModeName(mode), aa ? "_aa" : "");
}
- XfermodeBench(SkXfermode* xferMode, const char* name) {
+ XfermodeBench(SkXfermode* xferMode, const char* name, bool aa) {
SkASSERT(xferMode);
fXfermode.reset(xferMode);
- fName.printf("Xfermode_%s", name);
+ fAA = aa;
+ fName.printf("Xfermode_%s%s", name, aa ? "_aa" : "");
}
protected:
const char* onGetName() override { return fName.c_str(); }
void onDraw(const int loops, SkCanvas* canvas) override {
+ const char* text = "Hamburgefons";
+ size_t len = strlen(text);
SkISize size = canvas->getDeviceSize();
SkRandom random;
for (int i = 0; i < loops; ++i) {
SkPaint paint;
paint.setXfermode(fXfermode.get());
paint.setColor(random.nextU());
- SkScalar w = random.nextRangeScalar(SkIntToScalar(kMinSize), SkIntToScalar(kMaxSize));
- SkScalar h = random.nextRangeScalar(SkIntToScalar(kMinSize), SkIntToScalar(kMaxSize));
- SkRect rect = SkRect::MakeXYWH(
- random.nextUScalar1() * (size.fWidth - w),
- random.nextUScalar1() * (size.fHeight - h),
- w,
- h
- );
- for (int j = 0; j < 1000; ++j) {
- canvas->drawRect(rect, paint);
+ if (fAA) {
+ // Draw text to exercise AA code paths.
+ paint.setAntiAlias(true);
+ paint.setTextSize(random.nextRangeScalar(12, 96));
+ SkScalar x = random.nextRangeScalar(0, (SkScalar)size.fWidth),
+ y = random.nextRangeScalar(0, (SkScalar)size.fHeight);
+ for (int j = 0; j < 1000; ++j) {
+ canvas->drawText(text, len, x, y, paint);
+ }
+ } else {
+ // Draw rects to exercise non-AA code paths.
+ SkScalar w = random.nextRangeScalar(50, 100);
+ SkScalar h = random.nextRangeScalar(50, 100);
+ SkRect rect = SkRect::MakeXYWH(
+ random.nextUScalar1() * (size.fWidth - w),
+ random.nextUScalar1() * (size.fHeight - h),
+ w,
+ h
+ );
+ for (int j = 0; j < 1000; ++j) {
+ canvas->drawRect(rect, paint);
+ }
}
}
}
private:
- enum {
- kMinSize = 50,
- kMaxSize = 100,
- };
SkAutoTUnref<SkXfermode> fXfermode;
SkString fName;
+ bool fAA;
typedef Benchmark INHERITED;
};
@@ -87,11 +100,9 @@ private:
//////////////////////////////////////////////////////////////////////////////
-#define CONCAT_I(x, y) x ## y
-#define CONCAT(x, y) CONCAT_I(x, y) // allow for macro expansion
-#define BENCH(...) \
- DEF_BENCH( return new XfermodeBench(__VA_ARGS__); );\
-
+#define BENCH(...) \
+ DEF_BENCH( return new XfermodeBench(__VA_ARGS__, true); ) \
+ DEF_BENCH( return new XfermodeBench(__VA_ARGS__, false); )
BENCH(SkXfermode::kClear_Mode)
BENCH(SkXfermode::kSrc_Mode)