5#include "flutter/flow/layers/layer_state_stack.h"
7#include "flutter/display_list/utils/dl_matrix_clip_tracker.h"
8#include "flutter/flow/layers/layer.h"
9#include "flutter/flow/paint_utils.h"
10#include "flutter/flow/raster_cache_util.h"
26 static const std::shared_ptr<DummyDelegate>
kInstance;
53 LayerStateStack::RenderingAttributes& attributes,
69 FML_DCHECK(
false) <<
"LayerStateStack state queried without a delegate";
73 std::make_shared<DummyDelegate>();
78 : canvas_(
canvas), initial_save_level_(
canvas->GetSaveCount()) {}
100 LayerStateStack::RenderingAttributes& attributes,
135 const int initial_save_level_;
141 save_stack_.emplace_back(cull_rect,
matrix);
156 void save()
override { save_stack_.emplace_back(state()); }
158 LayerStateStack::RenderingAttributes& attributes,
161 save_stack_.emplace_back(state());
163 void restore()
override { save_stack_.pop_back(); }
171 if (state().using_4x4_matrix()) {
198 const DisplayListMatrixClipState& state()
const {
return save_stack_.back(); }
200 std::vector<DisplayListMatrixClipState> save_stack_;
212 stack->delegate_->save();
215 stack->delegate_->restore();
225 const LayerStateStack::RenderingAttributes&
prev)
231 stack->outstanding_ = {};
234 stack->delegate_->restore();
250 const LayerStateStack::RenderingAttributes&
prev)
253 old_opacity_(
prev.opacity),
254 old_bounds_(
prev.save_layer_bounds) {}
257 stack->outstanding_.save_layer_bounds = bounds_;
258 stack->outstanding_.opacity *= opacity_;
261 stack->outstanding_.save_layer_bounds = old_bounds_;
262 stack->outstanding_.opacity = old_opacity_;
280 const std::shared_ptr<const DlImageFilter>& filter,
281 const LayerStateStack::RenderingAttributes&
prev)
284 old_filter_(
prev.image_filter),
285 old_bounds_(
prev.save_layer_bounds) {}
289 stack->outstanding_.save_layer_bounds = bounds_;
290 stack->outstanding_.image_filter = filter_;
293 stack->outstanding_.save_layer_bounds = old_bounds_;
294 stack->outstanding_.image_filter = old_filter_;
302 const std::shared_ptr<const DlImageFilter> filter_;
303 const std::shared_ptr<const DlImageFilter> old_filter_;
312 const std::shared_ptr<const DlColorFilter>& filter,
313 const LayerStateStack::RenderingAttributes&
prev)
317 old_bounds_(
prev.save_layer_bounds) {}
321 stack->outstanding_.save_layer_bounds = bounds_;
322 stack->outstanding_.color_filter = filter_;
325 stack->outstanding_.save_layer_bounds = old_bounds_;
326 stack->outstanding_.color_filter = old_filter_;
334 const std::shared_ptr<const DlColorFilter> filter_;
335 const std::shared_ptr<const DlColorFilter> old_filter_;
344 const std::shared_ptr<const DlImageFilter>& filter,
346 const LayerStateStack::RenderingAttributes&
prev)
353 stack->outstanding_ = {};
368 const std::shared_ptr<const DlImageFilter> filter_;
378 stack->delegate_->translate(tx_, ty_);
396 stack->delegate_->transform(matrix_);
413 stack->delegate_->transform(m44_);
430 stack->delegate_->integralTransform();
440 : clip_rect_(clip_rect), is_aa_(is_aa) {}
460 : clip_rrect_(clip_rrect), is_aa_(is_aa) {}
480 : clip_path_(clip_path), is_aa_(is_aa) {}
515 paint.setImageFilter(image_filter);
533 layer_state_stack_->save_layer(
bounds);
538 layer_state_stack_->push_opacity(
bounds, opacity);
544 const std::shared_ptr<const DlImageFilter>& filter) {
546 layer_state_stack_->push_image_filter(
bounds, filter);
552 const std::shared_ptr<const DlColorFilter>& filter) {
554 layer_state_stack_->push_color_filter(
bounds, filter);
560 const std::shared_ptr<const DlImageFilter>& filter,
562 layer_state_stack_->push_backdrop(
bounds, filter, blend_mode);
566 if (!(tx == 0 && ty == 0)) {
567 layer_state_stack_->maybe_save_layer_for_transform(save_needed_);
568 save_needed_ =
false;
569 layer_state_stack_->push_translate(tx, ty);
574 if (
matrix.isTranslate()) {
576 }
else if (!
matrix.isIdentity()) {
577 layer_state_stack_->maybe_save_layer_for_transform(save_needed_);
578 save_needed_ =
false;
579 layer_state_stack_->push_transform(
matrix);
587 layer_state_stack_->maybe_save_layer_for_transform(save_needed_);
588 save_needed_ =
false;
589 layer_state_stack_->push_transform(m44);
594 layer_state_stack_->maybe_save_layer_for_transform(save_needed_);
595 save_needed_ =
false;
596 layer_state_stack_->push_integral_transform();
600 layer_state_stack_->maybe_save_layer_for_clip(save_needed_);
601 save_needed_ =
false;
602 layer_state_stack_->push_clip_rect(
rect, is_aa);
606 layer_state_stack_->maybe_save_layer_for_clip(save_needed_);
607 save_needed_ =
false;
608 layer_state_stack_->push_clip_rrect(
rrect, is_aa);
612 layer_state_stack_->maybe_save_layer_for_clip(save_needed_);
613 save_needed_ =
false;
614 layer_state_stack_->push_clip_path(
path, is_aa);
624 delegate_->decommission();
630 if (canvas == delegate_->canvas()) {
636 delegate_ = std::make_shared<DlCanvasDelegate>(canvas);
650 delegate_ = std::make_shared<PrerollDelegate>(cull_rect,
matrix);
654void LayerStateStack::reapply_all() {
660 RenderingAttributes attributes = outstanding_;
662 for (
auto&
state : state_stack_) {
663 state->reapply(
this);
669 for (
auto&
state : state_stack_) {
670 state->update_mutators(mutators);
674void LayerStateStack::restore_to_count(
size_t restore_count) {
675 while (state_stack_.size() > restore_count) {
676 state_stack_.back()->restore(
this);
677 state_stack_.pop_back();
682 maybe_save_layer(opacity);
683 state_stack_.emplace_back(
684 std::make_unique<OpacityEntry>(
bounds, opacity, outstanding_));
688void LayerStateStack::push_color_filter(
690 const std::shared_ptr<const DlColorFilter>& filter) {
691 maybe_save_layer(filter);
692 state_stack_.emplace_back(
693 std::make_unique<ColorFilterEntry>(
bounds, filter, outstanding_));
697void LayerStateStack::push_image_filter(
699 const std::shared_ptr<const DlImageFilter>& filter) {
700 maybe_save_layer(filter);
701 state_stack_.emplace_back(
702 std::make_unique<ImageFilterEntry>(
bounds, filter, outstanding_));
706void LayerStateStack::push_backdrop(
708 const std::shared_ptr<const DlImageFilter>& filter,
710 state_stack_.emplace_back(std::make_unique<BackdropFilterEntry>(
711 bounds, filter, blend_mode, outstanding_));
716 state_stack_.emplace_back(std::make_unique<TranslateEntry>(tx, ty));
720void LayerStateStack::push_transform(
const SkM44& m44) {
721 state_stack_.emplace_back(std::make_unique<TransformM44Entry>(m44));
726 state_stack_.emplace_back(std::make_unique<TransformMatrixEntry>(
matrix));
730void LayerStateStack::push_integral_transform() {
731 state_stack_.emplace_back(std::make_unique<IntegralTransformEntry>());
735void LayerStateStack::push_clip_rect(
const SkRect&
rect,
bool is_aa) {
736 state_stack_.emplace_back(std::make_unique<ClipRectEntry>(
rect, is_aa));
740void LayerStateStack::push_clip_rrect(
const SkRRect&
rrect,
bool is_aa) {
741 state_stack_.emplace_back(std::make_unique<ClipRRectEntry>(
rrect, is_aa));
745void LayerStateStack::push_clip_path(
const SkPath&
path,
bool is_aa) {
746 state_stack_.emplace_back(std::make_unique<ClipPathEntry>(
path, is_aa));
750bool LayerStateStack::needs_save_layer(
int flags)
const {
755 if (outstanding_.image_filter &&
759 if (outstanding_.color_filter &&
766void LayerStateStack::do_save() {
767 state_stack_.emplace_back(std::make_unique<SaveEntry>());
772 state_stack_.emplace_back(std::make_unique<SaveLayerEntry>(
777void LayerStateStack::maybe_save_layer_for_transform(
bool save_needed) {
779 if (outstanding_.image_filter) {
780 save_layer(outstanding_.save_layer_bounds);
781 }
else if (save_needed) {
786void LayerStateStack::maybe_save_layer_for_clip(
bool save_needed) {
790 if (outstanding_.image_filter) {
791 save_layer(outstanding_.save_layer_bounds);
792 }
else if (save_needed) {
797void LayerStateStack::maybe_save_layer(
int apply_flags) {
799 save_layer(outstanding_.save_layer_bounds);
803void LayerStateStack::maybe_save_layer(
SkScalar opacity) {
804 if (outstanding_.image_filter) {
805 save_layer(outstanding_.save_layer_bounds);
809void LayerStateStack::maybe_save_layer(
810 const std::shared_ptr<const DlColorFilter>& filter) {
811 if (outstanding_.color_filter || outstanding_.image_filter ||
813 !filter->can_commute_with_opacity())) {
815 save_layer(outstanding_.save_layer_bounds);
819void LayerStateStack::maybe_save_layer(
820 const std::shared_ptr<const DlImageFilter>& filter) {
821 if (outstanding_.image_filter) {
823 save_layer(outstanding_.save_layer_bounds);
static void apply_flags(SkFont *font, unsigned flags)
static float prev(float f)
static sk_sp< SkImage > color_filter(const SkImage *image, SkColorFilter *colorFilter)
static SkMatrix Translate(SkScalar dx, SkScalar dy)
static const SkMatrix & I()
void apply(LayerStateStack *stack) const override
~BackdropFilterEntry() override=default
BackdropFilterEntry(const SkRect &bounds, const std::shared_ptr< const DlImageFilter > &filter, DlBlendMode blend_mode, const LayerStateStack::RenderingAttributes &prev)
void reapply(LayerStateStack *stack) const override
ClipPathEntry(const SkPath &clip_path, bool is_aa)
void apply(LayerStateStack *stack) const override
void update_mutators(MutatorsStack *mutators_stack) const override
~ClipPathEntry() override=default
void apply(LayerStateStack *stack) const override
void update_mutators(MutatorsStack *mutators_stack) const override
ClipRRectEntry(const SkRRect &clip_rrect, bool is_aa)
ClipRectEntry(const SkRect &clip_rect, bool is_aa)
void update_mutators(MutatorsStack *mutators_stack) const override
void apply(LayerStateStack *stack) const override
void restore(LayerStateStack *stack) const override
~ColorFilterEntry() override=default
void apply(LayerStateStack *stack) const override
ColorFilterEntry(const SkRect &bounds, const std::shared_ptr< const DlColorFilter > &filter, const LayerStateStack::RenderingAttributes &prev)
void clipRRect(const SkRRect &rrect, ClipOp op, bool is_aa)
SkMatrix matrix_3x3() const
void clipRect(const DlRect &rect, ClipOp op, bool is_aa)
SkRect device_cull_rect() const
void setTransform(const DlMatrix &matrix)
void clipPath(const SkPath &path, ClipOp op, bool is_aa)
SkRect local_cull_rect() const
bool content_culled(const DlRect &content_bounds) const
void transform(const DlMatrix &matrix)
static bool is_3x3(const SkM44 &m44)
void translate(SkScalar tx, SkScalar ty)
void saveLayer(const SkRect &bounds, LayerStateStack::RenderingAttributes &attributes, DlBlendMode blend_mode, const DlImageFilter *backdrop) override
void integralTransform() override
void clipPath(const SkPath &path, ClipOp op, bool is_aa) override
SkRect local_cull_rect() const override
SkM44 matrix_4x4() const override
DlCanvasDelegate(DlCanvas *canvas)
void transform(const SkMatrix &matrix) override
void clipRRect(const SkRRect &rrect, ClipOp op, bool is_aa) override
void transform(const SkM44 &m44) override
bool content_culled(const SkRect &content_bounds) const override
SkMatrix matrix_3x3() const override
DlCanvas * canvas() const override
void translate(SkScalar tx, SkScalar ty) override
void clipRect(const SkRect &rect, ClipOp op, bool is_aa) override
void decommission() override
SkRect device_cull_rect() const override
Developer-facing API for rendering anything within the engine.
virtual void Transform(const SkMatrix *matrix)=0
virtual void ClipRect(const SkRect &rect, ClipOp clip_op=ClipOp::kIntersect, bool is_aa=false)=0
virtual SkM44 GetTransformFullPerspective() const =0
virtual void SetTransform(const SkMatrix *matrix)=0
virtual SkRect GetDestinationClipBounds() const =0
virtual void SaveLayer(const SkRect *bounds, const DlPaint *paint=nullptr, const DlImageFilter *backdrop=nullptr)=0
virtual SkRect GetLocalClipBounds() const =0
virtual bool QuickReject(const SkRect &bounds) const =0
virtual void RestoreToCount(int restore_count)=0
virtual void Translate(SkScalar tx, SkScalar ty)=0
virtual SkMatrix GetTransform() const =0
virtual void ClipPath(const SkPath &path, ClipOp clip_op=ClipOp::kIntersect, bool is_aa=false)=0
virtual void ClipRRect(const SkRRect &rrect, ClipOp clip_op=ClipOp::kIntersect, bool is_aa=false)=0
bool content_culled(const SkRect &content_bounds) const override
static const std::shared_ptr< DummyDelegate > kInstance
SkM44 matrix_4x4() const override
void clipRRect(const SkRRect &rrect, ClipOp op, bool is_aa) override
void integralTransform() override
void decommission() override
void saveLayer(const SkRect &bounds, LayerStateStack::RenderingAttributes &attributes, DlBlendMode blend, const DlImageFilter *backdrop) override
SkRect local_cull_rect() const override
void clipPath(const SkPath &path, ClipOp op, bool is_aa) override
void transform(const SkM44 &m44) override
SkRect device_cull_rect() const override
void translate(SkScalar tx, SkScalar ty) override
void clipRect(const SkRect &rect, ClipOp op, bool is_aa) override
SkMatrix matrix_3x3() const override
void transform(const SkMatrix &matrix) override
~ImageFilterEntry() override=default
void apply(LayerStateStack *stack) const override
void restore(LayerStateStack *stack) const override
ImageFilterEntry(const SkRect &bounds, const std::shared_ptr< const DlImageFilter > &filter, const LayerStateStack::RenderingAttributes &prev)
void apply(LayerStateStack *stack) const override
IntegralTransformEntry()=default
void applyColorFilter(const SkRect &bounds, const std::shared_ptr< const DlColorFilter > &filter)
void translate(SkScalar tx, SkScalar ty)
void applyImageFilter(const SkRect &bounds, const std::shared_ptr< const DlImageFilter > &filter)
void clipPath(const SkPath &path, bool is_aa)
void applyBackdropFilter(const SkRect &bounds, const std::shared_ptr< const DlImageFilter > &filter, DlBlendMode blend_mode)
void clipRRect(const SkRRect &rrect, bool is_aa)
void clipRect(const SkRect &rect, bool is_aa)
void applyOpacity(const SkRect &bounds, SkScalar opacity)
void saveLayer(const SkRect &bounds)
void transform(const SkM44 &m44)
void fill(MutatorsStack *mutators)
void set_preroll_delegate(const SkRect &cull_rect, const SkMatrix &matrix)
friend class MutatorContext
static constexpr int kCallerCanApplyColorFilter
void set_delegate(DlCanvas *canvas)
static constexpr int kCallerCanApplyImageFilter
static constexpr int kCallerCanApplyOpacity
void update_mutators(MutatorsStack *mutators_stack) const override
void restore(LayerStateStack *stack) const override
OpacityEntry(const SkRect &bounds, SkScalar opacity, const LayerStateStack::RenderingAttributes &prev)
void apply(LayerStateStack *stack) const override
void clipRect(const SkRect &rect, ClipOp op, bool is_aa) override
SkMatrix matrix_3x3() const override
void clipRRect(const SkRRect &rrect, ClipOp op, bool is_aa) override
bool content_culled(const SkRect &content_bounds) const override
void clipPath(const SkPath &path, ClipOp op, bool is_aa) override
void saveLayer(const SkRect &bounds, LayerStateStack::RenderingAttributes &attributes, DlBlendMode blend, const DlImageFilter *backdrop) override
void integralTransform() override
SkRect device_cull_rect() const override
SkRect local_cull_rect() const override
void transform(const SkMatrix &matrix) override
void transform(const SkM44 &m44) override
void decommission() override
SkM44 matrix_4x4() const override
void translate(SkScalar tx, SkScalar ty) override
PrerollDelegate(const SkRect &cull_rect, const SkMatrix &matrix)
FML_DISALLOW_COPY_ASSIGN_AND_MOVE(SaveEntry)
void apply(LayerStateStack *stack) const override
void restore(LayerStateStack *stack) const override
const LayerStateStack::RenderingAttributes old_attributes_
SaveLayerEntry(const SkRect &bounds, DlBlendMode blend_mode, const LayerStateStack::RenderingAttributes &prev)
void apply(LayerStateStack *stack) const override
void restore(LayerStateStack *stack) const override
FML_DISALLOW_COPY_ASSIGN_AND_MOVE(SaveLayerEntry)
const DlBlendMode blend_mode_
TransformM44Entry(const SkM44 &m44)
void apply(LayerStateStack *stack) const override
void update_mutators(MutatorsStack *mutators_stack) const override
void update_mutators(MutatorsStack *mutators_stack) const override
TransformMatrixEntry(const SkMatrix &matrix)
void apply(LayerStateStack *stack) const override
void apply(LayerStateStack *stack) const override
void update_mutators(MutatorsStack *mutators_stack) const override
TranslateEntry(SkScalar tx, SkScalar ty)
FlutterSemanticsFlag flags
#define FML_DCHECK(condition)
static SkColor blend(SkColor dst, SkColor src, void(*mode)(float, float, float, float *, float *, float *))
static float max(float r, float g, float b)
unsigned useCenter Optional< SkMatrix > matrix
Optional< SkRect > bounds
sk_sp< const SkImageFilter > backdrop
sk_sp< SkBlender > blender SkRect rect
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
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
static constexpr SkRect kGiantRect
@ kSrcOver
r = s + (1-sa)*d
static constexpr uint8_t toAlpha(SkScalar opacity)
static bool ComputeIntegralTransCTM(const SkMatrix &in, SkMatrix *out)
Snap the translation components of the |in| matrix to integers and store the snapped matrix in |out|.
#define TRACE_EVENT0(category_group, name)