[web] add FlutterConfiguration, use it to supply local CanvasKit files (flutter/engine#29056)
* [web] add FlutterConfiguration, use it to supply local CanvasKit files in tests
This commit is contained in:
@@ -513,6 +513,7 @@ FILE: ../../../flutter/lib/web_ui/lib/src/engine/canvaskit/vertices.dart
|
||||
FILE: ../../../flutter/lib/web_ui/lib/src/engine/canvaskit/viewport_metrics.dart
|
||||
FILE: ../../../flutter/lib/web_ui/lib/src/engine/clipboard.dart
|
||||
FILE: ../../../flutter/lib/web_ui/lib/src/engine/color_filter.dart
|
||||
FILE: ../../../flutter/lib/web_ui/lib/src/engine/configuration.dart
|
||||
FILE: ../../../flutter/lib/web_ui/lib/src/engine/dom_renderer.dart
|
||||
FILE: ../../../flutter/lib/web_ui/lib/src/engine/engine_canvas.dart
|
||||
FILE: ../../../flutter/lib/web_ui/lib/src/engine/font_change_util.dart
|
||||
|
||||
@@ -132,11 +132,11 @@ Future<void> _updateDepsFile(String cipdInstanceId) async {
|
||||
}
|
||||
|
||||
Future<void> _updateCanvaskitInitializationCode(String canvaskitVersion) async {
|
||||
const String kCanvasKitVersionKey = 'const String canvaskitVersion';
|
||||
const String kPathToInitializationCode = 'lib/src/engine/canvaskit/initialization.dart';
|
||||
const String kCanvasKitVersionKey = 'const String _canvaskitVersion';
|
||||
const String kPathToConfigurationCode = 'lib/src/engine/configuration.dart';
|
||||
final File initializationFile = File(pathlib.join(
|
||||
environment.webUiRootDir.path,
|
||||
kPathToInitializationCode,
|
||||
kPathToConfigurationCode,
|
||||
));
|
||||
final String originalInitializationCode = await initializationFile.readAsString();
|
||||
|
||||
@@ -146,7 +146,7 @@ Future<void> _updateCanvaskitInitializationCode(String canvaskitVersion) async {
|
||||
if (line.trim().startsWith(kCanvasKitVersionKey)) {
|
||||
canvaskitVersionFound = true;
|
||||
rewrittenCode.add(
|
||||
"const String canvaskitVersion = '$canvaskitVersion';",
|
||||
"const String _canvaskitVersion = '$canvaskitVersion';",
|
||||
);
|
||||
} else {
|
||||
rewrittenCode.add(line);
|
||||
@@ -155,11 +155,11 @@ Future<void> _updateCanvaskitInitializationCode(String canvaskitVersion) async {
|
||||
|
||||
if (!canvaskitVersionFound) {
|
||||
stderr.writeln(
|
||||
'Failed to update CanvasKit version in $kPathToInitializationCode.\n'
|
||||
'Failed to update CanvasKit version in $kPathToConfigurationCode.\n'
|
||||
'Could not to locate the constant that defines the version. Make sure the '
|
||||
'$kPathToInitializationCode file contains a line like this:\n'
|
||||
'$kPathToConfigurationCode file contains a line like this:\n'
|
||||
'\n'
|
||||
'const String canvaskitVersion = \'VERSION\';'
|
||||
'const String _canvaskitVersion = \'VERSION\';'
|
||||
);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -126,6 +126,9 @@ class BrowserPlatform extends PlatformPlugin {
|
||||
// * Assets that are part of the engine sources, such as Ahem.ttf
|
||||
.add(_packageUrlHandler)
|
||||
|
||||
// Serves CanvasKit assets.
|
||||
.add(_canvasKitHandler)
|
||||
|
||||
// Serves files from the web_ui/build/ directory at the root (/) URL path.
|
||||
//
|
||||
// Includes:
|
||||
@@ -310,6 +313,50 @@ class BrowserPlatform extends PlatformPlugin {
|
||||
write: write);
|
||||
}
|
||||
|
||||
/// Serves /canvaskit/* requests.
|
||||
///
|
||||
/// The requested path is rewritten to look for CanvasKit assets under:
|
||||
///
|
||||
/// ENGINE_ROOT/src/third_party/web_dependencies/canvaskit
|
||||
shelf.Response _canvasKitHandler(shelf.Request request) {
|
||||
if (!request.url.path.startsWith('canvaskit/')) {
|
||||
return shelf.Response.notFound('Not found.');
|
||||
}
|
||||
|
||||
final String filePath = p.join(
|
||||
env.environment.engineSrcDir.path,
|
||||
'third_party',
|
||||
'web_dependencies',
|
||||
request.url.path,
|
||||
);
|
||||
final File fileInPackage = File(filePath);
|
||||
if (!fileInPackage.existsSync()) {
|
||||
return shelf.Response.notFound('File not found: ${request.url.path}');
|
||||
}
|
||||
|
||||
final String extension = p.extension(filePath);
|
||||
final String contentType;
|
||||
switch (extension) {
|
||||
case '.js':
|
||||
contentType = 'text/javascript';
|
||||
break;
|
||||
case '.wasm':
|
||||
contentType = 'application/wasm';
|
||||
break;
|
||||
default:
|
||||
final String error = 'Failed to determine Content-Type for "${request.url.path}".';
|
||||
stderr.writeln(error);
|
||||
return shelf.Response.internalServerError(body: error);
|
||||
}
|
||||
|
||||
return shelf.Response.ok(
|
||||
fileInPackage.readAsBytesSync(),
|
||||
headers: <String, Object>{
|
||||
HttpHeaders.contentTypeHeader: contentType,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// Serves the HTML file that bootstraps the test.
|
||||
shelf.Response _testBootstrapHandler(shelf.Request request) {
|
||||
final String path = p.fromUri(request.url);
|
||||
@@ -326,6 +373,11 @@ class BrowserPlatform extends PlatformPlugin {
|
||||
<html>
|
||||
<head>
|
||||
<title>${htmlEscape.convert(test)} Test</title>
|
||||
<script>
|
||||
window.flutterConfiguration = {
|
||||
canvasKitBaseUrl: "/canvaskit/"
|
||||
};
|
||||
</script>
|
||||
$link
|
||||
<script src="packages/test/dart.js"></script>
|
||||
</head>
|
||||
|
||||
@@ -37,6 +37,8 @@ import 'package:meta/meta.dart';
|
||||
|
||||
import '../ui.dart' as ui;
|
||||
|
||||
// ignore: unused_import
|
||||
import 'engine/configuration.dart';
|
||||
import 'engine/dom_renderer.dart';
|
||||
import 'engine/keyboard.dart';
|
||||
import 'engine/mouse_cursor.dart';
|
||||
@@ -120,6 +122,8 @@ export 'engine/clipboard.dart';
|
||||
|
||||
export 'engine/color_filter.dart';
|
||||
|
||||
export 'engine/configuration.dart';
|
||||
|
||||
export 'engine/dom_renderer.dart';
|
||||
|
||||
export 'engine/engine_canvas.dart';
|
||||
|
||||
@@ -8,6 +8,7 @@ import 'dart:math' as math;
|
||||
import 'package:ui/ui.dart' as ui;
|
||||
|
||||
import '../../engine.dart' show NullTreeSanitizer, platformViewManager;
|
||||
import '../configuration.dart';
|
||||
import '../html/path_to_svg_clip.dart';
|
||||
import '../platform_views/slots.dart';
|
||||
import '../util.dart';
|
||||
@@ -27,19 +28,13 @@ class HtmlViewEmbedder {
|
||||
|
||||
HtmlViewEmbedder._();
|
||||
|
||||
/// The maximum number of overlay surfaces that can be live at once.
|
||||
static const int maximumSurfaces = int.fromEnvironment(
|
||||
'FLUTTER_WEB_MAXIMUM_SURFACES',
|
||||
defaultValue: 8,
|
||||
);
|
||||
|
||||
/// If `true`, overlay canvases are disabled.
|
||||
///
|
||||
/// This causes all drawing to go to a single canvas, with all of the platform
|
||||
/// views rendered over top. This may result in incorrect rendering with
|
||||
/// platform views.
|
||||
static bool get disableOverlays =>
|
||||
debugDisableOverlays || maximumSurfaces <= 1;
|
||||
debugDisableOverlays || configuration.canvasKitMaximumSurfaces <= 1;
|
||||
|
||||
/// Force the view embedder to disable overlays.
|
||||
///
|
||||
|
||||
@@ -12,6 +12,7 @@ import 'package:js/js.dart';
|
||||
|
||||
import '../../engine.dart' show kProfileMode;
|
||||
import '../browser_detection.dart';
|
||||
import '../configuration.dart';
|
||||
import '../dom_renderer.dart';
|
||||
import 'canvaskit_api.dart';
|
||||
import 'fonts.dart';
|
||||
@@ -22,7 +23,7 @@ import 'fonts.dart';
|
||||
external String? get requestedRendererType;
|
||||
|
||||
/// Whether to use CanvasKit as the rendering backend.
|
||||
bool get useCanvasKit => flutterWebAutoDetect ? _detectRenderer() : _useSkia;
|
||||
bool get useCanvasKit => FlutterConfiguration.flutterWebAutoDetect ? _detectRenderer() : FlutterConfiguration.useSkia;
|
||||
|
||||
/// Returns true if CanvasKit is used.
|
||||
///
|
||||
@@ -36,66 +37,9 @@ bool _detectRenderer() {
|
||||
return isDesktop;
|
||||
}
|
||||
|
||||
/// Auto detect which rendering backend to use.
|
||||
///
|
||||
/// Using flutter tools option "--web-render=auto" or not specifying one
|
||||
/// would set the value to true. Otherwise, it would be false.
|
||||
const bool flutterWebAutoDetect =
|
||||
bool.fromEnvironment('FLUTTER_WEB_AUTO_DETECT', defaultValue: true);
|
||||
|
||||
/// Enable the Skia-based rendering backend.
|
||||
///
|
||||
/// Using flutter tools option "--web-render=canvaskit" would set the value to
|
||||
/// true.
|
||||
/// Using flutter tools option "--web-render=html" would set the value to false.
|
||||
const bool _useSkia =
|
||||
bool.fromEnvironment('FLUTTER_WEB_USE_SKIA', defaultValue: false);
|
||||
|
||||
/// If set to true, forces CPU-only rendering (i.e. no WebGL).
|
||||
///
|
||||
/// This is mainly used for testing or for apps that want to ensure they
|
||||
/// run on devices which don't support WebGL.
|
||||
const bool canvasKitForceCpuOnly = bool.fromEnvironment(
|
||||
'FLUTTER_WEB_CANVASKIT_FORCE_CPU_ONLY',
|
||||
defaultValue: false);
|
||||
|
||||
/// The version of CanvasKit used by the web engine by default.
|
||||
// DO NOT EDIT THE NEXT LINE OF CODE MANUALLY
|
||||
// See `lib/web_ui/README.md` for how to roll CanvasKit to a new version.
|
||||
const String canvaskitVersion = '0.30.0';
|
||||
|
||||
/// The URL to use when downloading the CanvasKit script and associated wasm.
|
||||
///
|
||||
/// The expected directory structure nested under this URL is as follows:
|
||||
///
|
||||
/// /canvaskit.js - the release build of CanvasKit JS API bindings
|
||||
/// /canvaskit.wasm - the release build of CanvasKit WASM module
|
||||
/// /profiling/canvaskit.js - the profile build of CanvasKit JS API bindings
|
||||
/// /profiling/canvaskit.wasm - the profile build of CanvasKit WASM module
|
||||
///
|
||||
/// The base URL can be overridden using the `FLUTTER_WEB_CANVASKIT_URL`
|
||||
/// environment variable, which can be set in the Flutter tool using the
|
||||
/// `--dart-define` option. The value must end with a `/`.
|
||||
///
|
||||
/// Example:
|
||||
///
|
||||
/// ```
|
||||
/// flutter run \
|
||||
/// -d chrome \
|
||||
/// --web-renderer=canvaskit \
|
||||
/// --dart-define=FLUTTER_WEB_CANVASKIT_URL=https://example.com/custom-canvaskit-build/
|
||||
/// ```
|
||||
///
|
||||
/// When CanvasKit pushes a new release to NPM, update this URL to reflect the
|
||||
/// most recent version. For example, if CanvasKit releases version 0.34.0 to
|
||||
/// NPM, update this URL to `https://unpkg.com/canvaskit-wasm@0.34.0/bin/`.
|
||||
const String canvasKitBaseUrl = String.fromEnvironment(
|
||||
'FLUTTER_WEB_CANVASKIT_URL',
|
||||
defaultValue: 'https://unpkg.com/canvaskit-wasm@$canvaskitVersion/bin/',
|
||||
);
|
||||
const String canvasKitBuildUrl =
|
||||
canvasKitBaseUrl + (kProfileMode ? 'profiling/' : '');
|
||||
const String canvasKitJavaScriptBindingsUrl =
|
||||
String get canvasKitBuildUrl =>
|
||||
configuration.canvasKitBaseUrl + (kProfileMode ? 'profiling/' : '');
|
||||
String get canvasKitJavaScriptBindingsUrl =>
|
||||
canvasKitBuildUrl + 'canvaskit.js';
|
||||
String canvasKitWasmModuleUrl(String file) => _currentCanvasKitBase! + file;
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import 'dart:html' as html;
|
||||
import 'package:ui/ui.dart' as ui;
|
||||
|
||||
import '../browser_detection.dart';
|
||||
import '../configuration.dart';
|
||||
import '../platform_dispatcher.dart';
|
||||
import '../util.dart';
|
||||
import '../window.dart';
|
||||
@@ -295,7 +296,7 @@ class Surface {
|
||||
_forceNewContext = false;
|
||||
_contextLost = false;
|
||||
|
||||
if (webGLVersion != -1 && !canvasKitForceCpuOnly) {
|
||||
if (webGLVersion != -1 && !configuration.canvasKitForceCpuOnly) {
|
||||
final int glContext = canvasKit.GetWebGLContext(
|
||||
htmlCanvas,
|
||||
SkWebGLContextOptions(
|
||||
@@ -328,7 +329,7 @@ class Surface {
|
||||
if (webGLVersion == -1) {
|
||||
return _makeSoftwareCanvasSurface(
|
||||
htmlCanvas!, 'WebGL support not detected');
|
||||
} else if (canvasKitForceCpuOnly) {
|
||||
} else if (configuration.canvasKitForceCpuOnly) {
|
||||
return _makeSoftwareCanvasSurface(
|
||||
htmlCanvas!, 'CPU rendering forced by application');
|
||||
} else if (_glContext == 0) {
|
||||
|
||||
@@ -12,7 +12,7 @@ class SurfaceFactory {
|
||||
///
|
||||
/// [debugClear] causes this singleton to be reinitialized.
|
||||
static SurfaceFactory get instance =>
|
||||
_instance ??= SurfaceFactory(HtmlViewEmbedder.maximumSurfaces);
|
||||
_instance ??= SurfaceFactory(configuration.canvasKitMaximumSurfaces);
|
||||
|
||||
/// Returns the raw (potentially uninitialized) value of the singleton.
|
||||
///
|
||||
|
||||
171
engine/src/flutter/lib/web_ui/lib/src/engine/configuration.dart
Normal file
171
engine/src/flutter/lib/web_ui/lib/src/engine/configuration.dart
Normal file
@@ -0,0 +1,171 @@
|
||||
// Copyright 2013 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.
|
||||
|
||||
/// JavaScript API a Flutter Web application can use to configure the Web
|
||||
/// Engine.
|
||||
///
|
||||
/// The configuration is a plain JavaScript object set as the
|
||||
/// `flutterConfiguration` property of the top-level `window` object.
|
||||
///
|
||||
/// Example:
|
||||
///
|
||||
/// <head>
|
||||
/// <script>
|
||||
/// window.flutterConfiguration = {
|
||||
/// canvasKitBaseUrl: "https://example.com/my-custom-canvaskit/"
|
||||
/// };
|
||||
/// </script>
|
||||
/// </head>
|
||||
///
|
||||
/// Configuration properties supplied via `window.flutterConfiguration`
|
||||
/// override those supplied using the corresponding environment variables. For
|
||||
/// example, if both `window.flutterConfiguration.canvasKitBaseUrl` and the
|
||||
/// `FLUTTER_WEB_CANVASKIT_URL` environment variables are provided,
|
||||
/// `window.flutterConfiguration.canvasKitBaseUrl` is used.
|
||||
|
||||
@JS()
|
||||
library configuration;
|
||||
|
||||
import 'package:js/js.dart';
|
||||
|
||||
/// The version of CanvasKit used by the web engine by default.
|
||||
// DO NOT EDIT THE NEXT LINE OF CODE MANUALLY
|
||||
// See `lib/web_ui/README.md` for how to roll CanvasKit to a new version.
|
||||
const String _canvaskitVersion = '0.30.0';
|
||||
|
||||
/// The Web Engine configuration for the current application.
|
||||
FlutterConfiguration get configuration => _configuration ??= FlutterConfiguration(_jsConfiguration);
|
||||
FlutterConfiguration? _configuration;
|
||||
|
||||
/// Sets the given configuration as the current one.
|
||||
///
|
||||
/// This must be called before the engine is initialized. Calling it after the
|
||||
/// engine is initialized will result in some of the properties not taking
|
||||
/// effect because they are consumed during initialization.
|
||||
void debugSetConfiguration(FlutterConfiguration configuration) {
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
/// Supplies Web Engine configuration properties.
|
||||
class FlutterConfiguration {
|
||||
/// Constructs a configuration from a JavaScript object containing
|
||||
/// runtime-supplied properties.
|
||||
FlutterConfiguration(this._js);
|
||||
|
||||
final JsFlutterConfiguration? _js;
|
||||
|
||||
// Static constant parameters.
|
||||
//
|
||||
// These properties affect tree shaking and therefore cannot be supplied at
|
||||
// runtime. They must be static constants for the compiler to remove dead
|
||||
// effectively.
|
||||
|
||||
/// Auto detect which rendering backend to use.
|
||||
///
|
||||
/// Using flutter tools option "--web-render=auto" or not specifying one
|
||||
/// would set the value to true. Otherwise, it would be false.
|
||||
static const bool flutterWebAutoDetect =
|
||||
bool.fromEnvironment('FLUTTER_WEB_AUTO_DETECT', defaultValue: true);
|
||||
|
||||
/// Enable the Skia-based rendering backend.
|
||||
///
|
||||
/// Using flutter tools option "--web-render=canvaskit" would set the value to
|
||||
/// true.
|
||||
///
|
||||
/// Using flutter tools option "--web-render=html" would set the value to false.
|
||||
static const bool useSkia =
|
||||
bool.fromEnvironment('FLUTTER_WEB_USE_SKIA', defaultValue: false);
|
||||
|
||||
|
||||
// Runtime parameters.
|
||||
//
|
||||
// These parameters can be supplied either as environment variables, or at
|
||||
// runtime. Runtime-supplied values take precedence over environment
|
||||
// variables.
|
||||
|
||||
/// The URL to use when downloading the CanvasKit script and associated wasm.
|
||||
///
|
||||
/// The expected directory structure nested under this URL is as follows:
|
||||
///
|
||||
/// /canvaskit.js - the release build of CanvasKit JS API bindings
|
||||
/// /canvaskit.wasm - the release build of CanvasKit WASM module
|
||||
/// /profiling/canvaskit.js - the profile build of CanvasKit JS API bindings
|
||||
/// /profiling/canvaskit.wasm - the profile build of CanvasKit WASM module
|
||||
///
|
||||
/// The base URL can be overridden using the `FLUTTER_WEB_CANVASKIT_URL`
|
||||
/// environment variable or using the configuration API for JavaScript.
|
||||
///
|
||||
/// When specifying using the environment variable set it in the Flutter tool
|
||||
/// using the `--dart-define` option. The value must end with a `/`.
|
||||
///
|
||||
/// Example:
|
||||
///
|
||||
/// ```
|
||||
/// flutter run \
|
||||
/// -d chrome \
|
||||
/// --web-renderer=canvaskit \
|
||||
/// --dart-define=FLUTTER_WEB_CANVASKIT_URL=https://example.com/custom-canvaskit-build/
|
||||
/// ```
|
||||
String get canvasKitBaseUrl => _js?.canvasKitBaseUrl ?? _defaultCanvasKitBaseUrl;
|
||||
static const String _defaultCanvasKitBaseUrl = String.fromEnvironment(
|
||||
'FLUTTER_WEB_CANVASKIT_URL',
|
||||
defaultValue: 'https://unpkg.com/canvaskit-wasm@$_canvaskitVersion/bin/',
|
||||
);
|
||||
|
||||
/// If set to true, forces CPU-only rendering in CanvasKit (i.e. the engine
|
||||
/// won't use WebGL).
|
||||
///
|
||||
/// This is mainly used for testing or for apps that want to ensure they
|
||||
/// run on devices which don't support WebGL.
|
||||
bool get canvasKitForceCpuOnly => _js?.canvasKitForceCpuOnly ?? _defaultCanvasKitForceCpuOnly;
|
||||
static const bool _defaultCanvasKitForceCpuOnly = bool.fromEnvironment(
|
||||
'FLUTTER_WEB_CANVASKIT_FORCE_CPU_ONLY',
|
||||
defaultValue: false,
|
||||
);
|
||||
|
||||
/// The maximum number of overlay surfaces that the CanvasKit renderer will use.
|
||||
///
|
||||
/// Overlay surfaces are extra WebGL `<canvas>` elements used to paint on top
|
||||
/// of platform views. Too many platform views can cause the browser to run
|
||||
/// out of resources (memory, CPU, GPU) to handle the content efficiently.
|
||||
/// The number of overlay surfaces is therefore limited.
|
||||
///
|
||||
/// This value can be specified using either the `FLUTTER_WEB_MAXIMUM_SURFACES`
|
||||
/// environment variable, or using the runtime configuration.
|
||||
int get canvasKitMaximumSurfaces => _js?.canvasKitMaximumSurfaces ?? _defaultCanvasKitMaximumSurfaces;
|
||||
static const int _defaultCanvasKitMaximumSurfaces = int.fromEnvironment(
|
||||
'FLUTTER_WEB_MAXIMUM_SURFACES',
|
||||
defaultValue: 8,
|
||||
);
|
||||
|
||||
/// Set this flag to `true` to cause the engine to visualize the semantics tree
|
||||
/// on the screen for debugging.
|
||||
///
|
||||
/// This only works in profile and release modes. Debug mode does not support
|
||||
/// passing compile-time constants.
|
||||
///
|
||||
/// Example:
|
||||
///
|
||||
/// ```
|
||||
/// flutter run -d chrome --profile --dart-define=FLUTTER_WEB_DEBUG_SHOW_SEMANTICS=true
|
||||
/// ```
|
||||
bool get debugShowSemanticsNodes => _js?.debugShowSemanticsNodes ?? _defaultDebugShowSemanticsNodes;
|
||||
static const bool _defaultDebugShowSemanticsNodes = bool.fromEnvironment(
|
||||
'FLUTTER_WEB_DEBUG_SHOW_SEMANTICS',
|
||||
defaultValue: false,
|
||||
);
|
||||
}
|
||||
|
||||
@JS('window.flutterConfiguration')
|
||||
external JsFlutterConfiguration? get _jsConfiguration;
|
||||
|
||||
/// The JS bindings for the object that's set as `window.flutterConfiguration`.
|
||||
@JS()
|
||||
@anonymous
|
||||
class JsFlutterConfiguration {
|
||||
external String? get canvasKitBaseUrl;
|
||||
external bool? get canvasKitForceCpuOnly;
|
||||
external int? get canvasKitMaximumSurfaces;
|
||||
external bool? get debugShowSemanticsNodes;
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import 'package:ui/ui.dart' as ui;
|
||||
import '../engine.dart' show buildMode, registerHotRestartListener;
|
||||
import 'browser_detection.dart';
|
||||
import 'canvaskit/initialization.dart';
|
||||
import 'configuration.dart';
|
||||
import 'host_node.dart';
|
||||
import 'keyboard_binding.dart';
|
||||
import 'platform_dispatcher.dart';
|
||||
@@ -294,7 +295,7 @@ class DomRenderer {
|
||||
setElementAttribute(
|
||||
bodyElement,
|
||||
'flt-renderer',
|
||||
'${useCanvasKit ? 'canvaskit' : 'html'} (${flutterWebAutoDetect ? 'auto-selected' : 'requested explicitly'})',
|
||||
'${useCanvasKit ? 'canvaskit' : 'html'} (${FlutterConfiguration.flutterWebAutoDetect ? 'auto-selected' : 'requested explicitly'})',
|
||||
);
|
||||
setElementAttribute(bodyElement, 'flt-build-mode', buildMode);
|
||||
|
||||
@@ -401,7 +402,7 @@ class DomRenderer {
|
||||
|
||||
// When debugging semantics, make the scene semi-transparent so that the
|
||||
// semantics tree is visible.
|
||||
if (debugShowSemanticsNodes) {
|
||||
if (configuration.debugShowSemanticsNodes) {
|
||||
_sceneHostElement!.style.opacity = '0.3';
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import 'dart:html' as html;
|
||||
|
||||
import 'package:ui/ui.dart' as ui;
|
||||
|
||||
import '../configuration.dart';
|
||||
import 'semantics.dart';
|
||||
|
||||
/// Renders [_label] and [_value] to the semantics DOM.
|
||||
@@ -107,7 +108,7 @@ class LabelAndValue extends RoleManager {
|
||||
// Normally use a small font size so that text doesn't leave the scope
|
||||
// of the semantics node. When debugging semantics, use a font size
|
||||
// that's reasonably visible.
|
||||
_auxiliaryValueElement!.style.fontSize = debugShowSemanticsNodes ? '12px' : '6px';
|
||||
_auxiliaryValueElement!.style.fontSize = configuration.debugShowSemanticsNodes ? '12px' : '6px';
|
||||
semanticsObject.element.append(_auxiliaryValueElement!);
|
||||
}
|
||||
_auxiliaryValueElement!.text = combinedValue.toString();
|
||||
|
||||
@@ -11,6 +11,7 @@ import 'package:ui/ui.dart' as ui;
|
||||
import '../../engine.dart' show registerHotRestartListener;
|
||||
import '../alarm_clock.dart';
|
||||
import '../browser_detection.dart';
|
||||
import '../configuration.dart';
|
||||
import '../dom_renderer.dart';
|
||||
import '../platform_dispatcher.dart';
|
||||
import '../util.dart';
|
||||
@@ -25,22 +26,6 @@ import 'semantics_helper.dart';
|
||||
import 'tappable.dart';
|
||||
import 'text_field.dart';
|
||||
|
||||
/// Set this flag to `true` to cause the engine to visualize the semantics tree
|
||||
/// on the screen for debugging.
|
||||
///
|
||||
/// This only works in profile and release modes. Debug mode does not support
|
||||
/// passing compile-time constants.
|
||||
///
|
||||
/// Example:
|
||||
///
|
||||
/// ```
|
||||
/// flutter run -d chrome --profile --dart-define=FLUTTER_WEB_DEBUG_SHOW_SEMANTICS=true
|
||||
/// ```
|
||||
const bool debugShowSemanticsNodes = bool.fromEnvironment(
|
||||
'FLUTTER_WEB_DEBUG_SHOW_SEMANTICS',
|
||||
defaultValue: false,
|
||||
);
|
||||
|
||||
/// Contains updates for the semantics tree.
|
||||
///
|
||||
/// This class provides private engine-side API that's not available in the
|
||||
@@ -291,7 +276,7 @@ class SemanticsObject {
|
||||
element.style.position = 'absolute';
|
||||
|
||||
// The root node has some properties that other nodes do not.
|
||||
if (id == 0 && !debugShowSemanticsNodes) {
|
||||
if (id == 0 && !configuration.debugShowSemanticsNodes) {
|
||||
// Make all semantics transparent. We use `filter` instead of `opacity`
|
||||
// attribute because `filter` is stronger. `opacity` does not apply to
|
||||
// some elements, particularly on iOS, such as the slider thumb and track.
|
||||
@@ -308,7 +293,7 @@ class SemanticsObject {
|
||||
// Make semantic elements visible for debugging by outlining them using a
|
||||
// green border. We do not use `border` attribute because it affects layout
|
||||
// (`outline` does not).
|
||||
if (debugShowSemanticsNodes) {
|
||||
if (configuration.debugShowSemanticsNodes) {
|
||||
element.style.outline = '1px solid green';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,7 +213,7 @@ void testMain() {
|
||||
|
||||
// Initialize all platform views to be used in the test.
|
||||
final List<int> platformViewIds = <int>[];
|
||||
for (int i = 0; i < HtmlViewEmbedder.maximumSurfaces * 2; i++) {
|
||||
for (int i = 0; i < configuration.canvasKitMaximumSurfaces * 2; i++) {
|
||||
ui.platformViewRegistry.registerViewFactory(
|
||||
'test-platform-view',
|
||||
(int viewId) => html.DivElement()..id = 'view-$i',
|
||||
@@ -242,8 +242,8 @@ void testMain() {
|
||||
// Frame 1:
|
||||
// Render: up to cache size platform views.
|
||||
// Expect: main canvas plus platform view overlays.
|
||||
renderTestScene(viewCount: HtmlViewEmbedder.maximumSurfaces);
|
||||
expect(countCanvases(), HtmlViewEmbedder.maximumSurfaces);
|
||||
renderTestScene(viewCount: configuration.canvasKitMaximumSurfaces);
|
||||
expect(countCanvases(), configuration.canvasKitMaximumSurfaces);
|
||||
|
||||
// Frame 2:
|
||||
// Render: zero platform views.
|
||||
@@ -256,15 +256,15 @@ void testMain() {
|
||||
// Render: less than cache size platform views.
|
||||
// Expect: overlays reused.
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
renderTestScene(viewCount: HtmlViewEmbedder.maximumSurfaces - 2);
|
||||
expect(countCanvases(), HtmlViewEmbedder.maximumSurfaces - 1);
|
||||
renderTestScene(viewCount: configuration.canvasKitMaximumSurfaces - 2);
|
||||
expect(countCanvases(), configuration.canvasKitMaximumSurfaces - 1);
|
||||
|
||||
// Frame 4:
|
||||
// Render: more platform views than max cache size.
|
||||
// Expect: main canvas, backup overlay, maximum overlays.
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
renderTestScene(viewCount: HtmlViewEmbedder.maximumSurfaces * 2);
|
||||
expect(countCanvases(), HtmlViewEmbedder.maximumSurfaces);
|
||||
renderTestScene(viewCount: configuration.canvasKitMaximumSurfaces * 2);
|
||||
expect(countCanvases(), configuration.canvasKitMaximumSurfaces);
|
||||
|
||||
// Frame 5:
|
||||
// Render: zero platform views.
|
||||
@@ -346,21 +346,21 @@ void testMain() {
|
||||
// Render: Views 1-10
|
||||
// Expect: main canvas plus platform view overlays; empty cache.
|
||||
renderTestScene(<int>[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
|
||||
expect(countCanvases(), HtmlViewEmbedder.maximumSurfaces);
|
||||
expect(countCanvases(), configuration.canvasKitMaximumSurfaces);
|
||||
|
||||
// Frame 2:
|
||||
// Render: Views 2-11
|
||||
// Expect: main canvas plus platform view overlays; empty cache.
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
renderTestScene(<int>[2, 3, 4, 5, 6, 7, 8, 9, 10, 11]);
|
||||
expect(countCanvases(), HtmlViewEmbedder.maximumSurfaces);
|
||||
expect(countCanvases(), configuration.canvasKitMaximumSurfaces);
|
||||
|
||||
// Frame 3:
|
||||
// Render: Views 3-12
|
||||
// Expect: main canvas plus platform view overlays; empty cache.
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
renderTestScene(<int>[3, 4, 5, 6, 7, 8, 9, 10, 11, 12]);
|
||||
expect(countCanvases(), HtmlViewEmbedder.maximumSurfaces);
|
||||
expect(countCanvases(), configuration.canvasKitMaximumSurfaces);
|
||||
|
||||
// TODO(yjbanov): skipped due to https://github.com/flutter/flutter/issues/73867
|
||||
}, skip: isSafari);
|
||||
|
||||
Reference in New Issue
Block a user