[flutter_tools] support toggling CanvasKit rendering on with 'k' (#52511)

This commit is contained in:
Jonah Williams
2020-03-13 07:02:34 -07:00
committed by GitHub
parent 9666f697fb
commit b3a37d0273
8 changed files with 97 additions and 6 deletions

View File

@@ -153,6 +153,12 @@ class CommandHelp {
'Toggle elevation checker.',
);
CommandHelpOption _k;
CommandHelpOption get k => _k ??= _makeOption(
'k',
'Toggle CanvasKit rendering.',
);
CommandHelpOption _makeOption(String key, String description, [
String inParenthesis = '',
]) {

View File

@@ -205,8 +205,9 @@ class WebAssetServer implements AssetReader {
return shelf.Response.notFound('');
}
// For real files, use a serialized file stat as a revision
final String etag = file.lastModifiedSync().toIso8601String();
// For real files, use a serialized file stat plus path as a revision.
// This allows us to update between canvaskit and non-canvaskit SDKs.
final String etag = file.lastModifiedSync().toIso8601String() + file.path;
if (ifNoneMatch == etag) {
return shelf.Response.notModified();
}
@@ -291,6 +292,9 @@ class WebAssetServer implements AssetReader {
return modules;
}
/// Whether to use the cavaskit SDK for rendering.
bool canvasKitRendering = false;
@visibleForTesting
final File dartSdk = globals.fs.file(globals.fs.path.join(
globals.artifacts.getArtifactPath(Artifact.flutterWebSdk),
@@ -299,6 +303,14 @@ class WebAssetServer implements AssetReader {
'dart_sdk.js',
));
@visibleForTesting
final File canvasKitDartSdk = globals.fs.file(globals.fs.path.join(
globals.artifacts.getArtifactPath(Artifact.flutterWebSdk),
'kernel',
'amd-canvaskit',
'dart_sdk.js',
));
@visibleForTesting
final File dartSdkSourcemap = globals.fs.file(globals.fs.path.join(
globals.artifacts.getArtifactPath(Artifact.flutterWebSdk),
@@ -307,14 +319,26 @@ class WebAssetServer implements AssetReader {
'dart_sdk.js.map',
));
@visibleForTesting
final File canvasKitDartSdkSourcemap = globals.fs.file(globals.fs.path.join(
globals.artifacts.getArtifactPath(Artifact.flutterWebSdk),
'kernel',
'amd-canvaskit',
'dart_sdk.js.map',
));
// Attempt to resolve `path` to a dart file.
File _resolveDartFile(String path) {
// Return the actual file objects so that local engine changes are automatically picked up.
switch (path) {
case '/dart_sdk.js':
return dartSdk;
case '.dart_sdk.js.map':
return dartSdkSourcemap;
return canvasKitRendering
? canvasKitDartSdk
: dartSdk;
case '/dart_sdk.js.map':
return canvasKitRendering
? canvasKitDartSdkSourcemap
: dartSdkSourcemap;
}
// If this is a dart file, it must be on the local file system and is
// likely coming from a source map request. The tool doesn't currently
@@ -405,7 +429,6 @@ class WebDevFS implements DevFS {
final bool enableDwds;
final bool testMode;
@visibleForTesting
WebAssetServer webAssetServer;
Dwds get dwds => webAssetServer.dwds;

View File

@@ -710,6 +710,16 @@ class _ResidentWebRunner extends ResidentWebRunner {
return 0;
}
@override
bool get supportsCanvasKit => supportsServiceProtocol;
@override
Future<void> toggleCanvaskit() async {
final WebDevFS webDevFS = device.devFS as WebDevFS;
webDevFS.webAssetServer.canvasKitRendering = !webDevFS.webAssetServer.canvasKitRendering;
await _wipConnection?.sendCommand('Page.reload');
}
@override
Future<void> exitApp() async {
await device.exitApps();

View File

@@ -665,6 +665,7 @@ abstract class ResidentRunner {
bool get isRunningProfile => debuggingOptions.buildInfo.isProfile;
bool get isRunningRelease => debuggingOptions.buildInfo.isRelease;
bool get supportsServiceProtocol => isRunningDebug || isRunningProfile;
bool get supportsCanvasKit => false;
// Returns the Uri of the first connected device for mobile,
// and only connected device for web.
@@ -724,6 +725,13 @@ abstract class ResidentRunner {
throw '${fullRestart ? 'Restart' : 'Reload'} is not supported in $mode mode';
}
/// Toggle whether canvaskit is being used for rendering.
///
/// Only supported on the web.
Future<void> toggleCanvaskit() {
throw Exception('Canvaskit not supported by this runner.');
}
/// The resident runner API for interaction with the reloadMethod vmservice
/// request.
///
@@ -1043,6 +1051,9 @@ abstract class ResidentRunner {
commandHelp.S.print();
commandHelp.U.print();
}
if (supportsCanvasKit){
commandHelp.k.print();
}
// `P` should precede `a`
commandHelp.P.print();
commandHelp.a.print();
@@ -1182,6 +1193,12 @@ class TerminalHandler {
return true;
}
return false;
case 'k':
if (residentRunner.supportsCanvasKit) {
await residentRunner.toggleCanvaskit();
return true;
}
return false;
case 'l':
final List<FlutterView> views = residentRunner.flutterDevices
.expand((FlutterDevice d) => d.views).toList();