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 ()
 
virtual void Preroll (PrerollContext *context, const SkMatrix &matrix)
 
bool needs_system_composite () const
 
void set_needs_system_composite (bool value)
 
const SkRect & paint_bounds () const
 
void set_paint_bounds (const SkRect &paint_bounds)
 
bool needs_painting () 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.

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(), 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 }

◆ Paint()

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

Implements flutter::Layer.

Definition at line 77 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.

77  {
78  const int padding = 8;
79 
80  if (!options_) {
81  return;
82  }
83 
84  TRACE_EVENT0("flutter", "PerformanceOverlayLayer::Paint");
85  SkScalar x = paint_bounds().x() + padding;
86  SkScalar y = paint_bounds().y() + padding;
87  SkScalar width = paint_bounds().width() - (padding * 2);
88  SkScalar height = paint_bounds().height() / 2;
89  SkAutoCanvasRestore save(context.leaf_nodes_canvas, true);
90 
91  VisualizeStopWatch(
92  context.leaf_nodes_canvas, context.raster_time, x, y, width,
93  height - padding, options_ & kVisualizeRasterizerStatistics,
94  options_ & kDisplayRasterizerStatistics, "Raster", font_path_);
95 
96  VisualizeStopWatch(context.leaf_nodes_canvas, context.ui_time, x, y + height,
97  width, height - padding,
98  options_ & kVisualizeEngineStatistics,
99  options_ & kDisplayEngineStatistics, "UI", font_path_);
100 }
const int kDisplayRasterizerStatistics
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:75
const int kVisualizeEngineStatistics
int32_t height
int32_t width
const SkRect & paint_bounds() const
Definition: layer.h:166
const int kVisualizeRasterizerStatistics
const int kDisplayEngineStatistics

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