Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
PaintDump.cpp File Reference
#include "tools/fiddle/examples.h"

Go to the source code of this file.

Functions

 REG_FIDDLE (PaintDump, 256, 256, true, 0)
 

Function Documentation

◆ REG_FIDDLE()

REG_FIDDLE ( PaintDump  ,
256  ,
256  ,
true  ,
 
)

Definition at line 4 of file PaintDump.cpp.

4 {
5static const char* str(SkPaint::Cap v) {
6 switch (v) {
7 case SkPaint::kButt_Cap: return "SkPaint::kButt_Cap";
8 case SkPaint::kRound_Cap: return "SkPaint::kRound_Cap";
9 case SkPaint::kSquare_Cap: return "SkPaint::kSquare_Cap";
10 default: return "?";
11 }
12}
13static const char* str(SkPaint::Join v) {
14 switch (v) {
15 case SkPaint::kMiter_Join: return "SkPaint::kMiter_Join";
16 case SkPaint::kRound_Join: return "SkPaint::kRound_Join";
17 case SkPaint::kBevel_Join: return "SkPaint::kBevel_Join";
18 default: return "?";
19 }
20}
21static const char* str(SkPaint::Style v) {
22 switch (v) {
23 case SkPaint::kFill_Style: return "SkPaint::kFill_Style";
24 case SkPaint::kStroke_Style: return "SkPaint::kStroke_Style";
25 case SkPaint::kStrokeAndFill_Style: return "SkPaint::kStrokeAndFill_Style";
26 default: return "?";
27 }
28}
29
30static const char* str(bool v) { return v ? "true" : "false"; }
31
32SkString PaintStringDump(const SkPaint& p) {
33 SkString s("SkPaint p;\n");
34 SkPaint d;
35 if (d.getStrokeWidth() != p.getStrokeWidth()) {
36 s.appendf("p.setStrokeWidth(%.9g);\n", p.getStrokeWidth());
37 }
38 if (d.getStrokeMiter() != p.getStrokeMiter()) {
39 s.appendf("p.setStrokeMiter(%.9g);\n", p.getStrokeMiter());
40 }
41 SkColor4f c = p.getColor4f();
42 if (c != d.getColor4f()) {
43 s.appendf("p.setColor4f({%.9g, %.9g, %.9g, %.9g}, nullptr);\n", c.fR, c.fG, c.fB, c.fA);
44 }
45 if (d.isAntiAlias() != p.isAntiAlias()) {
46 s.appendf("p.setAntiAlias(%s);\n", str(p.isAntiAlias()));
47 }
48 if (d.isDither() != p.isDither()) {
49 s.appendf("p.setDither(%s);\n", str(p.isDither()));
50 }
51 if (d.getStrokeCap() != p.getStrokeCap()) {
52 s.appendf("p.setStrokeCap(%s);\n", str(p.getStrokeCap()));
53 }
54 if (d.getStrokeJoin() != p.getStrokeJoin()) {
55 s.appendf("p.setStrokeJoin(%s);\n", str(p.getStrokeJoin()));
56 }
57 if (d.getStyle() != p.getStyle()) {
58 s.appendf("p.setStyle(%s);\n", str(p.getStyle()));
59 }
60 if (d.asBlendMode() != p.asBlendMode()) {
61 s.appendf("p.setBlendMode(SkBlendMode::k%s);\n",
62 SkBlendMode_Name(p.getBlendMode_or(SkBlendMode::kSrcOver)));
63 }
64 if (p.getPathEffect()) {
65 s.appendf("p.setPathEffect(/*FIXME*/);\n");
66 }
67 if (p.getShader()) {
68 s.appendf("p.setShader(/*FIXME*/);\n");
69 }
70 if (p.getMaskFilter()) {
71 s.appendf("p.setMaskFilter(/*FIXME*/);\n");
72 }
73 if (p.getColorFilter()) {
74 s.appendf("p.setColorFilter(/*FIXME*/);\n");
75 }
76 if (p.getImageFilter()) {
77 s.appendf("p.setImageFilter(/*FIXME*/);\n");
78 }
79 return s;
80}
81
82void draw(SkCanvas* canvas) {
83 SkPaint p;
84 p.setColor(SK_ColorRED);
85 p.setAntiAlias(true);
86 p.setStyle(SkPaint::kStroke_Style);
87 p.setStrokeWidth(10);
88 p.setBlendMode(SkBlendMode::kDstOver);
89 p.setStrokeCap(SkPaint::kRound_Cap);
91
92 auto s = PaintStringDump(p);
93 SkDebugf("%s", s.c_str());
94}
95
96} // END FIDDLE
SK_API const char * SkBlendMode_Name(SkBlendMode blendMode)
@ kSrcOver
r = s + (1-sa)*d
@ kDstOver
r = d + (1-da)*s
constexpr SkColor SK_ColorRED
Definition SkColor.h:126
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition aaclip.cpp:27
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
Definition SkImage.cpp:179
@ kRound_Cap
adds circle
Definition SkPaint.h:335
@ kButt_Cap
no stroke extension
Definition SkPaint.h:334
@ kSquare_Cap
adds square
Definition SkPaint.h:336
@ kStroke_Style
set to stroke geometry
Definition SkPaint.h:194
@ kFill_Style
set to fill geometry
Definition SkPaint.h:193
@ kStrokeAndFill_Style
sets to stroke and fill geometry
Definition SkPaint.h:195
@ kRound_Join
adds circle
Definition SkPaint.h:360
@ kMiter_Join
extends to miter limit
Definition SkPaint.h:359
@ kBevel_Join
connects outside edges
Definition SkPaint.h:361
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition main.cc:19
sk_sp< SkImage > image
Definition examples.cpp:29
struct MyStruct s