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

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: rm line accidentally leftover from previous patch 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);
26 p0.setAntiAlias(aa);
27 // Set a reasonable stroke width that configureStyle can override.
28 p0.setStrokeWidth(15.f);
29 // Use alpha so we see magenta on overlap between arc and its complement .
30 p0.setAlpha(100);
31 SkPaint p1 = p0;
32 p1.setColor(SK_ColorBLUE);
33 configureStyle(&p0);
34 configureStyle(&p1);
35
36 canvas->save();
37 canvas->translate(kPad + x, kPad + y);
38 for (auto start : kStarts) {
39 canvas->save();
40 for (auto sweep : kSweeps) {
41 canvas->drawArc(kRect, start, sweep, useCenter, p0);
42 canvas->drawArc(kRect, start, -(360.f - sweep), useCenter, p1);
43 canvas->translate(kRect.width() + kPad, 0.f);
44 }
45 canvas->restore();
46 canvas->translate(0, kRect.height() + kPad);
47 }
48 canvas->restore();
49 };
50 // Draw a grids for combo of enabling/disabling aa and using center.
51 static constexpr SkScalar kGridW = kW / 2.f;
52 static constexpr SkScalar kGridH = kH / 2.f;
53 drawGrid(0.f , 0.f , false, false);
54 drawGrid(kGridW, 0.f , true , false);
55 drawGrid(0.f , kGridH, false, true );
56 drawGrid(kGridW, kGridH, true , true );
57 // Draw separators between the grids.
58 SkPaint linePaint;
59 linePaint.setAntiAlias(true);
60 linePaint.setColor(SK_ColorBLACK);
61 canvas->drawLine(kGridW, 0.f , kGridW, SkIntToScalar(kH), lineP aint);
62 canvas->drawLine(0.f , kGridH, SkIntToScalar(kW), kGridH, lineP aint);
63 }
64
65 #define DEF_ARC_GM(name) DEF_SIMPLE_GM(circular_arcs_##name, canvas, kW, kH)
66
67 DEF_ARC_GM(circular_arcs_fill) {
egdaniel 2016/08/19 18:35:18 the "circular_arcs_circular_arcs_fill" gm? somehow
bsalomon 2016/08/19 18:52:35 shoot, should be just fill here.
68 auto setFill = [] (SkPaint*p) { p->setStyle(SkPaint::kFill_Style); };
69 draw_arcs(canvas, setFill);
70 }
71
72 DEF_ARC_GM(hairline) {
73 auto setHairline = [] (SkPaint* p) {
74 p->setStyle(SkPaint::kStroke_Style);
75 p->setStrokeWidth(0.f);
76 };
77 draw_arcs(canvas, setHairline);
78 }
79
80 DEF_ARC_GM(stroke_butt) {
81 auto setStroke = [](SkPaint* p) {
82 p->setStyle(SkPaint::kStroke_Style);
83 p->setStrokeCap(SkPaint::kButt_Cap);
84 };
85 draw_arcs(canvas, setStroke);
86 }
87
88 DEF_ARC_GM(stroke_square) {
89 auto setStroke = [] (SkPaint* p) {
90 p->setStyle(SkPaint::kStroke_Style);
91 p->setStrokeCap(SkPaint::kSquare_Cap);
92 };
93 draw_arcs(canvas, setStroke);
94 }
95
96 DEF_ARC_GM(stroke_round) {
97 auto setStroke = [] (SkPaint* p) {
98 p->setStyle(SkPaint::kStroke_Style);
99 p->setStrokeCap(SkPaint::kRound_Cap);
100 };
101 draw_arcs(canvas, setStroke);
102 }
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