blob: 1e23f15a534db37825e47fbc2284e74b8e38cedc [file] [log] [blame]
reed@google.com8d850be2012-07-13 15:55:15 +00001/*
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
8#include "gm.h"
9#include "SkCanvas.h"
10#include "SkPath.h"
11#include "SkParsePath.h"
12#include "SkDashPathEffect.h"
13
14/*
15 * Inspired by http://code.google.com/p/chromium/issues/detail?id=112145
16 */
17
18class DashCubicsGM : public skiagm::GM {
19public:
20 DashCubicsGM() {}
21
22protected:
commit-bot@chromium.orga90c6802014-04-30 13:20:45 +000023 virtual uint32_t onGetFlags() const SK_OVERRIDE {
24 return kSkipTiled_Flag;
25 }
26
reed@google.com8d850be2012-07-13 15:55:15 +000027 virtual SkString onShortName() {
28 return SkString("dashcubics");
29 }
30
31 virtual SkISize onISize() {
32 return SkISize::Make(640, 480);
33 }
34
35 virtual void onDraw(SkCanvas* canvas) {
36 SkPath path;
37 const char* d = "M 337,98 C 250,141 250,212 250,212 C 250,212 250,212 250,212"
38 "C 250,212 250,212 250,212 C 250,212 250,141 163,98 C 156,195 217,231 217,231"
39 "C 217,231 217,231 217,231 C 217,231 217,231 217,231 C 217,231 156,195 75,250"
40 "C 156,305 217,269 217,269 C 217,269 217,269 217,269 C 217,269 217,269 217,269"
41 "C 217,269 156,305 163,402 C 250,359 250,288 250,288 C 250,288 250,288 250,288"
42 "C 250,288 250,288 250,288 C 250,288 250,359 338,402 C 345,305 283,269 283,269"
43 "C 283,269 283,269 283,269 C 283,269 283,269 283,269 C 283,269 345,305 425,250"
44 "C 344,195 283,231 283,231 C 283,231 283,231 283,231 C 283,231 283,231 283,231"
45 "C 283,231 344,195 338,98";
46
47 SkParsePath::FromSVGString(d, &path);
rmistry@google.comae933ce2012-08-23 18:19:56 +000048
reed@google.com8d850be2012-07-13 15:55:15 +000049 SkScalar intervals[] = { 5, 10 };
commit-bot@chromium.org0a2bf902014-02-20 20:40:19 +000050 SkPathEffect* pe = SkDashPathEffect::Create(intervals, 2, 0);
reed@google.com8d850be2012-07-13 15:55:15 +000051
52 SkPaint paint;
53 paint.setAntiAlias(true);
54 paint.setStyle(SkPaint::kStroke_Style);
55
56 paint.setStrokeWidth(42);
57 canvas->drawPath(path, paint);
58
59 paint.setColor(SK_ColorRED);
60 paint.setStrokeWidth(21);
61 paint.setPathEffect(pe)->unref();
62 canvas->drawPath(path, paint);
63
64 paint.setColor(SK_ColorGREEN);
65 paint.setPathEffect(NULL);
66 paint.setStrokeWidth(0);
67 canvas->drawPath(path, paint);
68 }
69
70private:
71 typedef GM INHERITED;
72};
73
74//////////////////////////////////////////////////////////////////////////////
75
76static skiagm::GM* MyFactory(void*) { return new DashCubicsGM; }
77static skiagm::GMRegistry reg(MyFactory);