From 9b26cdc88c1913e7156c6bca7bfa2bc7f8f8e604 Mon Sep 17 00:00:00 2001 From: Harry Terkelsen <1961493+harryterkelsen@users.noreply.github.com> Date: Thu, 30 Nov 2023 12:41:23 -0800 Subject: [PATCH] [canvaskit] Revert to `drawImage` rendering on Chrome 110 or earlier (flutter/engine#48515) This updates a fix for Chrome 110 and earlier to always activate, not just on Windows. Fixes https://github.com/flutter/flutter/issues/138827 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I added new tests to check the change I am making or feature I am adding, or the PR is [test-exempt]. See [testing the engine] for instructions on writing and running engine tests. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I signed the [CLA]. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. [Contributor Guide]: https://github.com/flutter/flutter/wiki/Tree-hygiene#overview [Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene [test-exempt]: https://github.com/flutter/flutter/wiki/Tree-hygiene#tests [Flutter Style Guide]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style [testing the engine]: https://github.com/flutter/flutter/wiki/Testing-the-engine [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/wiki/Chat --- .../lib/src/engine/browser_detection.dart | 28 +++++++++---------- .../lib/web_ui/lib/src/engine/dom.dart | 2 +- .../no_create_image_bitmap_test.dart | 4 +-- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/browser_detection.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/browser_detection.dart index f771c9ea64e..c6c7dc84222 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/browser_detection.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/browser_detection.dart @@ -206,35 +206,33 @@ bool get isIOS15 { domWindow.navigator.userAgent.contains('OS 15_'); } -/// Detect if running on Chrome version 110 or older on Windows. +/// Detect if running on Chrome version 110 or older. /// -/// These versions of Chrome have a bug on Windows which causes -/// rendering to be flipped upside down. +/// These versions of Chrome have a bug which causes rendering to be flipped +/// upside down when using `createImageBitmap`: see +/// https://chromium.googlesource.com/chromium/src/+/a7f9b00e422a1755918f8ca5500380f98b6fddf2 // TODO(harryterkelsen): Remove this check once we stop supporting Chrome 110 // and earlier, https://github.com/flutter/flutter/issues/139186. -bool get isChrome110OrOlderOnWindows { - if (debugIsChrome110OrOlderOnWindows != null) { - return debugIsChrome110OrOlderOnWindows!; +bool get isChrome110OrOlder { + if (debugIsChrome110OrOlder != null) { + return debugIsChrome110OrOlder!; } - if (_cachedIsChrome110OrOlderOnWindows != null) { - return _cachedIsChrome110OrOlderOnWindows!; - } - if (operatingSystem != OperatingSystem.windows) { - return _cachedIsChrome110OrOlderOnWindows = false; + if (_cachedIsChrome110OrOlder != null) { + return _cachedIsChrome110OrOlder!; } final RegExp chromeRegexp = RegExp(r'Chrom(e|ium)\/([0-9]+)\.'); final RegExpMatch? match = chromeRegexp.firstMatch(domWindow.navigator.userAgent); if (match != null) { final int chromeVersion = int.parse(match.group(2)!); - return _cachedIsChrome110OrOlderOnWindows = chromeVersion <= 110; + return _cachedIsChrome110OrOlder = chromeVersion <= 110; } - return _cachedIsChrome110OrOlderOnWindows = false; + return _cachedIsChrome110OrOlder = false; } // Cache the result of checking if the app is running on Chrome 110 on Windows // since we check this on every frame. -bool? _cachedIsChrome110OrOlderOnWindows; +bool? _cachedIsChrome110OrOlder; /// If set to true pretends that the current browser is iOS Safari. /// @@ -267,7 +265,7 @@ bool get isWasm => const bool.fromEnvironment('dart.library.ffi'); bool? debugIsIOS15; /// Use in tests to simulated the detection of Chrome 110 or older on Windows. -bool? debugIsChrome110OrOlderOnWindows; +bool? debugIsChrome110OrOlder; int? _cachedWebGLVersion; diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/dom.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/dom.dart index 47c464a8de8..cd2d3a46c31 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/dom.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/dom.dart @@ -3674,7 +3674,7 @@ bool debugDisableCreateImageBitmapSupport = false; bool get browserSupportsCreateImageBitmap => _createImageBitmapFunction != null && - !isChrome110OrOlderOnWindows && + !isChrome110OrOlder && !debugDisableCreateImageBitmapSupport; @JS() diff --git a/engine/src/flutter/lib/web_ui/test/canvaskit/no_create_image_bitmap_test.dart b/engine/src/flutter/lib/web_ui/test/canvaskit/no_create_image_bitmap_test.dart index d23270e1e8a..8861e9c037f 100644 --- a/engine/src/flutter/lib/web_ui/test/canvaskit/no_create_image_bitmap_test.dart +++ b/engine/src/flutter/lib/web_ui/test/canvaskit/no_create_image_bitmap_test.dart @@ -24,7 +24,7 @@ void testMain() { tearDown(() { debugDisableCreateImageBitmapSupport = false; - debugIsChrome110OrOlderOnWindows = null; + debugIsChrome110OrOlder = null; }); test('can render without createImageBitmap', () async { @@ -69,7 +69,7 @@ void testMain() { test( 'createImageBitmap support is disabled on ' 'Windows on Chrome version 110 or older', () async { - debugIsChrome110OrOlderOnWindows = true; + debugIsChrome110OrOlder = true; debugDisableCreateImageBitmapSupport = false; expect(browserSupportsCreateImageBitmap, isFalse);