Flutter Impeller
impeller::FirstPassDispatcher Class Reference

#include <dl_dispatcher.h>

Inheritance diagram for impeller::FirstPassDispatcher:

Public Member Functions

 FirstPassDispatcher (const ContentContext &renderer, const Matrix &initial_matrix, const Rect cull_rect)
 
 ~FirstPassDispatcher ()
 
void save () override
 
void saveLayer (const DlRect &bounds, const flutter::SaveLayerOptions options, const flutter::DlImageFilter *backdrop, std::optional< int64_t > backdrop_id) 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
 
std::pair< std::unordered_map< int64_t, BackdropData >, size_t > TakeBackdropData ()
 

Detailed Description

Performs a first pass over the display list to collect infomation. Collects things like text frames and backdrop filters.

Definition at line 316 of file dl_dispatcher.h.

Constructor & Destructor Documentation

◆ FirstPassDispatcher()

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

Definition at line 1042 of file dl_dispatcher.cc.

1045  : renderer_(renderer), matrix_(initial_matrix) {
1046  cull_rect_state_.push_back(cull_rect);
1047 }

◆ ~FirstPassDispatcher()

impeller::FirstPassDispatcher::~FirstPassDispatcher ( )

Definition at line 1049 of file dl_dispatcher.cc.

1049  {
1050  FML_DCHECK(cull_rect_state_.size() == 1);
1051 }

Member Function Documentation

◆ drawDisplayList()

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

Definition at line 1192 of file dl_dispatcher.cc.

1194  {
1195  [[maybe_unused]] size_t stack_depth = stack_.size();
1196  save();
1197  Paint old_paint = paint_;
1198  paint_ = Paint{};
1199  bool old_has_image_filter = has_image_filter_;
1200  has_image_filter_ = false;
1201 
1202  if (matrix_.HasPerspective()) {
1203  display_list->Dispatch(*this);
1204  } else {
1205  Rect local_cull_bounds = GetCurrentLocalCullingBounds();
1206  if (local_cull_bounds.IsMaximum()) {
1207  display_list->Dispatch(*this);
1208  } else if (!local_cull_bounds.IsEmpty()) {
1209  IRect cull_rect = IRect::RoundOut(local_cull_bounds);
1210  display_list->Dispatch(*this,
1211  SkIRect::MakeLTRB(cull_rect.GetLeft(), //
1212  cull_rect.GetTop(), //
1213  cull_rect.GetRight(), //
1214  cull_rect.GetBottom() //
1215  ));
1216  }
1217  }
1218 
1219  restore();
1220  paint_ = old_paint;
1221  has_image_filter_ = old_has_image_filter;
1222  FML_DCHECK(stack_depth == stack_.size());
1223 }
TRect< Scalar > Rect
Definition: rect.h:792
IRect64 IRect
Definition: rect.h:795
constexpr bool HasPerspective() const
Definition: matrix.h:365
RoundOut(const TRect< U > &r)
Definition: rect.h:683

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::FirstPassDispatcher::drawTextFrame ( const std::shared_ptr< impeller::TextFrame > &  text_frame,
DlScalar  x,
DlScalar  y 
)
override

Definition at line 1152 of file dl_dispatcher.cc.

1155  {
1156  GlyphProperties properties;
1157  if (paint_.style == Paint::Style::kStroke) {
1158  properties.stroke = true;
1159  properties.stroke_cap = paint_.stroke_cap;
1160  properties.stroke_join = paint_.stroke_join;
1161  properties.stroke_miter = paint_.stroke_miter;
1162  properties.stroke_width = paint_.stroke_width;
1163  }
1164  if (text_frame->HasColor()) {
1165  // Alpha is always applied when rendering, remove it here so
1166  // we do not double-apply the alpha.
1167  properties.color = paint_.color.WithAlpha(1.0);
1168  }
1170  (matrix_ * Matrix::MakeTranslation(Point(x, y))).GetMaxBasisLengthXY());
1171 
1172  renderer_.GetLazyGlyphAtlas()->AddTextFrame(
1173  text_frame, //
1174  scale, //
1175  Point(x, y), //
1176  matrix_,
1177  (properties.stroke || text_frame->HasColor()) //
1178  ? std::optional<GlyphProperties>(properties) //
1179  : std::nullopt //
1180  );
1181 }
const std::shared_ptr< LazyGlyphAtlas > & GetLazyGlyphAtlas() const
void scale(DlScalar sx, DlScalar sy) override
static Rational RoundScaledFontSize(Scalar scale)
Definition: text_frame.cc:55
int32_t x
TPoint< Scalar > Point
Definition: point.h:327
constexpr Color WithAlpha(Scalar new_alpha) const
Definition: color.h:278
static constexpr Matrix MakeTranslation(const Vector3 &t)
Definition: matrix.h:95
Cap stroke_cap
Definition: paint.h:80
Join stroke_join
Definition: paint.h:81
Scalar stroke_miter
Definition: paint.h:82
Style style
Definition: paint.h:83
Color color
Definition: paint.h:74
Scalar stroke_width
Definition: paint.h:79

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

