Skip to content

Commit

Permalink
Add stubs for Skwasm renderer (flutter#35748)
Browse files Browse the repository at this point in the history
  • Loading branch information
eyebrowsoffire authored Sep 1, 2022
1 parent b197788 commit 12e9318
Show file tree
Hide file tree
Showing 14 changed files with 682 additions and 177 deletions.
4 changes: 4 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -1283,6 +1283,10 @@ FILE: ../../../flutter/lib/web_ui/lib/src/engine/services/message_codec.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/services/message_codecs.dart
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/renderer.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_stub.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_stub/renderer.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/svg.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/test_embedding.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/text/canvas_paragraph.dart
Expand Down
17 changes: 13 additions & 4 deletions lib/web_ui/dev/steps/compile_tests_step.dart
Original file line number Diff line number Diff line change
Expand Up @@ -186,21 +186,28 @@ Future<void> compileTests(List<FilePath> testFiles) async {
// different dart2js options.
final List<FilePath> htmlTargets = <FilePath>[];
final List<FilePath> canvasKitTargets = <FilePath>[];
final List<FilePath> skwasmTargets = <FilePath>[];
final String canvasKitTestDirectory =
pathlib.join(environment.webUiTestDir.path, 'canvaskit');
final String skwasmTestDirectory =
pathlib.join(environment.webUiTestDir.path, 'skwasm');
for (final FilePath testFile in testFiles) {
if (pathlib.isWithin(canvasKitTestDirectory, testFile.absolute)) {
canvasKitTargets.add(testFile);
} else if (pathlib.isWithin(skwasmTestDirectory, testFile.absolute)) {
skwasmTargets.add(testFile);
} else {
htmlTargets.add(testFile);
}
}

await Future.wait(<Future<void>>[
if (htmlTargets.isNotEmpty)
_compileTestsInParallel(targets: htmlTargets, forCanvasKit: false),
_compileTestsInParallel(targets: htmlTargets),
if (canvasKitTargets.isNotEmpty)
_compileTestsInParallel(targets: canvasKitTargets, forCanvasKit: true),
if (skwasmTargets.isNotEmpty)
_compileTestsInParallel(targets: skwasmTargets, forSkwasm: true),
]);

stopwatch.stop();
Expand All @@ -220,11 +227,12 @@ final Pool _dart2jsPool = Pool(_dart2jsConcurrency);
/// Spawns multiple dart2js processes to compile [targets] in parallel.
Future<void> _compileTestsInParallel({
required List<FilePath> targets,
required bool forCanvasKit,
bool forCanvasKit = false,
bool forSkwasm = false,
}) async {
final Stream<bool> results = _dart2jsPool.forEach(
targets,
(FilePath file) => compileUnitTest(file, forCanvasKit: forCanvasKit),
(FilePath file) => compileUnitTest(file, forCanvasKit: forCanvasKit, forSkwasm: forSkwasm),
);
await for (final bool isSuccess in results) {
if (!isSuccess) {
Expand All @@ -250,7 +258,7 @@ Future<void> _compileTestsInParallel({
/// directory before test are build. See [_copyFilesFromTestToBuild].
///
/// Later the extra files will be deleted in [_cleanupExtraFilesUnderTestDir].
Future<bool> compileUnitTest(FilePath input, {required bool forCanvasKit}) async {
Future<bool> compileUnitTest(FilePath input, {required bool forCanvasKit, required bool forSkwasm}) async {
final String targetFileName = pathlib.join(
environment.webUiBuildDir.path,
'${input.relativeToWebUi}.browser_test.dart.js',
Expand All @@ -277,6 +285,7 @@ Future<bool> compileUnitTest(FilePath input, {required bool forCanvasKit}) async
// renderer explicitly.
'-DFLUTTER_WEB_AUTO_DETECT=false',
'-DFLUTTER_WEB_USE_SKIA=$forCanvasKit',
'-DFLUTTER_WEB_USE_SKWASM=$forSkwasm',

'-O2',
'-o',
Expand Down
3 changes: 3 additions & 0 deletions lib/web_ui/lib/src/engine/configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ class FlutterConfiguration {
static const bool flutterWebAutoDetect =
bool.fromEnvironment('FLUTTER_WEB_AUTO_DETECT', defaultValue: true);

static const bool flutterWebUseSkwasm =
bool.fromEnvironment('FLUTTER_WEB_USE_SKWASM');

/// Enable the Skia-based rendering backend.
///
/// Using flutter tools option "--web-render=canvaskit" would set the value to
Expand Down
46 changes: 25 additions & 21 deletions lib/web_ui/lib/src/engine/renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'embedder.dart';
import 'fonts.dart';
import 'html/renderer.dart';
import 'html_image_codec.dart';
import 'skwasm/skwasm_stub/renderer.dart' if (dart.library.ffi) 'skwasm/skwasm_impl/renderer.dart';

final Renderer _renderer = Renderer._internal();
Renderer get renderer => _renderer;
Expand All @@ -26,6 +27,9 @@ Renderer get renderer => _renderer;
/// of functionality needed by the rest of the generic web engine code.
abstract class Renderer {
factory Renderer._internal() {
if (FlutterConfiguration.flutterWebUseSkwasm) {
return SkwasmRenderer();
}
bool useCanvasKit;
if (FlutterConfiguration.flutterWebAutoDetect) {
if (requestedRendererType != null) {
Expand Down Expand Up @@ -154,27 +158,27 @@ abstract class Renderer {
ui.Path combinePaths(ui.PathOperation op, ui.Path path1, ui.Path path2);

ui.TextStyle createTextStyle({
ui.Color? color,
ui.TextDecoration? decoration,
ui.Color? decorationColor,
ui.TextDecorationStyle? decorationStyle,
double? decorationThickness,
ui.FontWeight? fontWeight,
ui.FontStyle? fontStyle,
ui.TextBaseline? textBaseline,
String? fontFamily,
List<String>? fontFamilyFallback,
double? fontSize,
double? letterSpacing,
double? wordSpacing,
double? height,
ui.TextLeadingDistribution? leadingDistribution,
ui.Locale? locale,
ui.Paint? background,
ui.Paint? foreground,
List<ui.Shadow>? shadows,
List<ui.FontFeature>? fontFeatures,
List<ui.FontVariation>? fontVariations,
required ui.Color? color,
required ui.TextDecoration? decoration,
required ui.Color? decorationColor,
required ui.TextDecorationStyle? decorationStyle,
required double? decorationThickness,
required ui.FontWeight? fontWeight,
required ui.FontStyle? fontStyle,
required ui.TextBaseline? textBaseline,
required String? fontFamily,
required List<String>? fontFamilyFallback,
required double? fontSize,
required double? letterSpacing,
required double? wordSpacing,
required double? height,
required ui.TextLeadingDistribution? leadingDistribution,
required ui.Locale? locale,
required ui.Paint? background,
required ui.Paint? foreground,
required List<ui.Shadow>? shadows,
required List<ui.FontFeature>? fontFeatures,
required List<ui.FontVariation>? fontVariations,
});

ui.ParagraphStyle createParagraphStyle({
Expand Down
7 changes: 7 additions & 0 deletions lib/web_ui/lib/src/engine/skwasm/skwasm_impl.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// 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.

library skwasm_impl;

export 'skwasm_impl/renderer.dart';
168 changes: 168 additions & 0 deletions lib/web_ui/lib/src/engine/skwasm/skwasm_impl/renderer.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
// 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.

import 'dart:async';
import 'dart:math' as math;
import 'dart:typed_data';

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

import '../../embedder.dart';
import '../../fonts.dart';
import '../../html_image_codec.dart';
import '../../renderer.dart';

// TODO(jacksongardner): Actually implement skwasm renderer.
class SkwasmRenderer implements Renderer {
@override
ui.Path combinePaths(ui.PathOperation op, ui.Path path1, ui.Path path2) {
throw UnimplementedError('Not yet implemented');
}

@override
ui.ImageFilter composeImageFilters({required ui.ImageFilter outer, required ui.ImageFilter inner}) {
throw UnimplementedError('Not yet implemented');
}

@override
ui.Path copyPath(ui.Path src) {
throw UnimplementedError('Not yet implemented');
}

@override
ui.ImageFilter createBlurImageFilter({double sigmaX = 0.0, double sigmaY = 0.0, ui.TileMode tileMode = ui.TileMode.clamp}) {
throw UnimplementedError('Not yet implemented');
}

@override
ui.Canvas createCanvas(ui.PictureRecorder recorder, [ui.Rect? cullRect]) {
throw UnimplementedError('Not yet implemented');
}

@override
ui.Gradient createConicalGradient(ui.Offset focal, double focalRadius, ui.Offset center, double radius, List<ui.Color> colors, [List<double>? colorStops, ui.TileMode tileMode = ui.TileMode.clamp, Float32List? matrix]) {
throw UnimplementedError('Not yet implemented');
}

@override
ui.ImageFilter createDilateImageFilter({double radiusX = 0.0, double radiusY = 0.0}) {
throw UnimplementedError('Not yet implemented');
}

@override
ui.ImageFilter createErodeImageFilter({double radiusX = 0.0, double radiusY = 0.0}) {
throw UnimplementedError('Not yet implemented');
}

@override
ui.ImageShader createImageShader(ui.Image image, ui.TileMode tmx, ui.TileMode tmy, Float64List matrix4, ui.FilterQuality? filterQuality) {
throw UnimplementedError('Not yet implemented');
}

@override
ui.Gradient createLinearGradient(ui.Offset from, ui.Offset to, List<ui.Color> colors, [List<double>? colorStops, ui.TileMode tileMode = ui.TileMode.clamp, Float32List? matrix4]) {
throw UnimplementedError('Not yet implemented');
}

@override
ui.ImageFilter createMatrixImageFilter(Float64List matrix4, {ui.FilterQuality filterQuality = ui.FilterQuality.low}) {
throw UnimplementedError('Not yet implemented');
}

@override
ui.Paint createPaint() {
throw UnimplementedError('Not yet implemented');
}

@override
ui.ParagraphBuilder createParagraphBuilder(ui.ParagraphStyle style) {
throw UnimplementedError('Not yet implemented');
}

@override
ui.ParagraphStyle createParagraphStyle({ui.TextAlign? textAlign, ui.TextDirection? textDirection, int? maxLines, String? fontFamily, double? fontSize, double? height, ui.TextHeightBehavior? textHeightBehavior, ui.FontWeight? fontWeight, ui.FontStyle? fontStyle, ui.StrutStyle? strutStyle, String? ellipsis, ui.Locale? locale}) {
throw UnimplementedError('Not yet implemented');
}

@override
ui.Path createPath() {
throw UnimplementedError('Not yet implemented');
}

@override
ui.PictureRecorder createPictureRecorder() {
throw UnimplementedError('Not yet implemented');
}

@override
ui.Gradient createRadialGradient(ui.Offset center, double radius, List<ui.Color> colors, [List<double>? colorStops, ui.TileMode tileMode = ui.TileMode.clamp, Float32List? matrix4]) {
throw UnimplementedError('Not yet implemented');
}

@override
ui.SceneBuilder createSceneBuilder() {
throw UnimplementedError('Not yet implemented');
}

@override
ui.StrutStyle createStrutStyle({String? fontFamily, List<String>? fontFamilyFallback, double? fontSize, double? height, ui.TextLeadingDistribution? leadingDistribution, double? leading, ui.FontWeight? fontWeight, ui.FontStyle? fontStyle, bool? forceStrutHeight}) {
throw UnimplementedError('Not yet implemented');
}

@override
ui.Gradient createSweepGradient(ui.Offset center, List<ui.Color> colors, [List<double>? colorStops, ui.TileMode tileMode = ui.TileMode.clamp, double startAngle = 0.0, double endAngle = math.pi * 2, Float32List? matrix4]) {
throw UnimplementedError('Not yet implemented');
}

@override
ui.TextStyle createTextStyle({ui.Color? color, ui.TextDecoration? decoration, ui.Color? decorationColor, ui.TextDecorationStyle? decorationStyle, double? decorationThickness, ui.FontWeight? fontWeight, ui.FontStyle? fontStyle, ui.TextBaseline? textBaseline, String? fontFamily, List<String>? fontFamilyFallback, double? fontSize, double? letterSpacing, double? wordSpacing, double? height, ui.TextLeadingDistribution? leadingDistribution, ui.Locale? locale, ui.Paint? background, ui.Paint? foreground, List<ui.Shadow>? shadows, List<ui.FontFeature>? fontFeatures, List<ui.FontVariation>? fontVariations}) {
throw UnimplementedError('Not yet implemented');
}

@override
ui.Vertices createVertices(ui.VertexMode mode, List<ui.Offset> positions, {List<ui.Offset>? textureCoordinates, List<ui.Color>? colors, List<int>? indices}) {
throw UnimplementedError('Not yet implemented');
}

@override
ui.Vertices createVerticesRaw(ui.VertexMode mode, Float32List positions, {Float32List? textureCoordinates, Int32List? colors, Uint16List? indices}) {
throw UnimplementedError('Not yet implemented');
}

@override
void decodeImageFromPixels(Uint8List pixels, int width, int height, ui.PixelFormat format, ui.ImageDecoderCallback callback, {int? rowBytes, int? targetWidth, int? targetHeight, bool allowUpscaling = true}) {
throw UnimplementedError('Not yet implemented');
}

@override
FontCollection get fontCollection => throw UnimplementedError('Not yet implemented');

@override
FutureOr<void> initialize() {
throw UnimplementedError('Not yet implemented');
}

@override
Future<ui.Codec> instantiateImageCodec(Uint8List list, {int? targetWidth, int? targetHeight, bool allowUpscaling = true}) {
throw UnimplementedError('Not yet implemented');
}

@override
Future<ui.Codec> instantiateImageCodecFromUrl(Uri uri, {WebOnlyImageCodecChunkCallback? chunkCallback}) {
throw UnimplementedError('Not yet implemented');
}

@override
void renderScene(ui.Scene scene) {
throw UnimplementedError('Not yet implemented');
}

@override
String get rendererTag => throw UnimplementedError('Not yet implemented');

@override
void reset(FlutterViewEmbedder embedder) {
throw UnimplementedError('Not yet implemented');
}
}
7 changes: 7 additions & 0 deletions lib/web_ui/lib/src/engine/skwasm/skwasm_stub.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// 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.

library skwasm_stub;

export 'skwasm_stub/renderer.dart';
Loading

0 comments on commit 12e9318

Please sign in to comment.