Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/web_ui/dev/goldens_lock.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
repository: https://github.com/flutter/goldens.git
revision: 1c6b4fcf242ef6c4475340d30aadad754b8a0c54
revision: 578ecb91ea33004cd0ba0af513884cc28ba88cf4
14 changes: 5 additions & 9 deletions lib/web_ui/lib/src/engine/canvaskit/initialization.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,10 @@ const bool canvasKitForceCpuOnly = bool.fromEnvironment(
/// 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@0.23.0/bin/',
defaultValue: 'https://unpkg.com/canvaskit-wasm@0.22.0/bin/',
);
final String canvasKitBuildUrl =
canvasKitBaseUrl + (kProfileMode ? 'profiling/' : '');
final String canvasKitJavaScriptBindingsUrl =
canvasKitBuildUrl + 'canvaskit.js';
final String canvasKitBuildUrl = canvasKitBaseUrl + (kProfileMode ? 'profiling/' : '');
final String canvasKitJavaScriptBindingsUrl = canvasKitBuildUrl + 'canvaskit.js';
String canvasKitWasmModuleUrl(String file) => canvasKitBuildUrl + file;

/// Initialize CanvasKit.
Expand All @@ -91,10 +89,8 @@ Future<void> initializeCanvasKit() {
late StreamSubscription<html.Event> loadSubscription;
loadSubscription = domRenderer.canvasKitScript!.onLoad.listen((_) {
loadSubscription.cancel();
final CanvasKitInitPromise canvasKitInitPromise =
CanvasKitInit(CanvasKitInitOptions(
locateFile: js.allowInterop(
(String file, String unusedBase) => canvasKitWasmModuleUrl(file)),
final CanvasKitInitPromise canvasKitInitPromise = CanvasKitInit(CanvasKitInitOptions(
locateFile: js.allowInterop((String file, String unusedBase) => canvasKitWasmModuleUrl(file)),
));
canvasKitInitPromise.then(js.allowInterop((CanvasKit ck) {
canvasKit = ck;
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/test/canvaskit/canvaskit_api_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1313,7 +1313,7 @@ void _paragraphTests() {
expect(paragraph.getIdeographicBaseline(), within<double>(distance: 0.5, from: 28));
expect(paragraph.getLongestLine(), 50);
expect(paragraph.getMaxIntrinsicWidth(), 50);
expect(paragraph.getMinIntrinsicWidth(), 50);
expect(paragraph.getMinIntrinsicWidth(), 0);
expect(paragraph.getMaxWidth(), 55);
expect(paragraph.getRectsForRange(1, 3, canvasKit.RectHeightStyle.Tight, canvasKit.RectWidthStyle.Max), <double>[]);
expect(paragraph.getRectsForPlaceholders(), hasLength(1));
Expand Down
40 changes: 12 additions & 28 deletions lib/web_ui/test/canvaskit/surface_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,9 @@ void testMain() {
group('CanvasKit', () {
setUpCanvasKitTest();

setUp(() {
window.debugOverrideDevicePixelRatio(1);
});

test('Surface allocates canvases efficiently', () {
final Surface surface = Surface(HtmlViewEmbedder());
final CkSurface original =
surface.acquireFrame(ui.Size(9, 19)).skiaSurface;
final CkSurface original = surface.acquireFrame(ui.Size(9, 19)).skiaSurface;

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

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

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

// Subsequent increases within 40% reuse the old surface.
final CkSurface secondIncrease =
surface.acquireFrame(ui.Size(11, 22)).skiaSurface;
final CkSurface secondIncrease = surface.acquireFrame(ui.Size(11, 22)).skiaSurface;
expect(secondIncrease, same(firstIncrease));

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

// Shrink again. Reuse the last allocated surface.
final CkSurface shrunk2 =
surface.acquireFrame(ui.Size(5, 15)).skiaSurface;
final CkSurface shrunk2 = surface.acquireFrame(ui.Size(5, 15)).skiaSurface;
expect(shrunk2, same(huge));
});

Expand All @@ -79,30 +71,25 @@ void testMain() {
() async {
final Surface surface = Surface(HtmlViewEmbedder());
expect(surface.debugForceNewContext, isTrue);
final CkSurface before =
surface.acquireFrame(ui.Size(9, 19)).skiaSurface;
final CkSurface before = surface.acquireFrame(ui.Size(9, 19)).skiaSurface;
expect(surface.debugForceNewContext, isFalse);

// Pump a timer to flush any microtasks.
await Future<void>.delayed(Duration.zero);
final CkSurface afterAcquireFrame =
surface.acquireFrame(ui.Size(9, 19)).skiaSurface;
final CkSurface afterAcquireFrame = surface.acquireFrame(ui.Size(9, 19)).skiaSurface;
// Existing context is reused.
expect(afterAcquireFrame, same(before));

// Emulate WebGL context loss.
final html.CanvasElement canvas =
surface.htmlElement.children.single as html.CanvasElement;
final html.CanvasElement canvas = surface.htmlElement.children.single as html.CanvasElement;
final dynamic ctx = canvas.getContext('webgl2');
final dynamic loseContextExtension =
ctx.getExtension('WEBGL_lose_context');
final dynamic loseContextExtension = ctx.getExtension('WEBGL_lose_context');
loseContextExtension.loseContext();

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

expect(original.width(), 10);
expect(original.height(), 16);
Expand All @@ -124,8 +110,7 @@ void testMain() {
// Increase device-pixel ratio: this makes CSS pixels bigger, so we need
// fewer of them to cover the browser window.
window.debugOverrideDevicePixelRatio(2.0);
final CkSurface highDpr =
surface.acquireFrame(ui.Size(10, 16)).skiaSurface;
final CkSurface highDpr = surface.acquireFrame(ui.Size(10, 16)).skiaSurface;
expect(highDpr.width(), 10);
expect(highDpr.height(), 16);
expect(surface.htmlCanvas!.style.width, '5px');
Expand All @@ -134,8 +119,7 @@ void testMain() {
// Decrease device-pixel ratio: this makes CSS pixels smaller, so we need
// more of them to cover the browser window.
window.debugOverrideDevicePixelRatio(0.5);
final CkSurface lowDpr =
surface.acquireFrame(ui.Size(10, 16)).skiaSurface;
final CkSurface lowDpr = surface.acquireFrame(ui.Size(10, 16)).skiaSurface;
expect(lowDpr.width(), 10);
expect(lowDpr.height(), 16);
expect(surface.htmlCanvas!.style.width, '20px');
Expand Down