2011-07-28 14:26:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2018-01-23 16:24:08 +00:00
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
#include "Benchmark.h"
|
2018-01-23 16:24:08 +00:00
|
|
|
#include "SkBitmap.h"
|
2009-01-05 03:34:50 +00:00
|
|
|
#include "SkCanvas.h"
|
2013-09-10 19:23:38 +00:00
|
|
|
#include "SkCommandLineFlags.h"
|
2009-01-05 03:34:50 +00:00
|
|
|
#include "SkPaint.h"
|
|
|
|
#include "SkRandom.h"
|
2011-03-09 12:55:47 +00:00
|
|
|
#include "SkShader.h"
|
2013-09-10 19:23:38 +00:00
|
|
|
#include "SkString.h"
|
|
|
|
|
|
|
|
DEFINE_double(strokeWidth, -1.0, "If set, use this stroke width in RectBench.");
|
2009-01-05 03:34:50 +00:00
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class RectBench : public Benchmark {
|
2009-01-05 03:34:50 +00:00
|
|
|
public:
|
2011-04-02 13:37:23 +00:00
|
|
|
int fShift, fStroke;
|
2009-01-05 03:34:50 +00:00
|
|
|
enum {
|
|
|
|
W = 640,
|
|
|
|
H = 480,
|
2013-09-10 19:23:38 +00:00
|
|
|
N = 300,
|
2009-01-05 03:34:50 +00:00
|
|
|
};
|
|
|
|
SkRect fRects[N];
|
|
|
|
SkColor fColors[N];
|
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
RectBench(int shift, int stroke = 0)
|
|
|
|
: fShift(shift)
|
2013-12-05 12:07:44 +00:00
|
|
|
, fStroke(stroke) {}
|
2011-01-05 15:50:27 +00:00
|
|
|
|
2009-01-08 03:00:57 +00:00
|
|
|
const char* computeName(const char root[]) {
|
2017-03-01 14:49:58 +00:00
|
|
|
fBaseName.printf("%s_%d", root, fShift);
|
2011-04-02 13:37:23 +00:00
|
|
|
if (fStroke > 0) {
|
2017-03-01 14:49:58 +00:00
|
|
|
fBaseName.appendf("_stroke_%d", fStroke);
|
2011-04-02 13:37:23 +00:00
|
|
|
}
|
2017-03-01 14:49:58 +00:00
|
|
|
return fBaseName.c_str();
|
2009-01-08 03:00:57 +00:00
|
|
|
}
|
2011-01-05 15:50:27 +00:00
|
|
|
|
2015-09-24 15:08:23 +00:00
|
|
|
bool isVisual() override { return true; }
|
|
|
|
|
2009-01-05 03:34:50 +00:00
|
|
|
protected:
|
2017-02-28 21:11:04 +00:00
|
|
|
|
2009-01-05 03:34:50 +00:00
|
|
|
virtual void drawThisRect(SkCanvas* c, const SkRect& r, const SkPaint& p) {
|
|
|
|
c->drawRect(r, p);
|
|
|
|
}
|
|
|
|
|
2015-09-25 11:49:43 +00:00
|
|
|
const char* onGetName() override { return computeName("rects"); }
|
2013-12-05 12:07:44 +00:00
|
|
|
|
2015-09-30 19:11:07 +00:00
|
|
|
void onDelayedSetup() override {
|
2013-12-05 12:07:44 +00:00
|
|
|
SkRandom rand;
|
|
|
|
const SkScalar offset = SK_Scalar1/3;
|
|
|
|
for (int i = 0; i < N; i++) {
|
|
|
|
int x = rand.nextU() % W;
|
|
|
|
int y = rand.nextU() % H;
|
|
|
|
int w = rand.nextU() % W;
|
|
|
|
int h = rand.nextU() % H;
|
|
|
|
w >>= fShift;
|
|
|
|
h >>= fShift;
|
|
|
|
x -= w/2;
|
|
|
|
y -= h/2;
|
|
|
|
fRects[i].set(SkIntToScalar(x), SkIntToScalar(y),
|
|
|
|
SkIntToScalar(x+w), SkIntToScalar(y+h));
|
|
|
|
fRects[i].offset(offset, offset);
|
|
|
|
fColors[i] = rand.nextU() | 0xFF808080;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2009-01-05 03:34:50 +00:00
|
|
|
SkPaint paint;
|
2011-04-02 13:37:23 +00:00
|
|
|
if (fStroke > 0) {
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
paint.setStrokeWidth(SkIntToScalar(fStroke));
|
|
|
|
}
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; i++) {
|
2013-09-10 19:23:38 +00:00
|
|
|
paint.setColor(fColors[i % N]);
|
2009-01-19 20:08:35 +00:00
|
|
|
this->setupPaint(&paint);
|
2013-09-10 19:23:38 +00:00
|
|
|
this->drawThisRect(canvas, fRects[i % N], paint);
|
2009-01-05 03:34:50 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-01 14:49:58 +00:00
|
|
|
|
2009-09-02 21:12:42 +00:00
|
|
|
private:
|
2017-03-01 14:49:58 +00:00
|
|
|
SkString fBaseName;
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2009-01-05 03:34:50 +00:00
|
|
|
};
|
|
|
|
|
2012-11-15 19:52:07 +00:00
|
|
|
class SrcModeRectBench : public RectBench {
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
SrcModeRectBench() : INHERITED(1, 0) {
|
2016-10-06 00:33:02 +00:00
|
|
|
fMode = SkBlendMode::kSrc;
|
2012-11-15 19:52:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
void setupPaint(SkPaint* paint) override {
|
2012-11-15 19:52:07 +00:00
|
|
|
this->INHERITED::setupPaint(paint);
|
|
|
|
// srcmode is most interesting when we're not opaque
|
|
|
|
paint->setAlpha(0x80);
|
2016-10-06 00:33:02 +00:00
|
|
|
paint->setBlendMode(fMode);
|
2012-11-15 19:52:07 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2012-11-15 19:52:07 +00:00
|
|
|
fName.set(this->INHERITED::onGetName());
|
|
|
|
fName.prepend("srcmode_");
|
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2016-10-06 00:33:02 +00:00
|
|
|
SkBlendMode fMode;
|
2017-03-01 14:49:58 +00:00
|
|
|
SkString fName;
|
2012-11-15 19:52:07 +00:00
|
|
|
|
|
|
|
typedef RectBench INHERITED;
|
|
|
|
};
|
|
|
|
|
2015-09-24 19:42:02 +00:00
|
|
|
class TransparentRectBench : public RectBench {
|
|
|
|
public:
|
|
|
|
TransparentRectBench() : INHERITED(1, 0) {}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void setupPaint(SkPaint* paint) override {
|
|
|
|
this->INHERITED::setupPaint(paint);
|
|
|
|
// draw non opaque rect
|
|
|
|
paint->setAlpha(0x80);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* onGetName() override {
|
|
|
|
fName.set(this->INHERITED::onGetName());
|
|
|
|
fName.prepend("transparent_");
|
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2017-03-01 14:49:58 +00:00
|
|
|
SkString fName;
|
2015-09-24 19:42:02 +00:00
|
|
|
typedef RectBench INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-01-05 03:34:50 +00:00
|
|
|
class OvalBench : public RectBench {
|
2009-01-08 03:00:57 +00:00
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
OvalBench(int shift, int stroke = 0) : RectBench(shift, stroke) {}
|
2009-01-05 03:34:50 +00:00
|
|
|
protected:
|
2015-09-25 11:49:43 +00:00
|
|
|
void drawThisRect(SkCanvas* c, const SkRect& r, const SkPaint& p) override {
|
2009-01-05 03:34:50 +00:00
|
|
|
c->drawOval(r, p);
|
|
|
|
}
|
2015-09-25 11:49:43 +00:00
|
|
|
const char* onGetName() override { return computeName("ovals"); }
|
2009-01-05 03:34:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class RRectBench : public RectBench {
|
2009-01-08 03:00:57 +00:00
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
RRectBench(int shift, int stroke = 0) : RectBench(shift, stroke) {}
|
2009-01-05 03:34:50 +00:00
|
|
|
protected:
|
2015-09-25 11:49:43 +00:00
|
|
|
void drawThisRect(SkCanvas* c, const SkRect& r, const SkPaint& p) override {
|
2009-01-05 03:34:50 +00:00
|
|
|
c->drawRoundRect(r, r.width() / 4, r.height() / 4, p);
|
|
|
|
}
|
2015-09-25 11:49:43 +00:00
|
|
|
const char* onGetName() override { return computeName("rrects"); }
|
2009-01-05 03:34:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class PointsBench : public RectBench {
|
|
|
|
public:
|
|
|
|
SkCanvas::PointMode fMode;
|
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
PointsBench(SkCanvas::PointMode mode, const char* name)
|
|
|
|
: RectBench(2)
|
|
|
|
, fMode(mode) {
|
2009-01-05 03:34:50 +00:00
|
|
|
fName = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2010-04-27 15:47:34 +00:00
|
|
|
SkScalar gSizes[] = {
|
2009-01-05 03:34:50 +00:00
|
|
|
SkIntToScalar(7), 0
|
|
|
|
};
|
2010-04-27 15:47:34 +00:00
|
|
|
size_t sizes = SK_ARRAY_COUNT(gSizes);
|
|
|
|
|
2013-09-10 19:23:38 +00:00
|
|
|
if (FLAGS_strokeWidth >= 0) {
|
2013-09-10 19:51:10 +00:00
|
|
|
gSizes[0] = (SkScalar)FLAGS_strokeWidth;
|
2010-04-27 15:47:34 +00:00
|
|
|
sizes = 1;
|
|
|
|
}
|
2009-01-05 03:34:50 +00:00
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setStrokeCap(SkPaint::kRound_Cap);
|
2010-04-27 15:47:34 +00:00
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int loop = 0; loop < loops; loop++) {
|
2013-09-10 19:23:38 +00:00
|
|
|
for (size_t i = 0; i < sizes; i++) {
|
|
|
|
paint.setStrokeWidth(gSizes[i]);
|
|
|
|
this->setupPaint(&paint);
|
2018-06-14 18:41:22 +00:00
|
|
|
canvas->drawPoints(fMode, N * 2, reinterpret_cast<SkPoint*>(fRects), paint);
|
2013-09-10 19:23:38 +00:00
|
|
|
paint.setColor(fColors[i % N]);
|
|
|
|
}
|
2009-01-05 03:34:50 +00:00
|
|
|
}
|
|
|
|
}
|
2017-02-28 21:11:04 +00:00
|
|
|
const char* onGetName() override { return fName.c_str(); }
|
2017-03-01 14:49:58 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
SkString fName;
|
|
|
|
|
2009-01-05 03:34:50 +00:00
|
|
|
};
|
|
|
|
|
2011-03-09 12:55:47 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
* to bench BlitMask [Opaque, Black, color, shader]
|
|
|
|
*******************************************************************************/
|
|
|
|
|
|
|
|
class BlitMaskBench : public RectBench {
|
|
|
|
public:
|
|
|
|
enum kMaskType {
|
|
|
|
kMaskOpaque = 0,
|
|
|
|
kMaskBlack,
|
|
|
|
kMaskColor,
|
|
|
|
KMaskShader
|
|
|
|
};
|
|
|
|
SkCanvas::PointMode fMode;
|
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
BlitMaskBench(SkCanvas::PointMode mode,
|
2011-03-09 12:55:47 +00:00
|
|
|
BlitMaskBench::kMaskType type, const char* name) :
|
2013-09-13 19:52:27 +00:00
|
|
|
RectBench(2), fMode(mode), _type(type) {
|
2011-03-09 12:55:47 +00:00
|
|
|
fName = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2011-03-09 12:55:47 +00:00
|
|
|
SkScalar gSizes[] = {
|
|
|
|
SkIntToScalar(13), SkIntToScalar(24)
|
|
|
|
};
|
|
|
|
size_t sizes = SK_ARRAY_COUNT(gSizes);
|
|
|
|
|
2013-09-10 19:23:38 +00:00
|
|
|
if (FLAGS_strokeWidth >= 0) {
|
2013-09-10 19:51:10 +00:00
|
|
|
gSizes[0] = (SkScalar)FLAGS_strokeWidth;
|
2011-03-09 12:55:47 +00:00
|
|
|
sizes = 1;
|
|
|
|
}
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom rand;
|
2011-03-09 12:55:47 +00:00
|
|
|
SkColor color = 0xFF000000;
|
|
|
|
U8CPU alpha = 0xFF;
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setStrokeCap(SkPaint::kRound_Cap);
|
|
|
|
if (_type == KMaskShader) {
|
|
|
|
SkBitmap srcBM;
|
2014-06-10 02:52:07 +00:00
|
|
|
srcBM.allocN32Pixels(10, 1);
|
2011-03-09 12:55:47 +00:00
|
|
|
srcBM.eraseColor(0xFF00FF00);
|
|
|
|
|
2016-03-14 19:22:10 +00:00
|
|
|
paint.setShader(SkShader::MakeBitmapShader(srcBM, SkShader::kClamp_TileMode,
|
|
|
|
SkShader::kClamp_TileMode));
|
2011-03-09 12:55:47 +00:00
|
|
|
}
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int loop = 0; loop < loops; loop++) {
|
2013-09-10 19:23:38 +00:00
|
|
|
for (size_t i = 0; i < sizes; i++) {
|
|
|
|
switch (_type) {
|
|
|
|
case kMaskOpaque:
|
|
|
|
color = fColors[i];
|
|
|
|
alpha = 0xFF;
|
|
|
|
break;
|
|
|
|
case kMaskBlack:
|
|
|
|
alpha = 0xFF;
|
|
|
|
color = 0xFF000000;
|
|
|
|
break;
|
|
|
|
case kMaskColor:
|
|
|
|
color = fColors[i];
|
|
|
|
alpha = rand.nextU() & 255;
|
|
|
|
break;
|
|
|
|
case KMaskShader:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
paint.setStrokeWidth(gSizes[i]);
|
|
|
|
this->setupPaint(&paint);
|
|
|
|
paint.setColor(color);
|
|
|
|
paint.setAlpha(alpha);
|
2018-06-14 18:41:22 +00:00
|
|
|
canvas->drawPoints(fMode, N * 2, reinterpret_cast<SkPoint*>(fRects), paint);
|
2013-09-10 19:23:38 +00:00
|
|
|
}
|
|
|
|
}
|
2011-03-09 12:55:47 +00:00
|
|
|
}
|
2017-02-28 21:11:04 +00:00
|
|
|
const char* onGetName() override { return fName.c_str(); }
|
2017-03-01 14:49:58 +00:00
|
|
|
|
2011-03-09 12:55:47 +00:00
|
|
|
private:
|
2012-08-23 18:09:54 +00:00
|
|
|
typedef RectBench INHERITED;
|
|
|
|
kMaskType _type;
|
2017-03-01 14:49:58 +00:00
|
|
|
SkString fName;
|
2011-03-09 12:55:47 +00:00
|
|
|
};
|
|
|
|
|
2015-08-26 20:07:48 +00:00
|
|
|
DEF_BENCH(return new RectBench(1);)
|
|
|
|
DEF_BENCH(return new RectBench(1, 4);)
|
|
|
|
DEF_BENCH(return new RectBench(3);)
|
|
|
|
DEF_BENCH(return new RectBench(3, 4);)
|
|
|
|
DEF_BENCH(return new OvalBench(1);)
|
|
|
|
DEF_BENCH(return new OvalBench(3);)
|
|
|
|
DEF_BENCH(return new OvalBench(1, 4);)
|
|
|
|
DEF_BENCH(return new OvalBench(3, 4);)
|
|
|
|
DEF_BENCH(return new RRectBench(1);)
|
|
|
|
DEF_BENCH(return new RRectBench(1, 4);)
|
|
|
|
DEF_BENCH(return new RRectBench(3);)
|
|
|
|
DEF_BENCH(return new RRectBench(3, 4);)
|
|
|
|
DEF_BENCH(return new PointsBench(SkCanvas::kPoints_PointMode, "points");)
|
|
|
|
DEF_BENCH(return new PointsBench(SkCanvas::kLines_PointMode, "lines");)
|
|
|
|
DEF_BENCH(return new PointsBench(SkCanvas::kPolygon_PointMode, "polygon");)
|
|
|
|
|
|
|
|
DEF_BENCH(return new SrcModeRectBench();)
|
2013-05-02 13:57:52 +00:00
|
|
|
|
2015-09-24 19:42:02 +00:00
|
|
|
DEF_BENCH(return new TransparentRectBench();)
|
|
|
|
|
2011-03-09 12:55:47 +00:00
|
|
|
/* init the blitmask bench
|
|
|
|
*/
|
2015-08-26 20:07:48 +00:00
|
|
|
DEF_BENCH(return new BlitMaskBench(SkCanvas::kPoints_PointMode,
|
|
|
|
BlitMaskBench::kMaskOpaque,
|
|
|
|
"maskopaque");)
|
|
|
|
DEF_BENCH(return new BlitMaskBench(SkCanvas::kPoints_PointMode,
|
|
|
|
BlitMaskBench::kMaskBlack,
|
|
|
|
"maskblack");)
|
|
|
|
DEF_BENCH(return new BlitMaskBench(SkCanvas::kPoints_PointMode,
|
|
|
|
BlitMaskBench::kMaskColor,
|
|
|
|
"maskcolor");)
|
|
|
|
DEF_BENCH(return new BlitMaskBench(SkCanvas::kPoints_PointMode,
|
|
|
|
BlitMaskBench::KMaskShader,
|
|
|
|
"maskshader");)
|