2013-04-01 12:51:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
#include "Benchmark.h"
|
2013-04-01 12:51:34 +00:00
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkPaint.h"
|
|
|
|
#include "SkRandom.h"
|
|
|
|
#include "SkString.h"
|
|
|
|
#include "SkXfermode.h"
|
|
|
|
|
2015-05-13 18:54:00 +00:00
|
|
|
// Benchmark that draws non-AA rects or AA text with an SkXfermode::Mode.
|
2014-06-19 19:32:29 +00:00
|
|
|
class XfermodeBench : public Benchmark {
|
2013-04-01 12:51:34 +00:00
|
|
|
public:
|
2015-05-13 18:54:00 +00:00
|
|
|
XfermodeBench(SkXfermode::Mode mode, bool aa) {
|
2013-04-01 12:51:34 +00:00
|
|
|
fXfermode.reset(SkXfermode::Create(mode));
|
2015-05-13 18:54:00 +00:00
|
|
|
fAA = aa;
|
2014-09-05 20:34:00 +00:00
|
|
|
SkASSERT(fXfermode.get() || SkXfermode::kSrcOver_Mode == mode);
|
2015-05-13 18:54:00 +00:00
|
|
|
fName.printf("Xfermode_%s%s", SkXfermode::ModeName(mode), aa ? "_aa" : "");
|
2013-04-01 12:51:34 +00:00
|
|
|
}
|
|
|
|
|
2015-05-13 18:54:00 +00:00
|
|
|
XfermodeBench(SkXfermode* xferMode, const char* name, bool aa) {
|
2014-09-05 20:34:00 +00:00
|
|
|
SkASSERT(xferMode);
|
2013-08-23 13:13:12 +00:00
|
|
|
fXfermode.reset(xferMode);
|
2015-05-13 18:54:00 +00:00
|
|
|
fAA = aa;
|
|
|
|
fName.printf("Xfermode_%s%s", name, aa ? "_aa" : "");
|
2013-08-23 13:13:12 +00:00
|
|
|
}
|
|
|
|
|
2013-04-01 12:51:34 +00:00
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override { return fName.c_str(); }
|
2013-04-01 12:51:34 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(const int loops, SkCanvas* canvas) override {
|
2015-05-13 18:54:00 +00:00
|
|
|
const char* text = "Hamburgefons";
|
|
|
|
size_t len = strlen(text);
|
2013-04-01 12:51:34 +00:00
|
|
|
SkISize size = canvas->getDeviceSize();
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom random;
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; ++i) {
|
2013-04-01 12:51:34 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setXfermode(fXfermode.get());
|
|
|
|
paint.setColor(random.nextU());
|
2015-05-13 18:54:00 +00:00
|
|
|
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);
|
|
|
|
}
|
2015-04-02 19:46:24 +00:00
|
|
|
}
|
2013-04-01 12:51:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SkAutoTUnref<SkXfermode> fXfermode;
|
|
|
|
SkString fName;
|
2015-05-13 18:54:00 +00:00
|
|
|
bool fAA;
|
2013-04-02 07:01:34 +00:00
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2013-04-01 12:51:34 +00:00
|
|
|
};
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class XferCreateBench : public Benchmark {
|
2013-10-04 16:52:55 +00:00
|
|
|
public:
|
2015-03-26 01:17:31 +00:00
|
|
|
bool isSuitableFor(Backend backend) override {
|
2013-11-21 06:21:58 +00:00
|
|
|
return backend == kNonRendering_Backend;
|
2013-10-04 16:52:55 +00:00
|
|
|
}
|
2013-10-05 07:01:34 +00:00
|
|
|
|
2013-10-04 16:52:55 +00:00
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override { return "xfermode_create"; }
|
2013-10-04 16:52:55 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(const int loops, SkCanvas* canvas) override {
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int outer = 0; outer < loops * 10; ++outer) {
|
2013-10-04 16:52:55 +00:00
|
|
|
for (int i = 0; i <= SkXfermode::kLastMode; ++i) {
|
|
|
|
SkXfermode* xfer = SkXfermode::Create(SkXfermode::Mode(i));
|
|
|
|
SkSafeUnref(xfer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-10-05 07:01:34 +00:00
|
|
|
|
2013-10-04 16:52:55 +00:00
|
|
|
private:
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2013-10-04 16:52:55 +00:00
|
|
|
};
|
|
|
|
|
2013-04-01 12:51:34 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-05-13 18:54:00 +00:00
|
|
|
#define BENCH(...) \
|
|
|
|
DEF_BENCH( return new XfermodeBench(__VA_ARGS__, true); ) \
|
|
|
|
DEF_BENCH( return new XfermodeBench(__VA_ARGS__, false); )
|
2013-08-23 13:13:12 +00:00
|
|
|
|
|
|
|
BENCH(SkXfermode::kClear_Mode)
|
|
|
|
BENCH(SkXfermode::kSrc_Mode)
|
|
|
|
BENCH(SkXfermode::kDst_Mode)
|
|
|
|
BENCH(SkXfermode::kSrcOver_Mode)
|
|
|
|
BENCH(SkXfermode::kDstOver_Mode)
|
|
|
|
BENCH(SkXfermode::kSrcIn_Mode)
|
|
|
|
BENCH(SkXfermode::kDstIn_Mode)
|
|
|
|
BENCH(SkXfermode::kSrcOut_Mode)
|
|
|
|
BENCH(SkXfermode::kDstOut_Mode)
|
|
|
|
BENCH(SkXfermode::kSrcATop_Mode)
|
|
|
|
BENCH(SkXfermode::kDstATop_Mode)
|
|
|
|
BENCH(SkXfermode::kXor_Mode)
|
|
|
|
|
|
|
|
BENCH(SkXfermode::kPlus_Mode)
|
|
|
|
BENCH(SkXfermode::kModulate_Mode)
|
|
|
|
BENCH(SkXfermode::kScreen_Mode)
|
|
|
|
|
|
|
|
BENCH(SkXfermode::kOverlay_Mode)
|
|
|
|
BENCH(SkXfermode::kDarken_Mode)
|
|
|
|
BENCH(SkXfermode::kLighten_Mode)
|
|
|
|
BENCH(SkXfermode::kColorDodge_Mode)
|
|
|
|
BENCH(SkXfermode::kColorBurn_Mode)
|
|
|
|
BENCH(SkXfermode::kHardLight_Mode)
|
|
|
|
BENCH(SkXfermode::kSoftLight_Mode)
|
|
|
|
BENCH(SkXfermode::kDifference_Mode)
|
|
|
|
BENCH(SkXfermode::kExclusion_Mode)
|
|
|
|
BENCH(SkXfermode::kMultiply_Mode)
|
|
|
|
|
|
|
|
BENCH(SkXfermode::kHue_Mode)
|
|
|
|
BENCH(SkXfermode::kSaturation_Mode)
|
|
|
|
BENCH(SkXfermode::kColor_Mode)
|
|
|
|
BENCH(SkXfermode::kLuminosity_Mode)
|
2013-04-01 12:51:34 +00:00
|
|
|
|
2013-10-04 16:52:55 +00:00
|
|
|
DEF_BENCH(return new XferCreateBench;)
|