◆ restore()

void impeller::FirstPassDispatcher::restore ( )
override

Definition at line 1099 of file dl_dispatcher.cc.

1099  {
1100  matrix_ = stack_.back();
1101  stack_.pop_back();
1102  cull_rect_state_.pop_back();
1103 }

Referenced by drawDisplayList().

◆ rotate()

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

Definition at line 1113 of file dl_dispatcher.cc.

1113  {
1114  matrix_ = matrix_ * Matrix::MakeRotationZ(Degrees(degrees));
1115 }
static Matrix MakeRotationZ(Radians r)
Definition: matrix.h:223

References impeller::Matrix::MakeRotationZ().

◆ save()

void impeller::FirstPassDispatcher::save ( )
override

Definition at line 1053 of file dl_dispatcher.cc.

1053  {
1054  stack_.emplace_back(matrix_);
1055  cull_rect_state_.push_back(cull_rect_state_.back());
1056 }

Referenced by drawDisplayList(), and saveLayer().

◆ saveLayer()

void impeller::FirstPassDispatcher::saveLayer ( const DlRect bounds,
const flutter::SaveLayerOptions  options,
const flutter::DlImageFilter *  backdrop,
std::optional< int64_t >  backdrop_id 
)
override

Definition at line 1058 of file dl_dispatcher.cc.

1061  {
1062  save();
1063 
1064  backdrop_count_ += (backdrop == nullptr ? 0 : 1);
1065  if (backdrop != nullptr && backdrop_id.has_value()) {
1066  std::shared_ptr<flutter::DlImageFilter> shared_backdrop =
1067  backdrop->shared();
1068  std::unordered_map<int64_t, BackdropData>::iterator existing =
1069  backdrop_data_.find(backdrop_id.value());
1070  if (existing == backdrop_data_.end()) {
1071  backdrop_data_[backdrop_id.value()] =
1072  BackdropData{.backdrop_count = 1, .last_backdrop = shared_backdrop};
1073  } else {
1074  BackdropData& data = existing->second;
1075  data.backdrop_count++;
1076  if (data.all_filters_equal) {
1077  data.all_filters_equal = (*data.last_backdrop == *shared_backdrop);
1078  data.last_backdrop = shared_backdrop;
1079  }
1080  }
1081  }
1082 
1083  // This dispatcher does not track enough state to accurately compute
1084  // cull rects with image filters.
1085  auto global_cull_rect = cull_rect_state_.back();
1086  if (has_image_filter_ || global_cull_rect.IsMaximum()) {
1087  cull_rect_state_.back() = Rect::MakeMaximum();
1088  } else {
1089  auto global_save_bounds = bounds.TransformBounds(matrix_);
1090  auto new_cull_rect = global_cull_rect.Intersection(global_save_bounds);
1091  if (new_cull_rect.has_value()) {
1092  cull_rect_state_.back() = new_cull_rect.value();
1093  } else {
1094  cull_rect_state_.back() = Rect::MakeLTRB(0, 0, 0, 0);
1095  }
1096  }
1097 }
constexpr static TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
Definition: rect.h:129
constexpr static TRect MakeMaximum()
Definition: rect.h:188
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:67

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

◆ scale()

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

Definition at line 1109 of file dl_dispatcher.cc.

1109  {
1110  matrix_ = matrix_.Scale({sx, sy, 1.0f});
1111 }
constexpr Matrix Scale(const Vector3 &s) const
Definition: matrix.h:275

References impeller::Matrix::Scale().

Referenced by drawTextFrame().

◆ setColor()

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

Definition at line 1231 of file dl_dispatcher.cc.

1231  {
1232  paint_.color = skia_conversions::ToColor(color);
1233 }
Color ToColor(const flutter::DlColor &color)

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

