Flutter Impeller
impeller::Canvas Class Reference

#include <canvas.h>

Classes

struct  SaveLayerState
 

Public Types

using BackdropFilterProc = std::function< std::shared_ptr< FilterContents >(FilterInput::Ref, const Matrix &effect_transform, Entity::RenderingMode rendering_mode)>
 

Public Member Functions

 Canvas (ContentContext &renderer, const RenderTarget &render_target, bool is_onscreen, bool requires_readback)
 
 Canvas (ContentContext &renderer, const RenderTarget &render_target, bool is_onscreen, bool requires_readback, Rect cull_rect)
 
 Canvas (ContentContext &renderer, const RenderTarget &render_target, bool is_onscreen, bool requires_readback, IRect cull_rect)
 
 ~Canvas ()=default
 
void SetBackdropData (std::unordered_map< int64_t, BackdropData > backdrop_data, size_t backdrop_count)
 Update the backdrop data used to group together backdrop filters within the same layer. More...
 
std::optional< RectGetLocalCoverageLimit () const
 Return the culling bounds of the current render target, or nullopt if there is no coverage. More...
 
void Save (uint32_t total_content_depth=kMaxDepth)
 
void SaveLayer (const Paint &paint, std::optional< Rect > bounds=std::nullopt, const flutter::DlImageFilter *backdrop_filter=nullptr, ContentBoundsPromise bounds_promise=ContentBoundsPromise::kUnknown, uint32_t total_content_depth=kMaxDepth, bool can_distribute_opacity=false, std::optional< int64_t > backdrop_id=std::nullopt)
 
bool Restore ()
 
size_t GetSaveCount () const
 
void RestoreToCount (size_t count)
 
const MatrixGetCurrentTransform () const
 
void ResetTransform ()
 
void Transform (const Matrix &transform)
 
void Concat (const Matrix &transform)
 
void PreConcat (const Matrix &transform)
 
void Translate (const Vector3 &offset)
 
void Scale (const Vector2 &scale)
 
void Scale (const Vector3 &scale)
 
void Skew (Scalar sx, Scalar sy)
 
void Rotate (Radians radians)
 
void DrawPath (const flutter::DlPath &path, const Paint &paint)
 
void DrawPaint (const Paint &paint)
 
void DrawLine (const Point &p0, const Point &p1, const Paint &paint, bool reuse_depth=false)
 
void DrawDashedLine (const Point &p0, const Point &p1, Scalar on_length, Scalar off_length, const Paint &paint)
 
void DrawRect (const Rect &rect, const Paint &paint)
 
void DrawOval (const Rect &rect, const Paint &paint)
 
void DrawArc (const Arc &arc, const Paint &paint)
 
void DrawRoundRect (const RoundRect &rect, const Paint &paint)
 
void DrawDiffRoundRect (const RoundRect &outer, const RoundRect &inner, const Paint &paint)
 
void DrawRoundSuperellipse (const RoundSuperellipse &rse, const Paint &paint)
 
void DrawCircle (const Point &center, Scalar radius, const Paint &paint)
 
void DrawPoints (const Point points[], uint32_t count, Scalar radius, const Paint &paint, PointStyle point_style)
 
void DrawImage (const std::shared_ptr< Texture > &image, Point offset, const Paint &paint, const SamplerDescriptor &sampler={})
 
void DrawImageRect (const std::shared_ptr< Texture > &image, Rect source, Rect dest, const Paint &paint, const SamplerDescriptor &sampler={}, SourceRectConstraint src_rect_constraint=SourceRectConstraint::kFast)
 
void DrawTextFrame (const std::shared_ptr< TextFrame > &text_frame, Point position, const Paint &paint)
 
void DrawVertices (const std::shared_ptr< VerticesGeometry > &vertices, BlendMode blend_mode, const Paint &paint)
 
void DrawAtlas (const std::shared_ptr< AtlasContents > &atlas_contents, const Paint &paint)
 
void ClipGeometry (const Geometry &geometry, Entity::ClipOperation clip_op, bool is_aa=true)
 
void EndReplay ()
 
uint64_t GetOpDepth () const
 
uint64_t GetMaxOpDepth () const
 
bool RequiresReadback () const
 
bool SupportsBlitToOnscreen () const
 
bool EnsureFinalMipmapGeneration () const
 

Static Public Attributes

static constexpr uint32_t kMaxDepth = 1 << 24
 

Detailed Description

Definition at line 120 of file canvas.h.

Member Typedef Documentation

◆ BackdropFilterProc

using impeller::Canvas::BackdropFilterProc = std::function<std::shared_ptr<FilterContents>( FilterInput::Ref, const Matrix& effect_transform, Entity::RenderingMode rendering_mode)>

Definition at line 124 of file canvas.h.

Constructor & Destructor Documentation

◆ Canvas() [1/3]

impeller::Canvas::Canvas ( ContentContext renderer,
const RenderTarget render_target,
bool  is_onscreen,
bool  requires_readback 
)

Definition at line 197 of file canvas.cc.

201  : renderer_(renderer),
202  render_target_(render_target),
203  is_onscreen_(is_onscreen),
204  requires_readback_(requires_readback),
205  clip_coverage_stack_(EntityPassClipStack(
206  Rect::MakeSize(render_target.GetRenderTargetSize()))) {
207  Initialize(std::nullopt);
208  SetupRenderPass();
209 }
constexpr static TRect MakeSize(const TSize< U > &size)
Definition: rect.h:150

◆ Canvas() [2/3]

impeller::Canvas::Canvas ( ContentContext renderer,
const RenderTarget render_target,
bool  is_onscreen,
bool  requires_readback,
Rect  cull_rect 
)
explicit

Definition at line 211 of file canvas.cc.

216  : renderer_(renderer),
217  render_target_(render_target),
218  is_onscreen_(is_onscreen),
219  requires_readback_(requires_readback),
220  clip_coverage_stack_(EntityPassClipStack(
221  Rect::MakeSize(render_target.GetRenderTargetSize()))) {
222  Initialize(cull_rect);
223  SetupRenderPass();
224 }

◆ Canvas() [3/3]

impeller::Canvas::Canvas ( ContentContext renderer,
const RenderTarget render_target,
bool  is_onscreen,
bool  requires_readback,
IRect  cull_rect 
)
explicit

Definition at line 226 of file canvas.cc.

231  : renderer_(renderer),
232  render_target_(render_target),
233  is_onscreen_(is_onscreen),
234  requires_readback_(requires_readback),
235  clip_coverage_stack_(EntityPassClipStack(
236  Rect::MakeSize(render_target.GetRenderTargetSize()))) {
237  Initialize(Rect::MakeLTRB(cull_rect.GetLeft(), cull_rect.GetTop(),
238  cull_rect.GetRight(), cull_rect.GetBottom()));
239  SetupRenderPass();
240 }
constexpr static TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
Definition: rect.h:129

References impeller::TRect< T >::GetBottom(), impeller::TRect< T >::GetLeft(), impeller::TRect< T >::GetRight(), impeller::TRect< T >::GetTop(), and impeller::TRect< Scalar >::MakeLTRB().

◆ ~Canvas()

impeller::Canvas::~Canvas ( )
default

Member Function Documentation

◆ ClipGeometry()

void impeller::Canvas::ClipGeometry ( const Geometry geometry,
Entity::ClipOperation  clip_op,
bool  is_aa = true 
)

Definition at line 826 of file canvas.cc.

828  {
829  if (IsSkipping()) {
830  return;
831  }
832 
833  // Ideally the clip depth would be greater than the current rendering
834  // depth because any rendering calls that follow this clip operation will
835  // pre-increment the depth and then be rendering above our clip depth,
836  // but that case will be caught by the CHECK in AddRenderEntity above.
837  // In practice we sometimes have a clip set with no rendering after it
838  // and in such cases the current depth will equal the clip depth.
839  // Eventually the DisplayList should optimize these out, but it is hard
840  // to know if a clip will actually be used in advance of storing it in
841  // the DisplayList buffer.
842  // See https://github.com/flutter/flutter/issues/147021
843  FML_DCHECK(current_depth_ <= transform_stack_.back().clip_depth)
844  << current_depth_ << " <=? " << transform_stack_.back().clip_depth;
845  uint32_t clip_depth = transform_stack_.back().clip_depth;
846 
847  const Matrix clip_transform =
848  Matrix::MakeTranslation(Vector3(-GetGlobalPassPosition())) *
850 
851  std::optional<Rect> clip_coverage = geometry.GetCoverage(clip_transform);
852  if (!clip_coverage.has_value()) {
853  return;
854  }
855 
856  ClipContents clip_contents(
857  clip_coverage.value(),
858  /*is_axis_aligned_rect=*/geometry.IsAxisAlignedRect() &&
859  GetCurrentTransform().IsTranslationScaleOnly());
860  clip_contents.SetClipOperation(clip_op);
861 
862  EntityPassClipStack::ClipStateResult clip_state_result =
863  clip_coverage_stack_.RecordClip(
864  clip_contents, //
865  /*transform=*/clip_transform, //
866  /*global_pass_position=*/GetGlobalPassPosition(), //
867  /*clip_depth=*/clip_depth, //
868  /*clip_height_floor=*/GetClipHeightFloor(), //
869  /*is_aa=*/is_aa);
870 
871  if (clip_state_result.clip_did_change) {
872  // We only need to update the pass scissor if the clip state has changed.
873  SetClipScissor(clip_coverage_stack_.CurrentClipCoverage(),
874  *render_passes_.back().inline_pass_context->GetRenderPass(),
875  GetGlobalPassPosition());
876  }
877 
878  ++transform_stack_.back().clip_height;
879  ++transform_stack_.back().num_clips;
880 
881  if (!clip_state_result.should_render) {
882  return;
883  }
884 
885  // Note: this is a bit of a hack. Its not possible to construct a geometry
886  // result without begninning the render pass. We should refactor the geometry
887  // objects so that they only need a reference to the render pass size and/or
888  // orthographic transform.
889  Entity entity;
890  entity.SetTransform(clip_transform);
891  entity.SetClipDepth(clip_depth);
892 
893  GeometryResult geometry_result = geometry.GetPositionBuffer(
894  renderer_, //
895  entity, //
896  *render_passes_.back().inline_pass_context->GetRenderPass() //
897  );
898  clip_contents.SetGeometry(geometry_result);
899  clip_coverage_stack_.GetLastReplayResult().clip_contents.SetGeometry(
900  geometry_result);
901 
902  clip_contents.Render(
903  renderer_, *render_passes_.back().inline_pass_context->GetRenderPass(),
904  clip_depth);
905 }
const Matrix & GetCurrentTransform() const
Definition: canvas.cc:271
void SetGeometry(GeometryResult geometry)
Set the pre-tessellated clip geometry.
std::optional< Rect > CurrentClipCoverage() const
ClipStateResult RecordClip(const ClipContents &clip_contents, Matrix transform, Point global_pass_position, uint32_t clip_depth, size_t clip_height_floor, bool is_aa)
static constexpr Matrix MakeTranslation(const Vector3 &t)
Definition: matrix.h:95

