Extend blendmodes bench to time sprites

Change-Id: I3801e869d8a2e177dae108a494a221d502c3caaf
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/425182
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
Mike Reed 2021-07-07 11:05:42 -04:00 committed by Skia Commit-Bot
parent 66657d17c6
commit cd947ac177

View File

@ -13,18 +13,37 @@
#include "include/core/SkTextBlob.h"
#include "include/utils/SkRandom.h"
#include "src/core/SkBlendModePriv.h"
#include "tools/Resources.h"
namespace {
enum Type {
kText,
kRect,
kSprite,
};
}
const char* gTypeNames[] = {
"mask", "rect", "sprite",
};
// Benchmark that draws non-AA rects or AA text with an SkXfermode::Mode.
class XfermodeBench : public Benchmark {
public:
XfermodeBench(SkBlendMode mode, bool aa) : fBlendMode(mode) {
fAA = aa;
fName.printf("blendmicro_%s_%s", aa ? "mask" : "rect", SkBlendMode_Name(mode));
XfermodeBench(SkBlendMode mode, Type t) : fBlendMode(mode) {
fType = t;
fName.printf("blendmicro_%s_%s", gTypeNames[t], SkBlendMode_Name(mode));
}
protected:
const char* onGetName() override { return fName.c_str(); }
void onDelayedSetup() override {
if (fType == kSprite) {
fImage = GetResourceAsImage("images/color_wheel.png");
}
}
void onDraw(int loops, SkCanvas* canvas) override {
const char* text = "Hamburgefons";
size_t len = strlen(text);
@ -34,7 +53,8 @@ protected:
SkPaint paint;
paint.setBlendMode(fBlendMode);
paint.setColor(random.nextU());
if (fAA) {
switch (fType) {
case kText: {
// Draw text to exercise AA code paths.
SkFont font;
font.setSize(random.nextRangeScalar(12, 96));
@ -46,7 +66,8 @@ protected:
canvas->drawTextBlob(blob, x, y, paint);
}
loops -= iterations;
} else {
} break;
case kRect: {
// Draw rects to exercise non-AA code paths.
SkScalar w = random.nextRangeScalar(50, 100);
SkScalar h = random.nextRangeScalar(50, 100);
@ -61,23 +82,37 @@ protected:
canvas->drawRect(rect, paint);
}
loops -= iterations;
} break;
case kSprite:
paint.setAlphaf(1.0f);
for (int i = 0; i < 10; ++i) {
canvas->drawImage(fImage, 0, 0, SkSamplingOptions(), &paint);
}
loops -= 1;
break;
}
}
}
bool isSuitableFor(Backend backend) override {
return backend == kRaster_Backend;
}
private:
SkBlendMode fBlendMode;
SkString fName;
bool fAA;
sk_sp<SkImage> fImage;
Type fType;
using INHERITED = Benchmark;
};
//////////////////////////////////////////////////////////////////////////////
#define BENCH(...) \
DEF_BENCH( return new XfermodeBench(__VA_ARGS__, true); ) \
DEF_BENCH( return new XfermodeBench(__VA_ARGS__, false); )
#define BENCH(mode) \
DEF_BENCH( return new XfermodeBench(mode, kText); ) \
DEF_BENCH( return new XfermodeBench(mode, kRect); ) \
DEF_BENCH( return new XfermodeBench(mode, kSprite); )
BENCH(SkBlendMode::kClear)
BENCH(SkBlendMode::kSrc)