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

#include <performance_overlay_layer.h>

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

Public Member Functions

bool IsReplacing (DiffContext *context, const Layer *layer) const override
 
void Diff (DiffContext *context, const Layer *old_layer) override
 
const PerformanceOverlayLayeras_performance_overlay_layer () const override
 
 PerformanceOverlayLayer (uint64_t options, const char *font_path=nullptr)
 
void Preroll (PrerollContext *context) override
 
void Paint (PaintContext &context) const override
 
- Public Member Functions inherited from flutter::Layer
 Layer ()
 
virtual ~Layer ()
 
void AssignOldLayer (Layer *old_layer)
 
virtual void PreservePaintRegion (DiffContext *context)
 
virtual void PaintChildren (PaintContext &context) const
 
bool subtree_has_platform_view () const
 
void set_subtree_has_platform_view (bool value)
 
const DlRectpaint_bounds () const
 
void set_paint_bounds (const DlRect &paint_bounds)
 
bool is_empty () const
 
bool needs_painting (PaintContext &context) const
 
uint64_t original_layer_id () const
 
uint64_t unique_id () const
 
virtual RasterCacheKeyID caching_key_id () const
 
virtual const ContainerLayeras_container_layer () const
 
virtual const DisplayListLayeras_display_list_layer () const
 
virtual const TextureLayeras_texture_layer () const
 
virtual const testing::MockLayeras_mock_layer () const
 

Static Public Member Functions

static SkFont MakeStatisticsFont (std::string_view font_path)
 
static sk_sp< SkTextBlob > MakeStatisticsText (const Stopwatch &stopwatch, const SkFont &font, std::string_view label_prefix)
 

Additional Inherited Members

- Static Public Attributes inherited from flutter::Layer
static constexpr int kSaveLayerRenderFlags
 
static constexpr int kRasterCacheRenderFlags
 

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 107 of file performance_overlay_layer.cc.

109 : options_(options) {
110 if (font_path != nullptr) {
111 font_path_ = font_path;
112 }
113}

Member Function Documentation

◆ as_performance_overlay_layer()

const PerformanceOverlayLayer * flutter::PerformanceOverlayLayer::as_performance_overlay_layer ( ) const
inlineoverridevirtual

Reimplemented from flutter::Layer.

Definition at line 37 of file performance_overlay_layer.h.

37 {
38 return this;
39 }

◆ Diff()

void flutter::PerformanceOverlayLayer::Diff ( DiffContext context,
const Layer old_layer 
)
overridevirtual

Reimplemented from flutter::Layer.

Definition at line 115 of file performance_overlay_layer.cc.

116 {
117 DiffContext::AutoSubtreeRestore subtree(context);
118 if (!context->IsSubtreeDirty()) {
119 FML_DCHECK(old_layer);
120 auto prev = old_layer->as_performance_overlay_layer();
121 context->MarkSubtreeDirty(context->GetOldLayerPaintRegion(prev));
122 }
123 context->AddLayerBounds(paint_bounds());
124 context->SetLayerPaintRegion(this, context->CurrentSubtreeRegion());
125}
const DlRect & paint_bounds() const
Definition layer.h:196
#define FML_DCHECK(condition)
Definition logging.h:122

References flutter::DiffContext::AddLayerBounds(), flutter::Layer::as_performance_overlay_layer(), flutter::DiffContext::CurrentSubtreeRegion(), FML_DCHECK, flutter::DiffContext::GetOldLayerPaintRegion(), flutter::DiffContext::IsSubtreeDirty(), flutter::DiffContext::MarkSubtreeDirty(), flutter::Layer::paint_bounds(), and flutter::DiffContext::SetLayerPaintRegion().

◆ IsReplacing()

bool flutter::PerformanceOverlayLayer::IsReplacing ( DiffContext context,
const Layer layer 
) const
inlineoverridevirtual

Reimplemented from flutter::Layer.

Definition at line 31 of file performance_overlay_layer.h.

31 {
32 return layer->as_performance_overlay_layer() != nullptr;
33 }

References flutter::Layer::as_performance_overlay_layer().

◆ MakeStatisticsFont()

SkFont flutter::PerformanceOverlayLayer::MakeStatisticsFont ( std::string_view  font_path)
static

Definition at line 71 of file performance_overlay_layer.cc.

