[web] make new image decoder opt-in via experimental flag (flutter/engine#30324)

This commit is contained in:
Yegor
2021-12-14 12:47:37 -08:00
committed by GitHub
parent 605a4cd2c2
commit 831f7e12d7
2 changed files with 18 additions and 1 deletions

View File

@@ -258,6 +258,14 @@ Future<bool> compileUnitTest(FilePath input, { required bool forCanvasKit }) asy
'-DFLUTTER_WEB_AUTO_DETECT=false',
'-DFLUTTER_WEB_USE_SKIA=$forCanvasKit',
// Enable the image decoder experiment in tests so we can test the new
// functionality. WASM decoders are still tested by forcing the value of
// `browserSupportsImageDecoder` to false in the test. See also:
//
// lib/web_ui/test/canvaskit/image_golden_test.dart
// TODO(yjbanov): https://github.com/flutter/flutter/issues/95277
'-DEXPERIMENTAL_IMAGE_DECODER=true',
'-O2',
'-o',
targetFileName, // target path.

View File

@@ -218,9 +218,18 @@ html.CanvasElement? tryCreateCanvasElement(int width, int height) {
@JS('window.ImageDecoder')
external Object? get _imageDecoderConstructor;
/// Hides `image_web_codecs.dart` behind a flag.
// TODO(yjbanov): https://github.com/flutter/flutter/issues/95277
const bool _imageDecoderExperimentEnabled = bool.fromEnvironment(
'EXPERIMENTAL_IMAGE_DECODER',
defaultValue: false,
);
/// Whether the current browser supports `ImageDecoder`.
bool browserSupportsImageDecoder =
_imageDecoderConstructor != null && browserEngine == BrowserEngine.blink;
_imageDecoderExperimentEnabled &&
_imageDecoderConstructor != null &&
browserEngine == BrowserEngine.blink;
/// Sets the value of [browserSupportsImageDecoder] to its default value.
void debugResetBrowserSupportsImageDecoder() {