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.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "bench/Benchmark.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkFont.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/core/SkTextBlob.h"
|
|
|
|
#include "include/utils/SkRandom.h"
|
|
|
|
#include "src/core/SkBlendModePriv.h"
|
2013-04-01 12:51:34 +00:00
|
|
|
|
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:
|
2016-10-06 00:33:02 +00:00
|
|
|
XfermodeBench(SkBlendMode mode, bool aa) : fBlendMode(mode) {
|
2015-05-13 18:54:00 +00:00
|
|
|
fAA = aa;
|
2017-07-04 13:05:32 +00:00
|
|
|
fName.printf("blendmode_%s_%s", aa ? "mask" : "rect", SkBlendMode_Name(mode));
|
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-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2015-05-13 18:54:00 +00:00
|
|
|
const char* text = "Hamburgefons";
|
|
|
|
size_t len = strlen(text);
|
2017-02-22 18:21:42 +00:00
|
|
|
SkISize size = canvas->getBaseLayerSize();
|
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;
|
2016-10-06 00:33:02 +00:00
|
|
|
paint.setBlendMode(fBlendMode);
|
2013-04-01 12:51:34 +00:00
|
|
|
paint.setColor(random.nextU());
|
2015-05-13 18:54:00 +00:00
|
|
|
if (fAA) {
|
|
|
|
// Draw text to exercise AA code paths.
|
2019-01-04 04:29:38 +00:00
|
|
|
SkFont font;
|
|
|
|
font.setSize(random.nextRangeScalar(12, 96));
|
2015-05-13 18:54:00 +00:00
|
|
|
SkScalar x = random.nextRangeScalar(0, (SkScalar)size.fWidth),
|
|
|
|
y = random.nextRangeScalar(0, (SkScalar)size.fHeight);
|
2019-05-07 19:38:46 +00:00
|
|
|
auto blob = SkTextBlob::MakeFromText(text, len, font, SkTextEncoding::kUTF8);
|
2015-05-13 18:54:00 +00:00
|
|
|
for (int j = 0; j < 1000; ++j) {
|
2019-01-04 04:29:38 +00:00
|
|
|
canvas->drawTextBlob(blob, x, y, paint);
|
2015-05-13 18:54:00 +00:00
|
|
|
}
|
|
|
|
} 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:
|
2016-10-06 00:33:02 +00:00
|
|
|
SkBlendMode fBlendMode;
|
|
|
|
SkString fName;
|
|
|
|
bool fAA;
|
2013-04-02 07:01:34 +00:00
|
|
|
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = Benchmark;
|
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
|
|
|
|
2016-10-06 00:33:02 +00:00
|
|
|
BENCH(SkBlendMode::kClear)
|
|
|
|
BENCH(SkBlendMode::kSrc)
|
|
|
|
BENCH(SkBlendMode::kDst)
|
|
|
|
BENCH(SkBlendMode::kSrcOver)
|
|
|
|
BENCH(SkBlendMode::kDstOver)
|
|
|
|
BENCH(SkBlendMode::kSrcIn)
|
|
|
|
BENCH(SkBlendMode::kDstIn)
|
|
|
|
BENCH(SkBlendMode::kSrcOut)
|
|
|
|
BENCH(SkBlendMode::kDstOut)
|
|
|
|
BENCH(SkBlendMode::kSrcATop)
|
|
|
|
BENCH(SkBlendMode::kDstATop)
|
|
|
|
BENCH(SkBlendMode::kXor)
|
|
|
|
|
|
|
|
BENCH(SkBlendMode::kPlus)
|
|
|
|
BENCH(SkBlendMode::kModulate)
|
|
|
|
BENCH(SkBlendMode::kScreen)
|
|
|
|
|
|
|
|
BENCH(SkBlendMode::kOverlay)
|
|
|
|
BENCH(SkBlendMode::kDarken)
|
|
|
|
BENCH(SkBlendMode::kLighten)
|
|
|
|
BENCH(SkBlendMode::kColorDodge)
|
|
|
|
BENCH(SkBlendMode::kColorBurn)
|
|
|
|
BENCH(SkBlendMode::kHardLight)
|
|
|
|
BENCH(SkBlendMode::kSoftLight)
|
|
|
|
BENCH(SkBlendMode::kDifference)
|
|
|
|
BENCH(SkBlendMode::kExclusion)
|
|
|
|
BENCH(SkBlendMode::kMultiply)
|
|
|
|
|
|
|
|
BENCH(SkBlendMode::kHue)
|
|
|
|
BENCH(SkBlendMode::kSaturation)
|
|
|
|
BENCH(SkBlendMode::kColor)
|
|
|
|
BENCH(SkBlendMode::kLuminosity)
|