Flutter Engine
flutter::Canvas Class Reference

#include <canvas.h>

Inheritance diagram for flutter::Canvas:
flutter::RefCountedDartWrappable< Canvas > fml::RefCountedThreadSafe< Canvas > tonic::DartWrappable fml::internal::RefCountedThreadSafeBase

Public Member Functions

 ~Canvas () override
 
void save ()
 
void saveLayerWithoutBounds (const Paint &paint, const PaintData &paint_data)
 
void saveLayer (double left, double top, double right, double bottom, const Paint &paint, const PaintData &paint_data)
 
void restore ()
 
int getSaveCount ()
 
void translate (double dx, double dy)
 
void scale (double sx, double sy)
 
void rotate (double radians)
 
void skew (double sx, double sy)
 
void transform (const tonic::Float64List &matrix4)
 
void clipRect (double left, double top, double right, double bottom, SkClipOp clipOp, bool doAntiAlias=true)
 
void clipRRect (const RRect &rrect, bool doAntiAlias=true)
 
void clipPath (const CanvasPath *path, bool doAntiAlias=true)
 
void drawColor (SkColor color, SkBlendMode blend_mode)
 
void drawLine (double x1, double y1, double x2, double y2, const Paint &paint, const PaintData &paint_data)
 
void drawPaint (const Paint &paint, const PaintData &paint_data)
 
void drawRect (double left, double top, double right, double bottom, const Paint &paint, const PaintData &paint_data)
 
void drawRRect (const RRect &rrect, const Paint &paint, const PaintData &paint_data)
 
void drawDRRect (const RRect &outer, const RRect &inner, const Paint &paint, const PaintData &paint_data)
 
void drawOval (double left, double top, double right, double bottom, const Paint &paint, const PaintData &paint_data)
 
void drawCircle (double x, double y, double radius, const Paint &paint, const PaintData &paint_data)
 
void drawArc (double left, double top, double right, double bottom, double startAngle, double sweepAngle, bool useCenter, const Paint &paint, const PaintData &paint_data)
 
void drawPath (const CanvasPath *path, const Paint &paint, const PaintData &paint_data)
 
void drawImage (const CanvasImage *image, double x, double y, const Paint &paint, const PaintData &paint_data)
 
void drawImageRect (const CanvasImage *image, double src_left, double src_top, double src_right, double src_bottom, double dst_left, double dst_top, double dst_right, double dst_bottom, const Paint &paint, const PaintData &paint_data)
 
void drawImageNine (const CanvasImage *image, double center_left, double center_top, double center_right, double center_bottom, double dst_left, double dst_top, double dst_right, double dst_bottom, const Paint &paint, const PaintData &paint_data)
 
void drawPicture (Picture *picture)
 
void drawPoints (const Paint &paint, const PaintData &paint_data, SkCanvas::PointMode point_mode, const tonic::Float32List &points)
 
void drawVertices (const Vertices *vertices, SkBlendMode blend_mode, const Paint &paint, const PaintData &paint_data)
 
void drawAtlas (const Paint &paint, const PaintData &paint_data, CanvasImage *atlas, const tonic::Float32List &transforms, const tonic::Float32List &rects, const tonic::Int32List &colors, SkBlendMode blend_mode, const tonic::Float32List &cull_rect)
 
void drawShadow (const CanvasPath *path, SkColor color, double elevation, bool transparentOccluder)
 
SkCanvas * canvas () const
 
void Invalidate ()
 
- Public Member Functions inherited from flutter::RefCountedDartWrappable< Canvas >
virtual void RetainDartWrappableReference () const override
 
virtual void ReleaseDartWrappableReference () const override
 
- Public Member Functions inherited from fml::RefCountedThreadSafe< Canvas >
void Release () const
 
- Public Member Functions inherited from fml::internal::RefCountedThreadSafeBase
void AddRef () const
 
bool HasOneRef () const
 
void AssertHasOneRef () const
 
- Public Member Functions inherited from tonic::DartWrappable
 DartWrappable ()
 
virtual const DartWrapperInfoGetDartWrapperInfo () const =0
 
virtual size_t GetAllocationSize () const
 
