mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
This re-lands #20496 and #21780 after fixing the semantics-enabling code that was causing the post-submit web_smoke_test to fail. Below is the description from the original PR: This is a PR for converting the dart:ui code in the engine to use a multi-window API. The goal here is to convert from the window singleton to an API that has the concept of multiple windows. Also, I'm matching up the new PlatformDispatcher class to talk directly to the PlatformConfiguration class in the engine. I'm not attempting to actually enable creating multiple windows here, just migrate to an API that has a concept of multiple windows. The multi-window API in this PR currently only ever creates one window. The design doc for this change is here. The major changes in this PR: Move the platfom-specific attributes out of Window, and into the new PlatformDispatcher class that holds all of the platform state, so that the platform code need only update the configuration on this class. Create FlutterView, FlutterWindow, and SingletonFlutterWindow classes to separate out the concepts of a view (of which there may be multiple in a window), a window (of which there may be multiple on a screen, and they host views), and a window where there is only ever expected to be one (this hosts the entire API of the former Window class, and will eventually be the type of the window singleton). Next step after this PR lands: Remove the Window class entirely (it is replaced by SingletonFlutterWindow). Some minor changes in the Framework are needed to switch to using SingletonFlutterWindow directly first. The Window class still exists in this PR, but will be removed as soon as the framework is converted to point to the SingletonFlutterWindow class instead. They share the same API, just have different names (Window is currently a subclass of SingletonFlutterWindow). The intention is that the Window name will be freed up to use as a widget class name in the framework for managing windows. The singleton called window will remain, and keep the same API it has now.
93 lines
3.0 KiB
Dart
93 lines
3.0 KiB
Dart
// Copyright 2013 The Flutter Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
// TODO(dnfield): remove unused_element ignores when https://github.com/dart-lang/sdk/issues/35164 is resolved.
|
|
|
|
// @dart = 2.10
|
|
|
|
part of dart.ui;
|
|
|
|
// Corelib 'print' implementation.
|
|
void _print(dynamic arg) {
|
|
_Logger._printString(arg.toString());
|
|
}
|
|
|
|
void _printDebug(dynamic arg) {
|
|
_Logger._printDebugString(arg.toString());
|
|
}
|
|
|
|
class _Logger {
|
|
static void _printString(String? s) native 'Logger_PrintString';
|
|
static void _printDebugString(String? s) native 'Logger_PrintDebugString';
|
|
}
|
|
|
|
// If we actually run on big endian machines, we'll need to do something smarter
|
|
// here. We don't use [Endian.Host] because it's not a compile-time
|
|
// constant and can't propagate into the set/get calls.
|
|
const Endian _kFakeHostEndian = Endian.little;
|
|
|
|
// A service protocol extension to schedule a frame to be rendered into the
|
|
// window.
|
|
Future<developer.ServiceExtensionResponse> _scheduleFrame(
|
|
String method,
|
|
Map<String, String> parameters
|
|
) async {
|
|
// Schedule the frame.
|
|
PlatformDispatcher.instance.scheduleFrame();
|
|
// Always succeed.
|
|
return developer.ServiceExtensionResponse.result(json.encode(<String, String>{
|
|
'type': 'Success',
|
|
}));
|
|
}
|
|
|
|
@pragma('vm:entry-point')
|
|
void _setupHooks() { // ignore: unused_element
|
|
assert(() {
|
|
// In debug mode, register the schedule frame extension.
|
|
developer.registerExtension('ext.ui.window.scheduleFrame', _scheduleFrame);
|
|
return true;
|
|
}());
|
|
}
|
|
|
|
/// Returns runtime Dart compilation trace as a UTF-8 encoded memory buffer.
|
|
///
|
|
/// The buffer contains a list of symbols compiled by the Dart JIT at runtime up
|
|
/// to the point when this function was called. This list can be saved to a text
|
|
/// file and passed to tools such as `flutter build` or Dart `gen_snapshot` in
|
|
/// order to pre-compile this code offline.
|
|
///
|
|
/// The list has one symbol per line of the following format:
|
|
/// `<namespace>,<class>,<symbol>\n`.
|
|
///
|
|
/// Here are some examples:
|
|
///
|
|
/// ```
|
|
/// dart:core,Duration,get:inMilliseconds
|
|
/// package:flutter/src/widgets/binding.dart,::,runApp
|
|
/// file:///.../my_app.dart,::,main
|
|
/// ```
|
|
///
|
|
/// This function is only effective in debug and dynamic modes, and will throw in AOT mode.
|
|
List<int> saveCompilationTrace() {
|
|
final dynamic result = _saveCompilationTrace();
|
|
if (result is Error)
|
|
throw result;
|
|
return result as List<int>;
|
|
}
|
|
|
|
dynamic _saveCompilationTrace() native 'SaveCompilationTrace';
|
|
|
|
void _scheduleMicrotask(void callback()) native 'ScheduleMicrotask';
|
|
|
|
int? _getCallbackHandle(Function closure) native 'GetCallbackHandle';
|
|
Function? _getCallbackFromHandle(int handle) native 'GetCallbackFromHandle';
|
|
|
|
// Required for gen_snapshot to work correctly.
|
|
int? _isolateId; // ignore: unused_element
|
|
|
|
@pragma('vm:entry-point')
|
|
Function _getPrintClosure() => _print; // ignore: unused_element
|
|
@pragma('vm:entry-point')
|
|
Function _getScheduleMicrotaskClosure() => _scheduleMicrotask; // ignore: unused_element
|