Flutter Impeller
impeller::TextFrameDispatcher Class Reference

Performs a first pass over the display list to collect all text frames. More...

#include <dl_dispatcher.h>

Inheritance diagram for impeller::TextFrameDispatcher:

Public Member Functions

 TextFrameDispatcher (const ContentContext &renderer, const Matrix &initial_matrix, const Rect cull_rect)
 
 ~TextFrameDispatcher ()
 
void save () override
 
void saveLayer (const DlRect &bounds, const flutter::SaveLayerOptions options, const flutter::DlImageFilter *backdrop) override
 
void restore () override
 
void translate (DlScalar tx, DlScalar ty) override
 
void scale (DlScalar sx, DlScalar sy) override
 
void rotate (DlScalar degrees) override
 
void skew (DlScalar sx, DlScalar sy) override
 
void transform2DAffine (DlScalar mxx, DlScalar mxy, DlScalar mxt, DlScalar myx, DlScalar myy, DlScalar myt) override
 
void transformFullPerspective (DlScalar mxx, DlScalar mxy, DlScalar mxz, DlScalar mxt, DlScalar myx, DlScalar myy, DlScalar myz, DlScalar myt, DlScalar mzx, DlScalar mzy, DlScalar mzz, DlScalar mzt, DlScalar mwx, DlScalar mwy, DlScalar mwz, DlScalar mwt) override
 
void transformReset () override
 
void drawTextFrame (const std::shared_ptr< impeller::TextFrame > &text_frame, DlScalar x, DlScalar y) override
 
void drawDisplayList (const sk_sp< flutter::DisplayList > display_list, DlScalar opacity) override
 
void setDrawStyle (flutter::DlDrawStyle style) override
 
void setColor (flutter::DlColor color) override
 
void setStrokeWidth (DlScalar width) override
 
void setStrokeMiter (DlScalar limit) override
 
void setStrokeCap (flutter::DlStrokeCap cap) override
 
void setStrokeJoin (flutter::DlStrokeJoin join) override
 
void setImageFilter (const flutter::DlImageFilter *filter) override
 

Detailed Description

Performs a first pass over the display list to collect all text frames.

Definition at line 288 of file dl_dispatcher.h.

Constructor & Destructor Documentation

◆ TextFrameDispatcher()

impeller::TextFrameDispatcher::TextFrameDispatcher ( const ContentContext renderer,
const Matrix initial_matrix,
const Rect  cull_rect 
)

Definition at line 979 of file dl_dispatcher.cc.

982  : renderer_(renderer), matrix_(initial_matrix) {
983  cull_rect_state_.push_back(cull_rect);
984 }

◆ ~TextFrameDispatcher()

impeller::TextFrameDispatcher::~TextFrameDispatcher ( )

Definition at line 986 of file dl_dispatcher.cc.

986  {
987  FML_DCHECK(cull_rect_state_.size() == 1);
988 }

Member Function Documentation

◆ drawDisplayList()

void impeller::TextFrameDispatcher::drawDisplayList ( const sk_sp< flutter::DisplayList >  display_list,
DlScalar  opacity 
)
override

Definition at line 1104 of file dl_dispatcher.cc.

1106  {
1107  [[maybe_unused]] size_t stack_depth = stack_.size();
1108  save();
1109  Paint old_paint = paint_;
1110  paint_ = Paint{};
1111  bool old_has_image_filter = has_image_filter_;
1112  has_image_filter_ = false;
1113 
1114  if (matrix_.HasPerspective()) {
1115  display_list->Dispatch(*this);
1116  } else {
1117  Rect local_cull_bounds = GetCurrentLocalCullingBounds();
1118  if (local_cull_bounds.IsMaximum()) {
1119  display_list->Dispatch(*this);
1120  } else if (!local_cull_bounds.IsEmpty()) {
1121  IRect cull_rect = IRect::RoundOut(local_cull_bounds);
1122  display_list->Dispatch(*this, SkIRect::MakeLTRB(cull_rect.GetLeft(), //
1123  cull_rect.GetTop(), //
1124  cull_rect.GetRight(), //
1125  cull_rect.GetBottom() //
1126  ));
1127  }
1128  }
1129 
1130  restore();
1131  paint_ = old_paint;
1132  has_image_filter_ = old_has_image_filter;
1133  FML_DCHECK(stack_depth == stack_.size());
1134 }

References impeller::TRect< T >::GetBottom(), impeller::TRect< T >::GetLeft(), impeller::TRect< T >::GetRight(), impeller::TRect< T >::GetTop(), impeller::Matrix::HasPerspective(), impeller::TRect< T >::IsEmpty(), impeller::TRect< T >::IsMaximum(), restore(), impeller::TRect< T >::RoundOut(), and save().

