2014-07-30 15:58:20 +00:00
|
|
|
/*
|
|
|
|
* 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"
|
|
|
|
|
2014-08-08 14:43:29 +00:00
|
|
|
#include <ctype.h>
|
|
|
|
|
2014-07-30 15:58:20 +00:00
|
|
|
/** This benchmark tests rendering rotated rectangles. It can optionally apply AA and/or change the
|
2014-08-08 14:43:29 +00:00
|
|
|
paint color between each rect in different ways using the ColorType enum. The xfermode used can
|
|
|
|
be specified as well.
|
|
|
|
*/
|
|
|
|
|
|
|
|
enum ColorType {
|
|
|
|
kConstantOpaque_ColorType,
|
|
|
|
kConstantTransparent_ColorType,
|
|
|
|
kChangingOpaque_ColorType,
|
|
|
|
kChangingTransparent_ColorType,
|
|
|
|
kAlternatingOpaqueAndTransparent_ColorType,
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline SkColor start_color(ColorType ct) {
|
|
|
|
switch (ct) {
|
|
|
|
case kConstantOpaque_ColorType:
|
|
|
|
case kChangingOpaque_ColorType:
|
|
|
|
case kAlternatingOpaqueAndTransparent_ColorType:
|
|
|
|
return 0xFFA07040;
|
|
|
|
case kConstantTransparent_ColorType:
|
|
|
|
case kChangingTransparent_ColorType:
|
|
|
|
return 0x80A07040;
|
|
|
|
}
|
|
|
|
SkFAIL("Shouldn't reach here.");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline SkColor advance_color(SkColor old, ColorType ct, int step) {
|
|
|
|
if (kAlternatingOpaqueAndTransparent_ColorType == ct) {
|
|
|
|
ct = (step & 0x1) ? kChangingOpaque_ColorType : kChangingTransparent_ColorType ;
|
|
|
|
}
|
|
|
|
switch (ct) {
|
|
|
|
case kConstantOpaque_ColorType:
|
|
|
|
case kConstantTransparent_ColorType:
|
|
|
|
return old;
|
|
|
|
case kChangingOpaque_ColorType:
|
|
|
|
return 0xFF000000 | (old + 0x00010307);
|
|
|
|
case kChangingTransparent_ColorType:
|
|
|
|
return (0x00FFFFFF & (old + 0x00010307)) | 0x80000000;
|
|
|
|
case kAlternatingOpaqueAndTransparent_ColorType:
|
|
|
|
SkFAIL("Can't get here");
|
|
|
|
}
|
|
|
|
SkFAIL("Shouldn't reach here.");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static SkString to_lower(const char* str) {
|
|
|
|
SkString lower(str);
|
|
|
|
for (size_t i = 0; i < lower.size(); i++) {
|
|
|
|
lower[i] = tolower(lower[i]);
|
|
|
|
}
|
|
|
|
return lower;
|
|
|
|
}
|
|
|
|
|
2014-07-30 15:58:20 +00:00
|
|
|
class RotRectBench: public Benchmark {
|
|
|
|
public:
|
2014-08-08 14:43:29 +00:00
|
|
|
RotRectBench(bool aa, ColorType ct, SkXfermode::Mode mode)
|
2014-07-30 15:58:20 +00:00
|
|
|
: fAA(aa)
|
2014-08-08 14:43:29 +00:00
|
|
|
, fColorType(ct)
|
|
|
|
, fMode(mode) {
|
2014-07-30 15:58:20 +00:00
|
|
|
this->makeName();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override { return fName.c_str(); }
|
2014-07-30 15:58:20 +00:00
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2014-07-30 15:58:20 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(fAA);
|
2014-08-08 14:43:29 +00:00
|
|
|
paint.setXfermodeMode(fMode);
|
|
|
|
SkColor color = start_color(fColorType);
|
2014-07-30 15:58:20 +00:00
|
|
|
|
2015-03-23 14:46:13 +00:00
|
|
|
int w = this->getSize().x();
|
|
|
|
int h = this->getSize().y();
|
2014-07-30 15:58:20 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
SkScalar tx = 0, ty = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < loops; ++i) {
|
|
|
|
canvas->save();
|
|
|
|
canvas->translate(tx, ty);
|
|
|
|
canvas->concat(m);
|
|
|
|
paint.setColor(color);
|
2014-08-08 14:43:29 +00:00
|
|
|
color = advance_color(color, fColorType, i);
|
|
|
|
|
2014-07-30 15:58:20 +00:00
|
|
|
canvas->drawRect(SkRect::MakeWH(kRectW, kRectH), paint);
|
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
tx += kRectW + 2;
|
|
|
|
if (tx > w) {
|
|
|
|
tx = 0;
|
|
|
|
ty += kRectH + 2;
|
|
|
|
if (ty > h) {
|
|
|
|
ty = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m.postConcat(rotate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void makeName() {
|
|
|
|
fName = "rotated_rects";
|
|
|
|
if (fAA) {
|
|
|
|
fName.append("_aa");
|
|
|
|
} else {
|
|
|
|
fName.append("_bw");
|
|
|
|
}
|
2014-08-08 14:43:29 +00:00
|
|
|
switch (fColorType) {
|
|
|
|
case kConstantOpaque_ColorType:
|
|
|
|
fName.append("_same_opaque");
|
|
|
|
break;
|
|
|
|
case kConstantTransparent_ColorType:
|
|
|
|
fName.append("_same_transparent");
|
|
|
|
break;
|
|
|
|
case kChangingOpaque_ColorType:
|
|
|
|
fName.append("_changing_opaque");
|
|
|
|
break;
|
|
|
|
case kChangingTransparent_ColorType:
|
|
|
|
fName.append("_changing_transparent");
|
|
|
|
break;
|
|
|
|
case kAlternatingOpaqueAndTransparent_ColorType:
|
|
|
|
fName.append("_alternating_transparent_and_opaque");
|
|
|
|
break;
|
2014-07-30 15:58:20 +00:00
|
|
|
}
|
2014-08-08 14:43:29 +00:00
|
|
|
fName.appendf("_%s", to_lower(SkXfermode::ModeName(fMode)).c_str());
|
2014-07-30 15:58:20 +00:00
|
|
|
}
|
|
|
|
|
2014-08-08 14:43:29 +00:00
|
|
|
bool fAA;
|
|
|
|
ColorType fColorType;
|
|
|
|
SkXfermode::Mode fMode;
|
|
|
|
SkString fName;
|
2014-07-30 15:58:20 +00:00
|
|
|
|
|
|
|
typedef Benchmark INHERITED;
|
|
|
|
};
|
|
|
|
|
2014-08-08 14:43:29 +00:00
|
|
|
// Choose kSrcOver because it always allows coverage and alpha to be conflated. kSrc only allows
|
|
|
|
// conflation when opaque, and kDarken because it isn't possilbe with standard GL blending.
|
|
|
|
DEF_BENCH(return new RotRectBench(true, kConstantOpaque_ColorType, SkXfermode::kSrcOver_Mode);)
|
|
|
|
DEF_BENCH(return new RotRectBench(true, kConstantTransparent_ColorType, SkXfermode::kSrcOver_Mode);)
|
|
|
|
DEF_BENCH(return new RotRectBench(true, kChangingOpaque_ColorType, SkXfermode::kSrcOver_Mode);)
|
|
|
|
DEF_BENCH(return new RotRectBench(true, kChangingTransparent_ColorType, SkXfermode::kSrcOver_Mode);)
|
|
|
|
DEF_BENCH(return new RotRectBench(true, kAlternatingOpaqueAndTransparent_ColorType, SkXfermode::kSrcOver_Mode);)
|
|
|
|
|
|
|
|
DEF_BENCH(return new RotRectBench(false, kConstantOpaque_ColorType, SkXfermode::kSrcOver_Mode);)
|
|
|
|
DEF_BENCH(return new RotRectBench(false, kConstantTransparent_ColorType, SkXfermode::kSrcOver_Mode);)
|
|
|
|
DEF_BENCH(return new RotRectBench(false, kChangingOpaque_ColorType, SkXfermode::kSrcOver_Mode);)
|
|
|
|
DEF_BENCH(return new RotRectBench(false, kChangingTransparent_ColorType, SkXfermode::kSrcOver_Mode);)
|
|
|
|
DEF_BENCH(return new RotRectBench(false, kAlternatingOpaqueAndTransparent_ColorType, SkXfermode::kSrcOver_Mode);)
|
|
|
|
|
|
|
|
DEF_BENCH(return new RotRectBench(true, kConstantOpaque_ColorType, SkXfermode::kSrc_Mode);)
|
|
|
|
DEF_BENCH(return new RotRectBench(true, kConstantTransparent_ColorType, SkXfermode::kSrc_Mode);)
|
|
|
|
DEF_BENCH(return new RotRectBench(true, kChangingOpaque_ColorType, SkXfermode::kSrc_Mode);)
|
|
|
|
DEF_BENCH(return new RotRectBench(true, kChangingTransparent_ColorType, SkXfermode::kSrc_Mode);)
|
|
|
|
DEF_BENCH(return new RotRectBench(true, kAlternatingOpaqueAndTransparent_ColorType, SkXfermode::kSrc_Mode);)
|
|
|
|
|
|
|
|
DEF_BENCH(return new RotRectBench(false, kConstantOpaque_ColorType, SkXfermode::kSrc_Mode);)
|
|
|
|
DEF_BENCH(return new RotRectBench(false, kConstantTransparent_ColorType, SkXfermode::kSrc_Mode);)
|
|
|
|
DEF_BENCH(return new RotRectBench(false, kChangingOpaque_ColorType, SkXfermode::kSrc_Mode);)
|
|
|
|
DEF_BENCH(return new RotRectBench(false, kChangingTransparent_ColorType, SkXfermode::kSrc_Mode);)
|
|
|
|
DEF_BENCH(return new RotRectBench(false, kAlternatingOpaqueAndTransparent_ColorType, SkXfermode::kSrc_Mode);)
|
|
|
|
|
|
|
|
DEF_BENCH(return new RotRectBench(true, kConstantOpaque_ColorType, SkXfermode::kDarken_Mode);)
|
|
|
|
DEF_BENCH(return new RotRectBench(true, kConstantTransparent_ColorType, SkXfermode::kDarken_Mode);)
|
|
|
|
DEF_BENCH(return new RotRectBench(true, kChangingOpaque_ColorType, SkXfermode::kDarken_Mode);)
|
|
|
|
DEF_BENCH(return new RotRectBench(true, kChangingTransparent_ColorType, SkXfermode::kDarken_Mode);)
|
|
|
|
DEF_BENCH(return new RotRectBench(true, kAlternatingOpaqueAndTransparent_ColorType, SkXfermode::kDarken_Mode);)
|
|
|
|
|
|
|
|
DEF_BENCH(return new RotRectBench(false, kConstantOpaque_ColorType, SkXfermode::kDarken_Mode);)
|
|
|
|
DEF_BENCH(return new RotRectBench(false, kConstantTransparent_ColorType, SkXfermode::kDarken_Mode);)
|
|
|
|
DEF_BENCH(return new RotRectBench(false, kChangingOpaque_ColorType, SkXfermode::kDarken_Mode);)
|
|
|
|
DEF_BENCH(return new RotRectBench(false, kChangingTransparent_ColorType, SkXfermode::kDarken_Mode);)
|
|
|
|
DEF_BENCH(return new RotRectBench(false, kAlternatingOpaqueAndTransparent_ColorType, SkXfermode::kDarken_Mode);)
|