From c0dddacb811eda2971329a39742a4ec029d1034e Mon Sep 17 00:00:00 2001 From: alanwutang11 <50225138+alanwutang11@users.noreply.github.com> Date: Sat, 17 Dec 2022 23:33:32 -0800 Subject: [PATCH] Fix is canvas kit bool (#116944) * isCanvasKit implement and test * isCanvasKit implement and test * ++ * forgot license * make isCanvasKit a getter * addressed comments * forgot to change names of integration test files * typo * simplified tests * comments --- dev/bots/test.dart | 5 +++++ .../capabilities_integration_canvaskit.dart | 16 ++++++++++++++++ .../capabilities_integration_canvaskit_test.dart | 7 +++++++ .../capabilities_integration_html.dart | 15 +++++++++++++++ .../capabilities_integration_html_test.dart | 7 +++++++ packages/flutter/lib/foundation.dart | 1 + .../lib/src/foundation/_capabilities_io.dart | 10 ++++++++++ .../lib/src/foundation/_capabilities_web.dart | 13 +++++++++++++ .../flutter/lib/src/foundation/capabilities.dart | 11 +++++++++++ .../flutter/lib/src/foundation/constants.dart | 3 --- 10 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 dev/integration_tests/web_e2e_tests/test_driver/capabilities_integration_canvaskit.dart create mode 100644 dev/integration_tests/web_e2e_tests/test_driver/capabilities_integration_canvaskit_test.dart create mode 100644 dev/integration_tests/web_e2e_tests/test_driver/capabilities_integration_html.dart create mode 100644 dev/integration_tests/web_e2e_tests/test_driver/capabilities_integration_html_test.dart create mode 100644 packages/flutter/lib/src/foundation/_capabilities_io.dart create mode 100644 packages/flutter/lib/src/foundation/_capabilities_web.dart create mode 100644 packages/flutter/lib/src/foundation/capabilities.dart diff --git a/dev/bots/test.dart b/dev/bots/test.dart index dea990ae5089..52e2e31e6b5d 100644 --- a/dev/bots/test.dart +++ b/dev/bots/test.dart @@ -1177,6 +1177,11 @@ Future _runWebLongRunningTests() async { () => _runWebE2eTest('url_strategy_integration', buildMode: 'profile', renderer: 'canvaskit'), () => _runWebE2eTest('url_strategy_integration', buildMode: 'release', renderer: 'html'), + // This test doesn't do anything interesting w.r.t. rendering, so we don't run the full build mode x renderer matrix. + () => _runWebE2eTest('capabilities_integration_canvaskit', buildMode: 'debug', renderer: 'auto'), + () => _runWebE2eTest('capabilities_integration_canvaskit', buildMode: 'profile', renderer: 'canvaskit'), + () => _runWebE2eTest('capabilities_integration_html', buildMode: 'release', renderer: 'html'), + () => _runWebTreeshakeTest(), () => _runFlutterDriverWebTest( diff --git a/dev/integration_tests/web_e2e_tests/test_driver/capabilities_integration_canvaskit.dart b/dev/integration_tests/web_e2e_tests/test_driver/capabilities_integration_canvaskit.dart new file mode 100644 index 000000000000..2dbbfb58e0ab --- /dev/null +++ b/dev/integration_tests/web_e2e_tests/test_driver/capabilities_integration_canvaskit.dart @@ -0,0 +1,16 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:integration_test/integration_test.dart'; + +void main() { + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + + testWidgets('isCanvasKit returns true in CanvasKit mode', (WidgetTester tester) async { + await tester.pumpAndSettle(); + expect(isCanvasKit, true); + }); +} diff --git a/dev/integration_tests/web_e2e_tests/test_driver/capabilities_integration_canvaskit_test.dart b/dev/integration_tests/web_e2e_tests/test_driver/capabilities_integration_canvaskit_test.dart new file mode 100644 index 000000000000..b2d2a1770b2f --- /dev/null +++ b/dev/integration_tests/web_e2e_tests/test_driver/capabilities_integration_canvaskit_test.dart @@ -0,0 +1,7 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:integration_test/integration_test_driver.dart' as test; + +Future main() async => test.integrationDriver(); diff --git a/dev/integration_tests/web_e2e_tests/test_driver/capabilities_integration_html.dart b/dev/integration_tests/web_e2e_tests/test_driver/capabilities_integration_html.dart new file mode 100644 index 000000000000..1f0a11e339e5 --- /dev/null +++ b/dev/integration_tests/web_e2e_tests/test_driver/capabilities_integration_html.dart @@ -0,0 +1,15 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:integration_test/integration_test.dart'; +void main() { + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + + testWidgets('isCanvasKit returns false in HTML mode', (WidgetTester tester) async { + await tester.pumpAndSettle(); + expect(isCanvasKit, false); + }); +} diff --git a/dev/integration_tests/web_e2e_tests/test_driver/capabilities_integration_html_test.dart b/dev/integration_tests/web_e2e_tests/test_driver/capabilities_integration_html_test.dart new file mode 100644 index 000000000000..b2d2a1770b2f --- /dev/null +++ b/dev/integration_tests/web_e2e_tests/test_driver/capabilities_integration_html_test.dart @@ -0,0 +1,7 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:integration_test/integration_test_driver.dart' as test; + +Future main() async => test.integrationDriver(); diff --git a/packages/flutter/lib/foundation.dart b/packages/flutter/lib/foundation.dart index 40b35f205aee..dff7553436b3 100644 --- a/packages/flutter/lib/foundation.dart +++ b/packages/flutter/lib/foundation.dart @@ -24,6 +24,7 @@ export 'src/foundation/assertions.dart'; export 'src/foundation/basic_types.dart'; export 'src/foundation/binding.dart'; export 'src/foundation/bitfield.dart'; +export 'src/foundation/capabilities.dart'; export 'src/foundation/change_notifier.dart'; export 'src/foundation/collections.dart'; export 'src/foundation/consolidate_response.dart'; diff --git a/packages/flutter/lib/src/foundation/_capabilities_io.dart b/packages/flutter/lib/src/foundation/_capabilities_io.dart new file mode 100644 index 000000000000..202dc7ba00d4 --- /dev/null +++ b/packages/flutter/lib/src/foundation/_capabilities_io.dart @@ -0,0 +1,10 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/// The dart:io implementation of [isCanvasKit]. +/// +/// This bool shouldn't be used outside of web. +bool get isCanvasKit { + throw UnimplementedError('isCanvasKit is not implemented for dart:io.'); +} diff --git a/packages/flutter/lib/src/foundation/_capabilities_web.dart b/packages/flutter/lib/src/foundation/_capabilities_web.dart new file mode 100644 index 000000000000..5b5de845b1c9 --- /dev/null +++ b/packages/flutter/lib/src/foundation/_capabilities_web.dart @@ -0,0 +1,13 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:js/js.dart'; + +// This value is set by the engine. It is used to determine if the application is +// using canvaskit. +@JS('window.flutterCanvasKit') +external Object? get _windowFlutterCanvasKit; + +/// The web implementation of [isCanvasKit] +bool get isCanvasKit => _windowFlutterCanvasKit != null; diff --git a/packages/flutter/lib/src/foundation/capabilities.dart b/packages/flutter/lib/src/foundation/capabilities.dart new file mode 100644 index 000000000000..d2d6d81b70c7 --- /dev/null +++ b/packages/flutter/lib/src/foundation/capabilities.dart @@ -0,0 +1,11 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import '_capabilities_io.dart' + if (dart.library.js_util) '_capabilities_web.dart' as capabilities; + +/// Returns true if the application is using CanvasKit. +/// +/// Only to be used for web. +bool get isCanvasKit => capabilities.isCanvasKit; diff --git a/packages/flutter/lib/src/foundation/constants.dart b/packages/flutter/lib/src/foundation/constants.dart index 0e5ccb6e1ce9..576de1e22917 100644 --- a/packages/flutter/lib/src/foundation/constants.dart +++ b/packages/flutter/lib/src/foundation/constants.dart @@ -69,6 +69,3 @@ const double precisionErrorTolerance = 1e-10; /// A constant that is true if the application was compiled to run on the web. const bool kIsWeb = bool.fromEnvironment('dart.library.js_util'); - -/// A constant that is true if the application is using canvasKit -const bool isCanvasKit = bool.fromEnvironment('FLUTTER_WEB_USE_SKIA');