Dart_Handle CreateDartWrapper (DartState *dart_state)
 
void AssociateWithDartWrapper (Dart_Handle wrappable)
 
void ClearDartWrapper ()
 
Dart_WeakPersistentHandle dart_wrapper () const
 

Static Public Member Functions

static fml::RefPtr< CanvasCreate (PictureRecorder *recorder, double left, double top, double right, double bottom)
 
static void RegisterNatives (tonic::DartLibraryNatives *natives)
 

Additional Inherited Members

- Public Types inherited from tonic::DartWrappable
enum  DartNativeFields {
  kPeerIndex,
  kWrapperInfoIndex,
  kNumberOfNativeFields
}
 
- Protected Member Functions inherited from fml::RefCountedThreadSafe< Canvas >
 RefCountedThreadSafe ()
 
 ~RefCountedThreadSafe ()
 
- Protected Member Functions inherited from fml::internal::RefCountedThreadSafeBase
 RefCountedThreadSafeBase ()
 
 ~RefCountedThreadSafeBase ()
 
bool Release () const
 
void Adopt ()
 
- Protected Member Functions inherited from tonic::DartWrappable
virtual ~DartWrappable ()
 
- Static Protected Member Functions inherited from tonic::DartWrappable
static Dart_PersistentHandle GetTypeForWrapper (tonic::DartState *dart_state, const tonic::DartWrapperInfo &wrapper_info)
 

Detailed Description

Definition at line 26 of file canvas.h.

Constructor & Destructor Documentation

◆ ~Canvas()

flutter::Canvas::~Canvas ( )
override

Definition at line 92 of file canvas.cc.

92 {}

Member Function Documentation

◆ canvas()

SkCanvas* flutter::Canvas::canvas ( ) const
inline

Definition at line 167 of file canvas.h.

Referenced by Create(), and flutter::Paragraph::paint().

167 { return canvas_; }

◆ clipPath()

void flutter::Canvas::clipPath ( const CanvasPath path,
bool  doAntiAlias = true 
)

Definition at line 191 of file canvas.cc.

References flutter::CanvasPath::path(), and tonic::ToDart().

191  {
192  if (!canvas_) {
193  return;
194  }
195  if (!path) {
196  Dart_ThrowException(
197  ToDart("Canvas.clipPath called with non-genuine Path."));
198  return;
199  }
200  canvas_->clipPath(path->path(), doAntiAlias);
201 }
DEF_SWITCHES_START snapshot asset path
Definition: switches.h:32
Dart_Handle ToDart(const T &object)

◆ clipRect()

void flutter::Canvas::clipRect ( double  left,
double  top,
double  right,
double  bottom,
SkClipOp  clipOp,
bool  doAntiAlias = true 
)

Definition at line 171 of file canvas.cc.

176  {
177  if (!canvas_) {
178  return;
179  }
180  canvas_->clipRect(SkRect::MakeLTRB(left, top, right, bottom), clipOp,
181  doAntiAlias);
182 }

◆ clipRRect()

void flutter::Canvas::clipRRect ( const RRect rrect,
bool  doAntiAlias = true 
)

Definition at line 184 of file canvas.cc.

References flutter::RRect::sk_rrect.

184  {
185  if (!canvas_) {
186  return;
187  }
188  canvas_->clipRRect(rrect.sk_rrect, doAntiAlias);
189 }

◆ Create()

fml::RefPtr< Canvas > flutter::Canvas::Create ( PictureRecorder recorder,
double  left,
double  top,
double  right,
double  bottom 
)
static

Definition at line 74 of file canvas.cc.

References flutter::PictureRecorder::BeginRecording(), canvas(), flutter::PictureRecorder::set_canvas(), and tonic::ToDart().

Referenced by flutter::Canvas_constructor().

78  {
79  if (!recorder) {
80  Dart_ThrowException(
81  ToDart("Canvas constructor called with non-genuine PictureRecorder."));
82  return nullptr;
83  }
84  fml::RefPtr<Canvas> canvas = fml::MakeRefCounted<Canvas>(
85  recorder->BeginRecording(SkRect::MakeLTRB(left, top, right, bottom)));
86  recorder->set_canvas(canvas);
87  return canvas;
88 }
SkCanvas * canvas() const
Definition: canvas.h:167
Dart_Handle ToDart(const T &object)