References impeller::EntityPassClipStack::ReplayResult::clip_contents, impeller::EntityPassClipStack::ClipStateResult::clip_did_change, impeller::EntityPassClipStack::CurrentClipCoverage(), impeller::Geometry::GetCoverage(), GetCurrentTransform(), impeller::EntityPassClipStack::GetLastReplayResult(), impeller::Geometry::GetPositionBuffer(), impeller::Geometry::IsAxisAlignedRect(), impeller::Matrix::MakeTranslation(), impeller::EntityPassClipStack::RecordClip(), impeller::ClipContents::Render(), impeller::Entity::SetClipDepth(), impeller::ClipContents::SetClipOperation(), impeller::ClipContents::SetGeometry(), impeller::Entity::SetTransform(), and impeller::EntityPassClipStack::ClipStateResult::should_render.

Referenced by impeller::DlDispatcherBase::clipOval(), impeller::DlDispatcherBase::clipPath(), impeller::DlDispatcherBase::clipRect(), impeller::DlDispatcherBase::clipRoundRect(), and impeller::DlDispatcherBase::clipRoundSuperellipse().

◆ Concat()

void impeller::Canvas::Concat ( const Matrix transform)

Definition at line 255 of file canvas.cc.

255  {
256  transform_stack_.back().transform = GetCurrentTransform() * transform;
257 }

References GetCurrentTransform(), and transform.

Referenced by DrawTextFrame(), Rotate(), Scale(), Skew(), Transform(), and Translate().

◆ DrawArc()

void impeller::Canvas::DrawArc ( const Arc arc,
const Paint paint 
)

Definition at line 678 of file canvas.cc.

678  {
679  Entity entity;
680  entity.SetTransform(GetCurrentTransform());
681  entity.SetBlendMode(paint.blend_mode);
682 
683  if (paint.style == Paint::Style::kFill) {
684  ArcGeometry geom(arc);
685  AddRenderEntityWithFiltersToCurrentPass(entity, &geom, paint);
686  return;
687  }
688 
689  const Rect& oval_bounds = arc.GetOvalBounds();
690  if (paint.stroke.width > oval_bounds.GetSize().MaxDimension()) {
691  // This is a special case for rendering arcs whose stroke width is so large
692  // you are effectively drawing a sector of a circle.
693  // https://github.com/flutter/flutter/issues/158567
694  Arc expanded_arc(oval_bounds.Expand(Size(paint.stroke.width * 0.5f)),
695  arc.GetStart(), arc.GetSweep(), true);
696 
697  ArcGeometry geom(expanded_arc);
698  AddRenderEntityWithFiltersToCurrentPass(entity, &geom, paint);
699  return;
700  }
701 
702  // IncludeCenter incurs lots of extra work for stroking an arc, including:
703  // - It introduces segments to/from the center point (not too hard).
704  // - It introduces joins on those segments (a bit more complicated).
705  // - Even if the sweep is >=360 degrees, we still draw the segment to
706  // the center and it basically looks like a pie cut into the complete
707  // boundary circle, as if the slice were cut, but not extracted
708  // (hard to express as a continuous kTriangleStrip).
709  if (!arc.IncludeCenter()) {
710  if (arc.IsFullCircle()) {
711  return DrawOval(oval_bounds, paint);
712  }
713 
714  // Our fast stroking code only works for circular bounds as it assumes
715  // that the inner and outer radii can be scaled along each angular step
716  // of the arc - which is not true for elliptical arcs where the inner
717  // and outer samples are perpendicular to the traveling direction of the
718  // elliptical curve which may not line up with the center of the bounds.
719  //
720  // TODO(flar): It also only supports Butt and Square caps for now.
721  // See https://github.com/flutter/flutter/issues/169400
722  if (oval_bounds.IsSquare() && paint.stroke.cap != Cap::kRound) {
723  ArcGeometry geom(arc, paint.stroke);
724  AddRenderEntityWithFiltersToCurrentPass(entity, &geom, paint);
725  return;
726  }
727  }
728 
729  ArcStrokeGeometry geom(arc, paint.stroke);
730  AddRenderEntityWithFiltersToCurrentPass(entity, &geom, paint);
731 }
void DrawOval(const Rect &rect, const Paint &paint)
Definition: canvas.cc:649
TRect< Scalar > Rect
Definition: rect.h:792
TSize< Scalar > Size
Definition: size.h:159

References impeller::Paint::blend_mode, impeller::StrokeParameters::cap, DrawOval(), impeller::TRect< T >::Expand(), GetCurrentTransform(), impeller::Arc::GetOvalBounds(), impeller::TRect< T >::GetSize(), impeller::Arc::GetStart(), impeller::Arc::GetSweep(), impeller::Arc::IncludeCenter(), impeller::Arc::IsFullCircle(), impeller::TRect< T >::IsSquare(), impeller::Paint::kFill, impeller::kRound, impeller::Entity::SetBlendMode(), impeller::Entity::SetTransform(), impeller::Paint::stroke, impeller::Paint::style, and impeller::StrokeParameters::width.

Referenced by impeller::DlDispatcherBase::drawArc().

◆ DrawAtlas()

void impeller::Canvas::DrawAtlas ( const std::shared_ptr< AtlasContents > &  atlas_contents,
const Paint paint 
)

Definition at line 1117 of file canvas.cc.

1118  {
1119  atlas_contents->SetAlpha(paint.color.alpha);
1120 
1121  Entity entity;
1122  entity.SetTransform(GetCurrentTransform());
1123  entity.SetBlendMode(paint.blend_mode);
1124  entity.SetContents(paint.WithFilters(atlas_contents));
1125 
1126  AddRenderEntityToCurrentPass(entity);
1127 }

References impeller::Color::alpha, impeller::Paint::blend_mode, impeller::Paint::color, GetCurrentTransform(), impeller::Entity::SetBlendMode(), impeller::Entity::SetContents(), impeller::Entity::SetTransform(), and impeller::Paint::WithFilters().

Referenced by impeller::DlDispatcherBase::drawAtlas().

◆ DrawCircle()

void impeller::Canvas::DrawCircle ( const Point center,
Scalar  radius,
const Paint paint 
)

Definition at line 803 of file canvas.cc.

805  {
806  Size half_size(radius, radius);
807  if (AttemptDrawBlurredRRect(
808  Rect::MakeOriginSize(center - half_size, half_size * 2),
809  {radius, radius}, paint)) {
810  return;
811  }
812 
813  Entity entity;
814  entity.SetTransform(GetCurrentTransform());
815  entity.SetBlendMode(paint.blend_mode);
816 
817  if (paint.style == Paint::Style::kStroke) {
818  CircleGeometry geom(center, radius, paint.stroke.width);
819  AddRenderEntityWithFiltersToCurrentPass(entity, &geom, paint);
820  } else {
821  CircleGeometry geom(center, radius);
822  AddRenderEntityWithFiltersToCurrentPass(entity, &geom, paint);
823  }
824 }
constexpr static TRect MakeOriginSize(const TPoint< Type > &origin, const TSize< Type > &size)
Definition: rect.h:144

References impeller::Paint::blend_mode, GetCurrentTransform(), impeller::Paint::kStroke, impeller::TRect< Scalar >::MakeOriginSize(), impeller::Entity::SetBlendMode(), impeller::Entity::SetTransform(), impeller::Paint::stroke, impeller::Paint::style, and impeller::StrokeParameters::width.

Referenced by impeller::DlDispatcherBase::drawCircle(), and DrawOval().

◆ DrawDashedLine()

void impeller::Canvas::DrawDashedLine ( const Point p0,
const Point p1,
Scalar  on_length,
Scalar  off_length,
const Paint paint 
)

Definition at line 605 of file canvas.cc.

609  {
610  // Reasons to defer to regular DrawLine:
611  // - performance for degenerate and "regular line" cases
612  // - length is non-positive - DrawLine will draw appropriate "dot"
613  // - off_length is non-positive - no gaps, DrawLine will draw it solid
614  // - on_length is negative - invalid dashing
615  //
616  // Note that a 0 length "on" dash will draw "dot"s every "off" distance
617  // apart so we proceed with the dashing process in that case.
618  Scalar length = p0.GetDistance(p1);
619  if (length > 0.0f && on_length >= 0.0f && off_length > 0.0f) {
620  Entity entity;
621  entity.SetTransform(GetCurrentTransform());
622  entity.SetBlendMode(paint.blend_mode);
623 
624  StrokeDashedLineGeometry geom(p0, p1, on_length, off_length, paint.stroke);
625  AddRenderEntityWithFiltersToCurrentPass(entity, &geom, paint);
626  } else {
627  DrawLine(p0, p1, paint);
628  }
629 }
void DrawLine(const Point &p0, const Point &p1, const Paint &paint, bool reuse_depth=false)
Definition: canvas.cc:583
float Scalar
Definition: scalar.h:19

References impeller::Paint::blend_mode, DrawLine(), GetCurrentTransform(), impeller::TPoint< T >::GetDistance(), impeller::Entity::SetBlendMode(), impeller::Entity::SetTransform(), and impeller::Paint::stroke.

Referenced by impeller::DlDispatcherBase::drawDashedLine().

◆ DrawDiffRoundRect()

