Flutter Engine
The Flutter Engine
Classes | Macros | Functions | Variables
strokes.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPath.h"
#include "include/core/SkPathEffect.h"
#include "include/core/SkPathUtils.h"
#include "include/core/SkPoint.h"
#include "include/core/SkRect.h"
#include "include/core/SkScalar.h"
#include "include/core/SkSize.h"
#include "include/core/SkString.h"
#include "include/core/SkTypes.h"
#include "include/effects/SkDashPathEffect.h"
#include "include/utils/SkParsePath.h"
#include "src/base/SkFloatBits.h"
#include "src/base/SkRandom.h"
#include "tools/ToolUtils.h"
#include <string.h>

Go to the source code of this file.

Classes

class  StrokesGM
 
class  ZeroLenStrokesGM
 
class  TeenyStrokesGM
 
class  Strokes2GM
 
class  Strokes3GM
 
class  Strokes4GM
 
class  Strokes5GM
 

Macros

#define W   400
 
#define H   400
 
#define N   50
 

Functions

static void rnd_rect (SkRect *r, SkPaint *paint, SkRandom &rand)
 
 DEF_SIMPLE_GM (CubicStroke, canvas, 384, 384)
 
 DEF_SIMPLE_GM (zerolinestroke, canvas, 90, 120)
 
 DEF_SIMPLE_GM (quadcap, canvas, 200, 200)
 
static SkRect inset (const SkRect &r)
 
 DEF_SIMPLE_GM (zerolinedash, canvas, 256, 256)
 
 DEF_SIMPLE_GM (inner_join_geometry, canvas, 1000, 700)
 
 DEF_SIMPLE_GM (skbug12244, canvas, 150, 150)
 
 DEF_SIMPLE_GM (b_340982297, canvas, 80, 50)
 

Variables

constexpr SkScalar SW = SkIntToScalar(W)
 
constexpr SkScalar SH = SkIntToScalar(H)
 

Macro Definition Documentation

◆ H

#define H   400

Definition at line 34 of file strokes.cpp.

◆ N

#define N   50

Definition at line 35 of file strokes.cpp.

◆ W

#define W   400

Definition at line 33 of file strokes.cpp.

Function Documentation

◆ DEF_SIMPLE_GM() [1/7]

DEF_SIMPLE_GM ( b_340982297  ,
canvas  ,
80  ,
50   
)

Definition at line 626 of file strokes.cpp.

626 {
628 paint.setAntiAlias(true);
629
630 SkPath path;
631 path.moveTo(30.23983f, 48.5674667f);
632 path.lineTo(1.30884242f, 45.5222702f);
633 path.lineTo(2.97688866f, 29.6749554f);
634 path.lineTo(17.4423828f, 31.1975555f);
635 path.lineTo(2.94269657f, 30.0452003f);
636 path.lineTo(4.38597536f, 11.8849154f);
637 path.lineTo(33.3853493f, 14.1896257f);
638 path.close();
639
640 canvas->drawPath(path, paint);
641
642 path.reset();
643 path.moveTo(73.3853455f, 4.18963623f);
644 path.lineTo(69.995636f, 39.1360626f);
645 path.lineTo(42.83145142f, 21.056778f);
646 path.lineTo(42.97689819f, 19.6749573f);
647 path.lineTo(57.4423828f, 21.1975555f);
648 path.lineTo(42.94268799f, 20.0451965f);
649 path.lineTo(44.38595581f, 1.88491821f);
650 path.close();
651
652 canvas->drawPath(path, paint);
653}
Definition: SkPath.h:59
const Paint & paint
Definition: color_source.cc:38
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_SIMPLE_GM() [2/7]

DEF_SIMPLE_GM ( CubicStroke  ,
canvas  ,
384  ,
384   
)

Definition at line 208 of file strokes.cpp.

208 {
209 SkPaint p;
210 p.setAntiAlias(true);
211 p.setStyle(SkPaint::kStroke_Style);
212 p.setStrokeWidth(1.0720f);
213 SkPath path;
214 path.moveTo(-6000,-6000);
215 path.cubicTo(-3500,5500,-500,5500,2500,-6500);
216 canvas->drawPath(path, p);
217 p.setStrokeWidth(1.0721f);
218 canvas->translate(10, 10);
219 canvas->drawPath(path, p);
220 p.setStrokeWidth(1.0722f);
221 canvas->translate(10, 10);
222 canvas->drawPath(path, p);
223}
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194

◆ DEF_SIMPLE_GM() [3/7]

DEF_SIMPLE_GM ( inner_join_geometry  ,
canvas  ,
1000  ,
700   
)

Definition at line 558 of file strokes.cpp.

