Commit 3373d0ba authored by Adam Barth's avatar Adam Barth

Switch clients from ui.view to ui.window

parent 02a1ebab
......@@ -21,8 +21,8 @@ ui.Picture paint(ui.Rect paintBounds) {
}
ui.Scene composite(ui.Picture picture, ui.Rect paintBounds) {
final double devicePixelRatio = ui.view.devicePixelRatio;
ui.Rect sceneBounds = new ui.Rect.fromLTWH(0.0, 0.0, ui.view.width * devicePixelRatio, ui.view.height * devicePixelRatio);
final double devicePixelRatio = ui.window.devicePixelRatio;
ui.Rect sceneBounds = new ui.Rect.fromLTWH(0.0, 0.0, ui.window.size.width * devicePixelRatio, ui.window.size.height * devicePixelRatio);
Float64List deviceTransform = new Float64List(16)
..[0] = devicePixelRatio
..[5] = devicePixelRatio
......@@ -35,23 +35,23 @@ ui.Scene composite(ui.Picture picture, ui.Rect paintBounds) {
return sceneBuilder.build();
}
void beginFrame(double timeStamp) {
ui.Rect paintBounds = new ui.Rect.fromLTWH(0.0, 0.0, ui.view.width, ui.view.height);
void beginFrame(Duration timeStamp) {
ui.Rect paintBounds = ui.Point.origin & ui.window.size;
ui.Picture picture = paint(paintBounds);
ui.Scene scene = composite(picture, paintBounds);
ui.view.scene = scene;
ui.window.render(scene);
}
bool handleEvent(ui.Event event) {
if (event.type == 'pointerdown') {
color = new ui.Color.fromARGB(255, 0, 0, 255);
ui.view.scheduleFrame();
ui.window.scheduleFrame();
return true;
}
if (event.type == 'pointerup') {
color = new ui.Color.fromARGB(255, 0, 255, 0);
ui.view.scheduleFrame();
ui.window.scheduleFrame();
return true;
}
......@@ -66,7 +66,7 @@ bool handleEvent(ui.Event event) {
void main() {
print('Hello, world');
color = new ui.Color.fromARGB(255, 0, 255, 0);
ui.view.setFrameCallback(beginFrame);
ui.view.setEventCallback(handleEvent);
ui.view.scheduleFrame();
ui.window.onBeginFrame = beginFrame;
ui.window.onEvent = handleEvent;
ui.window.scheduleFrame();
}
......@@ -17,9 +17,9 @@ ui.Picture paint(ui.Rect paintBounds) {
canvas.drawPaint(new ui.Paint()..color = const ui.Color(0xFFFFFFFF));
canvas.save();
canvas.translate(-mid.x/2.0, ui.view.height*2.0);
canvas.translate(-mid.x/2.0, ui.window.size.height*2.0);
canvas.clipRect(
new ui.Rect.fromLTRB(0.0, -ui.view.height, ui.view.width, radius));
new ui.Rect.fromLTRB(0.0, -ui.window.size.height, ui.window.size.width, radius));
canvas.translate(mid.x, mid.y);
paint.color = const ui.Color.fromARGB(128, 255, 0, 255);
......@@ -94,8 +94,8 @@ ui.Picture paint(ui.Rect paintBounds) {
}
ui.Scene composite(ui.Picture picture, ui.Rect paintBounds) {
final double devicePixelRatio = ui.view.devicePixelRatio;
ui.Rect sceneBounds = new ui.Rect.fromLTWH(0.0, 0.0, ui.view.width * devicePixelRatio, ui.view.height * devicePixelRatio);
final double devicePixelRatio = ui.window.devicePixelRatio;
ui.Rect sceneBounds = new ui.Rect.fromLTWH(0.0, 0.0, ui.window.size.width * devicePixelRatio, ui.window.size.height * devicePixelRatio);
Float64List deviceTransform = new Float64List(16)
..[0] = devicePixelRatio
..[5] = devicePixelRatio
......@@ -108,14 +108,14 @@ ui.Scene composite(ui.Picture picture, ui.Rect paintBounds) {
return sceneBuilder.build();
}
void beginFrame(double timeStamp) {
ui.Rect paintBounds = new ui.Rect.fromLTWH(0.0, 0.0, ui.view.width, ui.view.height);
void beginFrame(Duration timeStamp) {
ui.Rect paintBounds = ui.Point.origin & ui.window.size;
ui.Picture picture = paint(paintBounds);
ui.Scene scene = composite(picture, paintBounds);
ui.view.scene = scene;
ui.window.render(scene);
}
void main() {
ui.view.setFrameCallback(beginFrame);
ui.view.scheduleFrame();
ui.window.onBeginFrame = beginFrame;
ui.window.scheduleFrame();
}
......@@ -37,8 +37,8 @@ ui.Picture paint(ui.Rect paintBounds) {
}
ui.Scene composite(ui.Picture picture, ui.Rect paintBounds) {
final double devicePixelRatio = ui.view.devicePixelRatio;
ui.Rect sceneBounds = new ui.Rect.fromLTWH(0.0, 0.0, ui.view.width * devicePixelRatio, ui.view.height * devicePixelRatio);
final double devicePixelRatio = ui.window.devicePixelRatio;
ui.Rect sceneBounds = new ui.Rect.fromLTWH(0.0, 0.0, ui.window.size.width * devicePixelRatio, ui.window.size.height * devicePixelRatio);
Float64List deviceTransform = new Float64List(16)
..[0] = devicePixelRatio
..[5] = devicePixelRatio
......@@ -51,14 +51,14 @@ ui.Scene composite(ui.Picture picture, ui.Rect paintBounds) {
return sceneBuilder.build();
}
void beginFrame(double timeStamp) {
ui.Rect paintBounds = new ui.Rect.fromLTWH(0.0, 0.0, ui.view.width, ui.view.height);
void beginFrame(Duration timeStamp) {
ui.Rect paintBounds = ui.Point.origin & ui.window.size;
ui.Picture picture = paint(paintBounds);
ui.Scene scene = composite(picture, paintBounds);
ui.view.scene = scene;
ui.window.render(scene);
}
void main() {
ui.view.setFrameCallback(beginFrame);
ui.view.scheduleFrame();
ui.window.onBeginFrame = beginFrame;
ui.window.scheduleFrame();
}
......@@ -6,14 +6,14 @@ import 'dart:math' as math;
import 'dart:ui' as ui;
import 'dart:typed_data';
double timeBase = null;
Duration timeBase = null;
ui.Paragraph paragraph;
ui.Picture paint(ui.Rect paintBounds, double delta) {
ui.PictureRecorder recorder = new ui.PictureRecorder();
ui.Canvas canvas = new ui.Canvas(recorder, paintBounds);
canvas.translate(ui.view.width / 2.0, ui.view.height / 2.0);
canvas.translate(ui.window.size.width / 2.0, ui.window.size.height / 2.0);
canvas.rotate(math.PI * delta / 1800);
canvas.drawRect(new ui.Rect.fromLTRB(-100.0, -100.0, 100.0, 100.0),
new ui.Paint()..color = const ui.Color.fromARGB(255, 0, 255, 0));
......@@ -29,8 +29,8 @@ ui.Picture paint(ui.Rect paintBounds, double delta) {
}
ui.Scene composite(ui.Picture picture, ui.Rect paintBounds) {
final double devicePixelRatio = ui.view.devicePixelRatio;
ui.Rect sceneBounds = new ui.Rect.fromLTWH(0.0, 0.0, ui.view.width * devicePixelRatio, ui.view.height * devicePixelRatio);
final double devicePixelRatio = ui.window.devicePixelRatio;
ui.Rect sceneBounds = new ui.Rect.fromLTWH(0.0, 0.0, ui.window.size.width * devicePixelRatio, ui.window.size.height * devicePixelRatio);
Float64List deviceTransform = new Float64List(16)
..[0] = devicePixelRatio
..[5] = devicePixelRatio
......@@ -43,15 +43,15 @@ ui.Scene composite(ui.Picture picture, ui.Rect paintBounds) {
return sceneBuilder.build();
}
void beginFrame(double timeStamp) {
void beginFrame(Duration timeStamp) {
if (timeBase == null)
timeBase = timeStamp;
double delta = timeStamp - timeBase;
ui.Rect paintBounds = new ui.Rect.fromLTWH(0.0, 0.0, ui.view.width, ui.view.height);
double delta = (timeStamp - timeBase).inMicroseconds / Duration.MICROSECONDS_PER_MILLISECOND;
ui.Rect paintBounds = ui.Point.origin & ui.window.size;
ui.Picture picture = paint(paintBounds, delta);
ui.Scene scene = composite(picture, paintBounds);
ui.view.scene = scene;
ui.view.scheduleFrame();
ui.window.render(scene);
ui.window.scheduleFrame();
}
void main() {
......@@ -63,6 +63,6 @@ void main() {
builder.addText(" و أكثر قليلا لجعله أطول. ");
paragraph = builder.build(new ui.ParagraphStyle());
ui.view.setFrameCallback(beginFrame);
ui.view.scheduleFrame();
ui.window.onBeginFrame = beginFrame;
ui.window.scheduleFrame();
}
......@@ -8,7 +8,7 @@ import 'dart:typed_data';
import 'package:flutter/services.dart';
double timeBase = null;
Duration timeBase = null;
ui.Image image = null;
String url1 = "https://raw.githubusercontent.com/dart-lang/logos/master/logos_and_wordmarks/dart-logo.png";
......@@ -42,8 +42,8 @@ ui.Picture paint(ui.Rect paintBounds, double delta) {
}
ui.Scene composite(ui.Picture picture, ui.Rect paintBounds) {
final double devicePixelRatio = ui.view.devicePixelRatio;
ui.Rect sceneBounds = new ui.Rect.fromLTWH(0.0, 0.0, ui.view.width * devicePixelRatio, ui.view.height * devicePixelRatio);
final double devicePixelRatio = ui.window.devicePixelRatio;
ui.Rect sceneBounds = new ui.Rect.fromLTWH(0.0, 0.0, ui.window.size.width * devicePixelRatio, ui.window.size.height * devicePixelRatio);
Float64List deviceTransform = new Float64List(16)
..[0] = devicePixelRatio
..[5] = devicePixelRatio
......@@ -56,15 +56,15 @@ ui.Scene composite(ui.Picture picture, ui.Rect paintBounds) {
return sceneBuilder.build();
}
void beginFrame(double timeStamp) {
void beginFrame(Duration timeStamp) {
if (timeBase == null)
timeBase = timeStamp;
double delta = timeStamp - timeBase;
ui.Rect paintBounds = new ui.Rect.fromLTWH(0.0, 0.0, ui.view.width, ui.view.height);
double delta = (timeStamp - timeBase).inMicroseconds / Duration.MICROSECONDS_PER_MILLISECOND;
ui.Rect paintBounds = ui.Point.origin & ui.window.size;
ui.Picture picture = paint(paintBounds, delta);
ui.Scene scene = composite(picture, paintBounds);
ui.view.scene = scene;
ui.view.scheduleFrame();
ui.window.render(scene);
ui.window.scheduleFrame();
}
......@@ -72,7 +72,7 @@ void handleImageLoad(result) {
if (result != image) {
print("${result.width}x${result.width} image loaded!");
image = result;
ui.view.scheduleFrame();
ui.window.scheduleFrame();
} else {
print("Existing image was loaded again");
}
......@@ -93,6 +93,6 @@ bool handleEvent(ui.Event event) {
void main() {
imageCache.load(url1).first.then(handleImageLoad);
ui.view.setEventCallback(handleEvent);
ui.view.setFrameCallback(beginFrame);
ui.window.onEvent = handleEvent;
ui.window.onBeginFrame = beginFrame;
}
......@@ -6,16 +6,16 @@ import 'dart:math' as math;
import 'dart:ui' as ui;
import 'dart:typed_data';
double timeBase = null;
Duration timeBase = null;
void beginFrame(double timeStamp) {
void beginFrame(Duration timeStamp) {
ui.tracing.begin('beginFrame');
if (timeBase == null)
timeBase = timeStamp;
double delta = timeStamp - timeBase;
double delta = (timeStamp - timeBase).inMicroseconds / Duration.MICROSECONDS_PER_MILLISECOND;
// paint
ui.Rect paintBounds = new ui.Rect.fromLTWH(0.0, 0.0, ui.view.width, ui.view.height);
ui.Rect paintBounds = ui.Point.origin & ui.window.size;
ui.PictureRecorder recorder = new ui.PictureRecorder();
ui.Canvas canvas = new ui.Canvas(recorder, paintBounds);
canvas.translate(paintBounds.width / 2.0, paintBounds.height / 2.0);
......@@ -25,8 +25,8 @@ void beginFrame(double timeStamp) {
ui.Picture picture = recorder.endRecording();
// composite
final double devicePixelRatio = ui.view.devicePixelRatio;
ui.Rect sceneBounds = new ui.Rect.fromLTWH(0.0, 0.0, ui.view.width * devicePixelRatio, ui.view.height * devicePixelRatio);
final double devicePixelRatio = ui.window.devicePixelRatio;
ui.Rect sceneBounds = new ui.Rect.fromLTWH(0.0, 0.0, ui.window.size.width * devicePixelRatio, ui.window.size.height * devicePixelRatio);
Float64List deviceTransform = new Float64List(16)
..[0] = devicePixelRatio
..[5] = devicePixelRatio
......@@ -36,13 +36,13 @@ void beginFrame(double timeStamp) {
..pushTransform(deviceTransform)
..addPicture(ui.Offset.zero, picture, paintBounds)
..pop();
ui.view.scene = sceneBuilder.build();
ui.window.render(sceneBuilder.build());
ui.tracing.end('beginFrame');
ui.view.scheduleFrame();
ui.window.scheduleFrame();
}
void main() {
ui.view.setFrameCallback(beginFrame);
ui.view.scheduleFrame();
ui.window.onBeginFrame = beginFrame;
ui.window.scheduleFrame();
}
......@@ -101,5 +101,5 @@ Pancetta meatball tongue tenderloin rump tail jowl boudin.""";
updateTaskDescription('Interactive Flex', topColor);
new FlutterBinding(root: root);
ui.view.setEventCallback(handleEvent);
ui.window.onEvent = handleEvent;
}
......@@ -12,8 +12,8 @@ Future showStockMenu({BuildContext context, bool autorefresh, ValueChanged<bool>
switch (await showMenu(
context: context,
position: new MenuPosition(
right: ui.view.paddingRight + _kMenuMargin,
top: ui.view.paddingTop + _kMenuMargin
right: ui.window.padding.right + _kMenuMargin,
top: ui.window.padding.top + _kMenuMargin
),
items: <PopupMenuItem>[
new PopupMenuItem(
......
......@@ -27,7 +27,7 @@ SchedulerExceptionHandler debugSchedulerExceptionHandler;
class Scheduler {
/// Requires clients to use the [scheduler] singleton
Scheduler._() {
ui.view.setFrameCallback(beginFrame);
ui.window.onBeginFrame = beginFrame;
}
bool _haveScheduledVisualUpdate = false;
......@@ -49,13 +49,11 @@ class Scheduler {
/// [requestAnimationFrame], then calls all the callbacks registered by
/// [addPersistentFrameCallback], which typically drive the rendering pipeline,
/// and finally calls the callbacks registered by [requestPostFrameCallback].
void beginFrame(double rawTimeStamp) {
void beginFrame(Duration rawTimeStamp) {
assert(!_inFrame);
_inFrame = true;
rawTimeStamp /= timeDilation;
final Duration timeStamp = new Duration(
microseconds: (rawTimeStamp * Duration.MICROSECONDS_PER_MILLISECOND).round()
);
Duration timeStamp = new Duration(
microseconds: (rawTimeStamp.inMicroseconds / timeDilation).round());
_haveScheduledVisualUpdate = false;
assert(_postFrameCallbacks.length == 0);
......@@ -148,7 +146,7 @@ class Scheduler {
void ensureVisualUpdate() {
if (_haveScheduledVisualUpdate)
return;
ui.view.scheduleFrame();
ui.window.scheduleFrame();
_haveScheduledVisualUpdate = true;
}
}
......
......@@ -109,11 +109,11 @@ Simulation _createFlingScrollSimulation(double position, double velocity, double
// scrolling less than one logical pixel per frame. We're essentially
// normalizing by the devicePixelRatio so that the threshold has the
// same effect independent of the device's pixel density.
double endVelocity = 15.0 * ui.view.devicePixelRatio;
double endVelocity = 15.0 * ui.window.devicePixelRatio;
// Similar to endVelocity. Stop scrolling when we're this close to
// destiniation scroll offset.
double endDistance = 0.5 * ui.view.devicePixelRatio;
double endDistance = 0.5 * ui.window.devicePixelRatio;
SpringDescription spring = new SpringDescription.withDampingRatio(mass: 1.0, springConstant: 170.0, ratio: 1.1);
ScrollSimulation simulation =
......@@ -124,7 +124,7 @@ Simulation _createFlingScrollSimulation(double position, double velocity, double
Simulation _createSnapScrollSimulation(double startOffset, double endOffset, double velocity) {
double startVelocity = velocity * _kSecondsPerMillisecond;
double endVelocity = 15.0 * ui.view.devicePixelRatio * velocity.sign;
double endVelocity = 15.0 * ui.window.devicePixelRatio * velocity.sign;
return new FrictionSimulation.through(startOffset, endOffset, startVelocity, endVelocity);
}
......
......@@ -28,7 +28,7 @@ class Scaffold extends StatelessComponent {
Widget build(BuildContext context) {
double toolBarHeight = 0.0;
if (toolBar != null)
toolBarHeight = kToolBarHeight + ui.view.paddingTop;
toolBarHeight = kToolBarHeight + ui.window.padding.top;
double statusBarHeight = 0.0;
if (statusBar != null)
......
......@@ -132,9 +132,9 @@ class FlutterBinding extends HitTestTarget {
assert(_instance == null);
_instance = this;
ui.view.setEventCallback(_handleEvent);
ui.window.onEvent = _handleEvent;
ui.window.onMetricsChanged = _handleMetricsChanged;
ui.view.setMetricsChangedCallback(_handleMetricsChanged);
if (renderViewOverride == null) {
_renderView = new RenderView(child: root);
_renderView.attach();
......@@ -166,7 +166,7 @@ class FlutterBinding extends HitTestTarget {
bool removeMetricListener(MetricListener listener) => _metricListeners.remove(listener);
void _handleMetricsChanged() {
Size size = new Size(ui.view.width, ui.view.height);
Size size = ui.window.size;
_renderView.rootConstraints = new ViewConstraints(size: size);
for (MetricListener listener in _metricListeners)
listener(size);
......
......@@ -62,7 +62,7 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin<RenderBox>
}
Matrix4 get _logicalToDeviceTransform {
double devicePixelRatio = ui.view.devicePixelRatio;
double devicePixelRatio = ui.window.devicePixelRatio;
return new Matrix4.diagonal3Values(devicePixelRatio, devicePixelRatio, 1.0);
}
......@@ -119,10 +119,10 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin<RenderBox>
ui.tracing.begin('RenderView.compositeFrame');
try {
(layer as TransformLayer).transform = _logicalToDeviceTransform;
Rect bounds = Point.origin & (size * ui.view.devicePixelRatio);
Rect bounds = Point.origin & (size * ui.window.devicePixelRatio);
ui.SceneBuilder builder = new ui.SceneBuilder(bounds);
layer.addToScene(builder, Offset.zero);
ui.view.scene = builder.build();
ui.window.render(builder.build());
} finally {
ui.tracing.end('RenderView.compositeFrame');
}
......@@ -130,6 +130,6 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin<RenderBox>
Rect get paintBounds => Point.origin & size;
String debugDescribeSettings(String prefix) => '${prefix}view width: ${ui.view.width} (in device pixels)\n${prefix}view height: ${ui.view.height} (in device pixels)\n${prefix}device pixel ratio: ${ui.view.devicePixelRatio} (device pixels per logical pixel)\n${prefix}root constraints: $rootConstraints (in logical pixels)\n';
String debugDescribeSettings(String prefix) => '${prefix}window size: ${ui.window.size} (in device pixels)\n${prefix}device pixel ratio: ${ui.window.devicePixelRatio} (device pixels per logical pixel)\n${prefix}root constraints: $rootConstraints (in logical pixels)\n';
// call to ${super.debugDescribeSettings(prefix)} is omitted because the root superclasses don't include any interesting information for this class
}
......@@ -136,7 +136,7 @@ class RenderViewport extends RenderBox with RenderObjectWithChildMixin<RenderBox
}
Offset get _scrollOffsetRoundedToIntegerDevicePixels {
double devicePixelRatio = ui.view.devicePixelRatio;
double devicePixelRatio = ui.window.devicePixelRatio;
int dxInDevicePixels = (scrollOffset.dx * devicePixelRatio).round();
int dyInDevicePixels = (scrollOffset.dy * devicePixelRatio).round();
return new Offset(dxInDevicePixels / devicePixelRatio,
......
......@@ -26,7 +26,7 @@ void main() {
scheduler.requestAnimationFrame(firstCallback);
secondId = scheduler.requestAnimationFrame(secondCallback);
scheduler.beginFrame(16.0);
scheduler.beginFrame(const Duration(milliseconds: 16));
expect(firstCallbackRan, isTrue);
expect(secondCallbackRan, isFalse);
......@@ -34,7 +34,7 @@ void main() {
firstCallbackRan = false;
secondCallbackRan = false;
scheduler.beginFrame(32.0);
scheduler.beginFrame(const Duration(milliseconds: 32));
expect(firstCallbackRan, isFalse);
expect(secondCallbackRan, isFalse);
......
......@@ -42,7 +42,7 @@ class WidgetTester {
void pump([ Duration duration ]) {
if (duration != null)
async.elapse(duration);
scheduler.beginFrame(clock.now().millisecondsSinceEpoch.toDouble());
scheduler.beginFrame(new Duration(milliseconds: clock.now().millisecondsSinceEpoch));
async.flushMicrotasks();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment