5#ifndef FLUTTER_DISPLAY_LIST_DL_BUILDER_H_
6#define FLUTTER_DISPLAY_LIST_DL_BUILDER_H_
8#include "flutter/display_list/display_list.h"
9#include "flutter/display_list/dl_blend_mode.h"
10#include "flutter/display_list/dl_canvas.h"
11#include "flutter/display_list/dl_op_flags.h"
12#include "flutter/display_list/dl_op_receiver.h"
13#include "flutter/display_list/dl_paint.h"
14#include "flutter/display_list/dl_sampling_options.h"
15#include "flutter/display_list/geometry/dl_geometry_types.h"
16#include "flutter/display_list/image/dl_image.h"
17#include "flutter/display_list/utils/dl_accumulation_rect.h"
18#include "flutter/display_list/utils/dl_comparable.h"
19#include "flutter/display_list/utils/dl_matrix_clip_tracker.h"
20#include "flutter/fml/macros.h"
39 bool prepare_rtree =
false);
118 bool is_aa =
false)
override;
122 bool is_aa =
false)
override;
126 bool is_aa =
false)
override;
234 void drawTextFrame(
const std::shared_ptr<impeller::TextFrame>& text_frame,
238 void DrawTextFrame(
const std::shared_ptr<impeller::TextFrame>& text_frame,
247 bool transparent_occluder,
256 void Init(
bool prepare_rtree);
273 const DisplayListAttributeFlags
flags);
276 void setAntiAlias(
bool aa)
override {
282 void setInvertColors(
bool invert)
override {
284 onSetInvertColors(
invert);
296 onSetStrokeJoin(
join);
302 onSetDrawStyle(style);
306 void setStrokeWidth(
float width)
override {
308 onSetStrokeWidth(
width);
312 void setStrokeMiter(
float limit)
override {
314 onSetStrokeMiter(limit);
326 onSetBlendMode(
mode);
330 void setColorSource(
const DlColorSource*
source)
override {
336 void setImageFilter(
const DlImageFilter* filter)
override {
338 onSetImageFilter(filter);
342 void setColorFilter(
const DlColorFilter* filter)
override {
344 onSetColorFilter(filter);
348 void setMaskFilter(
const DlMaskFilter* filter)
override {
350 onSetMaskFilter(filter);
354 DlPaint CurrentAttributes()
const {
return current_; }
355 int LastOpIndex()
const {
return op_index_ - 1; }
358 void save()
override {
Save(); }
365 const DlImageFilter*
backdrop)
override;
367 void restore()
override {
Restore(); }
385 void transformFullPerspective(
413 void drawPaint()
override;
421 void drawDashedLine(
const DlPoint& p0,
434 void drawDRRect(
const SkRRect& outer,
const SkRRect& inner)
override;
441 bool useCenter)
override;
445 void drawVertices(
const DlVertices* vertices,
DlBlendMode mode)
override;
451 bool render_with_attributes)
override;
458 bool render_with_attributes,
465 bool render_with_attributes)
override;
475 bool render_with_attributes)
override;
490 bool transparent_occluder,
495 void checkForDeferredSave();
497 DisplayListStorage storage_;
499 size_t allocated_ = 0u;
500 uint32_t render_op_count_ = 0u;
501 uint32_t depth_ = 0u;
504 uint32_t render_op_depth_cost_ = 1u;
508 size_t nested_bytes_ = 0;
509 uint32_t nested_op_count_ = 0;
511 bool is_ui_thread_safe_ =
true;
513 template <
typename T,
typename... Args>
514 void* Push(
size_t extra, Args&&...
args);
517 std::vector<SkRect> rects;
518 std::vector<int> indices;
522 LayerInfo(
const std::shared_ptr<const DlImageFilter>& filter,
523 size_t rtree_rects_start_index)
525 rtree_rects_start_index(rtree_rects_start_index) {}
529 const std::shared_ptr<const DlImageFilter> filter;
534 const size_t rtree_rects_start_index = 0;
538 AccumulationRect global_space_accumulator;
542 AccumulationRect layer_local_accumulator;
546 bool opacity_incompatible_op_detected =
false;
547 bool affects_transparent_layer =
false;
548 bool contains_backdrop_filter =
false;
550 bool is_group_opacity_compatible()
const {
551 return !opacity_incompatible_op_detected &&
552 !layer_local_accumulator.overlap_detected();
556 if (max_blend_mode <
mode) {
557 max_blend_mode =
mode;
567 SaveInfo(
const SaveInfo&
copy) =
default;
568 SaveInfo(SaveInfo&&
copy) =
default;
571 explicit SaveInfo(
const DlRect& cull_rect)
572 : is_save_layer(
true),
573 has_valid_clip(
false),
574 global_state(cull_rect),
575 layer_state(cull_rect),
576 layer_info(new LayerInfo(nullptr, 0u)) {}
581 explicit SaveInfo(
const SaveInfo* parent_info)
582 : is_save_layer(
false),
583 has_deferred_save_op(
true),
584 has_valid_clip(parent_info->has_valid_clip),
585 global_state(parent_info->global_state),
586 layer_state(parent_info->layer_state),
587 layer_info(parent_info->layer_info) {}
590 explicit SaveInfo(
const SaveInfo* parent_info,
591 const std::shared_ptr<const DlImageFilter>& filter,
592 int rtree_rect_index)
593 : is_save_layer(
true),
594 has_valid_clip(
false),
595 global_state(parent_info->global_state),
597 layer_info(new LayerInfo(filter, rtree_rect_index)) {}
599 const bool is_save_layer;
601 bool has_deferred_save_op =
false;
607 uint32_t save_depth = 0;
612 size_t save_offset = 0;
615 DisplayListMatrixClipState global_state;
619 DisplayListMatrixClipState layer_state;
621 std::shared_ptr<LayerInfo> layer_info;
628 void TransferBoundsToParent(
const SaveInfo& parent);
631 const DlRect original_cull_rect_;
632 std::vector<SaveInfo> save_stack_;
633 std::optional<RTreeData> rtree_data_;
640 SaveInfo& current_info() {
return save_stack_.back(); }
641 const SaveInfo& current_info()
const {
return save_stack_.back(); }
645 SaveInfo& parent_info() {
return *
std::prev(save_stack_.end(), 2); }
646 const SaveInfo& parent_info()
const {
653 LayerInfo& current_layer() {
return *save_stack_.back().layer_info; }
654 const LayerInfo& current_layer()
const {
655 return *save_stack_.back().layer_info;
660 LayerInfo& parent_layer() {
661 return *
std::prev(save_stack_.end(), 2)->layer_info;
663 const LayerInfo& parent_layer()
const {
664 return *
std::prev(save_stack_.end(), 2)->layer_info;
673 DisplayListMatrixClipState& global_state() {
674 return current_info().global_state;
676 const DisplayListMatrixClipState& global_state()
const {
677 return current_info().global_state;
687 DisplayListMatrixClipState& layer_local_state() {
688 return current_info().layer_state;
690 const DisplayListMatrixClipState& layer_local_state()
const {
691 return current_info().layer_state;
695 void TransferLayerBounds(
const SkRect& content_bounds);
696 bool AdjustRTreeRects(RTreeData&
data,
697 const DlImageFilter& filter,
704 bool current_opacity_compatibility_ =
true;
716 void UpdateCurrentOpacityCompatibility() {
717 current_opacity_compatibility_ =
718 current_.getColorFilter() ==
nullptr &&
719 !current_.isInvertColors() &&
720 IsOpacityCompatible(current_.getBlendMode());
725 void UpdateLayerOpacityCompatibility(
bool compatible) {
727 current_layer().opacity_incompatible_op_detected =
true;
736 void CheckLayerOpacityCompatibility(
bool uses_blend_attribute =
true) {
737 UpdateLayerOpacityCompatibility(!uses_blend_attribute ||
738 current_opacity_compatibility_);
741 void CheckLayerOpacityHairlineCompatibility() {
742 UpdateLayerOpacityCompatibility(
743 current_opacity_compatibility_ &&
745 current_.getStrokeWidth() > 0));
752 UpdateLayerOpacityCompatibility(IsOpacityCompatible(
mode));
755 void onSetAntiAlias(
bool aa);
756 void onSetInvertColors(
bool invert);
761 void onSetStrokeMiter(
SkScalar limit);
764 void onSetColorSource(
const DlColorSource*
source);
765 void onSetImageFilter(
const DlImageFilter* filter);
766 void onSetColorFilter(
const DlColorFilter* filter);
767 void onSetMaskFilter(
const DlMaskFilter* filter);
769 static DisplayListAttributeFlags FlagsForPointMode(
PointMode mode);
771 enum class OpResult {
773 kPreservesTransparency,
777 bool paint_nops_on_transparency();
783 case OpResult::kNoEffect:
784 case OpResult::kPreservesTransparency:
786 case OpResult::kAffectsAll:
787 current_layer().affects_transparent_layer =
true;
790 current_layer().update_blend_mode(
mode);
792 void UpdateLayerResult(OpResult
result,
bool uses_attributes =
true) {
793 UpdateLayerResult(
result, uses_attributes ? current_.getBlendMode()
800 static_assert(!kAnyColor.isOpaque());
801 static_assert(!kAnyColor.isTransparent());
803 DisplayListAttributeFlags
flags);
811 bool AccumulateUnbounded(
const SaveInfo& save);
812 bool AccumulateUnbounded() {
813 return AccumulateUnbounded(current_info());
819 DisplayListAttributeFlags
flags) {
821 return AccumulateOpBounds(safe_bounds,
flags);
831 bool AccumulateBounds(
const SkRect&
bounds, SaveInfo& layer,
int id);
833 return AccumulateBounds(
bounds, current_info(), op_index_);
static bool compatible(const MTLRenderPassAttachmentDescriptor *first, const MTLRenderPassAttachmentDescriptor *second, const GrMtlPipelineState *pipelineState)
static float prev(float f)
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
static constexpr SkRect kMaxCullRect
void Skew(SkScalar sx, SkScalar sy) override
SkISize GetBaseLayerSize() const override
friend DlOpReceiver & DisplayListBuilderBenchmarkAccessor(DisplayListBuilder &builder)
void DrawLine(const SkPoint &p0, const SkPoint &p1, const DlPaint &paint) override
void RestoreToCount(int restore_count) override
void DrawDRRect(const SkRRect &outer, const SkRRect &inner, const DlPaint &paint) override
void DrawVertices(const DlVertices *vertices, DlBlendMode mode, const DlPaint &paint) override
void TransformFullPerspective(SkScalar mxx, SkScalar mxy, SkScalar mxz, SkScalar mxt, SkScalar myx, SkScalar myy, SkScalar myz, SkScalar myt, SkScalar mzx, SkScalar mzy, SkScalar mzz, SkScalar mzt, SkScalar mwx, SkScalar mwy, SkScalar mwz, SkScalar mwt) override
SkRect GetLocalClipBounds() const override
void DrawRect(const SkRect &rect, const DlPaint &paint) override
void SetTransform(const SkM44 *matrix44) override
void Transform(const SkMatrix *matrix) override
void DrawColor(DlColor color, DlBlendMode mode) override
void DrawOval(const SkRect &bounds, const DlPaint &paint) override
void TransformReset() override
void ClipRRect(const SkRRect &rrect, ClipOp clip_op=ClipOp::kIntersect, bool is_aa=false) override
friend DlOpReceiver & DisplayListBuilderTestingAccessor(DisplayListBuilder &builder)
bool QuickReject(const SkRect &bounds) const override
void Translate(SkScalar tx, SkScalar ty) override
void DrawTextFrame(const std::shared_ptr< impeller::TextFrame > &text_frame, SkScalar x, SkScalar y, const DlPaint &paint) override
void DrawRRect(const SkRRect &rrect, const DlPaint &paint) override
void Scale(SkScalar sx, SkScalar sy) override
void DrawPath(const SkPath &path, const DlPaint &paint) override
SkMatrix GetTransform() const override
void Rotate(SkScalar degrees) override
void DrawCircle(const SkPoint ¢er, SkScalar radius, const DlPaint &paint) override
void DrawPoints(PointMode mode, uint32_t count, const SkPoint pts[], const DlPaint &paint) override
void Transform2DAffine(SkScalar mxx, SkScalar mxy, SkScalar mxt, SkScalar myx, SkScalar myy, SkScalar myt) override
DisplayListBuilder(bool prepare_rtree)
void drawTextFrame(const std::shared_ptr< impeller::TextFrame > &text_frame, SkScalar x, SkScalar y) override
friend int DisplayListBuilderTestingLastOpIndex(DisplayListBuilder &builder)
SkImageInfo GetImageInfo() const override
void SetTransform(const SkMatrix *matrix) override
void DrawTextBlob(const sk_sp< SkTextBlob > &blob, SkScalar x, SkScalar y, const DlPaint &paint) override
void DrawImage(const sk_sp< DlImage > &image, const SkPoint point, DlImageSampling sampling, const DlPaint *paint=nullptr) override
void DrawShadow(const SkPath &path, const DlColor color, const SkScalar elevation, bool transparent_occluder, SkScalar dpr) override
void DrawPaint(const DlPaint &paint) override
void SaveLayer(const SkRect *bounds, const DlPaint *paint=nullptr, const DlImageFilter *backdrop=nullptr) override
void DrawDashedLine(const DlPoint &p0, const DlPoint &p1, DlScalar on_length, DlScalar off_length, const DlPaint &paint) override
sk_sp< DisplayList > Build()
SkM44 GetTransformFullPerspective() const override
void ClipRect(const SkRect &rect, ClipOp clip_op=ClipOp::kIntersect, bool is_aa=false) override
void DrawImageRect(const sk_sp< DlImage > &image, const SkRect &src, const SkRect &dst, DlImageSampling sampling, const DlPaint *paint=nullptr, SrcRectConstraint constraint=SrcRectConstraint::kFast) override
void DrawDisplayList(const sk_sp< DisplayList > display_list, SkScalar opacity=SK_Scalar1) override
SkRect GetDestinationClipBounds() const override
friend DlPaint DisplayListBuilderTestingAttributes(DisplayListBuilder &builder)
void ClipPath(const SkPath &path, ClipOp clip_op=ClipOp::kIntersect, bool is_aa=false) override
void DrawImageNine(const sk_sp< DlImage > &image, const SkIRect ¢er, const SkRect &dst, DlFilterMode filter, const DlPaint *paint=nullptr) override
int GetSaveCount() const override
void DrawArc(const SkRect &bounds, SkScalar start, SkScalar sweep, bool useCenter, const DlPaint &paint) override
void DrawAtlas(const sk_sp< DlImage > &atlas, const SkRSXform xform[], const SkRect tex[], const DlColor colors[], int count, DlBlendMode mode, DlImageSampling sampling, const SkRect *cullRect, const DlPaint *paint=nullptr) override
SkMatrix matrix_3x3() const
SkRect device_cull_rect() const
SkRect local_cull_rect() const
static constexpr DisplayListAttributeFlags kDrawPaintFlags
Developer-facing API for rendering anything within the engine.
virtual void Transform(const SkMatrix *matrix)=0
virtual void DrawVertices(const DlVertices *vertices, DlBlendMode mode, const DlPaint &paint)=0
virtual void DrawImageRect(const sk_sp< DlImage > &image, const SkRect &src, const SkRect &dst, DlImageSampling sampling, const DlPaint *paint=nullptr, SrcRectConstraint constraint=SrcRectConstraint::kFast)=0
Internal API for rendering recorded display lists to backends.
DlStrokeCap getStrokeCap() const
DlBlendMode getBlendMode() const
float getStrokeMiter() const
std::shared_ptr< const DlColorSource > getColorSource() const
DlStrokeJoin getStrokeJoin() const
DlDrawStyle getDrawStyle() const
std::shared_ptr< const DlMaskFilter > getMaskFilter() const
std::shared_ptr< const DlColorFilter > getColorFilter() const
float getStrokeWidth() const
std::shared_ptr< const DlImageFilter > getImageFilter() const
bool isInvertColors() const
Holds all of the data (both required and optional) for a DisplayList drawVertices call.
FlutterSemanticsFlag flags
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
sk_sp< const SkImage > atlas
unsigned useCenter Optional< SkMatrix > matrix
Optional< SkRect > bounds
sk_sp< const SkImage > image
sk_sp< const SkImageFilter > backdrop
sk_sp< SkBlender > blender SkRect rect
PODArray< SkColor > colors
SkSamplingOptions sampling
impeller::Scalar DlScalar
bool NotEquals(const T *a, const T *b)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
@ kFill
fills interior of shapes
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
@ kSrcOver
r = s + (1-sa)*d
flutter::SaveLayerOptions SaveLayerOptions
static SkString join(const CommandLineFlags::StringArray &)
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
constexpr DlColor withAlpha(uint8_t alpha) const
static constexpr DlColor kMidGrey()