Remove more references to dart:ui.window (#120994)

* Remove more references to dart:ui.window

* two more doc referenes

* revert icon_color_test.dart
This commit is contained in:
Michael Goderbauer
2023-02-17 17:50:08 -08:00
committed by GitHub
parent f99f472807
commit 2b4c960885
15 changed files with 99 additions and 57 deletions

View File

@@ -9,6 +9,9 @@ import 'dart:math' as math;
import 'dart:typed_data';
import 'dart:ui' as ui;
// The FlutterView into which this example will draw; set in the main method.
late final ui.FlutterView view;
ui.Picture paint(ui.Rect paintBounds) {
// First we create a PictureRecorder to record the commands we're going to
// feed in the canvas. The PictureRecorder will eventually produce a Picture,
@@ -29,8 +32,8 @@ ui.Picture paint(ui.Rect paintBounds) {
final ui.Offset mid = size.center(ui.Offset.zero);
final double radius = size.shortestSide / 2.0;
final double devicePixelRatio = ui.window.devicePixelRatio;
final ui.Size logicalSize = ui.window.physicalSize / devicePixelRatio;
final double devicePixelRatio = view.devicePixelRatio;
final ui.Size logicalSize = view.physicalSize / devicePixelRatio;
// Saves a copy of current transform onto the save stack.
canvas.save();
@@ -101,7 +104,7 @@ ui.Picture paint(ui.Rect paintBounds) {
}
ui.Scene composite(ui.Picture picture, ui.Rect paintBounds) {
final double devicePixelRatio = ui.window.devicePixelRatio;
final double devicePixelRatio = view.devicePixelRatio;
final Float64List deviceTransform = Float64List(16)
..[0] = devicePixelRatio
..[5] = devicePixelRatio
@@ -115,13 +118,17 @@ ui.Scene composite(ui.Picture picture, ui.Rect paintBounds) {
}
void beginFrame(Duration timeStamp) {
final ui.Rect paintBounds = ui.Offset.zero & (ui.window.physicalSize / ui.window.devicePixelRatio);
final ui.Rect paintBounds = ui.Offset.zero & (view.physicalSize / view.devicePixelRatio);
final ui.Picture picture = paint(paintBounds);
final ui.Scene scene = composite(picture, paintBounds);
ui.window.render(scene);
view.render(scene);
}
void main() {
// TODO(goderbauer): Create a window if embedder doesn't provide an implicit view to draw into.
assert(ui.PlatformDispatcher.instance.implicitView != null);
view = ui.PlatformDispatcher.instance.implicitView!;
ui.PlatformDispatcher.instance
..onBeginFrame = beginFrame
..scheduleFrame();

View File

@@ -7,9 +7,12 @@
import 'dart:ui' as ui;
// The FlutterView into which this example will draw; set in the main method.
late final ui.FlutterView view;
void beginFrame(Duration timeStamp) {
final double devicePixelRatio = ui.window.devicePixelRatio;
final ui.Size logicalSize = ui.window.physicalSize / devicePixelRatio;
final double devicePixelRatio = view.devicePixelRatio;
final ui.Size logicalSize = view.physicalSize / devicePixelRatio;
final ui.ParagraphBuilder paragraphBuilder = ui.ParagraphBuilder(
ui.ParagraphStyle(textDirection: ui.TextDirection.ltr),
@@ -35,12 +38,16 @@ void beginFrame(Duration timeStamp) {
..addPicture(ui.Offset.zero, picture)
..pop();
ui.window.render(sceneBuilder.build());
view.render(sceneBuilder.build());
}
// This function is the primary entry point to your application. The engine
// calls main() as soon as it has loaded your code.
void main() {
// TODO(goderbauer): Create a window if embedder doesn't provide an implicit view to draw into.
assert(ui.PlatformDispatcher.instance.implicitView != null);
view = ui.PlatformDispatcher.instance.implicitView!;
// The engine calls onBeginFrame whenever it wants us to produce a frame.
ui.PlatformDispatcher.instance.onBeginFrame = beginFrame;
// Here we kick off the whole process by asking the engine to schedule a new

View File

@@ -9,6 +9,9 @@ import 'dart:math' as math;
import 'dart:typed_data';
import 'dart:ui' as ui;
// The FlutterView into which this example will draw; set in the main method.
late final ui.FlutterView view;
void beginFrame(Duration timeStamp) {
// The timeStamp argument to beginFrame indicates the timing information we
// should use to clock our animations. It's important to use timeStamp rather
@@ -19,7 +22,7 @@ void beginFrame(Duration timeStamp) {
// PAINT
final ui.Rect paintBounds = ui.Offset.zero & (ui.window.physicalSize / ui.window.devicePixelRatio);
final ui.Rect paintBounds = ui.Offset.zero & (view.physicalSize / view.devicePixelRatio);
final ui.PictureRecorder recorder = ui.PictureRecorder();
final ui.Canvas canvas = ui.Canvas(recorder, paintBounds);
canvas.translate(paintBounds.width / 2.0, paintBounds.height / 2.0);
@@ -37,7 +40,7 @@ void beginFrame(Duration timeStamp) {
// COMPOSITE
final double devicePixelRatio = ui.window.devicePixelRatio;
final double devicePixelRatio = view.devicePixelRatio;
final Float64List deviceTransform = Float64List(16)
..[0] = devicePixelRatio
..[5] = devicePixelRatio
@@ -47,7 +50,7 @@ void beginFrame(Duration timeStamp) {
..pushTransform(deviceTransform)
..addPicture(ui.Offset.zero, picture)
..pop();
ui.window.render(sceneBuilder.build());
view.render(sceneBuilder.build());
// After rendering the current frame of the animation, we ask the engine to
// schedule another frame. The engine will call beginFrame again when its time
@@ -56,6 +59,10 @@ void beginFrame(Duration timeStamp) {
}
void main() {
// TODO(goderbauer): Create a window if embedder doesn't provide an implicit view to draw into.
assert(ui.PlatformDispatcher.instance.implicitView != null);
view = ui.PlatformDispatcher.instance.implicitView!;
ui.PlatformDispatcher.instance
..onBeginFrame = beginFrame
..scheduleFrame();

View File

@@ -8,6 +8,9 @@
import 'dart:typed_data';
import 'dart:ui' as ui;
// The FlutterView into which this example will draw; set in the main method.
late final ui.FlutterView view;
// A paragraph represents a rectangular region that contains some text.
late ui.Paragraph paragraph;
@@ -15,8 +18,8 @@ ui.Picture paint(ui.Rect paintBounds) {
final ui.PictureRecorder recorder = ui.PictureRecorder();
final ui.Canvas canvas = ui.Canvas(recorder, paintBounds);
final double devicePixelRatio = ui.window.devicePixelRatio;
final ui.Size logicalSize = ui.window.physicalSize / devicePixelRatio;
final double devicePixelRatio = view.devicePixelRatio;
final ui.Size logicalSize = view.physicalSize / devicePixelRatio;
canvas.translate(logicalSize.width / 2.0, logicalSize.height / 2.0);
canvas.drawRect(
@@ -32,7 +35,7 @@ ui.Picture paint(ui.Rect paintBounds) {
}
ui.Scene composite(ui.Picture picture, ui.Rect paintBounds) {
final double devicePixelRatio = ui.window.devicePixelRatio;
final double devicePixelRatio = view.devicePixelRatio;
final Float64List deviceTransform = Float64List(16)
..[0] = devicePixelRatio
..[5] = devicePixelRatio
@@ -46,13 +49,17 @@ ui.Scene composite(ui.Picture picture, ui.Rect paintBounds) {
}
void beginFrame(Duration timeStamp) {
final ui.Rect paintBounds = ui.Offset.zero & (ui.window.physicalSize / ui.window.devicePixelRatio);
final ui.Rect paintBounds = ui.Offset.zero & (view.physicalSize / view.devicePixelRatio);
final ui.Picture picture = paint(paintBounds);
final ui.Scene scene = composite(picture, paintBounds);
ui.window.render(scene);
view.render(scene);
}
void main() {
// TODO(goderbauer): Create a window if embedder doesn't provide an implicit view to draw into.
assert(ui.PlatformDispatcher.instance.implicitView != null);
view = ui.PlatformDispatcher.instance.implicitView!;
// To create a paragraph of text, we use ParagraphBuilder.
final ui.ParagraphBuilder builder = ui.ParagraphBuilder(
// The text below has a primary direction of left-to-right.

View File

@@ -8,6 +8,9 @@
import 'dart:typed_data';
import 'dart:ui' as ui;
// The FlutterView into which this example will draw; set in the main method.
late final ui.FlutterView view;
late ui.Color color;
ui.Picture paint(ui.Rect paintBounds) {
@@ -43,7 +46,7 @@ ui.Scene composite(ui.Picture picture, ui.Rect paintBounds) {
// the device's screen to "normal" sized pixels. We commonly work in logical
// pixels, which are then scaled by the device pixel ratio before being drawn
// on the screen.
final double devicePixelRatio = ui.window.devicePixelRatio;
final double devicePixelRatio = view.devicePixelRatio;
// This transform scales the x and y coordinates by the devicePixelRatio.
final Float64List deviceTransform = Float64List(16)
@@ -67,13 +70,13 @@ ui.Scene composite(ui.Picture picture, ui.Rect paintBounds) {
}
void beginFrame(Duration timeStamp) {
final ui.Rect paintBounds = ui.Offset.zero & (ui.window.physicalSize / ui.window.devicePixelRatio);
final ui.Rect paintBounds = ui.Offset.zero & (view.physicalSize / view.devicePixelRatio);
// First, record a picture with our painting commands.
final ui.Picture picture = paint(paintBounds);
// Second, include that picture in a scene graph.
final ui.Scene scene = composite(picture, paintBounds);
// Third, instruct the engine to render that scene graph.
ui.window.render(scene);
view.render(scene);
}
void handlePointerDataPacket(ui.PointerDataPacket packet) {
@@ -86,7 +89,7 @@ void handlePointerDataPacket(ui.PointerDataPacket packet) {
// Rather than calling paint() synchronously, we ask the engine to
// schedule a frame. The engine will call onBeginFrame when it is actually
// time to produce the frame.
ui.window.scheduleFrame();
ui.PlatformDispatcher.instance.scheduleFrame();
} else if (datum.change == ui.PointerChange.up) {
// Similarly, if the pointer went up, we change the color of the circle to
// green and schedule a frame. It's harmless to call scheduleFrame many
@@ -102,6 +105,10 @@ void handlePointerDataPacket(ui.PointerDataPacket packet) {
// This function is the primary entry point to your application. The engine
// calls main() as soon as it has loaded your code.
void main() {
// TODO(goderbauer): Create a window if embedder doesn't provide an implicit view to draw into.
assert(ui.PlatformDispatcher.instance.implicitView != null);
view = ui.PlatformDispatcher.instance.implicitView!;
color = const ui.Color(0xFF00FF00);
// The engine calls onBeginFrame whenever it wants us to produce a frame.
ui.PlatformDispatcher.instance.onBeginFrame = beginFrame;