558 {
559 // These paths trigger cases where we must add inner join geometry.
560 // skbug.com/11964
561 const SkPoint pathPoints[] = {
562 /*moveTo*/ /*lineTo*/ /*lineTo*/
563 {119, 71}, {129, 151}, {230, 24},
564 {200, 144}, {129, 151}, {230, 24},
565 {192, 176}, {224, 175}, {281, 103},
566 {233, 205}, {224, 175}, {281, 103},
567 {121, 216}, {234, 189}, {195, 147},
568 {141, 216}, {254, 189}, {238, 250},
569 {159, 202}, {269, 197}, {289, 165},
570 {159, 202}, {269, 197}, {287, 227},
571 };
572
573 SkPaint pathPaint;
574 pathPaint.setStroke(true);
575 pathPaint.setAntiAlias(true);
576 pathPaint.setStrokeWidth(100);
577
578 SkPaint skeletonPaint;
579 skeletonPaint.setStroke(true);
580 skeletonPaint.setAntiAlias(true);
581 skeletonPaint.setStrokeWidth(0);
582 skeletonPaint.setColor(SK_ColorRED);
583
584 canvas->translate(0, 50);
585 for (size_t i = 0; i < std::size(pathPoints) / 3; i++) {
586 auto path = SkPath::Polygon(pathPoints + i * 3, 3, false);
587 canvas->drawPath(path, pathPaint);
588
589 SkPath fillPath;
590 skpathutils::FillPathWithPaint(path, pathPaint, &fillPath);
591 canvas->drawPath(fillPath, skeletonPaint);
592
593 canvas->translate(200, 0);
594 if ((i + 1) % 4 == 0) {
595 canvas->translate(-800, 200);
596 }
597 }
598}
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
void setColor(SkColor color)
Definition: SkPaint.cpp:119
void setAntiAlias(bool aa)
Definition: SkPaint.h:170
void setStroke(bool)
Definition: SkPaint.cpp:115
void setStrokeWidth(SkScalar width)
Definition: SkPaint.cpp:159
static SkPath Polygon(const SkPoint pts[], int count, bool isClosed, SkPathFillType=SkPathFillType::kWinding, bool isVolatile=false)
Definition: SkPath.cpp:3614
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
SK_API bool FillPathWithPaint(const SkPath &src, const SkPaint &paint, SkPath *dst, const SkRect *cullRect, SkScalar resScale=1)
Definition: SkPathUtils.cpp:23

◆ DEF_SIMPLE_GM() [4/7]

DEF_SIMPLE_GM ( quadcap  ,
canvas  ,
200  ,
200   
)

Definition at line 251 of file strokes.cpp.

251 {
252 SkPaint p;
253 p.setAntiAlias(true);
254 p.setStyle(SkPaint::kStroke_Style);
255 p.setStrokeWidth(0);
256 SkPath path;
257 SkPoint pts[] = {{105.738571f,13.126318f},
258 {105.738571f,13.126318f},
259 {123.753784f,1.f}};
260 SkVector tangent = pts[1] - pts[2];
261 tangent.normalize();
262 SkPoint pts2[3];
263 memcpy(pts2, pts, sizeof(pts));
264 const SkScalar capOutset = SK_ScalarPI / 8;
265 pts2[0].fX += tangent.fX * capOutset;
266 pts2[0].fY += tangent.fY * capOutset;
267 pts2[1].fX += tangent.fX * capOutset;
268 pts2[1].fY += tangent.fY * capOutset;
269 pts2[2].fX += -tangent.fX * capOutset;
270 pts2[2].fY += -tangent.fY * capOutset;
271 path.moveTo(pts2[0]);
272 path.quadTo(pts2[1], pts2[2]);
273 canvas->drawPath(path, p);
274
275 path.reset();
276 path.moveTo(pts[0]);
277 path.quadTo(pts[1], pts[2]);
278 p.setStrokeCap(SkPaint::kRound_Cap);
279 canvas->translate(30, 0);
280 canvas->drawPath(path, p);
281}
#define SK_ScalarPI
Definition: SkScalar.h:21
@ kRound_Cap
adds circle
Definition: SkPaint.h:335
float SkScalar
Definition: extension.cpp:12
float fX
x-axis value
Definition: SkPoint_impl.h:164
float fY
y-axis value
Definition: SkPoint_impl.h:165
bool normalize()
Definition: SkPoint.cpp:22

◆ DEF_SIMPLE_GM() [5/7]

DEF_SIMPLE_GM ( skbug12244  ,
canvas  ,
150  ,
150   
)

Definition at line 600 of file strokes.cpp.