◆ drawTextFrame()

void impeller::TextFrameDispatcher::drawTextFrame ( const std::shared_ptr< impeller::TextFrame > &  text_frame,
DlScalar  x,
DlScalar  y 
)
override

Definition at line 1069 of file dl_dispatcher.cc.

1072  {
1073  GlyphProperties properties;
1074  if (paint_.style == Paint::Style::kStroke) {
1075  properties.stroke = true;
1076  properties.stroke_cap = paint_.stroke_cap;
1077  properties.stroke_join = paint_.stroke_join;
1078  properties.stroke_miter = paint_.stroke_miter;
1079  properties.stroke_width = paint_.stroke_width;
1080  }
1081  if (text_frame->HasColor()) {
1082  // Alpha is always applied when rendering, remove it here so
1083  // we do not double-apply the alpha.
1084  properties.color = paint_.color.WithAlpha(1.0);
1085  }
1086  auto scale =
1087  (matrix_ * Matrix::MakeTranslation(Point(x, y))).GetMaxBasisLengthXY();
1088  renderer_.GetLazyGlyphAtlas()->AddTextFrame(*text_frame, //
1089  scale, //
1090  Point(x, y), //
1091  properties //
1092  );
1093 }

References impeller::GlyphProperties::color, impeller::Paint::color, impeller::ContentContext::GetLazyGlyphAtlas(), impeller::Paint::kStroke, impeller::Matrix::MakeTranslation(), scale(), impeller::GlyphProperties::stroke, impeller::GlyphProperties::stroke_cap, impeller::Paint::stroke_cap, impeller::GlyphProperties::stroke_join, impeller::Paint::stroke_join, impeller::GlyphProperties::stroke_miter, impeller::Paint::stroke_miter, impeller::GlyphProperties::stroke_width, impeller::Paint::stroke_width, impeller::Paint::style, and impeller::Color::WithAlpha().

◆ restore()

void impeller::TextFrameDispatcher::restore ( )
override

Definition at line 1016 of file dl_dispatcher.cc.

1016  {
1017  matrix_ = stack_.back();
1018  stack_.pop_back();
1019  cull_rect_state_.pop_back();
1020 }

Referenced by drawDisplayList().

◆ rotate()

void impeller::TextFrameDispatcher::rotate ( DlScalar  degrees)
override

Definition at line 1030 of file dl_dispatcher.cc.

1030  {
1031  matrix_ = matrix_ * Matrix::MakeRotationZ(Degrees(degrees));
1032 }

References impeller::Matrix::MakeRotationZ().

◆ save()

void impeller::TextFrameDispatcher::save ( )
override

Definition at line 990 of file dl_dispatcher.cc.

990  {
991  stack_.emplace_back(matrix_);
992  cull_rect_state_.push_back(cull_rect_state_.back());
993 }

Referenced by drawDisplayList(), and saveLayer().

◆ saveLayer()

void impeller::TextFrameDispatcher::saveLayer ( const DlRect bounds,
const flutter::SaveLayerOptions  options,
const flutter::DlImageFilter *  backdrop 
)
override

Definition at line 995 of file dl_dispatcher.cc.

997  {
998  save();
999 
1000  // This dispatcher does not track enough state to accurately compute
1001  // cull rects with image filters.
1002  auto global_cull_rect = cull_rect_state_.back();
1003  if (has_image_filter_ || global_cull_rect.IsMaximum()) {
1004  cull_rect_state_.back() = Rect::MakeMaximum();
1005  } else {
1006  auto global_save_bounds = bounds.TransformBounds(matrix_);
1007  auto new_cull_rect = global_cull_rect.Intersection(global_save_bounds);
1008  if (new_cull_rect.has_value()) {
1009  cull_rect_state_.back() = new_cull_rect.value();
1010  } else {
1011  cull_rect_state_.back() = Rect::MakeLTRB(0, 0, 0, 0);
1012  }
1013  }
1014 }

References impeller::TRect< Scalar >::MakeLTRB(), impeller::TRect< Scalar >::MakeMaximum(), and save().

◆ scale()

void impeller::TextFrameDispatcher::scale ( DlScalar  sx,
DlScalar  sy 
)
override

Definition at line 1026 of file dl_dispatcher.cc.

1026  {
1027  matrix_ = matrix_.Scale({sx, sy, 1.0f});
1028 }

References impeller::Matrix::Scale().

Referenced by drawTextFrame().

◆ setColor()

