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

Commit 879abb4

Browse files
committed
[web] Migrate Flutter Web to JS static interop - 7.
1 parent 541b636 commit 879abb4

File tree

3 files changed

+51
-18
lines changed

3 files changed

+51
-18
lines changed

lib/web_ui/lib/src/engine/canvaskit/canvaskit_api.dart

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -927,27 +927,34 @@ class SkPaint {
927927

928928
@JS()
929929
@anonymous
930+
@staticInterop
930931
abstract class CkFilterOptions {}
931932

932933
@JS()
933934
@anonymous
935+
@staticInterop
934936
class _CkCubicFilterOptions extends CkFilterOptions {
937+
external factory _CkCubicFilterOptions({double B, double C});
938+
}
939+
940+
extension _CkCubicFilterOptionsExtension on _CkCubicFilterOptions {
935941
external double get B;
936942
external double get C;
937-
938-
external factory _CkCubicFilterOptions({double B, double C});
939943
}
940944

941945
@JS()
942946
@anonymous
947+
@staticInterop
943948
class _CkTransformFilterOptions extends CkFilterOptions {
944-
external SkFilterMode get filter;
945-
external SkMipmapMode get mipmap;
946-
947949
external factory _CkTransformFilterOptions(
948950
{SkFilterMode filter, SkMipmapMode mipmap});
949951
}
950952

953+
extension _CkTransformFilterOptionsExtension on _CkTransformFilterOptions {
954+
external SkFilterMode get filter;
955+
external SkMipmapMode get mipmap;
956+
}
957+
951958
final Map<ui.FilterQuality, CkFilterOptions> _filterOptions =
952959
<ui.FilterQuality, CkFilterOptions>{
953960
ui.FilterQuality.none: _CkTransformFilterOptions(
@@ -974,12 +981,18 @@ CkFilterOptions toSkFilterOptions(ui.FilterQuality filterQuality) {
974981

975982
@JS()
976983
@anonymous
977-
class SkMaskFilter {
984+
@staticInterop
985+
class SkMaskFilter {}
986+
987+
extension SkMaskFilterExtension on SkMaskFilter {
978988
external void delete();
979989
}
980990

981991
@JS()
982-
class SkColorFilterNamespace {
992+
@staticInterop
993+
class SkColorFilterNamespace {}
994+
995+
extension SkColorFilterNamespaceExtension on SkColorFilterNamespace {
983996
external SkColorFilter? MakeBlend(Float32List color, SkBlendMode blendMode);
984997
external SkColorFilter MakeMatrix(
985998
Float32List matrix, // 20-element matrix
@@ -991,12 +1004,18 @@ class SkColorFilterNamespace {
9911004

9921005
@JS()
9931006
@anonymous
994-
class SkColorFilter {
1007+
@staticInterop
1008+
class SkColorFilter {}
1009+
1010+
extension SkColorFilterExtension on SkColorFilter {
9951011
external void delete();
9961012
}
9971013

9981014
@JS()
999-
class SkImageFilterNamespace {
1015+
@staticInterop
1016+
class SkImageFilterNamespace {}
1017+
1018+
extension SkImageFilterNamespaceExtension on SkImageFilterNamespace {
10001019
external SkImageFilter MakeBlur(
10011020
double sigmaX,
10021021
double sigmaY,
@@ -1023,12 +1042,18 @@ class SkImageFilterNamespace {
10231042

10241043
@JS()
10251044
@anonymous
1026-
class SkImageFilter {
1045+
@staticInterop
1046+
class SkImageFilter {}
1047+
1048+
extension SkImageFilterExtension on SkImageFilter {
10271049
external void delete();
10281050
}
10291051

10301052
@JS()
1031-
class SkPathNamespace {
1053+
@staticInterop
1054+
class SkPathNamespace {}
1055+
1056+
extension SkPathNamespaceExtension on SkPathNamespace {
10321057
/// Creates an [SkPath] using commands obtained from [SkPath.toCmds].
10331058
external SkPath MakeFromCmds(List<dynamic> pathCommands);
10341059

@@ -1119,6 +1144,7 @@ Float32List toSkColorStops(List<double>? colorStops) {
11191144
external _NativeFloat32ArrayType get _nativeFloat32ArrayType;
11201145

11211146
@JS()
1147+
@staticInterop
11221148
class _NativeFloat32ArrayType {}
11231149

11241150
@JS('window.flutterCanvasKit.Malloc')
@@ -1149,7 +1175,10 @@ external void freeFloat32List(SkFloat32List list);
11491175
/// when WASM grows its memory. Call [toTypedArray] to get a new instance
11501176
/// that's attached to the current WASM memory block.
11511177
@JS()
1152-
class SkFloat32List {
1178+
@staticInterop
1179+
class SkFloat32List {}
1180+
1181+
extension SkFloat32ListExtension on SkFloat32List {
11531182
/// Returns the [Float32List] object backed by WASM memory.
11541183
///
11551184
/// Do not reuse the returned list across multiple WASM function/method
@@ -1204,8 +1233,12 @@ Float32List toSharedSkColor3(ui.Color color) {
12041233
final SkFloat32List _sharedSkColor3 = mallocFloat32List(4);
12051234

12061235
@JS('window.flutterCanvasKit.Path')
1236+
@staticInterop
12071237
class SkPath {
1208-
external SkPath([SkPath? other]);
1238+
external factory SkPath.create([SkPath? other]);
1239+
}
1240+
1241+
extension SkPathExtension on SkPath {
12091242
external void setFillType(SkFillType fillType);
12101243
external void addArc(
12111244
Float32List oval,

lib/web_ui/lib/src/engine/canvaskit/path.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ class CkPath extends ManagedSkiaObject<SkPath> implements ui.Path {
316316

317317
@override
318318
SkPath createDefault() {
319-
final SkPath path = SkPath();
319+
final SkPath path = SkPath.create();
320320
path.setFillType(toSkFillType(_fillType));
321321
return path;
322322
}

lib/web_ui/test/canvaskit/canvaskit_api_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ void _toSkRectTests() {
724724
}
725725

726726
SkPath _testClosedSkPath() {
727-
return SkPath()
727+
return SkPath.create()
728728
..moveTo(10, 10)
729729
..lineTo(20, 10)
730730
..lineTo(20, 20)
@@ -736,7 +736,7 @@ void _pathTests() {
736736
late SkPath path;
737737

738738
setUp(() {
739-
path = SkPath();
739+
path = SkPath.create();
740740
});
741741

742742
test('setFillType', () {
@@ -890,7 +890,7 @@ void _pathTests() {
890890
});
891891

892892
test('isEmpty', () {
893-
expect(SkPath().isEmpty(), isTrue);
893+
expect(SkPath.create().isEmpty(), isTrue);
894894
expect(_testClosedSkPath().isEmpty(), isFalse);
895895
});
896896

@@ -948,7 +948,7 @@ void _pathTests() {
948948

949949
test('SkPath.toCmds and CanvasKit.Path.MakeFromCmds', () {
950950
const ui.Rect rect = ui.Rect.fromLTRB(0, 0, 10, 10);
951-
final SkPath path = SkPath();
951+
final SkPath path = SkPath.create();
952952
path.addRect(toSkRect(rect));
953953
expect(path.toCmds(), <num>[
954954
0, 0, 0, // moveTo

0 commit comments

Comments
 (0)