◆ drawArc()

void flutter::Canvas::drawArc ( double  left,
double  top,
double  right,
double  bottom,
double  startAngle,
double  sweepAngle,
bool  useCenter,
const Paint paint,
const PaintData paint_data 
)

Definition at line 283 of file canvas.cc.

References flutter::Paint::paint().

291  {
292  if (!canvas_) {
293  return;
294  }
295  canvas_->drawArc(SkRect::MakeLTRB(left, top, right, bottom),
296  startAngle * 180.0 / M_PI, sweepAngle * 180.0 / M_PI,
297  useCenter, *paint.paint());
298 }

◆ drawAtlas()

void flutter::Canvas::drawAtlas ( const Paint paint,
const PaintData paint_data,
CanvasImage atlas,
const tonic::Float32List &  transforms,
const tonic::Float32List &  rects,
const tonic::Int32List &  colors,
SkBlendMode  blend_mode,
const tonic::Float32List &  cull_rect 
)

Definition at line 426 of file canvas.cc.

References flutter::CanvasImage::image(), flutter::Paint::paint(), and tonic::ToDart().

433  {
434  if (!canvas_) {
435  return;
436  }
437  if (!atlas) {
438  Dart_ThrowException(
439  ToDart("Canvas.drawAtlas or Canvas.drawRawAtlas called with "
440  "non-genuine Image."));
441  return;
442  }
443 
444  sk_sp<SkImage> skImage = atlas->image();
445 
446  static_assert(sizeof(SkRSXform) == sizeof(float) * 4,
447  "SkRSXform doesn't use floats.");
448  static_assert(sizeof(SkRect) == sizeof(float) * 4,
449  "SkRect doesn't use floats.");
450 
451  canvas_->drawAtlas(
452  skImage.get(), reinterpret_cast<const SkRSXform*>(transforms.data()),
453  reinterpret_cast<const SkRect*>(rects.data()),
454  reinterpret_cast<const SkColor*>(colors.data()),
455  rects.num_elements() / 4, // SkRect have four floats.
456  blend_mode, reinterpret_cast<const SkRect*>(cull_rect.data()),
457  paint.paint());
458 }
Dart_Handle ToDart(const T &object)

◆ drawCircle()

void flutter::Canvas::drawCircle ( double  x,
double  y,
double  radius,
const Paint paint,
const PaintData paint_data 
)

Definition at line 272 of file canvas.cc.

References flutter::Paint::paint().

276  {
277  if (!canvas_) {
278  return;
279  }
280  canvas_->drawCircle(x, y, radius, *paint.paint());
281 }

◆ drawColor()

void flutter::Canvas::drawColor ( SkColor  color,
SkBlendMode  blend_mode 
)

Definition at line 203 of file canvas.cc.

203  {
204  if (!canvas_) {
205  return;
206  }
207  canvas_->drawColor(color, blend_mode);
208 }

◆ drawDRRect()

void flutter::Canvas::drawDRRect ( const RRect outer,
const RRect inner,
const Paint paint,
const PaintData paint_data 
)

Definition at line 250 of file canvas.cc.

References flutter::Paint::paint(), and flutter::RRect::sk_rrect.

253  {
254  if (!canvas_) {
255  return;
256  }
257  canvas_->drawDRRect(outer.sk_rrect, inner.sk_rrect, *paint.paint());
258 }

◆ drawImage()

void flutter::Canvas::drawImage ( const CanvasImage image,
double  x,
double  y,
const Paint paint,
const PaintData paint_data 
)

Definition at line 314 of file canvas.cc.

References flutter::CanvasImage::image(), flutter::Paint::paint(), and tonic::ToDart().

318  {
319  if (!canvas_) {
320  return;
321  }
322  if (!image) {
323  Dart_ThrowException(
324  ToDart("Canvas.drawImage called with non-genuine Image."));
325  return;
326  }
327  canvas_->drawImage(image->image(), x, y, paint.paint());
328 }
Dart_Handle ToDart(const T &object)

