2013-02-04 14:57:28 +00:00
|
|
|
/*
|
2015-05-29 14:17:16 +00:00
|
|
|
* Copyright 2015 Google Inc.
|
2013-02-04 14:57:28 +00:00
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "bench/Benchmark.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkPath.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/utils/SkRandom.h"
|
2013-02-04 14:57:28 +00:00
|
|
|
|
2015-05-29 14:17:16 +00:00
|
|
|
class StrokeBench : public Benchmark {
|
|
|
|
public:
|
2015-06-01 13:30:06 +00:00
|
|
|
StrokeBench(const SkPath& path, const SkPaint& paint, const char pathType[], SkScalar res)
|
|
|
|
: fPath(path), fPaint(paint), fRes(res)
|
2015-05-29 14:17:16 +00:00
|
|
|
{
|
|
|
|
fName.printf("build_stroke_%s_%g_%d_%d",
|
|
|
|
pathType, paint.getStrokeWidth(), paint.getStrokeJoin(), paint.getStrokeCap());
|
|
|
|
}
|
2013-02-04 14:57:28 +00:00
|
|
|
|
2015-05-29 14:17:16 +00:00
|
|
|
protected:
|
2015-07-13 13:18:39 +00:00
|
|
|
bool isSuitableFor(Backend backend) override {
|
2015-06-01 13:30:06 +00:00
|
|
|
return backend == kNonRendering_Backend;
|
|
|
|
}
|
|
|
|
|
2015-05-29 14:17:16 +00:00
|
|
|
const char* onGetName() override { return fName.c_str(); }
|
2013-02-04 14:57:28 +00:00
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2015-05-29 14:17:16 +00:00
|
|
|
SkPaint paint(fPaint);
|
|
|
|
this->setupPaint(&paint);
|
2013-02-04 14:57:28 +00:00
|
|
|
|
2015-05-29 14:17:16 +00:00
|
|
|
for (int outer = 0; outer < 10; ++outer) {
|
|
|
|
for (int i = 0; i < loops; ++i) {
|
|
|
|
SkPath result;
|
2015-08-27 14:41:13 +00:00
|
|
|
paint.getFillPath(fPath, &result, nullptr, fRes);
|
2015-05-29 14:17:16 +00:00
|
|
|
}
|
2013-02-04 14:57:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-29 14:17:16 +00:00
|
|
|
private:
|
|
|
|
SkPath fPath;
|
|
|
|
SkPaint fPaint;
|
|
|
|
SkString fName;
|
2015-06-01 13:30:06 +00:00
|
|
|
SkScalar fRes;
|
2015-05-29 14:17:16 +00:00
|
|
|
typedef Benchmark INHERITED;
|
|
|
|
};
|
2013-02-04 14:57:28 +00:00
|
|
|
|
2015-05-29 14:17:16 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2013-02-05 07:02:01 +00:00
|
|
|
|
2015-05-29 14:17:16 +00:00
|
|
|
static const int N = 100;
|
|
|
|
static const SkScalar X = 100;
|
|
|
|
static const SkScalar Y = 100;
|
2013-02-04 14:57:28 +00:00
|
|
|
|
2015-05-29 14:17:16 +00:00
|
|
|
static SkPoint rand_pt(SkRandom& rand) {
|
|
|
|
return SkPoint::Make(rand.nextSScalar1() * X, rand.nextSScalar1() * Y);
|
|
|
|
}
|
2013-02-04 14:57:28 +00:00
|
|
|
|
2015-05-29 14:17:16 +00:00
|
|
|
static SkPath line_path_maker() {
|
|
|
|
SkPath path;
|
|
|
|
SkRandom rand;
|
|
|
|
path.moveTo(rand_pt(rand));
|
|
|
|
for (int i = 0; i < N; ++i) {
|
|
|
|
path.lineTo(rand_pt(rand));
|
2013-02-04 14:57:28 +00:00
|
|
|
}
|
2015-05-29 14:17:16 +00:00
|
|
|
return path;
|
|
|
|
}
|
|
|
|
static SkPath quad_path_maker() {
|
|
|
|
SkPath path;
|
|
|
|
SkRandom rand;
|
|
|
|
path.moveTo(rand_pt(rand));
|
|
|
|
for (int i = 0; i < N; ++i) {
|
|
|
|
path.quadTo(rand_pt(rand), rand_pt(rand));
|
|
|
|
}
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
static SkPath conic_path_maker() {
|
|
|
|
SkPath path;
|
|
|
|
SkRandom rand;
|
|
|
|
path.moveTo(rand_pt(rand));
|
|
|
|
for (int i = 0; i < N; ++i) {
|
|
|
|
path.conicTo(rand_pt(rand), rand_pt(rand), rand.nextUScalar1());
|
|
|
|
}
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
static SkPath cubic_path_maker() {
|
|
|
|
SkPath path;
|
|
|
|
SkRandom rand;
|
|
|
|
path.moveTo(rand_pt(rand));
|
|
|
|
for (int i = 0; i < N; ++i) {
|
|
|
|
path.cubicTo(rand_pt(rand), rand_pt(rand), rand_pt(rand));
|
|
|
|
}
|
|
|
|
return path;
|
|
|
|
}
|
2013-02-04 14:57:28 +00:00
|
|
|
|
2015-05-29 14:17:16 +00:00
|
|
|
static SkPaint paint_maker() {
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
paint.setStrokeWidth(X / 10);
|
|
|
|
paint.setStrokeJoin(SkPaint::kMiter_Join);
|
|
|
|
paint.setStrokeCap(SkPaint::kSquare_Cap);
|
|
|
|
return paint;
|
|
|
|
}
|
2013-02-04 14:57:28 +00:00
|
|
|
|
2015-08-26 20:07:48 +00:00
|
|
|
DEF_BENCH(return new StrokeBench(line_path_maker(), paint_maker(), "line_1", 1);)
|
|
|
|
DEF_BENCH(return new StrokeBench(quad_path_maker(), paint_maker(), "quad_1", 1);)
|
|
|
|
DEF_BENCH(return new StrokeBench(conic_path_maker(), paint_maker(), "conic_1", 1);)
|
|
|
|
DEF_BENCH(return new StrokeBench(cubic_path_maker(), paint_maker(), "cubic_1", 1);)
|
2015-06-01 13:30:06 +00:00
|
|
|
|
2015-08-26 20:07:48 +00:00
|
|
|
DEF_BENCH(return new StrokeBench(line_path_maker(), paint_maker(), "line_4", 4);)
|
|
|
|
DEF_BENCH(return new StrokeBench(quad_path_maker(), paint_maker(), "quad_4", 4);)
|
|
|
|
DEF_BENCH(return new StrokeBench(conic_path_maker(), paint_maker(), "conic_4", 4);)
|
|
|
|
DEF_BENCH(return new StrokeBench(cubic_path_maker(), paint_maker(), "cubic_4", 4);)
|
2015-06-01 13:30:06 +00:00
|
|
|
|
2015-08-26 20:07:48 +00:00
|
|
|
DEF_BENCH(return new StrokeBench(line_path_maker(), paint_maker(), "line_.25", .25f);)
|
|
|
|
DEF_BENCH(return new StrokeBench(quad_path_maker(), paint_maker(), "quad_.25", .25f);)
|
|
|
|
DEF_BENCH(return new StrokeBench(conic_path_maker(), paint_maker(), "conic_.25", .25f);)
|
|
|
|
DEF_BENCH(return new StrokeBench(cubic_path_maker(), paint_maker(), "cubic_.25", .25f);)
|