Flutter Engine
The Flutter Engine
pathcontourstart.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2015 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/gm.h"
11#include "include/core/SkPath.h"
15#include "include/core/SkRect.h"
17#include "include/core/SkSize.h"
22
23using namespace skia_private;
24
25namespace skiagm {
26
27class ContourStartGM : public GM {
28protected:
29 void onOnceBeforeDraw() override {
30 const SkScalar kMaxDashLen = 100;
31 const SkScalar kDashGrowth = 1.2f;
32
33 STArray<100, SkScalar> intervals;
34 for (SkScalar len = 1; len < kMaxDashLen; len *= kDashGrowth) {
35 intervals.push_back(len);
36 intervals.push_back(len);
37 }
38
39 fDashPaint.setAntiAlias(true);
41 fDashPaint.setStrokeWidth(6);
42 fDashPaint.setColor(0xff008000);
43 fDashPaint.setPathEffect(SkDashPathEffect::Make(intervals.begin(), intervals.size(), 0));
44
45 fPointsPaint.setColor(0xff800000);
46 fPointsPaint.setStrokeWidth(3);
47
48 fRect = SkRect::MakeLTRB(10, 10, 100, 70);
49 }
50
51 SkString getName() const override { return SkString("contour_start"); }
52
53 SkISize getISize() override { return SkISize::Make(kImageWidth, kImageHeight); }
54
55 void onDraw(SkCanvas* canvas) override {
56
57 drawDirs(canvas, [](const SkRect& rect, SkPathDirection dir, unsigned startIndex) {
58 return SkPath::Rect(rect, dir, startIndex);
59 });
60
61 drawDirs(canvas, [](const SkRect& rect, SkPathDirection dir, unsigned startIndex) {
62 return SkPath::Oval(rect, dir, startIndex);
63 });
64
65 drawDirs(canvas, [](const SkRect& rect, SkPathDirection dir, unsigned startIndex) {
67 const SkVector radii[4] = { {15, 15}, {15, 15}, {15, 15}, {15, 15}};
68 rrect.setRectRadii(rect, radii);
69 return SkPath::RRect(rrect, dir, startIndex);
70 });
71
72 drawDirs(canvas, [](const SkRect& rect, SkPathDirection dir, unsigned startIndex) {
75 return SkPath::RRect(rrect, dir, startIndex);
76 });
77
78 drawDirs(canvas, [](const SkRect& rect, SkPathDirection dir, unsigned startIndex) {
81 return SkPath::RRect(rrect, dir, startIndex);
82 });
83
84 }
85
86private:
87 inline static constexpr int kImageWidth = 1200;
88 inline static constexpr int kImageHeight = 600;
89
90 SkPaint fDashPaint, fPointsPaint;
91 SkRect fRect;
92
93 void drawDirs(SkCanvas* canvas,
94 SkPath (*makePath)(const SkRect&, SkPathDirection, unsigned)) const {
95 drawOneColumn(canvas, SkPathDirection::kCW, makePath);
96 canvas->translate(kImageWidth / 10, 0);
97 drawOneColumn(canvas, SkPathDirection::kCCW, makePath);
98 canvas->translate(kImageWidth / 10, 0);
99 }
100
101 void drawOneColumn(SkCanvas* canvas, SkPathDirection dir,
102 SkPath (*makePath)(const SkRect&, SkPathDirection, unsigned)) const {
103 SkAutoCanvasRestore acr(canvas, true);
104
105 for (unsigned i = 0; i < 8; ++i) {
106 const SkPath path = makePath(fRect, dir, i);
107 canvas->drawPath(path, fDashPaint);
108
109 const int n = path.countPoints();
111 path.getPoints(points.get(), n);
112 canvas->drawPoints(SkCanvas::kPoints_PointMode, n, points.get(), fPointsPaint);
113
114 canvas->translate(0, kImageHeight / 8);
115 }
116 }
117
118 using INHERITED = GM;
119};
120
121DEF_GM( return new ContourStartGM(); )
122
123} // namespace skiagm
static const int points[]
SkPathDirection
Definition: SkPathTypes.h:34
void drawPoints(PointMode mode, size_t count, const SkPoint pts[], const SkPaint &paint)
Definition: SkCanvas.cpp:1710
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void drawPath(const SkPath &path, const SkPaint &paint)
Definition: SkCanvas.cpp:1747
@ kPoints_PointMode
draw each point separately
Definition: SkCanvas.h:1241
static sk_sp< SkPathEffect > Make(const SkScalar intervals[], int count, SkScalar phase)
void setStyle(Style style)
Definition: SkPaint.cpp:105
void setColor(SkColor color)
Definition: SkPaint.cpp:119
void setAntiAlias(bool aa)
Definition: SkPaint.h:170
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
void setPathEffect(sk_sp< SkPathEffect > pathEffect)
void setStrokeWidth(SkScalar width)
Definition: SkPaint.cpp:159
Definition: SkPath.h:59
static SkPath RRect(const SkRRect &, SkPathDirection dir=SkPathDirection::kCW)
Definition: SkPath.cpp:3602
static SkPath Rect(const SkRect &, SkPathDirection=SkPathDirection::kCW, unsigned startIndex=0)
Definition: SkPath.cpp:3586
static SkPath Oval(const SkRect &, SkPathDirection=SkPathDirection::kCW)
Definition: SkPath.cpp:3590
void setOval(const SkRect &oval)
Definition: SkRRect.cpp:30
void setRectRadii(const SkRect &rect, const SkVector radii[4])
Definition: SkRRect.cpp:189
void setRect(const SkRect &rect)
Definition: SkRRect.h:126
int size() const
Definition: SkTArray.h:421
void onDraw(SkCanvas *canvas) override
SkString getName() const override
SkISize getISize() override
void onOnceBeforeDraw() override
Definition: gm.h:110
GM(SkColor backgroundColor=SK_ColorWHITE)
Definition: gm.cpp:81
float SkScalar
Definition: extension.cpp:12
SkRRect rrect
Definition: SkRecords.h:232
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets dir
Definition: switches.h:145
DEF_GM(return F(C(clipbox), 0.0f, 0.0f, {})) DEF_GM(return F(C(clipbox)
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition: SkRect.h:646