2012-05-04 21:49:27 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gm.h"
|
2017-03-22 17:47:51 +00:00
|
|
|
#include "sk_tool_utils.h"
|
2012-05-04 21:49:27 +00:00
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkPaint.h"
|
|
|
|
#include "SkDashPathEffect.h"
|
|
|
|
|
2012-05-21 16:47:43 +00:00
|
|
|
static void drawline(SkCanvas* canvas, int on, int off, const SkPaint& paint,
|
2014-05-19 14:32:49 +00:00
|
|
|
SkScalar finalX = SkIntToScalar(600), SkScalar finalY = SkIntToScalar(0),
|
2016-03-29 16:03:52 +00:00
|
|
|
SkScalar phase = SkIntToScalar(0),
|
2014-11-04 21:33:50 +00:00
|
|
|
SkScalar startX = SkIntToScalar(0), SkScalar startY = SkIntToScalar(0)) {
|
2012-05-04 21:49:27 +00:00
|
|
|
SkPaint p(paint);
|
|
|
|
|
|
|
|
const SkScalar intervals[] = {
|
|
|
|
SkIntToScalar(on),
|
|
|
|
SkIntToScalar(off),
|
|
|
|
};
|
|
|
|
|
2016-03-18 18:22:57 +00:00
|
|
|
p.setPathEffect(SkDashPathEffect::Make(intervals, 2, phase));
|
2014-11-04 21:33:50 +00:00
|
|
|
canvas->drawLine(startX, startY, finalX, finalY, p);
|
2012-05-21 16:47:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// earlier bug stopped us from drawing very long single-segment dashes, because
|
|
|
|
// SkPathMeasure was skipping very small delta-T values (nearlyzero). This is
|
|
|
|
// now fixes, so this giant dash should appear.
|
|
|
|
static void show_giant_dash(SkCanvas* canvas) {
|
|
|
|
SkPaint paint;
|
|
|
|
|
|
|
|
drawline(canvas, 1, 1, paint, SkIntToScalar(20 * 1000));
|
2012-05-04 21:49:27 +00:00
|
|
|
}
|
|
|
|
|
2014-11-05 13:02:27 +00:00
|
|
|
static void show_zero_len_dash(SkCanvas* canvas) {
|
|
|
|
SkPaint paint;
|
|
|
|
|
|
|
|
drawline(canvas, 2, 2, paint, SkIntToScalar(0));
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
paint.setStrokeWidth(SkIntToScalar(2));
|
|
|
|
canvas->translate(0, SkIntToScalar(20));
|
|
|
|
drawline(canvas, 4, 4, paint, SkIntToScalar(0));
|
|
|
|
}
|
|
|
|
|
2012-05-18 17:59:08 +00:00
|
|
|
class DashingGM : public skiagm::GM {
|
2012-05-04 21:49:27 +00:00
|
|
|
public:
|
|
|
|
DashingGM() {}
|
|
|
|
|
|
|
|
protected:
|
2014-04-30 13:20:45 +00:00
|
|
|
|
2012-05-04 21:49:27 +00:00
|
|
|
SkString onShortName() {
|
|
|
|
return SkString("dashing");
|
|
|
|
}
|
|
|
|
|
2015-10-05 15:11:49 +00:00
|
|
|
SkISize onISize() { return SkISize::Make(640, 340); }
|
2012-05-04 21:49:27 +00:00
|
|
|
|
|
|
|
virtual void onDraw(SkCanvas* canvas) {
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr struct {
|
2012-05-04 21:49:27 +00:00
|
|
|
int fOnInterval;
|
|
|
|
int fOffInterval;
|
|
|
|
} gData[] = {
|
|
|
|
{ 1, 1 },
|
|
|
|
{ 4, 1 },
|
|
|
|
};
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2012-05-04 21:49:27 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
|
|
|
|
canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
|
|
|
|
canvas->translate(0, SK_ScalarHalf);
|
|
|
|
for (int width = 0; width <= 2; ++width) {
|
|
|
|
for (size_t data = 0; data < SK_ARRAY_COUNT(gData); ++data) {
|
|
|
|
for (int aa = 0; aa <= 1; ++aa) {
|
|
|
|
int w = width * width * width;
|
|
|
|
paint.setAntiAlias(SkToBool(aa));
|
|
|
|
paint.setStrokeWidth(SkIntToScalar(w));
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2012-05-04 21:49:27 +00:00
|
|
|
int scale = w ? w : 1;
|
|
|
|
|
|
|
|
drawline(canvas, gData[data].fOnInterval * scale,
|
|
|
|
gData[data].fOffInterval * scale,
|
|
|
|
paint);
|
|
|
|
canvas->translate(0, SkIntToScalar(20));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2012-05-21 16:47:43 +00:00
|
|
|
show_giant_dash(canvas);
|
2014-11-05 13:02:27 +00:00
|
|
|
canvas->translate(0, SkIntToScalar(20));
|
|
|
|
show_zero_len_dash(canvas);
|
2015-10-05 15:11:49 +00:00
|
|
|
canvas->translate(0, SkIntToScalar(20));
|
|
|
|
// Draw 0 on, 0 off dashed line
|
|
|
|
paint.setStrokeWidth(SkIntToScalar(8));
|
|
|
|
drawline(canvas, 0, 0, paint);
|
2012-05-04 21:49:27 +00:00
|
|
|
}
|
2012-05-18 17:59:08 +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:19:56 +00:00
|
|
|
|
2012-05-18 17:59:08 +00:00
|
|
|
path->moveTo(0, -SK_Scalar1);
|
|
|
|
for (int i = 1; i < n; i++) {
|
|
|
|
rad += drad;
|
|
|
|
SkScalar cosV, sinV = SkScalarSinCos(rad, &cosV);
|
|
|
|
path->lineTo(cosV, sinV);
|
|
|
|
}
|
|
|
|
path->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void make_path_line(SkPath* path, const SkRect& bounds) {
|
|
|
|
path->moveTo(bounds.left(), bounds.top());
|
|
|
|
path->lineTo(bounds.right(), bounds.bottom());
|
|
|
|
}
|
|
|
|
|
|
|
|
static void make_path_rect(SkPath* path, const SkRect& bounds) {
|
|
|
|
path->addRect(bounds);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void make_path_oval(SkPath* path, const SkRect& bounds) {
|
|
|
|
path->addOval(bounds);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void make_path_star(SkPath* path, const SkRect& bounds) {
|
|
|
|
make_unit_star(path, 5);
|
|
|
|
SkMatrix matrix;
|
|
|
|
matrix.setRectToRect(path->getBounds(), bounds, SkMatrix::kCenter_ScaleToFit);
|
|
|
|
path->transform(matrix);
|
|
|
|
}
|
|
|
|
|
|
|
|
class Dashing2GM : public skiagm::GM {
|
|
|
|
public:
|
|
|
|
Dashing2GM() {}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2012-05-18 17:59:08 +00:00
|
|
|
protected:
|
2014-04-30 13:20:45 +00:00
|
|
|
|
2012-05-18 17:59:08 +00:00
|
|
|
SkString onShortName() {
|
|
|
|
return SkString("dashing2");
|
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2014-06-10 06:59:03 +00:00
|
|
|
SkISize onISize() { return SkISize::Make(640, 480); }
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2012-05-18 17:59:08 +00:00
|
|
|
virtual void onDraw(SkCanvas* canvas) {
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr int gIntervals[] = {
|
2012-05-18 17:59:08 +00:00
|
|
|
3, // 3 dashes: each count [0] followed by intervals [1..count]
|
|
|
|
2, 10, 10,
|
|
|
|
4, 20, 5, 5, 5,
|
|
|
|
2, 2, 2
|
|
|
|
};
|
2012-05-04 21:49:27 +00:00
|
|
|
|
2012-05-18 17:59:08 +00:00
|
|
|
void (*gProc[])(SkPath*, const SkRect&) = {
|
|
|
|
make_path_line, make_path_rect, make_path_oval, make_path_star,
|
|
|
|
};
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2012-05-18 17:59:08 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
paint.setStrokeWidth(SkIntToScalar(6));
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2012-05-18 17:59:08 +00:00
|
|
|
SkRect bounds = SkRect::MakeWH(SkIntToScalar(120), SkIntToScalar(120));
|
|
|
|
bounds.offset(SkIntToScalar(20), SkIntToScalar(20));
|
|
|
|
SkScalar dx = bounds.width() * 4 / 3;
|
|
|
|
SkScalar dy = bounds.height() * 4 / 3;
|
|
|
|
|
|
|
|
const int* intervals = &gIntervals[1];
|
|
|
|
for (int y = 0; y < gIntervals[0]; ++y) {
|
|
|
|
SkScalar vals[SK_ARRAY_COUNT(gIntervals)]; // more than enough
|
|
|
|
int count = *intervals++;
|
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
vals[i] = SkIntToScalar(*intervals++);
|
|
|
|
}
|
|
|
|
SkScalar phase = vals[0] / 2;
|
2016-03-18 18:22:57 +00:00
|
|
|
paint.setPathEffect(SkDashPathEffect::Make(vals, count, phase));
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2012-05-18 17:59:08 +00:00
|
|
|
for (size_t x = 0; x < SK_ARRAY_COUNT(gProc); ++x) {
|
|
|
|
SkPath path;
|
|
|
|
SkRect r = bounds;
|
|
|
|
r.offset(x * dx, y * dy);
|
|
|
|
gProc[x](&path, r);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2012-05-18 17:59:08 +00:00
|
|
|
canvas->drawPath(path, paint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-05-04 21:49:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-11-28 17:18:11 +00:00
|
|
|
// Test out the on/off line dashing Chrome if fond of
|
|
|
|
class Dashing3GM : public skiagm::GM {
|
|
|
|
public:
|
|
|
|
Dashing3GM() {}
|
|
|
|
|
|
|
|
protected:
|
2014-04-30 13:20:45 +00:00
|
|
|
|
2012-11-28 17:18:11 +00:00
|
|
|
SkString onShortName() {
|
|
|
|
return SkString("dashing3");
|
|
|
|
}
|
|
|
|
|
2014-06-10 06:59:03 +00:00
|
|
|
SkISize onISize() { return SkISize::Make(640, 480); }
|
2012-11-28 17:18:11 +00:00
|
|
|
|
|
|
|
// Draw a 100x100 block of dashed lines. The horizontal ones are BW
|
|
|
|
// while the vertical ones are AA.
|
2012-12-05 02:01:21 +00:00
|
|
|
void drawDashedLines(SkCanvas* canvas,
|
|
|
|
SkScalar lineLength,
|
2012-12-04 20:34:11 +00:00
|
|
|
SkScalar phase,
|
|
|
|
SkScalar dashLength,
|
|
|
|
int strokeWidth,
|
|
|
|
bool circles) {
|
2012-11-28 17:18:11 +00:00
|
|
|
SkPaint p;
|
|
|
|
p.setColor(SK_ColorBLACK);
|
|
|
|
p.setStyle(SkPaint::kStroke_Style);
|
2012-12-04 20:34:11 +00:00
|
|
|
p.setStrokeWidth(SkIntToScalar(strokeWidth));
|
2012-11-28 17:18:11 +00:00
|
|
|
|
2012-12-04 20:34:11 +00:00
|
|
|
if (circles) {
|
|
|
|
p.setStrokeCap(SkPaint::kRound_Cap);
|
|
|
|
}
|
|
|
|
|
|
|
|
SkScalar intervals[2] = { dashLength, dashLength };
|
2012-11-28 17:18:11 +00:00
|
|
|
|
2016-03-18 18:22:57 +00:00
|
|
|
p.setPathEffect(SkDashPathEffect::Make(intervals, 2, phase));
|
2012-11-28 17:18:11 +00:00
|
|
|
|
|
|
|
SkPoint pts[2];
|
|
|
|
|
2012-12-04 20:34:11 +00:00
|
|
|
for (int y = 0; y < 100; y += 10*strokeWidth) {
|
2012-11-28 17:18:11 +00:00
|
|
|
pts[0].set(0, SkIntToScalar(y));
|
2012-12-04 20:34:11 +00:00
|
|
|
pts[1].set(lineLength, SkIntToScalar(y));
|
2012-11-28 17:18:11 +00:00
|
|
|
|
|
|
|
canvas->drawPoints(SkCanvas::kLines_PointMode, 2, pts, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
p.setAntiAlias(true);
|
|
|
|
|
2012-12-04 20:34:11 +00:00
|
|
|
for (int x = 0; x < 100; x += 14*strokeWidth) {
|
2012-11-28 17:18:11 +00:00
|
|
|
pts[0].set(SkIntToScalar(x), 0);
|
2012-12-04 20:34:11 +00:00
|
|
|
pts[1].set(SkIntToScalar(x), lineLength);
|
2012-11-28 17:18:11 +00:00
|
|
|
|
|
|
|
canvas->drawPoints(SkCanvas::kLines_PointMode, 2, pts, p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void onDraw(SkCanvas* canvas) {
|
2012-12-04 20:34:11 +00:00
|
|
|
// 1on/1off 1x1 squares with phase of 0 - points fastpath
|
|
|
|
canvas->save();
|
|
|
|
canvas->translate(2, 0);
|
|
|
|
this->drawDashedLines(canvas, 100, 0, SK_Scalar1, 1, false);
|
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
// 1on/1off 1x1 squares with phase of .5 - rects fastpath (due to partial squares)
|
|
|
|
canvas->save();
|
|
|
|
canvas->translate(112, 0);
|
|
|
|
this->drawDashedLines(canvas, 100, SK_ScalarHalf, SK_Scalar1, 1, false);
|
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
// 1on/1off 1x1 squares with phase of 1 - points fastpath
|
|
|
|
canvas->save();
|
|
|
|
canvas->translate(222, 0);
|
|
|
|
this->drawDashedLines(canvas, 100, SK_Scalar1, SK_Scalar1, 1, false);
|
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
// 1on/1off 1x1 squares with phase of 1 and non-integer length - rects fastpath
|
|
|
|
canvas->save();
|
|
|
|
canvas->translate(332, 0);
|
2013-01-07 20:25:04 +00:00
|
|
|
this->drawDashedLines(canvas, 99.5f, SK_ScalarHalf, SK_Scalar1, 1, false);
|
2012-12-04 20:34:11 +00:00
|
|
|
canvas->restore();
|
|
|
|
|
2013-01-15 12:53:31 +00:00
|
|
|
// 255on/255off 1x1 squares with phase of 0 - rects fast path
|
|
|
|
canvas->save();
|
|
|
|
canvas->translate(446, 0);
|
|
|
|
this->drawDashedLines(canvas, 100, 0, SkIntToScalar(255), 1, false);
|
|
|
|
canvas->restore();
|
|
|
|
|
2012-12-04 20:34:11 +00:00
|
|
|
// 1on/1off 3x3 squares with phase of 0 - points fast path
|
2012-11-28 17:18:11 +00:00
|
|
|
canvas->save();
|
2012-12-04 20:34:11 +00:00
|
|
|
canvas->translate(2, 110);
|
|
|
|
this->drawDashedLines(canvas, 100, 0, SkIntToScalar(3), 3, false);
|
2012-11-28 17:18:11 +00:00
|
|
|
canvas->restore();
|
|
|
|
|
2012-12-04 20:34:11 +00:00
|
|
|
// 1on/1off 3x3 squares with phase of 1.5 - rects fast path
|
2012-11-28 17:18:11 +00:00
|
|
|
canvas->save();
|
2012-12-04 20:34:11 +00:00
|
|
|
canvas->translate(112, 110);
|
2013-11-25 19:44:07 +00:00
|
|
|
this->drawDashedLines(canvas, 100, 1.5f, SkIntToScalar(3), 3, false);
|
2012-11-28 17:18:11 +00:00
|
|
|
canvas->restore();
|
|
|
|
|
2012-12-04 20:34:11 +00:00
|
|
|
// 1on/1off 1x1 circles with phase of 1 - no fast path yet
|
2012-11-28 17:18:11 +00:00
|
|
|
canvas->save();
|
2012-12-04 20:34:11 +00:00
|
|
|
canvas->translate(2, 220);
|
|
|
|
this->drawDashedLines(canvas, 100, SK_Scalar1, SK_Scalar1, 1, true);
|
2012-11-28 17:18:11 +00:00
|
|
|
canvas->restore();
|
|
|
|
|
2012-12-04 20:34:11 +00:00
|
|
|
// 1on/1off 3x3 circles with phase of 1 - no fast path yet
|
2012-11-28 17:18:11 +00:00
|
|
|
canvas->save();
|
2012-12-04 20:34:11 +00:00
|
|
|
canvas->translate(112, 220);
|
|
|
|
this->drawDashedLines(canvas, 100, 0, SkIntToScalar(3), 3, true);
|
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
// 1on/1off 1x1 squares with rotation - should break fast path
|
|
|
|
canvas->save();
|
|
|
|
canvas->translate(332+SK_ScalarRoot2Over2*100, 110+SK_ScalarRoot2Over2*100);
|
2012-11-28 17:18:11 +00:00
|
|
|
canvas->rotate(45);
|
|
|
|
canvas->translate(-50, -50);
|
|
|
|
|
2012-12-04 20:34:11 +00:00
|
|
|
this->drawDashedLines(canvas, 100, SK_Scalar1, SK_Scalar1, 1, false);
|
2012-11-28 17:18:11 +00:00
|
|
|
canvas->restore();
|
|
|
|
|
2012-12-04 20:34:11 +00:00
|
|
|
// 3on/3off 3x1 rects - should use rect fast path regardless of phase
|
|
|
|
for (int phase = 0; phase <= 3; ++phase) {
|
|
|
|
canvas->save();
|
2012-12-05 02:01:21 +00:00
|
|
|
canvas->translate(SkIntToScalar(phase*110+2),
|
2012-12-04 20:34:11 +00:00
|
|
|
SkIntToScalar(330));
|
|
|
|
this->drawDashedLines(canvas, 100, SkIntToScalar(phase), SkIntToScalar(3), 1, false);
|
|
|
|
canvas->restore();
|
|
|
|
}
|
2012-11-28 17:18:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-05-19 14:32:49 +00:00
|
|
|
class Dashing4GM : public skiagm::GM {
|
|
|
|
public:
|
|
|
|
Dashing4GM() {}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
SkString onShortName() {
|
|
|
|
return SkString("dashing4");
|
|
|
|
}
|
|
|
|
|
2017-06-29 16:27:48 +00:00
|
|
|
SkISize onISize() { return SkISize::Make(640, 1050); }
|
2014-05-19 14:32:49 +00:00
|
|
|
|
|
|
|
virtual void onDraw(SkCanvas* canvas) {
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr struct {
|
2014-05-19 14:32:49 +00:00
|
|
|
int fOnInterval;
|
|
|
|
int fOffInterval;
|
|
|
|
} gData[] = {
|
|
|
|
{ 1, 1 },
|
|
|
|
{ 4, 2 },
|
|
|
|
{ 0, 4 }, // test for zero length on interval
|
|
|
|
};
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
|
|
|
|
canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
|
2017-06-30 14:36:38 +00:00
|
|
|
canvas->translate(SK_ScalarHalf, SK_ScalarHalf);
|
2014-05-19 14:32:49 +00:00
|
|
|
|
|
|
|
for (int width = 0; width <= 2; ++width) {
|
|
|
|
for (size_t data = 0; data < SK_ARRAY_COUNT(gData); ++data) {
|
|
|
|
for (int aa = 0; aa <= 1; ++aa) {
|
|
|
|
for (int cap = 0; cap <= 1; ++cap) {
|
|
|
|
int w = width * width * width;
|
|
|
|
paint.setAntiAlias(SkToBool(aa));
|
|
|
|
paint.setStrokeWidth(SkIntToScalar(w));
|
|
|
|
|
|
|
|
SkToBool(cap) ? paint.setStrokeCap(SkPaint::kSquare_Cap)
|
|
|
|
: paint.setStrokeCap(SkPaint::kRound_Cap);
|
|
|
|
|
|
|
|
int scale = w ? w : 1;
|
|
|
|
|
|
|
|
drawline(canvas, gData[data].fOnInterval * scale,
|
|
|
|
gData[data].fOffInterval * scale,
|
|
|
|
paint);
|
|
|
|
canvas->translate(0, SkIntToScalar(20));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int aa = 0; aa <= 1; ++aa) {
|
|
|
|
paint.setAntiAlias(SkToBool(aa));
|
|
|
|
paint.setStrokeWidth(8.f);
|
|
|
|
paint.setStrokeCap(SkPaint::kSquare_Cap);
|
|
|
|
// Single dash element that is cut off at start and end
|
2014-05-19 14:59:04 +00:00
|
|
|
drawline(canvas, 32, 16, paint, 20.f, 0, 5.f);
|
2014-05-19 14:32:49 +00:00
|
|
|
canvas->translate(0, SkIntToScalar(20));
|
|
|
|
|
|
|
|
// Two dash elements where each one is cut off at beginning and end respectively
|
2014-05-19 14:59:04 +00:00
|
|
|
drawline(canvas, 32, 16, paint, 56.f, 0, 5.f);
|
2014-05-19 14:32:49 +00:00
|
|
|
canvas->translate(0, SkIntToScalar(20));
|
|
|
|
|
|
|
|
// Many dash elements where first and last are cut off at beginning and end respectively
|
2014-05-19 14:59:04 +00:00
|
|
|
drawline(canvas, 32, 16, paint, 584.f, 0, 5.f);
|
2014-05-19 14:32:49 +00:00
|
|
|
canvas->translate(0, SkIntToScalar(20));
|
|
|
|
|
|
|
|
// Diagonal dash line where src pnts are not axis aligned (as apposed to being diagonal from
|
|
|
|
// a canvas rotation)
|
2014-05-19 14:59:04 +00:00
|
|
|
drawline(canvas, 32, 16, paint, 600.f, 30.f);
|
2014-05-19 14:32:49 +00:00
|
|
|
canvas->translate(0, SkIntToScalar(20));
|
|
|
|
|
|
|
|
// Case where only the off interval exists on the line. Thus nothing should be drawn
|
2014-05-19 14:59:04 +00:00
|
|
|
drawline(canvas, 32, 16, paint, 8.f, 0.f, 40.f);
|
2014-05-19 14:32:49 +00:00
|
|
|
canvas->translate(0, SkIntToScalar(20));
|
|
|
|
}
|
2017-06-29 16:27:48 +00:00
|
|
|
|
|
|
|
// Test overlapping circles.
|
|
|
|
canvas->translate(SkIntToScalar(5), SkIntToScalar(20));
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setStrokeCap(SkPaint::kRound_Cap);
|
|
|
|
paint.setColor(0x44000000);
|
|
|
|
paint.setStrokeWidth(40);
|
|
|
|
drawline(canvas, 0, 30, paint);
|
|
|
|
|
|
|
|
canvas->translate(0, SkIntToScalar(50));
|
|
|
|
paint.setStrokeCap(SkPaint::kSquare_Cap);
|
|
|
|
drawline(canvas, 0, 30, paint);
|
2014-05-19 14:32:49 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-11-04 21:33:50 +00:00
|
|
|
class Dashing5GM : public skiagm::GM {
|
|
|
|
public:
|
|
|
|
Dashing5GM(bool doAA) : fDoAA(doAA) {}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
bool runAsBench() const override { return true; }
|
2015-01-23 18:31:45 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2014-11-04 21:33:50 +00:00
|
|
|
if (fDoAA) {
|
|
|
|
return SkString("dashing5_aa");
|
|
|
|
} else {
|
|
|
|
return SkString("dashing5_bw");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override { return SkISize::Make(400, 200); }
|
2014-11-04 21:33:50 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr int kOn = 4;
|
|
|
|
constexpr int kOff = 4;
|
|
|
|
constexpr int kIntervalLength = kOn + kOff;
|
2014-11-04 21:33:50 +00:00
|
|
|
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr SkColor gColors[kIntervalLength] = {
|
2014-11-04 21:33:50 +00:00
|
|
|
SK_ColorRED,
|
|
|
|
SK_ColorGREEN,
|
|
|
|
SK_ColorBLUE,
|
|
|
|
SK_ColorCYAN,
|
|
|
|
SK_ColorMAGENTA,
|
|
|
|
SK_ColorYELLOW,
|
|
|
|
SK_ColorGRAY,
|
|
|
|
SK_ColorDKGRAY
|
|
|
|
};
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
|
|
|
|
paint.setAntiAlias(fDoAA);
|
|
|
|
|
|
|
|
SkMatrix rot;
|
|
|
|
rot.setRotate(90);
|
|
|
|
SkASSERT(rot.rectStaysRect());
|
|
|
|
|
|
|
|
canvas->concat(rot);
|
|
|
|
|
|
|
|
int sign; // used to toggle the direction of the lines
|
|
|
|
int phase = 0;
|
|
|
|
|
|
|
|
for (int x = 0; x < 200; x += 10) {
|
|
|
|
paint.setStrokeWidth(SkIntToScalar(phase+1));
|
|
|
|
paint.setColor(gColors[phase]);
|
|
|
|
sign = (x % 20) ? 1 : -1;
|
2016-03-29 16:03:52 +00:00
|
|
|
drawline(canvas, kOn, kOff, paint,
|
|
|
|
SkIntToScalar(x), -sign * SkIntToScalar(10003),
|
2014-11-04 21:33:50 +00:00
|
|
|
SkIntToScalar(phase),
|
|
|
|
SkIntToScalar(x), sign * SkIntToScalar(10003));
|
|
|
|
phase = (phase + 1) % kIntervalLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int y = -400; y < 0; y += 10) {
|
|
|
|
paint.setStrokeWidth(SkIntToScalar(phase+1));
|
|
|
|
paint.setColor(gColors[phase]);
|
|
|
|
sign = (y % 20) ? 1 : -1;
|
2016-03-29 16:03:52 +00:00
|
|
|
drawline(canvas, kOn, kOff, paint,
|
|
|
|
-sign * SkIntToScalar(10003), SkIntToScalar(y),
|
2014-11-04 21:33:50 +00:00
|
|
|
SkIntToScalar(phase),
|
|
|
|
sign * SkIntToScalar(10003), SkIntToScalar(y));
|
|
|
|
phase = (phase + 1) % kIntervalLength;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool fDoAA;
|
|
|
|
};
|
|
|
|
|
2016-04-11 14:46:38 +00:00
|
|
|
DEF_SIMPLE_GM(longpathdash, canvas, 612, 612) {
|
2015-12-18 15:03:13 +00:00
|
|
|
SkPath lines;
|
|
|
|
for (int x = 32; x < 256; x += 16) {
|
|
|
|
for (SkScalar a = 0; a < 3.141592f * 2; a += 0.03141592f) {
|
|
|
|
SkPoint pts[2] = {
|
|
|
|
{ 256 + (float) sin(a) * x,
|
|
|
|
256 + (float) cos(a) * x },
|
|
|
|
{ 256 + (float) sin(a + 3.141592 / 3) * (x + 64),
|
|
|
|
256 + (float) cos(a + 3.141592 / 3) * (x + 64) }
|
|
|
|
};
|
|
|
|
lines.moveTo(pts[0]);
|
|
|
|
for (SkScalar i = 0; i < 1; i += 0.05f) {
|
|
|
|
lines.lineTo(pts[0].fX * (1 - i) + pts[1].fX * i,
|
|
|
|
pts[0].fY * (1 - i) + pts[1].fY * i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SkPaint p;
|
|
|
|
p.setAntiAlias(true);
|
|
|
|
p.setStyle(SkPaint::kStroke_Style);
|
|
|
|
p.setStrokeWidth(1);
|
|
|
|
const SkScalar intervals[] = { 1, 1 };
|
2016-03-18 18:22:57 +00:00
|
|
|
p.setPathEffect(SkDashPathEffect::Make(intervals, SK_ARRAY_COUNT(intervals), 0));
|
2017-10-09 19:45:33 +00:00
|
|
|
|
2016-04-11 14:46:38 +00:00
|
|
|
canvas->translate(50, 50);
|
2015-12-18 15:03:13 +00:00
|
|
|
canvas->drawPath(lines, p);
|
|
|
|
}
|
|
|
|
|
2016-01-30 18:11:21 +00:00
|
|
|
DEF_SIMPLE_GM(longlinedash, canvas, 512, 512) {
|
|
|
|
SkPaint p;
|
|
|
|
p.setAntiAlias(true);
|
|
|
|
p.setStyle(SkPaint::kStroke_Style);
|
|
|
|
p.setStrokeWidth(80);
|
|
|
|
|
|
|
|
const SkScalar intervals[] = { 2, 2 };
|
2016-03-18 18:22:57 +00:00
|
|
|
p.setPathEffect(SkDashPathEffect::Make(intervals, SK_ARRAY_COUNT(intervals), 0));
|
2016-01-30 18:11:21 +00:00
|
|
|
canvas->drawRect(SkRect::MakeXYWH(-10000, 100, 20000, 20), p);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_SIMPLE_GM(longwavyline, canvas, 512, 512) {
|
|
|
|
SkPaint p;
|
|
|
|
p.setAntiAlias(true);
|
|
|
|
p.setStyle(SkPaint::kStroke_Style);
|
|
|
|
p.setStrokeWidth(2);
|
|
|
|
|
|
|
|
SkPath wavy;
|
|
|
|
wavy.moveTo(-10000, 100);
|
|
|
|
for (SkScalar i = -10000; i < 10000; i += 20) {
|
|
|
|
wavy.quadTo(i + 5, 95, i + 10, 100);
|
|
|
|
wavy.quadTo(i + 15, 105, i + 20, 100);
|
|
|
|
}
|
|
|
|
canvas->drawPath(wavy, p);
|
|
|
|
}
|
|
|
|
|
2016-03-16 14:34:02 +00:00
|
|
|
DEF_SIMPLE_GM(dashtextcaps, canvas, 512, 512) {
|
|
|
|
SkPaint p;
|
|
|
|
p.setAntiAlias(true);
|
|
|
|
p.setStyle(SkPaint::kStroke_Style);
|
|
|
|
p.setStrokeWidth(10);
|
|
|
|
p.setStrokeCap(SkPaint::kRound_Cap);
|
2016-03-17 14:01:49 +00:00
|
|
|
p.setStrokeJoin(SkPaint::kRound_Join);
|
2016-03-16 14:34:02 +00:00
|
|
|
p.setTextSize(100);
|
|
|
|
p.setARGB(0xff, 0xbb, 0x00, 0x00);
|
2016-03-17 14:01:49 +00:00
|
|
|
sk_tool_utils::set_portable_typeface(&p);
|
2016-03-16 14:34:02 +00:00
|
|
|
const SkScalar intervals[] = { 12, 12 };
|
2016-03-18 18:22:57 +00:00
|
|
|
p.setPathEffect(SkDashPathEffect::Make(intervals, SK_ARRAY_COUNT(intervals), 0));
|
2017-04-28 19:35:12 +00:00
|
|
|
canvas->drawString("Sausages", 10, 90, p);
|
2016-03-16 14:34:02 +00:00
|
|
|
canvas->drawLine(8, 120, 456, 120, p);
|
|
|
|
}
|
|
|
|
|
2014-11-04 21:33:50 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-08-26 20:07:48 +00:00
|
|
|
DEF_GM(return new DashingGM;)
|
|
|
|
DEF_GM(return new Dashing2GM;)
|
|
|
|
DEF_GM(return new Dashing3GM;)
|
|
|
|
DEF_GM(return new Dashing4GM;)
|
|
|
|
DEF_GM(return new Dashing5GM(true);)
|
|
|
|
DEF_GM(return new Dashing5GM(false);)
|