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
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ allowed_hosts = [
]

deps = {
'src': 'https://github.com/flutter/buildroot.git' + '@' + '337fdd987f500ca48902aef9abbcde98be2803c7',
'src': 'https://github.com/flutter/buildroot.git' + '@' + 'af893d511e89f93194f86dae8a4ef39e3b3fe59b',

# Fuchsia compatibility
#
Expand Down
2 changes: 2 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,7 @@ FILE: ../../../flutter/lib/ui/isolate_name_server/isolate_name_server_natives.cc
FILE: ../../../flutter/lib/ui/isolate_name_server/isolate_name_server_natives.h
FILE: ../../../flutter/lib/ui/key.dart
FILE: ../../../flutter/lib/ui/lerp.dart
FILE: ../../../flutter/lib/ui/math.dart
FILE: ../../../flutter/lib/ui/natives.dart
FILE: ../../../flutter/lib/ui/painting.dart
FILE: ../../../flutter/lib/ui/painting/canvas.cc
Expand Down Expand Up @@ -1149,6 +1150,7 @@ FILE: ../../../flutter/lib/web_ui/lib/hash_codes.dart
FILE: ../../../flutter/lib/web_ui/lib/initialization.dart
FILE: ../../../flutter/lib/web_ui/lib/key.dart
FILE: ../../../flutter/lib/web_ui/lib/lerp.dart
FILE: ../../../flutter/lib/web_ui/lib/math.dart
FILE: ../../../flutter/lib/web_ui/lib/natives.dart
FILE: ../../../flutter/lib/web_ui/lib/painting.dart
FILE: ../../../flutter/lib/web_ui/lib/path.dart
Expand Down
1 change: 1 addition & 0 deletions lib/ui/dart_ui.gni
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dart_ui_files = [
"//flutter/lib/ui/isolate_name_server.dart",
"//flutter/lib/ui/key.dart",
"//flutter/lib/ui/lerp.dart",
"//flutter/lib/ui/math.dart",
"//flutter/lib/ui/natives.dart",
"//flutter/lib/ui/painting.dart",
"//flutter/lib/ui/platform_dispatcher.dart",
Expand Down
139 changes: 100 additions & 39 deletions lib/ui/geometry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,37 @@ class Radius {
/// You can use [Radius.zero] with [RRect] to have right-angle corners.
static const Radius zero = Radius.circular(0.0);

/// Returns this [Radius], with values clamped to the given min and max
/// [Radius] values.
///
/// The `min` value defaults to `Radius.circular(-double.infinity)`, and
/// the `max` value defaults to `Radius.circular(double.infinity)`.
Radius clamp({Radius? minimum, Radius? maximum}) {
minimum ??= const Radius.circular(-double.infinity);
maximum ??= const Radius.circular(double.infinity);
return Radius.elliptical(
clampDouble(x, minimum.x, maximum.x),
clampDouble(y, minimum.y, maximum.y),
);
}

/// Returns this [Radius], with values clamped to the given min and max
/// values in each dimension
///
/// The `minimumX` and `minimumY` values default to `-double.infinity`, and
/// the `maximumX` and `maximumY` values default to `double.infinity`.
Radius clampValues({
double? minimumX,
double? minimumY,
double? maximumX,
double? maximumY,
}) {
return Radius.elliptical(
clampDouble(x, minimumX ?? -double.infinity, maximumX ?? double.infinity),
clampDouble(y, minimumY ?? -double.infinity, maximumY ?? double.infinity),
);
}

/// Unary negation operator.
///
/// Returns a Radius with the distances negated.
Expand Down Expand Up @@ -1056,8 +1087,16 @@ class Radius {
class RRect {
/// Construct a rounded rectangle from its left, top, right, and bottom edges,
/// and the same radii along its horizontal axis and its vertical axis.
const RRect.fromLTRBXY(double left, double top, double right, double bottom,
double radiusX, double radiusY) : this._raw(
///
/// Will assert in debug mode if `radiusX` or `radiusY` are negative.
const RRect.fromLTRBXY(
double left,
double top,
double right,
double bottom,
double radiusX,
double radiusY,
) : this._raw(
top: top,
left: left,
right: right,
Expand All @@ -1074,8 +1113,15 @@ class RRect {

/// Construct a rounded rectangle from its left, top, right, and bottom edges,
/// and the same radius in each corner.
RRect.fromLTRBR(double left, double top, double right, double bottom,
Radius radius)
///
/// Will assert in debug mode if the `radius` is negative in either x or y.
RRect.fromLTRBR(
double left,
double top,
double right,
double bottom,
Radius radius,
)
: this._raw(
top: top,
left: left,
Expand All @@ -1093,6 +1139,8 @@ class RRect {

/// Construct a rounded rectangle from its bounding box and the same radii
/// along its horizontal axis and its vertical axis.
///
/// Will assert in debug mode if `radiusX` or `radiusY` are negative.
RRect.fromRectXY(Rect rect, double radiusX, double radiusY)
: this._raw(
top: rect.top,
Expand All @@ -1111,6 +1159,8 @@ class RRect {

/// Construct a rounded rectangle from its bounding box and a radius that is
/// the same in each corner.
///
/// Will assert in debug mode if the `radius` is negative in either x or y.
RRect.fromRectAndRadius(Rect rect, Radius radius)
: this._raw(
top: rect.top,
Expand All @@ -1130,7 +1180,8 @@ class RRect {
/// Construct a rounded rectangle from its left, top, right, and bottom edges,
/// and topLeft, topRight, bottomRight, and bottomLeft radii.
///
/// The corner radii default to [Radius.zero], i.e. right-angled corners.
/// The corner radii default to [Radius.zero], i.e. right-angled corners. Will
/// assert in debug mode if any of the radii are negative in either x or y.
RRect.fromLTRBAndCorners(
double left,
double top,
Expand Down Expand Up @@ -1158,7 +1209,8 @@ class RRect {
/// Construct a rounded rectangle from its bounding box and and topLeft,
/// topRight, bottomRight, and bottomLeft radii.
///
/// The corner radii default to [Radius.zero], i.e. right-angled corners
/// The corner radii default to [Radius.zero], i.e. right-angled corners. Will
/// assert in debug mode if any of the radii are negative in either x or y.
RRect.fromRectAndCorners(
Rect rect,
{
Expand Down Expand Up @@ -1206,7 +1258,15 @@ class RRect {
assert(brRadiusX != null),
assert(brRadiusY != null),
assert(blRadiusX != null),
assert(blRadiusY != null);
assert(blRadiusY != null),
assert(tlRadiusX >= 0),
assert(tlRadiusY >= 0),
assert(trRadiusX >= 0),
assert(trRadiusY >= 0),
assert(brRadiusX >= 0),
assert(brRadiusY >= 0),
assert(blRadiusX >= 0),
assert(blRadiusY >= 0);

Float32List _getValue32() {
final Float32List result = Float32List(12);
Expand Down Expand Up @@ -1302,14 +1362,14 @@ class RRect {
top: top - delta,
right: right + delta,
bottom: bottom + delta,
tlRadiusX: tlRadiusX + delta,
tlRadiusY: tlRadiusY + delta,
trRadiusX: trRadiusX + delta,
trRadiusY: trRadiusY + delta,
blRadiusX: blRadiusX + delta,
blRadiusY: blRadiusY + delta,
brRadiusX: brRadiusX + delta,
brRadiusY: brRadiusY + delta,
tlRadiusX: math.max(0, tlRadiusX + delta),
tlRadiusY: math.max(0, tlRadiusY + delta),
trRadiusX: math.max(0, trRadiusX + delta),
trRadiusY: math.max(0, trRadiusY + delta),
blRadiusX: math.max(0, blRadiusX + delta),
blRadiusY: math.max(0, blRadiusY + delta),
brRadiusX: math.max(0, brRadiusX + delta),
brRadiusY: math.max(0, brRadiusY + delta),
);
}

Expand Down Expand Up @@ -1472,6 +1532,7 @@ class RRect {
scale = _getMin(scale, tlRadiusX, trRadiusX, width);
scale = _getMin(scale, trRadiusY, brRadiusY, height);
scale = _getMin(scale, brRadiusX, blRadiusX, width);
assert(scale >= 0);

if (scale < 1.0) {
return RRect._raw(
Expand Down Expand Up @@ -1590,14 +1651,14 @@ class RRect {
top: a.top * k,
right: a.right * k,
bottom: a.bottom * k,
tlRadiusX: a.tlRadiusX * k,
tlRadiusY: a.tlRadiusY * k,
trRadiusX: a.trRadiusX * k,
trRadiusY: a.trRadiusY * k,
brRadiusX: a.brRadiusX * k,
brRadiusY: a.brRadiusY * k,
blRadiusX: a.blRadiusX * k,
blRadiusY: a.blRadiusY * k,
tlRadiusX: math.max(0, a.tlRadiusX * k),
tlRadiusY: math.max(0, a.tlRadiusY * k),
trRadiusX: math.max(0, a.trRadiusX * k),
trRadiusY: math.max(0, a.trRadiusY * k),
brRadiusX: math.max(0, a.brRadiusX * k),
brRadiusY: math.max(0, a.brRadiusY * k),
blRadiusX: math.max(0, a.blRadiusX * k),
blRadiusY: math.max(0, a.blRadiusY * k),
);
}
} else {
Expand All @@ -1607,29 +1668,29 @@ class RRect {
top: b.top * t,
right: b.right * t,
bottom: b.bottom * t,
tlRadiusX: b.tlRadiusX * t,
tlRadiusY: b.tlRadiusY * t,
trRadiusX: b.trRadiusX * t,
trRadiusY: b.trRadiusY * t,
brRadiusX: b.brRadiusX * t,
brRadiusY: b.brRadiusY * t,
blRadiusX: b.blRadiusX * t,
blRadiusY: b.blRadiusY * t,
tlRadiusX: math.max(0, b.tlRadiusX * t),
tlRadiusY: math.max(0, b.tlRadiusY * t),
trRadiusX: math.max(0, b.trRadiusX * t),
trRadiusY: math.max(0, b.trRadiusY * t),
brRadiusX: math.max(0, b.brRadiusX * t),
brRadiusY: math.max(0, b.brRadiusY * t),
blRadiusX: math.max(0, b.blRadiusX * t),
blRadiusY: math.max(0, b.blRadiusY * t),
);
} else {
return RRect._raw(
left: _lerpDouble(a.left, b.left, t),
top: _lerpDouble(a.top, b.top, t),
right: _lerpDouble(a.right, b.right, t),
bottom: _lerpDouble(a.bottom, b.bottom, t),
tlRadiusX: _lerpDouble(a.tlRadiusX, b.tlRadiusX, t),
tlRadiusY: _lerpDouble(a.tlRadiusY, b.tlRadiusY, t),
trRadiusX: _lerpDouble(a.trRadiusX, b.trRadiusX, t),
trRadiusY: _lerpDouble(a.trRadiusY, b.trRadiusY, t),
brRadiusX: _lerpDouble(a.brRadiusX, b.brRadiusX, t),
brRadiusY: _lerpDouble(a.brRadiusY, b.brRadiusY, t),
blRadiusX: _lerpDouble(a.blRadiusX, b.blRadiusX, t),
blRadiusY: _lerpDouble(a.blRadiusY, b.blRadiusY, t),
tlRadiusX: math.max(0, _lerpDouble(a.tlRadiusX, b.tlRadiusX, t)),
tlRadiusY: math.max(0, _lerpDouble(a.tlRadiusY, b.tlRadiusY, t)),
trRadiusX: math.max(0, _lerpDouble(a.trRadiusX, b.trRadiusX, t)),
trRadiusY: math.max(0, _lerpDouble(a.trRadiusY, b.trRadiusY, t)),
brRadiusX: math.max(0, _lerpDouble(a.brRadiusX, b.brRadiusX, t)),
brRadiusY: math.max(0, _lerpDouble(a.brRadiusY, b.brRadiusY, t)),
blRadiusX: math.max(0, _lerpDouble(a.blRadiusX, b.blRadiusX, t)),
blRadiusY: math.max(0, _lerpDouble(a.blRadiusY, b.blRadiusY, t)),
);
}
}
Expand Down
25 changes: 25 additions & 0 deletions lib/ui/math.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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 dart.ui;

/// Same as [num.clamp] but optimized for a non-null [double].
///
/// This is faster because it avoids polymorphism, boxing, and special cases for
/// floating point numbers.
//
// See also: //dev/benchmarks/microbenchmarks/lib/foundation/clamp.dart
double clampDouble(double x, double min, double max) {
assert(min <= max && !max.isNaN && !min.isNaN);
if (x < min) {
return min;
}
if (x > max) {
return max;
}
if (x.isNaN) {
return max;
}
return x;
}
2 changes: 1 addition & 1 deletion lib/ui/painting.dart
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ class Color {
/// The [opacity] value may not be null.
static int getAlphaFromOpacity(double opacity) {
assert(opacity != null);
return (opacity.clamp(0.0, 1.0) * 255).round();
return (clampDouble(opacity, 0.0, 1.0) * 255).round();
}

@override
Expand Down
1 change: 1 addition & 0 deletions lib/ui/ui.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ part 'hooks.dart';
part 'isolate_name_server.dart';
part 'key.dart';
part 'lerp.dart';
part 'math.dart';
part 'natives.dart';
part 'painting.dart';
part 'platform_dispatcher.dart';
Expand Down
11 changes: 7 additions & 4 deletions lib/web_ui/dev/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class BuildCommand extends Command<bool> with ArgUtils<bool> {
if (buildCanvasKit) {
steps.addAll(<PipelineStep>[
GnPipelineStep(target: 'canvaskit'),
NinjaPipelineStep(target: environment.canvasKitOutDir),
NinjaPipelineStep(target: environment.wasmReleaseOutDir),
]);
}
final Pipeline buildPipeline = Pipeline(steps: steps);
Expand All @@ -74,7 +74,7 @@ class BuildCommand extends Command<bool> with ArgUtils<bool> {
/// state. GN is pretty quick though, so it's OK to not support interruption.
class GnPipelineStep extends ProcessStep {
GnPipelineStep({this.target = 'engine'})
: assert(target == 'engine' || target == 'sdk');
: assert(target == 'engine' || target == 'canvaskit');

@override
String get description => 'gn';
Expand All @@ -89,7 +89,7 @@ class GnPipelineStep extends ProcessStep {

@override
Future<ProcessManager> createProcess() {
print('Running gn...');
print('Running gn for $target...');
final List<String> gnArgs = <String>[];
if (target == 'engine') {
gnArgs.addAll(<String>[
Expand All @@ -98,7 +98,10 @@ class GnPipelineStep extends ProcessStep {
'--full-dart-sdk',
]);
} else if (target == 'canvaskit') {
gnArgs.add('--wasm');
gnArgs.addAll(<String>[
'--wasm',
'--runtime-mode=release',
]);
} else {
throw StateError('Target was not engine or canvaskit: $target');
}
Expand Down
17 changes: 10 additions & 7 deletions lib/web_ui/dev/environment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class Environment {
io.Directory(pathlib.join(engineSrcDir.path, 'out'));
final io.Directory hostDebugUnoptDir =
io.Directory(pathlib.join(outDir.path, 'host_debug_unopt'));
final io.Directory canvasKitOutDir =
io.Directory(pathlib.join(outDir.path, 'wasm_debug'));
final io.Directory wasmReleaseOutDir =
io.Directory(pathlib.join(outDir.path, 'wasm_release'));
final io.Directory dartSdkDir =
io.Directory(pathlib.join(hostDebugUnoptDir.path, 'dart-sdk'));
final io.Directory webUiRootDir = io.Directory(
Expand All @@ -44,14 +44,15 @@ class Environment {
}
}


return Environment._(
self: self,
webUiRootDir: webUiRootDir,
engineSrcDir: engineSrcDir,
engineToolsDir: engineToolsDir,
outDir: outDir,
hostDebugUnoptDir: hostDebugUnoptDir,
canvasKitOutDir: canvasKitOutDir,
wasmReleaseOutDir: wasmReleaseOutDir,
dartSdkDir: dartSdkDir,
);
}
Expand All @@ -63,7 +64,7 @@ class Environment {
required this.engineToolsDir,
required this.outDir,
required this.hostDebugUnoptDir,
required this.canvasKitOutDir,
required this.wasmReleaseOutDir,
required this.dartSdkDir,
});

Expand All @@ -84,11 +85,13 @@ class Environment {
/// This is where you'll find the ninja output, such as the Dart SDK.
final io.Directory outDir;

/// The "host_debug_unopt" build of the Dart SDK.
/// The output directory for the host_debug_unopt build.
final io.Directory hostDebugUnoptDir;

/// The output directory for the build of CanvasKit.
final io.Directory canvasKitOutDir;
/// The output directory for the wasm_release build.
///
/// We build CanvasKit in release mode to reduce code size.
final io.Directory wasmReleaseOutDir;

/// The root of the Dart SDK.
final io.Directory dartSdkDir;
Expand Down
Loading