Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions lib/web_ui/lib/src/engine/canvaskit/layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,8 @@ class PhysicalShapeLayer extends ContainerLayer
assert(needsPainting);

if (_elevation != 0) {
drawShadow(paintContext.leafNodesCanvas!, _path, _shadowColor!, _elevation,
_color.alpha != 0xff);
drawShadow(paintContext.leafNodesCanvas!, _path, _shadowColor!,
_elevation, _color.alpha != 0xff);
}

final ui.Paint paint = ui.Paint()..color = _color;
Expand Down Expand Up @@ -528,6 +528,25 @@ class PhysicalShapeLayer extends ContainerLayer
}
}

/// A layer which contains a [ui.ColorFilter].
class ColorFilterLayer extends ContainerLayer {
ColorFilterLayer(this.filter);

final ui.ColorFilter filter;

@override
void paint(PaintContext paintContext) {
assert(needsPainting);

CkPaint paint = CkPaint();
paint.colorFilter = filter;

paintContext.internalNodesCanvas.saveLayer(paintBounds, paint);
paintChildren(paintContext);
paintContext.internalNodesCanvas.restore();
}
}

/// A layer which renders a platform view (an HTML element in this case).
class PlatformViewLayer extends Layer {
PlatformViewLayer(this.viewId, this.offset, this.width, this.height);
Expand Down
5 changes: 3 additions & 2 deletions lib/web_ui/lib/src/engine/canvaskit/layer_scene_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,13 @@ class LayerSceneBuilder implements ui.SceneBuilder {
}

@override
ui.ColorFilterEngineLayer pushColorFilter(
ui.ColorFilterEngineLayer? pushColorFilter(
ui.ColorFilter filter, {
ui.ColorFilterEngineLayer? oldLayer,
}) {
assert(filter != null); // ignore: unnecessary_null_comparison
throw UnimplementedError();
pushLayer(ColorFilterLayer(filter));
return null;
}

ui.ImageFilterEngineLayer? pushImageFilter(
Expand Down
13 changes: 12 additions & 1 deletion lib/web_ui/test/canvaskit/scene_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ void testMain() {
final ui.Image sceneImage = await scene.toImage(100, 100);
expect(sceneImage, isA<CkImage>());
});
// TODO: https://github.com/flutter/flutter/issues/60040

test('pushColorFilter does not throw', () async {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bonus points for making it a screenshot test. To do that, simply rename the file to scene_golden_test.dart and use golden_tester.dart like normal (example).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

although the test would need to be skipped outside chrome.

final ui.SceneBuilder builder = ui.SceneBuilder();
expect(builder, isA<LayerSceneBuilder>());

builder.pushOffset(0, 0);
builder.pushColorFilter(ui.ColorFilter.srgbToLinearGamma());

final ui.Scene scene = builder.build();
expect(scene, isNotNull);
});
// TODO: https://github.com/flutter/flutter/issues/60040
}, skip: isIosSafari);
}