From c9649b2863c7bd10decb306b87ff2d88577c7d56 Mon Sep 17 00:00:00 2001 From: Jackson Gardner Date: Tue, 4 Apr 2023 16:51:14 -0700 Subject: [PATCH 1/4] Re-enable some wasm tests which have been fixed now. --- .../src/engine/canvaskit/image_web_codecs.dart | 17 +++++++++++++++-- .../test/canvaskit/canvas_golden_test.dart | 2 +- .../test/canvaskit/image_golden_test.dart | 4 ++-- .../test/engine/channel_buffers_test.dart | 4 ++-- .../test/engine/semantics/semantics_test.dart | 4 ++-- 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/lib/web_ui/lib/src/engine/canvaskit/image_web_codecs.dart b/lib/web_ui/lib/src/engine/canvaskit/image_web_codecs.dart index 6eb9ed1f7257b..b12f1e18cf991 100644 --- a/lib/web_ui/lib/src/engine/canvaskit/image_web_codecs.dart +++ b/lib/web_ui/lib/src/engine/canvaskit/image_web_codecs.dart @@ -14,6 +14,7 @@ import 'dart:js_interop'; import 'dart:math' as math; import 'dart:typed_data'; +import 'package:js/js.dart'; import 'package:meta/meta.dart'; import 'package:ui/ui.dart' as ui; @@ -439,12 +440,24 @@ bool _shouldReadPixelsUnmodified(VideoFrame videoFrame, ui.ImageByteFormat forma return format == ui.ImageByteFormat.rawRgba && isRgbFrame; } +@JS('Uint8Array') +@staticInterop +class _JSUint8Array { + external factory _JSUint8Array(JSNumber length); +} + Future readVideoFramePixelsUnmodified(VideoFrame videoFrame) async { final int size = videoFrame.allocationSize().toInt(); - final Uint8List destination = Uint8List(size); + + // In dart2wasm, Uint8List is not the same as a JS Uint8Array. So we + // explicitly construct the JS object here. + final JSUint8Array destination = _JSUint8Array(size.toJS) as JSUint8Array; final JsPromise copyPromise = videoFrame.copyTo(destination); await promiseToFuture(copyPromise); - return destination.buffer; + + // In dart2wasm, `toDart` incurs a copy here. On JS backends, this is a + // no-op. + return destination.toDart.buffer; } Future encodeVideoFrameAsPng(VideoFrame videoFrame) async { diff --git a/lib/web_ui/test/canvaskit/canvas_golden_test.dart b/lib/web_ui/test/canvaskit/canvas_golden_test.dart index 5d77675283f84..b3790cf78bac4 100644 --- a/lib/web_ui/test/canvaskit/canvas_golden_test.dart +++ b/lib/web_ui/test/canvaskit/canvas_golden_test.dart @@ -802,7 +802,7 @@ void testMain() { test('emoji text with skin tone', () async { await testSampleText('emoji_with_skin_tone', '👋🏿 👋🏾 👋🏽 👋🏼 👋🏻'); - }, skip: isWasm || isSafari || isFirefox); // https://github.com/flutter/flutter/issues/124068 + }); // Make sure we clear the canvas in between frames. test('empty frame after contentful frame', () async { diff --git a/lib/web_ui/test/canvaskit/image_golden_test.dart b/lib/web_ui/test/canvaskit/image_golden_test.dart index ffc9507620f2e..549ba84fed09b 100644 --- a/lib/web_ui/test/canvaskit/image_golden_test.dart +++ b/lib/web_ui/test/canvaskit/image_golden_test.dart @@ -889,7 +889,7 @@ void _testCkBrowserImageDecoder() { testCollector.collectNow(); // TODO(jacksongardner): enable on wasm // see https://github.com/flutter/flutter/issues/118334 - }, skip: isWasm); + }); test('ImageDecoder expires after inactivity', () async { const Duration testExpireDuration = Duration(milliseconds: 100); @@ -936,7 +936,7 @@ void _testCkBrowserImageDecoder() { debugRestoreWebDecoderExpireDuration(); // TODO(jacksongardner): enable on wasm // see https://github.com/flutter/flutter/issues/118334 - }, skip: isWasm); + }); } Future expectFrameData(ui.FrameInfo frame, List data) async { diff --git a/lib/web_ui/test/engine/channel_buffers_test.dart b/lib/web_ui/test/engine/channel_buffers_test.dart index bd72acab10978..6fc91100aec92 100644 --- a/lib/web_ui/test/engine/channel_buffers_test.dart +++ b/lib/web_ui/test/engine/channel_buffers_test.dart @@ -271,7 +271,7 @@ void testMain() { 'b: seven', '-9', ]); - }, skip: isWasm); // https://github.com/dart-lang/sdk/issues/50778 + }); test('ChannelBuffers.clearListener', () async { final List log = []; @@ -365,7 +365,7 @@ void testMain() { 'callback1: true', 'callback2: true', ]); - }, skip: isWasm); // https://github.com/dart-lang/sdk/issues/50778 + }); } class _TestChannelBuffers extends ui.ChannelBuffers { diff --git a/lib/web_ui/test/engine/semantics/semantics_test.dart b/lib/web_ui/test/engine/semantics/semantics_test.dart index e773cb33dcef3..4e9e466560fde 100644 --- a/lib/web_ui/test/engine/semantics/semantics_test.dart +++ b/lib/web_ui/test/engine/semantics/semantics_test.dart @@ -997,7 +997,7 @@ void _testVerticalScrolling() { expect(scrollable.scrollTop >= (10 - browserMaxScrollDiff), isTrue); semantics().semanticsEnabled = false; - }, skip: isWasm); // https://github.com/dart-lang/sdk/issues/50778 + }); } void _testHorizontalScrolling() { @@ -1130,7 +1130,7 @@ void _testHorizontalScrolling() { expect(scrollable.scrollLeft >= (10 - browserMaxScrollDiff), isTrue); semantics().semanticsEnabled = false; - }, skip: isWasm); // https://github.com/dart-lang/sdk/issues/50778 + }); } void _testIncrementables() { From 7de3f5220a721c1b3dcc9afc92e7e57aec3137bb Mon Sep 17 00:00:00 2001 From: Jackson Gardner Date: Tue, 4 Apr 2023 16:57:09 -0700 Subject: [PATCH 2/4] Remove todo. --- lib/web_ui/test/canvaskit/image_golden_test.dart | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/web_ui/test/canvaskit/image_golden_test.dart b/lib/web_ui/test/canvaskit/image_golden_test.dart index 549ba84fed09b..5f8f83f2f2dd1 100644 --- a/lib/web_ui/test/canvaskit/image_golden_test.dart +++ b/lib/web_ui/test/canvaskit/image_golden_test.dart @@ -887,8 +887,6 @@ void _testCkBrowserImageDecoder() { expect(rgba!.buffer.asUint8List(), expectedColors[i]); } testCollector.collectNow(); - // TODO(jacksongardner): enable on wasm - // see https://github.com/flutter/flutter/issues/118334 }); test('ImageDecoder expires after inactivity', () async { @@ -934,8 +932,6 @@ void _testCkBrowserImageDecoder() { testCollector.collectNow(); debugRestoreWebDecoderExpireDuration(); - // TODO(jacksongardner): enable on wasm - // see https://github.com/flutter/flutter/issues/118334 }); } From 811283a655c974ac72d90f00f161b004f8b51cde Mon Sep 17 00:00:00 2001 From: Jackson Gardner Date: Tue, 4 Apr 2023 21:59:07 -0700 Subject: [PATCH 3/4] Disable the semantics tests again, they still don't work. --- lib/web_ui/test/engine/semantics/semantics_test.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/web_ui/test/engine/semantics/semantics_test.dart b/lib/web_ui/test/engine/semantics/semantics_test.dart index 4e9e466560fde..e773cb33dcef3 100644 --- a/lib/web_ui/test/engine/semantics/semantics_test.dart +++ b/lib/web_ui/test/engine/semantics/semantics_test.dart @@ -997,7 +997,7 @@ void _testVerticalScrolling() { expect(scrollable.scrollTop >= (10 - browserMaxScrollDiff), isTrue); semantics().semanticsEnabled = false; - }); + }, skip: isWasm); // https://github.com/dart-lang/sdk/issues/50778 } void _testHorizontalScrolling() { @@ -1130,7 +1130,7 @@ void _testHorizontalScrolling() { expect(scrollable.scrollLeft >= (10 - browserMaxScrollDiff), isTrue); semantics().semanticsEnabled = false; - }); + }, skip: isWasm); // https://github.com/dart-lang/sdk/issues/50778 } void _testIncrementables() { From a90934991725f457ba2ed286da445b0967ce0430 Mon Sep 17 00:00:00 2001 From: Jackson Gardner Date: Thu, 6 Apr 2023 10:39:53 -0700 Subject: [PATCH 4/4] Increase the timeout on the emoji test, which is pretty slow on wasm. --- lib/web_ui/test/canvaskit/canvas_golden_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/web_ui/test/canvaskit/canvas_golden_test.dart b/lib/web_ui/test/canvaskit/canvas_golden_test.dart index b3790cf78bac4..36cdf783135aa 100644 --- a/lib/web_ui/test/canvaskit/canvas_golden_test.dart +++ b/lib/web_ui/test/canvaskit/canvas_golden_test.dart @@ -802,7 +802,7 @@ void testMain() { test('emoji text with skin tone', () async { await testSampleText('emoji_with_skin_tone', '👋🏿 👋🏾 👋🏽 👋🏼 👋🏻'); - }); + }, timeout: const Timeout.factor(2)); // Make sure we clear the canvas in between frames. test('empty frame after contentful frame', () async {