Skip to content

Commit 2b4c960

Browse files
authored
Remove more references to dart:ui.window (#120994)
* Remove more references to dart:ui.window * two more doc referenes * revert icon_color_test.dart
1 parent f99f472 commit 2b4c960

File tree

15 files changed

+99
-57
lines changed

15 files changed

+99
-57
lines changed

dev/benchmarks/macrobenchmarks/lib/src/web/bench_child_layers.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@ class BenchUpdateManyChildLayers extends SceneBuilderRecorder {
3232
double wobbleCounter = 0;
3333

3434
late List<Picture> _pictures;
35-
late Size windowSize;
35+
late Size viewSize;
3636
late Size cellSize;
3737
late Size rectSize;
3838

3939
@override
4040
Future<void> setUpAll() async {
4141
_pictures = <Picture>[];
42-
windowSize = window.physicalSize;
42+
viewSize = view.physicalSize;
4343
cellSize = Size(
44-
windowSize.width / kColumns,
45-
windowSize.height / kRows,
44+
viewSize.width / kColumns,
45+
viewSize.height / kRows,
4646
);
4747
rectSize = cellSize * 0.8;
4848

dev/benchmarks/macrobenchmarks/lib/src/web/bench_clipped_out_pictures.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ class BenchClippedOutPictures extends SceneBuilderRecorder {
4141

4242
@override
4343
void onDrawFrame(SceneBuilder sceneBuilder) {
44-
final Size screenSize = window.physicalSize / window.devicePixelRatio;
44+
final Size viewSize = view.physicalSize / view.devicePixelRatio;
4545
final Size pictureSize = Size(
46-
screenSize.width / kColumns,
47-
screenSize.height / kRows,
46+
viewSize.width / kColumns,
47+
viewSize.height / kRows,
4848
);
4949

5050
// Fills a single cell with random text.
@@ -71,8 +71,8 @@ class BenchClippedOutPictures extends SceneBuilderRecorder {
7171

7272
// Starting with the top-left cell, fill every cell.
7373
sceneBuilder.pushClipRect(Rect.fromCircle(
74-
center: Offset(screenSize.width / 2, screenSize.height / 2),
75-
radius: math.min(screenSize.width, screenSize.height) / 6,
74+
center: Offset(viewSize.width / 2, viewSize.height / 2),
75+
radius: math.min(viewSize.width, viewSize.height) / 6,
7676
));
7777
sceneBuilder.pushOffset(
7878
5.0 * math.cos(angle),

dev/benchmarks/macrobenchmarks/lib/src/web/bench_draw_rect.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ class BenchDrawRect extends SceneBuilderRecorder {
6767
void onDrawFrame(SceneBuilder sceneBuilder) {
6868
final PictureRecorder pictureRecorder = PictureRecorder();
6969
final Canvas canvas = Canvas(pictureRecorder);
70-
final Size windowSize = window.physicalSize;
70+
final Size viewSize = view.physicalSize;
7171

7272
final Size cellSize = Size(
73-
windowSize.width / kColumns,
74-
windowSize.height / kRows,
73+
viewSize.width / kColumns,
74+
viewSize.height / kRows,
7575
);
7676
final Size rectSize = cellSize * 0.8;
7777

dev/benchmarks/macrobenchmarks/lib/src/web/bench_dynamic_clip_on_static_picture.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ class BenchDynamicClipOnStaticPicture extends SceneBuilderRecorder {
5151
const Color black = Color.fromARGB(255, 0, 0, 0);
5252
final PictureRecorder pictureRecorder = PictureRecorder();
5353
final Canvas canvas = Canvas(pictureRecorder);
54-
screenSize = window.physicalSize / window.devicePixelRatio;
54+
viewSize = view.physicalSize / view.devicePixelRatio;
5555
clipSize = Size(
56-
screenSize.width / 2,
57-
screenSize.height / 5,
56+
viewSize.width / 2,
57+
viewSize.height / 5,
5858
);
59-
final double cellWidth = screenSize.width / kColumns;
59+
final double cellWidth = viewSize.width / kColumns;
6060

6161
final List<Paragraph> paragraphs = generateLaidOutParagraphs(
6262
paragraphCount: 500,
@@ -93,7 +93,7 @@ class BenchDynamicClipOnStaticPicture extends SceneBuilderRecorder {
9393

9494
static const String benchmarkName = 'dynamic_clip_on_static_picture';
9595

96-
late Size screenSize;
96+
late Size viewSize;
9797
late Size clipSize;
9898
late Picture picture;
9999
double pictureVerticalOffset = 0.0;

dev/benchmarks/macrobenchmarks/lib/src/web/bench_text_out_of_picture_bounds.dart

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ class BenchTextOutOfPictureBounds extends SceneBuilderRecorder {
3737
paragraphCount: 500,
3838
minWordCountPerParagraph: 2,
3939
maxWordCountPerParagraph: 4,
40-
widthConstraint: window.physicalSize.width / 2,
40+
widthConstraint: view.physicalSize.width / 2,
4141
color: red,
4242
);
4343
multiLineParagraphs = generateLaidOutParagraphs(
4444
paragraphCount: 50,
4545
minWordCountPerParagraph: 30,
4646
maxWordCountPerParagraph: 49,
47-
widthConstraint: window.physicalSize.width / 2,
47+
widthConstraint: view.physicalSize.width / 2,
4848
color: green,
4949
);
5050
}
@@ -61,19 +61,19 @@ class BenchTextOutOfPictureBounds extends SceneBuilderRecorder {
6161
void onDrawFrame(SceneBuilder sceneBuilder) {
6262
final PictureRecorder pictureRecorder = PictureRecorder();
6363
final Canvas canvas = Canvas(pictureRecorder);
64-
final Size screenSize = window.physicalSize;
64+
final Size viewSize = view.physicalSize;
6565
const double padding = 10.0;
6666

6767
// Fills a single cell with random text.
6868
void fillCellWithText(List<Paragraph> textSource) {
6969
canvas.save();
7070
double topOffset = 0;
71-
while (topOffset < screenSize.height) {
71+
while (topOffset < viewSize.height) {
7272
final Paragraph paragraph =
7373
textSource[_random.nextInt(textSource.length)];
7474

7575
// Give it enough space to make sure it ends up being a single-line paragraph.
76-
paragraph.layout(ParagraphConstraints(width: screenSize.width / 2));
76+
paragraph.layout(ParagraphConstraints(width: viewSize.width / 2));
7777

7878
canvas.drawParagraph(paragraph, Offset.zero);
7979
canvas.translate(0, paragraph.height + padding);
@@ -83,12 +83,12 @@ class BenchTextOutOfPictureBounds extends SceneBuilderRecorder {
8383
}
8484

8585
// Starting with the top-left cell, fill every cell with text.
86-
canvas.translate(-screenSize.width, -screenSize.height);
86+
canvas.translate(-viewSize.width, -viewSize.height);
8787
for (int row = 0; row < 3; row++) {
8888
canvas.save();
8989
for (int col = 0; col < 3; col++) {
9090
canvas.drawRect(
91-
Offset.zero & screenSize,
91+
Offset.zero & viewSize,
9292
Paint()
9393
..style = PaintingStyle.stroke
9494
..strokeWidth = 2.0,
@@ -98,19 +98,19 @@ class BenchTextOutOfPictureBounds extends SceneBuilderRecorder {
9898

9999
// Fill multi-line text.
100100
canvas.save();
101-
canvas.translate(screenSize.width / 2, 0);
101+
canvas.translate(viewSize.width / 2, 0);
102102
fillCellWithText(multiLineParagraphs);
103103
canvas.restore();
104104

105105
// Shift to next column.
106-
canvas.translate(screenSize.width, 0);
106+
canvas.translate(viewSize.width, 0);
107107
}
108108

109109
// Undo horizontal shift.
110110
canvas.restore();
111111

112112
// Shift to next row.
113-
canvas.translate(0, screenSize.height);
113+
canvas.translate(0, viewSize.height);
114114
}
115115

116116
final Picture picture = pictureRecorder.endRecording();

dev/benchmarks/macrobenchmarks/lib/src/web/recorder.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ abstract class SceneBuilderRecorder extends Recorder {
279279
_profile!.record('sceneBuildDuration', () {
280280
final Scene scene = sceneBuilder.build();
281281
_profile!.record('windowRenderDuration', () {
282-
window.render(scene);
282+
view.render(scene);
283283
}, reported: false);
284284
}, reported: false);
285285
}, reported: true);
@@ -298,6 +298,11 @@ abstract class SceneBuilderRecorder extends Recorder {
298298
PlatformDispatcher.instance.scheduleFrame();
299299
return profileCompleter.future;
300300
}
301+
302+
FlutterView get view {
303+
assert(PlatformDispatcher.instance.implicitView != null, 'This benchmark requires the embedder to provide an implicit view.');
304+
return PlatformDispatcher.instance.implicitView!;
305+
}
301306
}
302307

303308
/// A recorder for benchmarking interactions with the framework by creating

dev/integration_tests/windows_startup_test/lib/main.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import 'package:flutter_driver/driver_extension.dart';
1010

1111
import 'windows.dart';
1212

13-
void drawHelloWorld() {
13+
void drawHelloWorld(ui.FlutterView view) {
1414
final ui.ParagraphStyle style = ui.ParagraphStyle();
1515
final ui.ParagraphBuilder paragraphBuilder = ui.ParagraphBuilder(style)
1616
..addText('Hello world');
@@ -28,10 +28,14 @@ void drawHelloWorld() {
2828
..addPicture(ui.Offset.zero, picture)
2929
..pop();
3030

31-
ui.window.render(sceneBuilder.build());
31+
view.render(sceneBuilder.build());
3232
}
3333

3434
void main() async {
35+
// TODO(goderbauer): Create a window if embedder doesn't provide an implicit view to draw into.
36+
assert(ui.PlatformDispatcher.instance.implicitView != null);
37+
final ui.FlutterView view = ui.PlatformDispatcher.instance.implicitView!;
38+
3539
// Create a completer to send the window visibility result back to the
3640
// integration test.
3741
final Completer<String> visibilityCompleter = Completer<String>();
@@ -81,7 +85,7 @@ void main() async {
8185

8286
// Draw something to trigger the first frame callback that displays the
8387
// window.
84-
drawHelloWorld();
88+
drawHelloWorld(view);
8589
firstFrame = false;
8690
};
8791

examples/layers/raw/canvas.dart

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import 'dart:math' as math;
99
import 'dart:typed_data';
1010
import 'dart:ui' as ui;
1111

12+
// The FlutterView into which this example will draw; set in the main method.
13+
late final ui.FlutterView view;
14+
1215
ui.Picture paint(ui.Rect paintBounds) {
1316
// First we create a PictureRecorder to record the commands we're going to
1417
// feed in the canvas. The PictureRecorder will eventually produce a Picture,
@@ -29,8 +32,8 @@ ui.Picture paint(ui.Rect paintBounds) {
2932
final ui.Offset mid = size.center(ui.Offset.zero);
3033
final double radius = size.shortestSide / 2.0;
3134

32-
final double devicePixelRatio = ui.window.devicePixelRatio;
33-
final ui.Size logicalSize = ui.window.physicalSize / devicePixelRatio;
35+
final double devicePixelRatio = view.devicePixelRatio;
36+
final ui.Size logicalSize = view.physicalSize / devicePixelRatio;
3437

3538
// Saves a copy of current transform onto the save stack.
3639
canvas.save();
@@ -101,7 +104,7 @@ ui.Picture paint(ui.Rect paintBounds) {
101104
}
102105

103106
ui.Scene composite(ui.Picture picture, ui.Rect paintBounds) {
104-
final double devicePixelRatio = ui.window.devicePixelRatio;
107+
final double devicePixelRatio = view.devicePixelRatio;
105108
final Float64List deviceTransform = Float64List(16)
106109
..[0] = devicePixelRatio
107110
..[5] = devicePixelRatio
@@ -115,13 +118,17 @@ ui.Scene composite(ui.Picture picture, ui.Rect paintBounds) {
115118
}
116119

117120
void beginFrame(Duration timeStamp) {
118-
final ui.Rect paintBounds = ui.Offset.zero & (ui.window.physicalSize / ui.window.devicePixelRatio);
121+
final ui.Rect paintBounds = ui.Offset.zero & (view.physicalSize / view.devicePixelRatio);
119122
final ui.Picture picture = paint(paintBounds);
120123
final ui.Scene scene = composite(picture, paintBounds);
121-
ui.window.render(scene);
124+
view.render(scene);
122125
}
123126

124127
void main() {
128+
// TODO(goderbauer): Create a window if embedder doesn't provide an implicit view to draw into.
129+
assert(ui.PlatformDispatcher.instance.implicitView != null);
130+
view = ui.PlatformDispatcher.instance.implicitView!;
131+
125132
ui.PlatformDispatcher.instance
126133
..onBeginFrame = beginFrame
127134
..scheduleFrame();

examples/layers/raw/hello_world.dart

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77

88
import 'dart:ui' as ui;
99

10+
// The FlutterView into which this example will draw; set in the main method.
11+
late final ui.FlutterView view;
12+
1013
void beginFrame(Duration timeStamp) {
11-
final double devicePixelRatio = ui.window.devicePixelRatio;
12-
final ui.Size logicalSize = ui.window.physicalSize / devicePixelRatio;
14+
final double devicePixelRatio = view.devicePixelRatio;
15+
final ui.Size logicalSize = view.physicalSize / devicePixelRatio;
1316

1417
final ui.ParagraphBuilder paragraphBuilder = ui.ParagraphBuilder(
1518
ui.ParagraphStyle(textDirection: ui.TextDirection.ltr),
@@ -35,12 +38,16 @@ void beginFrame(Duration timeStamp) {
3538
..addPicture(ui.Offset.zero, picture)
3639
..pop();
3740

38-
ui.window.render(sceneBuilder.build());
41+
view.render(sceneBuilder.build());
3942
}
4043

4144
// This function is the primary entry point to your application. The engine
4245
// calls main() as soon as it has loaded your code.
4346
void main() {
47+
// TODO(goderbauer): Create a window if embedder doesn't provide an implicit view to draw into.
48+
assert(ui.PlatformDispatcher.instance.implicitView != null);
49+
view = ui.PlatformDispatcher.instance.implicitView!;
50+
4451
// The engine calls onBeginFrame whenever it wants us to produce a frame.
4552
ui.PlatformDispatcher.instance.onBeginFrame = beginFrame;
4653
// Here we kick off the whole process by asking the engine to schedule a new

examples/layers/raw/spinning_square.dart

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import 'dart:math' as math;
99
import 'dart:typed_data';
1010
import 'dart:ui' as ui;
1111

12+
// The FlutterView into which this example will draw; set in the main method.
13+
late final ui.FlutterView view;
14+
1215
void beginFrame(Duration timeStamp) {
1316
// The timeStamp argument to beginFrame indicates the timing information we
1417
// should use to clock our animations. It's important to use timeStamp rather
@@ -19,7 +22,7 @@ void beginFrame(Duration timeStamp) {
1922

2023
// PAINT
2124

22-
final ui.Rect paintBounds = ui.Offset.zero & (ui.window.physicalSize / ui.window.devicePixelRatio);
25+
final ui.Rect paintBounds = ui.Offset.zero & (view.physicalSize / view.devicePixelRatio);
2326
final ui.PictureRecorder recorder = ui.PictureRecorder();
2427
final ui.Canvas canvas = ui.Canvas(recorder, paintBounds);
2528
canvas.translate(paintBounds.width / 2.0, paintBounds.height / 2.0);
@@ -37,7 +40,7 @@ void beginFrame(Duration timeStamp) {
3740

3841
// COMPOSITE
3942

40-
final double devicePixelRatio = ui.window.devicePixelRatio;
43+
final double devicePixelRatio = view.devicePixelRatio;
4144
final Float64List deviceTransform = Float64List(16)
4245
..[0] = devicePixelRatio
4346
..[5] = devicePixelRatio
@@ -47,7 +50,7 @@ void beginFrame(Duration timeStamp) {
4750
..pushTransform(deviceTransform)
4851
..addPicture(ui.Offset.zero, picture)
4952
..pop();
50-
ui.window.render(sceneBuilder.build());
53+
view.render(sceneBuilder.build());
5154

5255
// After rendering the current frame of the animation, we ask the engine to
5356
// schedule another frame. The engine will call beginFrame again when its time
@@ -56,6 +59,10 @@ void beginFrame(Duration timeStamp) {
5659
}
5760

5861
void main() {
62+
// TODO(goderbauer): Create a window if embedder doesn't provide an implicit view to draw into.
63+
assert(ui.PlatformDispatcher.instance.implicitView != null);
64+
view = ui.PlatformDispatcher.instance.implicitView!;
65+
5966
ui.PlatformDispatcher.instance
6067
..onBeginFrame = beginFrame
6168
..scheduleFrame();

0 commit comments

Comments
 (0)