Skip to content

Commit

Permalink
[web] Migrate Flutter Web to JS static interop - 7.
Browse files Browse the repository at this point in the history
  • Loading branch information
joshualitt committed Apr 8, 2022
1 parent 541b636 commit 54c16fa
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 19 deletions.
51 changes: 37 additions & 14 deletions lib/web_ui/lib/src/engine/canvaskit/canvaskit_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -927,23 +927,20 @@ class SkPaint {

@JS()
@anonymous
@staticInterop
abstract class CkFilterOptions {}

@JS()
@anonymous
@staticInterop
class _CkCubicFilterOptions extends CkFilterOptions {
external double get B;
external double get C;

external factory _CkCubicFilterOptions({double B, double C});
}

@JS()
@anonymous
@staticInterop
class _CkTransformFilterOptions extends CkFilterOptions {
external SkFilterMode get filter;
external SkMipmapMode get mipmap;

external factory _CkTransformFilterOptions(
{SkFilterMode filter, SkMipmapMode mipmap});
}
Expand Down Expand Up @@ -974,12 +971,18 @@ CkFilterOptions toSkFilterOptions(ui.FilterQuality filterQuality) {

@JS()
@anonymous
class SkMaskFilter {
@staticInterop
class SkMaskFilter {}

extension SkMaskFilterExtension on SkMaskFilter {
external void delete();
}

@JS()
class SkColorFilterNamespace {
@staticInterop
class SkColorFilterNamespace {}

extension SkColorFilterNamespaceExtension on SkColorFilterNamespace {
external SkColorFilter? MakeBlend(Float32List color, SkBlendMode blendMode);
external SkColorFilter MakeMatrix(
Float32List matrix, // 20-element matrix
Expand All @@ -991,12 +994,18 @@ class SkColorFilterNamespace {

@JS()
@anonymous
class SkColorFilter {
@staticInterop
class SkColorFilter {}

extension SkColorFilterExtension on SkColorFilter {
external void delete();
}

@JS()
class SkImageFilterNamespace {
@staticInterop
class SkImageFilterNamespace {}

extension SkImageFilterNamespaceExtension on SkImageFilterNamespace {
external SkImageFilter MakeBlur(
double sigmaX,
double sigmaY,
Expand All @@ -1023,12 +1032,18 @@ class SkImageFilterNamespace {

@JS()
@anonymous
class SkImageFilter {
@staticInterop
class SkImageFilter {}

extension SkImageFilterExtension on SkImageFilter {
external void delete();
}

@JS()
class SkPathNamespace {
@staticInterop
class SkPathNamespace {}

extension SkPathNamespaceExtension on SkPathNamespace {
/// Creates an [SkPath] using commands obtained from [SkPath.toCmds].
external SkPath MakeFromCmds(List<dynamic> pathCommands);

Expand Down Expand Up @@ -1119,6 +1134,7 @@ Float32List toSkColorStops(List<double>? colorStops) {
external _NativeFloat32ArrayType get _nativeFloat32ArrayType;

@JS()
@staticInterop
class _NativeFloat32ArrayType {}

@JS('window.flutterCanvasKit.Malloc')
Expand Down Expand Up @@ -1149,7 +1165,10 @@ external void freeFloat32List(SkFloat32List list);
/// when WASM grows its memory. Call [toTypedArray] to get a new instance
/// that's attached to the current WASM memory block.
@JS()
class SkFloat32List {
@staticInterop
class SkFloat32List {}

extension SkFloat32ListExtension on SkFloat32List {
/// Returns the [Float32List] object backed by WASM memory.
///
/// Do not reuse the returned list across multiple WASM function/method
Expand Down Expand Up @@ -1204,8 +1223,12 @@ Float32List toSharedSkColor3(ui.Color color) {
final SkFloat32List _sharedSkColor3 = mallocFloat32List(4);

@JS('window.flutterCanvasKit.Path')
@staticInterop
class SkPath {
external SkPath([SkPath? other]);
external factory SkPath.create([SkPath? other]);
}

extension SkPathExtension on SkPath {
external void setFillType(SkFillType fillType);
external void addArc(
Float32List oval,
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/lib/src/engine/canvaskit/path.dart
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ class CkPath extends ManagedSkiaObject<SkPath> implements ui.Path {

@override
SkPath createDefault() {
final SkPath path = SkPath();
final SkPath path = SkPath.create();
path.setFillType(toSkFillType(_fillType));
return path;
}
Expand Down
8 changes: 4 additions & 4 deletions lib/web_ui/test/canvaskit/canvaskit_api_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ void _toSkRectTests() {
}

SkPath _testClosedSkPath() {
return SkPath()
return SkPath.create()
..moveTo(10, 10)
..lineTo(20, 10)
..lineTo(20, 20)
Expand All @@ -736,7 +736,7 @@ void _pathTests() {
late SkPath path;

setUp(() {
path = SkPath();
path = SkPath.create();
});

test('setFillType', () {
Expand Down Expand Up @@ -890,7 +890,7 @@ void _pathTests() {
});

test('isEmpty', () {
expect(SkPath().isEmpty(), isTrue);
expect(SkPath.create().isEmpty(), isTrue);
expect(_testClosedSkPath().isEmpty(), isFalse);
});

Expand Down Expand Up @@ -948,7 +948,7 @@ void _pathTests() {

test('SkPath.toCmds and CanvasKit.Path.MakeFromCmds', () {
const ui.Rect rect = ui.Rect.fromLTRB(0, 0, 10, 10);
final SkPath path = SkPath();
final SkPath path = SkPath.create();
path.addRect(toSkRect(rect));
expect(path.toCmds(), <num>[
0, 0, 0, // moveTo
Expand Down

0 comments on commit 54c16fa

Please sign in to comment.