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

Commit 7c78879

Browse files
committed
Add flush to canvas
This is required for a high-priority Google client. I've tested it locally and the ShaderWarmUp can now generate multiple shaders in one frame that were not possible before. The engine roll with this PR needs a manual fix on `_MulticastCanvas`
1 parent acfc831 commit 7c78879

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

lib/ui/painting.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3191,6 +3191,14 @@ class Canvas extends NativeFieldWrapperClass2 {
31913191
/// This number cannot go below 1.
31923192
int getSaveCount() native 'Canvas_getSaveCount';
31933193

3194+
/// Flush the operations on this canvas so far.
3195+
///
3196+
/// This prevents Skia's GPU backend to group the operations across the flush
3197+
/// boundary. It's useful for [ShaderWarmUp] to force Skia's GPU backend to
3198+
/// warm up different shaders that may otherwise be combined by grouping the
3199+
/// operations together.
3200+
void flush() native 'Canvas_flush';
3201+
31943202
/// Add a translation to the current transform, shifting the coordinate space
31953203
/// horizontally by the first argument and vertically by the second argument.
31963204
void translate(double dx, double dy) native 'Canvas_translate';

lib/ui/painting/canvas.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ IMPLEMENT_WRAPPERTYPEINFO(ui, Canvas);
3636
V(Canvas, saveLayer) \
3737
V(Canvas, restore) \
3838
V(Canvas, getSaveCount) \
39+
V(Canvas, flush) \
3940
V(Canvas, translate) \
4041
V(Canvas, scale) \
4142
V(Canvas, rotate) \
@@ -126,6 +127,12 @@ int Canvas::getSaveCount() {
126127
return canvas_->getSaveCount();
127128
}
128129

130+
void Canvas::flush() {
131+
if (!canvas_)
132+
return;
133+
canvas_->flush();
134+
}
135+
129136
void Canvas::translate(double dx, double dy) {
130137
if (!canvas_)
131138
return;

lib/ui/painting/canvas.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ class Canvas : public RefCountedDartWrappable<Canvas> {
4949
void restore();
5050
int getSaveCount();
5151

52+
void flush();
53+
5254
void translate(double dx, double dy);
5355
void scale(double sx, double sy);
5456
void rotate(double radians);

0 commit comments

Comments
 (0)