Skip to content

Commit 93197e2

Browse files
authored
[wimp] Adds wimp-heavy variant for non-chrome browsers (flutter#189953)
issue: flutter#187212 This gets wimp_heavy loading on firefox. There are still some webgl errors though. ## video Before this change nothing rendered for counter, now it works as long as you don't hover over the floating button. https://github.com/user-attachments/assets/e68facbe-50a4-4d19-80a3-6967aba2691f ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [AI contribution guidelines]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
1 parent b92c68c commit 93197e2

17 files changed

Lines changed: 262 additions & 33 deletions

File tree

‎engine/src/flutter/lib/web_ui/dev/build.dart‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const Map<String, String> targetAliases = <String, String>{
2424
'skwasm_heavy': 'flutter/third_party/canvaskit:skwasm_heavy_group',
2525
'skwasm_heavy_st': 'flutter/third_party/canvaskit:skwasm_heavy_st_group',
2626
'wimp': 'flutter/third_party/canvaskit:wimp_group',
27+
'wimp_heavy': 'flutter/third_party/canvaskit:wimp_heavy_group',
2728
'archive': 'flutter/web_sdk:flutter_web_sdk_archive',
2829
};
2930

‎engine/src/flutter/lib/web_ui/dev/steps/copy_artifacts_step.dart‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ class CopyArtifactsStep implements PipelineStep {
137137
await copyWasmLibrary('skwasm', skwasmSourceDirectory, 'canvaskit');
138138
await copyWasmLibrary('skwasm_heavy', skwasmHeavySourceDirectory, 'canvaskit');
139139
await copyWasmLibrary('wimp', skwasmSourceDirectory, 'canvaskit');
140+
await copyWasmLibrary('wimp_heavy', skwasmHeavySourceDirectory, 'canvaskit');
140141
}
141142
print('Copied artifacts: ${copied.join(', ')}');
142143
}

‎engine/src/flutter/lib/web_ui/flutter_js/src/skwasm_loader.js‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,8 @@ import { resolveUrlWithSegments } from "./utils.js";
77

