debug.dart 2.98 KB
Newer Older
1 2 3 4
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
import 'dart:ui' as ui;
6 7
import 'dart:async';
import 'dart:collection';
8

Adam Barth's avatar
Adam Barth committed
9
/// Causes each RenderBox to paint a box around its bounds.
10
bool debugPaintSizeEnabled = false;
Adam Barth's avatar
Adam Barth committed
11 12

/// The color to use when painting RenderObject bounds.
13
ui.Color debugPaintSizeColor = const ui.Color(0xFF00FFFF);
14

Adam Barth's avatar
Adam Barth committed
15
/// Causes each RenderBox to paint a line at each of its baselines.
16
bool debugPaintBaselinesEnabled = false;
Adam Barth's avatar
Adam Barth committed
17 18

/// The color to use when painting alphabetic baselines.
19
ui.Color debugPaintAlphabeticBaselineColor = const ui.Color(0xFF00FF00);
Adam Barth's avatar
Adam Barth committed
20 21

/// The color ot use when painting ideographic baselines.
22
ui.Color debugPaintIdeographicBaselineColor = const ui.Color(0xFFFFD000);
23

Adam Barth's avatar
Adam Barth committed
24
/// Causes each Layer to paint a box around its bounds.
25
bool debugPaintLayerBordersEnabled = false;
Adam Barth's avatar
Adam Barth committed
26 27

/// The color to use when painting Layer borders.
28
ui.Color debugPaintLayerBordersColor = const ui.Color(0xFFFF9800);
29

Adam Barth's avatar
Adam Barth committed
30
/// Causes RenderObjects to paint warnings when painting outside their bounds.
31
bool debugPaintBoundsEnabled = false;
32

33 34 35 36 37 38
/// Causes RenderBox objects to flash while they are being tapped
bool debugPaintPointersEnabled = false;

/// The color to use when reporting pointers.
int debugPaintPointersColorValue = 0x00BBBB;

39
/// The color to use when painting RenderError boxes in checked mode.
40
ui.Color debugErrorBoxColor = const ui.Color(0xFFFF0000);
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55

/// Prints a message to the console, which you can access using the "flutter"
/// tool's "logs" command ("flutter logs").
///
/// This function very crudely attempts to throttle the rate at which messages
/// are sent to avoid data loss on Android. This means that interleaving calls
/// to this function (directly or indirectly via [debugDumpRenderTree] or
/// [debugDumpApp]) and to the Dart [print] method can result in out-of-order
/// messages in the logs.
void debugPrint(String message) {
  _debugPrintBuffer.addAll(message.split('\n'));
  if (!_debugPrintScheduled)
    _debugPrintTask();
}
int _debugPrintedCharacters = 0;
56 57
int _kDebugPrintCapacity = 16 * 1024;
Duration _kDebugPrintPauseTime = const Duration(seconds: 1);
58
Queue<String> _debugPrintBuffer = new Queue<String>();
59
Stopwatch _debugPrintStopwatch = new Stopwatch();
60 61 62
bool _debugPrintScheduled = false;
void _debugPrintTask() {
  _debugPrintScheduled = false;
63 64 65 66 67
  if (_debugPrintStopwatch.elapsed > _kDebugPrintPauseTime) {
    _debugPrintStopwatch.stop();
    _debugPrintStopwatch.reset();
    _debugPrintedCharacters = 0;
  }
68 69 70 71 72 73 74 75
  while (_debugPrintedCharacters < _kDebugPrintCapacity && _debugPrintBuffer.length > 0) {
    String line = _debugPrintBuffer.removeFirst();
    _debugPrintedCharacters += line.length; // TODO(ianh): Use the UTF-8 byte length instead
    print(line);
  }
  if (_debugPrintBuffer.length > 0) {
    _debugPrintScheduled = true;
    _debugPrintedCharacters = 0;
76 77 78
    new Timer(_kDebugPrintPauseTime, _debugPrintTask);
  } else {
    _debugPrintStopwatch.start();
79 80
  }
}