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 all commits
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
3 changes: 3 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ FILE: ../../../flutter/lib/web_ui/lib/src/engine/color_filter.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/dom_canvas.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/dom_renderer.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/engine_canvas.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/font_change_util.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/frame_reference.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/backdrop_filter.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/canvas.dart
Expand All @@ -495,12 +496,14 @@ FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/painting.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/path/conic.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/path/cubic.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/path/path.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/path/path_iterator.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/path/path_metrics.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/path/path_ref.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/path/path_to_svg.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/path/path_utils.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/path/path_windings.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/path/tangent.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/path_to_svg_clip.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/picture.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/platform_view.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/recording_canvas.dart
Expand Down
31 changes: 25 additions & 6 deletions lib/web_ui/lib/src/engine.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,27 @@ export 'engine/alarm_clock.dart';
import 'engine/browser_detection.dart';
export 'engine/browser_detection.dart';

import 'engine/html/path_to_svg_clip.dart';
export 'engine/html/path_to_svg_clip.dart';

import 'engine/html/path/conic.dart';
export 'engine/html/path/conic.dart';

import 'engine/html/path/cubic.dart';
export 'engine/html/path/cubic.dart';

import 'engine/html/path/path_iterator.dart';
export 'engine/html/path/path_iterator.dart';

import 'engine/html/path/path_metrics.dart';
export 'engine/html/path/path_metrics.dart';

import 'engine/html/path/path_ref.dart';
export 'engine/html/path/path_ref.dart';

import 'engine/html/path/path_utils.dart';
export 'engine/html/path/path_utils.dart';

import 'engine/mouse_cursor.dart';
export 'engine/mouse_cursor.dart';

Expand Down Expand Up @@ -83,6 +104,9 @@ export 'engine/test_embedding.dart';
import 'engine/ulps.dart';
export 'engine/ulps.dart';

import 'engine/util.dart';
export 'engine/util.dart';

import 'engine/validators.dart';
export 'engine/validators.dart';

Expand Down Expand Up @@ -141,13 +165,8 @@ part 'engine/html/image_filter.dart';
part 'engine/html/offset.dart';
part 'engine/html/opacity.dart';
part 'engine/html/painting.dart';
part 'engine/html/path/conic.dart';
part 'engine/html/path/cubic.dart';
part 'engine/html/path/path.dart';
part 'engine/html/path/path_metrics.dart';
part 'engine/html/path/path_ref.dart';
part 'engine/html/path/path_to_svg.dart';
part 'engine/html/path/path_utils.dart';
part 'engine/html/path/path_windings.dart';
part 'engine/html/path/tangent.dart';
part 'engine/html/picture.dart';
Expand Down Expand Up @@ -200,7 +219,7 @@ part 'engine/text_editing/autofill_hint.dart';
part 'engine/text_editing/input_type.dart';
part 'engine/text_editing/text_capitalization.dart';
part 'engine/text_editing/text_editing.dart';
part 'engine/util.dart';
part 'engine/font_change_util.dart';
part 'engine/window.dart';

