2012-05-04 16:37:45 +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.
|
|
|
|
*/
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "bench/Benchmark.h"
|
|
|
|
#include "include/core/SkBitmap.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkPath.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/core/SkStrokeRec.h"
|
|
|
|
#include "include/effects/SkDashPathEffect.h"
|
|
|
|
#include "include/private/SkTDArray.h"
|
|
|
|
#include "include/utils/SkRandom.h"
|
2012-05-04 16:37:45 +00:00
|
|
|
|
2012-05-10 15:40:57 +00:00
|
|
|
|
2012-05-04 16:37:45 +00:00
|
|
|
/*
|
|
|
|
* Cases to consider:
|
|
|
|
*
|
|
|
|
* 1. antialiasing on/off (esp. width <= 1)
|
|
|
|
* 2. strokewidth == 0, 1, 2
|
|
|
|
* 3. hline, vline, diagonal, rect, oval
|
|
|
|
* 4. dots [1,1] ([N,N] where N=strokeWidth?) or arbitrary (e.g. [2,1] or [1,2,3,2])
|
|
|
|
*/
|
|
|
|
static void path_hline(SkPath* path) {
|
|
|
|
path->moveTo(SkIntToScalar(10), SkIntToScalar(10));
|
|
|
|
path->lineTo(SkIntToScalar(600), SkIntToScalar(10));
|
|
|
|
}
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class DashBench : public Benchmark {
|
2012-05-10 15:40:57 +00:00
|
|
|
protected:
|
2012-05-05 13:46:10 +00:00
|
|
|
SkString fName;
|
2012-05-04 16:37:45 +00:00
|
|
|
SkTDArray<SkScalar> fIntervals;
|
2012-05-05 13:46:10 +00:00
|
|
|
int fWidth;
|
2012-05-16 14:06:02 +00:00
|
|
|
SkPoint fPts[2];
|
|
|
|
bool fDoClip;
|
2012-05-04 16:37:45 +00:00
|
|
|
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
DashBench(const SkScalar intervals[], int count, int width,
|
|
|
|
bool doClip = false) {
|
2012-05-04 16:37:45 +00:00
|
|
|
fIntervals.append(count, intervals);
|
2012-05-05 13:46:10 +00:00
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
fIntervals[i] *= width;
|
|
|
|
}
|
|
|
|
fWidth = width;
|
2012-05-15 19:50:58 +00:00
|
|
|
fName.printf("dash_%d_%s", width, doClip ? "clipped" : "noclip");
|
|
|
|
fDoClip = doClip;
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2012-05-16 14:06:02 +00:00
|
|
|
fPts[0].set(SkIntToScalar(10), SkIntToScalar(10));
|
|
|
|
fPts[1].set(SkIntToScalar(600), SkIntToScalar(10));
|
2012-05-04 16:37:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void makePath(SkPath* path) {
|
|
|
|
path_hline(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2012-05-05 13:46:10 +00:00
|
|
|
return fName.c_str();
|
2012-05-04 16:37:45 +00:00
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2012-05-04 16:37:45 +00:00
|
|
|
SkPaint paint;
|
|
|
|
this->setupPaint(&paint);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
2012-05-05 13:46:10 +00:00
|
|
|
paint.setStrokeWidth(SkIntToScalar(fWidth));
|
2012-05-04 16:37:45 +00:00
|
|
|
paint.setAntiAlias(false);
|
|
|
|
|
|
|
|
SkPath path;
|
|
|
|
this->makePath(&path);
|
|
|
|
|
2016-03-18 18:22:57 +00:00
|
|
|
paint.setPathEffect(SkDashPathEffect::Make(fIntervals.begin(), fIntervals.count(), 0));
|
2012-05-15 19:50:58 +00:00
|
|
|
|
|
|
|
if (fDoClip) {
|
|
|
|
SkRect r = path.getBounds();
|
|
|
|
r.inset(-SkIntToScalar(20), -SkIntToScalar(20));
|
|
|
|
// now move it so we don't intersect
|
|
|
|
r.offset(0, r.height() * 3 / 2);
|
|
|
|
canvas->clipRect(r);
|
|
|
|
}
|
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
this->handlePath(canvas, path, paint, loops);
|
2012-05-10 15:40:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void handlePath(SkCanvas* canvas, const SkPath& path,
|
|
|
|
const SkPaint& paint, int N) {
|
2012-05-04 16:37:45 +00:00
|
|
|
for (int i = 0; i < N; ++i) {
|
2012-05-16 14:06:02 +00:00
|
|
|
// canvas->drawPoints(SkCanvas::kLines_PointMode, 2, fPts, paint);
|
2012-05-04 16:37:45 +00:00
|
|
|
canvas->drawPath(path, paint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2012-05-04 16:37:45 +00:00
|
|
|
};
|
|
|
|
|
2012-05-10 15:40:57 +00:00
|
|
|
class RectDashBench : public DashBench {
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
RectDashBench(const SkScalar intervals[], int count, int width)
|
|
|
|
: INHERITED(intervals, count, width) {
|
2012-05-10 15:40:57 +00:00
|
|
|
fName.append("_rect");
|
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2012-05-10 15:40:57 +00:00
|
|
|
protected:
|
|
|
|
virtual void handlePath(SkCanvas* canvas, const SkPath& path,
|
2015-03-26 01:17:31 +00:00
|
|
|
const SkPaint& paint, int N) override {
|
2012-05-10 15:40:57 +00:00
|
|
|
SkPoint pts[2];
|
|
|
|
if (!path.isLine(pts) || pts[0].fY != pts[1].fY) {
|
|
|
|
this->INHERITED::handlePath(canvas, path, paint, N);
|
|
|
|
} else {
|
|
|
|
SkRect rect;
|
|
|
|
rect.fLeft = pts[0].fX;
|
|
|
|
rect.fTop = pts[0].fY - paint.getStrokeWidth() / 2;
|
|
|
|
rect.fRight = rect.fLeft + SkIntToScalar(fWidth);
|
|
|
|
rect.fBottom = rect.fTop + paint.getStrokeWidth();
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2012-05-10 15:40:57 +00:00
|
|
|
SkPaint p(paint);
|
|
|
|
p.setStyle(SkPaint::kFill_Style);
|
2015-08-27 14:41:13 +00:00
|
|
|
p.setPathEffect(nullptr);
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2012-05-10 15:40:57 +00:00
|
|
|
int count = SkScalarRoundToInt((pts[1].fX - pts[0].fX) / (2*fWidth));
|
|
|
|
SkScalar dx = SkIntToScalar(2 * fWidth);
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2012-05-10 15:40:57 +00:00
|
|
|
for (int i = 0; i < N*10; ++i) {
|
|
|
|
SkRect r = rect;
|
|
|
|
for (int j = 0; j < count; ++j) {
|
|
|
|
canvas->drawRect(r, p);
|
|
|
|
r.offset(dx, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2012-05-10 15:40:57 +00:00
|
|
|
private:
|
|
|
|
typedef DashBench INHERITED;
|
|
|
|
};
|
|
|
|
|
2012-05-18 18:32:54 +00:00
|
|
|
static void make_unit_star(SkPath* path, int n) {
|
|
|
|
SkScalar rad = -SK_ScalarPI / 2;
|
|
|
|
const SkScalar drad = (n >> 1) * SK_ScalarPI * 2 / n;
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2012-05-18 18:32:54 +00:00
|
|
|
path->moveTo(0, -SK_Scalar1);
|
|
|
|
for (int i = 1; i < n; i++) {
|
|
|
|
rad += drad;
|
2019-04-02 14:59:28 +00:00
|
|
|
path->lineTo(SkScalarCos(rad), SkScalarSin(rad));
|
2012-05-18 18:32:54 +00:00
|
|
|
}
|
|
|
|
path->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void make_poly(SkPath* path) {
|
|
|
|
make_unit_star(path, 9);
|
2015-03-27 02:57:08 +00:00
|
|
|
const SkMatrix matrix = SkMatrix::MakeScale(SkIntToScalar(100), SkIntToScalar(100));
|
2012-05-18 18:32:54 +00:00
|
|
|
path->transform(matrix);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void make_quad(SkPath* path) {
|
|
|
|
SkScalar x0 = SkIntToScalar(10);
|
|
|
|
SkScalar y0 = SkIntToScalar(10);
|
|
|
|
path->moveTo(x0, y0);
|
|
|
|
path->quadTo(x0, y0 + 400 * SK_Scalar1,
|
|
|
|
x0 + 600 * SK_Scalar1, y0 + 400 * SK_Scalar1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void make_cubic(SkPath* path) {
|
|
|
|
SkScalar x0 = SkIntToScalar(10);
|
|
|
|
SkScalar y0 = SkIntToScalar(10);
|
|
|
|
path->moveTo(x0, y0);
|
|
|
|
path->cubicTo(x0, y0 + 400 * SK_Scalar1,
|
|
|
|
x0 + 600 * SK_Scalar1, y0 + 400 * SK_Scalar1,
|
|
|
|
x0 + 600 * SK_Scalar1, y0);
|
|
|
|
}
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class MakeDashBench : public Benchmark {
|
2012-05-18 18:32:54 +00:00
|
|
|
SkString fName;
|
|
|
|
SkPath fPath;
|
2016-03-18 18:22:57 +00:00
|
|
|
sk_sp<SkPathEffect> fPE;
|
2012-09-05 02:01:29 +00:00
|
|
|
|
2012-05-18 18:32:54 +00:00
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
MakeDashBench(void (*proc)(SkPath*), const char name[]) {
|
2012-05-18 18:32:54 +00:00
|
|
|
fName.printf("makedash_%s", name);
|
|
|
|
proc(&fPath);
|
2012-09-05 02:01:29 +00:00
|
|
|
|
2012-05-18 18:32:54 +00:00
|
|
|
SkScalar vals[] = { SkIntToScalar(4), SkIntToScalar(4) };
|
2016-03-18 18:22:57 +00:00
|
|
|
fPE = SkDashPathEffect::Make(vals, 2, 0);
|
2012-05-18 18:32:54 +00:00
|
|
|
}
|
2012-09-05 02:01:29 +00:00
|
|
|
|
2012-05-18 18:32:54 +00:00
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2012-05-18 18:32:54 +00:00
|
|
|
return fName.c_str();
|
|
|
|
}
|
2012-09-05 02:01:29 +00:00
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas*) override {
|
2012-05-18 18:32:54 +00:00
|
|
|
SkPath dst;
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; ++i) {
|
Change patheffect to take a (new) StrokeRec object, which encapsulates the fill
or stroke parameters for a path.
Today, the patheffect only sees if the caller was going to stroke or fill, and
if stroke, it just sees the width. With this change, the effect can see all of the
related parameters (e.g. cap/join/miter). No other change is intended at this
time.
After this change, I hope to use this additional data to allow SkDashPathEffect
to, at times, apply the stroke as part of its effect, which may be much more
efficient than first dashing, and then reading that and stroking it.
Most of these files changed just because of the new parameter to filterPath. The
key changes are in SkPathEffect.[h,cpp], SkPaint.cpp and SkScalerContext.cpp
Review URL: https://codereview.appspot.com/6250051
git-svn-id: http://skia.googlecode.com/svn/trunk@4048 2bbb7eff-a529-9590-31e7-b0007b416f81
2012-05-25 01:04:12 +00:00
|
|
|
SkStrokeRec rec(SkStrokeRec::kHairline_InitStyle);
|
2012-09-05 02:01:29 +00:00
|
|
|
|
2015-08-27 14:41:13 +00:00
|
|
|
fPE->filterPath(&dst, fPath, &rec, nullptr);
|
2012-05-18 18:32:54 +00:00
|
|
|
dst.rewind();
|
|
|
|
}
|
|
|
|
}
|
2012-09-05 02:01:29 +00:00
|
|
|
|
2012-09-04 20:07:23 +00:00
|
|
|
private:
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2012-09-04 20:07:23 +00:00
|
|
|
};
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2012-09-04 20:19:35 +00:00
|
|
|
/*
|
|
|
|
* We try to special case square dashes (intervals are equal to strokewidth).
|
|
|
|
*/
|
2014-06-19 19:32:29 +00:00
|
|
|
class DashLineBench : public Benchmark {
|
2012-09-04 20:07:23 +00:00
|
|
|
SkString fName;
|
2012-09-04 20:19:35 +00:00
|
|
|
SkScalar fStrokeWidth;
|
|
|
|
bool fIsRound;
|
2016-03-18 18:22:57 +00:00
|
|
|
sk_sp<SkPathEffect> fPE;
|
2012-09-05 02:01:29 +00:00
|
|
|
|
2012-09-04 20:07:23 +00:00
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
DashLineBench(SkScalar width, bool isRound) {
|
2012-09-04 20:19:35 +00:00
|
|
|
fName.printf("dashline_%g_%s", SkScalarToFloat(width), isRound ? "circle" : "square");
|
|
|
|
fStrokeWidth = width;
|
|
|
|
fIsRound = isRound;
|
2012-09-05 02:01:29 +00:00
|
|
|
|
2012-09-04 20:19:35 +00:00
|
|
|
SkScalar vals[] = { SK_Scalar1, SK_Scalar1 };
|
2016-03-18 18:22:57 +00:00
|
|
|
fPE = SkDashPathEffect::Make(vals, 2, 0);
|
2012-09-04 20:07:23 +00:00
|
|
|
}
|
2012-09-05 02:01:29 +00:00
|
|
|
|
2012-09-04 20:07:23 +00:00
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2012-09-04 20:07:23 +00:00
|
|
|
return fName.c_str();
|
|
|
|
}
|
2012-09-05 02:01:29 +00:00
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2012-09-04 20:07:23 +00:00
|
|
|
SkPaint paint;
|
|
|
|
this->setupPaint(&paint);
|
2012-09-04 20:19:35 +00:00
|
|
|
paint.setStrokeWidth(fStrokeWidth);
|
|
|
|
paint.setStrokeCap(fIsRound ? SkPaint::kRound_Cap : SkPaint::kSquare_Cap);
|
2012-09-04 20:07:23 +00:00
|
|
|
paint.setPathEffect(fPE);
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; ++i) {
|
2012-09-04 20:19:35 +00:00
|
|
|
canvas->drawLine(10 * SK_Scalar1, 10 * SK_Scalar1,
|
|
|
|
640 * SK_Scalar1, 10 * SK_Scalar1, paint);
|
2012-09-04 20:07:23 +00:00
|
|
|
}
|
|
|
|
}
|
2012-09-05 02:01:29 +00:00
|
|
|
|
2012-05-18 18:32:54 +00:00
|
|
|
private:
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2012-05-18 18:32:54 +00:00
|
|
|
};
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class DrawPointsDashingBench : public Benchmark {
|
2012-12-05 19:07:21 +00:00
|
|
|
SkString fName;
|
|
|
|
int fStrokeWidth;
|
2012-12-12 15:58:25 +00:00
|
|
|
bool fDoAA;
|
2012-12-05 19:07:21 +00:00
|
|
|
|
2016-03-18 18:22:57 +00:00
|
|
|
sk_sp<SkPathEffect> fPathEffect;
|
2012-12-05 19:07:21 +00:00
|
|
|
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
DrawPointsDashingBench(int dashLength, int strokeWidth, bool doAA)
|
|
|
|
{
|
2012-12-05 19:07:21 +00:00
|
|
|
fName.printf("drawpointsdash_%d_%d%s", dashLength, strokeWidth, doAA ? "_aa" : "_bw");
|
|
|
|
fStrokeWidth = strokeWidth;
|
2012-12-12 15:58:25 +00:00
|
|
|
fDoAA = doAA;
|
2012-12-05 19:07:21 +00:00
|
|
|
|
|
|
|
SkScalar vals[] = { SkIntToScalar(dashLength), SkIntToScalar(dashLength) };
|
2016-03-18 18:22:57 +00:00
|
|
|
fPathEffect = SkDashPathEffect::Make(vals, 2, SK_Scalar1);
|
2012-12-05 19:07:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2012-12-05 19:07:21 +00:00
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2012-12-05 19:07:21 +00:00
|
|
|
SkPaint p;
|
|
|
|
this->setupPaint(&p);
|
|
|
|
p.setColor(SK_ColorBLACK);
|
|
|
|
p.setStyle(SkPaint::kStroke_Style);
|
|
|
|
p.setStrokeWidth(SkIntToScalar(fStrokeWidth));
|
|
|
|
p.setPathEffect(fPathEffect);
|
2012-12-12 15:58:25 +00:00
|
|
|
p.setAntiAlias(fDoAA);
|
2012-12-05 19:07:21 +00:00
|
|
|
|
|
|
|
SkPoint pts[2] = {
|
|
|
|
{ SkIntToScalar(10), 0 },
|
|
|
|
{ SkIntToScalar(640), 0 }
|
|
|
|
};
|
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; ++i) {
|
2012-12-05 19:07:21 +00:00
|
|
|
pts[0].fY = pts[1].fY = SkIntToScalar(i % 480);
|
|
|
|
canvas->drawPoints(SkCanvas::kLines_PointMode, 2, pts, p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2012-12-05 19:07:21 +00:00
|
|
|
};
|
2013-01-24 17:17:28 +00:00
|
|
|
|
2013-01-24 17:33:21 +00:00
|
|
|
// Want to test how we handle dashing when 99% of the dash is clipped out
|
2014-06-19 19:32:29 +00:00
|
|
|
class GiantDashBench : public Benchmark {
|
2013-01-24 17:17:28 +00:00
|
|
|
SkString fName;
|
2013-01-24 17:33:21 +00:00
|
|
|
SkScalar fStrokeWidth;
|
2013-01-24 17:17:28 +00:00
|
|
|
SkPoint fPts[2];
|
2016-03-18 18:22:57 +00:00
|
|
|
sk_sp<SkPathEffect> fPathEffect;
|
2013-01-25 07:06:46 +00:00
|
|
|
|
2013-01-24 17:17:28 +00:00
|
|
|
public:
|
|
|
|
enum LineType {
|
|
|
|
kHori_LineType,
|
|
|
|
kVert_LineType,
|
2013-04-22 20:26:44 +00:00
|
|
|
kDiag_LineType,
|
|
|
|
kLineTypeCount
|
2013-01-24 17:17:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const char* LineTypeName(LineType lt) {
|
|
|
|
static const char* gNames[] = { "hori", "vert", "diag" };
|
2015-08-20 14:57:51 +00:00
|
|
|
static_assert(kLineTypeCount == SK_ARRAY_COUNT(gNames), "names_wrong_size");
|
2013-01-24 17:17:28 +00:00
|
|
|
return gNames[lt];
|
|
|
|
}
|
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
GiantDashBench(LineType lt, SkScalar width) {
|
2013-01-24 17:33:21 +00:00
|
|
|
fName.printf("giantdashline_%s_%g", LineTypeName(lt), width);
|
|
|
|
fStrokeWidth = width;
|
|
|
|
|
2013-01-24 17:17:28 +00:00
|
|
|
// deliberately pick intervals that won't be caught by asPoints(), so
|
|
|
|
// we can test the filterPath code-path.
|
2014-05-01 15:30:52 +00:00
|
|
|
const SkScalar intervals[] = { 20, 10, 10, 10 };
|
2016-03-18 18:22:57 +00:00
|
|
|
fPathEffect = SkDashPathEffect::Make(intervals, SK_ARRAY_COUNT(intervals), 0);
|
2013-01-24 17:17:28 +00:00
|
|
|
|
|
|
|
SkScalar cx = 640 / 2; // center X
|
|
|
|
SkScalar cy = 480 / 2; // center Y
|
|
|
|
SkMatrix matrix;
|
2013-01-25 07:06:46 +00:00
|
|
|
|
2013-01-24 17:17:28 +00:00
|
|
|
switch (lt) {
|
|
|
|
case kHori_LineType:
|
|
|
|
matrix.setIdentity();
|
|
|
|
break;
|
|
|
|
case kVert_LineType:
|
|
|
|
matrix.setRotate(90, cx, cy);
|
|
|
|
break;
|
|
|
|
case kDiag_LineType:
|
|
|
|
matrix.setRotate(45, cx, cy);
|
|
|
|
break;
|
2013-04-22 20:26:44 +00:00
|
|
|
case kLineTypeCount:
|
|
|
|
// Not a real enum value.
|
|
|
|
break;
|
2013-01-24 17:17:28 +00:00
|
|
|
}
|
2013-01-25 07:06:46 +00:00
|
|
|
|
2013-01-24 17:33:21 +00:00
|
|
|
const SkScalar overshoot = 100*1000;
|
2013-01-24 17:17:28 +00:00
|
|
|
const SkPoint pts[2] = {
|
|
|
|
{ -overshoot, cy }, { 640 + overshoot, cy }
|
|
|
|
};
|
|
|
|
matrix.mapPoints(fPts, pts, 2);
|
|
|
|
}
|
2013-01-25 07:06:46 +00:00
|
|
|
|
2013-01-24 17:17:28 +00:00
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2013-01-24 17:17:28 +00:00
|
|
|
return fName.c_str();
|
|
|
|
}
|
2013-01-25 07:06:46 +00:00
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2013-01-24 17:17:28 +00:00
|
|
|
SkPaint p;
|
|
|
|
this->setupPaint(&p);
|
|
|
|
p.setStyle(SkPaint::kStroke_Style);
|
2013-01-24 17:33:21 +00:00
|
|
|
p.setStrokeWidth(fStrokeWidth);
|
2013-01-24 17:17:28 +00:00
|
|
|
p.setPathEffect(fPathEffect);
|
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; i++) {
|
2013-09-10 19:23:38 +00:00
|
|
|
canvas->drawPoints(SkCanvas::kLines_PointMode, 2, fPts, p);
|
|
|
|
}
|
2013-01-24 17:17:28 +00:00
|
|
|
}
|
2013-01-25 07:06:46 +00:00
|
|
|
|
2013-01-24 17:17:28 +00:00
|
|
|
private:
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2013-01-24 17:17:28 +00:00
|
|
|
};
|
|
|
|
|
2014-06-04 15:15:31 +00:00
|
|
|
// Want to test how we draw a dashed grid (like what is used in spreadsheets) of many
|
|
|
|
// small dashed lines switching back and forth between horizontal and vertical
|
2014-06-19 19:32:29 +00:00
|
|
|
class DashGridBench : public Benchmark {
|
2014-06-04 15:15:31 +00:00
|
|
|
SkString fName;
|
|
|
|
int fStrokeWidth;
|
|
|
|
bool fDoAA;
|
|
|
|
|
2016-03-18 18:22:57 +00:00
|
|
|
sk_sp<SkPathEffect> fPathEffect;
|
2014-06-04 15:15:31 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
DashGridBench(int dashLength, int strokeWidth, bool doAA) {
|
|
|
|
fName.printf("dashgrid_%d_%d%s", dashLength, strokeWidth, doAA ? "_aa" : "_bw");
|
|
|
|
fStrokeWidth = strokeWidth;
|
|
|
|
fDoAA = doAA;
|
|
|
|
|
|
|
|
SkScalar vals[] = { SkIntToScalar(dashLength), SkIntToScalar(dashLength) };
|
2016-03-18 18:22:57 +00:00
|
|
|
fPathEffect = SkDashPathEffect::Make(vals, 2, SK_Scalar1);
|
2014-06-04 15:15:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2014-06-04 15:15:31 +00:00
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2014-06-04 15:15:31 +00:00
|
|
|
SkPaint p;
|
|
|
|
this->setupPaint(&p);
|
|
|
|
p.setColor(SK_ColorBLACK);
|
|
|
|
p.setStyle(SkPaint::kStroke_Style);
|
|
|
|
p.setStrokeWidth(SkIntToScalar(fStrokeWidth));
|
|
|
|
p.setPathEffect(fPathEffect);
|
|
|
|
p.setAntiAlias(fDoAA);
|
|
|
|
|
|
|
|
SkPoint pts[4] = {
|
|
|
|
{ SkIntToScalar(0), 20.5f },
|
|
|
|
{ SkIntToScalar(20), 20.5f },
|
|
|
|
{ 20.5f, SkIntToScalar(0) },
|
|
|
|
{ 20.5f, SkIntToScalar(20) }
|
|
|
|
};
|
|
|
|
|
|
|
|
for (int i = 0; i < loops; ++i) {
|
|
|
|
for (int j = 0; j < 10; ++j) {
|
|
|
|
for (int k = 0; k < 10; ++k) {
|
|
|
|
// Horizontal line
|
|
|
|
SkPoint horPts[2];
|
|
|
|
horPts[0].fX = pts[0].fX + k * 22.f;
|
|
|
|
horPts[0].fY = pts[0].fY + j * 22.f;
|
|
|
|
horPts[1].fX = pts[1].fX + k * 22.f;
|
|
|
|
horPts[1].fY = pts[1].fY + j * 22.f;
|
|
|
|
canvas->drawPoints(SkCanvas::kLines_PointMode, 2, horPts, p);
|
|
|
|
|
|
|
|
// Vertical line
|
|
|
|
SkPoint vertPts[2];
|
|
|
|
vertPts[0].fX = pts[2].fX + k * 22.f;
|
|
|
|
vertPts[0].fY = pts[2].fY + j * 22.f;
|
|
|
|
vertPts[1].fX = pts[3].fX + k * 22.f;
|
|
|
|
vertPts[1].fY = pts[3].fY + j * 22.f;
|
|
|
|
canvas->drawPoints(SkCanvas::kLines_PointMode, 2, vertPts, p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2014-06-04 15:15:31 +00:00
|
|
|
};
|
2013-01-24 17:17:28 +00:00
|
|
|
|
2012-05-04 16:37:45 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static const SkScalar gDots[] = { SK_Scalar1, SK_Scalar1 };
|
|
|
|
|
|
|
|
#define PARAM(array) array, SK_ARRAY_COUNT(array)
|
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH( return new DashBench(PARAM(gDots), 0); )
|
|
|
|
DEF_BENCH( return new DashBench(PARAM(gDots), 1); )
|
|
|
|
DEF_BENCH( return new DashBench(PARAM(gDots), 1, true); )
|
|
|
|
DEF_BENCH( return new DashBench(PARAM(gDots), 4); )
|
|
|
|
DEF_BENCH( return new MakeDashBench(make_poly, "poly"); )
|
|
|
|
DEF_BENCH( return new MakeDashBench(make_quad, "quad"); )
|
|
|
|
DEF_BENCH( return new MakeDashBench(make_cubic, "cubic"); )
|
|
|
|
DEF_BENCH( return new DashLineBench(0, false); )
|
|
|
|
DEF_BENCH( return new DashLineBench(SK_Scalar1, false); )
|
|
|
|
DEF_BENCH( return new DashLineBench(2 * SK_Scalar1, false); )
|
|
|
|
DEF_BENCH( return new DashLineBench(0, true); )
|
|
|
|
DEF_BENCH( return new DashLineBench(SK_Scalar1, true); )
|
|
|
|
DEF_BENCH( return new DashLineBench(2 * SK_Scalar1, true); )
|
|
|
|
|
|
|
|
DEF_BENCH( return new DrawPointsDashingBench(1, 1, false); )
|
|
|
|
DEF_BENCH( return new DrawPointsDashingBench(1, 1, true); )
|
|
|
|
DEF_BENCH( return new DrawPointsDashingBench(3, 1, false); )
|
|
|
|
DEF_BENCH( return new DrawPointsDashingBench(3, 1, true); )
|
|
|
|
DEF_BENCH( return new DrawPointsDashingBench(5, 5, false); )
|
|
|
|
DEF_BENCH( return new DrawPointsDashingBench(5, 5, true); )
|
2013-01-24 17:17:28 +00:00
|
|
|
|
2013-07-18 17:22:30 +00:00
|
|
|
/* Disable the GiantDashBench for Android devices until we can better control
|
|
|
|
* the memory usage. (https://code.google.com/p/skia/issues/detail?id=1430)
|
|
|
|
*/
|
|
|
|
#ifndef SK_BUILD_FOR_ANDROID
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH( return new GiantDashBench(GiantDashBench::kHori_LineType, 0); )
|
|
|
|
DEF_BENCH( return new GiantDashBench(GiantDashBench::kVert_LineType, 0); )
|
|
|
|
DEF_BENCH( return new GiantDashBench(GiantDashBench::kDiag_LineType, 0); )
|
2013-01-24 17:33:21 +00:00
|
|
|
|
|
|
|
// pass 2 to explicitly avoid any 1-is-the-same-as-hairline special casing
|
|
|
|
|
|
|
|
// hori_2 is just too slow to enable at the moment
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH( return new GiantDashBench(GiantDashBench::kHori_LineType, 2); )
|
|
|
|
DEF_BENCH( return new GiantDashBench(GiantDashBench::kVert_LineType, 2); )
|
|
|
|
DEF_BENCH( return new GiantDashBench(GiantDashBench::kDiag_LineType, 2); )
|
2014-06-04 15:15:31 +00:00
|
|
|
|
|
|
|
DEF_BENCH( return new DashGridBench(1, 1, true); )
|
|
|
|
DEF_BENCH( return new DashGridBench(1, 1, false); )
|
|
|
|
DEF_BENCH( return new DashGridBench(3, 1, true); )
|
|
|
|
DEF_BENCH( return new DashGridBench(3, 1, false); )
|
2013-07-18 17:22:30 +00:00
|
|
|
#endif
|