Flutter Engine
The Flutter Engine
third_party
skia
docs
examples
PaintDump.cpp
Go to the documentation of this file.
1
// Copyright 2020 Google LLC.
2
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
3
#include "
tools/fiddle/examples.h
"
4
REG_FIDDLE
(PaintDump, 256, 256,
true
, 0) {
5
static
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
}
13
static
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
}
21
static
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
30
static
const
char
* str(
bool
v) {
return
v ?
"true"
:
"false"
; }
31
32
SkString
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
82
void
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
);
90
p
.setShader(
image
->
makeShader
(
SkTileMode::kRepeat
,
SkTileMode::kRepeat
,
SkSamplingOptions
()));
91
92
auto
s
= PaintStringDump(
p
);
93
SkDebugf
(
"%s"
,
s
.c_str());
94
}
95
96
}
// END FIDDLE
REG_FIDDLE
REG_FIDDLE(PaintDump, 256, 256, true, 0)
Definition:
PaintDump.cpp:4
SkBlendMode_Name
SK_API const char * SkBlendMode_Name(SkBlendMode blendMode)
Definition:
SkBlendMode.cpp:167
SkBlendMode::kSrcOver
@ kSrcOver
r = s + (1-sa)*d
SkBlendMode::kDstOver
@ kDstOver
r = d + (1-da)*s
SK_ColorRED
constexpr SkColor SK_ColorRED
Definition:
SkColor.h:126
SkDebugf
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
SkTileMode::kRepeat
@ kRepeat
draw
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition:
aaclip.cpp:27
SkCanvas
Definition:
SkCanvas.h:106
SkImage::makeShader
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
Definition:
SkImage.cpp:179
SkPaint
Definition:
SkPaint.h:44
SkPaint::Cap
Cap
Definition:
SkPaint.h:333
SkPaint::kRound_Cap
@ kRound_Cap
adds circle
Definition:
SkPaint.h:335
SkPaint::kButt_Cap
@ kButt_Cap
no stroke extension
Definition:
SkPaint.h:334
SkPaint::kSquare_Cap
@ kSquare_Cap
adds square
Definition:
SkPaint.h:336
SkPaint::Style
Style
Definition:
SkPaint.h:192
SkPaint::kStroke_Style
@ kStroke_Style
set to stroke geometry
Definition:
SkPaint.h:194
SkPaint::kFill_Style
@ kFill_Style
set to fill geometry
Definition:
SkPaint.h:193
SkPaint::kStrokeAndFill_Style
@ kStrokeAndFill_Style
sets to stroke and fill geometry
Definition:
SkPaint.h:195
SkPaint::Join
Join
Definition:
SkPaint.h:358
SkPaint::kRound_Join
@ kRound_Join
adds circle
Definition:
SkPaint.h:360
SkPaint::kMiter_Join
@ kMiter_Join
extends to miter limit
Definition:
SkPaint.h:359
SkPaint::kBevel_Join
@ kBevel_Join
connects outside edges
Definition:
SkPaint.h:361
SkString
Definition:
SkString.h:118
d
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition:
main.cc:19
examples.h
s
struct MyStruct s
SkRecords::image
sk_sp< const SkImage > image
Definition:
SkRecords.h:269
dart_profiler_symbols.p
p
Definition:
dart_profiler_symbols.py:55
SkColor4f
SkSamplingOptions
Definition:
SkSamplingOptions.h:58
Generated on Sun Jun 23 2024 21:55:55 for Flutter Engine by
1.9.4