Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Friends | List of all members
flutter::Paint Class Reference

#include <paint.h>

Public Member Functions

 Paint ()=default
 
 Paint (Dart_Handle paint_objects, Dart_Handle paint_data)
 
const DlPaintpaint (DlPaint &paint, const DisplayListAttributeFlags &flags) const
 
void toDlPaint (DlPaint &paint) const
 
bool isNull () const
 
bool isNotNull () const
 

Friends

struct tonic::DartConverter< Paint >
 

Detailed Description

Definition at line 15 of file paint.h.

Constructor & Destructor Documentation

◆ Paint() [1/2]

flutter::Paint::Paint ( )
default

◆ Paint() [2/2]

Paint::Paint ( Dart_Handle  paint_objects,
Dart_Handle  paint_data 
)

Definition at line 61 of file paint.cc.

62 : paint_objects_(paint_objects), paint_data_(paint_data) {}

Member Function Documentation

◆ isNotNull()

bool flutter::Paint::isNotNull ( ) const
inline

Definition at line 26 of file paint.h.

26{ return !Dart_IsNull(paint_data_); }
DART_EXPORT bool Dart_IsNull(Dart_Handle object)

◆ isNull()

bool flutter::Paint::isNull ( ) const
inline

Definition at line 25 of file paint.h.

25{ return Dart_IsNull(paint_data_); }

◆ paint()

const DlPaint * Paint::paint ( DlPaint paint,
const DisplayListAttributeFlags flags 
) const

Definition at line 64 of file paint.cc.

