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 | /// @docImport 'package:flutter/material.dart'; |
6 | /// |
7 | /// @docImport 'app.dart'; |
8 | library; |
9 | |
10 | import 'package:flutter/rendering.dart'; |
11 | |
12 | import 'framework.dart'; |
13 | |
14 | /// Displays performance statistics. |
15 | /// |
16 | /// The overlay shows two time series. The first shows how much time was |
17 | /// required on this thread to produce each frame. The second shows how much |
18 | /// time was required on the raster thread (formerly known as the GPU thread) |
19 | /// to produce each frame. Ideally, both these values would be less than |
20 | /// the total frame budget for the hardware on which the app is running. |
21 | /// For example, if the hardware has a screen that updates at 60 Hz, each |
22 | /// thread should ideally spend less than 16ms producing each frame. |
23 | /// This ideal condition is indicated by a green vertical line for each thread. |
24 | /// Otherwise, the performance overlay shows a red vertical line. |
25 | /// |
26 | /// The simplest way to show the performance overlay is to set |
27 | /// [MaterialApp.showPerformanceOverlay] or [WidgetsApp.showPerformanceOverlay] |
28 | /// to true. |
29 | class PerformanceOverlay extends LeafRenderObjectWidget { |
30 | /// Create a performance overlay that only displays specific statistics. The |
31 | /// mask is created by shifting 1 by the index of the specific |
32 | /// [PerformanceOverlayOption] to enable. |
33 | const PerformanceOverlay({super.key, this.optionsMask = 0}); |
34 | |
35 | /// Create a performance overlay that displays all available statistics. |
36 | PerformanceOverlay.allEnabled({super.key}) |
37 | : optionsMask = |
38 | 1 << PerformanceOverlayOption.displayRasterizerStatistics.index | |
39 | 1 << PerformanceOverlayOption.visualizeRasterizerStatistics.index | |
40 | 1 << PerformanceOverlayOption.displayEngineStatistics.index | |
41 | 1 << PerformanceOverlayOption.visualizeEngineStatistics.index; |
42 | |
43 | /// The mask is created by shifting 1 by the index of the specific |
44 | /// [PerformanceOverlayOption] to enable. |
45 | final int optionsMask; |
46 | |
47 | @override |
48 | RenderPerformanceOverlay createRenderObject(BuildContext context) => |
49 | RenderPerformanceOverlay(optionsMask: optionsMask); |
50 | |
51 | @override |
52 | void updateRenderObject(BuildContext context, RenderPerformanceOverlay renderObject) { |
53 | renderObject.optionsMask = optionsMask; |
54 | } |
55 | } |
56 | |