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

[web] Migrate Flutter Web to JS static interop - 7. #32519

Merged
merged 1 commit into from
Apr 14, 2022
Merged
Changes from all commits
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
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;
Copy link
Contributor

Choose a reason for hiding this comment

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

What errors were you getting from moving these to extensions? Are these unused (similar question for the other removed members)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea, they appear to be unused and so the analyzer warned. The flutter web project has a check that turns the analyzer warnings to errors. It sort of makes sense that the analyzer is stricter with extension methods because they are static.

I'm not sure what we can really do here other than maybe some annotation that makes the warnings go away, but given that the methods really are seemingly unused, it may make sense to just remove them.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed, I was just mostly curious why warnings started to appear now instead of before when they were unused anyways.

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([SkPath? other]);
}

extension SkPathExtension on SkPath {
external void setFillType(SkFillType fillType);
external void addArc(
Float32List oval,
Expand Down