2012-10-25 17:32:10 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
#include "Benchmark.h"
|
2012-10-25 17:32:10 +00:00
|
|
|
#include "SkBitmap.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkColorPriv.h"
|
|
|
|
#include "SkPaint.h"
|
|
|
|
#include "SkRandom.h"
|
|
|
|
#include "SkShader.h"
|
|
|
|
#include "SkString.h"
|
|
|
|
#include "SkTArray.h"
|
|
|
|
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class LineBench : public Benchmark {
|
2012-10-25 17:32:10 +00:00
|
|
|
SkScalar fStrokeWidth;
|
|
|
|
bool fDoAA;
|
|
|
|
SkString fName;
|
|
|
|
enum {
|
2016-05-05 20:24:04 +00:00
|
|
|
LINES = 500,
|
2012-10-25 17:32:10 +00:00
|
|
|
};
|
2016-05-05 20:24:04 +00:00
|
|
|
SkPoint fStartPts[LINES];
|
|
|
|
SkPoint fEndPts[LINES];
|
2012-10-25 17:32:10 +00:00
|
|
|
|
|
|
|
public:
|
2016-05-05 20:24:04 +00:00
|
|
|
enum LineType {
|
|
|
|
SH, // Straight + horizontally
|
|
|
|
SV, // Straight + vertically
|
|
|
|
RAND,
|
|
|
|
};
|
|
|
|
LineBench(SkScalar width, bool doAA, LineType type) {
|
2012-10-25 17:32:10 +00:00
|
|
|
fStrokeWidth = width;
|
|
|
|
fDoAA = doAA;
|
2016-05-05 20:24:04 +00:00
|
|
|
fName.printf("lines_%g_%s_%s", width, doAA ? "AA" : "BW",
|
|
|
|
type == SH ? "SH" : (type == SV ? "SV" : "RAND"));
|
2012-10-25 17:32:10 +00:00
|
|
|
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom rand;
|
2016-05-05 20:24:04 +00:00
|
|
|
for (int i = 0; i < LINES; ++i) {
|
|
|
|
fStartPts[i].set(rand.nextUScalar1() * 640, rand.nextUScalar1() * 480);
|
|
|
|
if (type == SH) {
|
|
|
|
fEndPts[i].set(rand.nextUScalar1() * 640, fStartPts[i].y());
|
|
|
|
} else if (type == SV) {
|
|
|
|
fEndPts[i].set(fStartPts[i].x(), rand.nextUScalar1() * 480);
|
|
|
|
} else {
|
|
|
|
fEndPts[i].set(rand.nextUScalar1() * 640, rand.nextUScalar1() * 480);
|
|
|
|
}
|
2012-10-25 17:32:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2012-10-25 17:32:10 +00:00
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2012-10-25 17:32:10 +00:00
|
|
|
SkPaint paint;
|
|
|
|
this->setupPaint(&paint);
|
|
|
|
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
paint.setAntiAlias(fDoAA);
|
|
|
|
paint.setStrokeWidth(fStrokeWidth);
|
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; i++) {
|
2016-05-05 20:24:04 +00:00
|
|
|
canvas->drawLine(fStartPts[i].x(), fStartPts[i].y(), fEndPts[i].x(), fEndPts[i].y(), paint);
|
2012-10-25 17:32:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2012-10-25 17:32:10 +00:00
|
|
|
};
|
|
|
|
|
2016-05-05 20:24:04 +00:00
|
|
|
DEF_BENCH(return new LineBench(0, false, LineBench::SH);)
|
|
|
|
DEF_BENCH(return new LineBench(SK_Scalar1, false, LineBench::SH);)
|
|
|
|
DEF_BENCH(return new LineBench(0, true, LineBench::SH);)
|
|
|
|
DEF_BENCH(return new LineBench(SK_Scalar1/2, true, LineBench::SH);)
|
|
|
|
DEF_BENCH(return new LineBench(SK_Scalar1, true, LineBench::SH);)
|
|
|
|
DEF_BENCH(return new LineBench(SK_Scalar1*10,true, LineBench::SH);)
|
|
|
|
DEF_BENCH(return new LineBench(0, false, LineBench::SV);)
|
|
|
|
DEF_BENCH(return new LineBench(SK_Scalar1, false, LineBench::SV);)
|
|
|
|
DEF_BENCH(return new LineBench(0, true, LineBench::SV);)
|
|
|
|
DEF_BENCH(return new LineBench(SK_Scalar1/2, true, LineBench::SV);)
|
|
|
|
DEF_BENCH(return new LineBench(SK_Scalar1, true, LineBench::SV);)
|
|
|
|
DEF_BENCH(return new LineBench(SK_Scalar1*10,true, LineBench::SV);)
|
|
|
|
DEF_BENCH(return new LineBench(0, false, LineBench::RAND);)
|
|
|
|
DEF_BENCH(return new LineBench(SK_Scalar1, false, LineBench::RAND);)
|
|
|
|
DEF_BENCH(return new LineBench(0, true, LineBench::RAND);)
|
|
|
|
DEF_BENCH(return new LineBench(SK_Scalar1/2, true, LineBench::RAND);)
|
|
|
|
DEF_BENCH(return new LineBench(SK_Scalar1, true, LineBench::RAND);)
|
|
|
|
DEF_BENCH(return new LineBench(SK_Scalar1*10,true, LineBench::RAND);)
|