71 {
72 sk_sp<SkFontMgr> font_mgr = txt::GetDefaultFontManager();
73 if (font_path == "") {
74 if (sk_sp<SkTypeface> face = font_mgr->matchFamilyStyle(nullptr, {})) {
75 return SkFont(face, 15);
76 } else {
77 // In Skia's Android fontmgr, matchFamilyStyle can return null instead
78 // of falling back to a default typeface. If that's the case, we can use
79 // legacyMakeTypeface, which *does* use that default typeface.
80 return SkFont(font_mgr->legacyMakeTypeface(nullptr, {}), 15);
81 }
82 } else {
83 return SkFont(font_mgr->makeFromFile(font_path.data()), 15);
84 }
85}
sk_sp< SkFontMgr > GetDefaultFontManager(uint32_t font_initialization_data)
Definition platform.cc:17

References txt::GetDefaultFontManager().

Referenced by Paint(), and flutter::testing::TEST_F().

◆ MakeStatisticsText()

sk_sp< SkTextBlob > flutter::PerformanceOverlayLayer::MakeStatisticsText ( const Stopwatch stopwatch,
const SkFont &  font,
std::string_view  label_prefix 
)
static

Definition at line 88 of file performance_overlay_layer.cc.

91 {
92 // Make sure there's not an empty typeface returned, or we won't see any text.
93 FML_DCHECK(font.getTypeface()->countGlyphs() > 0);
94
95 double max_ms_per_frame = stopwatch.MaxDelta().ToMillisecondsF();
96 double average_ms_per_frame = stopwatch.AverageDelta().ToMillisecondsF();
97 std::stringstream stream;
98 stream.setf(std::ios::fixed | std::ios::showpoint);
99 stream << std::setprecision(1);
100 stream << label_prefix << " " << "max " << max_ms_per_frame << " ms/frame, "
101 << "avg " << average_ms_per_frame << " ms/frame";
102 auto text = stream.str();
103 return SkTextBlob::MakeFromText(text.c_str(), text.size(), font,
104 SkTextEncoding::kUTF8);
105}
std::u16string text

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

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

◆ Paint()

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

Implements flutter::Layer.

Definition at line 127 of file performance_overlay_layer.cc.

127 {
128 const int padding = 8;
129
130 if (!options_) {
131 return;
132 }
133
138 auto mutator = context.state_stack.save();
139 // Cached storage for vertex output.
140 std::vector<DlPoint> vertices_storage;
141 std::vector<DlColor> color_storage;
142 SkFont font = MakeStatisticsFont(font_path_);
143
144 VisualizeStopWatch(context.canvas, context.impeller_enabled,
145 context.raster_time, x, y, width, height - padding,
147 options_ & kDisplayRasterizerStatistics, "Raster",
148 vertices_storage, color_storage, font);
149
150 VisualizeStopWatch(context.canvas, context.impeller_enabled, context.ui_time,
151 x, y + height, width, height - padding,
153 options_ & kDisplayEngineStatistics, "UI",
154 vertices_storage, color_storage, font);
155}
static SkFont MakeStatisticsFont(std::string_view font_path)
int32_t x
Vector2 padding
The halo padding in source space.
double y
const int kVisualizeEngineStatistics
impeller::Scalar DlScalar
const int kDisplayEngineStatistics
const int kVisualizeRasterizerStatistics
const int kDisplayRasterizerStatistics
int32_t height
int32_t width
constexpr Type GetY() const
Returns the Y coordinate of the upper left corner, equivalent to |GetOrigin().y|.
Definition rect.h:337
constexpr Type GetHeight() const
Returns the height of the rectangle, equivalent to |GetSize().height|.
Definition rect.h:347
constexpr Type GetX() const
Returns the X coordinate of the upper left corner, equivalent to |GetOrigin().x|.
Definition rect.h:333
constexpr Type GetWidth() const
Returns the width of the rectangle, equivalent to |GetSize().width|.
Definition rect.h:341

References flutter::PaintContext::canvas, impeller::TRect< T >::GetHeight(), impeller::TRect< T >::GetWidth(), impeller::TRect< T >::GetX(), impeller::TRect< T >::GetY(), height, flutter::PaintContext::impeller_enabled, flutter::kDisplayEngineStatistics, flutter::kDisplayRasterizerStatistics, flutter::kVisualizeEngineStatistics, flutter::kVisualizeRasterizerStatistics, MakeStatisticsFont(), padding, flutter::Layer::paint_bounds(), flutter::PaintContext::raster_time, flutter::LayerStateStack::save(), flutter::PaintContext::state_stack, flutter::PaintContext::ui_time, width, x, and y.

◆ Preroll()

void flutter::PerformanceOverlayLayer::Preroll ( PrerollContext context)
inlineoverridevirtual

Implements flutter::Layer.

Definition at line 44 of file performance_overlay_layer.h.

44{}

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