◆ setDrawStyle()

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

Definition at line 1226 of file dl_dispatcher.cc.

1226  {
1227  paint_.style = ToStyle(style);
1228 }
static Paint::Style ToStyle(flutter::DlDrawStyle style)

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

◆ setImageFilter()

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

Definition at line 1276 of file dl_dispatcher.cc.

1276  {
1277  if (filter == nullptr) {
1278  has_image_filter_ = false;
1279  } else {
1280  has_image_filter_ = true;
1281  }
1282 }

◆ setStrokeCap()

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

Definition at line 1246 of file dl_dispatcher.cc.

1246  {
1247  switch (cap) {
1248  case flutter::DlStrokeCap::kButt:
1249  paint_.stroke_cap = Cap::kButt;
1250  break;
1251  case flutter::DlStrokeCap::kRound:
1252  paint_.stroke_cap = Cap::kRound;
1253  break;
1254  case flutter::DlStrokeCap::kSquare:
1255  paint_.stroke_cap = Cap::kSquare;
1256  break;
1257  }
1258 }

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

◆ setStrokeJoin()

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

Definition at line 1261 of file dl_dispatcher.cc.

1261  {
1262  switch (join) {
1263  case flutter::DlStrokeJoin::kMiter:
1264  paint_.stroke_join = Join::kMiter;
1265  break;
1266  case flutter::DlStrokeJoin::kRound:
1267  paint_.stroke_join = Join::kRound;
1268  break;
1269  case flutter::DlStrokeJoin::kBevel:
1270  paint_.stroke_join = Join::kBevel;
1271  break;
1272  }
1273 }

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

◆ setStrokeMiter()

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

Definition at line 1241 of file dl_dispatcher.cc.

1241  {
1242  paint_.stroke_miter = limit;
1243 }

References impeller::Paint::stroke_miter.

◆ setStrokeWidth()

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

Definition at line 1236 of file dl_dispatcher.cc.

1236  {
1237  paint_.stroke_width = width;
1238 }

References impeller::Paint::stroke_width.

◆ skew()

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

Definition at line 1117 of file dl_dispatcher.cc.

1117  {
1118  matrix_ = matrix_ * Matrix::MakeSkew(sx, sy);
1119 }
static constexpr Matrix MakeSkew(Scalar sx, Scalar sy)
Definition: matrix.h:127

References impeller::Matrix::MakeSkew().

◆ TakeBackdropData()

std::pair< std::unordered_map< int64_t, BackdropData >, size_t > impeller::FirstPassDispatcher::TakeBackdropData ( )

Definition at line 1285 of file dl_dispatcher.cc.

1285  {
1286  std::unordered_map<int64_t, BackdropData> temp;
1287  std::swap(temp, backdrop_data_);
1288  return std::make_pair(temp, backdrop_count_);
1289 }

Referenced by impeller::DisplayListToTexture(), and impeller::RenderToTarget().

◆ transform2DAffine()

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

Definition at line 1123 of file dl_dispatcher.cc.

1124  {
1125  matrix_ = matrix_ * Matrix::MakeColumn(
1126  mxx, myx, 0.0f, 0.0f,
1127  mxy, myy, 0.0f, 0.0f,
1128  0.0f, 0.0f, 1.0f, 0.0f,
1129  mxt, myt, 0.0f, 1.0f
1130  );
1131  }
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

References impeller::Matrix::MakeColumn().

◆ transformFullPerspective()

void impeller::FirstPassDispatcher::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 1134 of file dl_dispatcher.cc.

1138  {
1139  matrix_ = matrix_ * Matrix::MakeColumn(
1140  mxx, myx, mzx, mwx,
1141  mxy, myy, mzy, mwy,
1142  mxz, myz, mzz, mwz,
1143  mxt, myt, mzt, mwt
1144  );
1145  }

References impeller::Matrix::MakeColumn().

◆ transformReset()

void impeller::FirstPassDispatcher::transformReset ( )
override

Definition at line 1148 of file dl_dispatcher.cc.

1148  {
1149  matrix_ = Matrix();
1150 }

◆ translate()

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

Definition at line 1105 of file dl_dispatcher.cc.

1105  {
1106  matrix_ = matrix_.Translate({tx, ty});
1107 }
constexpr Matrix Translate(const Vector3 &t) const
Definition: matrix.h:263

References impeller::Matrix::Translate().


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