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

Side by Side Diff: gm/beziers.cpp

Issue 558163005: thick stroke Beziers (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix bench Created 6 years, 2 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 | « bench/BezierBench.cpp ('k') | gm/smallarc.cpp » ('j') | 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 2014 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 "gm.h"
9 #include "SkRandom.h"
10
11 #define W 400
12 #define H 400
13 #define N 10
14
15 static const SkScalar SW = SkIntToScalar(W);
16 static const SkScalar SH = SkIntToScalar(H);
17
18 static void rnd_quad(SkPath* p, SkPaint* paint, SkLCGRandom& rand) {
19 p->moveTo(rand.nextRangeScalar(0, W), rand.nextRangeScalar(0, H));
20 for (int x = 0; x < 2; ++x) {
21 p->quadTo(rand.nextRangeScalar(W / 4, W), rand.nextRangeScalar(0, H),
22 rand.nextRangeScalar(0, W), rand.nextRangeScalar(H / 4, H));
23 }
24 paint->setColor(rand.nextU());
25 SkScalar width = rand.nextRangeScalar(1, 5);
26 width *= width;
27 paint->setStrokeWidth(width);
28 paint->setAlpha(0xFF);
29 }
30
31 static void rnd_cubic(SkPath* p, SkPaint* paint, SkLCGRandom& rand) {
32 p->moveTo(rand.nextRangeScalar(0, W), rand.nextRangeScalar(0, H));
33 for (int x = 0; x < 2; ++x) {
34 p->cubicTo(rand.nextRangeScalar(W / 4, W), rand.nextRangeScalar(0, H),
35 rand.nextRangeScalar(0, W), rand.nextRangeScalar(H / 4, H),
36 rand.nextRangeScalar(W / 4, W), rand.nextRangeScalar(H / 4, H) );
37 }
38 paint->setColor(rand.nextU());
39 SkScalar width = rand.nextRangeScalar(1, 5);
40 width *= width;
41 paint->setStrokeWidth(width);
42 paint->setAlpha(0xFF);
43 }
44
45 class BeziersGM : public skiagm::GM {
46 public:
47 BeziersGM() {}
48
49 protected:
50 virtual uint32_t onGetFlags() const SK_OVERRIDE {
51 return kSkipTiled_Flag;
52 }
53
54 virtual SkString onShortName() {
55 return SkString("beziers");
56 }
57
58 virtual SkISize onISize() {
59 return SkISize::Make(W, H*2);
60 }
61
62 virtual void onDraw(SkCanvas* canvas) {
63 SkPaint paint;
64 paint.setStyle(SkPaint::kStroke_Style);
65 paint.setStrokeWidth(SkIntToScalar(9)/2);
66 paint.setAntiAlias(true);
67
68 SkLCGRandom rand;
69 for (int i = 0; i < N; i++) {
70 SkPath p;
71 rnd_quad(&p, &paint, rand);
72 canvas->drawPath(p, paint);
73 }
74 canvas->translate(0, SH);
75 for (int i = 0; i < N; i++) {
76 SkPath p;
77 rnd_cubic(&p, &paint, rand);
78 canvas->drawPath(p, paint);
79 }
80 }
81
82 private:
83 typedef skiagm::GM INHERITED;
84 };
85
86 static skiagm::GM* F0(void*) { return new BeziersGM; }
87 static skiagm::GMRegistry R0(F0);
OLDNEW
« no previous file with comments | « bench/BezierBench.cpp ('k') | gm/smallarc.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698