From ac99851ce8f37d7a3bcbc41324a74113958ecc64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Drago=C8=99=20Tiselice?= Date: Mon, 12 Sep 2016 13:41:01 -0700 Subject: [PATCH] Added drawArc to Canvas. (flutter/engine#2995) * Added drawArc to Canvas. Added a way to call SkCanvas::drawArc from Dart. This method is optimized for the arc case and should be faster that drawing paths. * Removed implementation details from docs. * Added more details to the docs. --- engine/src/flutter/lib/ui/painting.dart | 24 ++++++++++++++++++++ engine/src/flutter/lib/ui/painting/canvas.cc | 19 ++++++++++++++++ engine/src/flutter/lib/ui/painting/canvas.h | 9 ++++++++ 3 files changed, 52 insertions(+) diff --git a/engine/src/flutter/lib/ui/painting.dart b/engine/src/flutter/lib/ui/painting.dart index 6c93143051..c4377709de 100644 --- a/engine/src/flutter/lib/ui/painting.dart +++ b/engine/src/flutter/lib/ui/painting.dart @@ -1297,6 +1297,30 @@ class Canvas extends NativeFieldWrapperClass2 { List paintObjects, ByteData paintData) native "Canvas_drawCircle"; + /// Draw an arc scaled to fit inside the given rectangle. It starts from + /// startAngle radians around the oval up to startAngle + sweepAngle + /// radians around the oval, with zero radians being the point on + /// the right hand side of the oval that crosses the horizontal line + /// that intersects the center of the rectangle and with positive + /// angles going clockwise around the oval. If useCenter is true, the arc is + /// closed back to the center, forming a circle sector. Otherwise, the arc is + /// not closed, forming a circle segment. + /// + /// This method is optimized for drawing arcs and should be faster than [Path.arcTo]. + void drawArc(Rect rect, double startAngle, double sweepAngle, bool useCenter, Paint paint) { + _drawArc(rect.left, rect.top, rect.right, rect.bottom, startAngle, + sweepAngle, useCenter, paint._objects, paint._data); + } + void _drawArc(double left, + double top, + double right, + double bottom, + double startAngle, + double sweepAngle, + bool useCenter, + List paintObjects, + ByteData paintData) native "Canvas_drawArc"; + /// Draws the given [Path] with the given [Paint]. Whether this shape is /// filled or stroked (or both) is controlled by [Paint.style]. If the path is /// filled, then subpaths within it are implicitly closed (see [Path.close]). diff --git a/engine/src/flutter/lib/ui/painting/canvas.cc b/engine/src/flutter/lib/ui/painting/canvas.cc index ecbcffc2a0..7b9fdff3f9 100644 --- a/engine/src/flutter/lib/ui/painting/canvas.cc +++ b/engine/src/flutter/lib/ui/painting/canvas.cc @@ -46,6 +46,7 @@ IMPLEMENT_WRAPPERTYPEINFO(ui, Canvas); V(Canvas, drawDRRect) \ V(Canvas, drawOval) \ V(Canvas, drawCircle) \ + V(Canvas, drawArc) \ V(Canvas, drawPath) \ V(Canvas, drawImage) \ V(Canvas, drawImageRect) \ @@ -242,6 +243,24 @@ void Canvas::drawCircle(double x, canvas_->drawCircle(x, y, radius, *paint.paint()); } +void Canvas::drawArc(double left, + double top, + double right, + double bottom, + double startAngle, + double sweepAngle, + bool useCenter, + const Paint& paint, + const PaintData& paint_data) { + if (!canvas_) + return; + canvas_->drawArc(SkRect::MakeLTRB(left, top, right, bottom), + startAngle * 180.0 / M_PI, + sweepAngle* 180.0 / M_PI, + useCenter, + *paint.paint()); +} + void Canvas::drawPath(const CanvasPath* path, const Paint& paint, const PaintData& paint_data) { diff --git a/engine/src/flutter/lib/ui/painting/canvas.h b/engine/src/flutter/lib/ui/painting/canvas.h index 95b22f11fd..e9972dc3da 100644 --- a/engine/src/flutter/lib/ui/painting/canvas.h +++ b/engine/src/flutter/lib/ui/painting/canvas.h @@ -100,6 +100,15 @@ class Canvas : public ftl::RefCountedThreadSafe, 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);