Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 1da5b83

Browse files
committed
add web functional tests (both CK and Dom)
1 parent 9e6d51a commit 1da5b83

File tree

8 files changed

+338
-13
lines changed

8 files changed

+338
-13
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,11 +319,13 @@ class CkCanvas {
319319

320320
Float32List getLocalToDevice() {
321321
final List<dynamic> list = skCanvas.getLocalToDevice();
322-
final Float32List matrix = Float32List(16);
323-
for (int i = 0; i < 16; i++) {
324-
matrix[i] = list[i];
322+
final Float32List matrix4 = Float32List(16);
323+
for (int r = 0; r < 4; r++) {
324+
for (int c = 0; c < 4; c++) {
325+
matrix4[c * 4 + r] = list[r * 4 + c].toDouble();
326+
}
325327
}
326-
return matrix;
328+
return matrix4;
327329
}
328330

329331
CkPictureSnapshot? get pictureSnapshot => null;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class CanvasKitCanvas implements ui.Canvas {
149149
// non-invertible transforms collapse space to a line or point
150150
return ui.Rect.zero;
151151
}
152-
return transformRect(transform, getDestinationClipBounds());
152+
return transformRect(transform, _canvas.getDeviceClipBounds());
153153
}
154154

155155
@override

lib/web_ui/lib/src/engine/html/canvas.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,15 @@ class SurfaceCanvas implements ui.Canvas {
142142
return _canvas.getDestinationClipBounds() ?? ui.Rect.largest;
143143
}
144144

145+
ui.Rect _roundOut(ui.Rect rect) {
146+
return ui.Rect.fromLTRB(
147+
rect.left.floorToDouble(),
148+
rect.top.floorToDouble(),
149+
rect.right.ceilToDouble(),
150+
rect.bottom.ceilToDouble(),
151+
);
152+
}
153+
145154
@override
146155
ui.Rect getLocalClipBounds() {
147156
final ui.Rect? destBounds = _canvas.getDestinationClipBounds();
@@ -153,7 +162,7 @@ class SurfaceCanvas implements ui.Canvas {
153162
// non-invertible transforms collapse space to a line or point
154163
return ui.Rect.zero;
155164
}
156-
return transformRect(transform, destBounds);
165+
return transformRect(transform, _roundOut(destBounds));
157166
}
158167

159168
@override

lib/web_ui/lib/src/engine/html/recording_canvas.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1722,7 +1722,7 @@ class _PaintBounds {
17221722
if (sx != 1.0 || sy != 1.0) {
17231723
_currentMatrixIsIdentity = false;
17241724
}
1725-
_currentMatrix.scale(sx, sy);
1725+
_currentMatrix.scale(sx, sy, 1.0);
17261726
}
17271727

17281728
void rotateZ(double radians) {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
@TestOn('chrome || safari || firefox')
6+
7+
import 'dart:async';
8+
9+
import 'package:test/bootstrap/browser.dart';
10+
import 'package:test/test.dart';
11+
import 'package:ui/src/engine/browser_detection.dart';
12+
13+
import '../engine/canvas_test.dart';
14+
import 'common.dart';
15+
16+
void main() {
17+
internalBootstrapBrowserTest(() => testMain);
18+
}
19+
20+
// Run the same semantics tests in CanvasKit mode because as of today we do not
21+
// yet share platform view logic with the HTML renderer, which affects
22+
// semantics.
23+
Future<void> testMain() async {
24+
group('CanvasKit semantics', () {
25+
setUpCanvasKitTest();
26+
27+
runCanvasTests(deviceClipRoundsOut: true);
28+
// TODO(hterkelsen): https://github.com/flutter/flutter/issues/60040
29+
}, skip: isIosSafari);
30+
}

lib/web_ui/test/canvaskit/canvaskit_api_test.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,11 @@ void _canvasTests() {
10331033

10341034
test('clipPath', () {
10351035
canvas.clipPath(
1036-
_testClosedSkPath(),
1036+
SkPath()
1037+
..moveTo(10.9, 10.9)
1038+
..lineTo(19.1, 10.9)
1039+
..lineTo(19.1, 19.1)
1040+
..lineTo(10.9, 19.1),
10371041
canvasKit.ClipOp.Intersect,
10381042
true,
10391043
);
@@ -1042,7 +1046,7 @@ void _canvasTests() {
10421046

10431047
test('clipRRect', () {
10441048
canvas.clipRRect(
1045-
Float32List.fromList(<double>[0, 0, 100, 100, 1, 2, 3, 4, 5, 6, 7, 8]),
1049+
Float32List.fromList(<double>[0.9, 0.9, 99.1, 99.1, 1, 2, 3, 4, 5, 6, 7, 8]),
10461050
canvasKit.ClipOp.Intersect,
10471051
true,
10481052
);
@@ -1051,7 +1055,7 @@ void _canvasTests() {
10511055

10521056
test('clipRect', () {
10531057
canvas.clipRect(
1054-
Float32List.fromList(<double>[0, 0, 100, 100]),
1058+
Float32List.fromList(<double>[0.9, 0.9, 99.1, 99.1]),
10551059
canvasKit.ClipOp.Intersect,
10561060
true,
10571061
);

0 commit comments

Comments
 (0)