"Fossies" - the Fresh Open Source Software Archive

Member "flutter-1.22.4/packages/flutter/lib/src/rendering/performance_overlay.dart" (13 Nov 2020, 6819 Bytes) of package /linux/misc/flutter-1.22.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Dart source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 // Copyright 2014 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 import 'box.dart';
    6 import 'layer.dart';
    7 import 'object.dart';
    8 
    9 /// The options that control whether the performance overlay displays certain
   10 /// aspects of the compositor.
   11 enum PerformanceOverlayOption {
   12   // these must be in the order needed for their index values to match the
   13   // constants in //engine/src/sky/compositor/performance_overlay_layer.h
   14 
   15   /// Display the frame time and FPS of the last frame rendered. This field is
   16   /// updated every frame.
   17   ///
   18   /// This is the time spent by the rasterizer as it tries
   19   /// to convert the layer tree obtained from the widgets into OpenGL commands
   20   /// and tries to flush them onto the screen. When the total time taken by this
   21   /// step exceeds the frame slice, a frame is lost.
   22   displayRasterizerStatistics,
   23 
   24   /// Display the rasterizer frame times as they change over a set period of
   25   /// time in the form of a graph. The y axis of the graph denotes the total
   26   /// time spent by the rasterizer as a fraction of the total frame slice. When
   27   /// the bar turns red, a frame is lost.
   28   visualizeRasterizerStatistics,
   29 
   30   /// Display the frame time and FPS at which the interface can construct a
   31   /// layer tree for the rasterizer (whose behavior is described above) to
   32   /// consume.
   33   ///
   34   /// This involves all layout, animations, etc. When the total time taken by
   35   /// this step exceeds the frame slice, a frame is lost.
   36   displayEngineStatistics,
   37 
   38   /// Display the engine frame times as they change over a set period of time
   39   /// in the form of a graph. The y axis of the graph denotes the total time
   40   /// spent by the engine as a fraction of the total frame slice. When the bar
   41   /// turns red, a frame is lost.
   42   visualizeEngineStatistics,
   43 }
   44 
   45 /// Displays performance statistics.
   46 ///
   47 /// The overlay shows two time series. The first shows how much time was
   48 /// required on this thread to produce each frame. The second shows how much
   49 /// time was required on the raster thread (formerly known as the GPU thread)
   50 /// to produce each frame. Ideally, both these values would be less than
   51 /// the total frame budget for the hardware on which the app is running.
   52 /// For example, if the hardware has a screen that updates at 60 Hz, each
   53 /// thread should ideally spend less than 16ms producing each frame.
   54 /// This ideal condition is indicated by a green vertical line for each thread.
   55 /// Otherwise, the performance overlay shows a red vertical line.
   56 ///
   57 /// The simplest way to show the performance overlay is to set
   58 /// [MaterialApp.showPerformanceOverlay] or [WidgetsApp.showPerformanceOverlay]
   59 /// to true.
   60 class RenderPerformanceOverlay extends RenderBox {
   61   /// Creates a performance overlay render object.
   62   ///
   63   /// The [optionsMask], [rasterizerThreshold], [checkerboardRasterCacheImages],
   64   /// and [checkerboardOffscreenLayers] arguments must not be null.
   65   RenderPerformanceOverlay({
   66     int optionsMask = 0,
   67     int rasterizerThreshold = 0,
   68     bool checkerboardRasterCacheImages = false,
   69     bool checkerboardOffscreenLayers = false,
   70   }) : assert(optionsMask != null),
   71        assert(rasterizerThreshold != null),
   72        assert(checkerboardRasterCacheImages != null),
   73        assert(checkerboardOffscreenLayers != null),
   74        _optionsMask = optionsMask,
   75        _rasterizerThreshold = rasterizerThreshold,
   76        _checkerboardRasterCacheImages = checkerboardRasterCacheImages,
   77        _checkerboardOffscreenLayers = checkerboardOffscreenLayers;
   78 
   79   /// The mask is created by shifting 1 by the index of the specific
   80   /// [PerformanceOverlayOption] to enable.
   81   int get optionsMask => _optionsMask;
   82   int _optionsMask;
   83   set optionsMask(int value) {
   84     assert(value != null);
   85     if (value == _optionsMask)
   86       return;
   87     _optionsMask = value;
   88     markNeedsPaint();
   89   }
   90 
   91   /// The rasterizer threshold is an integer specifying the number of frame
   92   /// intervals that the rasterizer must miss before it decides that the frame
   93   /// is suitable for capturing an SkPicture trace for further analysis.
   94   int get rasterizerThreshold => _rasterizerThreshold;
   95   int _rasterizerThreshold;
   96   set rasterizerThreshold(int value) {
   97     assert(value != null);
   98     if (value == _rasterizerThreshold)
   99       return;
  100     _rasterizerThreshold = value;
  101     markNeedsPaint();
  102   }
  103 
  104   /// Whether the raster cache should checkerboard cached entries.
  105   bool get checkerboardRasterCacheImages => _checkerboardRasterCacheImages;
  106   bool _checkerboardRasterCacheImages;
  107   set checkerboardRasterCacheImages(bool value) {
  108     assert(value != null);
  109     if (value == _checkerboardRasterCacheImages)
  110       return;
  111     _checkerboardRasterCacheImages = value;
  112     markNeedsPaint();
  113   }
  114 
  115   /// Whether the compositor should checkerboard layers rendered to offscreen bitmaps.
  116   bool get checkerboardOffscreenLayers => _checkerboardOffscreenLayers;
  117   bool _checkerboardOffscreenLayers;
  118   set checkerboardOffscreenLayers(bool value) {
  119     assert(value != null);
  120     if (value == _checkerboardOffscreenLayers)
  121       return;
  122     _checkerboardOffscreenLayers = value;
  123     markNeedsPaint();
  124   }
  125 
  126   @override
  127   bool get sizedByParent => true;
  128 
  129   @override
  130   bool get alwaysNeedsCompositing => true;
  131 
  132   @override
  133   double computeMinIntrinsicWidth(double height) {
  134     return 0.0;
  135   }
  136 
  137   @override
  138   double computeMaxIntrinsicWidth(double height) {
  139     return 0.0;
  140   }
  141 
  142   double get _intrinsicHeight {
  143     const double kDefaultGraphHeight = 80.0;
  144     double result = 0.0;
  145     if ((optionsMask | (1 << PerformanceOverlayOption.displayRasterizerStatistics.index) > 0) ||
  146         (optionsMask | (1 << PerformanceOverlayOption.visualizeRasterizerStatistics.index) > 0))
  147       result += kDefaultGraphHeight;
  148     if ((optionsMask | (1 << PerformanceOverlayOption.displayEngineStatistics.index) > 0) ||
  149         (optionsMask | (1 << PerformanceOverlayOption.visualizeEngineStatistics.index) > 0))
  150       result += kDefaultGraphHeight;
  151     return result;
  152   }
  153 
  154   @override
  155   double computeMinIntrinsicHeight(double width) {
  156     return _intrinsicHeight;
  157   }
  158 
  159   @override
  160   double computeMaxIntrinsicHeight(double width) {
  161     return _intrinsicHeight;
  162   }
  163 
  164   @override
  165   void performResize() {
  166     size = constraints.constrain(Size(double.infinity, _intrinsicHeight));
  167   }
  168 
  169   @override
  170   void paint(PaintingContext context, Offset offset) {
  171     assert(needsCompositing);
  172     context.addLayer(PerformanceOverlayLayer(
  173       overlayRect: Rect.fromLTWH(offset.dx, offset.dy, size.width, size.height),
  174       optionsMask: optionsMask,
  175       rasterizerThreshold: rasterizerThreshold,
  176       checkerboardRasterCacheImages: checkerboardRasterCacheImages,
  177       checkerboardOffscreenLayers: checkerboardOffscreenLayers,
  178     ));
  179   }
  180 }