[web] Fix shadermask rendering using CanvasKit (flutter/engine#25456)

This commit is contained in:
Ferhat
2021-04-06 12:57:29 -07:00
committed by GitHub
parent d4900af074
commit e3c5c74009
3 changed files with 68 additions and 2 deletions

View File

@@ -1,2 +1,2 @@
repository: https://github.com/flutter/goldens.git
revision: 0c09e67a17eecc0c0c936f28d9138c1aa39a5043
revision: 82c1ccb1247f279cfd9f23a3929d13e2f32771ad

View File

@@ -401,7 +401,8 @@ class ShaderMaskEngineLayer extends ContainerLayer implements ui.ShaderMaskEngin
paintContext.leafNodesCanvas!.save();
paintContext.leafNodesCanvas!.translate(maskRect.left, maskRect.top);
paintContext.leafNodesCanvas!.drawRect(maskRect, paint);
paintContext.leafNodesCanvas!.drawRect(
ui.Rect.fromLTWH(0, 0, maskRect.width, maskRect.height), paint);
paintContext.leafNodesCanvas!.restore();
paintContext.internalNodesCanvas.restore();

View File

@@ -93,6 +93,71 @@ void testMain() {
await matchSceneGolden('canvaskit_shadermask_linear.png',
builder.build());
});
/// Regression test for https://github.com/flutter/flutter/issues/78959
test('Renders sweep gradient with color blend translated', () async {
final LayerSceneBuilder builder = LayerSceneBuilder();
builder.pushOffset(0, 0);
// Draw a red circle and apply it to the scene.
final CkPictureRecorder recorder = CkPictureRecorder();
final CkCanvas canvas = recorder.beginRecording(region);
canvas.drawCircle(
ui.Offset(425, 125),
50,
CkPaint()..color = ui.Color.fromARGB(255, 255, 0, 0),
);
final CkPicture redCircle = recorder.endRecording();
builder.addPicture(ui.Offset.zero, redCircle);
final CkGradientSweep shader = CkGradientSweep(
ui.Offset(250, 125),
<ui.Color>[
ui.Color(0xFF4285F4),
ui.Color(0xFF34A853),
ui.Color(0xFFFBBC05),
ui.Color(0xFFEA4335),
ui.Color(0xFF4285F4),
],
<double>[
0.0,
0.25,
0.5,
0.75,
1.0,
],
ui.TileMode.clamp,
-(math.pi / 2),
math.pi * 2 - (math.pi / 2),
null);
final ui.Path clipPath = ui.Path()
..addOval(ui.Rect.fromLTWH(25, 75, 100, 100));
builder.pushClipPath(clipPath);
// Apply a shader mask.
builder.pushShaderMask(shader, ui.Rect.fromLTRB(50, 50, 200, 250),
ui.BlendMode.color);
// Draw another red circle and apply it to the scene.
// This one should be grey since we have the color filter.
final CkPictureRecorder recorder2 = CkPictureRecorder();
final CkCanvas canvas2 = recorder2.beginRecording(region);
canvas2.drawRect(ui.Rect.fromLTWH(25, 75, 100, 100),
CkPaint()..color = ui.Color.fromARGB(255, 0, 255, 0),
);
final CkPicture sweepCircle = recorder2.endRecording();
builder.addPicture(ui.Offset.zero, sweepCircle);
await matchSceneGolden('canvaskit_shadermask_linear_translated.png',
builder.build());
});
// TODO: https://github.com/flutter/flutter/issues/60040
// TODO: https://github.com/flutter/flutter/issues/71520
}, skip: isIosSafari || isFirefox);