Flutter Engine
flutter::Paint Class Reference

#include <paint.h>

Public Member Functions

 Paint ()=default
 
 Paint (Dart_Handle paint_objects, Dart_Handle paint_data)
 
const SkPaint * paint () const
 

Friends

struct tonic::DartConverter< Paint >
 

Detailed Description

Definition at line 13 of file paint.h.

Constructor & Destructor Documentation

◆ Paint() [1/2]

flutter::Paint::Paint ( )
default

◆ Paint() [2/2]

flutter::Paint::Paint ( Dart_Handle  paint_objects,
Dart_Handle  paint_data 
)

Definition at line 68 of file paint.cc.

References flutter::Blur, tonic::DartByteData::data(), flutter::ImageFilter::filter(), flutter::ColorFilter::filter(), FML_CHECK, FML_DCHECK, flutter::kBlendModeDefault, flutter::kBlendModeIndex, flutter::kColorDefault, flutter::kColorFilterIndex, flutter::kColorIndex, flutter::kDataByteCount, flutter::kFilterQualityIndex, flutter::kImageFilterIndex, flutter::kMaskFilterBlurStyleIndex, flutter::kMaskFilterSigmaIndex, flutter::kObjectCount, flutter::kShaderIndex, flutter::kStrokeCapIndex, flutter::kStrokeJoinIndex, flutter::kStrokeMiterLimitIndex, flutter::kStrokeWidthIndex, flutter::kStyleIndex, length, tonic::DartByteData::length_in_bytes(), flutter::ColorFilter::MakeColorMatrixFilter255(), flutter::Null, and flutter::Shader::shader().