65 {
66 if (isNull()) {
67 return nullptr;
68 }
69 tonic::DartByteData byte_data(paint_data_);
70 FML_CHECK(byte_data.length_in_bytes() == kDataByteCount);
71
72 const uint32_t* uint_data = static_cast<const uint32_t*>(byte_data.data());
73 const float* float_data = static_cast<const float*>(byte_data.data());
74
76 if (Dart_IsNull(paint_objects_)) {
77 if (flags.applies_shader()) {
78 paint.setColorSource(nullptr);
79 }
80 if (flags.applies_color_filter()) {
81 paint.setColorFilter(nullptr);
82 }
83 if (flags.applies_image_filter()) {
84 paint.setImageFilter(nullptr);
85 }
86 } else {
87 FML_DCHECK(Dart_IsList(paint_objects_));
88 intptr_t length = 0;
89 Dart_ListLength(paint_objects_, &length);
90
92 if (Dart_IsError(
93 Dart_ListGetRange(paint_objects_, 0, kObjectCount, values))) {
94 return nullptr;
95 }
96
97 if (flags.applies_shader()) {
99 if (Dart_IsNull(shader)) {
100 paint.setColorSource(nullptr);
101 } else {
102 if (Shader* decoded = tonic::DartConverter<Shader*>::FromDart(shader)) {
103 auto sampling =
105 paint.setColorSource(decoded->shader(sampling));
106 } else {
107 paint.setColorSource(nullptr);
108 }
109 }
110 }
111
112 if (flags.applies_color_filter()) {
115 paint.setColorFilter(nullptr);
116 } else {
117 ColorFilter* decoded =
119 paint.setColorFilter(decoded->filter());
120 }
121 }
122
123 if (flags.applies_image_filter()) {
124 Dart_Handle image_filter = values[kImageFilterIndex];
125 if (Dart_IsNull(image_filter)) {
126 paint.setImageFilter(nullptr);
127 } else {
128 ImageFilter* decoded =
130 paint.setImageFilter(decoded->filter());
131 }
132 }
133 }
134
135 if (flags.applies_anti_alias()) {
136 paint.setAntiAlias(uint_data[kIsAntiAliasIndex] == 0);
137 }
138
139 if (flags.applies_alpha_or_color()) {
140 uint32_t encoded_color = uint_data[kColorIndex];
141 paint.setColor(DlColor(encoded_color ^ kColorDefault));
142 }
143
144 if (flags.applies_blend()) {
145 uint32_t encoded_blend_mode = uint_data[kBlendModeIndex];
146 uint32_t blend_mode = encoded_blend_mode ^ kBlendModeDefault;
147 paint.setBlendMode(static_cast<DlBlendMode>(blend_mode));
148 }
149
150 if (flags.applies_style()) {
151 uint32_t style = uint_data[kStyleIndex];
152 paint.setDrawStyle(static_cast<DlDrawStyle>(style));
153 }
154
155 if (flags.is_stroked(paint.getDrawStyle())) {
156 float stroke_width = float_data[kStrokeWidthIndex];
157 paint.setStrokeWidth(stroke_width);
158
159 float stroke_miter_limit = float_data[kStrokeMiterLimitIndex];
160 paint.setStrokeMiter(stroke_miter_limit + kStrokeMiterLimitDefault);
161
162 uint32_t stroke_cap = uint_data[kStrokeCapIndex];
163 paint.setStrokeCap(static_cast<DlStrokeCap>(stroke_cap));
164
165 uint32_t stroke_join = uint_data[kStrokeJoinIndex];
166 paint.setStrokeJoin(static_cast<DlStrokeJoin>(stroke_join));
167 }
168
169 if (flags.applies_color_filter()) {
170 paint.setInvertColors(uint_data[kInvertColorIndex] != 0);
171 }
172
173 if (flags.applies_path_effect()) {
174 // The paint API exposed to Dart does not support path effects. But other
175 // operations such as text may set a path effect, which must be cleared.
176 paint.setPathEffect(nullptr);
177 }
178
179 if (flags.applies_mask_filter()) {
180 switch (uint_data[kMaskFilterIndex]) {
181 case kNull:
182 paint.setMaskFilter(nullptr);
183 break;
184 case kBlur:
185 DlBlurStyle blur_style =
186 static_cast<DlBlurStyle>(uint_data[kMaskFilterBlurStyleIndex]);
187 double sigma = float_data[kMaskFilterSigmaIndex];
188 paint.setMaskFilter(
189 DlBlurMaskFilter::Make(blur_style, SafeNarrow(sigma)));
190 break;
191 }
192 }
193
194 return &paint;
195}
static sk_sp< SkImage > color_filter(const SkImage *image, SkColorFilter *colorFilter)
static std::shared_ptr< DlMaskFilter > Make(DlBlurStyle style, SkScalar sigma, bool respect_ctm=true)
static DlImageSampling SamplingFromIndex(int filterQualityIndex)
bool isNull() const
Definition paint.h:25
const Paint & paint
DART_EXPORT Dart_Handle Dart_ListGetRange(Dart_Handle list, intptr_t offset, intptr_t length, Dart_Handle *result)
struct _Dart_Handle * Dart_Handle
Definition dart_api.h:258
DART_EXPORT Dart_Handle Dart_ListLength(Dart_Handle list, intptr_t *length)
DART_EXPORT bool Dart_IsError(Dart_Handle handle)
DART_EXPORT bool Dart_IsList(Dart_Handle object)
FlutterSemanticsFlag flags
#define FML_CHECK(condition)
Definition logging.h:85
#define FML_DCHECK(condition)
Definition logging.h:103
size_t length
SkSamplingOptions sampling
Definition SkRecords.h:337
constexpr int kStrokeJoinIndex
Definition paint.cc:30
constexpr int kMaskFilterIndex
Definition paint.cc:33
DlStrokeJoin
Definition dl_paint.h:38
constexpr int kShaderIndex
Definition paint.cc:42
constexpr uint32_t kColorDefault
Definition paint.cc:48
constexpr int kInvertColorIndex
Definition paint.cc:36
constexpr int kBlendModeIndex
Definition paint.cc:26
DlStrokeCap
Definition dl_paint.h:29
constexpr int kStyleIndex
Definition paint.cc:27
constexpr int kMaskFilterSigmaIndex
Definition paint.cc:35
constexpr int kStrokeCapIndex
Definition paint.cc:29
constexpr int kObjectCount
Definition paint.cc:45
DlDrawStyle
Definition dl_paint.h:20
constexpr uint32_t kBlendModeDefault
Definition paint.cc:51
static float SafeNarrow(double value)
constexpr int kColorFilterIndex
Definition paint.cc:43
constexpr int kStrokeMiterLimitIndex
Definition paint.cc:31
constexpr int kImageFilterIndex
Definition paint.cc:44
constexpr int kIsAntiAliasIndex
Definition paint.cc:24
constexpr int kStrokeWidthIndex
Definition paint.cc:28
@ kBlur
Definition paint.cc:59
@ kNull
Definition paint.cc:59
constexpr float kStrokeMiterLimitDefault
Definition paint.cc:56
constexpr int kFilterQualityIndex
Definition paint.cc:32
constexpr int kColorIndex
Definition paint.cc:25
constexpr int kMaskFilterBlurStyleIndex
Definition paint.cc:34
constexpr size_t kDataByteCount
Definition paint.cc:37
SK_API sk_sp< PrecompileShader > ColorFilter(SkSpan< const sk_sp< PrecompileShader > > shaders, SkSpan< const sk_sp< PrecompileColorFilter > > colorFilters)
const Scalar stroke_width