600 {
601 // Should look like a stroked triangle; these vertices are the results of the SkStroker
602 // but we draw as a filled path in order to highlight that it's the GPU triangulating path
603 // renderer that's the source of the problem, and not the stroking operation. The original
604 // path was a simple:
605 // m(0,0), l(100, 40), l(0, 80), l(0,0) with a stroke width of 15px
606 SkPath path;
607 path.moveTo(2.7854299545288085938, -6.9635753631591796875);
608 path.lineTo( 120.194366455078125, 40);
609 path.lineTo(-7.5000004768371582031, 91.07775115966796875);
610 path.lineTo(-7.5000004768371582031, -11.077748298645019531);
611 path.lineTo(2.7854299545288085938, -6.9635753631591796875);
612 path.moveTo(-2.7854299545288085938, 6.9635753631591796875);
613 path.lineTo( 0, 0);
614 path.lineTo( 7.5, 0);
615 path.lineTo(7.5000004768371582031, 68.92224884033203125);
616 path.lineTo( 79.805633544921875, 40);
617 path.lineTo(-2.7854299545288085938, 6.9635753631591796875);
618
619 SkPaint p;
620 p.setColor(SK_ColorGREEN);
621
622 canvas->translate(20.f, 20.f);
623 canvas->drawPath(path, p);
624}
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131

◆ DEF_SIMPLE_GM() [6/7]

DEF_SIMPLE_GM ( zerolinedash  ,
canvas  ,
256  ,
256   
)

Definition at line 513 of file strokes.cpp.

513 {
514 canvas->clear(SK_ColorWHITE);
515
517 paint.setColor(SkColorSetARGB(255, 0, 0, 0));
518 paint.setStrokeWidth(11);
519 paint.setStrokeCap(SkPaint::kRound_Cap);
520 paint.setStrokeJoin(SkPaint::kBevel_Join);
521
522 SkScalar dash_pattern[] = {1, 5};
523 paint.setPathEffect(SkDashPathEffect::Make(dash_pattern, 2, 0));
524
525 canvas->drawLine(100, 100, 100, 100, paint);
526}
static constexpr SkColor SkColorSetARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Definition: SkColor.h:49
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
static sk_sp< SkPathEffect > Make(const SkScalar intervals[], int count, SkScalar phase)
@ kBevel_Join
connects outside edges
Definition: SkPaint.h:361

◆ DEF_SIMPLE_GM() [7/7]

DEF_SIMPLE_GM ( zerolinestroke  ,
canvas  ,
90  ,
120   
)

Definition at line 225 of file strokes.cpp.

225 {
228 paint.setStrokeWidth(20);
229 paint.setAntiAlias(true);
230 paint.setStrokeCap(SkPaint::kRound_Cap);
231
232 SkPath path;
233 path.moveTo(30, 90);
234 path.lineTo(30, 90);
235 path.lineTo(60, 90);
236 path.lineTo(60, 90);
237 canvas->drawPath(path, paint);
238
239 path.reset();
240 path.moveTo(30, 30);
241 path.lineTo(60, 30);
242 canvas->drawPath(path, paint);
243
244 path.reset();
245 path.moveTo(30, 60);
246 path.lineTo(30, 60);
247 path.lineTo(60, 60);
248 canvas->drawPath(path, paint);
249}

◆ inset()

static SkRect inset ( const SkRect r)
static

Definition at line 332 of file strokes.cpp.

332 {
333 SkRect rr(r);
334 rr.inset(r.width()/10, r.height()/10);
335 return rr;
336}
constexpr float height() const
Definition: SkRect.h:769
constexpr float width() const
Definition: SkRect.h:762

◆ rnd_rect()

static void rnd_rect ( SkRect r,
SkPaint paint,
SkRandom rand 
)
static

Definition at line 40 of file strokes.cpp.

40 {
41 SkScalar x = rand.nextUScalar1() * W;
42 SkScalar y = rand.nextUScalar1() * H;
43 SkScalar w = rand.nextUScalar1() * (W >> 2);
44 SkScalar h = rand.nextUScalar1() * (H >> 2);
45 SkScalar hoffset = rand.nextSScalar1();
46 SkScalar woffset = rand.nextSScalar1();
47
48 r->setXYWH(x, y, w, h);
49 r->offset(-w/2 + woffset, -h/2 + hoffset);
50
51 paint->setColor(rand.nextU());
52 paint->setAlphaf(1.0f);
53}
uint32_t nextU()
Definition: SkRandom.h:42
SkScalar nextUScalar1()
Definition: SkRandom.h:101
SkScalar nextSScalar1()
Definition: SkRandom.h:113
double y
double x
SkScalar w
SkScalar h
#define W
Definition: strokes.cpp:33
#define H
Definition: strokes.cpp:34
Definition: SkMD5.cpp:130
void setXYWH(float x, float y, float width, float height)
Definition: SkRect.h:931
void offset(float dx, float dy)
Definition: SkRect.h:1016

Variable Documentation

◆ SH

constexpr SkScalar SH = SkIntToScalar(H)
constexpr

Definition at line 38 of file strokes.cpp.

◆ SW

constexpr SkScalar SW = SkIntToScalar(W)
constexpr

Definition at line 37 of file strokes.cpp.