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 {
|
|
|
|
PTS = 500,
|
|
|
|
};
|
|
|
|
SkPoint fPts[PTS];
|
|
|
|
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
LineBench(SkScalar width, bool doAA) {
|
2012-10-25 17:32:10 +00:00
|
|
|
fStrokeWidth = width;
|
|
|
|
fDoAA = doAA;
|
|
|
|
fName.printf("lines_%g_%s", width, doAA ? "AA" : "BW");
|
|
|
|
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom rand;
|
2012-10-25 17:32:10 +00:00
|
|
|
for (int i = 0; i < PTS; ++i) {
|
|
|
|
fPts[i].set(rand.nextUScalar1() * 640, rand.nextUScalar1() * 480);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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++) {
|
2012-10-25 17:32:10 +00:00
|
|
|
canvas->drawPoints(SkCanvas::kLines_PointMode, PTS, fPts, paint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2012-10-25 17:32:10 +00:00
|
|
|
};
|
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH(return new LineBench(0, false);)
|
|
|
|
DEF_BENCH(return new LineBench(SK_Scalar1, false);)
|
|
|
|
DEF_BENCH(return new LineBench(0, true);)
|
|
|
|
DEF_BENCH(return new LineBench(SK_Scalar1/2, true);)
|
|
|
|
DEF_BENCH(return new LineBench(SK_Scalar1, true);)
|