Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | List of all members
flutter::DlStopwatchVisualizer Class Reference

#include <stopwatch_dl.h>

Inheritance diagram for flutter::DlStopwatchVisualizer:
flutter::StopwatchVisualizer

Public Member Functions

 DlStopwatchVisualizer (const Stopwatch &stopwatch)
 
void Visualize (DlCanvas *canvas, const SkRect &rect) const override
 Renders the stopwatch as a graph.
 
- Public Member Functions inherited from flutter::StopwatchVisualizer
 StopwatchVisualizer (const Stopwatch &stopwatch)
 
virtual ~StopwatchVisualizer ()=default
 
 FML_DISALLOW_COPY_AND_ASSIGN (StopwatchVisualizer)
 

Additional Inherited Members

- Protected Member Functions inherited from flutter::StopwatchVisualizer
double UnitFrameInterval (double time_ms) const
 Converts a raster time to a unit interval.
 
double UnitHeight (double time_ms, double max_height) const
 Converts a raster time to a unit height.
 
fml::Milliseconds GetFrameBudget () const
 
- Protected Attributes inherited from flutter::StopwatchVisualizer
const Stopwatchstopwatch_
 
fml::Milliseconds frame_budget_
 

Detailed Description

A stopwatch visualizer that uses DisplayList (|DlCanvas|) to draw.

Note
This is the newer non-backend specific version, that works in both Skia and Impeller. The older Skia-specific version is |SkStopwatchVisualizer|, which still should be used for Skia-specific optimizations.

Definition at line 19 of file stopwatch_dl.h.

Constructor & Destructor Documentation

◆ DlStopwatchVisualizer()

flutter::DlStopwatchVisualizer::DlStopwatchVisualizer ( const Stopwatch stopwatch)
inlineexplicit

Definition at line 21 of file stopwatch_dl.h.

22 : StopwatchVisualizer(stopwatch) {}
StopwatchVisualizer(const Stopwatch &stopwatch)
Definition stopwatch.h:95

Member Function Documentation

◆ Visualize()

void flutter::DlStopwatchVisualizer::Visualize ( DlCanvas canvas,
const SkRect rect 
) const
overridevirtual

Renders the stopwatch as a graph.

Parameters
canvasThe canvas to draw on.
[in]rectThe rectangle to draw in.

Implements flutter::StopwatchVisualizer.

Definition at line 20 of file stopwatch_dl.cc.

21 {
22 auto painter = DlVertexPainter();
23 DlPaint paint;
24
25 // Establish the graph position.
26 auto const x = rect.x();
27 auto const y = rect.y();
28 auto const width = rect.width();
29 auto const height = rect.height();
30 auto const bottom = rect.bottom();
31
32 // Scale the graph to show time frames up to those that are 3x the frame time.
33 auto const one_frame_ms = GetFrameBudget().count();
34 auto const max_interval = one_frame_ms * 3.0;
35 auto const max_unit_interval = UnitFrameInterval(max_interval);
36 auto const sample_unit_width = (1.0 / kMaxSamples);
37
38 // Provide a semi-transparent background for the graph.
39 painter.DrawRect(rect, DlColor(0x99FFFFFF));
40
41 // Prepare a path for the data; we start at the height of the last point so
42 // it looks like we wrap around.
43 {
44 for (auto i = size_t(0); i < stopwatch_.GetLapsCount(); i++) {
45 auto const sample_unit_height =
47 max_unit_interval));
48
49 auto const bar_width = width * sample_unit_width;
50 auto const bar_height = height * sample_unit_height;
51 auto const bar_left = x + width * sample_unit_width * i;
52
53 painter.DrawRect(SkRect::MakeLTRB(/*l=*/bar_left,
54 /*t=*/y + bar_height,
55 /*r=*/bar_left + bar_width,
56 /*b=*/bottom),
57 DlColor(0xAA0000FF));
58 }
59 }
60
61 // Draw horizontal frame markers.
62 {
63 if (max_interval > one_frame_ms) {
64 // Paint the horizontal markers.
65 auto count = static_cast<size_t>(max_interval / one_frame_ms);
66
67 // Limit the number of markers to a reasonable amount.
68 if (count > kMaxFrameMarkers) {
69 count = 1;
70 }
71
72 for (auto i = size_t(0); i < count; i++) {
73 auto const frame_height =
74 height * (1.0 - (UnitFrameInterval(i + 1) * one_frame_ms) /
75 max_unit_interval);
76
77 // Draw a skinny rectangle (i.e. a line).
78 painter.DrawRect(SkRect::MakeLTRB(/*l=*/x,
79 /*t=*/y + frame_height,
80 /*r=*/width,
81 /*b=*/y + frame_height + 1),
82 DlColor(0xCC000000));
83 }
84 }
85 }
86
87 // Paint the vertical marker for the current frame.
88 {
89 DlColor color = DlColor::kGreen();
91 // budget exceeded.
93 }
94 auto const l =
95 x + width * (static_cast<double>(stopwatch_.GetCurrentSample()) /
97 auto const t = y;
98 auto const r = l + width * sample_unit_width;
99 auto const b = rect.bottom();
100 painter.DrawRect(SkRect::MakeLTRB(l, t, r, b), color);
101 }
102
103 // Actually draw.
104 // Use kSrcOver blend mode so that elements under the performance overlay are
105 // partially visible.
106 paint.setBlendMode(DlBlendMode::kSrcOver);
107 // The second blend mode does nothing since the paint has no additional color
108 // sources like a tiled image or gradient.
109 canvas->DrawVertices(painter.IntoVertices(), DlBlendMode::kSrcOver, paint);
110}
int count
SkColor4f color
double UnitHeight(double time_ms, double max_height) const
Converts a raster time to a unit height.
Definition stopwatch.cc:61
const Stopwatch & stopwatch_
Definition stopwatch.h:122
fml::Milliseconds GetFrameBudget() const
Definition stopwatch.h:120
double UnitFrameInterval(double time_ms) const
Converts a raster time to a unit interval.
Definition stopwatch.cc:57
const fml::TimeDelta & GetLap(size_t index) const
Definition stopwatch.cc:45
const fml::TimeDelta & LastLap() const
Definition stopwatch.cc:41
size_t GetLapsCount() const
Return a reference to all the laps.
Definition stopwatch.cc:49
size_t GetCurrentSample() const
Definition stopwatch.cc:53
constexpr double ToMillisecondsF() const
Definition time_delta.h:68
const Paint & paint
static bool b
double y
double x
sk_sp< SkBlender > blender SkRect rect
Definition SkRecords.h:350
static const size_t kMaxSamples
Definition stopwatch.cc:9
static const size_t kMaxFrameMarkers
@ kSrcOver
r = s + (1-sa)*d
int32_t height
int32_t width
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition SkRect.h:646
static constexpr DlColor kRed()
Definition dl_color.h:24
static constexpr DlColor kGreen()
Definition dl_color.h:25

The documentation for this class was generated from the following files: