From 212249cd2b6c4a8adb39b13cdeab3f1082ab38c3 Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Wed, 18 Oct 2017 16:39:19 -0700 Subject: [PATCH] Export the SkClipOp argument in Canvas.clipRect (flutter/engine#4243) --- engine/src/flutter/lib/ui/painting.dart | 23 +++++++++++++++++--- engine/src/flutter/lib/ui/painting/canvas.cc | 9 +++++--- engine/src/flutter/lib/ui/painting/canvas.h | 6 ++++- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/engine/src/flutter/lib/ui/painting.dart b/engine/src/flutter/lib/ui/painting.dart index 95c9fc594f..08b9fc39b4 100644 --- a/engine/src/flutter/lib/ui/painting.dart +++ b/engine/src/flutter/lib/ui/painting.dart @@ -1461,6 +1461,18 @@ enum PointMode { polygon, } +/// Defines how a new clip region should be merged with the existing clip +/// region. +/// +/// Used by [Canvas.clipRect]. +enum ClipOp { + /// Subtract the new region from the existing region. + difference, + + /// Intersect the new region from the existing region. + intersect, +} + /// An interface for recording graphical operations. /// /// [Canvas] objects are used in creating [Picture] objects, which can @@ -1692,14 +1704,19 @@ class Canvas extends NativeFieldWrapperClass2 { /// 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 clipRect(Rect rect) { + /// + /// Use [ClipOp.difference] to subtract the provided rectangle from the + /// current clip. + void clipRect(Rect rect, { ClipOp clipOp: ClipOp.intersect }) { assert(_rectIsValid(rect)); - _clipRect(rect.left, rect.top, rect.right, rect.bottom); + assert(clipOp != null); + _clipRect(rect.left, rect.top, rect.right, rect.bottom, clipOp.index); } void _clipRect(double left, double top, double right, - double bottom) native "Canvas_clipRect"; + double bottom, + int clipOp) native "Canvas_clipRect"; /// Reduces the clip region to the intersection of the current clip and the /// given rounded rectangle. diff --git a/engine/src/flutter/lib/ui/painting/canvas.cc b/engine/src/flutter/lib/ui/painting/canvas.cc index 929e545715..34523f2048 100644 --- a/engine/src/flutter/lib/ui/painting/canvas.cc +++ b/engine/src/flutter/lib/ui/painting/canvas.cc @@ -155,11 +155,14 @@ void Canvas::transform(const tonic::Float64List& matrix4) { canvas_->concat(ToSkMatrix(matrix4)); } -void Canvas::clipRect(double left, double top, double right, double bottom) { +void Canvas::clipRect(double left, + double top, + double right, + double bottom, + SkClipOp clipOp) { if (!canvas_) return; - canvas_->clipRect(SkRect::MakeLTRB(left, top, right, bottom), - SkClipOp::kIntersect, true); + canvas_->clipRect(SkRect::MakeLTRB(left, top, right, bottom), clipOp, true); } void Canvas::clipRRect(const RRect& rrect) { diff --git a/engine/src/flutter/lib/ui/painting/canvas.h b/engine/src/flutter/lib/ui/painting/canvas.h index 1d171467fb..03dfe618f4 100644 --- a/engine/src/flutter/lib/ui/painting/canvas.h +++ b/engine/src/flutter/lib/ui/painting/canvas.h @@ -56,7 +56,11 @@ class Canvas : public fxl::RefCountedThreadSafe, void skew(double sx, double sy); void transform(const tonic::Float64List& matrix4); - void clipRect(double left, double top, double right, double bottom); + void clipRect(double left, + double top, + double right, + double bottom, + SkClipOp clipOp); void clipRRect(const RRect& rrect); void clipPath(const CanvasPath* path);