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

Commit f45f52f

Browse files
authored
Move path part files to libraries (#25842)
1 parent aac3658 commit f45f52f

22 files changed

Lines changed: 626 additions & 536 deletions

ci/licenses_golden/licenses_flutter

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,7 @@ FILE: ../../../flutter/lib/web_ui/lib/src/engine/color_filter.dart
482482
FILE: ../../../flutter/lib/web_ui/lib/src/engine/dom_canvas.dart
483483
FILE: ../../../flutter/lib/web_ui/lib/src/engine/dom_renderer.dart
484484
FILE: ../../../flutter/lib/web_ui/lib/src/engine/engine_canvas.dart
485+
FILE: ../../../flutter/lib/web_ui/lib/src/engine/font_change_util.dart
485486
FILE: ../../../flutter/lib/web_ui/lib/src/engine/frame_reference.dart
486487
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/backdrop_filter.dart
487488
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/canvas.dart
@@ -495,12 +496,14 @@ FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/painting.dart
495496
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/path/conic.dart
496497
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/path/cubic.dart
497498
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/path/path.dart
499+
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/path/path_iterator.dart
498500
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/path/path_metrics.dart
499501
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/path/path_ref.dart
500502
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/path/path_to_svg.dart
501503
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/path/path_utils.dart
502504
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/path/path_windings.dart
503505
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/path/tangent.dart
506+
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/path_to_svg_clip.dart
504507
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/picture.dart
505508
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/platform_view.dart
506509
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/recording_canvas.dart

lib/web_ui/lib/src/engine.dart

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,27 @@ export 'engine/alarm_clock.dart';
3838
import 'engine/browser_detection.dart';
3939
export 'engine/browser_detection.dart';
4040

41+
import 'engine/html/path_to_svg_clip.dart';
42+
export 'engine/html/path_to_svg_clip.dart';
43+
44+
import 'engine/html/path/conic.dart';
45+
export 'engine/html/path/conic.dart';
46+
47+
import 'engine/html/path/cubic.dart';
48+
export 'engine/html/path/cubic.dart';
49+
50+
import 'engine/html/path/path_iterator.dart';
51+
export 'engine/html/path/path_iterator.dart';
52+
53+
import 'engine/html/path/path_metrics.dart';
54+
export 'engine/html/path/path_metrics.dart';
55+
56+
import 'engine/html/path/path_ref.dart';
57+
export 'engine/html/path/path_ref.dart';
58+
59+
import 'engine/html/path/path_utils.dart';
60+
export 'engine/html/path/path_utils.dart';
61+
4162
import 'engine/mouse_cursor.dart';
4263
export 'engine/mouse_cursor.dart';
4364

@@ -83,6 +104,9 @@ export 'engine/test_embedding.dart';
83104
import 'engine/ulps.dart';
84105
export 'engine/ulps.dart';
85106

107+
import 'engine/util.dart';
108+
export 'engine/util.dart';
109+
86110
import 'engine/validators.dart';
87111
export 'engine/validators.dart';
88112

@@ -141,13 +165,8 @@ part 'engine/html/image_filter.dart';
141165
part 'engine/html/offset.dart';
142166
part 'engine/html/opacity.dart';
143167
part 'engine/html/painting.dart';
144-
part 'engine/html/path/conic.dart';
145-
part 'engine/html/path/cubic.dart';
146168
part 'engine/html/path/path.dart';
147-
part 'engine/html/path/path_metrics.dart';
148-
part 'engine/html/path/path_ref.dart';
149169
part 'engine/html/path/path_to_svg.dart';
150-
part 'engine/html/path/path_utils.dart';
151170
part 'engine/html/path/path_windings.dart';
152171
part 'engine/html/path/tangent.dart';
153172
part 'engine/html/picture.dart';
@@ -200,7 +219,7 @@ part 'engine/text_editing/autofill_hint.dart';
200219
part 'engine/text_editing/input_type.dart';
201220
part 'engine/text_editing/text_capitalization.dart';
202221
part 'engine/text_editing/text_editing.dart';
203-
part 'engine/util.dart';
222+
part 'engine/font_change_util.dart';
204223
part 'engine/window.dart';
205224

206225
// The mode the app is running in.

lib/web_ui/lib/src/engine/canvas_pool.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ class _CanvasPool extends _SaveStackTracking {
193193
} catch (e) {
194194
// Firefox may explode here:
195195
// https://bugzilla.mozilla.org/show_bug.cgi?id=941146
196-
if (!_isNsErrorFailureException(e)) {
196+
if (!isNsErrorFailureException(e)) {
197197
rethrow;
198198
}
199199
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ class CanvasKitCanvas implements ui.Canvas {
135135

136136
@override
137137
void drawLine(ui.Offset p1, ui.Offset p2, ui.Paint paint) {
138-
assert(_offsetIsValid(p1));
139-
assert(_offsetIsValid(p2));
138+
assert(offsetIsValid(p1));
139+
assert(offsetIsValid(p2));
140140
assert(paint != null); // ignore: unnecessary_null_comparison
141141
_drawLine(p1, p2, paint);
142142
}
@@ -202,7 +202,7 @@ class CanvasKitCanvas implements ui.Canvas {
202202

203203
@override
204204
void drawCircle(ui.Offset c, double radius, ui.Paint paint) {
205-
assert(_offsetIsValid(c));
205+
assert(offsetIsValid(c));
206206
assert(paint != null); // ignore: unnecessary_null_comparison
207207
_drawCircle(c, radius, paint);
208208
}
@@ -236,7 +236,7 @@ class CanvasKitCanvas implements ui.Canvas {
236236
void drawImage(ui.Image image, ui.Offset p, ui.Paint paint) {
237237
// ignore: unnecessary_null_comparison
238238
assert(image != null); // image is checked on the engine side
239-
assert(_offsetIsValid(p));
239+
assert(offsetIsValid(p));
240240
assert(paint != null); // ignore: unnecessary_null_comparison
241241
_canvas.drawImage(image as CkImage, p, paint as CkPaint);
242242
}
@@ -272,7 +272,7 @@ class CanvasKitCanvas implements ui.Canvas {
272272
@override
273273
void drawParagraph(ui.Paragraph paragraph, ui.Offset offset) {
274274
assert(paragraph != null); // ignore: unnecessary_null_comparison
275-
assert(_offsetIsValid(offset));
275+
assert(offsetIsValid(offset));
276276
_drawParagraph(paragraph, offset);
277277
}
278278

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ abstract class CkShader extends ManagedSkiaObject<SkShader>
1717
class CkGradientSweep extends CkShader implements ui.Gradient {
1818
CkGradientSweep(this.center, this.colors, this.colorStops, this.tileMode,
1919
this.startAngle, this.endAngle, this.matrix4)
20-
: assert(_offsetIsValid(center)),
20+
: assert(offsetIsValid(center)),
2121
assert(colors != null), // ignore: unnecessary_null_comparison
2222
assert(tileMode != null), // ignore: unnecessary_null_comparison
2323
assert(startAngle != null), // ignore: unnecessary_null_comparison
2424
assert(endAngle != null), // ignore: unnecessary_null_comparison
2525
assert(startAngle < endAngle),
26-
assert(matrix4 == null || _matrix4IsValid(matrix4)) {
27-
_validateColorStops(colors, colorStops);
26+
assert(matrix4 == null || matrix4IsValid(matrix4)) {
27+
validateColorStops(colors, colorStops);
2828
}
2929

3030
final ui.Offset center;
@@ -65,14 +65,14 @@ class CkGradientLinear extends CkShader implements ui.Gradient {
6565
this.colorStops,
6666
this.tileMode,
6767
Float32List? matrix,
68-
) : assert(_offsetIsValid(from)),
69-
assert(_offsetIsValid(to)),
68+
) : assert(offsetIsValid(from)),
69+
assert(offsetIsValid(to)),
7070
assert(colors != null), // ignore: unnecessary_null_comparison
7171
assert(tileMode != null), // ignore: unnecessary_null_comparison
7272
this.matrix4 = matrix {
7373
if (assertionsEnabled) {
74-
assert(matrix4 == null || _matrix4IsValid(matrix4!));
75-
_validateColorStops(colors, colorStops);
74+
assert(matrix4 == null || matrix4IsValid(matrix4!));
75+
validateColorStops(colors, colorStops);
7676
}
7777
}
7878

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
part of engine;
6+
7+
final ByteData? _fontChangeMessage =
8+
JSONMessageCodec().encodeMessage(<String, dynamic>{'type': 'fontsChange'});
9+
10+
// Font load callbacks will typically arrive in sequence, we want to prevent
11+
// sendFontChangeMessage of causing multiple synchronous rebuilds.
12+
// This flag ensures we properly schedule a single call to framework.
13+
bool _fontChangeScheduled = false;
14+
15+
FutureOr<void> sendFontChangeMessage() async {
16+
if (!_fontChangeScheduled) {
17+
_fontChangeScheduled = true;
18+
// Batch updates into next animationframe.
19+
html.window.requestAnimationFrame((num _) {
20+
_fontChangeScheduled = false;
21+
EnginePlatformDispatcher.instance.invokeOnPlatformMessage(
22+
'flutter/system',
23+
_fontChangeMessage,
24+
(_) {},
25+
);
26+
});
27+
}
28+
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -326,12 +326,12 @@ class PersistedPhysicalShape extends PersistedContainerSurface
326326
/// to clipping rect bounds (which is the case for elevation == 0.0 where
327327
/// we shift outer/inner clip area instead to position clip-path).
328328
final String svgClipPath = elevation == 0.0
329-
? _pathToSvgClipPath(path,
329+
? pathToSvgClipPath(path,
330330
offsetX: -pathBounds.left,
331331
offsetY: -pathBounds.top,
332332
scaleX: 1.0 / pathBounds.width,
333333
scaleY: 1.0 / pathBounds.height)
334-
: _pathToSvgClipPath(path,
334+
: pathToSvgClipPath(path,
335335
offsetX: 0.0,
336336
offsetY: 0.0,
337337
scaleX: 1.0 / pathBounds.right,
@@ -345,7 +345,7 @@ class PersistedPhysicalShape extends PersistedContainerSurface
345345
html.Element.html(svgClipPath, treeSanitizer: _NullTreeSanitizer());
346346
domRenderer.append(rootElement!, _clipElement!);
347347
if (elevation == 0.0) {
348-
DomRenderer.setClipPath(rootElement!, 'url(#svgClip$_clipIdCounter)');
348+
DomRenderer.setClipPath(rootElement!, createSvgClipUrl());
349349
final html.CssStyleDeclaration rootElementStyle = rootElement!.style;
350350
rootElementStyle
351351
..overflow = ''
@@ -360,7 +360,7 @@ class PersistedPhysicalShape extends PersistedContainerSurface
360360
return;
361361
}
362362

363-
DomRenderer.setClipPath(childContainer!, 'url(#svgClip$_clipIdCounter)');
363+
DomRenderer.setClipPath(childContainer!, createSvgClipUrl());
364364
final html.CssStyleDeclaration rootElementStyle = rootElement!.style;
365365
rootElementStyle
366366
..overflow = ''
@@ -500,9 +500,9 @@ class PersistedClipPath extends PersistedContainerSurface
500500
/// Creates an svg clipPath and applies it to [element].
501501
String createSvgClipDef(html.HtmlElement element, ui.Path clipPath) {
502502
final ui.Rect pathBounds = clipPath.getBounds();
503-
final String svgClipPath = _pathToSvgClipPath(clipPath,
503+
final String svgClipPath = pathToSvgClipPath(clipPath,
504504
scaleX: 1.0 / pathBounds.right, scaleY: 1.0 / pathBounds.bottom);
505-
DomRenderer.setClipPath(element, 'url(#svgClip$_clipIdCounter)');
505+
DomRenderer.setClipPath(element, createSvgClipUrl());
506506
// We need to set width and height for the clipElement to cover the
507507
// bounds of the path since browsers such as Safari and Edge
508508
// seem to incorrectly intersect the element bounding rect with

lib/web_ui/lib/src/engine/html/path/conic.dart

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
part of engine;
5+
import 'dart:typed_data';
6+
import 'dart:math' as math;
7+
8+
import 'package:ui/ui.dart' as ui;
9+
10+
import 'path_utils.dart';
611

712
/// Converts conic curve to a list of quadratic curves for rendering on
813
/// canvas or conversion to svg.
@@ -198,7 +203,7 @@ class Conic {
198203
final double coeff0 = fW * p20 - p20;
199204
final double coeff1 = p20 - 2 * wP10;
200205
final double coeff2 = wP10;
201-
final _QuadRoots quadRoots = _QuadRoots();
206+
final QuadRoots quadRoots = QuadRoots();
202207
int rootCount = quadRoots.findRoots(coeff0, coeff1, coeff2);
203208
assert(rootCount == 0 || rootCount == 1);
204209
if (rootCount == 1) {
@@ -230,12 +235,12 @@ class Conic {
230235
final double dz1 = dz0 + (dz2 - dz0) * t;
231236
// Compute new weights.
232237
final double root = math.sqrt(dz1);
233-
if (_nearlyEqual(root, 0)) {
238+
if (SPath.nearlyEqual(root, 0)) {
234239
return false;
235240
}
236241
final double w0 = dz0 / root;
237242
final double w2 = dz2 / root;
238-
if (_nearlyEqual(dz0, 0) || _nearlyEqual(dz1, 0) || _nearlyEqual(dz2, 0)) {
243+
if (SPath.nearlyEqual(dz0, 0) || SPath.nearlyEqual(dz1, 0) || SPath.nearlyEqual(dz2, 0)) {
239244
return false;
240245
}
241246
// Now we can construct the 2 conics by projecting 3D down to 2D.
@@ -314,33 +319,34 @@ class Conic {
314319
double ay = fW * p20y - p20y;
315320
double bx = p20x - cx - cx;
316321
double by = p20y - cy - cy;
317-
_SkQuadCoefficients quadC = _SkQuadCoefficients(ax, ay, bx, by, cx, cy);
322+
SkQuadCoefficients quadC = SkQuadCoefficients(ax, ay, bx, by, cx, cy);
318323
return ui.Offset(quadC.evalX(t), quadC.evalY(t));
319324
}
320-
}
321325

322-
double _conicEvalNumerator(
323-
double p0, double p1, double p2, double w, double t) {
324-
assert(t >= 0 && t <= 1);
325-
final double src2w = p1 * w;
326-
final C = p0;
327-
final A = p2 - 2 * src2w + C;
328-
final B = 2 * (src2w - C);
329-
return polyEval(A, B, C, t);
330-
}
326+
static double evalNumerator(
327+
double p0, double p1, double p2, double w, double t) {
328+
assert(t >= 0 && t <= 1);
329+
final double src2w = p1 * w;
330+
final C = p0;
331+
final A = p2 - 2 * src2w + C;
332+
final B = 2 * (src2w - C);
333+
return polyEval(A, B, C, t);
334+
}
331335

332-
double _conicEvalDenominator(double w, double t) {
333-
double B = 2 * (w - 1);
334-
double C = 1;
335-
double A = -B;
336-
return polyEval(A, B, C, t);
336+
static double evalDenominator(double w, double t) {
337+
double B = 2 * (w - 1);
338+
double C = 1;
339+
double A = -B;
340+
return polyEval(A, B, C, t);
341+
}
337342
}
338343

339-
class _QuadBounds {
344+
class QuadBounds {
340345
double minX = 0;
341346
double minY = 0;
342347
double maxX = 0;
343348
double maxY = 0;
349+
344350
void calculateBounds(Float32List points, int pointIndex) {
345351
final double x1 = points[pointIndex++];
346352
final double y1 = points[pointIndex++];
@@ -398,7 +404,7 @@ class _QuadBounds {
398404
}
399405
}
400406

401-
class _ConicBounds {
407+
class ConicBounds {
402408
double minX = 0;
403409
double minY = 0;
404410
double maxX = 0;
@@ -420,7 +426,7 @@ class _ConicBounds {
420426
// ------------------------------------------------
421427
// {t^2 (2 - 2 w), t (-2 + 2 w), 1}
422428
// Calculate coefficients and solve root.
423-
_QuadRoots roots = _QuadRoots();
429+
QuadRoots roots = QuadRoots();
424430
final double P20x = x2 - x1;
425431
final double P10x = cpX - x1;
426432
final double wP10x = w * P10x;
@@ -431,10 +437,10 @@ class _ConicBounds {
431437
if (n != 0) {
432438
final double t1 = roots.root0!;
433439
if ((t1 >= 0) && (t1 <= 1.0)) {
434-
final double denom = _conicEvalDenominator(w, t1);
435-
double numerator = _conicEvalNumerator(x1, cpX, x2, w, t1);
440+
final double denom = Conic.evalDenominator(w, t1);
441+
double numerator = Conic.evalNumerator(x1, cpX, x2, w, t1);
436442
final double extremaX = numerator / denom;
437-
numerator = _conicEvalNumerator(y1, cpY, y2, w, t1);
443+
numerator = Conic.evalNumerator(y1, cpY, y2, w, t1);
438444
final double extremaY = numerator / denom;
439445
// Expand bounds.
440446
minX = math.min(minX, extremaX);
@@ -454,10 +460,10 @@ class _ConicBounds {
454460
if (n != 0) {
455461
final double t2 = roots.root0!;
456462
if ((t2 >= 0) && (t2 <= 1.0)) {
457-
final double denom = _conicEvalDenominator(w, t2);
458-
double numerator = _conicEvalNumerator(x1, cpX, x2, w, t2);
463+
final double denom = Conic.evalDenominator(w, t2);
464+
double numerator = Conic.evalNumerator(x1, cpX, x2, w, t2);
459465
final double extrema2X = numerator / denom;
460-
numerator = _conicEvalNumerator(y1, cpY, y2, w, t2);
466+
numerator = Conic.evalNumerator(y1, cpY, y2, w, t2);
461467
final double extrema2Y = numerator / denom;
462468
// Expand bounds.
463469
minX = math.min(minX, extrema2X);

0 commit comments

Comments
 (0)