Skip to content

Commit afe6cce

Browse files
author
Harry Terkelsen
authored
Roll CanvasKit to 0.23 (flutter#24249)
1 parent 9bcb3bf commit afe6cce

File tree

4 files changed

+39
-19
lines changed

4 files changed

+39
-19
lines changed

lib/web_ui/dev/goldens_lock.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
repository: https://github.com/flutter/goldens.git
2-
revision: 578ecb91ea33004cd0ba0af513884cc28ba88cf4
2+
revision: 1c6b4fcf242ef6c4475340d30aadad754b8a0c54

lib/web_ui/lib/src/engine/canvaskit/initialization.dart

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,12 @@ const bool canvasKitForceCpuOnly = bool.fromEnvironment(
7575
/// NPM, update this URL to `https://unpkg.com/canvaskit-wasm@0.34.0/bin/`.
7676
const String canvasKitBaseUrl = String.fromEnvironment(
7777
'FLUTTER_WEB_CANVASKIT_URL',
78-
defaultValue: 'https://unpkg.com/canvaskit-wasm@0.22.0/bin/',
78+
defaultValue: 'https://unpkg.com/canvaskit-wasm@0.23.0/bin/',
7979
);
80-
final String canvasKitBuildUrl = canvasKitBaseUrl + (kProfileMode ? 'profiling/' : '');
81-
final String canvasKitJavaScriptBindingsUrl = canvasKitBuildUrl + 'canvaskit.js';
80+
final String canvasKitBuildUrl =
81+
canvasKitBaseUrl + (kProfileMode ? 'profiling/' : '');
82+
final String canvasKitJavaScriptBindingsUrl =
83+
canvasKitBuildUrl + 'canvaskit.js';
8284
String canvasKitWasmModuleUrl(String file) => canvasKitBuildUrl + file;
8385

8486
/// Initialize CanvasKit.
@@ -89,8 +91,10 @@ Future<void> initializeCanvasKit() {
8991
late StreamSubscription<html.Event> loadSubscription;
9092
loadSubscription = domRenderer.canvasKitScript!.onLoad.listen((_) {
9193
loadSubscription.cancel();
92-
final CanvasKitInitPromise canvasKitInitPromise = CanvasKitInit(CanvasKitInitOptions(
93-
locateFile: js.allowInterop((String file, String unusedBase) => canvasKitWasmModuleUrl(file)),
94+
final CanvasKitInitPromise canvasKitInitPromise =
95+
CanvasKitInit(CanvasKitInitOptions(
96+
locateFile: js.allowInterop(
97+
(String file, String unusedBase) => canvasKitWasmModuleUrl(file)),
9498
));
9599
canvasKitInitPromise.then(js.allowInterop((CanvasKit ck) {
96100
canvasKit = ck;

lib/web_ui/test/canvaskit/canvaskit_api_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1313,7 +1313,7 @@ void _paragraphTests() {
13131313
expect(paragraph.getIdeographicBaseline(), within<double>(distance: 0.5, from: 28));
13141314
expect(paragraph.getLongestLine(), 50);
13151315
expect(paragraph.getMaxIntrinsicWidth(), 50);
1316-
expect(paragraph.getMinIntrinsicWidth(), 0);
1316+
expect(paragraph.getMinIntrinsicWidth(), 50);
13171317
expect(paragraph.getMaxWidth(), 55);
13181318
expect(paragraph.getRectsForRange(1, 3, canvasKit.RectHeightStyle.Tight, canvasKit.RectWidthStyle.Max), <double>[]);
13191319
expect(paragraph.getRectsForPlaceholders(), hasLength(1));

lib/web_ui/test/canvaskit/surface_test.dart

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@ void testMain() {
2020
group('CanvasKit', () {
2121
setUpCanvasKitTest();
2222

23+
setUp(() {
24+
window.debugOverrideDevicePixelRatio(1);
25+
});
26+
2327
test('Surface allocates canvases efficiently', () {
2428
final Surface surface = Surface(HtmlViewEmbedder());
25-
final CkSurface original = surface.acquireFrame(ui.Size(9, 19)).skiaSurface;
29+
final CkSurface original =
30+
surface.acquireFrame(ui.Size(9, 19)).skiaSurface;
2631

2732
// Expect exact requested dimensions.
2833
expect(original.width(), 9);
@@ -38,7 +43,8 @@ void testMain() {
3843

3944
// The first increase will allocate a new surface, but will overallocate
4045
// by 40% to accommodate future increases.
41-
final CkSurface firstIncrease = surface.acquireFrame(ui.Size(10, 20)).skiaSurface;
46+
final CkSurface firstIncrease =
47+
surface.acquireFrame(ui.Size(10, 20)).skiaSurface;
4248
expect(firstIncrease, isNot(same(original)));
4349

4450
// Expect overallocated dimensions
@@ -48,7 +54,8 @@ void testMain() {
4854
expect(surface.htmlCanvas!.style.height, '28px');
4955

5056
// Subsequent increases within 40% reuse the old surface.
51-
final CkSurface secondIncrease = surface.acquireFrame(ui.Size(11, 22)).skiaSurface;
57+
final CkSurface secondIncrease =
58+
surface.acquireFrame(ui.Size(11, 22)).skiaSurface;
5259
expect(secondIncrease, same(firstIncrease));
5360

5461
// Increases beyond the 40% limit will cause a new allocation.
@@ -62,7 +69,8 @@ void testMain() {
6269
expect(surface.htmlCanvas!.style.height, '56px');
6370

6471
// Shrink again. Reuse the last allocated surface.
65-
final CkSurface shrunk2 = surface.acquireFrame(ui.Size(5, 15)).skiaSurface;
72+
final CkSurface shrunk2 =
73+
surface.acquireFrame(ui.Size(5, 15)).skiaSurface;
6674
expect(shrunk2, same(huge));
6775
});
6876

@@ -71,25 +79,30 @@ void testMain() {
7179
() async {
7280
final Surface surface = Surface(HtmlViewEmbedder());
7381
expect(surface.debugForceNewContext, isTrue);
74-
final CkSurface before = surface.acquireFrame(ui.Size(9, 19)).skiaSurface;
82+
final CkSurface before =
83+
surface.acquireFrame(ui.Size(9, 19)).skiaSurface;
7584
expect(surface.debugForceNewContext, isFalse);
7685

7786
// Pump a timer to flush any microtasks.
7887
await Future<void>.delayed(Duration.zero);
79-
final CkSurface afterAcquireFrame = surface.acquireFrame(ui.Size(9, 19)).skiaSurface;
88+
final CkSurface afterAcquireFrame =
89+
surface.acquireFrame(ui.Size(9, 19)).skiaSurface;
8090
// Existing context is reused.
8191
expect(afterAcquireFrame, same(before));
8292

8393
// Emulate WebGL context loss.
84-
final html.CanvasElement canvas = surface.htmlElement.children.single as html.CanvasElement;
94+
final html.CanvasElement canvas =
95+
surface.htmlElement.children.single as html.CanvasElement;
8596
final dynamic ctx = canvas.getContext('webgl2');
86-
final dynamic loseContextExtension = ctx.getExtension('WEBGL_lose_context');
97+
final dynamic loseContextExtension =
98+
ctx.getExtension('WEBGL_lose_context');
8799
loseContextExtension.loseContext();
88100

89101
// Pump a timer to allow the "lose context" event to propagate.
90102
await Future<void>.delayed(Duration.zero);
91103
expect(surface.debugForceNewContext, isTrue);
92-
final CkSurface afterContextLost = surface.acquireFrame(ui.Size(9, 19)).skiaSurface;
104+
final CkSurface afterContextLost =
105+
surface.acquireFrame(ui.Size(9, 19)).skiaSurface;
93106
// A new cotext is created.
94107
expect(afterContextLost, isNot(same(before)));
95108
},
@@ -100,7 +113,8 @@ void testMain() {
100113
// Regression test for https://github.com/flutter/flutter/issues/75286
101114
test('updates canvas logical size when device-pixel ratio changes', () {
102115
final Surface surface = Surface(HtmlViewEmbedder());
103-
final CkSurface original = surface.acquireFrame(ui.Size(10, 16)).skiaSurface;
116+
final CkSurface original =
117+
surface.acquireFrame(ui.Size(10, 16)).skiaSurface;
104118

105119
expect(original.width(), 10);
106120
expect(original.height(), 16);
@@ -110,7 +124,8 @@ void testMain() {
110124
// Increase device-pixel ratio: this makes CSS pixels bigger, so we need
111125
// fewer of them to cover the browser window.
112126
window.debugOverrideDevicePixelRatio(2.0);
113-
final CkSurface highDpr = surface.acquireFrame(ui.Size(10, 16)).skiaSurface;
127+
final CkSurface highDpr =
128+
surface.acquireFrame(ui.Size(10, 16)).skiaSurface;
114129
expect(highDpr.width(), 10);
115130
expect(highDpr.height(), 16);
116131
expect(surface.htmlCanvas!.style.width, '5px');
@@ -119,7 +134,8 @@ void testMain() {
119134
// Decrease device-pixel ratio: this makes CSS pixels smaller, so we need
120135
// more of them to cover the browser window.
121136
window.debugOverrideDevicePixelRatio(0.5);
122-
final CkSurface lowDpr = surface.acquireFrame(ui.Size(10, 16)).skiaSurface;
137+
final CkSurface lowDpr =
138+
surface.acquireFrame(ui.Size(10, 16)).skiaSurface;
123139
expect(lowDpr.width(), 10);
124140
expect(lowDpr.height(), 16);
125141
expect(surface.htmlCanvas!.style.width, '20px');

0 commit comments

Comments
 (0)