Auto-format Framework (#160545)

This auto-formats all *.dart files in the repository outside of the
`engine` subdirectory and enforces that these files stay formatted with
a presubmit check.

**Reviewers:** Please carefully review all the commits except for the
one titled "formatted". The "formatted" commit was auto-generated by
running `dev/tools/format.sh -a -f`. The other commits were hand-crafted
to prepare the repo for the formatting change. I recommend reviewing the
commits one-by-one via the "Commits" tab and avoiding Github's "Files
changed" tab as it will likely slow down your browser because of the
size of this PR.

---------

Co-authored-by: Kate Lovett <katelovett@google.com>
Co-authored-by: LongCatIsLooong <31859944+LongCatIsLooong@users.noreply.github.com>
This commit is contained in:
Michael Goderbauer
2024-12-19 12:06:21 -08:00
committed by GitHub
parent 8e0993eda8
commit 5491c8c146
4411 changed files with 455108 additions and 415991 deletions

View File

@@ -44,8 +44,12 @@ bool _isAlmost(double x, double y, double epsilon) {
List<double> _deepRed = <double>[1.0931, -0.2268, -0.1501];
bool _findRGBAF16Color(
Uint8List bytes, int width, int height, List<double> color,
{required double epsilon}) {
Uint8List bytes,
int width,
int height,
List<double> color, {
required double epsilon,
}) {
final ByteData byteData = ByteData.sublistView(bytes);
expect(bytes.lengthInBytes, width * height * 8);
expect(bytes.lengthInBytes, byteData.lengthInBytes);
@@ -65,8 +69,12 @@ bool _findRGBAF16Color(
}
bool _findBGRA10Color(
Uint8List bytes, int width, int height, List<double> color,
{required double epsilon}) {
Uint8List bytes,
int width,
int height,
List<double> color, {
required double epsilon,
}) {
final ByteData byteData = ByteData.sublistView(bytes);
expect(bytes.lengthInBytes, width * height * 8);
expect(bytes.lengthInBytes, byteData.lengthInBytes);
@@ -85,8 +93,13 @@ bool _findBGRA10Color(
return foundDeepRed;
}
bool _findBGR10Color(Uint8List bytes, int width, int height, List<double> color,
{required double epsilon}) {
bool _findBGR10Color(
Uint8List bytes,
int width,
int height,
List<double> color, {
required double epsilon,
}) {
final ByteData byteData = ByteData.sublistView(bytes);
expect(bytes.lengthInBytes, width * height * 4);
expect(bytes.lengthInBytes, byteData.lengthInBytes);
@@ -105,18 +118,14 @@ bool _findBGR10Color(Uint8List bytes, int width, int height, List<double> color,
return foundDeepRed;
}
bool _findColor(List<dynamic> result, List<double> color,
{double epsilon = 0.01}) {
bool _findColor(List<dynamic> result, List<double> color, {double epsilon = 0.01}) {
expect(result, isNotNull);
expect(result.length, 4);
final [int width, int height, String format, Uint8List bytes] = result;
return switch (format) {
'MTLPixelFormatBGR10_XR' =>
_findBGR10Color(bytes, width, height, color, epsilon: epsilon),
'MTLPixelFormatBGRA10_XR' =>
_findBGRA10Color(bytes, width, height, color, epsilon: epsilon),
'MTLPixelFormatRGBA16Float' =>
_findRGBAF16Color(bytes, width, height, color, epsilon: epsilon),
'MTLPixelFormatBGR10_XR' => _findBGR10Color(bytes, width, height, color, epsilon: epsilon),
'MTLPixelFormatBGRA10_XR' => _findBGRA10Color(bytes, width, height, color, epsilon: epsilon),
'MTLPixelFormatRGBA16Float' => _findRGBAF16Color(bytes, width, height, color, epsilon: epsilon),
_ => fail('Unsupported pixel format: $format'),
};
}
@@ -130,8 +139,7 @@ void main() {
await tester.pumpAndSettle(const Duration(seconds: 2));
const MethodChannel channel = MethodChannel('flutter/screenshot');
final List<Object?> result =
await channel.invokeMethod('test') as List<Object?>;
final List<Object?> result = await channel.invokeMethod('test') as List<Object?>;
expect(_findColor(result, _deepRed), isTrue);
});
testWidgets('look for display p3 deepest red', (WidgetTester tester) async {
@@ -139,8 +147,7 @@ void main() {
await tester.pumpAndSettle(const Duration(seconds: 2));
const MethodChannel channel = MethodChannel('flutter/screenshot');
final List<Object?> result =
await channel.invokeMethod('test') as List<Object?>;
final List<Object?> result = await channel.invokeMethod('test') as List<Object?>;
expect(_findColor(result, _deepRed), isTrue);
});
testWidgets('no p3 deepest red without image', (WidgetTester tester) async {
@@ -148,8 +155,7 @@ void main() {
await tester.pumpAndSettle(const Duration(seconds: 2));
const MethodChannel channel = MethodChannel('flutter/screenshot');
final List<Object?> result =
await channel.invokeMethod('test') as List<Object?>;
final List<Object?> result = await channel.invokeMethod('test') as List<Object?>;
expect(_findColor(result, _deepRed), isFalse);
expect(_findColor(result, <double>[0.0, 1.0, 0.0]), isFalse);
});
@@ -158,73 +164,60 @@ void main() {
await tester.pumpAndSettle(const Duration(seconds: 2));
const MethodChannel channel = MethodChannel('flutter/screenshot');
final List<Object?> result =
await channel.invokeMethod('test') as List<Object?>;
final List<Object?> result = await channel.invokeMethod('test') as List<Object?>;
expect(_findColor(result, _deepRed), isTrue);
expect(_findColor(result, <double>[0.0, 1.0, 0.0]), isTrue);
});
testWidgets('draw image with wide gamut works',
(WidgetTester tester) async {
testWidgets('draw image with wide gamut works', (WidgetTester tester) async {
app.run(app.Setup.drawnImage);
await tester.pumpAndSettle(const Duration(seconds: 2));
const MethodChannel channel = MethodChannel('flutter/screenshot');
final List<Object?> result =
await channel.invokeMethod('test') as List<Object?>;
final List<Object?> result = await channel.invokeMethod('test') as List<Object?>;
expect(_findColor(result, <double>[0.0, 1.0, 0.0]), isTrue);
});
testWidgets('draw container with wide gamut works',
(WidgetTester tester) async {
testWidgets('draw container with wide gamut works', (WidgetTester tester) async {
app.run(app.Setup.container);
await tester.pumpAndSettle(const Duration(seconds: 2));
const MethodChannel channel = MethodChannel('flutter/screenshot');
final List<Object?> result =
await channel.invokeMethod('test') as List<Object?>;
final List<Object?> result = await channel.invokeMethod('test') as List<Object?>;
expect(_findColor(result, _deepRed), isTrue);
});
testWidgets('draw wide gamut linear gradient works',
(WidgetTester tester) async {
testWidgets('draw wide gamut linear gradient works', (WidgetTester tester) async {
app.run(app.Setup.linearGradient);
await tester.pumpAndSettle(const Duration(seconds: 2));
const MethodChannel channel = MethodChannel('flutter/screenshot');
final List<Object?> result =
await channel.invokeMethod('test') as List<Object?>;
final List<Object?> result = await channel.invokeMethod('test') as List<Object?>;
expect(_findColor(result, _deepRed), isTrue);
});
testWidgets('draw wide gamut radial gradient works',
(WidgetTester tester) async {
testWidgets('draw wide gamut radial gradient works', (WidgetTester tester) async {
app.run(app.Setup.radialGradient);
await tester.pumpAndSettle(const Duration(seconds: 2));
const MethodChannel channel = MethodChannel('flutter/screenshot');
final List<Object?> result =
await channel.invokeMethod('test') as List<Object?>;
final List<Object?> result = await channel.invokeMethod('test') as List<Object?>;
expect(_findColor(result, _deepRed, epsilon: 0.05), isTrue);
});
testWidgets('draw wide gamut conical gradient works',
(WidgetTester tester) async {
testWidgets('draw wide gamut conical gradient works', (WidgetTester tester) async {
app.run(app.Setup.conicalGradient);
await tester.pumpAndSettle(const Duration(seconds: 2));
const MethodChannel channel = MethodChannel('flutter/screenshot');
final List<Object?> result =
await channel.invokeMethod('test') as List<Object?>;
final List<Object?> result = await channel.invokeMethod('test') as List<Object?>;
expect(_findColor(result, _deepRed, epsilon: 0.05), isTrue);
});
testWidgets('draw wide gamut sweep gradient works',
(WidgetTester tester) async {
testWidgets('draw wide gamut sweep gradient works', (WidgetTester tester) async {
app.run(app.Setup.sweepGradient);
await tester.pumpAndSettle(const Duration(seconds: 2));
const MethodChannel channel = MethodChannel('flutter/screenshot');
final List<Object?> result =
await channel.invokeMethod('test') as List<Object?>;
final List<Object?> result = await channel.invokeMethod('test') as List<Object?>;
expect(_findColor(result, _deepRed), isTrue);
});
});

View File

@@ -165,9 +165,7 @@ class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
title: 'Wide Gamut Test',
theme: ThemeData(
primarySwatch: Colors.blue,
),
theme: ThemeData(primarySwatch: Colors.blue),
home: MyHomePage(_setup, title: 'Wide Gamut Test'),
);
}
@@ -182,19 +180,20 @@ class _SaveLayerDrawer extends CustomPainter {
void paint(Canvas canvas, Size size) {
if (_image != null) {
final Rect imageRect = Rect.fromCenter(
center: Offset.zero,
width: _image!.width.toDouble(),
height: _image!.height.toDouble());
center: Offset.zero,
width: _image!.width.toDouble(),
height: _image!.height.toDouble(),
);
canvas.saveLayer(imageRect, Paint());
canvas.drawRect(
imageRect.inflate(-_image!.width.toDouble() / 4.0),
Paint()
..style = PaintingStyle.stroke
..color = const Color(0xffffffff)
..strokeWidth = 3);
imageRect.inflate(-_image!.width.toDouble() / 4.0),
Paint()
..style = PaintingStyle.stroke
..color = const Color(0xffffffff)
..strokeWidth = 3,
);
canvas.saveLayer(imageRect, Paint()..blendMode = BlendMode.dstOver);
canvas.drawImage(_image!,
Offset(-_image!.width / 2.0, -_image!.height / 2.0), Paint());
canvas.drawImage(_image!, Offset(-_image!.width / 2.0, -_image!.height / 2.0), Paint());
canvas.restore();
canvas.restore();
}
@@ -208,43 +207,36 @@ Future<ui.Image> _drawImage() async {
final ui.PictureRecorder recorder = ui.PictureRecorder();
const Size markerSize = Size(120, 120);
final double canvasSize = markerSize.height + 3;
final Canvas canvas = Canvas(
recorder,
Rect.fromLTWH(0, 0, canvasSize, canvasSize),
);
final Canvas canvas = Canvas(recorder, Rect.fromLTWH(0, 0, canvasSize, canvasSize));
final Paint ovalPaint = Paint()..color = const Color(0xff00ff00);
final Path ovalPath = Path()
..addOval(Rect.fromLTWH(
(canvasSize - markerSize.width) / 2,
1,
markerSize.width,
markerSize.height,
));
final Path ovalPath =
Path()..addOval(
Rect.fromLTWH((canvasSize - markerSize.width) / 2, 1, markerSize.width, markerSize.height),
);
canvas.drawPath(ovalPath, ovalPaint);
final ui.Picture picture = recorder.endRecording();
final ui.Image image = await picture.toImage(
canvasSize.toInt(),
(canvasSize + 0).toInt(),
);
final ByteData? byteData =
await image.toByteData(format: ui.ImageByteFormat.rawExtendedRgba128);
final ui.Image image = await picture.toImage(canvasSize.toInt(), (canvasSize + 0).toInt());
final ByteData? byteData = await image.toByteData(format: ui.ImageByteFormat.rawExtendedRgba128);
final Completer<ui.Image> completer = Completer<ui.Image>();
ui.decodeImageFromPixels(Uint8List.view(byteData!.buffer),
canvasSize.toInt(),
canvasSize.toInt(),
ui.PixelFormat.rgbaFloat32, (ui.Image image) {
completer.complete(image);
});
ui.decodeImageFromPixels(
Uint8List.view(byteData!.buffer),
canvasSize.toInt(),
canvasSize.toInt(),
ui.PixelFormat.rgbaFloat32,
(ui.Image image) {
completer.complete(image);
},
);
return completer.future;
}
Future<ui.Image> _loadImage() async {
final ui.ImmutableBuffer buffer =
await ui.ImmutableBuffer.fromUint8List(base64Decode(_displayP3Logo));
final ui.ImageDescriptor descriptor =
await ui.ImageDescriptor.encoded(buffer);
final ui.ImmutableBuffer buffer = await ui.ImmutableBuffer.fromUint8List(
base64Decode(_displayP3Logo),
);
final ui.ImageDescriptor descriptor = await ui.ImageDescriptor.encoded(buffer);
final ui.Codec codec = await descriptor.instantiateCodec();
return (await codec.getNextFrame()).image;
}
@@ -266,17 +258,25 @@ class _MyHomePageState extends State<MyHomePage> {
void initState() {
switch (widget.setup) {
case Setup.canvasSaveLayer:
_loadImage().then((ui.Image? value) => setState(() { _image = value; }));
_loadImage().then(
(ui.Image? value) => setState(() {
_image = value;
}),
);
case Setup.drawnImage:
_drawImage().then((ui.Image? value) => setState(() { _image = value; }));
_drawImage().then(
(ui.Image? value) => setState(() {
_image = value;
}),
);
case Setup.image ||
Setup.blur ||
Setup.none ||
Setup.container ||
Setup.linearGradient ||
Setup.radialGradient ||
Setup.conicalGradient ||
Setup.sweepGradient:
Setup.blur ||
Setup.none ||
Setup.container ||
Setup.linearGradient ||
Setup.radialGradient ||
Setup.conicalGradient ||
Setup.sweepGradient:
break;
}
super.initState();
@@ -297,28 +297,25 @@ class _MyHomePageState extends State<MyHomePage> {
case Setup.blur:
imageWidget = Stack(
children: <Widget>[
const ColoredBox(
color: Color(0xff00ff00),
child: SizedBox(
width: 100,
height: 100,
),
),
const ColoredBox(color: Color(0xff00ff00), child: SizedBox(width: 100, height: 100)),
ImageFiltered(
imageFilter: ui.ImageFilter.blur(sigmaX: 6, sigmaY: 6),
child: Image.memory(base64Decode(_displayP3Logo))),
imageFilter: ui.ImageFilter.blur(sigmaX: 6, sigmaY: 6),
child: Image.memory(base64Decode(_displayP3Logo)),
),
],
);
case Setup.container:
imageWidget = Container(
width: 100,
height: 100,
color: const Color.from(
alpha: 1,
red: 1,
green: 0,
blue: 0,
colorSpace: ui.ColorSpace.displayP3));
color: const Color.from(
alpha: 1,
red: 1,
green: 0,
blue: 0,
colorSpace: ui.ColorSpace.displayP3,
),
);
case Setup.linearGradient:
imageWidget = Container(
width: 100,
@@ -333,13 +330,16 @@ class _MyHomePageState extends State<MyHomePage> {
red: 1,
green: 0,
blue: 0,
colorSpace: ui.ColorSpace.displayP3),
colorSpace: ui.ColorSpace.displayP3,
),
Color.from(
alpha: 1,
red: 0,
green: 1,
blue: 0,
colorSpace: ui.ColorSpace.displayP3)],
colorSpace: ui.ColorSpace.displayP3,
),
],
),
),
);
@@ -355,13 +355,16 @@ class _MyHomePageState extends State<MyHomePage> {
red: 1,
green: 0,
blue: 0,
colorSpace: ui.ColorSpace.displayP3),
colorSpace: ui.ColorSpace.displayP3,
),
Color.from(
alpha: 1,
red: 0,
green: 1,
blue: 0,
colorSpace: ui.ColorSpace.displayP3)],
colorSpace: ui.ColorSpace.displayP3,
),
],
),
),
);
@@ -378,13 +381,16 @@ class _MyHomePageState extends State<MyHomePage> {
red: 1,
green: 0,
blue: 0,
colorSpace: ui.ColorSpace.displayP3),
colorSpace: ui.ColorSpace.displayP3,
),
Color.from(
alpha: 1,
red: 0,
green: 1,
blue: 0,
colorSpace: ui.ColorSpace.displayP3)],
colorSpace: ui.ColorSpace.displayP3,
),
],
),
),
);
@@ -400,29 +406,25 @@ class _MyHomePageState extends State<MyHomePage> {
red: 1,
green: 0,
blue: 0,
colorSpace: ui.ColorSpace.displayP3),
colorSpace: ui.ColorSpace.displayP3,
),
Color.from(
alpha: 1,
red: 0,
green: 1,
blue: 0,
colorSpace: ui.ColorSpace.displayP3)],
colorSpace: ui.ColorSpace.displayP3,
),
],
),
),
);
}
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
appBar: AppBar(title: Text(widget.title)),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
imageWidget,
],
),
child: Column(mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[imageWidget]),
),
);
}