◆ drawImageNine()

void flutter::Canvas::drawImageNine ( const CanvasImage image,
double  center_left,
double  center_top,
double  center_right,
double  center_bottom,
double  dst_left,
double  dst_top,
double  dst_right,
double  dst_bottom,
const Paint paint,
const PaintData paint_data 
)

Definition at line 355 of file canvas.cc.

References flutter::CanvasImage::image(), flutter::Paint::paint(), and tonic::ToDart().

365  {
366  if (!canvas_) {
367  return;
368  }
369  if (!image) {
370  Dart_ThrowException(
371  ToDart("Canvas.drawImageNine called with non-genuine Image."));
372  return;
373  }
374  SkRect center =
375  SkRect::MakeLTRB(center_left, center_top, center_right, center_bottom);
376  SkIRect icenter;
377  center.round(&icenter);
378  SkRect dst = SkRect::MakeLTRB(dst_left, dst_top, dst_right, dst_bottom);
379  canvas_->drawImageNine(image->image(), icenter, dst, paint.paint());
380 }
Dart_Handle ToDart(const T &object)

◆ drawImageRect()

void flutter::Canvas::drawImageRect ( const CanvasImage image,
double  src_left,
double  src_top,
double  src_right,
double  src_bottom,
double  dst_left,
double  dst_top,
double  dst_right,
double  dst_bottom,
const Paint paint,
const PaintData paint_data 
)

Definition at line 330 of file canvas.cc.

References flutter::CanvasImage::image(), flutter::Paint::paint(), and tonic::ToDart().

340  {
341  if (!canvas_) {
342  return;
343  }
344  if (!image) {
345  Dart_ThrowException(
346  ToDart("Canvas.drawImageRect called with non-genuine Image."));
347  return;
348  }
349  SkRect src = SkRect::MakeLTRB(src_left, src_top, src_right, src_bottom);
350  SkRect dst = SkRect::MakeLTRB(dst_left, dst_top, dst_right, dst_bottom);
351  canvas_->drawImageRect(image->image(), src, dst, paint.paint(),
352  SkCanvas::kFast_SrcRectConstraint);
353 }
Dart_Handle ToDart(const T &object)

◆ drawLine()

void flutter::Canvas::drawLine ( double  x1,
double  y1,
double  x2,
double  y2,
const Paint paint,
const PaintData paint_data 
)

Definition at line 210 of file canvas.cc.

References flutter::Paint::paint().

215  {
216  if (!canvas_) {
217  return;
218  }
219  canvas_->drawLine(x1, y1, x2, y2, *paint.paint());
220 }

◆ drawOval()

void flutter::Canvas::drawOval ( double  left,
double  top,
double  right,
double  bottom,
const Paint paint,
const PaintData paint_data 
)

Definition at line 260 of file canvas.cc.

References flutter::Paint::paint().

265  {
266  if (!canvas_) {
267  return;
268  }
269  canvas_->drawOval(SkRect::MakeLTRB(left, top, right, bottom), *paint.paint());
270 }

◆ drawPaint()

void flutter::Canvas::drawPaint ( const Paint paint,
const PaintData paint_data 
)

Definition at line 222 of file canvas.cc.

References flutter::Paint::paint().

222  {
223  if (!canvas_) {
224  return;
225  }
226  canvas_->drawPaint(*paint.paint());
227 }

◆ drawPath()

void flutter::Canvas::drawPath ( const CanvasPath path,
const Paint paint,
const PaintData paint_data 
)

Definition at line 300 of file canvas.cc.

References flutter::Paint::paint(), flutter::CanvasPath::path(), and tonic::ToDart().

302  {
303  if (!canvas_) {
304  return;
305  }
306  if (!path) {
307  Dart_ThrowException(
308  ToDart("Canvas.drawPath called with non-genuine Path."));
309  return;
310  }
311  canvas_->drawPath(path->path(), *paint.paint());
312 }
DEF_SWITCHES_START snapshot asset path
Definition: switches.h:32
Dart_Handle ToDart(const T &object)

◆ drawPicture()

void flutter::Canvas::drawPicture ( Picture picture)

