Skip to content

Commit 7954351

Browse files
eyebrowsoffirekorca0220
authored andcommitted
[skwasm] Port to DisplayList objects (flutter#172314)
This PR refactors the skwasm renderer to use `DisplayList` objects as its main model objects instead of using Skia objects directly. Then, at render time, we dispatch the display list commands to the skia surface. This is a preparatory step for impeller on web. * Some build rules were reworked in order to allow `DisplayList` to compile via emscripten * Some pieces of the display list library were further refactored to allow us to compile it without actually building and linking the impeller shaders. The two major classes that needed to be separated out were `DlRuntimeEffect` and the text drawing system. * `SkPath` and `SkImage` are still used as the main model objects in skwasm. As of right now, `DisplayList` just thinly wraps these objects, so this is the minimal possible change for now. I will have to refactor this somewhat further when preparing for actual impeller adoption. * Several special cased code paths in skwasm were removed, as they are taken care of by `DisplayList` itself. This includes shadow drawing, determining when to enable dithering, and determining the right clamp value for filters.
1 parent 37dfde7 commit 7954351

34 files changed

+1017
-742
lines changed

engine/src/build/config/compiler/BUILD.gn

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,8 @@ if (is_win) {
716716
# freetype2 needs these two
717717
"-Wno-unused-function",
718718
"-Wno-unused-variable",
719+
720+
"-Wno-sign-conversion",
719721
]
720722
}
721723

@@ -1110,10 +1112,15 @@ config("prevent_unsafe_narrowing") {
11101112
"-Wshorten-64-to-32",
11111113
"-Wimplicit-int-conversion",
11121114
"-Wsign-compare",
1113-
"-Wsign-conversion",
11141115
# Avoid bugs of the form `if (size_t i = size; i >= 0; --i)` while
11151116
# fixing types to be sign-correct.
11161117
"-Wtautological-unsigned-zero-compare",
11171118
]
1119+
1120+
if (!is_wasm) {
1121+
# emscripten's headers themselves trigger this warning, so we can't
1122+
# keep this enabled on the wasm target.
1123+
cflags += [ "-Wsign-conversion" ]
1124+
}
11181125
}
11191126
}

