Skip to content

Commit

Permalink
Skwasm scene (flutter#40330)
Browse files Browse the repository at this point in the history
Skwasm scene
  • Loading branch information
eyebrowsoffire authored and zhongwuzw committed Apr 14, 2023
1 parent e180d60 commit f164d10
Show file tree
Hide file tree
Showing 53 changed files with 1,412 additions and 159 deletions.
8 changes: 8 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -1992,12 +1992,15 @@ ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/services/serialization.dart +
ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/shadow.dart + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl.dart + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/canvas.dart + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/font_collection.dart + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/image.dart + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/layers.dart + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/paint.dart + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/paragraph.dart + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/path.dart + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/path_metrics.dart + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/picture.dart + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/raw/js_functions.dart + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/raw/raw_canvas.dart + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/raw/raw_geometry.dart + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/raw/raw_memory.dart + ../../../flutter/LICENSE
Expand All @@ -2007,6 +2010,7 @@ ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/raw/raw_pa
ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/raw/raw_picture.dart + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/raw/raw_surface.dart + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/renderer.dart + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/scene_builder.dart + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/surface.dart + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/vertices.dart + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_stub.dart + ../../../flutter/LICENSE
Expand Down Expand Up @@ -4576,12 +4580,15 @@ FILE: ../../../flutter/lib/web_ui/lib/src/engine/services/serialization.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/shadow.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/canvas.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/font_collection.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/image.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/layers.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/paint.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/paragraph.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/path.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/path_metrics.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/picture.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/raw/js_functions.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/raw/raw_canvas.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/raw/raw_geometry.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/raw/raw_memory.dart
Expand All @@ -4591,6 +4598,7 @@ FILE: ../../../flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/raw/raw_path
FILE: ../../../flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/raw/raw_picture.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/raw/raw_surface.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/renderer.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/scene_builder.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/surface.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/vertices.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_stub.dart
Expand Down
18 changes: 13 additions & 5 deletions lib/web_ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ all web engine targets are built. Common targets are as follows:
The output of these steps is used in unit tests, and can be used with the flutter
command via the `--local-web-sdk=wasm_release` command.

The `build` command also accepts either the `--profile` or `--debug` flags, which
can be used to change the build profile of the artifacts.

##### Examples
Builds all web engine targets, then runs a Flutter app using it:
```
Expand All @@ -54,14 +57,19 @@ information on how test suites are structured, see the test configuration

By default, `felt test` compiles and runs all suites that are compatible with the
host system. Some useful flags supported by this command:
* `--compile` will only perform compilation of these suites without running them.
* `--run` will only run the tests and not compile them, and assume they have been
compiled in a previous run of the tool.
* Action flags which say what parts of the test pipeline to perform. More of one
of these can be specified to run multiple actions. If none are specified, then
*all* of these actions are performed
* `--compile` performs compilation of the test bundles.
* `--run` runs the unit tests
* `--copy-artifacts` will copy build artifacts needed for the tests to run.
* The `--profile` or `--debug` flags can be specified to copy over artifacts
from the profile or debug build folders instead of release.
* `--list` will list all the test suites and test bundles and exit without
compiling or running anything.
* `--verbose` will output some extra information that may be useful for debugging.
* `--debug` will open a browser window and pause the tests before starting so that
breakpoints can be set before starting the test suites.
* `--start-paused` will open a browser window and pause the tests before starting
so that breakpoints can be set before starting the test suites.

Several other flags can be passed that filter which test suites should be run:
* `--browser` runs only the test suites that test on the browsers passed. Valid
Expand Down
32 changes: 8 additions & 24 deletions lib/web_ui/dev/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ import 'environment.dart';
import 'pipeline.dart';
import 'utils.dart';

enum RuntimeMode {
profile,
release,
}

const Map<String, String> targetAliases = <String, String>{
'sdk': 'flutter/web_sdk',
'web_sdk': 'flutter/web_sdk',
Expand Down Expand Up @@ -45,6 +40,12 @@ class BuildCommand extends Command<bool> with ArgUtils<bool> {
'output will be located at "out/wasm_profile".\nThis only applies to '
'the wasm build. The host build is always built in release mode.',
);
argParser.addFlag(
'debug',
help: 'Build in debug mode instead of release mode. In this mode, the '
'output will be located at "out/wasm_debug".\nThis only applies to '
'the wasm build. The host build is always built in release mode.',
);
}

@override
Expand All @@ -57,9 +58,6 @@ class BuildCommand extends Command<bool> with ArgUtils<bool> {

bool get host => boolArg('host');

RuntimeMode get runtimeMode =>
boolArg('profile') ? RuntimeMode.profile : RuntimeMode.release;

List<String> get targets => argResults?.rest ?? <String>[];

@override
Expand Down Expand Up @@ -112,15 +110,6 @@ class GnPipelineStep extends ProcessStep {
@override
bool get isSafeToInterrupt => false;

String get runtimeModeFlag {
switch (runtimeMode) {
case RuntimeMode.profile:
return 'profile';
case RuntimeMode.release:
return 'release';
}
}

List<String> get _gnArgs {
if (host) {
return <String>[
Expand All @@ -130,7 +119,7 @@ class GnPipelineStep extends ProcessStep {
} else {
return <String>[
'--web',
'--runtime-mode=$runtimeModeFlag',
'--runtime-mode=${runtimeMode.name}',
];
}
}
Expand Down Expand Up @@ -169,12 +158,7 @@ class NinjaPipelineStep extends ProcessStep {
if (host) {
return environment.hostDebugUnoptDir.path;
}
switch (runtimeMode) {
case RuntimeMode.profile:
return environment.wasmProfileOutDir.path;
case RuntimeMode.release:
return environment.wasmReleaseOutDir.path;
}
return getBuildDirectoryForRuntimeMode(runtimeMode).path;
}

@override
Expand Down
7 changes: 7 additions & 0 deletions lib/web_ui/dev/environment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class Environment {
io.Directory(pathlib.join(outDir.path, 'wasm_release'));
final io.Directory wasmProfileOutDir =
io.Directory(pathlib.join(outDir.path, 'wasm_profile'));
final io.Directory wasmDebugOutDir =
io.Directory(pathlib.join(outDir.path, 'wasm_debug'));
final io.Directory hostDebugUnoptDir =
io.Directory(pathlib.join(outDir.path, 'host_debug_unopt'));
final io.Directory dartSdkDir = dartExecutable.parent.parent;
Expand All @@ -57,6 +59,7 @@ class Environment {
outDir: outDir,
wasmReleaseOutDir: wasmReleaseOutDir,
wasmProfileOutDir: wasmProfileOutDir,
wasmDebugOutDir: wasmDebugOutDir,
hostDebugUnoptDir: hostDebugUnoptDir,
dartSdkDir: dartSdkDir,
);
Expand All @@ -71,6 +74,7 @@ class Environment {
required this.outDir,
required this.wasmReleaseOutDir,
required this.wasmProfileOutDir,
required this.wasmDebugOutDir,
required this.hostDebugUnoptDir,
required this.dartSdkDir,
});
Expand Down Expand Up @@ -103,6 +107,9 @@ class Environment {
/// The output directory for the wasm_profile build.
final io.Directory wasmProfileOutDir;

/// The output directory for the wasm_debug build.
final io.Directory wasmDebugOutDir;

/// The output directory for the host_debug_unopt build.
final io.Directory hostDebugUnoptDir;

Expand Down
8 changes: 3 additions & 5 deletions lib/web_ui/dev/steps/copy_artifacts_step.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import '../pipeline.dart';
import '../utils.dart';

class CopyArtifactsStep implements PipelineStep {
CopyArtifactsStep(this.artifactDeps, { required this.isProfile });
CopyArtifactsStep(this.artifactDeps, { required this.runtimeMode });

final ArtifactDependencies artifactDeps;
final bool isProfile;
final RuntimeMode runtimeMode;

@override
String get description => 'copy_artifacts';
Expand Down Expand Up @@ -167,9 +167,7 @@ class CopyArtifactsStep implements PipelineStep {
}
}

String get outBuildPath => isProfile
? environment.wasmProfileOutDir.path
: environment.wasmReleaseOutDir.path;
String get outBuildPath => getBuildDirectoryForRuntimeMode(runtimeMode).path;

Future<void> copySkwasm() async {
final io.Directory targetDir = io.Directory(pathlib.join(
Expand Down
8 changes: 4 additions & 4 deletions lib/web_ui/dev/steps/run_suite_step.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import '../utils.dart';
/// them from another bot.
class RunSuiteStep implements PipelineStep {
RunSuiteStep(this.suite, {
required this.isDebug,
required this.startPaused,
required this.isVerbose,
required this.doUpdateScreenshotGoldens,
required this.requireSkiaGold,
Expand All @@ -39,7 +39,7 @@ class RunSuiteStep implements PipelineStep {

final TestSuite suite;
final Set<FilePath>? testFiles;
final bool isDebug;
final bool startPaused;
final bool isVerbose;
final bool doUpdateScreenshotGoldens;
final String? overridePathToCanvasKit;
Expand Down Expand Up @@ -76,7 +76,7 @@ class RunSuiteStep implements PipelineStep {
...<String>['-r', 'compact'],
// Disable concurrency. Running with concurrency proved to be flaky.
'--concurrency=1',
if (isDebug) '--pause-after-load',
if (startPaused) '--pause-after-load',
'--platform=${browserEnvironment.packageTestRuntime.identifier}',
'--precompiled=$bundleBuildPath',
'--configuration=$configurationFilePath',
Expand Down Expand Up @@ -173,7 +173,7 @@ class RunSuiteStep implements PipelineStep {
final Renderer renderer = suite.testBundle.compileConfig.renderer;
final CanvasKitVariant? variant = suite.runConfig.variant;
final SkiaGoldClient skiaClient = SkiaGoldClient(
environment.webUiSkiaGoldDirectory,
getSkiaGoldDirectoryForSuite(suite),
dimensions: <String, String> {
'Browser': suite.runConfig.browser.name,
if (isWasm) 'Wasm': 'true',
Expand Down
1 change: 1 addition & 0 deletions lib/web_ui/dev/test_dart2wasm.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ window.onload = async function () {
document.body.appendChild(skwasmScript);
skwasmScript.addEventListener('load', async () => {
const skwasmInstance = await skwasm();
window._flutter_skwasmInstance = skwasmInstance;
resolve({
"skwasm": skwasmInstance.asm,
"ffi": {
Expand Down
1 change: 1 addition & 0 deletions lib/web_ui/dev/test_platform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ class BrowserPlatform extends PlatformPlugin {
screenshot,
doUpdateScreenshotGoldens,
filename,
getSkiaGoldDirectoryForSuite(suite),
skiaClient,
isCanvaskitTest: isCanvaskitTest,
verbose: isVerbose,
Expand Down
13 changes: 9 additions & 4 deletions lib/web_ui/dev/test_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class TestCommand extends Command<bool> with ArgUtils<bool> {
TestCommand() {
argParser
..addFlag(
'debug',
'start-paused',
help: 'Pauses the browser before running a test, giving you an '
'opportunity to add breakpoints or inspect loaded code before '
'running the code.',
Expand Down Expand Up @@ -80,6 +80,11 @@ class TestCommand extends Command<bool> with ArgUtils<bool> {
help:
'Use artifacts from the profile build instead of release.'
)
..addFlag(
'debug',
help:
'Use artifacts from the debug build instead of release.'
)
..addFlag(
'require-skia-gold',
help:
Expand Down Expand Up @@ -152,7 +157,7 @@ class TestCommand extends Command<bool> with ArgUtils<bool> {
///
/// In this mode the browser pauses before running the test to allow
/// you set breakpoints or inspect the code.
bool get isDebug => boolArg('debug');
bool get startPaused => boolArg('start-paused');

bool get isVerbose => boolArg('verbose');

Expand Down Expand Up @@ -364,7 +369,7 @@ class TestCommand extends Command<bool> with ArgUtils<bool> {
final Set<FilePath>? testFiles = targetFiles.isEmpty ? null : Set<FilePath>.from(targetFiles);
final Pipeline testPipeline = Pipeline(steps: <PipelineStep>[
if (isWatchMode) ClearTerminalScreenStep(),
if (shouldCopyArtifacts) CopyArtifactsStep(artifacts, isProfile: boolArg('profile')),
if (shouldCopyArtifacts) CopyArtifactsStep(artifacts, runtimeMode: runtimeMode),
if (shouldCompile)
for (final TestBundle bundle in bundles)
CompileBundleStep(
Expand All @@ -376,7 +381,7 @@ class TestCommand extends Command<bool> with ArgUtils<bool> {
for (final TestSuite suite in filteredSuites)
RunSuiteStep(
suite,
isDebug: isDebug,
startPaused: startPaused,
isVerbose: isVerbose,
doUpdateScreenshotGoldens: doUpdateScreenshotGoldens,
requireSkiaGold: requireSkiaGold,
Expand Down
37 changes: 37 additions & 0 deletions lib/web_ui/dev/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ import 'environment.dart';
import 'exceptions.dart';
import 'felt_config.dart';

enum RuntimeMode {
debug,
profile,
release,
}

class FilePath {
FilePath.fromCwd(String relativePath)
: _absolutePath = path.absolute(relativePath);
Expand Down Expand Up @@ -328,8 +334,30 @@ mixin ArgUtils<T> on Command<T> {

/// Extracts a string argument from [argResults].
String stringArg(String name) => argResults![name] as String;

RuntimeMode get runtimeMode {
final bool isProfile = boolArg('profile');
final bool isDebug = boolArg('debug');
if (isProfile && isDebug) {
throw ToolExit('Cannot specify both --profile and --debug at the same time.');
}
if (isProfile) {
return RuntimeMode.profile;
} else if (isDebug) {
return RuntimeMode.debug;
} else {
return RuntimeMode.release;
}
}
}

io.Directory getBuildDirectoryForRuntimeMode(RuntimeMode runtimeMode) =>
switch (runtimeMode) {
RuntimeMode.debug => environment.wasmDebugOutDir,
RuntimeMode.profile => environment.wasmProfileOutDir,
RuntimeMode.release => environment.wasmReleaseOutDir,
};

/// There might be proccesses started during the tests.
///
/// Use this list to store those Processes, for cleaning up before shutdown.
Expand Down Expand Up @@ -390,6 +418,15 @@ io.Directory getBundleBuildDirectory(TestBundle bundle) {
);
}

io.Directory getSkiaGoldDirectoryForSuite(TestSuite suite) {
return io.Directory(
path.join(
environment.webUiSkiaGoldDirectory.path,
suite.name,
)
);
}

extension AnsiColors on String {
static bool shouldEscape = io.stdout.hasTerminal && io.stdout.supportsAnsiEscapes;

Expand Down
3 changes: 1 addition & 2 deletions lib/web_ui/lib/src/engine/canvaskit/canvaskit_canvas.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'dart:typed_data';

import 'package:ui/ui.dart' as ui;

import '../util.dart';
import '../validators.dart';
import '../vector_math.dart';
import 'canvas.dart';
Expand Down Expand Up @@ -145,7 +144,7 @@ class CanvasKitCanvas implements ui.Canvas {
// non-invertible transforms collapse space to a line or point
return ui.Rect.zero;
}
return transformRect(transform, _canvas.getDeviceClipBounds());
return transform.transformRect(_canvas.getDeviceClipBounds());
}

@override
Expand Down

0 comments on commit f164d10

Please sign in to comment.