Skip to content

Commit

Permalink
[web] flip browser image codec flag to opt-out (#30681)
Browse files Browse the repository at this point in the history
  • Loading branch information
yjbanov authored Jan 5, 2022
1 parent c726121 commit f181c4d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
8 changes: 0 additions & 8 deletions lib/web_ui/dev/steps/compile_tests_step.dart
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,6 @@ 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.
Expand Down
18 changes: 12 additions & 6 deletions lib/web_ui/lib/src/engine/safe_browser_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -219,16 +219,22 @@ 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,
/// Environment variable that allows the developer to opt out of using browser's
/// `ImageDecoder` API, and use the WASM codecs bundled with CanvasKit.
///
/// While all reported severe issues with `ImageDecoder` have been fixed, this
/// API remains relatively new. This option will allow developers to opt out of
/// it, if they hit a severe bug that we did not anticipate.
// TODO(yjbanov): remove this flag once we're fully confident in the new API.
// https://github.com/flutter/flutter/issues/95277
const bool _browserImageDecodingEnabled = bool.fromEnvironment(
'BROWSER_IMAGE_DECODING_ENABLED',
defaultValue: true,
);

/// Whether the current browser supports `ImageDecoder`.
bool browserSupportsImageDecoder =
_imageDecoderExperimentEnabled &&
_browserImageDecodingEnabled &&
_imageDecoderConstructor != null &&
browserEngine == BrowserEngine.blink;

Expand Down

0 comments on commit f181c4d

Please sign in to comment.