Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(284)

Side by Side Diff: gm/circulararcs.cpp

Issue 2264593002: Add GMs for testing drawArc (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: fix naming Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2016 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
8 #include <functional>
9 #include "SkCanvas.h"
10 #include "gm.h"
11
12 static constexpr SkScalar kStarts[] = {0.f, 10.f, 30.f, 45.f, 90.f, 165.f, 180.f , 270.f};
13 static constexpr SkScalar kSweeps[] = {45.f, 90.f, 165.f, 180.f, 220.f, 270.f, 3 00.f, 315.f};
14 static constexpr SkScalar kDiameter = 40.f;
15 static constexpr SkRect kRect = {0.f, 0.f, kDiameter, kDiameter};
16 static constexpr int kW = 1000;
17 static constexpr int kH = 1000;
18 static constexpr SkScalar kPad = 20.f;
19
20 void draw_arcs(SkCanvas* canvas, std::function<void(SkPaint*)> configureStyle) {
21 // Draws grid of arcs with different start/sweep angles in red and their com plement arcs in
22 // blue.
23 auto drawGrid = [canvas, &configureStyle] (SkScalar x, SkScalar y, bool useC enter, bool aa) {
24 SkPaint p0;
25 p0.setColor(SK_ColorRED);
robertphillips 2016/08/19 15:57:24 use aa here ?
bsalomon 2016/08/19 16:39:27 Done.
26 p0.setAntiAlias(true);
27 SkPaint p1 = p0;
28 p1.setColor(SK_ColorBLUE);
29 // Use alpha so we see magenta on overlap between arc and its complement .
30 p0.setAlpha(0xff * .4f);
31 p1.setAlpha(0xff * .4f);
32 // Set a reasonable stroke width that configureStyle can override.
33 p0.setStrokeWidth(15.f);
34 p1.setStrokeWidth(15.f);
35 configureStyle(&p0);
36 configureStyle(&p1);
37
38 canvas->save();
39 canvas->translate(kPad + x, kPad + y);
40 for (auto start : kStarts) {
41 canvas->save();
42 for (auto sweep : kSweeps) {
43 canvas->drawArc(kRect, start, sweep, useCenter, p0);
44 canvas->drawArc(kRect, start, -(360.f - sweep), useCenter, p1);
45 canvas->translate(kRect.width() + kPad, 0.f);
46 }
47 canvas->restore();
48 canvas->translate(0, kRect.height() + kPad);
49 }
50 canvas->restore();
51 };
52 // Draw a grids for combo of enabling/disabling aa and using center.
53 static constexpr SkScalar kGridW = kW / 2.f;
54 static constexpr SkScalar kGridH = kH / 2.f;
55 drawGrid(0.f , 0.f , false, false);
56 drawGrid(kGridW, 0.f , true , false);
57 drawGrid(0.f , kGridH, false, true );
58 drawGrid(kGridW, kGridH, true , true );
59 // Draw separators between the grids.
60 SkPaint linePaint;
61 linePaint.setAntiAlias(true);
62 linePaint.setColor(SK_ColorBLACK);
63 canvas->drawLine(kGridW, 0.f , kGridW, kH, linePaint);
64 canvas->drawLine(0.f , kGridH, kW , kGridH, linePaint);
65 }
66
67 #define DEF_ARC_GM(name) DEF_SIMPLE_GM(circular_arcs_##name, canvas, kW, kH)
68
69 DEF_ARC_GM(circular_arcs_fill) {
70 auto setFill = [] (SkPaint*p) { p->setStyle(SkPaint::kFill_Style); };
71 draw_arcs(canvas, setFill);
72 }
73
74 DEF_ARC_GM(hairline) {
75 auto setHairline = [] (SkPaint* p) {
76 p->setStyle(SkPaint::kStroke_Style);
77 p->setStrokeWidth(0.f);
78 };
79 draw_arcs(canvas, setHairline);
80 }
81
82 DEF_ARC_GM(stroke_butt) {
83 auto setStroke = [](SkPaint* p) {
84 p->setStyle(SkPaint::kStroke_Style);
85 p->setStrokeCap(SkPaint::kButt_Cap);
86 };
87 draw_arcs(canvas, setStroke);
88 }
89
90 DEF_ARC_GM(stroke_square) {
91 auto setStroke = [] (SkPaint* p) {
92 p->setStyle(SkPaint::kStroke_Style);
93 p->setStrokeCap(SkPaint::kSquare_Cap);
94 };
95 draw_arcs(canvas, setStroke);
96 }
97
98 DEF_ARC_GM(stroke_round) {
99 auto setStroke = [] (SkPaint* p) {
100 p->setStyle(SkPaint::kStroke_Style);
101 p->setStrokeCap(SkPaint::kRound_Cap);
102 };
103 draw_arcs(canvas, setStroke);
104 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698