Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit a2bf805

Browse files
authored
Add antiAlias and saveCount to clipPath and restore (#5638)
This would enable us to solve flutter/flutter#18057
1 parent 9e450d1 commit a2bf805

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

lib/ui/painting.dart

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2886,6 +2886,15 @@ class Canvas extends NativeFieldWrapperClass2 {
28862886
/// cause the new layer to be composited into the previous layer.
28872887
void restore() native 'Canvas_restore';
28882888

2889+
/// Restore the current save stack to the state where [saveCount] is gotten.
2890+
///
2891+
/// Use [save] and [saveLayer] to push state onto the stack, and use
2892+
/// [getSaveCount] to get the [saveCount].
2893+
///
2894+
/// If a state was pushed with with [saveLayer], then this call will also
2895+
/// cause the new layer to be composited into the previous layer.
2896+
void restoreToCount(int saveCount) native 'Canvas_restoreToCount';
2897+
28892898
/// Returns the number of items on the save stack, including the
28902899
/// initial state. This means it returns 1 for a clean canvas, and
28912900
/// that each call to [save] and [saveLayer] increments it, and that
@@ -2956,11 +2965,11 @@ class Canvas extends NativeFieldWrapperClass2 {
29562965
/// multiple draw commands intersect with the clip boundary, this can result
29572966
/// in incorrect blending at the clip boundary. See [saveLayer] for a
29582967
/// discussion of how to address that and some examples of using [clipRRect].
2959-
void clipRRect(RRect rrect) {
2968+
void clipRRect(RRect rrect, [bool doAntiAlias = true]) {
29602969
assert(_rrectIsValid(rrect));
2961-
_clipRRect(rrect._value);
2970+
_clipRRect(rrect._value, doAntiAlias);
29622971
}
2963-
void _clipRRect(Float32List rrect) native 'Canvas_clipRRect';
2972+
void _clipRRect(Float32List rrect, bool doAntiAlias) native 'Canvas_clipRRect';
29642973

29652974
/// Reduces the clip region to the intersection of the current clip and the
29662975
/// given [Path].
@@ -2969,11 +2978,11 @@ class Canvas extends NativeFieldWrapperClass2 {
29692978
/// multiple draw commands intersect with the clip boundary, this can result
29702979
/// in incorrect blending at the clip boundary. See [saveLayer] for a
29712980
/// discussion of how to address that.
2972-
void clipPath(Path path) {
2981+
void clipPath(Path path, [bool doAntiAlias = true]) {
29732982
assert(path != null); // path is checked on the engine side
2974-
_clipPath(path);
2983+
_clipPath(path, doAntiAlias);
29752984
}
2976-
void _clipPath(Path path) native 'Canvas_clipPath';
2985+
void _clipPath(Path path, bool doAntiAlias) native 'Canvas_clipPath';
29772986

29782987
/// Paints the given [Color] onto the canvas, applying the given
29792988
/// [BlendMode], with the given color being the source and the background

lib/ui/painting/canvas.cc

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ IMPLEMENT_WRAPPERTYPEINFO(ui, Canvas);
3535
V(Canvas, saveLayerWithoutBounds) \
3636
V(Canvas, saveLayer) \
3737
V(Canvas, restore) \
38+
V(Canvas, restoreToCount) \
3839
V(Canvas, getSaveCount) \
3940
V(Canvas, translate) \
4041
V(Canvas, scale) \
@@ -120,6 +121,12 @@ void Canvas::restore() {
120121
canvas_->restore();
121122
}
122123

124+
void Canvas::restoreToCount(int saveCount) {
125+
if (!canvas_)
126+
return;
127+
canvas_->restoreToCount(saveCount);
128+
}
129+
123130
int Canvas::getSaveCount() {
124131
if (!canvas_)
125132
return 0;
@@ -166,19 +173,19 @@ void Canvas::clipRect(double left,
166173
canvas_->clipRect(SkRect::MakeLTRB(left, top, right, bottom), clipOp, true);
167174
}
168175

169-
void Canvas::clipRRect(const RRect& rrect) {
176+
void Canvas::clipRRect(const RRect& rrect, bool doAntiAlias) {
170177
if (!canvas_)
171178
return;
172-
canvas_->clipRRect(rrect.sk_rrect, true);
179+
canvas_->clipRRect(rrect.sk_rrect, doAntiAlias);
173180
}
174181

175-
void Canvas::clipPath(const CanvasPath* path) {
182+
void Canvas::clipPath(const CanvasPath* path, bool doAntiAlias) {
176183
if (!canvas_)
177184
return;
178185
if (!path)
179186
Dart_ThrowException(
180187
ToDart("Canvas.clipPath called with non-genuine Path."));
181-
canvas_->clipPath(path->path(), true);
188+
canvas_->clipPath(path->path(), doAntiAlias);
182189
}
183190

184191
void Canvas::drawColor(SkColor color, SkBlendMode blend_mode) {

lib/ui/painting/canvas.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class Canvas : public fxl::RefCountedThreadSafe<Canvas>,
4848
const Paint& paint,
4949
const PaintData& paint_data);
5050
void restore();
51+
void restoreToCount(int saveCount);
5152
int getSaveCount();
5253

5354
void translate(double dx, double dy);
@@ -61,8 +62,8 @@ class Canvas : public fxl::RefCountedThreadSafe<Canvas>,
6162
double right,
6263
double bottom,
6364
SkClipOp clipOp);
64-
void clipRRect(const RRect& rrect);
65-
void clipPath(const CanvasPath* path);
65+
void clipRRect(const RRect& rrect, bool doAntiAlias = true);
66+
void clipPath(const CanvasPath* path, bool doAntiAlias = true);
6667

6768
void drawColor(SkColor color, SkBlendMode blend_mode);
6869
void drawLine(double x1,

0 commit comments

Comments
 (0)