Definition at line 382 of file canvas.cc.

References flutter::Picture::picture(), and tonic::ToDart().

382  {
383  if (!canvas_) {
384  return;
385  }
386  if (!picture) {
387  Dart_ThrowException(
388  ToDart("Canvas.drawPicture called with non-genuine Picture."));
389  return;
390  }
391  canvas_->drawPicture(picture->picture().get());
392 }
Dart_Handle ToDart(const T &object)

◆ drawPoints()

void flutter::Canvas::drawPoints ( const Paint paint,
const PaintData paint_data,
SkCanvas::PointMode  point_mode,
const tonic::Float32List &  points 
)

Definition at line 394 of file canvas.cc.

References flutter::Paint::paint().

397  {
398  if (!canvas_) {
399  return;
400  }
401 
402  static_assert(sizeof(SkPoint) == sizeof(float) * 2,
403  "SkPoint doesn't use floats.");
404 
405  canvas_->drawPoints(point_mode,
406  points.num_elements() / 2, // SkPoints have two floats.
407  reinterpret_cast<const SkPoint*>(points.data()),
408  *paint.paint());
409 }

◆ drawRect()

void flutter::Canvas::drawRect ( double  left,
double  top,
double  right,
double  bottom,
const Paint paint,
const PaintData paint_data 
)

Definition at line 229 of file canvas.cc.

References flutter::Paint::paint().

234  {
235  if (!canvas_) {
236  return;
237  }
238  canvas_->drawRect(SkRect::MakeLTRB(left, top, right, bottom), *paint.paint());
239 }

◆ drawRRect()

void flutter::Canvas::drawRRect ( const RRect rrect,
const Paint paint,
const PaintData paint_data 
)

Definition at line 241 of file canvas.cc.

References flutter::Paint::paint(), and flutter::RRect::sk_rrect.

243  {
244  if (!canvas_) {
245  return;
246  }
247  canvas_->drawRRect(rrect.sk_rrect, *paint.paint());
248 }

◆ drawShadow()

void flutter::Canvas::drawShadow ( const CanvasPath path,
SkColor  color,
double  elevation,
bool  transparentOccluder 
)

Definition at line 460 of file canvas.cc.

References flutter::UIDartState::Current(), flutter::ViewportMetrics::device_pixel_ratio, flutter::PhysicalShapeLayer::DrawShadow(), flutter::PlatformConfiguration::get_window(), flutter::CanvasPath::path(), flutter::UIDartState::platform_configuration(), tonic::ToDart(), and flutter::Window::viewport_metrics().

463  {
464  if (!path) {
465  Dart_ThrowException(
466  ToDart("Canvas.drawShader called with non-genuine Path."));
467  return;
468  }
469  SkScalar dpr = UIDartState::Current()
471  ->get_window(0)
472  ->viewport_metrics()
474  flutter::PhysicalShapeLayer::DrawShadow(canvas_, path->path(), color,
475  elevation, transparentOccluder, dpr);
476 }
DEF_SWITCHES_START snapshot asset path
Definition: switches.h:32
PlatformConfiguration * platform_configuration() const
Definition: ui_dart_state.h:48
static void DrawShadow(SkCanvas *canvas, const SkPath &path, SkColor color, float elevation, bool transparentOccluder, SkScalar dpr)
Dart_Handle ToDart(const T &object)
Window * get_window(int window_id)
Retrieves the Window with the given ID managed by the PlatformConfiguration.
const ViewportMetrics & viewport_metrics() const
Definition: window.h:27
static UIDartState * Current()

◆ drawVertices()

void flutter::Canvas::drawVertices ( const Vertices vertices,
SkBlendMode  blend_mode,
const Paint paint,
const PaintData paint_data 
)

Definition at line 411 of file canvas.cc.

References flutter::Paint::paint(), tonic::ToDart(), and flutter::Vertices::vertices().

414  {
415  if (!canvas_) {
416  return;
417  }
418  if (!vertices) {
419  Dart_ThrowException(
420  ToDart("Canvas.drawVertices called with non-genuine Vertices."));
421  return;
422  }
423  canvas_->drawVertices(vertices->vertices(), blend_mode, *paint.paint());
424 }
Dart_Handle ToDart(const T &object)