68  {
69  is_null_ = Dart_IsNull(paint_data);
70  if (is_null_) {
71  return;
72  }
73 
74  Dart_Handle values[kObjectCount];
75  if (!Dart_IsNull(paint_objects)) {
76  FML_DCHECK(Dart_IsList(paint_objects));
77  intptr_t length = 0;
78  Dart_ListLength(paint_objects, &length);
79 
80  FML_CHECK(length == kObjectCount);
81  if (Dart_IsError(
82  Dart_ListGetRange(paint_objects, 0, kObjectCount, values))) {
83  return;
84  }
85 
86  Dart_Handle shader = values[kShaderIndex];
87  if (!Dart_IsNull(shader)) {
88  Shader* decoded = tonic::DartConverter<Shader*>::FromDart(shader);
89  paint_.setShader(decoded->shader());
90  }
91 
92  Dart_Handle color_filter = values[kColorFilterIndex];
93  if (!Dart_IsNull(color_filter)) {
94  ColorFilter* decoded_color_filter =
96  paint_.setColorFilter(decoded_color_filter->filter());
97  }
98 
99  Dart_Handle image_filter = values[kImageFilterIndex];
100  if (!Dart_IsNull(image_filter)) {
101  ImageFilter* decoded =
103  paint_.setImageFilter(decoded->filter());
104  }
105  }
106 
107  tonic::DartByteData byte_data(paint_data);
108  FML_CHECK(byte_data.length_in_bytes() == kDataByteCount);
109 
110  const uint32_t* uint_data = static_cast<const uint32_t*>(byte_data.data());
111  const float* float_data = static_cast<const float*>(byte_data.data());
112 
113  paint_.setAntiAlias(uint_data[kIsAntiAliasIndex] == 0);
114 
115  uint32_t encoded_color = uint_data[kColorIndex];
116  if (encoded_color) {
117  SkColor color = encoded_color ^ kColorDefault;
118  paint_.setColor(color);
119  }
120 
121  uint32_t encoded_blend_mode = uint_data[kBlendModeIndex];
122  if (encoded_blend_mode) {
123  uint32_t blend_mode = encoded_blend_mode ^ kBlendModeDefault;
124  paint_.setBlendMode(static_cast<SkBlendMode>(blend_mode));
125  }
126 
127  uint32_t style = uint_data[kStyleIndex];
128  if (style) {
129  paint_.setStyle(static_cast<SkPaint::Style>(style));
130  }
131 
132  float stroke_width = float_data[kStrokeWidthIndex];
133  if (stroke_width != 0.0) {
134  paint_.setStrokeWidth(stroke_width);
135  }
136 
137  uint32_t stroke_cap = uint_data[kStrokeCapIndex];
138  if (stroke_cap) {
139  paint_.setStrokeCap(static_cast<SkPaint::Cap>(stroke_cap));
140  }
141 
142  uint32_t stroke_join = uint_data[kStrokeJoinIndex];
143  if (stroke_join) {
144  paint_.setStrokeJoin(static_cast<SkPaint::Join>(stroke_join));
145  }
146 
147  float stroke_miter_limit = float_data[kStrokeMiterLimitIndex];
148  if (stroke_miter_limit != 0.0) {
149  paint_.setStrokeMiter(stroke_miter_limit + kStrokeMiterLimitDefault);
150  }
151 
152  uint32_t filter_quality = uint_data[kFilterQualityIndex];
153  if (filter_quality) {
154  paint_.setFilterQuality(static_cast<SkFilterQuality>(filter_quality));
155  }
156 
157  if (uint_data[kInvertColorIndex]) {
158  sk_sp<SkColorFilter> invert_filter =
160  sk_sp<SkColorFilter> current_filter = paint_.refColorFilter();
161  if (current_filter) {
162  invert_filter = invert_filter->makeComposed(current_filter);
163  }
164  paint_.setColorFilter(invert_filter);
165  }
166 
167  if (uint_data[kDitherIndex]) {
168  paint_.setDither(true);
169  }
170 
171  switch (uint_data[kMaskFilterIndex]) {
172  case Null:
173  break;
174  case Blur:
175  SkBlurStyle blur_style =
176  static_cast<SkBlurStyle>(uint_data[kMaskFilterBlurStyleIndex]);
177  double sigma = float_data[kMaskFilterSigmaIndex];
178  paint_.setMaskFilter(SkMaskFilter::MakeBlur(blur_style, sigma));
179  break;
180  }
181 }
constexpr uint32_t kColorDefault
Definition: paint.cc:45
constexpr int kImageFilterIndex
Definition: paint.cc:41
constexpr int kStrokeJoinIndex
Definition: paint.cc:28
constexpr int kFilterQualityIndex
Definition: paint.cc:30
constexpr size_t kDataByteCount
Definition: paint.cc:36
constexpr int kIsAntiAliasIndex
Definition: paint.cc:22
constexpr int kColorFilterIndex
Definition: paint.cc:40
#define FML_DCHECK(condition)
Definition: logging.h:86
constexpr int kShaderIndex
Definition: paint.cc:39
constexpr int kStyleIndex
Definition: paint.cc:25
constexpr float invert_colors[20]
Definition: paint.cc:57
constexpr int kMaskFilterBlurStyleIndex
Definition: paint.cc:32
constexpr uint32_t kBlendModeDefault
Definition: paint.cc:48
constexpr double kStrokeMiterLimitDefault
Definition: paint.cc:53
size_t length
constexpr int kBlendModeIndex
Definition: paint.cc:24
constexpr int kMaskFilterSigmaIndex
Definition: paint.cc:33
constexpr int kDitherIndex
Definition: paint.cc:35
constexpr int kMaskFilterIndex
Definition: paint.cc:31
constexpr int kColorIndex
Definition: paint.cc:23
static sk_sp< SkColorFilter > MakeColorMatrixFilter255(const float array[20])
Definition: color_filter.cc:47
#define FML_CHECK(condition)
Definition: logging.h:68
constexpr int kObjectCount
Definition: paint.cc:42
constexpr int kStrokeCapIndex
Definition: paint.cc:27
constexpr int kStrokeMiterLimitIndex
Definition: paint.cc:29
constexpr int kInvertColorIndex
Definition: paint.cc:34
constexpr int kStrokeWidthIndex
Definition: paint.cc:26

Member Function Documentation

◆ paint()

Friends And Related Function Documentation

◆ tonic::DartConverter< Paint >

friend struct tonic::DartConverter< Paint >
friend

Definition at line 21 of file paint.h.


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