@@ -12,18 +12,14 @@ namespace impeller {
1212
1313Canvas::Canvas () {
1414 xformation_stack_.push ({});
15-
16- Paint default_paint;
17- default_paint.color = Color::White ();
18- paint_stack_.push (default_paint);
15+ passes_.emplace_back (CanvasPass{});
1916}
2017
2118Canvas::~Canvas () = default ;
2219
2320void Canvas::Save () {
2421 FML_DCHECK (xformation_stack_.size () > 0 );
2522 xformation_stack_.push (xformation_stack_.top ());
26- paint_stack_.push (paint_stack_.top ());
2723}
2824
2925bool Canvas::Restore () {
@@ -32,7 +28,6 @@ bool Canvas::Restore() {
3228 return false ;
3329 }
3430 xformation_stack_.pop ();
35- paint_stack_.pop ();
3631 return true ;
3732}
3833
@@ -69,46 +64,49 @@ void Canvas::RestoreToCount(size_t count) {
6964}
7065
7166void Canvas::DrawPath (Path path, Paint paint) {
72- Color color = paint.color ;
73- color.alpha *= paint_stack_.top ().color .alpha ;
74-
7567 Entity entity;
7668 entity.SetTransformation (GetCurrentTransformation ());
7769 entity.SetPath (std::move (path));
78- entity.SetBackgroundColor (color);
79- entity.SetContents (std::move (paint.contents ));
80-
81- ops_.emplace_back (std::move (entity));
70+ entity.SetContents (paint.CreateContentsForEntity ());
71+ GetCurrentPass ().PushEntity (std::move (entity));
8272}
8373
8474void Canvas::SaveLayer (const Paint& paint, std::optional<Rect> bounds) {
8575 Save ();
86- paint_stack_.top () = paint;
8776}
8877
8978void Canvas::ClipPath (Path path) {
9079 Entity entity;
9180 entity.SetTransformation (GetCurrentTransformation ());
9281 entity.SetPath (std::move (path));
9382 entity.SetIsClip (true );
94- ops_. emplace_back (std::move (entity));
83+ GetCurrentPass (). PushEntity (std::move (entity));
9584}
9685
9786void Canvas::DrawShadow (Path path, Color color, Scalar elevation) {}
9887
9988void Canvas::DrawPicture (const Picture& picture) {
100- for (const auto & entity : picture.entities ) {
101- auto new_entity = entity;
102- new_entity.SetTransformation (GetCurrentTransformation () *
103- new_entity.GetTransformation ());
104- ops_.emplace_back (std::move (new_entity));
89+ for (const auto & pass : picture.passes ) {
90+ CanvasPass new_pass;
91+ for (const auto & entity : pass.GetPassEntities ()) {
92+ auto new_entity = entity;
93+ new_entity.SetTransformation (GetCurrentTransformation () *
94+ entity.GetTransformation ());
95+ new_pass.PushEntity (std::move (new_entity));
96+ }
97+ passes_.emplace_back (std::move (new_pass));
10598 }
10699}
107100
108101Picture Canvas::EndRecordingAsPicture () {
109102 Picture picture;
110- picture.entities = std::move (ops_ );
103+ picture.passes = std::move (passes_ );
111104 return picture;
112105}
113106
107+ CanvasPass& Canvas::GetCurrentPass () {
108+ FML_DCHECK (!passes_.empty ());
109+ return passes_.back ();
110+ }
111+
114112} // namespace impeller
0 commit comments