void impeller::TextFrameDispatcher::setColor ( flutter::DlColor  color)
override

Definition at line 1142 of file dl_dispatcher.cc.

1142  {
1144 }

References color, impeller::Paint::color, and impeller::skia_conversions::ToColor().

◆ setDrawStyle()

void impeller::TextFrameDispatcher::setDrawStyle ( flutter::DlDrawStyle  style)
override

Definition at line 1137 of file dl_dispatcher.cc.

1137  {
1138  paint_.style = ToStyle(style);
1139 }

References impeller::Paint::style, and impeller::ToStyle().

◆ setImageFilter()

void impeller::TextFrameDispatcher::setImageFilter ( const flutter::DlImageFilter *  filter)
override

Definition at line 1187 of file dl_dispatcher.cc.

1187  {
1188  if (filter == nullptr) {
1189  has_image_filter_ = false;
1190  } else {
1191  has_image_filter_ = true;
1192  }
1193 }

◆ setStrokeCap()

void impeller::TextFrameDispatcher::setStrokeCap ( flutter::DlStrokeCap  cap)
override

Definition at line 1157 of file dl_dispatcher.cc.

1157  {
1158  switch (cap) {
1159  case flutter::DlStrokeCap::kButt:
1160  paint_.stroke_cap = Cap::kButt;
1161  break;
1162  case flutter::DlStrokeCap::kRound:
1163  paint_.stroke_cap = Cap::kRound;
1164  break;
1165  case flutter::DlStrokeCap::kSquare:
1166  paint_.stroke_cap = Cap::kSquare;
1167  break;
1168  }
1169 }

References impeller::kButt, impeller::kRound, impeller::kSquare, and impeller::Paint::stroke_cap.

◆ setStrokeJoin()

void impeller::TextFrameDispatcher::setStrokeJoin ( flutter::DlStrokeJoin  join)
override

Definition at line 1172 of file dl_dispatcher.cc.

1172  {
1173  switch (join) {
1174  case flutter::DlStrokeJoin::kMiter:
1175  paint_.stroke_join = Join::kMiter;
1176  break;
1177  case flutter::DlStrokeJoin::kRound:
1178  paint_.stroke_join = Join::kRound;
1179  break;
1180  case flutter::DlStrokeJoin::kBevel:
1181  paint_.stroke_join = Join::kBevel;
1182  break;
1183  }
1184 }

References impeller::kBevel, impeller::kMiter, impeller::kRound, and impeller::Paint::stroke_join.

◆ setStrokeMiter()

void impeller::TextFrameDispatcher::setStrokeMiter ( DlScalar  limit)
override

Definition at line 1152 of file dl_dispatcher.cc.

1152  {
1153  paint_.stroke_miter = limit;
1154 }

References impeller::Paint::stroke_miter.

◆ setStrokeWidth()

void impeller::TextFrameDispatcher::setStrokeWidth ( DlScalar  width)
override

Definition at line 1147 of file dl_dispatcher.cc.

1147  {
1148  paint_.stroke_width = width;
1149 }

References impeller::Paint::stroke_width.

◆ skew()

void impeller::TextFrameDispatcher::skew ( DlScalar  sx,
DlScalar  sy 
)
override

Definition at line 1034 of file dl_dispatcher.cc.

1034  {
1035  matrix_ = matrix_ * Matrix::MakeSkew(sx, sy);
1036 }

References impeller::Matrix::MakeSkew().

◆ transform2DAffine()

void impeller::TextFrameDispatcher::transform2DAffine ( DlScalar  mxx,
DlScalar  mxy,
DlScalar  mxt,
DlScalar  myx,
DlScalar  myy,
DlScalar  myt 
)
override

Definition at line 1040 of file dl_dispatcher.cc.

1041  {
1042  matrix_ = matrix_ * Matrix::MakeColumn(
1043  mxx, myx, 0.0f, 0.0f,
1044  mxy, myy, 0.0f, 0.0f,
1045  0.0f, 0.0f, 1.0f, 0.0f,
1046  mxt, myt, 0.0f, 1.0f
1047  );
1048  }

References impeller::Matrix::MakeColumn().

◆ transformFullPerspective()

void impeller::TextFrameDispatcher::transformFullPerspective ( DlScalar  mxx,
DlScalar  mxy,
DlScalar  mxz,
DlScalar  mxt,
DlScalar  myx,
DlScalar  myy,
DlScalar  myz,
DlScalar  myt,
DlScalar  mzx,
DlScalar  mzy,
DlScalar  mzz,
DlScalar  mzt,
DlScalar  mwx,
DlScalar  mwy,
DlScalar  mwz,
DlScalar  mwt 
)
override

