From 9056ea0aa4ab18338249d06552f745a9f564f6ee Mon Sep 17 00:00:00 2001 From: Jackson Gardner Date: Tue, 27 Jun 2023 10:45:40 -0700 Subject: [PATCH 1/2] Initialize skwasm codecs before handing them back to the user. --- lib/web_ui/lib/src/engine/skwasm/skwasm_impl/renderer.dart | 7 +++++-- lib/web_ui/test/ui/filters_test.dart | 2 ++ lib/web_ui/test/ui/image_golden_test.dart | 4 ++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/renderer.dart b/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/renderer.dart index e8228815ac806..71fc79ad335a9 100644 --- a/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/renderer.dart +++ b/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/renderer.dart @@ -369,11 +369,12 @@ class SkwasmRenderer implements Renderer { if (contentType == null) { throw Exception('Could not determine content type of image from data'); } - final ui.Codec baseDecoder = SkwasmImageDecoder( + final SkwasmImageDecoder baseDecoder = SkwasmImageDecoder( contentType: contentType, dataSource: list.toJS, debugSource: 'encoded image bytes', ); + await baseDecoder.initialize(); if (targetWidth == null && targetHeight == null) { return baseDecoder; } @@ -395,11 +396,13 @@ class SkwasmRenderer implements Renderer { if (contentType == null) { throw Exception('Could not determine content type of image at url $uri'); } - return SkwasmImageDecoder( + final SkwasmImageDecoder decoder = SkwasmImageDecoder( contentType: contentType, dataSource: response.body as JSAny, debugSource: uri.toString(), ); + await decoder.initialize(); + return decoder; } @override diff --git a/lib/web_ui/test/ui/filters_test.dart b/lib/web_ui/test/ui/filters_test.dart index 1b66d5bf434f5..21feebcdc67cc 100644 --- a/lib/web_ui/test/ui/filters_test.dart +++ b/lib/web_ui/test/ui/filters_test.dart @@ -29,6 +29,8 @@ Future testMain() async { final ui.Codec codec = await renderer.instantiateImageCodecFromUrl( Uri(path: '/test_images/mandrill_128.png') ); + expect(codec.frameCount, 1); + expect(codec.repetitionCount, 0); final ui.FrameInfo info = await codec.getNextFrame(); final ui.Image image = info.image; diff --git a/lib/web_ui/test/ui/image_golden_test.dart b/lib/web_ui/test/ui/image_golden_test.dart index c1defa07ccfed..52357bc37455d 100644 --- a/lib/web_ui/test/ui/image_golden_test.dart +++ b/lib/web_ui/test/ui/image_golden_test.dart @@ -288,6 +288,8 @@ Future testMain() async { final ui.Codec codec = await renderer.instantiateImageCodecFromUrl( Uri(path: '/test_images/mandrill_128.png') ); + expect(codec.frameCount, 1); + expect(codec.repetitionCount, 0); final ui.FrameInfo info = await codec.getNextFrame(); return info.image; @@ -300,6 +302,8 @@ Future testMain() async { targetWidth: 150, targetHeight: 150, ); + expect(codec.frameCount, 1); + expect(codec.repetitionCount, 0); final ui.FrameInfo info = await codec.getNextFrame(); return info.image; From 89cab7391bd510764b5d3708b9769e70b425f217 Mon Sep 17 00:00:00 2001 From: Jackson Gardner Date: Tue, 27 Jun 2023 12:29:27 -0700 Subject: [PATCH 2/2] Repetition count is not reliable. --- lib/web_ui/test/ui/filters_test.dart | 1 - lib/web_ui/test/ui/image_golden_test.dart | 2 -- 2 files changed, 3 deletions(-) diff --git a/lib/web_ui/test/ui/filters_test.dart b/lib/web_ui/test/ui/filters_test.dart index 21feebcdc67cc..56feb205b21df 100644 --- a/lib/web_ui/test/ui/filters_test.dart +++ b/lib/web_ui/test/ui/filters_test.dart @@ -30,7 +30,6 @@ Future testMain() async { Uri(path: '/test_images/mandrill_128.png') ); expect(codec.frameCount, 1); - expect(codec.repetitionCount, 0); final ui.FrameInfo info = await codec.getNextFrame(); final ui.Image image = info.image; diff --git a/lib/web_ui/test/ui/image_golden_test.dart b/lib/web_ui/test/ui/image_golden_test.dart index 52357bc37455d..df299250af8ba 100644 --- a/lib/web_ui/test/ui/image_golden_test.dart +++ b/lib/web_ui/test/ui/image_golden_test.dart @@ -289,7 +289,6 @@ Future testMain() async { Uri(path: '/test_images/mandrill_128.png') ); expect(codec.frameCount, 1); - expect(codec.repetitionCount, 0); final ui.FrameInfo info = await codec.getNextFrame(); return info.image; @@ -303,7 +302,6 @@ Future testMain() async { targetHeight: 150, ); expect(codec.frameCount, 1); - expect(codec.repetitionCount, 0); final ui.FrameInfo info = await codec.getNextFrame(); return info.image;