◆ getSaveCount()

int flutter::Canvas::getSaveCount ( )

Definition at line 129 of file canvas.cc.

129  {
130  if (!canvas_) {
131  return 0;
132  }
133  return canvas_->getSaveCount();
134 }

◆ Invalidate()

void flutter::Canvas::Invalidate ( )

Definition at line 478 of file canvas.cc.

References tonic::DartWrappable::ClearDartWrapper(), and tonic::DartWrappable::dart_wrapper().

478  {
479  canvas_ = nullptr;
480  if (dart_wrapper()) {
482  }
483 }
Dart_WeakPersistentHandle dart_wrapper() const

◆ RegisterNatives()

void flutter::Canvas::RegisterNatives ( tonic::DartLibraryNatives natives)
static

Definition at line 69 of file canvas.cc.

References flutter::Canvas_constructor(), DART_REGISTER_NATIVE, and FOR_EACH_BINDING.

Referenced by flutter::DartUI::InitForGlobal().

69  {
70  natives->Register({{"Canvas_constructor", Canvas_constructor, 6, true},
72 }
#define FOR_EACH_BINDING(V)
Definition: canvas.cc:34
void Register(std::initializer_list< Entry > entries)
static void Canvas_constructor(Dart_NativeArguments args)
Definition: canvas.cc:27
#define DART_REGISTER_NATIVE(CLASS, METHOD)

◆ restore()

void flutter::Canvas::restore ( )

Definition at line 122 of file canvas.cc.

122  {
123  if (!canvas_) {
124  return;
125  }
126  canvas_->restore();
127 }

◆ rotate()

void flutter::Canvas::rotate ( double  radians)

Definition at line 150 of file canvas.cc.

150  {
151  if (!canvas_) {
152  return;
153  }
154  canvas_->rotate(radians * 180.0 / M_PI);
155 }

◆ save()

void flutter::Canvas::save ( )

Definition at line 94 of file canvas.cc.

94  {
95  if (!canvas_) {
96  return;
97  }
98  canvas_->save();
99 }

◆ saveLayer()

void flutter::Canvas::saveLayer ( double  left,
double  top,
double  right,
double  bottom,
const Paint paint,
const PaintData paint_data 
)

Definition at line 109 of file canvas.cc.

References flutter::Paint::paint().

114  {
115  if (!canvas_) {
116  return;
117  }
118  SkRect bounds = SkRect::MakeLTRB(left, top, right, bottom);
119  canvas_->saveLayer(&bounds, paint.paint());
120 }

◆ saveLayerWithoutBounds()

void flutter::Canvas::saveLayerWithoutBounds ( const Paint paint,
const PaintData paint_data 
)

Definition at line 101 of file canvas.cc.

References flutter::Paint::paint().

102  {
103  if (!canvas_) {
104  return;
105  }
106  canvas_->saveLayer(nullptr, paint.paint());
107 }

◆ scale()

void flutter::Canvas::scale ( double  sx,
double  sy 
)

Definition at line 143 of file canvas.cc.

143  {
144  if (!canvas_) {
145  return;
146  }
147  canvas_->scale(sx, sy);
148 }

◆ skew()

void flutter::Canvas::skew ( double  sx,
double  sy 
)

Definition at line 157 of file canvas.cc.

157  {
158  if (!canvas_) {
159  return;
160  }
161  canvas_->skew(sx, sy);
162 }

◆ transform()

void flutter::Canvas::transform ( const tonic::Float64List &  matrix4)

Definition at line 164 of file canvas.cc.

References flutter::ToSkMatrix().

164  {
165  if (!canvas_) {
166  return;
167  }
168  canvas_->concat(ToSkMatrix(matrix4));
169 }
SkMatrix ToSkMatrix(const tonic::Float64List &matrix4)
Definition: matrix.cc:20

◆ translate()

void flutter::Canvas::translate ( double  dx,
double  dy 
)

Definition at line 136 of file canvas.cc.

136  {
137  if (!canvas_) {
138  return;
139  }
140  canvas_->translate(dx, dy);
141 }

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