Flutter Engine
 
Loading...
Searching...
No Matches
stopwatch_dl.h
Go to the documentation of this file.
1// Copyright 2013 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#ifndef FLUTTER_FLOW_STOPWATCH_DL_H_
6#define FLUTTER_FLOW_STOPWATCH_DL_H_
7
8#include "flow/stopwatch.h"
9
10namespace flutter {
11
12//------------------------------------------------------------------------------
13/// A stopwatch visualizer that uses DisplayList (|DlCanvas|) to draw.
14///
15/// @note This is the newer non-backend specific version, that works in both
16/// Skia and Impeller. The older Skia-specific version is
17/// |SkStopwatchVisualizer|, which still should be used for Skia-specific
18/// optimizations.
20 public:
21 explicit DlStopwatchVisualizer(const Stopwatch& stopwatch,
22 std::vector<DlPoint>& vertices_storage,
23 std::vector<DlColor>& color_storage)
24 : StopwatchVisualizer(stopwatch),
25 vertices_storage_(vertices_storage),
26 color_storage_(color_storage) {}
27
28 void Visualize(DlCanvas* canvas, const DlRect& rect) const override;
29
30 private:
31 std::vector<DlPoint>& vertices_storage_;
32 std::vector<DlColor>& color_storage_;
33};
34
35/// @brief Provides canvas-like painting methods that actually build vertices.
36///
37/// The goal is minimally invasive rendering for the performance monitor.
38///
39/// The methods in this class are intended to be used by |DlStopwatchVisualizer|
40/// only. The rationale is the creating lines, rectangles, and paths (while OK
41/// for general apps) would cause non-trivial work for the performance monitor
42/// due to tessellation per-frame.
43///
44/// @note A goal of this class was to make updating the performance monitor
45/// (and keeping it in sync with the |SkStopwatchVisualizer|) as easy as
46/// possible (i.e. not having to do triangle-math).
47class DlVertexPainter final {
48 public:
49 DlVertexPainter(std::vector<DlPoint>& vertices_storage,
50 std::vector<DlColor>& color_storage);
51
52 /// Draws a rectangle with the given color to a buffer.
53 void DrawRect(const DlRect& rect, const DlColor& color);
54
55 /// Converts the buffered vertices into a |DlVertices| object.
56 ///
57 /// @note This method clears the buffer.
58 std::shared_ptr<DlVertices> IntoVertices(const DlRect& bounds_rect);
59
60 private:
61 std::vector<DlPoint>& vertices_;
62 std::vector<DlColor>& colors_;
63 size_t vertices_offset_ = 0u;
64 size_t colors_offset_ = 0u;
65};
66
67} // namespace flutter
68
69#endif // FLUTTER_FLOW_STOPWATCH_DL_H_
Developer-facing API for rendering anything within the engine.
Definition dl_canvas.h:32
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.
Provides canvas-like painting methods that actually build vertices.
std::shared_ptr< DlVertices > IntoVertices(const DlRect &bounds_rect)
void DrawRect(const DlRect &rect, const DlColor &color)
Draws a rectangle with the given color to a buffer.
Abstract class for visualizing (i.e. drawing) a stopwatch.
Definition stopwatch.h:96