88
export const loadSkwasm = async (deps, config, browserEnvironment, baseUrl) => {
99
const needsHeavy = (!browserEnvironment.hasImageCodecs || !browserEnvironment.hasChromiumBreakIterators)
10-
if (needsHeavy && config.enableWimp) {
11-
console.error('Flutter Web: wimp_heavy is required but it hasn\'t been implemented yet.');
12-
}
1310
const fileStem = needsHeavy
14-
? 'skwasm_heavy'
11+
? (config.enableWimp ? 'wimp_heavy' : 'skwasm_heavy')
1512
: (config.enableWimp ? 'wimp' : 'skwasm');
1613
const rawSkwasmUrl = resolveUrlWithSegments(baseUrl, `${fileStem}.js`)
1714
let skwasmUrl = rawSkwasmUrl;

‎engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/renderer.dart‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,9 @@ class CanvasKitRenderer extends Renderer {
287287
@override
288288
bool get supportsResizingAnimatedImages => false;
289289

290+
@override
291+
bool get supportsAnimatedImages => true;
292+
290293
@override
291294
BackendImage decodeBackendImageFromPixels(
292295
Uint8List pixels, {

‎engine/src/flutter/lib/web_ui/lib/src/engine/image_decoder.dart‎

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,14 @@ Future<ui.Codec> engineInstantiateImageCodec(
339339
allowUpscaling: allowUpscaling,
340340
);
341341
} else {
342-
if (!imageType.isAnimated && browserSupportsCreateImageBitmap) {
342+
// The backend codec is the general fallback for anything the browser can't
343+
// decode itself, but only if it was built with the builtin codecs. When it
344+
// wasn't, it can't decode anything (static or animated), so it must never
345+
// be called. An animated image then degrades to a still of its first frame
346+
// via createImageBitmap rather than failing outright.
347+
final bool backendCanDecode = renderer.supportsAnimatedImages;
348+
final bool preferBitmap = !imageType.isAnimated || !backendCanDecode;
349+
if (preferBitmap && browserSupportsCreateImageBitmap) {
343350
final DomBlob blob = createDomBlob(<ByteBuffer>[list.buffer]);
344351
final DomImageBitmap originalBitmap = await createImageBitmap(blob);
345352
final int originalWidth = originalBitmap.width;
@@ -375,7 +382,7 @@ Future<ui.Codec> engineInstantiateImageCodec(
375382
targetHeight: targetHeight,
376383
allowUpscaling: allowUpscaling,
377384
);
378-
} else {
385+
} else if (backendCanDecode) {
379386
final BackendAnimatedImage backendAnimated = renderer.createAnimatedImage(
380387
list,
381388
targetWidth: targetWidth,
@@ -387,6 +394,12 @@ Future<ui.Codec> engineInstantiateImageCodec(
387394
targetHeight: targetHeight,
388395
allowUpscaling: allowUpscaling,
389396
);
397+
} else {
398+
throw ImageCodecException(
399+
'Failed to decode image: the browser does not support ImageDecoder or '
400+
'createImageBitmap, and the ${renderer.rendererTag} renderer was built '
401+
'without builtin image codecs.',
402+
);
390403
}
391404
}
392405
}
@@ -502,14 +515,25 @@ Future<ui.Codec> engineInstantiateImageCodecFromUrl(
502515
rethrow;
503516
}
504517
return EngineCodec.browser(decoder);
505-
} else if (!imageType.isAnimated && browserSupportsCreateImageBitmap) {
518+
}
519+
520+
// See the comment in [engineInstantiateImageCodec].
521+
final bool backendCanDecode = renderer.supportsAnimatedImages;
522+
final bool preferBitmap = !imageType.isAnimated || !backendCanDecode;
523+
if (preferBitmap && browserSupportsCreateImageBitmap) {
506524
final DomBlob blob = createDomBlob(<ByteBuffer>[buffer]);
507525
final DomImageBitmap bitmap = await createImageBitmap(blob);
508526
final ImageSource source = ImageBitmapImageSource(bitmap);
509527
return EngineCodec.staticImage(source);
510-
} else {
528+
} else if (backendCanDecode) {
511529
final BackendAnimatedImage backendAnimated = renderer.createAnimatedImage(list);
512530
return EngineCodec.skia(backendAnimated);
531+
} else {
532+
throw ImageCodecException(
533+
'Failed to decode image from $url: the browser does not support '
534+
'ImageDecoder or createImageBitmap, and the ${renderer.rendererTag} '
535+
'renderer was built without builtin image codecs.',
536+
);
513537
}
514538
}
515539
}

‎engine/src/flutter/lib/web_ui/lib/src/engine/renderer.dart‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,14 @@ abstract class Renderer {
176176
/// Whether this renderer natively supports resizing/scaling animated images during decoding.
177177
bool get supportsResizingAnimatedImages;
178178

179+
/// Whether this renderer can decode images itself via [createAnimatedImage].
180+
///
181+
/// When this is false, [createAnimatedImage] must not be called for any
182+
/// image, animated or not, and callers must fall back to a browser-provided
183+
/// decoder. Some backends (notably the Impeller-based skwasm variants) are
184+
/// built without the builtin image codecs.
185+
bool get supportsAnimatedImages;
186+
179187
BackendAnimatedImage createAnimatedImage(Uint8List bytes, {int? targetWidth, int? targetHeight});
180188

181189
BackendImage createImageFromImageSource(ImageSource source);

‎engine/src/flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/raw/skwasm_module.dart‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,13 @@ external bool skwasmIsWimp();
3232
@Native<Bool Function()>(symbol: 'skwasm_isHeavy', isLeaf: true)
3333
external bool skwasmIsHeavy();
3434

35+
/// Whether this skwasm binary was built with the builtin (Skia) animated image
36+
/// codecs.
37+
///
38+
/// This is decoupled from [skwasmIsHeavy] because `wimp_heavy` has builtin ICU
39+
/// but does not yet have an Impeller-compatible animated image implementation.
40+
@Native<Bool Function()>(symbol: 'skwasm_supportsAnimatedImages', isLeaf: true)
41+
external bool skwasmSupportsAnimatedImages();
42+
3543
@Native<Void Function(Pointer<Uint32>)>(symbol: 'skwasm_getLiveObjectCounts', isLeaf: true)
3644
external void skwasmGetLiveObjectCounts(Pointer<Uint32> objectCounts);

‎engine/src/flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/renderer.dart‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ class SkwasmRenderer extends Renderer {
1919
@override
2020
bool get supportsResizingAnimatedImages => true;
2121

22+
@override
23+
bool get supportsAnimatedImages => skwasmSupportsAnimatedImages();
24+
2225
bool get isWimp => skwasmIsWimp();
2326

2427
@override

‎engine/src/flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_stub/renderer.dart‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ class SkwasmRenderer extends Renderer {
1616
bool get supportsResizingAnimatedImages =>
1717
throw UnimplementedError('Skwasm not implemented on this platform.');
1818

19+
@override
20+
bool get supportsAnimatedImages =>
21+
throw UnimplementedError('Skwasm not implemented on this platform.');
22+
1923
bool get isWimp => false;
2024

2125
@override

‎engine/src/flutter/lib/web_ui/test/felt_config.yaml‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,14 @@ run-configs:
137137
wasm-allow-list:
138138
gecko: true
139139

140+
- name: firefox-wimp
141+
browser: firefox
142+
canvaskit-variant: full
143+
cross-origin-isolated: true
144+
enable-wimp: true
145+
wasm-allow-list:
146+
gecko: true
147+
140148
- name: safari
141149
browser: safari
142150
canvaskit-variant: full
@@ -154,6 +162,14 @@ run-configs:
154162
wasm-allow-list:
155163
webkit: true
156164

165+
- name: safari-wimp
166+
browser: safari
167+
canvaskit-variant: full
168+
cross-origin-isolated: true
169+
enable-wimp: true
170+
wasm-allow-list:
171+
webkit: true
172+
157173

158174
test-suites:
159175
- name: chrome-dart2js-webparagraph-ui
@@ -251,6 +267,12 @@ test-suites:
251267
run-config: firefox-coi-wasm
252268
artifact-deps: [ skwasm ]
253269

270+
- name: firefox-dart2wasm-wimp-ui
271+
test-bundle: dart2wasm-skwasm-ui
272+
run-config: firefox-wimp
273+
artifact-deps: [ skwasm ]
274+
enable-ci: false
275+
254276
- name: safari-dart2js-canvaskit-engine
255277
test-bundle: dart2js-canvaskit-engine
256278
run-config: safari
@@ -286,6 +308,12 @@ test-suites:
286308
run-config: safari-coi-wasm
287309
artifact-deps: [ skwasm ]
288310

311+
- name: safari-dart2wasm-wimp-ui
312+
test-bundle: dart2wasm-skwasm-ui
313+
run-config: safari-wimp
314+
artifact-deps: [ skwasm ]
315+
enable-ci: false
316+
289317
- name: chrome-dart2wasm-canvaskit-engine
290318
test-bundle: dart2wasm-canvaskit-engine
291319
run-config: chrome

0 commit comments

Comments
 (0)