engine/src/flutter/display_list/BUILD.gn

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,6 @@ if (enable_unittests) {
298298
deps = [
299299
":display_list",
300300
":display_list_fixtures",
301-
"$dart_src/runtime:libdart_jit", # for tracing
302301
"//flutter/benchmarking",
303302
"//flutter/common/graphics",
304303
"//flutter/display_list/testing:display_list_surface_provider",
@@ -308,6 +307,12 @@ if (enable_unittests) {
308307
"//flutter/testing:skia",
309308
"//flutter/testing:testing_lib",
310309
]
310+
311+
if (!is_wasm) {
312+
deps += [
313+
"$dart_src/runtime:libdart_jit", # for tracing
314+
]
315+
}
311316
}
312317

313318
executable("display_list_benchmarks") {

engine/src/flutter/fml/BUILD.gn

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ source_set("fml") {
3333
"hash_combine.h",
3434
"hex_codec.cc",
3535
"hex_codec.h",
36-
"icu_util.cc",
37-
"icu_util.h",
3836
"log_level.h",
3937
"log_settings.cc",
4038
"log_settings.h",
@@ -101,7 +99,7 @@ source_set("fml") {
10199
"wakeable.h",
102100
]
103101

104-
if (enable_backtrace) {
102+
if (enable_backtrace && !is_wasm) {
105103
sources += [ "backtrace.cc" ]
106104
} else {
107105
sources += [ "backtrace_stub.cc" ]
@@ -113,15 +111,24 @@ source_set("fml") {
113111
":string_conversion",
114112
]
115113

116-
deps = [ "//flutter/third_party/icu" ]
114+
deps = []
115+
if (target_os != "wasm") {
116+
deps += [ "//flutter/third_party/icu" ]
117+
118+
sources += [
119+
"icu_util.cc",
120+
"icu_util.h",
121+
]
122+
}
117123

118124
if (enable_backtrace) {
119125
# This abseil dependency is only used by backtrace.cc.
120126
deps += [ "//flutter/third_party/abseil-cpp/absl/debugging:symbolize" ]
121127
}
122128

123-
configs += [ "//flutter/third_party/icu:icu_config" ]
124-
129+
if (target_os != "wasm") {
130+
configs += [ "//flutter/third_party/icu:icu_config" ]
131+
}
125132
public_configs = [
126133
"//flutter:config",
127134
"//flutter/common:flutter_config",

engine/src/flutter/fml/build_config.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
#define FML_OS_SOLARIS 1
5151
#elif defined(__QNXNTO__)
5252
#define FML_OS_QNX 1
53+
#elif defined(__EMSCRIPTEN__)
54+
#define FML_OS_EMSCRIPTEN
5355
#else
5456
#error Please add support for your platform in flutter/fml/build_config.h
5557
#endif
@@ -106,6 +108,9 @@
106108
#elif defined(__pnacl__)
107109
#define FML_ARCH_CPU_32_BITS 1
108110
#define FML_ARCH_CPU_LITTLE_ENDIAN 1
111+
#elif defined(__EMSCRIPTEN__)
112+
#define FML_ARGH_CPU_32_BITS 1
113+
#define FML_ARCH_CPU_LITTLE_ENDIAN 1
109114
#else
110115
#error Please add support for your architecture in flutter/fml/build_config.h
111116
#endif

engine/src/flutter/impeller/display_list/aiks_context.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "impeller/entity/contents/content_context.h"
1111
#include "impeller/renderer/context.h"
12+
1213
#include "impeller/renderer/render_target.h"
1314
#include "impeller/typographer/typographer_context.h"
1415

engine/src/flutter/lib/web_ui/lib/src/engine/layers.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ class ImageFilterOperation implements LayerOperation {
418418
final ui.Offset offset;
419419

420420
@override
421-
ui.Rect mapRect(ui.Rect contentRect) => filter.filterBounds(contentRect);
421+
ui.Rect mapRect(ui.Rect contentRect) => filter.filterBounds(contentRect).shift(offset);
422422

423423
@override
424424
void pre(SceneCanvas canvas) {

engine/src/flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/canvas.dart

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,10 @@ class SkwasmCanvas implements SceneCanvas {
3434
final paintHandle = (paint as SkwasmPaint).toRawPaint();
3535
if (bounds != null) {
3636
withStackScope((StackScope s) {
37-
canvasSaveLayer(
38-
_handle,
39-
s.convertRectToNative(bounds),
40-
paintHandle,
41-
nullptr,
42-
ui.TileMode.clamp.index,
43-
);
37+
canvasSaveLayer(_handle, s.convertRectToNative(bounds), paintHandle, nullptr);
4438
});
4539
} else {
46-
canvasSaveLayer(_handle, nullptr, paintHandle, nullptr, ui.TileMode.clamp.index);
40+
canvasSaveLayer(_handle, nullptr, paintHandle, nullptr);
4741
}
4842
paintDispose(paintHandle);
4943
}
@@ -60,29 +54,16 @@ class SkwasmCanvas implements SceneCanvas {
6054
// and instead needs it supplied to the saveLayer call itself as a
6155
// separate argument.
6256
final SkwasmImageFilter nativeFilter = SkwasmImageFilter.fromUiFilter(imageFilter);
63-
final ui.TileMode? backdropTileMode = nativeFilter.backdropTileMode;
6457
final paintHandle = (paint as SkwasmPaint).toRawPaint(/*ui.TileMode.decal*/);
6558
if (bounds != null) {
6659
withStackScope((StackScope s) {
6760
nativeFilter.withRawImageFilter((nativeFilterHandle) {
68-
canvasSaveLayer(
69-
_handle,
70-
s.convertRectToNative(bounds),
71-
paintHandle,
72-
nativeFilterHandle,
73-
(backdropTileMode ?? ui.TileMode.mirror).index,
74-
);
61+
canvasSaveLayer(_handle, s.convertRectToNative(bounds), paintHandle, nativeFilterHandle);
7562
}, defaultBlurTileMode: ui.TileMode.mirror);
7663
});
7764
} else {
7865
nativeFilter.withRawImageFilter((nativeFilterHandle) {
79-
canvasSaveLayer(
80-
_handle,
81-
nullptr,
82-
paintHandle,
83-
nativeFilterHandle,
84-
(backdropTileMode ?? ui.TileMode.mirror).index,
85-
);
66+
canvasSaveLayer(_handle, nullptr, paintHandle, nativeFilterHandle);
8667
}, defaultBlurTileMode: ui.TileMode.mirror);
8768
}
8869
paintDispose(paintHandle);

0 commit comments

Comments
 (0)