• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// TODO(dnfield): remove unused_element ignores when https://github.com/dart-lang/sdk/issues/35164 is resolved.
6
7part of dart.ui;
8
9// Corelib 'print' implementation.
10void _print(dynamic arg) {
11  _Logger._printString(arg.toString());
12}
13
14class _Logger {
15  static void _printString(String s) native 'Logger_PrintString';
16}
17
18// If we actually run on big endian machines, we'll need to do something smarter
19// here. We don't use [Endian.Host] because it's not a compile-time
20// constant and can't propagate into the set/get calls.
21const Endian _kFakeHostEndian = Endian.little;
22
23// A service protocol extension to schedule a frame to be rendered into the
24// window.
25Future<developer.ServiceExtensionResponse> _scheduleFrame(
26    String method,
27    Map<String, String> parameters
28    ) async {
29  // Schedule the frame.
30  window.scheduleFrame();
31  // Always succeed.
32  return developer.ServiceExtensionResponse.result(json.encode(<String, String>{
33    'type': 'Success',
34  }));
35}
36
37@pragma('vm:entry-point')
38void _setupHooks() {  // ignore: unused_element
39  assert(() {
40    // In debug mode, register the schedule frame extension.
41    developer.registerExtension('ext.ui.window.scheduleFrame', _scheduleFrame);
42    return true;
43  }());
44}
45
46/// Returns runtime Dart compilation trace as a UTF-8 encoded memory buffer.
47///
48/// The buffer contains a list of symbols compiled by the Dart JIT at runtime up
49/// to the point when this function was called. This list can be saved to a text
50/// file and passed to tools such as `flutter build` or Dart `gen_snapshot` in
51/// order to pre-compile this code offline.
52///
53/// The list has one symbol per line of the following format:
54/// `<namespace>,<class>,<symbol>\n`.
55///
56/// Here are some examples:
57///
58/// ```
59/// dart:core,Duration,get:inMilliseconds
60/// package:flutter/src/widgets/binding.dart,::,runApp
61/// file:///.../my_app.dart,::,main
62/// ```
63///
64/// This function is only effective in debug and dynamic modes, and will throw in AOT mode.
65List<int> saveCompilationTrace() {
66  final dynamic result = _saveCompilationTrace();
67  if (result is Error)
68    throw result;
69  return result;
70}
71
72dynamic _saveCompilationTrace() native 'SaveCompilationTrace';
73
74void _scheduleMicrotask(void callback()) native 'ScheduleMicrotask';
75
76int _getCallbackHandle(Function closure) native 'GetCallbackHandle';
77Function _getCallbackFromHandle(int handle) native 'GetCallbackFromHandle';
78
79// Required for gen_snapshot to work correctly.
80int _isolateId; // ignore: unused_element
81
82@pragma('vm:entry-point')
83Function _getPrintClosure() => _print;  // ignore: unused_element
84@pragma('vm:entry-point')
85Function _getScheduleMicrotaskClosure() => _scheduleMicrotask; // ignore: unused_element
86