// The mode the app is running in.
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/lib/src/engine/canvas_pool.dart
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class _CanvasPool extends _SaveStackTracking {
} catch (e) {
// Firefox may explode here:
// https://bugzilla.mozilla.org/show_bug.cgi?id=941146
if (!_isNsErrorFailureException(e)) {
if (!isNsErrorFailureException(e)) {
rethrow;
}
}
Expand Down
10 changes: 5 additions & 5 deletions lib/web_ui/lib/src/engine/canvaskit/canvaskit_canvas.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ class CanvasKitCanvas implements ui.Canvas {

@override
void drawLine(ui.Offset p1, ui.Offset p2, ui.Paint paint) {
assert(_offsetIsValid(p1));
assert(_offsetIsValid(p2));
assert(offsetIsValid(p1));
assert(offsetIsValid(p2));
assert(paint != null); // ignore: unnecessary_null_comparison
_drawLine(p1, p2, paint);
}
Expand Down Expand Up @@ -202,7 +202,7 @@ class CanvasKitCanvas implements ui.Canvas {

@override
void drawCircle(ui.Offset c, double radius, ui.Paint paint) {
assert(_offsetIsValid(c));
assert(offsetIsValid(c));
assert(paint != null); // ignore: unnecessary_null_comparison
_drawCircle(c, radius, paint);
}
Expand Down Expand Up @@ -236,7 +236,7 @@ class CanvasKitCanvas implements ui.Canvas {
void drawImage(ui.Image image, ui.Offset p, ui.Paint paint) {
// ignore: unnecessary_null_comparison
assert(image != null); // image is checked on the engine side
assert(_offsetIsValid(p));
assert(offsetIsValid(p));
assert(paint != null); // ignore: unnecessary_null_comparison
_canvas.drawImage(image as CkImage, p, paint as CkPaint);
}
Expand Down Expand Up @@ -272,7 +272,7 @@ class CanvasKitCanvas implements ui.Canvas {
@override
void drawParagraph(ui.Paragraph paragraph, ui.Offset offset) {
assert(paragraph != null); // ignore: unnecessary_null_comparison
assert(_offsetIsValid(offset));
assert(offsetIsValid(offset));
_drawParagraph(paragraph, offset);
}

Expand Down
14 changes: 7 additions & 7 deletions lib/web_ui/lib/src/engine/canvaskit/shader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ abstract class CkShader extends ManagedSkiaObject<SkShader>
class CkGradientSweep extends CkShader implements ui.Gradient {
CkGradientSweep(this.center, this.colors, this.colorStops, this.tileMode,
this.startAngle, this.endAngle, this.matrix4)
: assert(_offsetIsValid(center)),
: assert(offsetIsValid(center)),
assert(colors != null), // ignore: unnecessary_null_comparison
assert(tileMode != null), // ignore: unnecessary_null_comparison
assert(startAngle != null), // ignore: unnecessary_null_comparison
assert(endAngle != null), // ignore: unnecessary_null_comparison
assert(startAngle < endAngle),
assert(matrix4 == null || _matrix4IsValid(matrix4)) {
_validateColorStops(colors, colorStops);
assert(matrix4 == null || matrix4IsValid(matrix4)) {
validateColorStops(colors, colorStops);
}

final ui.Offset center;
Expand Down Expand Up @@ -65,14 +65,14 @@ class CkGradientLinear extends CkShader implements ui.Gradient {
this.colorStops,
this.tileMode,
Float32List? matrix,
) : assert(_offsetIsValid(from)),
assert(_offsetIsValid(to)),
) : assert(offsetIsValid(from)),
assert(offsetIsValid(to)),
assert(colors != null), // ignore: unnecessary_null_comparison
assert(tileMode != null), // ignore: unnecessary_null_comparison
this.matrix4 = matrix {
if (assertionsEnabled) {
assert(matrix4 == null || _matrix4IsValid(matrix4!));
_validateColorStops(colors, colorStops);
assert(matrix4 == null || matrix4IsValid(matrix4!));
validateColorStops(colors, colorStops);
}
}

Expand Down
28 changes: 28 additions & 0 deletions lib/web_ui/lib/src/engine/font_change_util.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

part of engine;

final ByteData? _fontChangeMessage =
JSONMessageCodec().encodeMessage(<String, dynamic>{'type': 'fontsChange'});

// Font load callbacks will typically arrive in sequence, we want to prevent
// sendFontChangeMessage of causing multiple synchronous rebuilds.
// This flag ensures we properly schedule a single call to framework.
bool _fontChangeScheduled = false;

FutureOr<void> sendFontChangeMessage() async {
if (!_fontChangeScheduled) {
_fontChangeScheduled = true;
// Batch updates into next animationframe.
html.window.requestAnimationFrame((num _) {
_fontChangeScheduled = false;
EnginePlatformDispatcher.instance.invokeOnPlatformMessage(
'flutter/system',
_fontChangeMessage,
(_) {},
);
});
}
}
12 changes: 6 additions & 6 deletions lib/web_ui/lib/src/engine/html/clip.dart
Original file line number Diff line number Diff line change
Expand Up @@ -326,12 +326,12 @@ class PersistedPhysicalShape extends PersistedContainerSurface
/// to clipping rect bounds (which is the case for elevation == 0.0 where
/// we shift outer/inner clip area instead to position clip-path).
final String svgClipPath = elevation == 0.0
? _pathToSvgClipPath(path,
? pathToSvgClipPath(path,
offsetX: -pathBounds.left,
offsetY: -pathBounds.top,
scaleX: 1.0 / pathBounds.width,
scaleY: 1.0 / pathBounds.height)
: _pathToSvgClipPath(path,
: pathToSvgClipPath(path,
offsetX: 0.0,
offsetY: 0.0,
scaleX: 1.0 / pathBounds.right,
Expand All @@ -345,7 +345,7 @@ class PersistedPhysicalShape extends PersistedContainerSurface
html.Element.html(svgClipPath, treeSanitizer: _NullTreeSanitizer());
domRenderer.append(rootElement!, _clipElement!);
if (elevation == 0.0) {
DomRenderer.setClipPath(rootElement!, 'url(#svgClip$_clipIdCounter)');
DomRenderer.setClipPath(rootElement!, createSvgClipUrl());
final html.CssStyleDeclaration rootElementStyle = rootElement!.style;
rootElementStyle
..overflow = ''
Expand All @@ -360,7 +360,7 @@ class PersistedPhysicalShape extends PersistedContainerSurface
return;
}

DomRenderer.setClipPath(childContainer!, 'url(#svgClip$_clipIdCounter)');
DomRenderer.setClipPath(childContainer!, createSvgClipUrl());
final html.CssStyleDeclaration rootElementStyle = rootElement!.style;
rootElementStyle
..overflow = ''
Expand Down Expand Up @@ -500,9 +500,9 @@ class PersistedClipPath extends PersistedContainerSurface
/// Creates an svg clipPath and applies it to [element].
String createSvgClipDef(html.HtmlElement element, ui.Path clipPath) {
final ui.Rect pathBounds = clipPath.getBounds();
final String svgClipPath = _pathToSvgClipPath(clipPath,
final String svgClipPath = pathToSvgClipPath(clipPath,
scaleX: 1.0 / pathBounds.right, scaleY: 1.0 / pathBounds.bottom);
DomRenderer.setClipPath(element, 'url(#svgClip$_clipIdCounter)');
DomRenderer.setClipPath(element, createSvgClipUrl());
// We need to set width and height for the clipElement to cover the
// bounds of the path since browsers such as Safari and Edge
// seem to incorrectly intersect the element bounding rect with
Expand Down
64 changes: 35 additions & 29 deletions lib/web_ui/lib/src/engine/html/path/conic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

part of engine;
import 'dart:typed_data';
import 'dart:math' as math;

import 'package:ui/ui.dart' as ui;

import 'path_utils.dart';

/// Converts conic curve to a list of quadratic curves for rendering on
/// canvas or conversion to svg.
Expand Down Expand Up @@ -198,7 +203,7 @@ class Conic {
final double coeff0 = fW * p20 - p20;
final double coeff1 = p20 - 2 * wP10;
final double coeff2 = wP10;
final _QuadRoots quadRoots = _QuadRoots();
final QuadRoots quadRoots = QuadRoots();
int rootCount = quadRoots.findRoots(coeff0, coeff1, coeff2);
assert(rootCount == 0 || rootCount == 1);
if (rootCount == 1) {
Expand Down Expand Up @@ -230,12 +235,12 @@ class Conic {
final double dz1 = dz0 + (dz2 - dz0) * t;
// Compute new weights.
final double root = math.sqrt(dz1);
if (_nearlyEqual(root, 0)) {
if (SPath.nearlyEqual(root, 0)) {
return false;
}
final double w0 = dz0 / root;
final double w2 = dz2 / root;
if (_nearlyEqual(dz0, 0) || _nearlyEqual(dz1, 0) || _nearlyEqual(dz2, 0)) {
if (SPath.nearlyEqual(dz0, 0) || SPath.nearlyEqual(dz1, 0) || SPath.nearlyEqual(dz2, 0)) {
return false;
}
// Now we can construct the 2 conics by projecting 3D down to 2D.
Expand Down Expand Up @@ -314,33 +319,34 @@ class Conic {
double ay = fW * p20y - p20y;
double bx = p20x - cx - cx;
double by = p20y - cy - cy;
_SkQuadCoefficients quadC = _SkQuadCoefficients(ax, ay, bx, by, cx, cy);
SkQuadCoefficients quadC = SkQuadCoefficients(ax, ay, bx, by, cx, cy);
return ui.Offset(quadC.evalX(t), quadC.evalY(t));
}
}

double _conicEvalNumerator(
double p0, double p1, double p2, double w, double t) {
assert(t >= 0 && t <= 1);
final double src2w = p1 * w;
final C = p0;
final A = p2 - 2 * src2w + C;
final B = 2 * (src2w - C);
return polyEval(A, B, C, t);
}
static double evalNumerator(
double p0, double p1, double p2, double w, double t) {
assert(t >= 0 && t <= 1);
final double src2w = p1 * w;
final C = p0;
final A = p2 - 2 * src2w + C;
final B = 2 * (src2w - C);
return polyEval(A, B, C, t);
}

double _conicEvalDenominator(double w, double t) {
double B = 2 * (w - 1);
double C = 1;
double A = -B;
return polyEval(A, B, C, t);
static double evalDenominator(double w, double t) {
double B = 2 * (w - 1);
double C = 1;
double A = -B;
return polyEval(A, B, C, t);
}
}

class _QuadBounds {
class QuadBounds {
double minX = 0;
double minY = 0;
double maxX = 0;
double maxY = 0;

void calculateBounds(Float32List points, int pointIndex) {
final double x1 = points[pointIndex++];
final double y1 = points[pointIndex++];
Expand Down Expand Up @@ -398,7 +404,7 @@ class _QuadBounds {
}
}

class _ConicBounds {
class ConicBounds {
double minX = 0;
double minY = 0;
double maxX = 0;
Expand All @@ -420,7 +426,7 @@ class _ConicBounds {
// ------------------------------------------------
// {t^2 (2 - 2 w), t (-2 + 2 w), 1}
// Calculate coefficients and solve root.
_QuadRoots roots = _QuadRoots();
QuadRoots roots = QuadRoots();
final double P20x = x2 - x1;
final double P10x = cpX - x1;
final double wP10x = w * P10x;
Expand All @@ -431,10 +437,10 @@ class _ConicBounds {
if (n != 0) {
final double t1 = roots.root0!;
if ((t1 >= 0) && (t1 <= 1.0)) {
final double denom = _conicEvalDenominator(w, t1);
double numerator = _conicEvalNumerator(x1, cpX, x2, w, t1);
final double denom = Conic.evalDenominator(w, t1);
double numerator = Conic.evalNumerator(x1, cpX, x2, w, t1);
final double extremaX = numerator / denom;
numerator = _conicEvalNumerator(y1, cpY, y2, w, t1);
numerator = Conic.evalNumerator(y1, cpY, y2, w, t1);
final double extremaY = numerator / denom;
// Expand bounds.
minX = math.min(minX, extremaX);
Expand All @@ -454,10 +460,10 @@ class _ConicBounds {
if (n != 0) {
final double t2 = roots.root0!;
if ((t2 >= 0) && (t2 <= 1.0)) {
final double denom = _conicEvalDenominator(w, t2);
double numerator = _conicEvalNumerator(x1, cpX, x2, w, t2);
final double denom = Conic.evalDenominator(w, t2);
double numerator = Conic.evalNumerator(x1, cpX, x2, w, t2);
final double extrema2X = numerator / denom;
numerator = _conicEvalNumerator(y1, cpY, y2, w, t2);
numerator = Conic.evalNumerator(y1, cpY, y2, w, t2);
final double extrema2Y = numerator / denom;
// Expand bounds.
minX = math.min(minX, extrema2X);
Expand Down
Loading