2009-01-05 03:34:50 +00:00
|
|
|
#include "SkBenchmark.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkPaint.h"
|
|
|
|
#include "SkRandom.h"
|
2009-01-08 03:00:57 +00:00
|
|
|
#include "SkString.h"
|
2011-03-09 12:55:47 +00:00
|
|
|
#include "SkShader.h"
|
2009-01-05 03:34:50 +00:00
|
|
|
|
|
|
|
class RectBench : public SkBenchmark {
|
|
|
|
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,
|
2009-01-08 03:00:57 +00:00
|
|
|
N = 300
|
2009-01-05 03:34:50 +00:00
|
|
|
};
|
|
|
|
SkRect fRects[N];
|
|
|
|
SkColor fColors[N];
|
|
|
|
|
2011-04-02 13:37:23 +00:00
|
|
|
RectBench(void* param, int shift, int stroke = 0) : INHERITED(param), fShift(shift), fStroke(stroke) {
|
2009-01-05 03:34:50 +00:00
|
|
|
SkRandom rand;
|
2011-04-02 13:37:23 +00:00
|
|
|
const SkScalar offset = SK_Scalar1/3;
|
2009-01-05 03:34:50 +00:00
|
|
|
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;
|
2009-01-08 03:00:57 +00:00
|
|
|
w >>= shift;
|
|
|
|
h >>= shift;
|
2009-01-05 03:34:50 +00:00
|
|
|
x -= w/2;
|
|
|
|
y -= h/2;
|
|
|
|
fRects[i].set(SkIntToScalar(x), SkIntToScalar(y),
|
|
|
|
SkIntToScalar(x+w), SkIntToScalar(y+h));
|
2011-04-02 13:37:23 +00:00
|
|
|
fRects[i].offset(offset, offset);
|
2009-01-05 03:34:50 +00:00
|
|
|
fColors[i] = rand.nextU() | 0xFF808080;
|
|
|
|
}
|
|
|
|
}
|
2011-01-05 15:50:27 +00:00
|
|
|
|
2009-01-08 03:00:57 +00:00
|
|
|
SkString fName;
|
|
|
|
const char* computeName(const char root[]) {
|
2011-04-02 13:37:23 +00:00
|
|
|
fName.printf("%s_%d", root, fShift);
|
|
|
|
if (fStroke > 0) {
|
|
|
|
fName.appendf("_stroke_%d", fStroke);
|
|
|
|
}
|
2009-01-08 03:00:57 +00:00
|
|
|
return fName.c_str();
|
|
|
|
}
|
2011-01-05 15:50:27 +00:00
|
|
|
|
2009-01-05 03:34:50 +00:00
|
|
|
protected:
|
|
|
|
virtual void drawThisRect(SkCanvas* c, const SkRect& r, const SkPaint& p) {
|
|
|
|
c->drawRect(r, p);
|
|
|
|
}
|
|
|
|
|
2009-01-19 20:08:35 +00:00
|
|
|
virtual const char* onGetName() { return computeName("rects"); }
|
2009-01-05 03:34:50 +00:00
|
|
|
virtual void onDraw(SkCanvas* canvas) {
|
|
|
|
SkPaint paint;
|
2011-04-02 13:37:23 +00:00
|
|
|
if (fStroke > 0) {
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
paint.setStrokeWidth(SkIntToScalar(fStroke));
|
|
|
|
}
|
2009-01-05 03:34:50 +00:00
|
|
|
for (int i = 0; i < N; i++) {
|
|
|
|
paint.setColor(fColors[i]);
|
2009-01-19 20:08:35 +00:00
|
|
|
this->setupPaint(&paint);
|
2009-01-05 03:34:50 +00:00
|
|
|
this->drawThisRect(canvas, fRects[i], paint);
|
|
|
|
}
|
|
|
|
}
|
2009-09-02 21:12:42 +00:00
|
|
|
private:
|
|
|
|
typedef SkBenchmark INHERITED;
|
2009-01-05 03:34:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class OvalBench : public RectBench {
|
2009-01-08 03:00:57 +00:00
|
|
|
public:
|
2009-09-02 21:12:42 +00:00
|
|
|
OvalBench(void* param, int shift) : RectBench(param, shift) {}
|
2009-01-05 03:34:50 +00:00
|
|
|
protected:
|
|
|
|
virtual void drawThisRect(SkCanvas* c, const SkRect& r, const SkPaint& p) {
|
|
|
|
c->drawOval(r, p);
|
|
|
|
}
|
2009-01-08 03:00:57 +00:00
|
|
|
virtual const char* onGetName() { return computeName("ovals"); }
|
2009-01-05 03:34:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class RRectBench : public RectBench {
|
2009-01-08 03:00:57 +00:00
|
|
|
public:
|
2009-09-02 21:12:42 +00:00
|
|
|
RRectBench(void* param, int shift) : RectBench(param, shift) {}
|
2009-01-05 03:34:50 +00:00
|
|
|
protected:
|
|
|
|
virtual void drawThisRect(SkCanvas* c, const SkRect& r, const SkPaint& p) {
|
|
|
|
c->drawRoundRect(r, r.width() / 4, r.height() / 4, p);
|
|
|
|
}
|
2009-01-19 20:08:35 +00:00
|
|
|
virtual const char* onGetName() { return computeName("rrects"); }
|
2009-01-05 03:34:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class PointsBench : public RectBench {
|
|
|
|
public:
|
|
|
|
SkCanvas::PointMode fMode;
|
|
|
|
const char* fName;
|
|
|
|
|
2011-01-05 15:50:27 +00:00
|
|
|
PointsBench(void* param, SkCanvas::PointMode mode, const char* name) :
|
2009-09-02 21:12:42 +00:00
|
|
|
RectBench(param, 2), fMode(mode) {
|
2009-01-05 03:34:50 +00:00
|
|
|
fName = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void onDraw(SkCanvas* canvas) {
|
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);
|
|
|
|
|
|
|
|
if (this->hasStrokeWidth()) {
|
|
|
|
gSizes[0] = this->getStrokeWidth();
|
|
|
|
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
|
|
|
|
|
|
|
for (size_t i = 0; i < sizes; i++) {
|
2009-01-05 03:34:50 +00:00
|
|
|
paint.setStrokeWidth(gSizes[i]);
|
2009-01-19 20:08:35 +00:00
|
|
|
this->setupPaint(&paint);
|
2011-01-05 15:50:27 +00:00
|
|
|
canvas->drawPoints(fMode, N * 2, SkTCast<SkPoint*>(fRects), paint);
|
2009-01-05 03:34:50 +00:00
|
|
|
paint.setColor(fColors[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
virtual const char* onGetName() { return fName; }
|
|
|
|
};
|
|
|
|
|
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;
|
|
|
|
const char* fName;
|
|
|
|
|
|
|
|
BlitMaskBench(void* param, SkCanvas::PointMode mode,
|
|
|
|
BlitMaskBench::kMaskType type, const char* name) :
|
|
|
|
RectBench(param, 2), fMode(mode), _type(type) {
|
|
|
|
fName = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void onDraw(SkCanvas* canvas) {
|
|
|
|
SkScalar gSizes[] = {
|
|
|
|
SkIntToScalar(13), SkIntToScalar(24)
|
|
|
|
};
|
|
|
|
size_t sizes = SK_ARRAY_COUNT(gSizes);
|
|
|
|
|
|
|
|
if (this->hasStrokeWidth()) {
|
|
|
|
gSizes[0] = this->getStrokeWidth();
|
|
|
|
sizes = 1;
|
|
|
|
}
|
|
|
|
SkRandom rand;
|
|
|
|
SkColor color = 0xFF000000;
|
|
|
|
U8CPU alpha = 0xFF;
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setStrokeCap(SkPaint::kRound_Cap);
|
|
|
|
if (_type == KMaskShader) {
|
|
|
|
SkBitmap srcBM;
|
|
|
|
srcBM.setConfig(SkBitmap::kARGB_8888_Config, 10, 1);
|
|
|
|
srcBM.allocPixels();
|
|
|
|
srcBM.eraseColor(0xFF00FF00);
|
|
|
|
|
|
|
|
SkShader* s;
|
|
|
|
s = SkShader::CreateBitmapShader(srcBM, SkShader::kClamp_TileMode,
|
|
|
|
SkShader::kClamp_TileMode);
|
|
|
|
paint.setShader(s)->unref();
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
canvas->drawPoints(fMode, N * 2, SkTCast<SkPoint*>(fRects), paint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
virtual const char* onGetName() { return fName; }
|
|
|
|
private:
|
|
|
|
typedef RectBench INHERITED;
|
|
|
|
kMaskType _type;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-04-02 13:37:23 +00:00
|
|
|
static SkBenchmark* RectFactory1F(void* p) { return SkNEW_ARGS(RectBench, (p, 1)); }
|
|
|
|
static SkBenchmark* RectFactory1S(void* p) { return SkNEW_ARGS(RectBench, (p, 1, 4)); }
|
|
|
|
static SkBenchmark* RectFactory2F(void* p) { return SkNEW_ARGS(RectBench, (p, 3)); }
|
|
|
|
static SkBenchmark* RectFactory2S(void* p) { return SkNEW_ARGS(RectBench, (p, 3, 4)); }
|
2009-09-02 21:12:42 +00:00
|
|
|
static SkBenchmark* OvalFactory1(void* p) { return SkNEW_ARGS(OvalBench, (p, 1)); }
|
|
|
|
static SkBenchmark* OvalFactory2(void* p) { return SkNEW_ARGS(OvalBench, (p, 3)); }
|
|
|
|
static SkBenchmark* RRectFactory1(void* p) { return SkNEW_ARGS(RRectBench, (p, 1)); }
|
|
|
|
static SkBenchmark* RRectFactory2(void* p) { return SkNEW_ARGS(RRectBench, (p, 3)); }
|
|
|
|
static SkBenchmark* PointsFactory(void* p) {
|
|
|
|
return SkNEW_ARGS(PointsBench, (p, SkCanvas::kPoints_PointMode, "points"));
|
2009-01-05 03:34:50 +00:00
|
|
|
}
|
2009-09-02 21:12:42 +00:00
|
|
|
static SkBenchmark* LinesFactory(void* p) {
|
|
|
|
return SkNEW_ARGS(PointsBench, (p, SkCanvas::kLines_PointMode, "lines"));
|
2009-01-05 03:34:50 +00:00
|
|
|
}
|
2009-09-02 21:12:42 +00:00
|
|
|
static SkBenchmark* PolygonFactory(void* p) {
|
|
|
|
return SkNEW_ARGS(PointsBench, (p, SkCanvas::kPolygon_PointMode, "polygon"));
|
2009-01-05 03:34:50 +00:00
|
|
|
}
|
|
|
|
|
2011-03-09 12:55:47 +00:00
|
|
|
/* init the blitmask bench
|
|
|
|
*/
|
|
|
|
static SkBenchmark* BlitMaskOpaqueFactory(void* p) {
|
|
|
|
return SkNEW_ARGS(BlitMaskBench,
|
|
|
|
(p, SkCanvas::kPoints_PointMode,
|
|
|
|
BlitMaskBench::kMaskOpaque, "maskopaque")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
static SkBenchmark* BlitMaskBlackFactory(void* p) {
|
|
|
|
return SkNEW_ARGS(BlitMaskBench,
|
|
|
|
(p, SkCanvas::kPoints_PointMode,
|
|
|
|
BlitMaskBench::kMaskBlack, "maskblack")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
static SkBenchmark* BlitMaskColorFactory(void* p) {
|
|
|
|
return SkNEW_ARGS(BlitMaskBench,
|
|
|
|
(p, SkCanvas::kPoints_PointMode,
|
|
|
|
BlitMaskBench::kMaskColor, "maskcolor")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
static SkBenchmark* BlitMaskShaderFactory(void* p) {
|
|
|
|
return SkNEW_ARGS(BlitMaskBench,
|
|
|
|
(p, SkCanvas::kPoints_PointMode,
|
|
|
|
BlitMaskBench::KMaskShader, "maskshader")
|
|
|
|
);
|
|
|
|
}
|
2011-04-02 13:37:23 +00:00
|
|
|
|
|
|
|
static BenchRegistry gRectReg1F(RectFactory1F);
|
|
|
|
static BenchRegistry gRectReg1S(RectFactory1S);
|
|
|
|
static BenchRegistry gRectReg2F(RectFactory2F);
|
|
|
|
static BenchRegistry gRectReg2S(RectFactory2S);
|
2009-01-26 23:15:37 +00:00
|
|
|
static BenchRegistry gOvalReg1(OvalFactory1);
|
|
|
|
static BenchRegistry gOvalReg2(OvalFactory2);
|
|
|
|
static BenchRegistry gRRectReg1(RRectFactory1);
|
|
|
|
static BenchRegistry gRRectReg2(RRectFactory2);
|
|
|
|
static BenchRegistry gPointsReg(PointsFactory);
|
|
|
|
static BenchRegistry gLinesReg(LinesFactory);
|
|
|
|
static BenchRegistry gPolygonReg(PolygonFactory);
|
2011-03-09 12:55:47 +00:00
|
|
|
static BenchRegistry gRectRegOpaque(BlitMaskOpaqueFactory);
|
|
|
|
static BenchRegistry gRectRegBlack(BlitMaskBlackFactory);
|
|
|
|
static BenchRegistry gRectRegColor(BlitMaskColorFactory);
|
|
|
|
static BenchRegistry gRectRegShader(BlitMaskShaderFactory);
|