◆ toDlPaint()

void Paint::toDlPaint ( DlPaint paint) const

Definition at line 197 of file paint.cc.

197 {
198 if (isNull()) {
199 return;
200 }
201 FML_DCHECK(paint == DlPaint());
202
203 tonic::DartByteData byte_data(paint_data_);
204 FML_CHECK(byte_data.length_in_bytes() == kDataByteCount);
205
206 const uint32_t* uint_data = static_cast<const uint32_t*>(byte_data.data());
207 const float* float_data = static_cast<const float*>(byte_data.data());
208
210 if (!Dart_IsNull(paint_objects_)) {
211 FML_DCHECK(Dart_IsList(paint_objects_));
212 intptr_t length = 0;
213 Dart_ListLength(paint_objects_, &length);
214
216 if (Dart_IsError(
217 Dart_ListGetRange(paint_objects_, 0, kObjectCount, values))) {
218 return;
219 }
220
222 if (!Dart_IsNull(shader)) {
223 if (Shader* decoded = tonic::DartConverter<Shader*>::FromDart(shader)) {
224 auto sampling =
226 paint.setColorSource(decoded->shader(sampling));
227 }
228 }
229
232 ColorFilter* decoded =
234 paint.setColorFilter(decoded->filter());
235 }
236
237 Dart_Handle image_filter = values[kImageFilterIndex];
238 if (!Dart_IsNull(image_filter)) {
239 ImageFilter* decoded =
241 paint.setImageFilter(decoded->filter());
242 }
243 }
244
245 paint.setAntiAlias(uint_data[kIsAntiAliasIndex] == 0);
246
247 uint32_t encoded_color = uint_data[kColorIndex];
248 paint.setColor(DlColor(encoded_color ^ kColorDefault));
249
250 uint32_t encoded_blend_mode = uint_data[kBlendModeIndex];
251 uint32_t blend_mode = encoded_blend_mode ^ kBlendModeDefault;
252 paint.setBlendMode(static_cast<DlBlendMode>(blend_mode));
253
254 uint32_t style = uint_data[kStyleIndex];
255 paint.setDrawStyle(static_cast<DlDrawStyle>(style));
256
257 float stroke_width = float_data[kStrokeWidthIndex];
258 paint.setStrokeWidth(stroke_width);
259
260 float stroke_miter_limit = float_data[kStrokeMiterLimitIndex];
261 paint.setStrokeMiter(stroke_miter_limit + kStrokeMiterLimitDefault);
262
263 uint32_t stroke_cap = uint_data[kStrokeCapIndex];
264 paint.setStrokeCap(static_cast<DlStrokeCap>(stroke_cap));
265
266 uint32_t stroke_join = uint_data[kStrokeJoinIndex];
267 paint.setStrokeJoin(static_cast<DlStrokeJoin>(stroke_join));
268
269 paint.setInvertColors(uint_data[kInvertColorIndex] != 0);
270
271 switch (uint_data[kMaskFilterIndex]) {
272 case kNull:
273 break;
274 case kBlur:
275 DlBlurStyle blur_style =
276 static_cast<DlBlurStyle>(uint_data[kMaskFilterBlurStyleIndex]);
277 float sigma = SafeNarrow(float_data[kMaskFilterSigmaIndex]);
278 // Make could return a nullptr here if the values are NOP or
279 // do not make sense. We could interpret that as if there was
280 // no value passed from Dart at all (i.e. don't change the
281 // setting in the paint object as in the kNull branch right
282 // above here), but the maskfilter flag was actually set
283 // indicating that the developer "tried" to set a mask, so we
284 // should set the null value rather than do nothing.
285 paint.setMaskFilter(DlBlurMaskFilter::Make(blur_style, sigma));
286 break;
287 }
288}

Friends And Related Symbol Documentation

◆ tonic::DartConverter< Paint >

friend struct tonic::DartConverter< Paint >
friend

Definition at line 26 of file paint.h.


The documentation for this class was generated from the following files: