dashing.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. /*
  2. * Copyright 2012 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #include "gm/gm.h"
  8. #include "include/core/SkCanvas.h"
  9. #include "include/core/SkColor.h"
  10. #include "include/core/SkFont.h"
  11. #include "include/core/SkMatrix.h"
  12. #include "include/core/SkPaint.h"
  13. #include "include/core/SkPath.h"
  14. #include "include/core/SkPathEffect.h"
  15. #include "include/core/SkPoint.h"
  16. #include "include/core/SkRect.h"
  17. #include "include/core/SkScalar.h"
  18. #include "include/core/SkSize.h"
  19. #include "include/core/SkString.h"
  20. #include "include/core/SkTypeface.h"
  21. #include "include/core/SkTypes.h"
  22. #include "include/effects/SkDashPathEffect.h"
  23. #include "tools/ToolUtils.h"
  24. #include <math.h>
  25. #include <initializer_list>
  26. static void drawline(SkCanvas* canvas, int on, int off, const SkPaint& paint,
  27. SkScalar finalX = SkIntToScalar(600), SkScalar finalY = SkIntToScalar(0),
  28. SkScalar phase = SkIntToScalar(0),
  29. SkScalar startX = SkIntToScalar(0), SkScalar startY = SkIntToScalar(0)) {
  30. SkPaint p(paint);
  31. const SkScalar intervals[] = {
  32. SkIntToScalar(on),
  33. SkIntToScalar(off),
  34. };
  35. p.setPathEffect(SkDashPathEffect::Make(intervals, 2, phase));
  36. canvas->drawLine(startX, startY, finalX, finalY, p);
  37. }
  38. // earlier bug stopped us from drawing very long single-segment dashes, because
  39. // SkPathMeasure was skipping very small delta-T values (nearlyzero). This is
  40. // now fixes, so this giant dash should appear.
  41. static void show_giant_dash(SkCanvas* canvas) {
  42. SkPaint paint;
  43. drawline(canvas, 1, 1, paint, SkIntToScalar(20 * 1000));
  44. }
  45. static void show_zero_len_dash(SkCanvas* canvas) {
  46. SkPaint paint;
  47. drawline(canvas, 2, 2, paint, SkIntToScalar(0));
  48. paint.setStyle(SkPaint::kStroke_Style);
  49. paint.setStrokeWidth(SkIntToScalar(2));
  50. canvas->translate(0, SkIntToScalar(20));
  51. drawline(canvas, 4, 4, paint, SkIntToScalar(0));
  52. }
  53. class DashingGM : public skiagm::GM {
  54. SkString onShortName() override { return SkString("dashing"); }
  55. SkISize onISize() override { return {640, 340}; }
  56. void onDraw(SkCanvas* canvas) override {
  57. constexpr struct {
  58. int fOnInterval;
  59. int fOffInterval;
  60. } gData[] = {
  61. { 1, 1 },
  62. { 4, 1 },
  63. };
  64. SkPaint paint;
  65. paint.setStyle(SkPaint::kStroke_Style);
  66. canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
  67. canvas->translate(0, SK_ScalarHalf);
  68. for (int width = 0; width <= 2; ++width) {
  69. for (size_t data = 0; data < SK_ARRAY_COUNT(gData); ++data) {
  70. for (int aa = 0; aa <= 1; ++aa) {
  71. int w = width * width * width;
  72. paint.setAntiAlias(SkToBool(aa));
  73. paint.setStrokeWidth(SkIntToScalar(w));
  74. int scale = w ? w : 1;
  75. drawline(canvas, gData[data].fOnInterval * scale,
  76. gData[data].fOffInterval * scale,
  77. paint);
  78. canvas->translate(0, SkIntToScalar(20));
  79. }
  80. }
  81. }
  82. show_giant_dash(canvas);
  83. canvas->translate(0, SkIntToScalar(20));
  84. show_zero_len_dash(canvas);
  85. canvas->translate(0, SkIntToScalar(20));
  86. // Draw 0 on, 0 off dashed line
  87. paint.setStrokeWidth(SkIntToScalar(8));
  88. drawline(canvas, 0, 0, paint);
  89. }
  90. };
  91. ///////////////////////////////////////////////////////////////////////////////
  92. static void make_unit_star(SkPath* path, int n) {
  93. SkScalar rad = -SK_ScalarPI / 2;
  94. const SkScalar drad = (n >> 1) * SK_ScalarPI * 2 / n;
  95. path->moveTo(0, -SK_Scalar1);
  96. for (int i = 1; i < n; i++) {
  97. rad += drad;
  98. path->lineTo(SkScalarCos(rad), SkScalarSin(rad));
  99. }
  100. path->close();
  101. }
  102. static void make_path_line(SkPath* path, const SkRect& bounds) {
  103. path->moveTo(bounds.left(), bounds.top());
  104. path->lineTo(bounds.right(), bounds.bottom());
  105. }
  106. static void make_path_rect(SkPath* path, const SkRect& bounds) {
  107. path->addRect(bounds);
  108. }
  109. static void make_path_oval(SkPath* path, const SkRect& bounds) {
  110. path->addOval(bounds);
  111. }
  112. static void make_path_star(SkPath* path, const SkRect& bounds) {
  113. make_unit_star(path, 5);
  114. SkMatrix matrix;
  115. matrix.setRectToRect(path->getBounds(), bounds, SkMatrix::kCenter_ScaleToFit);
  116. path->transform(matrix);
  117. }
  118. class Dashing2GM : public skiagm::GM {
  119. SkString onShortName() override { return SkString("dashing2"); }
  120. SkISize onISize() override { return {640, 480}; }
  121. void onDraw(SkCanvas* canvas) override {
  122. constexpr int gIntervals[] = {
  123. 3, // 3 dashes: each count [0] followed by intervals [1..count]
  124. 2, 10, 10,
  125. 4, 20, 5, 5, 5,
  126. 2, 2, 2
  127. };
  128. void (*gProc[])(SkPath*, const SkRect&) = {
  129. make_path_line, make_path_rect, make_path_oval, make_path_star,
  130. };
  131. SkPaint paint;
  132. paint.setAntiAlias(true);
  133. paint.setStyle(SkPaint::kStroke_Style);
  134. paint.setStrokeWidth(SkIntToScalar(6));
  135. SkRect bounds = SkRect::MakeWH(SkIntToScalar(120), SkIntToScalar(120));
  136. bounds.offset(SkIntToScalar(20), SkIntToScalar(20));
  137. SkScalar dx = bounds.width() * 4 / 3;
  138. SkScalar dy = bounds.height() * 4 / 3;
  139. const int* intervals = &gIntervals[1];
  140. for (int y = 0; y < gIntervals[0]; ++y) {
  141. SkScalar vals[SK_ARRAY_COUNT(gIntervals)]; // more than enough
  142. int count = *intervals++;
  143. for (int i = 0; i < count; ++i) {
  144. vals[i] = SkIntToScalar(*intervals++);
  145. }
  146. SkScalar phase = vals[0] / 2;
  147. paint.setPathEffect(SkDashPathEffect::Make(vals, count, phase));
  148. for (size_t x = 0; x < SK_ARRAY_COUNT(gProc); ++x) {
  149. SkPath path;
  150. SkRect r = bounds;
  151. r.offset(x * dx, y * dy);
  152. gProc[x](&path, r);
  153. canvas->drawPath(path, paint);
  154. }
  155. }
  156. }
  157. };
  158. //////////////////////////////////////////////////////////////////////////////
  159. // Test out the on/off line dashing Chrome if fond of
  160. class Dashing3GM : public skiagm::GM {
  161. SkString onShortName() override { return SkString("dashing3"); }
  162. SkISize onISize() override { return {640, 480}; }
  163. // Draw a 100x100 block of dashed lines. The horizontal ones are BW
  164. // while the vertical ones are AA.
  165. void drawDashedLines(SkCanvas* canvas,
  166. SkScalar lineLength,
  167. SkScalar phase,
  168. SkScalar dashLength,
  169. int strokeWidth,
  170. bool circles) {
  171. SkPaint p;
  172. p.setColor(SK_ColorBLACK);
  173. p.setStyle(SkPaint::kStroke_Style);
  174. p.setStrokeWidth(SkIntToScalar(strokeWidth));
  175. if (circles) {
  176. p.setStrokeCap(SkPaint::kRound_Cap);
  177. }
  178. SkScalar intervals[2] = { dashLength, dashLength };
  179. p.setPathEffect(SkDashPathEffect::Make(intervals, 2, phase));
  180. SkPoint pts[2];
  181. for (int y = 0; y < 100; y += 10*strokeWidth) {
  182. pts[0].set(0, SkIntToScalar(y));
  183. pts[1].set(lineLength, SkIntToScalar(y));
  184. canvas->drawPoints(SkCanvas::kLines_PointMode, 2, pts, p);
  185. }
  186. p.setAntiAlias(true);
  187. for (int x = 0; x < 100; x += 14*strokeWidth) {
  188. pts[0].set(SkIntToScalar(x), 0);
  189. pts[1].set(SkIntToScalar(x), lineLength);
  190. canvas->drawPoints(SkCanvas::kLines_PointMode, 2, pts, p);
  191. }
  192. }
  193. void onDraw(SkCanvas* canvas) override {
  194. // 1on/1off 1x1 squares with phase of 0 - points fastpath
  195. canvas->save();
  196. canvas->translate(2, 0);
  197. this->drawDashedLines(canvas, 100, 0, SK_Scalar1, 1, false);
  198. canvas->restore();
  199. // 1on/1off 1x1 squares with phase of .5 - rects fastpath (due to partial squares)
  200. canvas->save();
  201. canvas->translate(112, 0);
  202. this->drawDashedLines(canvas, 100, SK_ScalarHalf, SK_Scalar1, 1, false);
  203. canvas->restore();
  204. // 1on/1off 1x1 squares with phase of 1 - points fastpath
  205. canvas->save();
  206. canvas->translate(222, 0);
  207. this->drawDashedLines(canvas, 100, SK_Scalar1, SK_Scalar1, 1, false);
  208. canvas->restore();
  209. // 1on/1off 1x1 squares with phase of 1 and non-integer length - rects fastpath
  210. canvas->save();
  211. canvas->translate(332, 0);
  212. this->drawDashedLines(canvas, 99.5f, SK_ScalarHalf, SK_Scalar1, 1, false);
  213. canvas->restore();
  214. // 255on/255off 1x1 squares with phase of 0 - rects fast path
  215. canvas->save();
  216. canvas->translate(446, 0);
  217. this->drawDashedLines(canvas, 100, 0, SkIntToScalar(255), 1, false);
  218. canvas->restore();
  219. // 1on/1off 3x3 squares with phase of 0 - points fast path
  220. canvas->save();
  221. canvas->translate(2, 110);
  222. this->drawDashedLines(canvas, 100, 0, SkIntToScalar(3), 3, false);
  223. canvas->restore();
  224. // 1on/1off 3x3 squares with phase of 1.5 - rects fast path
  225. canvas->save();
  226. canvas->translate(112, 110);
  227. this->drawDashedLines(canvas, 100, 1.5f, SkIntToScalar(3), 3, false);
  228. canvas->restore();
  229. // 1on/1off 1x1 circles with phase of 1 - no fast path yet
  230. canvas->save();
  231. canvas->translate(2, 220);
  232. this->drawDashedLines(canvas, 100, SK_Scalar1, SK_Scalar1, 1, true);
  233. canvas->restore();
  234. // 1on/1off 3x3 circles with phase of 1 - no fast path yet
  235. canvas->save();
  236. canvas->translate(112, 220);
  237. this->drawDashedLines(canvas, 100, 0, SkIntToScalar(3), 3, true);
  238. canvas->restore();
  239. // 1on/1off 1x1 squares with rotation - should break fast path
  240. canvas->save();
  241. canvas->translate(332+SK_ScalarRoot2Over2*100, 110+SK_ScalarRoot2Over2*100);
  242. canvas->rotate(45);
  243. canvas->translate(-50, -50);
  244. this->drawDashedLines(canvas, 100, SK_Scalar1, SK_Scalar1, 1, false);
  245. canvas->restore();
  246. // 3on/3off 3x1 rects - should use rect fast path regardless of phase
  247. for (int phase = 0; phase <= 3; ++phase) {
  248. canvas->save();
  249. canvas->translate(SkIntToScalar(phase*110+2),
  250. SkIntToScalar(330));
  251. this->drawDashedLines(canvas, 100, SkIntToScalar(phase), SkIntToScalar(3), 1, false);
  252. canvas->restore();
  253. }
  254. }
  255. };
  256. //////////////////////////////////////////////////////////////////////////////
  257. class Dashing4GM : public skiagm::GM {
  258. SkString onShortName() override { return SkString("dashing4"); }
  259. SkISize onISize() override { return {640, 1100}; }
  260. void onDraw(SkCanvas* canvas) override {
  261. constexpr struct {
  262. int fOnInterval;
  263. int fOffInterval;
  264. } gData[] = {
  265. { 1, 1 },
  266. { 4, 2 },
  267. { 0, 4 }, // test for zero length on interval
  268. };
  269. SkPaint paint;
  270. paint.setStyle(SkPaint::kStroke_Style);
  271. canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
  272. canvas->translate(SK_ScalarHalf, SK_ScalarHalf);
  273. for (int width = 0; width <= 2; ++width) {
  274. for (size_t data = 0; data < SK_ARRAY_COUNT(gData); ++data) {
  275. for (int aa = 0; aa <= 1; ++aa) {
  276. for (int cap = 0; cap <= 1; ++cap) {
  277. int w = width * width * width;
  278. paint.setAntiAlias(SkToBool(aa));
  279. paint.setStrokeWidth(SkIntToScalar(w));
  280. SkToBool(cap) ? paint.setStrokeCap(SkPaint::kSquare_Cap)
  281. : paint.setStrokeCap(SkPaint::kRound_Cap);
  282. int scale = w ? w : 1;
  283. drawline(canvas, gData[data].fOnInterval * scale,
  284. gData[data].fOffInterval * scale,
  285. paint);
  286. canvas->translate(0, SkIntToScalar(20));
  287. }
  288. }
  289. }
  290. }
  291. for (int aa = 0; aa <= 1; ++aa) {
  292. paint.setAntiAlias(SkToBool(aa));
  293. paint.setStrokeWidth(8.f);
  294. paint.setStrokeCap(SkPaint::kSquare_Cap);
  295. // Single dash element that is cut off at start and end
  296. drawline(canvas, 32, 16, paint, 20.f, 0, 5.f);
  297. canvas->translate(0, SkIntToScalar(20));
  298. // Two dash elements where each one is cut off at beginning and end respectively
  299. drawline(canvas, 32, 16, paint, 56.f, 0, 5.f);
  300. canvas->translate(0, SkIntToScalar(20));
  301. // Many dash elements where first and last are cut off at beginning and end respectively
  302. drawline(canvas, 32, 16, paint, 584.f, 0, 5.f);
  303. canvas->translate(0, SkIntToScalar(20));
  304. // Diagonal dash line where src pnts are not axis aligned (as apposed to being diagonal from
  305. // a canvas rotation)
  306. drawline(canvas, 32, 16, paint, 600.f, 30.f);
  307. canvas->translate(0, SkIntToScalar(20));
  308. // Case where only the off interval exists on the line. Thus nothing should be drawn
  309. drawline(canvas, 32, 16, paint, 8.f, 0.f, 40.f);
  310. canvas->translate(0, SkIntToScalar(20));
  311. }
  312. // Test overlapping circles.
  313. canvas->translate(SkIntToScalar(5), SkIntToScalar(20));
  314. paint.setAntiAlias(true);
  315. paint.setStrokeCap(SkPaint::kRound_Cap);
  316. paint.setColor(0x44000000);
  317. paint.setStrokeWidth(40);
  318. drawline(canvas, 0, 30, paint);
  319. canvas->translate(0, SkIntToScalar(50));
  320. paint.setStrokeCap(SkPaint::kSquare_Cap);
  321. drawline(canvas, 0, 30, paint);
  322. // Test we draw the cap when the line length is zero.
  323. canvas->translate(0, SkIntToScalar(50));
  324. paint.setStrokeCap(SkPaint::kRound_Cap);
  325. paint.setColor(0xFF000000);
  326. paint.setStrokeWidth(11);
  327. drawline(canvas, 0, 30, paint, 0);
  328. canvas->translate(SkIntToScalar(100), 0);
  329. drawline(canvas, 1, 30, paint, 0);
  330. }
  331. };
  332. //////////////////////////////////////////////////////////////////////////////
  333. class Dashing5GM : public skiagm::GM {
  334. public:
  335. Dashing5GM(bool doAA) : fDoAA(doAA) {}
  336. private:
  337. bool runAsBench() const override { return true; }
  338. SkString onShortName() override { return SkString(fDoAA ? "dashing5_aa" : "dashing5_bw"); }
  339. SkISize onISize() override { return {400, 200}; }
  340. void onDraw(SkCanvas* canvas) override {
  341. constexpr int kOn = 4;
  342. constexpr int kOff = 4;
  343. constexpr int kIntervalLength = kOn + kOff;
  344. constexpr SkColor gColors[kIntervalLength] = {
  345. SK_ColorRED,
  346. SK_ColorGREEN,
  347. SK_ColorBLUE,
  348. SK_ColorCYAN,
  349. SK_ColorMAGENTA,
  350. SK_ColorYELLOW,
  351. SK_ColorGRAY,
  352. SK_ColorDKGRAY
  353. };
  354. SkPaint paint;
  355. paint.setStyle(SkPaint::kStroke_Style);
  356. paint.setAntiAlias(fDoAA);
  357. SkMatrix rot;
  358. rot.setRotate(90);
  359. SkASSERT(rot.rectStaysRect());
  360. canvas->concat(rot);
  361. int sign; // used to toggle the direction of the lines
  362. int phase = 0;
  363. for (int x = 0; x < 200; x += 10) {
  364. paint.setStrokeWidth(SkIntToScalar(phase+1));
  365. paint.setColor(gColors[phase]);
  366. sign = (x % 20) ? 1 : -1;
  367. drawline(canvas, kOn, kOff, paint,
  368. SkIntToScalar(x), -sign * SkIntToScalar(10003),
  369. SkIntToScalar(phase),
  370. SkIntToScalar(x), sign * SkIntToScalar(10003));
  371. phase = (phase + 1) % kIntervalLength;
  372. }
  373. for (int y = -400; y < 0; y += 10) {
  374. paint.setStrokeWidth(SkIntToScalar(phase+1));
  375. paint.setColor(gColors[phase]);
  376. sign = (y % 20) ? 1 : -1;
  377. drawline(canvas, kOn, kOff, paint,
  378. -sign * SkIntToScalar(10003), SkIntToScalar(y),
  379. SkIntToScalar(phase),
  380. sign * SkIntToScalar(10003), SkIntToScalar(y));
  381. phase = (phase + 1) % kIntervalLength;
  382. }
  383. }
  384. private:
  385. bool fDoAA;
  386. };
  387. DEF_SIMPLE_GM(longpathdash, canvas, 612, 612) {
  388. SkPath lines;
  389. for (int x = 32; x < 256; x += 16) {
  390. for (SkScalar a = 0; a < 3.141592f * 2; a += 0.03141592f) {
  391. SkPoint pts[2] = {
  392. { 256 + (float) sin(a) * x,
  393. 256 + (float) cos(a) * x },
  394. { 256 + (float) sin(a + 3.141592 / 3) * (x + 64),
  395. 256 + (float) cos(a + 3.141592 / 3) * (x + 64) }
  396. };
  397. lines.moveTo(pts[0]);
  398. for (SkScalar i = 0; i < 1; i += 0.05f) {
  399. lines.lineTo(pts[0].fX * (1 - i) + pts[1].fX * i,
  400. pts[0].fY * (1 - i) + pts[1].fY * i);
  401. }
  402. }
  403. }
  404. SkPaint p;
  405. p.setAntiAlias(true);
  406. p.setStyle(SkPaint::kStroke_Style);
  407. p.setStrokeWidth(1);
  408. const SkScalar intervals[] = { 1, 1 };
  409. p.setPathEffect(SkDashPathEffect::Make(intervals, SK_ARRAY_COUNT(intervals), 0));
  410. canvas->translate(50, 50);
  411. canvas->drawPath(lines, p);
  412. }
  413. DEF_SIMPLE_GM(longlinedash, canvas, 512, 512) {
  414. SkPaint p;
  415. p.setAntiAlias(true);
  416. p.setStyle(SkPaint::kStroke_Style);
  417. p.setStrokeWidth(80);
  418. const SkScalar intervals[] = { 2, 2 };
  419. p.setPathEffect(SkDashPathEffect::Make(intervals, SK_ARRAY_COUNT(intervals), 0));
  420. canvas->drawRect(SkRect::MakeXYWH(-10000, 100, 20000, 20), p);
  421. }
  422. DEF_SIMPLE_GM(longwavyline, canvas, 512, 512) {
  423. SkPaint p;
  424. p.setAntiAlias(true);
  425. p.setStyle(SkPaint::kStroke_Style);
  426. p.setStrokeWidth(2);
  427. SkPath wavy;
  428. wavy.moveTo(-10000, 100);
  429. for (SkScalar i = -10000; i < 10000; i += 20) {
  430. wavy.quadTo(i + 5, 95, i + 10, 100);
  431. wavy.quadTo(i + 15, 105, i + 20, 100);
  432. }
  433. canvas->drawPath(wavy, p);
  434. }
  435. DEF_SIMPLE_GM(dashtextcaps, canvas, 512, 512) {
  436. SkPaint p;
  437. p.setAntiAlias(true);
  438. p.setStyle(SkPaint::kStroke_Style);
  439. p.setStrokeWidth(10);
  440. p.setStrokeCap(SkPaint::kRound_Cap);
  441. p.setStrokeJoin(SkPaint::kRound_Join);
  442. p.setARGB(0xff, 0xbb, 0x00, 0x00);
  443. SkFont font(ToolUtils::create_portable_typeface(), 100);
  444. const SkScalar intervals[] = { 12, 12 };
  445. p.setPathEffect(SkDashPathEffect::Make(intervals, SK_ARRAY_COUNT(intervals), 0));
  446. canvas->drawString("Sausages", 10, 90, font, p);
  447. canvas->drawLine(8, 120, 456, 120, p);
  448. }
  449. DEF_SIMPLE_GM(dash_line_zero_off_interval, canvas, 160, 330) {
  450. static constexpr SkScalar kIntervals[] = {5.f, 0.f, 2.f, 0.f};
  451. SkPaint dashPaint;
  452. dashPaint.setPathEffect(SkDashPathEffect::Make(kIntervals, SK_ARRAY_COUNT(kIntervals), 0.f));
  453. SkASSERT(dashPaint.getPathEffect());
  454. dashPaint.setStyle(SkPaint::kStroke_Style);
  455. dashPaint.setStrokeWidth(20.f);
  456. static constexpr struct {
  457. SkPoint fA, fB;
  458. } kLines[] = {{{0.5f, 0.5f}, {30.5f, 0.5f}}, // horizontal
  459. {{0.5f, 0.5f}, {0.5f, 30.5f}}, // vertical
  460. {{0.5f, 0.5f}, {0.5f, 0.5f}}, // point
  461. {{0.5f, 0.5f}, {25.5f, 25.5f}}}; // diagonal
  462. SkScalar pad = 5.f + dashPaint.getStrokeWidth();
  463. canvas->translate(pad / 2.f, pad / 2.f);
  464. canvas->save();
  465. SkScalar h = 0.f;
  466. for (const auto& line : kLines) {
  467. h = SkTMax(h, SkScalarAbs(line.fA.fY - line.fB.fY));
  468. }
  469. for (const auto& line : kLines) {
  470. SkScalar w = SkScalarAbs(line.fA.fX - line.fB.fX);
  471. for (auto cap : {SkPaint::kButt_Cap, SkPaint::kSquare_Cap, SkPaint::kRound_Cap}) {
  472. dashPaint.setStrokeCap(cap);
  473. for (auto aa : {false, true}) {
  474. dashPaint.setAntiAlias(aa);
  475. canvas->drawLine(line.fA, line.fB, dashPaint);
  476. canvas->translate(0.f, pad + h);
  477. }
  478. }
  479. canvas->restore();
  480. canvas->translate(pad + w, 0.f);
  481. canvas->save();
  482. }
  483. }
  484. //////////////////////////////////////////////////////////////////////////////
  485. DEF_GM(return new DashingGM;)
  486. DEF_GM(return new Dashing2GM;)
  487. DEF_GM(return new Dashing3GM;)
  488. DEF_GM(return new Dashing4GM;)
  489. DEF_GM(return new Dashing5GM(true);)
  490. DEF_GM(return new Dashing5GM(false);)