Definition at line 1051 of file dl_dispatcher.cc.

1055  {
1056  matrix_ = matrix_ * Matrix::MakeColumn(
1057  mxx, myx, mzx, mwx,
1058  mxy, myy, mzy, mwy,
1059  mxz, myz, mzz, mwz,
1060  mxt, myt, mzt, mwt
1061  );
1062  }

References impeller::Matrix::MakeColumn().

◆ transformReset()

void impeller::TextFrameDispatcher::transformReset ( )
override

Definition at line 1065 of file dl_dispatcher.cc.

1065  {
1066  matrix_ = Matrix();
1067 }

◆ translate()

void impeller::TextFrameDispatcher::translate ( DlScalar  tx,
DlScalar  ty 
)
override

Definition at line 1022 of file dl_dispatcher.cc.

1022  {
1023  matrix_ = matrix_.Translate({tx, ty});
1024 }

References impeller::Matrix::Translate().


The documentation for this class was generated from the following files:
impeller::Matrix::MakeSkew
static constexpr Matrix MakeSkew(Scalar sx, Scalar sy)
Definition: matrix.h:117
impeller::Paint::stroke_cap
Cap stroke_cap
Definition: paint.h:80
impeller::Matrix::HasPerspective
constexpr bool HasPerspective() const
Definition: matrix.h:335
impeller::Cap::kRound
@ kRound
impeller::TextFrameDispatcher::scale
void scale(DlScalar sx, DlScalar sy) override
Definition: dl_dispatcher.cc:1026
impeller::Cap::kSquare
@ kSquare
impeller::ContentContext::GetLazyGlyphAtlas
const std::shared_ptr< LazyGlyphAtlas > & GetLazyGlyphAtlas() const
Definition: content_context.h:721
impeller::Paint::Style::kStroke
@ kStroke
impeller::TextFrameDispatcher::restore
void restore() override
Definition: dl_dispatcher.cc:1016
impeller::Paint::color
Color color
Definition: paint.h:74
impeller::TextFrameDispatcher::save
void save() override
Definition: dl_dispatcher.cc:990
impeller::skia_conversions::ToColor
Color ToColor(const flutter::DlColor &color)
Definition: skia_conversions.cc:106
impeller::Cap::kButt
@ kButt
impeller::Matrix::MakeTranslation
static constexpr Matrix MakeTranslation(const Vector3 &t)
Definition: matrix.h:95
impeller::Join::kMiter
@ kMiter
impeller::Paint::stroke_miter
Scalar stroke_miter
Definition: paint.h:82
impeller::TRect::RoundOut
RoundOut(const TRect< U > &r)
Definition: rect.h:673
impeller::Point
TPoint< Scalar > Point
Definition: point.h:327
impeller::Paint::style
Style style
Definition: paint.h:83
impeller::Color::WithAlpha
constexpr Color WithAlpha(Scalar new_alpha) const
Definition: color.h:277
impeller::ToStyle
static Paint::Style ToStyle(flutter::DlDrawStyle style)
Definition: dl_dispatcher.cc:143
impeller::Matrix::Translate
constexpr Matrix Translate(const Vector3 &t) const
Definition: matrix.h:240
impeller::Matrix::MakeColumn
static constexpr Matrix MakeColumn(Scalar m0, Scalar m1, Scalar m2, Scalar m3, Scalar m4, Scalar m5, Scalar m6, Scalar m7, Scalar m8, Scalar m9, Scalar m10, Scalar m11, Scalar m12, Scalar m13, Scalar m14, Scalar m15)
Definition: matrix.h:69
impeller::Rect
TRect< Scalar > Rect
Definition: rect.h:776
impeller::Join::kRound
@ kRound
impeller::Join::kBevel
@ kBevel
impeller::Matrix::MakeRotationZ
static Matrix MakeRotationZ(Radians r)
Definition: matrix.h:213
impeller::TRect< Scalar >::MakeMaximum
constexpr static TRect MakeMaximum()
Definition: rect.h:178
impeller::IRect
IRect64 IRect
Definition: rect.h:779
color
DlColor color
Definition: dl_golden_blur_unittests.cc:24
impeller::TRect< Scalar >::MakeLTRB
constexpr static TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
Definition: rect.h:129
impeller::Paint::stroke_width
Scalar stroke_width
Definition: paint.h:79
impeller::Matrix::Scale
constexpr Matrix Scale(const Vector3 &s) const
Definition: matrix.h:252
impeller::Paint::stroke_join
Join stroke_join
Definition: paint.h:81