Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
Fix is canvas kit bool (#116944)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
alanwutang11 authored Dec 18, 2022
1 parent 49f3ca4 commit c0dddac
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 3 deletions.
5 changes: 5 additions & 0 deletions dev/bots/test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1177,6 +1177,11 @@ Future<void> _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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
});
}
Original file line number Diff line number Diff line change
@@ -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<void> main() async => test.integrationDriver();
Original file line number Diff line number Diff line change
@@ -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);
});
}
Original file line number Diff line number Diff line change
@@ -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<void> main() async => test.integrationDriver();
1 change: 1 addition & 0 deletions packages/flutter/lib/foundation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
10 changes: 10 additions & 0 deletions packages/flutter/lib/src/foundation/_capabilities_io.dart
Original file line number Diff line number Diff line change
@@ -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.');
}
13 changes: 13 additions & 0 deletions packages/flutter/lib/src/foundation/_capabilities_web.dart
Original file line number Diff line number Diff line change
@@ -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;
11 changes: 11 additions & 0 deletions packages/flutter/lib/src/foundation/capabilities.dart
Original file line number Diff line number Diff line change
@@ -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;
3 changes: 0 additions & 3 deletions packages/flutter/lib/src/foundation/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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');

0 comments on commit c0dddac

Please sign in to comment.