From dfa02e5881f31bd75736d3b7bc2a21dc954d5c84 Mon Sep 17 00:00:00 2001 From: liyuqian Date: Fri, 29 Jun 2018 16:24:12 -0700 Subject: [PATCH] Add antiAlias and saveCount to clipPath and restore (flutter/engine#5638) This would enable us to solve https://github.com/flutter/flutter/issues/18057 --- engine/src/flutter/lib/ui/painting.dart | 21 ++++++++++++++------ engine/src/flutter/lib/ui/painting/canvas.cc | 15 ++++++++++---- engine/src/flutter/lib/ui/painting/canvas.h | 5 +++-- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/engine/src/flutter/lib/ui/painting.dart b/engine/src/flutter/lib/ui/painting.dart index 6adb1902b3..36db2ac2d6 100644 --- a/engine/src/flutter/lib/ui/painting.dart +++ b/engine/src/flutter/lib/ui/painting.dart @@ -2886,6 +2886,15 @@ class Canvas extends NativeFieldWrapperClass2 { /// cause the new layer to be composited into the previous layer. void restore() native 'Canvas_restore'; + /// Restore the current save stack to the state where [saveCount] is gotten. + /// + /// Use [save] and [saveLayer] to push state onto the stack, and use + /// [getSaveCount] to get the [saveCount]. + /// + /// If a state was pushed with with [saveLayer], then this call will also + /// cause the new layer to be composited into the previous layer. + void restoreToCount(int saveCount) native 'Canvas_restoreToCount'; + /// Returns the number of items on the save stack, including the /// initial state. This means it returns 1 for a clean canvas, and /// that each call to [save] and [saveLayer] increments it, and that @@ -2956,11 +2965,11 @@ class Canvas extends NativeFieldWrapperClass2 { /// multiple draw commands intersect with the clip boundary, this can result /// in incorrect blending at the clip boundary. See [saveLayer] for a /// discussion of how to address that and some examples of using [clipRRect]. - void clipRRect(RRect rrect) { + void clipRRect(RRect rrect, [bool doAntiAlias = true]) { assert(_rrectIsValid(rrect)); - _clipRRect(rrect._value); + _clipRRect(rrect._value, doAntiAlias); } - void _clipRRect(Float32List rrect) native 'Canvas_clipRRect'; + void _clipRRect(Float32List rrect, bool doAntiAlias) native 'Canvas_clipRRect'; /// Reduces the clip region to the intersection of the current clip and the /// given [Path]. @@ -2969,11 +2978,11 @@ class Canvas extends NativeFieldWrapperClass2 { /// multiple draw commands intersect with the clip boundary, this can result /// in incorrect blending at the clip boundary. See [saveLayer] for a /// discussion of how to address that. - void clipPath(Path path) { + void clipPath(Path path, [bool doAntiAlias = true]) { assert(path != null); // path is checked on the engine side - _clipPath(path); + _clipPath(path, doAntiAlias); } - void _clipPath(Path path) native 'Canvas_clipPath'; + void _clipPath(Path path, bool doAntiAlias) native 'Canvas_clipPath'; /// Paints the given [Color] onto the canvas, applying the given /// [BlendMode], with the given color being the source and the background diff --git a/engine/src/flutter/lib/ui/painting/canvas.cc b/engine/src/flutter/lib/ui/painting/canvas.cc index 7bfeb5cfdd..23b8053a9e 100644 --- a/engine/src/flutter/lib/ui/painting/canvas.cc +++ b/engine/src/flutter/lib/ui/painting/canvas.cc @@ -35,6 +35,7 @@ IMPLEMENT_WRAPPERTYPEINFO(ui, Canvas); V(Canvas, saveLayerWithoutBounds) \ V(Canvas, saveLayer) \ V(Canvas, restore) \ + V(Canvas, restoreToCount) \ V(Canvas, getSaveCount) \ V(Canvas, translate) \ V(Canvas, scale) \ @@ -120,6 +121,12 @@ void Canvas::restore() { canvas_->restore(); } +void Canvas::restoreToCount(int saveCount) { + if (!canvas_) + return; + canvas_->restoreToCount(saveCount); +} + int Canvas::getSaveCount() { if (!canvas_) return 0; @@ -166,19 +173,19 @@ void Canvas::clipRect(double left, canvas_->clipRect(SkRect::MakeLTRB(left, top, right, bottom), clipOp, true); } -void Canvas::clipRRect(const RRect& rrect) { +void Canvas::clipRRect(const RRect& rrect, bool doAntiAlias) { if (!canvas_) return; - canvas_->clipRRect(rrect.sk_rrect, true); + canvas_->clipRRect(rrect.sk_rrect, doAntiAlias); } -void Canvas::clipPath(const CanvasPath* path) { +void Canvas::clipPath(const CanvasPath* path, bool doAntiAlias) { if (!canvas_) return; if (!path) Dart_ThrowException( ToDart("Canvas.clipPath called with non-genuine Path.")); - canvas_->clipPath(path->path(), true); + canvas_->clipPath(path->path(), doAntiAlias); } void Canvas::drawColor(SkColor color, SkBlendMode blend_mode) { diff --git a/engine/src/flutter/lib/ui/painting/canvas.h b/engine/src/flutter/lib/ui/painting/canvas.h index 03dfe618f4..e8ce866e99 100644 --- a/engine/src/flutter/lib/ui/painting/canvas.h +++ b/engine/src/flutter/lib/ui/painting/canvas.h @@ -48,6 +48,7 @@ class Canvas : public fxl::RefCountedThreadSafe, const Paint& paint, const PaintData& paint_data); void restore(); + void restoreToCount(int saveCount); int getSaveCount(); void translate(double dx, double dy); @@ -61,8 +62,8 @@ class Canvas : public fxl::RefCountedThreadSafe, double right, double bottom, SkClipOp clipOp); - void clipRRect(const RRect& rrect); - void clipPath(const CanvasPath* path); + 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,