@@ -1273,34 +1273,46 @@ Float32List toSkColorStops(List<double>? colorStops) {
1273
1273
return skColorStops;
1274
1274
}
1275
1275
1276
- @JS ('Float32Array' )
1277
- external _NativeFloat32ArrayType get _nativeFloat32ArrayType;
1278
-
1279
1276
@JS ()
1280
1277
@staticInterop
1281
- class _NativeFloat32ArrayType {}
1278
+ abstract class _ArrayType {}
1279
+
1280
+ @JS ('Float32Array' )
1281
+ external _ArrayType get _nativeFloat32ArrayType;
1282
+
1283
+ @JS ('Uint32Array' )
1284
+ external _ArrayType get _nativeUint32ArrayType;
1282
1285
1283
1286
@JS ('window.flutterCanvasKit.Malloc' )
1284
- external SkFloat32List _mallocFloat32List (
1285
- _NativeFloat32ArrayType float32ListType,
1286
- int size,
1287
- );
1287
+ external Object _mallocList (_ArrayType arrayType, int size);
1288
1288
1289
1289
/// Allocates a [Float32List] backed by WASM memory, managed by
1290
1290
/// a [SkFloat32List] .
1291
1291
///
1292
- /// To free the allocated array use [freeFloat32List ] .
1292
+ /// To free the allocated array use [freeList ] .
1293
1293
SkFloat32List mallocFloat32List (int size) {
1294
- return _mallocFloat32List (_nativeFloat32ArrayType, size);
1294
+ return _mallocList (_nativeFloat32ArrayType, size) as SkFloat32List ;
1295
+ }
1296
+
1297
+ /// Allocates a [Uint32List] backed by WASM memory, managed by
1298
+ /// a [SkUint32List] .
1299
+ ///
1300
+ /// To free the allocated array use [freeList] .
1301
+ SkUint32List mallocUint32List (int size) {
1302
+ return _mallocList (_nativeUint32ArrayType, size) as SkUint32List ;
1295
1303
}
1296
1304
1297
- /// Frees the WASM memory occupied by a [SkFloat32List] .
1305
+ /// Frees the WASM memory occupied by a [SkFloat32List] or [SkUint32List] .
1298
1306
///
1299
1307
/// The [list] is no longer usable after calling this function.
1300
1308
///
1301
1309
/// Use this function to free lists owned by the engine.
1302
1310
@JS ('window.flutterCanvasKit.Free' )
1303
- external void freeFloat32List (SkFloat32List list);
1311
+ external void freeList (_SkList list);
1312
+
1313
+ @JS ()
1314
+ @staticInterop
1315
+ abstract class _SkList {}
1304
1316
1305
1317
/// Wraps a [Float32List] backed by WASM memory.
1306
1318
///
@@ -1309,7 +1321,7 @@ external void freeFloat32List(SkFloat32List list);
1309
1321
/// that's attached to the current WASM memory block.
1310
1322
@JS ()
1311
1323
@staticInterop
1312
- class SkFloat32List {}
1324
+ class SkFloat32List extends _SkList {}
1313
1325
1314
1326
extension SkFloat32ListExtension on SkFloat32List {
1315
1327
/// Returns the [Float32List] object backed by WASM memory.
@@ -1322,6 +1334,26 @@ extension SkFloat32ListExtension on SkFloat32List {
1322
1334
external Float32List toTypedArray ();
1323
1335
}
1324
1336
1337
+ /// Wraps a [Uint32List] backed by WASM memory.
1338
+ ///
1339
+ /// This wrapper is necessary because the raw [Uint32List] will get detached
1340
+ /// when WASM grows its memory. Call [toTypedArray] to get a new instance
1341
+ /// that's attached to the current WASM memory block.
1342
+ @JS ()
1343
+ @staticInterop
1344
+ class SkUint32List extends _SkList {}
1345
+
1346
+ extension SkUint32ListExtension on SkUint32List {
1347
+ /// Returns the [Uint32List] object backed by WASM memory.
1348
+ ///
1349
+ /// Do not reuse the returned list across multiple WASM function/method
1350
+ /// invocations that may lead to WASM memory to grow. When WASM memory
1351
+ /// grows the [Uint32List] object becomes "detached" and is no longer
1352
+ /// usable. Instead, call this method every time you need to read from
1353
+ /// or write to the list.
1354
+ external Uint32List toTypedArray ();
1355
+ }
1356
+
1325
1357
/// Writes [color] information into the given [skColor] buffer.
1326
1358
Float32List _populateSkColor (SkFloat32List skColor, ui.Color color) {
1327
1359
final Float32List array = skColor.toTypedArray ();
@@ -1590,7 +1622,7 @@ Float32List toOuterSkRect(ui.RRect rrect) {
1590
1622
/// Uses `CanvasKit.Malloc` to allocate storage for the points in the WASM
1591
1623
/// memory to avoid unnecessary copying. Unless CanvasKit takes ownership of
1592
1624
/// the list the returned list must be explicitly freed using
1593
- /// [freeMallocedFloat32List ] .
1625
+ /// [freeList ] .
1594
1626
SkFloat32List toMallocedSkPoints (List <ui.Offset > points) {
1595
1627
final int len = points.length;
1596
1628
final SkFloat32List skPoints = mallocFloat32List (len * 2 );
0 commit comments