Commit cde14ab6 authored by Devon Carew's avatar Devon Carew

more checked mode guards; more types; fewer todos

parent 211aeabb
...@@ -24,8 +24,11 @@ abstract class Renderer extends Scheduler ...@@ -24,8 +24,11 @@ abstract class Renderer extends Scheduler
_instance = this; _instance = this;
ui.window.onMetricsChanged = handleMetricsChanged; ui.window.onMetricsChanged = handleMetricsChanged;
initRenderView(); initRenderView();
assert(() {
initServiceExtensions();
return true;
});
addPersistentFrameCallback(_handlePersistentFrameCallback); addPersistentFrameCallback(_handlePersistentFrameCallback);
initServiceExtensions();
} }
static Renderer _instance; static Renderer _instance;
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
import 'dart:async'; import 'dart:async';
import 'dart:collection'; import 'dart:collection';
import 'dart:convert' show JSON; import 'dart:convert' show JSON;
import 'dart:developer'; import 'dart:developer' as developer;
import 'dart:ui' as ui; import 'dart:ui' as ui;
import 'package:flutter/painting.dart'; import 'package:flutter/painting.dart';
...@@ -67,15 +67,13 @@ void initServiceExtensions() { ...@@ -67,15 +67,13 @@ void initServiceExtensions() {
_extensionsInitialized = true; _extensionsInitialized = true;
assert(() { assert(() {
registerExtension('flutter', _flutter); developer.registerExtension('flutter', _flutter);
// TODO: Expose debugDumpApp(). developer.registerExtension('flutter.debugPaint', _debugPaint);
// TODO: Expose StatisticsOverlay. developer.registerExtension('flutter.timeDilation', _timeDilation);
registerExtension('flutter.debugPaint', _debugPaint);
registerExtension('flutter.timeDilation', _timeDilation);
// Emit an info level log message; this tells the debugger that the Flutter // Emit an info level log message; this tells the debugger that the Flutter
// service extensions are registered. // service extensions are registered.
log('Flutter initialized', name: 'flutter', level: 800); developer.log('Flutter initialized', name: 'flutter', level: 800);
return true; return true;
}); });
...@@ -83,15 +81,20 @@ void initServiceExtensions() { ...@@ -83,15 +81,20 @@ void initServiceExtensions() {
/// Just respond to the request. Clients can use the existence of this call to /// Just respond to the request. Clients can use the existence of this call to
/// know that the debug client is a Flutter app. /// know that the debug client is a Flutter app.
Future<ServiceExtensionResponse> _flutter(String method, Map<String, dynamic> parameters) { Future<developer.ServiceExtensionResponse> _flutter(String method, Map<String, dynamic> parameters) {
String result = JSON.encode({ 'type': '_extensionType', 'method': method }); return new Future<developer.ServiceExtensionResponse>.value(
return new Future<ServiceExtensionResponse>.value(new ServiceExtensionResponse.result(result)); new developer.ServiceExtensionResponse.result(JSON.encode({
'type': '_extensionType',
'method': method
}))
);
} }
/// Toggle the [debugPaintSizeEnabled] setting. /// Toggle the [debugPaintSizeEnabled] setting.
Future<ServiceExtensionResponse> _debugPaint(String method, Map<String, dynamic> parameters) { Future<developer.ServiceExtensionResponse> _debugPaint(String method, Map<String, dynamic> parameters) {
if (parameters.containsKey('enabled')) { if (parameters.containsKey('enabled')) {
// TODO: This is a work around for a VM bug: sdk/25208 - all params are coerced to strings. // TODO(devoncarew): This is a work around for a VM bug: sdk/25208 - all
// params are coerced to strings.
debugPaintSizeEnabled = parameters['enabled'].toString() == 'true'; debugPaintSizeEnabled = parameters['enabled'].toString() == 'true';
// Redraw everything - mark the world as dirty. // Redraw everything - mark the world as dirty.
...@@ -100,21 +103,22 @@ Future<ServiceExtensionResponse> _debugPaint(String method, Map<String, dynamic> ...@@ -100,21 +103,22 @@ Future<ServiceExtensionResponse> _debugPaint(String method, Map<String, dynamic>
child.markNeedsPaint(); child.markNeedsPaint();
child.visitChildren(visitor); child.visitChildren(visitor);
}; };
Renderer.instance.renderView.visitChildren(visitor); Renderer.instance?.renderView?.visitChildren(visitor);
} }
String result = JSON.encode({ return new Future<developer.ServiceExtensionResponse>.value(
'type': '_extensionType', new developer.ServiceExtensionResponse.result(JSON.encode({
'method': method, 'type': '_extensionType',
'enabled': debugPaintSizeEnabled 'method': method,
}); 'enabled': debugPaintSizeEnabled
return new Future<ServiceExtensionResponse>.value(new ServiceExtensionResponse.result(result)); }))
);
} }
/// Manipulate the scheduler's [timeDilation] field. /// Manipulate the scheduler's [timeDilation] field.
Future<ServiceExtensionResponse> _timeDilation(String method, Map<String, dynamic> parameters) { Future<developer.ServiceExtensionResponse> _timeDilation(String method, Map<String, dynamic> parameters) {
if (parameters.containsKey('timeDilation')) { if (parameters.containsKey('timeDilation')) {
// TODO: Workaround for https://github.com/dart-lang/sdk/issues/25208. // TODO(devoncarew): Workaround for https://github.com/dart-lang/sdk/issues/25208.
dynamic param = parameters['timeDilation']; dynamic param = parameters['timeDilation'];
if (param is String) { if (param is String) {
param = double.parse(param); param = double.parse(param);
...@@ -126,12 +130,13 @@ Future<ServiceExtensionResponse> _timeDilation(String method, Map<String, dynami ...@@ -126,12 +130,13 @@ Future<ServiceExtensionResponse> _timeDilation(String method, Map<String, dynami
timeDilation = 1.0; timeDilation = 1.0;
} }
String result = JSON.encode({ return new Future<developer.ServiceExtensionResponse>.value(
'type': '_extensionType', new developer.ServiceExtensionResponse.result(JSON.encode({
'method': method, 'type': '_extensionType',
'timeDilation': '$timeDilation' 'method': method,
}); 'timeDilation': '$timeDilation'
return new Future<ServiceExtensionResponse>.value(new ServiceExtensionResponse.result(result)); }))
);
} }
/// Prints a message to the console, which you can access using the "flutter" /// Prints a message to the console, which you can access using the "flutter"
......
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