@@ -117,6 +117,7 @@ Canvas::~Canvas() = default;
117
117
void Canvas::Initialize (std::optional<Rect> cull_rect) {
118
118
initial_cull_rect_ = cull_rect;
119
119
base_pass_ = std::make_unique<EntityPass>();
120
+ base_pass_->SetNewClipDepth (++current_depth_);
120
121
current_pass_ = base_pass_.get ();
121
122
transform_stack_.emplace_back (CanvasStackEntry{.cull_rect = cull_rect});
122
123
FML_DCHECK (GetSaveCount () == 1u );
@@ -126,6 +127,7 @@ void Canvas::Initialize(std::optional<Rect> cull_rect) {
126
127
void Canvas::Reset () {
127
128
base_pass_ = nullptr ;
128
129
current_pass_ = nullptr ;
130
+ current_depth_ = 0u ;
129
131
transform_stack_ = {};
130
132
}
131
133
@@ -174,6 +176,7 @@ void Canvas::Save(bool create_subpass,
174
176
if (create_subpass) {
175
177
entry.rendering_mode = Entity::RenderingMode::kSubpass ;
176
178
auto subpass = std::make_unique<EntityPass>();
179
+ subpass->SetNewClipDepth (++current_depth_);
177
180
subpass->SetEnableOffscreenCheckerboard (
178
181
debug_options.offscreen_texture_checkerboard );
179
182
if (backdrop_filter) {
@@ -206,16 +209,16 @@ bool Canvas::Restore() {
206
209
if (transform_stack_.size () == 1 ) {
207
210
return false ;
208
211
}
212
+ size_t num_clips = transform_stack_.back ().num_clips ;
209
213
if (transform_stack_.back ().rendering_mode ==
210
214
Entity::RenderingMode::kSubpass ) {
215
+ current_pass_->PopClips (num_clips, current_depth_);
211
216
current_pass_ = GetCurrentPass ().GetSuperpass ();
212
217
FML_DCHECK (current_pass_);
213
218
}
214
219
215
- bool contains_clips = transform_stack_.back ().contains_clips ;
216
220
transform_stack_.pop_back ();
217
-
218
- if (contains_clips) {
221
+ if (num_clips > 0 ) {
219
222
RestoreClip ();
220
223
}
221
224
@@ -290,7 +293,7 @@ void Canvas::DrawPath(const Path& path, const Paint& paint) {
290
293
entity.SetBlendMode (paint.blend_mode );
291
294
entity.SetContents (CreatePathContentsWithFilters (paint, path));
292
295
293
- GetCurrentPass (). AddEntity (std::move (entity));
296
+ AddEntityToCurrentPass (std::move (entity));
294
297
}
295
298
296
299
void Canvas::DrawPaint (const Paint& paint) {
@@ -300,7 +303,7 @@ void Canvas::DrawPaint(const Paint& paint) {
300
303
entity.SetBlendMode (paint.blend_mode );
301
304
entity.SetContents (CreateCoverContentsWithFilters (paint));
302
305
303
- GetCurrentPass (). AddEntity (std::move (entity));
306
+ AddEntityToCurrentPass (std::move (entity));
304
307
}
305
308
306
309
bool Canvas::AttemptDrawBlurredRRect (const Rect& rect,
@@ -338,7 +341,7 @@ bool Canvas::AttemptDrawBlurredRRect(const Rect& rect,
338
341
entity.SetBlendMode (new_paint.blend_mode );
339
342
entity.SetContents (new_paint.WithFilters (std::move (contents)));
340
343
341
- GetCurrentPass (). AddEntity (std::move (entity));
344
+ AddEntityToCurrentPass (std::move (entity));
342
345
343
346
return true ;
344
347
}
@@ -351,7 +354,7 @@ void Canvas::DrawLine(const Point& p0, const Point& p1, const Paint& paint) {
351
354
entity.SetContents (CreateContentsForGeometryWithFilters (
352
355
paint, Geometry::MakeLine (p0, p1, paint.stroke_width , paint.stroke_cap )));
353
356
354
- GetCurrentPass (). AddEntity (std::move (entity));
357
+ AddEntityToCurrentPass (std::move (entity));
355
358
}
356
359
357
360
void Canvas::DrawRect (const Rect& rect, const Paint& paint) {
@@ -371,7 +374,7 @@ void Canvas::DrawRect(const Rect& rect, const Paint& paint) {
371
374
entity.SetContents (
372
375
CreateContentsForGeometryWithFilters (paint, Geometry::MakeRect (rect)));
373
376
374
- GetCurrentPass (). AddEntity (std::move (entity));
377
+ AddEntityToCurrentPass (std::move (entity));
375
378
}
376
379
377
380
void Canvas::DrawOval (const Rect& rect, const Paint& paint) {
@@ -398,7 +401,7 @@ void Canvas::DrawOval(const Rect& rect, const Paint& paint) {
398
401
entity.SetContents (
399
402
CreateContentsForGeometryWithFilters (paint, Geometry::MakeOval (rect)));
400
403
401
- GetCurrentPass (). AddEntity (std::move (entity));
404
+ AddEntityToCurrentPass (std::move (entity));
402
405
}
403
406
404
407
void Canvas::DrawRRect (const Rect& rect,
@@ -416,7 +419,7 @@ void Canvas::DrawRRect(const Rect& rect,
416
419
entity.SetContents (CreateContentsForGeometryWithFilters (
417
420
paint, Geometry::MakeRoundRect (rect, corner_radii)));
418
421
419
- GetCurrentPass (). AddEntity (std::move (entity));
422
+ AddEntityToCurrentPass (std::move (entity));
420
423
return ;
421
424
}
422
425
@@ -449,7 +452,7 @@ void Canvas::DrawCircle(const Point& center,
449
452
entity.SetContents (
450
453
CreateContentsForGeometryWithFilters (paint, std::move (geometry)));
451
454
452
- GetCurrentPass (). AddEntity (std::move (entity));
455
+ AddEntityToCurrentPass (std::move (entity));
453
456
}
454
457
455
458
void Canvas::ClipPath (const Path& path, Entity::ClipOperation clip_op) {
@@ -554,10 +557,10 @@ void Canvas::ClipGeometry(const std::shared_ptr<Geometry>& geometry,
554
557
entity.SetContents (std::move (contents));
555
558
entity.SetClipDepth (GetClipDepth ());
556
559
557
- GetCurrentPass ().AddEntity (std::move (entity));
560
+ GetCurrentPass ().PushClip (std::move (entity));
558
561
559
562
++transform_stack_.back ().clip_depth ;
560
- transform_stack_.back ().contains_clips = true ;
563
+ ++ transform_stack_.back ().num_clips ;
561
564
}
562
565
563
566
void Canvas::IntersectCulling (Rect clip_rect) {
@@ -593,7 +596,8 @@ void Canvas::RestoreClip() {
593
596
entity.SetContents (std::make_shared<ClipRestoreContents>());
594
597
entity.SetClipDepth (GetClipDepth ());
595
598
596
- GetCurrentPass ().AddEntity (std::move (entity));
599
+ // TODO(bdero): To be removed when swapping the clip strategy.
600
+ AddEntityToCurrentPass (std::move (entity));
597
601
}
598
602
599
603
void Canvas::DrawPoints (std::vector<Point> points,
@@ -613,7 +617,7 @@ void Canvas::DrawPoints(std::vector<Point> points,
613
617
Geometry::MakePointField (std::move (points), radius,
614
618
/* round=*/ point_style == PointStyle::kRound )));
615
619
616
- GetCurrentPass (). AddEntity (std::move (entity));
620
+ AddEntityToCurrentPass (std::move (entity));
617
621
}
618
622
619
623
void Canvas::DrawPicture (const Picture& picture) {
@@ -690,10 +694,16 @@ void Canvas::DrawImageRect(const std::shared_ptr<Image>& image,
690
694
entity.SetContents (paint.WithFilters (contents));
691
695
entity.SetTransform (GetCurrentTransform ());
692
696
693
- GetCurrentPass (). AddEntity (std::move (entity));
697
+ AddEntityToCurrentPass (std::move (entity));
694
698
}
695
699
696
700
Picture Canvas::EndRecordingAsPicture () {
701
+ // Assign clip depths to any outstanding clip entities.
702
+ while (current_pass_ != nullptr ) {
703
+ current_pass_->PopAllClips (current_depth_);
704
+ current_pass_ = current_pass_->GetSuperpass ();
705
+ }
706
+
697
707
Picture picture;
698
708
picture.pass = std::move (base_pass_);
699
709
@@ -712,6 +722,11 @@ size_t Canvas::GetClipDepth() const {
712
722
return transform_stack_.back ().clip_depth ;
713
723
}
714
724
725
+ void Canvas::AddEntityToCurrentPass (Entity entity) {
726
+ entity.SetNewClipDepth (++current_depth_);
727
+ GetCurrentPass ().AddEntity (std::move (entity));
728
+ }
729
+
715
730
void Canvas::SaveLayer (const Paint& paint,
716
731
std::optional<Rect> bounds,
717
732
const std::shared_ptr<ImageFilter>& backdrop_filter) {
@@ -768,7 +783,7 @@ void Canvas::DrawTextFrame(const std::shared_ptr<TextFrame>& text_frame,
768
783
entity.SetContents (
769
784
paint.WithFilters (paint.WithMaskBlur (std::move (text_contents), true )));
770
785
771
- GetCurrentPass (). AddEntity (std::move (entity));
786
+ AddEntityToCurrentPass (std::move (entity));
772
787
}
773
788
774
789
static bool UseColorSourceContents (
@@ -807,7 +822,7 @@ void Canvas::DrawVertices(const std::shared_ptr<VerticesGeometry>& vertices,
807
822
// are vertex coordinates then only if the contents are an image.
808
823
if (UseColorSourceContents (vertices, paint)) {
809
824
entity.SetContents (CreateContentsForGeometryWithFilters (paint, vertices));
810
- GetCurrentPass (). AddEntity (std::move (entity));
825
+ AddEntityToCurrentPass (std::move (entity));
811
826
return ;
812
827
}
813
828
@@ -845,7 +860,7 @@ void Canvas::DrawVertices(const std::shared_ptr<VerticesGeometry>& vertices,
845
860
contents->SetSourceContents (std::move (src_contents));
846
861
entity.SetContents (paint.WithFilters (std::move (contents)));
847
862
848
- GetCurrentPass (). AddEntity (std::move (entity));
863
+ AddEntityToCurrentPass (std::move (entity));
849
864
}
850
865
851
866
void Canvas::DrawAtlas (const std::shared_ptr<Image>& atlas,
@@ -876,7 +891,7 @@ void Canvas::DrawAtlas(const std::shared_ptr<Image>& atlas,
876
891
entity.SetBlendMode (paint.blend_mode );
877
892
entity.SetContents (paint.WithFilters (contents));
878
893
879
- GetCurrentPass (). AddEntity (std::move (entity));
894
+ AddEntityToCurrentPass (std::move (entity));
880
895
}
881
896
882
897
} // namespace impeller
0 commit comments