Flutter Engine
 
Loading...
Searching...
No Matches
flutter::DlStopwatchVisualizer Class Reference

#include <stopwatch_dl.h>

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

Public Member Functions

 DlStopwatchVisualizer (const Stopwatch &stopwatch, std::vector< DlPoint > &vertices_storage, std::vector< DlColor > &color_storage)
 
void Visualize (DlCanvas *canvas, const DlRect &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,
std::vector< DlPoint > &  vertices_storage,
std::vector< DlColor > &  color_storage 
)
inlineexplicit

Definition at line 21 of file stopwatch_dl.h.

24 : StopwatchVisualizer(stopwatch),
25 vertices_storage_(vertices_storage),
26 color_storage_(color_storage) {}
StopwatchVisualizer(const Stopwatch &stopwatch)
Definition stopwatch.h:98

Member Function Documentation

◆ Visualize()

void flutter::DlStopwatchVisualizer::Visualize ( DlCanvas canvas,
const DlRect 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 21 of file stopwatch_dl.cc.

22 {
23 DlVertexPainter painter(vertices_storage_, color_storage_);
24 DlPaint paint;
25
26 // Establish the graph position.
27 const DlScalar x = rect.GetX();
28 const DlScalar y = rect.GetY();
29 const DlScalar width = rect.GetWidth();
30 const DlScalar height = rect.GetHeight();
31 const DlScalar bottom = rect.GetBottom();
32
33 // Scale the graph to show time frames up to those that are 3x the frame time.
34 const DlScalar one_frame_ms = GetFrameBudget().count();
35 const DlScalar max_interval = one_frame_ms * 3.0;
36 const DlScalar max_unit_interval = UnitFrameInterval(max_interval);
37 const DlScalar sample_unit_width = width / kMaxSamples;
38
39 // resize backing storage to match expected lap count.
40 size_t required_storage =
42 if (vertices_storage_.size() < required_storage) {
43 vertices_storage_.resize(required_storage);
44 color_storage_.resize(required_storage);
45 }
46
47 // Provide a semi-transparent background for the graph.
48 painter.DrawRect(rect, DlColor(0x99FFFFFF));
49
50 // Prepare a path for the data; we start at the height of the last point so
51 // it looks like we wrap around.
52 {
53 DlScalar bar_left = x;
54 for (size_t i = 0u; i < stopwatch_.GetLapsCount(); i++) {
55 const double time_ms = stopwatch_.GetLap(i).ToMillisecondsF();
56 const DlScalar sample_unit_height = static_cast<DlScalar>(
57 height * UnitHeight(time_ms, max_unit_interval));
58
59 const DlScalar bar_top = bottom - sample_unit_height;
60 const DlScalar bar_right = x + (i + 1) * sample_unit_width;
61
62 painter.DrawRect(DlRect::MakeLTRB(/*left=*/bar_left,
63 /*top=*/bar_top,
64 /*right=*/bar_right,
65 /*bottom=*/bottom),
66 DlColor(0xAA0000FF));
67 bar_left = bar_right;
68 }
69 }
70
71 // Draw horizontal frame markers.
72 {
73 if (max_interval > one_frame_ms) {
74 // Paint the horizontal markers.
75 size_t count = static_cast<size_t>(max_interval / one_frame_ms);
76
77 // Limit the number of markers to a reasonable amount.
78 if (count > kMaxFrameMarkers) {
79 count = 1;
80 }
81
82 for (uint32_t i = 0u; i < count; i++) {
83 const DlScalar frame_height =
84 height * (1.0 - (UnitFrameInterval(i + 1) * one_frame_ms) /
85 max_unit_interval);
86
87 // Draw a skinny rectangle (i.e. a line).
88 painter.DrawRect(DlRect::MakeLTRB(/*left=*/x,
89 /*top=*/y + frame_height,
90 /*right=*/x + width,
91 /*bottom=*/y + frame_height + 1),
92 DlColor(0xCC000000));
93 }
94 }
95 }
96
97 // Paint the vertical marker for the current frame.
98 {
99 DlColor color = DlColor::kGreen();
101 // budget exceeded.
102 color = DlColor::kRed();
103 }
104 size_t sample =
106 const DlScalar l = x + sample * sample_unit_width;
107 const DlScalar t = y;
108 const DlScalar r = l + sample_unit_width;
109 const DlScalar b = rect.GetBottom();
110 painter.DrawRect(DlRect::MakeLTRB(l, t, r, b), color);
111 }
112
113 // Actually draw.
114 // Use kSrcOver blend mode so that elements under the performance overlay are
115 // partially visible.
116 paint.setBlendMode(DlBlendMode::kSrcOver);
117 // The second blend mode does nothing since the paint has no additional color
118 // sources like a tiled image or gradient.
119 canvas->DrawVertices(painter.IntoVertices(rect), DlBlendMode::kSrcOver,
120 paint);
121}
const fml::TimeDelta & GetLap(size_t index) const
Definition stopwatch.cc:42
const fml::TimeDelta & LastLap() const
Definition stopwatch.cc:38
size_t GetLapsCount() const
Return a reference to all the laps.
Definition stopwatch.cc:46
size_t GetCurrentSample() const
Definition stopwatch.cc:50
double UnitHeight(double time_ms, double max_height) const
Converts a raster time to a unit height.
Definition stopwatch.cc:58
const Stopwatch & stopwatch_
Definition stopwatch.h:125
fml::Milliseconds GetFrameBudget() const
Definition stopwatch.h:123
double UnitFrameInterval(double time_ms) const
Converts a raster time to a unit interval.
Definition stopwatch.cc:54
constexpr double ToMillisecondsF() const
Definition time_delta.h:68
int32_t x
double y
impeller::Scalar DlScalar
static const size_t kMaxSamples
static const size_t kMaxFrameMarkers
flutter::DlColor DlColor
flutter::DlPaint DlPaint
int32_t height
int32_t width
static constexpr DlColor kRed()
Definition dl_color.h:71
static constexpr DlColor kGreen()
Definition dl_color.h:72
static constexpr TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
Definition rect.h:129

References flutter::DlVertexPainter::DrawRect(), flutter::DlCanvas::DrawVertices(), impeller::TRect< T >::GetBottom(), flutter::Stopwatch::GetCurrentSample(), flutter::StopwatchVisualizer::GetFrameBudget(), impeller::TRect< T >::GetHeight(), flutter::Stopwatch::GetLap(), flutter::Stopwatch::GetLapsCount(), impeller::TRect< T >::GetWidth(), impeller::TRect< T >::GetX(), impeller::TRect< T >::GetY(), height, i, flutter::DlVertexPainter::IntoVertices(), flutter::DlColor::kGreen(), flutter::kMaxFrameMarkers, flutter::kMaxSamples, flutter::DlColor::kRed(), flutter::Stopwatch::LastLap(), impeller::TRect< Scalar >::MakeLTRB(), flutter::DlPaint::setBlendMode(), flutter::StopwatchVisualizer::stopwatch_, fml::TimeDelta::ToMillisecondsF(), flutter::StopwatchVisualizer::UnitFrameInterval(), flutter::StopwatchVisualizer::UnitHeight(), width, x, and y.


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