Flutter Engine
flutter::PerformanceOverlayLayer Class Reference

#include <performance_overlay_layer.h>

Inheritance diagram for flutter::PerformanceOverlayLayer:
flutter::Layer

Public Member Functions

 PerformanceOverlayLayer (uint64_t options, const char *font_path=nullptr)
 
void Paint (PaintContext &context) const override
 
- Public Member Functions inherited from flutter::Layer
 Layer ()
 
virtual ~Layer ()
 
void AssignOldLayer (Layer *old_layer)
 
virtual void Preroll (PrerollContext *context, const SkMatrix &matrix)
 
bool subtree_has_platform_view () const
 
void set_subtree_has_platform_view (bool value)
 
const SkRect & paint_bounds () const
 
void set_paint_bounds (const SkRect &paint_bounds)
 
bool is_empty () const
 
bool needs_painting (PaintContext &context) const
 
uint64_t original_layer_id () const
 
uint64_t unique_id () const
 

Static Public Member Functions

static sk_sp< SkTextBlob > MakeStatisticsText (const Stopwatch &stopwatch, const std::string &label_prefix, const std::string &font_path)
 

Detailed Description

Definition at line 23 of file performance_overlay_layer.h.

Constructor & Destructor Documentation

◆ PerformanceOverlayLayer()

flutter::PerformanceOverlayLayer::PerformanceOverlayLayer ( uint64_t  options,
const char *  font_path = nullptr 
)
explicit

Definition at line 69 of file performance_overlay_layer.cc.

References FML_DCHECK, and flutter::Layer::paint_bounds().

71  : options_(options) {
72  if (font_path != nullptr) {
73  font_path_ = font_path;
74  }
75 }

Member Function Documentation

◆ MakeStatisticsText()

sk_sp< SkTextBlob > flutter::PerformanceOverlayLayer::MakeStatisticsText ( const Stopwatch stopwatch,
const std::string &  label_prefix,
const std::string &  font_path 
)
static

Definition at line 46 of file performance_overlay_layer.cc.

References flutter::Stopwatch::AverageDelta(), flutter::Stopwatch::MaxDelta(), text, and fml::TimeDelta::ToMillisecondsF().

Referenced by flutter::testing::TEST_F().

49  {
50  SkFont font;
51  if (font_path != "") {
52  font = SkFont(SkTypeface::MakeFromFile(font_path.c_str()));
53  }
54  font.setSize(15);
55 
56  double max_ms_per_frame = stopwatch.MaxDelta().ToMillisecondsF();
57  double average_ms_per_frame = stopwatch.AverageDelta().ToMillisecondsF();
58  std::stringstream stream;
59  stream.setf(std::ios::fixed | std::ios::showpoint);
60  stream << std::setprecision(1);
61  stream << label_prefix << " "
62  << "max " << max_ms_per_frame << " ms/frame, "
63  << "avg " << average_ms_per_frame << " ms/frame";
64  auto text = stream.str();
65  return SkTextBlob::MakeFromText(text.c_str(), text.size(), font,
66  SkTextEncoding::kUTF8);
67 }
std::u16string text

◆ Paint()

void flutter::PerformanceOverlayLayer::Paint ( PaintContext context) const
overridevirtual

Implements flutter::Layer.

Definition at line 93 of file performance_overlay_layer.cc.

References flutter::kDisplayEngineStatistics, flutter::kDisplayRasterizerStatistics, flutter::kVisualizeEngineStatistics, flutter::kVisualizeRasterizerStatistics, flutter::Layer::PaintContext::leaf_nodes_canvas, flutter::Layer::paint_bounds(), flutter::Layer::PaintContext::raster_time, TRACE_EVENT0, and flutter::Layer::PaintContext::ui_time.

93  {
94  const int padding = 8;
95 
96  if (!options_) {
97  return;
98  }
99 
100  TRACE_EVENT0("flutter", "PerformanceOverlayLayer::Paint");
101  SkScalar x = paint_bounds().x() + padding;
102  SkScalar y = paint_bounds().y() + padding;
103  SkScalar width = paint_bounds().width() - (padding * 2);
104  SkScalar height = paint_bounds().height() / 2;
105  SkAutoCanvasRestore save(context.leaf_nodes_canvas, true);
106 
107  VisualizeStopWatch(
108  context.leaf_nodes_canvas, context.raster_time, x, y, width,
109  height - padding, options_ & kVisualizeRasterizerStatistics,
110  options_ & kDisplayRasterizerStatistics, "Raster", font_path_);
111 
112  VisualizeStopWatch(context.leaf_nodes_canvas, context.ui_time, x, y + height,
113  width, height - padding,
114  options_ & kVisualizeEngineStatistics,
115  options_ & kDisplayEngineStatistics, "UI", font_path_);
116 }
const int kDisplayRasterizerStatistics
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:90
const int kVisualizeEngineStatistics
int32_t width
const SkRect & paint_bounds() const
Definition: layer.h:227
const int kVisualizeRasterizerStatistics
int32_t height
const int kDisplayEngineStatistics

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