performance_overlay.dart 3.97 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 6
import 'box.dart';
import 'object.dart';
7

8 9 10 11 12 13
/// The options that control whether the performance overlay displays certain
/// aspects of the compositor.
enum PerformanceOverlayOption {
  // these must be in the order needed for their index values to match the
  // constants in //engine/src/sky/compositor/performance_overlay_layer.h

14 15 16 17 18 19 20 21
  /// Display the frame time and FPS of the last frame rendered. This field is
  /// updated every frame.
  ///
  /// This is the time spent by the rasterizer as it tries
  /// to convert the layer tree obtained from the widgets into OpenGL commands
  /// and tries to flush them onto the screen. When the total time taken by this
  /// step exceeds the frame slice, a frame is lost.
  displayRasterizerStatistics,
22

23 24 25 26 27
  /// Display the rasterizer frame times as they change over a set period of
  /// time in the form of a graph. The y axis of the graph denotes the total
  /// time spent by the rasterizer as a fraction of the total frame slice. When
  /// the bar turns red, a frame is lost.
  visualizeRasterizerStatistics,
28

29 30 31 32 33 34 35
  /// Display the frame time and FPS at which the interface can construct a
  /// layer tree for the rasterizer (whose behavior is described above) to
  /// consume.
  ///
  /// This involves all layout, animations, etc. When the total time taken by
  /// this step exceeds the frame slice, a frame is lost.
  displayEngineStatistics,
36

37 38 39 40 41 42
  /// Display the engine frame times as they change over a set period of time
  /// in the form of a graph. The y axis of the graph denotes the total time
  /// spent by the eninge as a fraction of the total frame slice. When the bar
  /// turns red, a frame is lost.
  visualizeEngineStatistics,
}
43

44 45
class RenderPerformanceOverlay extends RenderBox {
  RenderPerformanceOverlay({ int optionsMask: 0, int rasterizerThreshold: 0 })
46 47
    : _optionsMask = optionsMask,
      _rasterizerThreshold = rasterizerThreshold;
48

49
  /// The mask is created by shifting 1 by the index of the specific
50
  /// PerformanceOverlayOption to enable.
51
  int get optionsMask => _optionsMask;
52 53 54
  int _optionsMask;
  void set optionsMask(int mask) {
    if (mask == _optionsMask)
55 56 57 58 59
      return;
    _optionsMask = mask;
    markNeedsPaint();
  }

60
  int get rasterizerThreshold => _rasterizerThreshold;
61
  int _rasterizerThreshold;
62
  void set rasterizerThreshold (int threshold) {
63
    if (threshold == _rasterizerThreshold)
64 65 66 67 68
      return;
    _rasterizerThreshold = threshold;
    markNeedsPaint();
  }

69
  bool get sizedByParent => true;
70
  bool get alwaysNeedsCompositing => true;
71 72

  double getMinIntrinsicWidth(BoxConstraints constraints) {
73
    return constraints.constrainWidth(0.0);
74 75 76
  }

  double getMaxIntrinsicWidth(BoxConstraints constraints) {
77 78 79 80
    return constraints.constrainWidth(0.0);
  }

  double get intrinsicHeight {
81
    const double kGraphHeight = 80.0; // must match value in performance_overlay_layer.cc
82
    double result = 0.0;
83 84
    if ((optionsMask | (1 << PerformanceOverlayOption.displayRasterizerStatistics.index) > 0) ||
        (optionsMask | (1 << PerformanceOverlayOption.visualizeRasterizerStatistics.index) > 0))
85
      result += kGraphHeight;
86 87
    if ((optionsMask | (1 << PerformanceOverlayOption.displayEngineStatistics.index) > 0) ||
        (optionsMask | (1 << PerformanceOverlayOption.visualizeEngineStatistics.index) > 0))
88 89
      result += kGraphHeight;
    return result;
90 91 92
  }

  double getMinIntrinsicHeight(BoxConstraints constraints) {
93
    return constraints.constrainHeight(intrinsicHeight);
94 95 96
  }

  double getMaxIntrinsicHeight(BoxConstraints constraints) {
97
    return constraints.constrainHeight(intrinsicHeight);
98 99 100
  }

  void performResize() {
101
    size = constraints.constrain(new Size(double.INFINITY, intrinsicHeight));
102 103 104
  }

  void paint(PaintingContext context, Offset offset) {
105
    assert(needsCompositing);
106
    context.pushPerformanceOverlay(offset, optionsMask, rasterizerThreshold, size);
107 108
  }
}