void impeller::Canvas::DrawDiffRoundRect ( const RoundRect outer,
const RoundRect inner,
const Paint paint 
)

Definition at line 765 of file canvas.cc.

767  {
768  Entity entity;
769  entity.SetTransform(GetCurrentTransform());
770  entity.SetBlendMode(paint.blend_mode);
771 
772  if (paint.style == Paint::Style::kFill) {
773  FillDiffRoundRectGeometry geom(outer, inner);
774  AddRenderEntityWithFiltersToCurrentPass(entity, &geom, paint);
775  } else {
776  StrokeDiffRoundRectGeometry geom(outer, inner, paint.stroke);
777  AddRenderEntityWithFiltersToCurrentPass(entity, &geom, paint);
778  }
779 }

References impeller::Paint::blend_mode, GetCurrentTransform(), impeller::Paint::kFill, impeller::Entity::SetBlendMode(), impeller::Entity::SetTransform(), impeller::Paint::stroke, and impeller::Paint::style.

Referenced by impeller::DlDispatcherBase::drawDiffRoundRect().

◆ DrawImage()

void impeller::Canvas::DrawImage ( const std::shared_ptr< Texture > &  image,
Point  offset,
const Paint paint,
const SamplerDescriptor sampler = {} 
)

Definition at line 925 of file canvas.cc.

928  {
929  if (!image) {
930  return;
931  }
932 
933  const Rect source = Rect::MakeSize(image->GetSize());
934  const Rect dest = source.Shift(offset);
935 
936  DrawImageRect(image, source, dest, paint, sampler);
937 }
void DrawImageRect(const std::shared_ptr< Texture > &image, Rect source, Rect dest, const Paint &paint, const SamplerDescriptor &sampler={}, SourceRectConstraint src_rect_constraint=SourceRectConstraint::kFast)
Definition: canvas.cc:939
constexpr TRect< T > Shift(T dx, T dy) const
Returns a new rectangle translated by the given offset.
Definition: rect.h:606

References DrawImageRect(), impeller::TRect< Scalar >::MakeSize(), and impeller::TRect< T >::Shift().

◆ DrawImageRect()

void impeller::Canvas::DrawImageRect ( const std::shared_ptr< Texture > &  image,
Rect  source,
Rect  dest,
const Paint paint,
const SamplerDescriptor sampler = {},
SourceRectConstraint  src_rect_constraint = SourceRectConstraint::kFast 
)

Definition at line 939 of file canvas.cc.

