@@ -1267,34 +1267,46 @@ Float32List toSkColorStops(List<double>? colorStops) {
12671267 return skColorStops;
12681268}
12691269
1270- @JS ('Float32Array' )
1271- external _NativeFloat32ArrayType get _nativeFloat32ArrayType;
1272-
12731270@JS ()
12741271@staticInterop
1275- class _NativeFloat32ArrayType {}
1272+ abstract class _NativeType {}
1273+
1274+ @JS ('Float32Array' )
1275+ external _NativeType get _nativeFloat32ArrayType;
1276+
1277+ @JS ('Uint32Array' )
1278+ external _NativeType get _nativeUint32ArrayType;
12761279
12771280@JS ('window.flutterCanvasKit.Malloc' )
1278- external SkFloat32List _mallocFloat32List (
1279- _NativeFloat32ArrayType float32ListType,
1280- int size,
1281- );
1281+ external Object _malloc (_NativeType nativeType, int length);
1282+
1283+ /// Allocates a [Float32List] of [length] elements, backed by WASM memory,
1284+ /// managed by a [SkFloat32List] .
1285+ ///
1286+ /// To free the allocated array use [free] .
1287+ SkFloat32List mallocFloat32List (int length) {
1288+ return _malloc (_nativeFloat32ArrayType, length) as SkFloat32List ;
1289+ }
12821290
1283- /// Allocates a [Float32List] backed by WASM memory, managed by
1284- /// a [SkFloat32List ] .
1291+ /// Allocates a [Uint32List] of [length] elements, backed by WASM memory,
1292+ /// managed by a [SkUint32List ] .
12851293///
1286- /// To free the allocated array use [freeFloat32List ] .
1287- SkFloat32List mallocFloat32List (int size ) {
1288- return _mallocFloat32List (_nativeFloat32ArrayType, size) ;
1294+ /// To free the allocated array use [free ] .
1295+ SkUint32List mallocUint32List (int length ) {
1296+ return _malloc (_nativeUint32ArrayType, length) as SkUint32List ;
12891297}
12901298
1291- /// Frees the WASM memory occupied by a [SkFloat32List] .
1299+ /// Frees the WASM memory occupied by a [SkFloat32List] or [SkUint32List] .
12921300///
12931301/// The [list] is no longer usable after calling this function.
12941302///
12951303/// Use this function to free lists owned by the engine.
12961304@JS ('window.flutterCanvasKit.Free' )
1297- external void freeFloat32List (SkFloat32List list);
1305+ external void free (MallocObj list);
1306+
1307+ @JS ()
1308+ @staticInterop
1309+ abstract class MallocObj {}
12981310
12991311/// Wraps a [Float32List] backed by WASM memory.
13001312///
@@ -1303,19 +1315,45 @@ external void freeFloat32List(SkFloat32List list);
13031315/// that's attached to the current WASM memory block.
13041316@JS ()
13051317@staticInterop
1306- class SkFloat32List {}
1318+ class SkFloat32List extends MallocObj {}
13071319
13081320extension SkFloat32ListExtension on SkFloat32List {
1321+ /// The number of objects this pointer refers to.
1322+ external int length;
1323+
13091324 /// Returns the [Float32List] object backed by WASM memory.
13101325 ///
1311- /// Do not reuse the returned list across multiple WASM function/method
1326+ /// Do not reuse the returned array across multiple WASM function/method
13121327 /// invocations that may lead to WASM memory to grow. When WASM memory
1313- /// grows the [Float32List] object becomes "detached" and is no longer
1314- /// usable. Instead, call this method every time you need to read from
1328+ /// grows, the returned [Float32List] object becomes "detached" and is no
1329+ /// longer usable. Instead, call this method every time you need to read from
13151330 /// or write to the list.
13161331 external Float32List toTypedArray ();
13171332}
13181333
1334+ /// Wraps a [Uint32List] backed by WASM memory.
1335+ ///
1336+ /// This wrapper is necessary because the raw [Uint32List] will get detached
1337+ /// when WASM grows its memory. Call [toTypedArray] to get a new instance
1338+ /// that's attached to the current WASM memory block.
1339+ @JS ()
1340+ @staticInterop
1341+ class SkUint32List extends MallocObj {}
1342+
1343+ extension SkUint32ListExtension on SkUint32List {
1344+ /// The number of objects this pointer refers to.
1345+ external int length;
1346+
1347+ /// Returns the [Uint32List] object backed by WASM memory.
1348+ ///
1349+ /// Do not reuse the returned array across multiple WASM function/method
1350+ /// invocations that may lead to WASM memory to grow. When WASM memory
1351+ /// grows, the returned [Uint32List] object becomes "detached" and is no
1352+ /// longer usable. Instead, call this method every time you need to read from
1353+ /// or write to the list.
1354+ external Uint32List toTypedArray ();
1355+ }
1356+
13191357/// Writes [color] information into the given [skColor] buffer.
13201358Float32List _populateSkColor (SkFloat32List skColor, ui.Color color) {
13211359 final Float32List array = skColor.toTypedArray ();
@@ -1585,7 +1623,7 @@ Float32List toOuterSkRect(ui.RRect rrect) {
15851623/// Uses `CanvasKit.Malloc` to allocate storage for the points in the WASM
15861624/// memory to avoid unnecessary copying. Unless CanvasKit takes ownership of
15871625/// the list the returned list must be explicitly freed using
1588- /// [freeMallocedFloat32List ] .
1626+ /// [free ] .
15891627SkFloat32List toMallocedSkPoints (List <ui.Offset > points) {
15901628 final int len = points.length;
15911629 final SkFloat32List skPoints = mallocFloat32List (len * 2 );
0 commit comments