944  {
945  if (!image || source.IsEmpty() || dest.IsEmpty()) {
946  return;
947  }
948 
949  ISize size = image->GetSize();
950  if (size.IsEmpty()) {
951  return;
952  }
953 
954  std::optional<Rect> clipped_source =
955  source.Intersection(Rect::MakeSize(size));
956  if (!clipped_source) {
957  return;
958  }
959 
960  if (AttemptColorFilterOptimization(image, source, dest, paint, sampler,
961  src_rect_constraint)) {
962  return;
963  }
964 
965  if (*clipped_source != source) {
966  Scalar sx = dest.GetWidth() / source.GetWidth();
967  Scalar sy = dest.GetHeight() / source.GetHeight();
968  Scalar tx = dest.GetLeft() - source.GetLeft() * sx;
969  Scalar ty = dest.GetTop() - source.GetTop() * sy;
970  Matrix src_to_dest = Matrix::MakeTranslateScale({sx, sy, 1}, {tx, ty, 0});
971  dest = clipped_source->TransformBounds(src_to_dest);
972  }
973 
974  auto texture_contents = TextureContents::MakeRect(dest);
975  texture_contents->SetTexture(image);
976  texture_contents->SetSourceRect(*clipped_source);
977  texture_contents->SetStrictSourceRect(src_rect_constraint ==
979  texture_contents->SetSamplerDescriptor(sampler);
980  texture_contents->SetOpacity(paint.color.alpha);
981  texture_contents->SetDeferApplyingOpacity(paint.HasColorFilter());
982 
983  Entity entity;
984  entity.SetBlendMode(paint.blend_mode);
985  entity.SetTransform(GetCurrentTransform());
986 
987  if (!paint.mask_blur_descriptor.has_value()) {
988  entity.SetContents(paint.WithFilters(std::move(texture_contents)));
989  AddRenderEntityToCurrentPass(entity);
990  return;
991  }
992 
993  FillRectGeometry out_rect(Rect{});
994 
995  entity.SetContents(paint.WithFilters(
996  paint.mask_blur_descriptor->CreateMaskBlur(texture_contents, &out_rect)));
997  AddRenderEntityToCurrentPass(entity);
998 }
static std::shared_ptr< TextureContents > MakeRect(Rect destination)
@ kStrict
Sample only within the source rectangle. May be slower.
ISize64 ISize
Definition: size.h:162
static constexpr Matrix MakeTranslateScale(const Vector3 &s, const Vector3 &t)
Definition: matrix.h:113

References impeller::Color::alpha, impeller::Paint::blend_mode, impeller::Paint::color, GetCurrentTransform(), impeller::TRect< T >::GetHeight(), impeller::TRect< T >::GetLeft(), impeller::TRect< T >::GetTop(), impeller::TRect< T >::GetWidth(), impeller::Paint::HasColorFilter(), impeller::TRect< T >::Intersection(), impeller::TRect< T >::IsEmpty(), impeller::TSize< T >::IsEmpty(), impeller::kStrict, impeller::TextureContents::MakeRect(), impeller::TRect< Scalar >::MakeSize(), impeller::Matrix::MakeTranslateScale(), impeller::Paint::mask_blur_descriptor, impeller::Entity::SetBlendMode(), impeller::Entity::SetContents(), impeller::Entity::SetTransform(), impeller::TRect< T >::TransformBounds(), and impeller::Paint::WithFilters().

Referenced by DrawImage(), impeller::DlDispatcherBase::drawImageRect(), and impeller::NinePatchConverter::DrawNinePatch().

◆ DrawLine()

void impeller::Canvas::DrawLine ( const Point p0,
const Point p1,
const Paint paint,
bool  reuse_depth = false 
)

Definition at line 583 of file canvas.cc.

586  {
587  Entity entity;
588  entity.SetTransform(GetCurrentTransform());
589  entity.SetBlendMode(paint.blend_mode);
590 
591  auto geometry = std::make_unique<LineGeometry>(p0, p1, paint.stroke);
592 
593  if (renderer_.GetContext()->GetFlags().antialiased_lines &&
594  !paint.color_filter && !paint.invert_colors && !paint.image_filter &&
595  !paint.mask_blur_descriptor.has_value() && !paint.color_source) {
596  auto contents = LineContents::Make(std::move(geometry), paint.color);
597  entity.SetContents(std::move(contents));
598  AddRenderEntityToCurrentPass(entity, reuse_depth);
599  } else {
600  AddRenderEntityWithFiltersToCurrentPass(entity, geometry.get(), paint,
601  /*reuse_depth=*/reuse_depth);
602  }
603 }
std::shared_ptr< Context > GetContext() const
static std::unique_ptr< LineContents > Make(std::unique_ptr< LineGeometry > geometry, Color color)

References impeller::Paint::blend_mode, impeller::Paint::color, impeller::Paint::color_filter, impeller::Paint::color_source, impeller::ContentContext::GetContext(), GetCurrentTransform(), impeller::Paint::image_filter, impeller::Paint::invert_colors, impeller::LineContents::Make(), impeller::Paint::mask_blur_descriptor, impeller::Entity::SetBlendMode(), impeller::Entity::SetContents(), impeller::Entity::SetTransform(), and impeller::Paint::stroke.

Referenced by DrawDashedLine(), impeller::DlDispatcherBase::drawLine(), impeller::DlDispatcherBase::drawPoints(), and impeller::DlDispatcherBase::SimplifyOrDrawPath().

◆ DrawOval()

void impeller::Canvas::DrawOval ( const Rect rect,
const Paint paint 
)

Definition at line 649 of file canvas.cc.

649  {
650  // TODO(jonahwilliams): This additional condition avoids an assert in the
651  // stroke circle geometry generator. I need to verify the condition that this
652  // assert prevents.
653  if (rect.IsSquare() && (paint.style == Paint::Style::kFill ||
654  (paint.style == Paint::Style::kStroke &&
655  paint.stroke.width < rect.GetWidth()))) {
656  // Circles have slightly less overhead and can do stroking
657  DrawCircle(rect.GetCenter(), rect.GetWidth() * 0.5f, paint);
658  return;
659  }
660 
661  if (AttemptDrawBlurredRRect(rect, rect.GetSize() * 0.5f, paint)) {
662  return;
663  }
664 
665  Entity entity;
666  entity.SetTransform(GetCurrentTransform());
667  entity.SetBlendMode(paint.blend_mode);
668 
669  if (paint.style == Paint::Style::kStroke) {
670  StrokeEllipseGeometry geom(rect, paint.stroke);
671  AddRenderEntityWithFiltersToCurrentPass(entity, &geom, paint);
672  } else {
673  EllipseGeometry geom(rect);
674  AddRenderEntityWithFiltersToCurrentPass(entity, &geom, paint);
675  }
676 }
void DrawCircle(const Point &center, Scalar radius, const Paint &paint)
Definition: canvas.cc:803

References impeller::Paint::blend_mode, DrawCircle(), impeller::TRect< T >::GetCenter(), GetCurrentTransform(), impeller::TRect< T >::GetSize(), impeller::TRect< T >::GetWidth(), impeller::TRect< T >::IsSquare(), impeller::Paint::kFill, impeller::Paint::kStroke, impeller::Entity::SetBlendMode(), impeller::Entity::SetTransform(), impeller::Paint::stroke, impeller::Paint::style, and impeller::StrokeParameters::width.

Referenced by DrawArc(), impeller::DlDispatcherBase::drawOval(), and impeller::DlDispatcherBase::SimplifyOrDrawPath().

◆ DrawPaint()

void impeller::Canvas::DrawPaint ( const Paint paint)

Definition at line 340 of file canvas.cc.

340  {
341  Entity entity;
342  entity.SetTransform(GetCurrentTransform());
343  entity.SetBlendMode(paint.blend_mode);
344 
345  CoverGeometry geom;
346  AddRenderEntityWithFiltersToCurrentPass(entity, &geom, paint);
347 }

References impeller::Paint::blend_mode, GetCurrentTransform(), impeller::Entity::SetBlendMode(), and impeller::Entity::SetTransform().

Referenced by impeller::DlDispatcherBase::drawColor(), and impeller::DlDispatcherBase::drawPaint().

◆ DrawPath()

void impeller::Canvas::DrawPath ( const flutter::DlPath &  path,
const Paint paint 
)

Definition at line 326 of file canvas.cc.

326  {
327  Entity entity;
328  entity.SetTransform(GetCurrentTransform());
329  entity.SetBlendMode(paint.blend_mode);
330 
331  if (paint.style == Paint::Style::kFill) {
332  FillPathGeometry geom(path);
333  AddRenderEntityWithFiltersToCurrentPass(entity, &geom, paint);
334  } else {
335  StrokePathGeometry geom(path, paint.stroke);
336  AddRenderEntityWithFiltersToCurrentPass(entity, &geom, paint);
337  }
338 }

References impeller::Paint::blend_mode, GetCurrentTransform(), impeller::Paint::kFill, impeller::Entity::SetBlendMode(), impeller::Entity::SetTransform(), impeller::Paint::stroke, and impeller::Paint::style.

Referenced by DrawTextFrame(), and impeller::DlDispatcherBase::SimplifyOrDrawPath().

◆ DrawPoints()

void impeller::Canvas::DrawPoints ( const Point  points[],
uint32_t  count,
Scalar  radius,
const Paint paint,
PointStyle  point_style 
)

Definition at line 907 of file canvas.cc.

911  {
912  if (radius <= 0) {
913  return;
914  }
915 
916  Entity entity;
917  entity.SetTransform(GetCurrentTransform());
918  entity.SetBlendMode(paint.blend_mode);
919 
920  PointFieldGeometry geom(points, count, radius,
921  /*round=*/point_style == PointStyle::kRound);
922  AddRenderEntityWithFiltersToCurrentPass(entity, &geom, paint);
923 }
@ kRound
Points are drawn as squares.
std::vector< Point > points

References impeller::Paint::blend_mode, GetCurrentTransform(), impeller::kRound, points, impeller::Entity::SetBlendMode(), and impeller::Entity::SetTransform().

Referenced by impeller::DlDispatcherBase::drawPoints().

◆ DrawRect()

void impeller::Canvas::DrawRect ( const Rect rect,
const Paint paint 
)

Definition at line 631 of file canvas.cc.

631  {
632  if (AttemptDrawBlurredRRect(rect, {}, paint)) {
633  return;
634  }
635 
636  Entity entity;
637  entity.SetTransform(GetCurrentTransform());
638  entity.SetBlendMode(paint.blend_mode);
639 
640  if (paint.style == Paint::Style::kStroke) {
641  StrokeRectGeometry geom(rect, paint.stroke);
642  AddRenderEntityWithFiltersToCurrentPass(entity, &geom, paint);
643  } else {
644  FillRectGeometry geom(rect);
645  AddRenderEntityWithFiltersToCurrentPass(entity, &geom, paint);
646  }
647 }

References impeller::Paint::blend_mode, GetCurrentTransform(), impeller::Paint::kStroke, impeller::Entity::SetBlendMode(), impeller::Entity::SetTransform(), impeller::Paint::stroke, and impeller::Paint::style.

Referenced by impeller::DlDispatcherBase::drawRect(), and impeller::DlDispatcherBase::SimplifyOrDrawPath().

◆ DrawRoundRect()

void impeller::Canvas::DrawRoundRect ( const RoundRect rect,
const Paint paint 
)

Definition at line 733 of file canvas.cc.

733  {
734  auto& rect = round_rect.GetBounds();
735  auto& radii = round_rect.GetRadii();
736  if (radii.AreAllCornersSame()) {
737  if (AttemptDrawBlurredRRect(rect, radii.top_left, paint)) {
738  return;
739  }
740 
741  if (paint.style == Paint::Style::kFill) {
742  Entity entity;
743  entity.SetTransform(GetCurrentTransform());
744  entity.SetBlendMode(paint.blend_mode);
745 
746  RoundRectGeometry geom(rect, radii.top_left);
747  AddRenderEntityWithFiltersToCurrentPass(entity, &geom, paint);
748  return;
749  }
750  }
751 
752  Entity entity;
753  entity.SetTransform(GetCurrentTransform());
754  entity.SetBlendMode(paint.blend_mode);
755 
756  if (paint.style == Paint::Style::kFill) {
757  FillRoundRectGeometry geom(round_rect);
758  AddRenderEntityWithFiltersToCurrentPass(entity, &geom, paint);
759  } else {
760  StrokeRoundRectGeometry geom(round_rect, paint.stroke);
761  AddRenderEntityWithFiltersToCurrentPass(entity, &geom, paint);
762  }
763 }

References impeller::Paint::blend_mode, impeller::RoundRect::GetBounds(), GetCurrentTransform(), impeller::RoundRect::GetRadii(), impeller::Paint::kFill, impeller::Entity::SetBlendMode(), impeller::Entity::SetTransform(), impeller::Paint::stroke, and impeller::Paint::style.

Referenced by impeller::DlDispatcherBase::drawRoundRect(), and impeller::DlDispatcherBase::SimplifyOrDrawPath().

◆ DrawRoundSuperellipse()

void impeller::Canvas::DrawRoundSuperellipse ( const RoundSuperellipse rse,
const Paint paint 
)

Definition at line 781 of file canvas.cc.

782  {
783  auto& rect = round_superellipse.GetBounds();
784  auto& radii = round_superellipse.GetRadii();
785  if (radii.AreAllCornersSame() &&
786  AttemptDrawBlurredRSuperellipse(rect, radii.top_left, paint)) {
787  return;
788  }
789 
790  Entity entity;
791  entity.SetTransform(GetCurrentTransform());
792  entity.SetBlendMode(paint.blend_mode);
793 
794  if (paint.style == Paint::Style::kFill) {
795  RoundSuperellipseGeometry geom(rect, radii);
796  AddRenderEntityWithFiltersToCurrentPass(entity, &geom, paint);
797  } else {
798  StrokeRoundSuperellipseGeometry geom(round_superellipse, paint.stroke);
799  AddRenderEntityWithFiltersToCurrentPass(entity, &geom, paint);
800  }
801 }

References impeller::Paint::blend_mode, impeller::RoundSuperellipse::GetBounds(), GetCurrentTransform(), impeller::RoundSuperellipse::GetRadii(), impeller::Paint::kFill, impeller::Entity::SetBlendMode(), impeller::Entity::SetTransform(), impeller::Paint::stroke, and impeller::Paint::style.

Referenced by impeller::DlDispatcherBase::drawRoundSuperellipse(), and impeller::testing::TEST_P().

◆ DrawTextFrame()

void impeller::Canvas::DrawTextFrame ( const std::shared_ptr< TextFrame > &  text_frame,
Point  position,
const Paint paint 
)

Definition at line 1660 of file canvas.cc.

1662  {
1664  if (max_scale * text_frame->GetFont().GetMetrics().point_size >
1665  kMaxTextScale) {
1666  fml::StatusOr<flutter::DlPath> path = text_frame->GetPath();
1667  if (path.ok()) {
1668  Save(1);
1669  Concat(Matrix::MakeTranslation(position));
1670  DrawPath(path.value(), paint);
1671  Restore();
1672  return;
1673  }
1674  }
1675 
1676  Entity entity;
1677  entity.SetClipDepth(GetClipHeight());
1678  entity.SetBlendMode(paint.blend_mode);
1679 
1680  auto text_contents = std::make_shared<TextContents>();
1681  text_contents->SetTextFrame(text_frame);
1682  text_contents->SetForceTextColor(paint.mask_blur_descriptor.has_value());
1683  text_contents->SetScale(max_scale);
1684  text_contents->SetColor(paint.color);
1685  text_contents->SetOffset(position);
1686  text_contents->SetTextProperties(paint.color,
1687  paint.style == Paint::Style::kStroke
1688  ? std::optional(paint.stroke)
1689  : std::nullopt);
1690 
1691  entity.SetTransform(GetCurrentTransform() *
1692  Matrix::MakeTranslation(position));
1693 
1694  if (AttemptBlurredTextOptimization(text_frame, text_contents, entity,
1695  paint)) {
1696  return;
1697  }
1698 
1699  entity.SetContents(paint.WithFilters(std::move(text_contents)));
1700  AddRenderEntityToCurrentPass(entity, false);
1701 }
bool Restore()
Definition: canvas.cc:1469
void Concat(const Matrix &transform)
Definition: canvas.cc:255
void DrawPath(const flutter::DlPath &path, const Paint &paint)
Definition: canvas.cc:326
void Save(uint32_t total_content_depth=kMaxDepth)
Definition: canvas.cc:1183
static constexpr Scalar kMaxTextScale
Definition: canvas.cc:1658
Scalar GetMaxBasisLengthXY() const
Definition: matrix.h:323

References impeller::Paint::blend_mode, impeller::Paint::color, Concat(), DrawPath(), GetCurrentTransform(), impeller::Matrix::GetMaxBasisLengthXY(), impeller::kMaxTextScale, impeller::Paint::kStroke, impeller::Matrix::MakeTranslation(), impeller::Paint::mask_blur_descriptor, Restore(), Save(), impeller::Entity::SetBlendMode(), impeller::Entity::SetClipDepth(), impeller::Entity::SetContents(), impeller::Entity::SetTransform(), impeller::Paint::stroke, impeller::Paint::style, and impeller::Paint::WithFilters().

Referenced by impeller::DlDispatcherBase::drawTextFrame().

◆ DrawVertices()

void impeller::Canvas::DrawVertices ( const std::shared_ptr< VerticesGeometry > &  vertices,
BlendMode  blend_mode,
const Paint paint 
)

Definition at line 1004 of file canvas.cc.

1006  {
1007  // Override the blend mode with kDestination in order to match the behavior
1008  // of Skia's SK_LEGACY_IGNORE_DRAW_VERTICES_BLEND_WITH_NO_SHADER flag, which
1009  // is enabled when the Flutter engine builds Skia.
1010  if (!paint.color_source) {
1011  blend_mode = BlendMode::kDst;
1012  }
1013 
1014  Entity entity;
1015  entity.SetTransform(GetCurrentTransform());
1016  entity.SetBlendMode(paint.blend_mode);
1017 
1018  // If there are no vertex colors.
1019  if (UseColorSourceContents(vertices, paint)) {
1020  AddRenderEntityWithFiltersToCurrentPass(entity, vertices.get(), paint);
1021  return;
1022  }
1023 
1024  // If the blend mode is destination don't bother to bind or create a texture.
1025  if (blend_mode == BlendMode::kDst) {
1026  auto contents = std::make_shared<VerticesSimpleBlendContents>();
1027  contents->SetBlendMode(blend_mode);
1028  contents->SetAlpha(paint.color.alpha);
1029  contents->SetGeometry(vertices);
1030  entity.SetContents(paint.WithFilters(std::move(contents)));
1031  AddRenderEntityToCurrentPass(entity);
1032  return;
1033  }
1034 
1035  // If there is a texture, use this directly. Otherwise render the color
1036  // source to a texture.
1037  if (paint.color_source &&
1038  paint.color_source->type() == flutter::DlColorSourceType::kImage) {
1039  const flutter::DlImageColorSource* image_color_source =
1040  paint.color_source->asImage();
1041  FML_DCHECK(image_color_source &&
1042  image_color_source->image()->impeller_texture());
1043  auto texture = image_color_source->image()->impeller_texture();
1044  auto x_tile_mode = static_cast<Entity::TileMode>(
1045  image_color_source->horizontal_tile_mode());
1046  auto y_tile_mode =
1047  static_cast<Entity::TileMode>(image_color_source->vertical_tile_mode());
1048  auto sampler_descriptor =
1049  skia_conversions::ToSamplerDescriptor(image_color_source->sampling());
1050  auto effect_transform = image_color_source->matrix();
1051 
1052  auto contents = std::make_shared<VerticesSimpleBlendContents>();
1053  contents->SetBlendMode(blend_mode);
1054  contents->SetAlpha(paint.color.alpha);
1055  contents->SetGeometry(vertices);
1056  contents->SetEffectTransform(effect_transform);
1057  contents->SetTexture(texture);
1058  contents->SetTileMode(x_tile_mode, y_tile_mode);
1059  contents->SetSamplerDescriptor(sampler_descriptor);
1060 
1061  entity.SetContents(paint.WithFilters(std::move(contents)));
1062  AddRenderEntityToCurrentPass(entity);
1063  return;
1064  }
1065 
1066  auto src_paint = paint;
1067  src_paint.color = paint.color.WithAlpha(1.0);
1068 
1069  std::shared_ptr<ColorSourceContents> src_contents =
1070  src_paint.CreateContents();
1071  src_contents->SetGeometry(vertices.get());
1072 
1073  // If the color source has an intrinsic size, then we use that to
1074  // create the src contents as a simplification. Otherwise we use
1075  // the extent of the texture coordinates to determine how large
1076  // the src contents should be. If neither has a value we fall back
1077  // to using the geometry coverage data.
1078  Rect src_coverage;
1079  auto size = src_contents->GetColorSourceSize();
1080  if (size.has_value()) {
1081  src_coverage = Rect::MakeXYWH(0, 0, size->width, size->height);
1082  } else {
1083  auto cvg = vertices->GetCoverage(Matrix{});
1084  FML_CHECK(cvg.has_value());
1085  auto texture_coverage = vertices->GetTextureCoordinateCoverage();
1086  if (texture_coverage.has_value()) {
1087  src_coverage =
1088  Rect::MakeOriginSize(texture_coverage->GetOrigin(),
1089  texture_coverage->GetSize().Max({1, 1}));
1090  } else {
1091  src_coverage = cvg.value();
1092  }
1093  }
1094  src_contents = src_paint.CreateContents();
1095 
1096  clip_geometry_.push_back(Geometry::MakeRect(Rect::Round(src_coverage)));
1097  src_contents->SetGeometry(clip_geometry_.back().get());
1098 
1099  auto contents = std::make_shared<VerticesSimpleBlendContents>();
1100  contents->SetBlendMode(blend_mode);
1101  contents->SetAlpha(paint.color.alpha);
1102  contents->SetGeometry(vertices);
1103  contents->SetLazyTextureCoverage(src_coverage);
1104  contents->SetLazyTexture([src_contents,
1105  src_coverage](const ContentContext& renderer) {
1106  // Applying the src coverage as the coverage limit prevents the 1px
1107  // coverage pad from adding a border that is picked up by developer
1108  // specified UVs.
1109  auto snapshot =
1110  src_contents->RenderToSnapshot(renderer, {}, Rect::Round(src_coverage));
1111  return snapshot.has_value() ? snapshot->texture : nullptr;
1112  });
1113  entity.SetContents(paint.WithFilters(std::move(contents)));
1114  AddRenderEntityToCurrentPass(entity);
1115 }
static std::unique_ptr< Geometry > MakeRect(const Rect &rect)
Definition: geometry.cc:83
impeller::SamplerDescriptor ToSamplerDescriptor(const flutter::DlImageSampling options)
Round(const TRect< U > &r)
Definition: rect.h:699
constexpr static TRect MakeXYWH(Type x, Type y, Type width, Type height)
Definition: rect.h:136

References impeller::Color::alpha, impeller::Paint::blend_mode, impeller::Paint::color, impeller::Paint::color_source, GetCurrentTransform(), impeller::kDst, impeller::TRect< Scalar >::MakeOriginSize(), impeller::Geometry::MakeRect(), impeller::TRect< Scalar >::MakeXYWH(), impeller::TRect< Scalar >::Round(), impeller::Entity::SetBlendMode(), impeller::Entity::SetContents(), impeller::Entity::SetTransform(), impeller::skia_conversions::ToSamplerDescriptor(), impeller::Color::WithAlpha(), and impeller::Paint::WithFilters().

Referenced by impeller::CanvasDlDispatcher::drawVertices(), and impeller::testing::TEST_P().

◆ EndReplay()

void impeller::Canvas::EndReplay ( )

Definition at line 2086 of file canvas.cc.

2086  {
2087  FML_DCHECK(render_passes_.size() == 1u);
2088  render_passes_.back().inline_pass_context->GetRenderPass();
2089  render_passes_.back().inline_pass_context->EndPass(
2090  /*is_onscreen=*/!requires_readback_ && is_onscreen_);
2091  backdrop_data_.clear();
2092 
2093  // If requires_readback_ was true, then we rendered to an offscreen texture
2094  // instead of to the onscreen provided in the render target. Now we need to
2095  // draw or blit the offscreen back to the onscreen.
2096  if (requires_readback_) {
2097  BlitToOnscreen(/*is_onscreen_=*/is_onscreen_);
2098  }
2099  if (!EnsureFinalMipmapGeneration()) {
2100  VALIDATION_LOG << "Failed to generate onscreen mipmaps.";
2101  }
2102  if (!renderer_.GetContext()->FlushCommandBuffers()) {
2103  // Not much we can do.
2104  VALIDATION_LOG << "Failed to submit command buffers";
2105  }
2106  render_passes_.clear();
2107  renderer_.GetRenderTargetCache()->End();
2108  clip_geometry_.clear();
2109 
2110  Reset();
2111  Initialize(initial_cull_rect_);
2112 }
bool EnsureFinalMipmapGeneration() const
Definition: canvas.cc:2068
const std::shared_ptr< RenderTargetAllocator > & GetRenderTargetCache() const
#define VALIDATION_LOG
Definition: validation.h:91

References VALIDATION_LOG.

Referenced by impeller::CanvasDlDispatcher::FinishRecording(), and impeller::testing::TEST_P().

◆ EnsureFinalMipmapGeneration()

bool impeller::Canvas::EnsureFinalMipmapGeneration ( ) const

For picture snapshots we need addition steps to verify that final mipmaps are generated.

Definition at line 2068 of file canvas.cc.

2068  {
2069  if (!render_target_.GetRenderTargetTexture()->NeedsMipmapGeneration()) {
2070  return true;
2071  }
2072  std::shared_ptr<CommandBuffer> cmd_buffer =
2073  renderer_.GetContext()->CreateCommandBuffer();
2074  if (!cmd_buffer) {
2075  return false;
2076  }
2077  std::shared_ptr<BlitPass> blit_pass = cmd_buffer->CreateBlitPass();
2078  if (!blit_pass) {
2079  return false;
2080  }
2081  blit_pass->GenerateMipmap(render_target_.GetRenderTargetTexture());
2082  blit_pass->EncodeCommands();
2083  return renderer_.GetContext()->EnqueueCommandBuffer(std::move(cmd_buffer));
2084 }
std::shared_ptr< Texture > GetRenderTargetTexture() const

◆ GetCurrentTransform()

◆ GetLocalCoverageLimit()

std::optional< Rect > impeller::Canvas::GetLocalCoverageLimit ( ) const

Return the culling bounds of the current render target, or nullopt if there is no coverage.

Definition at line 1200 of file canvas.cc.

1200  {
1201  if (!clip_coverage_stack_.HasCoverage()) {
1202  // The current clip is empty. This means the pass texture won't be
1203  // visible, so skip it.
1204  return std::nullopt;
1205  }
1206 
1207  auto maybe_current_clip_coverage = clip_coverage_stack_.CurrentClipCoverage();
1208  if (!maybe_current_clip_coverage.has_value()) {
1209  return std::nullopt;
1210  }
1211 
1212  auto current_clip_coverage = maybe_current_clip_coverage.value();
1213 
1214  // The maximum coverage of the subpass. Subpasses textures should never
1215  // extend outside the parent pass texture or the current clip coverage.
1216  std::optional<Rect> maybe_coverage_limit =
1217  Rect::MakeOriginSize(GetGlobalPassPosition(),
1218  Size(render_passes_.back()
1219  .inline_pass_context->GetTexture()
1220  ->GetSize()))
1221  .Intersection(current_clip_coverage);
1222 
1223  if (!maybe_coverage_limit.has_value() || maybe_coverage_limit->IsEmpty()) {
1224  return std::nullopt;
1225  }
1226 
1227  return maybe_coverage_limit->Intersection(
1228  Rect::MakeSize(render_target_.GetRenderTargetSize()));
1229 }
ISize GetRenderTargetSize() const
constexpr std::optional< TRect > Intersection(const TRect &o) const
Definition: rect.h:532

References impeller::EntityPassClipStack::CurrentClipCoverage(), impeller::RenderTarget::GetRenderTargetSize(), impeller::EntityPassClipStack::HasCoverage(), impeller::TRect< T >::Intersection(), impeller::TRect< Scalar >::MakeOriginSize(), and impeller::TRect< Scalar >::MakeSize().

Referenced by impeller::DlDispatcherBase::drawDisplayList(), and SaveLayer().

◆ GetMaxOpDepth()

uint64_t impeller::Canvas::GetMaxOpDepth ( ) const
inline

Definition at line 263 of file canvas.h.

263 { return transform_stack_.back().clip_depth; }

Referenced by impeller::CanvasDlDispatcher::saveLayer().

◆ GetOpDepth()

uint64_t impeller::Canvas::GetOpDepth ( ) const
inline

Definition at line 261 of file canvas.h.

261 { return current_depth_; }

Referenced by impeller::CanvasDlDispatcher::saveLayer().

◆ GetSaveCount()

size_t impeller::Canvas::GetSaveCount ( ) const

Definition at line 310 of file canvas.cc.

310  {
311  return transform_stack_.size();
312 }

Referenced by impeller::DlDispatcherBase::drawDisplayList(), and RestoreToCount().

◆ PreConcat()

void impeller::Canvas::PreConcat ( const Matrix transform)

Definition at line 259 of file canvas.cc.

259  {
260  transform_stack_.back().transform = transform * GetCurrentTransform();
261 }

References GetCurrentTransform(), and transform.

Referenced by impeller::DlDispatcherBase::drawShadow().

◆ RequiresReadback()

bool impeller::Canvas::RequiresReadback ( ) const
inline

Definition at line 271 of file canvas.h.

271 { return requires_readback_; }

◆ ResetTransform()

void impeller::Canvas::ResetTransform ( )

Definition at line 263 of file canvas.cc.

263  {
264  transform_stack_.back().transform = {};
265 }

Referenced by impeller::DlDispatcherBase::transformReset().

◆ Restore()

bool impeller::Canvas::Restore ( )

Definition at line 1469 of file canvas.cc.

1469  {
1470  FML_DCHECK(transform_stack_.size() > 0);
1471  if (transform_stack_.size() == 1) {
1472  return false;
1473  }
1474 
1475  // This check is important to make sure we didn't exceed the depth
1476  // that the clips were rendered at while rendering any of the
1477  // rendering ops. It is OK for the current depth to equal the
1478  // outgoing clip depth because that means the clipping would have
1479  // been successful up through the last rendering op, but it cannot
1480  // be greater.
1481  // Also, we bump the current rendering depth to the outgoing clip
1482  // depth so that future rendering operations are not clipped by
1483  // any of the pixels set by the expiring clips. It is OK for the
1484  // estimates used to determine the clip depth in save/saveLayer
1485  // to be overly conservative, but we need to jump the depth to
1486  // the clip depth so that the next rendering op will get a
1487  // larger depth (it will pre-increment the current_depth_ value).
1488  FML_DCHECK(current_depth_ <= transform_stack_.back().clip_depth)
1489  << current_depth_ << " <=? " << transform_stack_.back().clip_depth;
1490  current_depth_ = transform_stack_.back().clip_depth;
1491 
1492  if (IsSkipping()) {
1493  transform_stack_.pop_back();
1494  return true;
1495  }
1496 
1497  if (transform_stack_.back().rendering_mode ==
1499  transform_stack_.back().rendering_mode ==
1501  auto lazy_render_pass = std::move(render_passes_.back());
1502  render_passes_.pop_back();
1503  // Force the render pass to be constructed if it never was.
1504  lazy_render_pass.inline_pass_context->GetRenderPass();
1505 
1506  SaveLayerState save_layer_state = save_layer_state_.back();
1507  save_layer_state_.pop_back();
1508  auto global_pass_position = GetGlobalPassPosition();
1509 
1510  std::shared_ptr<Contents> contents = CreateContentsForSubpassTarget(
1511  save_layer_state.paint, //
1512  lazy_render_pass.inline_pass_context->GetTexture(), //
1513  Matrix::MakeTranslation(Vector3{-global_pass_position}) * //
1514  transform_stack_.back().transform //
1515  );
1516 
1517  lazy_render_pass.inline_pass_context->EndPass();
1518 
1519  // Round the subpass texture position for pixel alignment with the parent
1520  // pass render target. By default, we draw subpass textures with nearest
1521  // sampling, so aligning here is important for avoiding visual nearest
1522  // sampling errors caused by limited floating point precision when
1523  // straddling a half pixel boundary.
1524  Point subpass_texture_position;
1525  if (transform_stack_.back().did_round_out) {
1526  // Subpass coverage was rounded out, origin potentially moved "down" by
1527  // as much as a pixel.
1528  subpass_texture_position =
1529  (save_layer_state.coverage.GetOrigin() - global_pass_position)
1530  .Floor();
1531  } else {
1532  // Subpass coverage was truncated. Pick the closest phyiscal pixel.
1533  subpass_texture_position =
1534  (save_layer_state.coverage.GetOrigin() - global_pass_position)
1535  .Round();
1536  }
1537 
1538  Entity element_entity;
1539  element_entity.SetClipDepth(++current_depth_);
1540  element_entity.SetContents(std::move(contents));
1541  element_entity.SetBlendMode(save_layer_state.paint.blend_mode);
1542  element_entity.SetTransform(
1543  Matrix::MakeTranslation(Vector3(subpass_texture_position)));
1544 
1545  if (element_entity.GetBlendMode() > Entity::kLastPipelineBlendMode) {
1546  if (renderer_.GetDeviceCapabilities().SupportsFramebufferFetch()) {
1547  ApplyFramebufferBlend(element_entity);
1548  } else {
1549  // End the active pass and flush the buffer before rendering "advanced"
1550  // blends. Advanced blends work by binding the current render target
1551  // texture as an input ("destination"), blending with a second texture
1552  // input ("source"), writing the result to an intermediate texture, and
1553  // finally copying the data from the intermediate texture back to the
1554  // render target texture. And so all of the commands that have written
1555  // to the render target texture so far need to execute before it's bound
1556  // for blending (otherwise the blend pass will end up executing before
1557  // all the previous commands in the active pass).
1558  auto input_texture = FlipBackdrop(GetGlobalPassPosition());
1559  if (!input_texture) {
1560  return false;
1561  }
1562 
1563  FilterInput::Vector inputs = {
1564  FilterInput::Make(input_texture,
1565  element_entity.GetTransform().Invert()),
1566  FilterInput::Make(element_entity.GetContents())};
1567  auto contents = ColorFilterContents::MakeBlend(
1568  element_entity.GetBlendMode(), inputs);
1569  contents->SetCoverageHint(element_entity.GetCoverage());
1570  element_entity.SetContents(std::move(contents));
1571  element_entity.SetBlendMode(BlendMode::kSrc);
1572  }
1573  }
1574 
1575  element_entity.Render(
1576  renderer_, //
1577  *render_passes_.back().inline_pass_context->GetRenderPass() //
1578  );
1579  clip_coverage_stack_.PopSubpass();
1580  transform_stack_.pop_back();
1581 
1582  // We don't need to restore clips if a saveLayer was performed, as the clip
1583  // state is per render target, and no more rendering operations will be
1584  // performed as the render target workloaded is completed in the restore.
1585  return true;
1586  }
1587 
1588  size_t num_clips = transform_stack_.back().num_clips;
1589  transform_stack_.pop_back();
1590 
1591  if (num_clips > 0) {
1592  EntityPassClipStack::ClipStateResult clip_state_result =
1593  clip_coverage_stack_.RecordRestore(GetGlobalPassPosition(),
1594  GetClipHeight());
1595 
1596  // Clip restores are never required with depth based clipping.
1597  FML_DCHECK(!clip_state_result.should_render);
1598  if (clip_state_result.clip_did_change) {
1599  // We only need to update the pass scissor if the clip state has changed.
1600  SetClipScissor(
1601  clip_coverage_stack_.CurrentClipCoverage(), //
1602  *render_passes_.back().inline_pass_context->GetRenderPass(), //
1603  GetGlobalPassPosition() //
1604  );
1605  }
1606  }
1607 
1608  return true;
1609 }
virtual bool SupportsFramebufferFetch() const =0
Whether the context backend is able to support pipelines with shaders that read from the framebuffer ...
static std::shared_ptr< ColorFilterContents > MakeBlend(BlendMode blend_mode, FilterInput::Vector inputs, std::optional< Color > foreground_color=std::nullopt)
the [inputs] are expected to be in the order of dst, src.
const Capabilities & GetDeviceCapabilities() const
static constexpr BlendMode kLastPipelineBlendMode
Definition: entity.h:28
ClipStateResult RecordRestore(Point global_pass_position, size_t restore_height)
static FilterInput::Ref Make(Variant input, bool msaa_enabled=true)
Definition: filter_input.cc:19
std::vector< FilterInput::Ref > Vector
Definition: filter_input.h:33
TPoint< Scalar > Point
Definition: point.h:327

References impeller::Paint::blend_mode, impeller::EntityPassClipStack::ClipStateResult::clip_did_change, impeller::Canvas::SaveLayerState::coverage, impeller::EntityPassClipStack::CurrentClipCoverage(), impeller::Entity::GetBlendMode(), impeller::Entity::GetContents(), impeller::Entity::GetCoverage(), impeller::ContentContext::GetDeviceCapabilities(), impeller::TRect< T >::GetOrigin(), impeller::Entity::GetTransform(), impeller::Matrix::Invert(), impeller::Entity::kLastPipelineBlendMode, impeller::kSrc, impeller::Entity::kSubpassAppendSnapshotTransform, impeller::Entity::kSubpassPrependSnapshotTransform, impeller::FilterInput::Make(), impeller::ColorFilterContents::MakeBlend(), impeller::Matrix::MakeTranslation(), impeller::Canvas::SaveLayerState::paint, impeller::EntityPassClipStack::PopSubpass(), impeller::EntityPassClipStack::RecordRestore(), impeller::Entity::Render(), impeller::Entity::SetBlendMode(), impeller::Entity::SetClipDepth(), impeller::Entity::SetContents(), impeller::Entity::SetTransform(), impeller::EntityPassClipStack::ClipStateResult::should_render, and impeller::Capabilities::SupportsFramebufferFetch().

Referenced by impeller::DlDispatcherBase::drawShadow(), DrawTextFrame(), impeller::DlDispatcherBase::restore(), and RestoreToCount().

◆ RestoreToCount()

void impeller::Canvas::RestoreToCount ( size_t  count)

Definition at line 318 of file canvas.cc.

318  {
319  while (GetSaveCount() > count) {
320  if (!Restore()) {
321  return;
322  }
323  }
324 }
size_t GetSaveCount() const
Definition: canvas.cc:310

References GetSaveCount(), and Restore().

Referenced by impeller::DlDispatcherBase::drawDisplayList().

◆ Rotate()

void impeller::Canvas::Rotate ( Radians  radians)

Definition at line 291 of file canvas.cc.

291  {
292  Concat(Matrix::MakeRotationZ(radians));
293 }
static Matrix MakeRotationZ(Radians r)
Definition: matrix.h:223

References Concat(), and impeller::Matrix::MakeRotationZ().

Referenced by impeller::DlDispatcherBase::rotate().

◆ Save()

void impeller::Canvas::Save ( uint32_t  total_content_depth = kMaxDepth)

Definition at line 1183 of file canvas.cc.

1183  {
1184  if (IsSkipping()) {
1185  return SkipUntilMatchingRestore(total_content_depth);
1186  }
1187 
1188  auto entry = CanvasStackEntry{};
1189  entry.transform = transform_stack_.back().transform;
1190  entry.clip_depth = current_depth_ + total_content_depth;
1191  entry.distributed_opacity = transform_stack_.back().distributed_opacity;
1192  FML_DCHECK(entry.clip_depth <= transform_stack_.back().clip_depth)
1193  << entry.clip_depth << " <=? " << transform_stack_.back().clip_depth
1194  << " after allocating " << total_content_depth;
1195  entry.clip_height = transform_stack_.back().clip_height;
1196  entry.rendering_mode = Entity::RenderingMode::kDirect;
1197  transform_stack_.push_back(entry);
1198 }

References impeller::Entity::kDirect, and impeller::CanvasStackEntry::transform.

Referenced by impeller::DlDispatcherBase::drawDisplayList(), impeller::DlDispatcherBase::drawShadow(), DrawTextFrame(), impeller::DlDispatcherBase::save(), and SaveLayer().

◆ SaveLayer()

void impeller::Canvas::SaveLayer ( const Paint paint,
std::optional< Rect bounds = std::nullopt,
const flutter::DlImageFilter *  backdrop_filter = nullptr,
ContentBoundsPromise  bounds_promise = ContentBoundsPromise::kUnknown,
uint32_t  total_content_depth = kMaxDepth,
bool  can_distribute_opacity = false,
std::optional< int64_t >  backdrop_id = std::nullopt 
)

Definition at line 1231 of file canvas.cc.

1237  {
1238  TRACE_EVENT0("flutter", "Canvas::saveLayer");
1239  if (IsSkipping()) {
1240  return SkipUntilMatchingRestore(total_content_depth);
1241  }
1242 
1243  auto maybe_coverage_limit = GetLocalCoverageLimit();
1244  if (!maybe_coverage_limit.has_value()) {
1245  return SkipUntilMatchingRestore(total_content_depth);
1246  }
1247  auto coverage_limit = maybe_coverage_limit.value();
1248 
1249  if (can_distribute_opacity && !backdrop_filter &&
1251  bounds_promise != ContentBoundsPromise::kMayClipContents) {
1252  Save(total_content_depth);
1253  transform_stack_.back().distributed_opacity *= paint.color.alpha;
1254  return;
1255  }
1256 
1257  std::shared_ptr<FilterContents> filter_contents = paint.WithImageFilter(
1258  Rect(), transform_stack_.back().transform,
1260 
1261  std::optional<Rect> maybe_subpass_coverage = ComputeSaveLayerCoverage(
1262  bounds.value_or(Rect::MakeMaximum()),
1263  transform_stack_.back().transform, //
1264  coverage_limit, //
1265  filter_contents, //
1266  /*flood_output_coverage=*/
1267  Entity::IsBlendModeDestructive(paint.blend_mode), //
1268  /*flood_input_coverage=*/!!backdrop_filter ||
1269  (paint.color_filter &&
1270  paint.color_filter->modifies_transparent_black()) //
1271  );
1272 
1273  if (!maybe_subpass_coverage.has_value()) {
1274  return SkipUntilMatchingRestore(total_content_depth);
1275  }
1276 
1277  auto subpass_coverage = maybe_subpass_coverage.value();
1278 
1279  // When an image filter is present, clamp to avoid flicking due to nearest
1280  // sampled image. For other cases, round out to ensure than any geometry is
1281  // not cut off.
1282  //
1283  // See also this bug: https://github.com/flutter/flutter/issues/144213
1284  //
1285  // TODO(jonahwilliams): this could still round out for filters that use decal
1286  // sampling mode.
1288  bool did_round_out = false;
1289  Point coverage_origin_adjustment = Point{0, 0};
1290  if (paint.image_filter) {
1291  subpass_size = ISize(subpass_coverage.GetSize());
1292  } else {
1293  did_round_out = true;
1294  subpass_size =
1295  static_cast<ISize>(IRect::RoundOut(subpass_coverage).GetSize());
1296  // If rounding out, adjust the coverage to account for the subpixel shift.
1297  coverage_origin_adjustment =
1298  Point(subpass_coverage.GetLeftTop().x -
1299  std::floor(subpass_coverage.GetLeftTop().x),
1300  subpass_coverage.GetLeftTop().y -
1301  std::floor(subpass_coverage.GetLeftTop().y));
1302  }
1303  if (subpass_size.IsEmpty()) {
1304  return SkipUntilMatchingRestore(total_content_depth);
1305  }
1306 
1307  // When there are scaling filters present, these contents may exceed the
1308  // maximum texture size. Perform a clamp here, which may cause rendering
1309  // artifacts.
1310  subpass_size = subpass_size.Min(renderer_.GetContext()
1311  ->GetCapabilities()
1312  ->GetMaximumRenderPassAttachmentSize());
1313 
1314  // Backdrop filter state, ignored if there is no BDF.
1315  std::shared_ptr<FilterContents> backdrop_filter_contents;
1316  Point local_position = Point(0, 0);
1317  if (backdrop_filter) {
1318  local_position = subpass_coverage.GetOrigin() - GetGlobalPassPosition();
1319  Canvas::BackdropFilterProc backdrop_filter_proc =
1320  [backdrop_filter = backdrop_filter](
1321  const FilterInput::Ref& input, const Matrix& effect_transform,
1322  Entity::RenderingMode rendering_mode) {
1323  auto filter = WrapInput(backdrop_filter, input);
1324  filter->SetEffectTransform(effect_transform);
1325  filter->SetRenderingMode(rendering_mode);
1326  return filter;
1327  };
1328 
1329  std::shared_ptr<Texture> input_texture;
1330 
1331  // If the backdrop ID is not nullopt and there is more than one usage
1332  // of it in the current scene, cache the backdrop texture and remove it from
1333  // the current entity pass flip.
1334  bool will_cache_backdrop_texture = false;
1335  BackdropData* backdrop_data = nullptr;
1336  // If we've reached this point, there is at least one backdrop filter. But
1337  // potentially more if there is a backdrop id. We may conditionally set this
1338  // to a higher value in the if block below.
1339  size_t backdrop_count = 1;
1340  if (backdrop_id.has_value()) {
1341  std::unordered_map<int64_t, BackdropData>::iterator backdrop_data_it =
1342  backdrop_data_.find(backdrop_id.value());
1343  if (backdrop_data_it != backdrop_data_.end()) {
1344  backdrop_data = &backdrop_data_it->second;
1345  will_cache_backdrop_texture =
1346  backdrop_data_it->second.backdrop_count > 1;
1347  backdrop_count = backdrop_data_it->second.backdrop_count;
1348  }
1349  }
1350 
1351  if (!will_cache_backdrop_texture || !backdrop_data->texture_slot) {
1352  backdrop_count_ -= backdrop_count;
1353 
1354  // The onscreen texture can be flipped to if:
1355  // 1. The device supports framebuffer fetch
1356  // 2. There are no more backdrop filters
1357  // 3. The current render pass is for the onscreen pass.
1358  const bool should_use_onscreen =
1360  backdrop_count_ == 0 && render_passes_.size() == 1u;
1361  input_texture = FlipBackdrop(
1362  GetGlobalPassPosition(), //
1363  /*should_remove_texture=*/will_cache_backdrop_texture, //
1364  /*should_use_onscreen=*/should_use_onscreen //
1365  );
1366  if (!input_texture) {
1367  // Validation failures are logged in FlipBackdrop.
1368  return;
1369  }
1370 
1371  if (will_cache_backdrop_texture) {
1372  backdrop_data->texture_slot = input_texture;
1373  }
1374  } else {
1375  input_texture = backdrop_data->texture_slot;
1376  }
1377 
1378  backdrop_filter_contents = backdrop_filter_proc(
1379  FilterInput::Make(std::move(input_texture)),
1380  transform_stack_.back().transform.Basis(),
1381  // When the subpass has a translation that means the math with
1382  // the snapshot has to be different.
1383  transform_stack_.back().transform.HasTranslation()
1386 
1387  if (will_cache_backdrop_texture) {
1388  FML_DCHECK(backdrop_data);
1389  // If all filters on the shared backdrop layer are equal, process the
1390  // layer once.
1391  if (backdrop_data->all_filters_equal &&
1392  !backdrop_data->shared_filter_snapshot.has_value()) {
1393  // TODO(157110): compute minimum input hint.
1394  backdrop_data->shared_filter_snapshot =
1395  backdrop_filter_contents->RenderToSnapshot(renderer_, {});
1396  }
1397 
1398  std::optional<Snapshot> maybe_snapshot =
1399  backdrop_data->shared_filter_snapshot;
1400  if (maybe_snapshot.has_value()) {
1401  Snapshot snapshot = maybe_snapshot.value();
1402  std::shared_ptr<TextureContents> contents = TextureContents::MakeRect(
1403  subpass_coverage.Shift(-GetGlobalPassPosition()));
1404  auto scaled =
1405  subpass_coverage.TransformBounds(snapshot.transform.Invert());
1406  contents->SetTexture(snapshot.texture);
1407  contents->SetSourceRect(scaled);
1408  contents->SetSamplerDescriptor(snapshot.sampler_descriptor);
1409 
1410  // This backdrop entity sets a depth value as it is written to the newly
1411  // flipped backdrop and not into a new saveLayer.
1412  Entity backdrop_entity;
1413  backdrop_entity.SetContents(std::move(contents));
1414  backdrop_entity.SetClipDepth(++current_depth_);
1415  backdrop_entity.SetBlendMode(paint.blend_mode);
1416 
1417  backdrop_entity.Render(renderer_, GetCurrentRenderPass());
1418  Save(0);
1419  return;
1420  }
1421  }
1422  }
1423 
1424  // When applying a save layer, absorb any pending distributed opacity.
1425  Paint paint_copy = paint;
1426  paint_copy.color.alpha *= transform_stack_.back().distributed_opacity;
1427  transform_stack_.back().distributed_opacity = 1.0;
1428 
1429  render_passes_.push_back(
1430  LazyRenderingConfig(renderer_, //
1431  CreateRenderTarget(renderer_, //
1432  subpass_size, //
1434  )));
1435  save_layer_state_.push_back(SaveLayerState{
1436  paint_copy, subpass_coverage.Shift(-coverage_origin_adjustment)});
1437 
1438  CanvasStackEntry entry;
1439  entry.transform = transform_stack_.back().transform;
1440  entry.clip_depth = current_depth_ + total_content_depth;
1441  FML_DCHECK(entry.clip_depth <= transform_stack_.back().clip_depth)
1442  << entry.clip_depth << " <=? " << transform_stack_.back().clip_depth
1443  << " after allocating " << total_content_depth;
1444  entry.clip_height = transform_stack_.back().clip_height;
1446  entry.did_round_out = did_round_out;
1447  transform_stack_.emplace_back(entry);
1448 
1449  // Start non-collapsed subpasses with a fresh clip coverage stack limited by
1450  // the subpass coverage. This is important because image filters applied to
1451  // save layers may transform the subpass texture after it's rendered,
1452  // causing parent clip coverage to get misaligned with the actual area that
1453  // the subpass will affect in the parent pass.
1454  clip_coverage_stack_.PushSubpass(subpass_coverage, GetClipHeight());
1455 
1456  if (!backdrop_filter_contents) {
1457  return;
1458  }
1459 
1460  // Render the backdrop entity.
1461  Entity backdrop_entity;
1462  backdrop_entity.SetContents(std::move(backdrop_filter_contents));
1463  backdrop_entity.SetTransform(
1464  Matrix::MakeTranslation(Vector3(-local_position)));
1465  backdrop_entity.SetClipDepth(std::numeric_limits<uint32_t>::max());
1466  backdrop_entity.Render(renderer_, GetCurrentRenderPass());
1467 }
std::optional< Rect > GetLocalCoverageLimit() const
Return the culling bounds of the current render target, or nullopt if there is no coverage.
Definition: canvas.cc:1200
std::function< std::shared_ptr< FilterContents >(FilterInput::Ref, const Matrix &effect_transform, Entity::RenderingMode rendering_mode)> BackdropFilterProc
Definition: canvas.h:127
static bool IsBlendModeDestructive(BlendMode blend_mode)
Returns true if the blend mode is "destructive", meaning that even fully transparent source colors wo...
Definition: entity.cc:127
void PushSubpass(std::optional< Rect > subpass_coverage, size_t clip_height)
std::shared_ptr< FilterInput > Ref
Definition: filter_input.h:32
ISize subpass_size
The output size of the down-sampling pass.
std::shared_ptr< FilterContents > WrapInput(const flutter::DlImageFilter *filter, const FilterInput::Ref &input)
Generate a new FilterContents using this filter's configuration.
Definition: image_filter.cc:18
@ kMayClipContents
The caller claims the bounds are a subset of an estimate of the reasonably tight bounds but likely cl...
std::optional< Rect > ComputeSaveLayerCoverage(const Rect &content_coverage, const Matrix &effect_transform, const Rect &coverage_limit, const std::shared_ptr< FilterContents > &image_filter, bool flood_output_coverage, bool flood_input_coverage)
Compute the coverage of a subpass in the global coordinate space.
static constexpr Color BlackTransparent()
Definition: color.h:270
static bool CanApplyOpacityPeephole(const Paint &paint)
Whether or not a save layer with the provided paint can perform the opacity peephole optimization.
Definition: paint.h:40
RoundOut(const TRect< U > &r)
Definition: rect.h:683
constexpr static TRect MakeMaximum()
Definition: rect.h:188

References impeller::BackdropData::all_filters_equal, impeller::Color::alpha, impeller::BackdropData::backdrop_count, impeller::Color::BlackTransparent(), impeller::Paint::blend_mode, impeller::Paint::CanApplyOpacityPeephole(), impeller::CanvasStackEntry::clip_depth, impeller::CanvasStackEntry::clip_height, impeller::Paint::color, impeller::Paint::color_filter, impeller::ComputeSaveLayerCoverage(), impeller::CanvasStackEntry::did_round_out, impeller::ContentContext::GetContext(), impeller::ContentContext::GetDeviceCapabilities(), GetLocalCoverageLimit(), impeller::Paint::image_filter, impeller::Matrix::Invert(), impeller::Entity::IsBlendModeDestructive(), impeller::kMayClipContents, impeller::Entity::kSubpassAppendSnapshotTransform, impeller::Entity::kSubpassPrependSnapshotTransform, impeller::FilterInput::Make(), impeller::TRect< Scalar >::MakeMaximum(), impeller::TextureContents::MakeRect(), impeller::Matrix::MakeTranslation(), impeller::EntityPassClipStack::PushSubpass(), impeller::Entity::Render(), impeller::CanvasStackEntry::rendering_mode, impeller::TRect< T >::RoundOut(), impeller::Snapshot::sampler_descriptor, Save(), impeller::Entity::SetBlendMode(), impeller::Entity::SetClipDepth(), impeller::Entity::SetContents(), impeller::Entity::SetTransform(), impeller::BackdropData::shared_filter_snapshot, subpass_size, impeller::Capabilities::SupportsFramebufferFetch(), impeller::Snapshot::texture, impeller::BackdropData::texture_slot, impeller::CanvasStackEntry::transform, impeller::Snapshot::transform, impeller::Paint::WithImageFilter(), and impeller::WrapInput().

Referenced by impeller::DlDispatcherBase::drawDisplayList(), and impeller::DlDispatcherBase::saveLayer().

◆ Scale() [1/2]

void impeller::Canvas::Scale ( const Vector2 scale)

Definition at line 279 of file canvas.cc.

279  {
280  Concat(Matrix::MakeScale(scale));
281 }
static constexpr Matrix MakeScale(const Vector3 &s)
Definition: matrix.h:104

References Concat(), and impeller::Matrix::MakeScale().

Referenced by impeller::DlDispatcherBase::scale().

◆ Scale() [2/2]

void impeller::Canvas::Scale ( const Vector3 scale)

Definition at line 283 of file canvas.cc.

283  {
284  Concat(Matrix::MakeScale(scale));
285 }

References Concat(), and impeller::Matrix::MakeScale().

◆ SetBackdropData()

void impeller::Canvas::SetBackdropData ( std::unordered_map< int64_t, BackdropData backdrop_data,
size_t  backdrop_count 
)

Update the backdrop data used to group together backdrop filters within the same layer.

Definition at line 1882 of file canvas.cc.

1884  {
1885  backdrop_data_ = std::move(backdrop_data);
1886  backdrop_count_ = backdrop_count;
1887 }

Referenced by impeller::CanvasDlDispatcher::SetBackdropData().

◆ Skew()

void impeller::Canvas::Skew ( Scalar  sx,
Scalar  sy 
)

Definition at line 287 of file canvas.cc.

287  {
288  Concat(Matrix::MakeSkew(sx, sy));
289 }
static constexpr Matrix MakeSkew(Scalar sx, Scalar sy)
Definition: matrix.h:127

References Concat(), and impeller::Matrix::MakeSkew().

Referenced by impeller::DlDispatcherBase::skew().

◆ SupportsBlitToOnscreen()

bool impeller::Canvas::SupportsBlitToOnscreen ( ) const

Definition at line 2011 of file canvas.cc.

2011  {
2012  return renderer_.GetContext()
2013  ->GetCapabilities()
2014  ->SupportsTextureToTextureBlits() &&
2015  renderer_.GetContext()->GetBackendType() ==
2017 }

◆ Transform()

void impeller::Canvas::Transform ( const Matrix transform)

Definition at line 267 of file canvas.cc.

267  {
268  Concat(transform);
269 }

References Concat(), and transform.

Referenced by impeller::DlDispatcherBase::transformFullPerspective(), and impeller::DlDispatcherBase::transformReset().

◆ Translate()

void impeller::Canvas::Translate ( const Vector3 offset)

Definition at line 275 of file canvas.cc.

275  {
277 }

References Concat(), and impeller::Matrix::MakeTranslation().

Referenced by impeller::DlDispatcherBase::translate().

Member Data Documentation

◆ kMaxDepth

constexpr uint32_t impeller::Canvas::kMaxDepth = 1 << 24
staticconstexpr

Definition at line 122 of file canvas.h.


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