diff --git a/engine/src/flutter/impeller/aiks/BUILD.gn b/engine/src/flutter/impeller/aiks/BUILD.gn index 39ad62609f..ce098d2b4a 100644 --- a/engine/src/flutter/impeller/aiks/BUILD.gn +++ b/engine/src/flutter/impeller/aiks/BUILD.gn @@ -8,6 +8,8 @@ impeller_component("aiks") { sources = [ "canvas.cc", "canvas.h", + "canvas_pass.cc", + "canvas_pass.h", "image.cc", "image.h", "paint.cc", diff --git a/engine/src/flutter/impeller/aiks/canvas.cc b/engine/src/flutter/impeller/aiks/canvas.cc index edfda32088..b8a4b052a8 100644 --- a/engine/src/flutter/impeller/aiks/canvas.cc +++ b/engine/src/flutter/impeller/aiks/canvas.cc @@ -12,10 +12,7 @@ namespace impeller { Canvas::Canvas() { xformation_stack_.push({}); - - Paint default_paint; - default_paint.color = Color::White(); - paint_stack_.push(default_paint); + passes_.emplace_back(CanvasPass{}); } Canvas::~Canvas() = default; @@ -23,7 +20,6 @@ Canvas::~Canvas() = default; void Canvas::Save() { FML_DCHECK(xformation_stack_.size() > 0); xformation_stack_.push(xformation_stack_.top()); - paint_stack_.push(paint_stack_.top()); } bool Canvas::Restore() { @@ -32,7 +28,6 @@ bool Canvas::Restore() { return false; } xformation_stack_.pop(); - paint_stack_.pop(); return true; } @@ -69,21 +64,15 @@ void Canvas::RestoreToCount(size_t count) { } void Canvas::DrawPath(Path path, Paint paint) { - Color color = paint.color; - color.alpha *= paint_stack_.top().color.alpha; - Entity entity; entity.SetTransformation(GetCurrentTransformation()); entity.SetPath(std::move(path)); - entity.SetBackgroundColor(color); - entity.SetContents(std::move(paint.contents)); - - ops_.emplace_back(std::move(entity)); + entity.SetContents(paint.CreateContentsForEntity()); + GetCurrentPass().PushEntity(std::move(entity)); } void Canvas::SaveLayer(const Paint& paint, std::optional bounds) { Save(); - paint_stack_.top() = paint; } void Canvas::ClipPath(Path path) { @@ -91,24 +80,33 @@ void Canvas::ClipPath(Path path) { entity.SetTransformation(GetCurrentTransformation()); entity.SetPath(std::move(path)); entity.SetIsClip(true); - ops_.emplace_back(std::move(entity)); + GetCurrentPass().PushEntity(std::move(entity)); } void Canvas::DrawShadow(Path path, Color color, Scalar elevation) {} void Canvas::DrawPicture(const Picture& picture) { - for (const auto& entity : picture.entities) { - auto new_entity = entity; - new_entity.SetTransformation(GetCurrentTransformation() * - new_entity.GetTransformation()); - ops_.emplace_back(std::move(new_entity)); + for (const auto& pass : picture.passes) { + CanvasPass new_pass; + for (const auto& entity : pass.GetPassEntities()) { + auto new_entity = entity; + new_entity.SetTransformation(GetCurrentTransformation() * + entity.GetTransformation()); + new_pass.PushEntity(std::move(new_entity)); + } + passes_.emplace_back(std::move(new_pass)); } } Picture Canvas::EndRecordingAsPicture() { Picture picture; - picture.entities = std::move(ops_); + picture.passes = std::move(passes_); return picture; } +CanvasPass& Canvas::GetCurrentPass() { + FML_DCHECK(!passes_.empty()); + return passes_.back(); +} + } // namespace impeller diff --git a/engine/src/flutter/impeller/aiks/canvas.h b/engine/src/flutter/impeller/aiks/canvas.h index 6cb9fcec37..4dedd32241 100644 --- a/engine/src/flutter/impeller/aiks/canvas.h +++ b/engine/src/flutter/impeller/aiks/canvas.h @@ -10,6 +10,7 @@ #include #include "flutter/fml/macros.h" +#include "impeller/aiks/canvas_pass.h" #include "impeller/aiks/paint.h" #include "impeller/aiks/picture.h" #include "impeller/geometry/matrix.h" @@ -58,8 +59,9 @@ class Canvas { private: std::stack xformation_stack_; - std::stack paint_stack_; - std::vector ops_; + std::vector passes_; + + CanvasPass& GetCurrentPass(); FML_DISALLOW_COPY_AND_ASSIGN(Canvas); }; diff --git a/engine/src/flutter/impeller/aiks/canvas_pass.cc b/engine/src/flutter/impeller/aiks/canvas_pass.cc new file mode 100644 index 0000000000..7ea207533a --- /dev/null +++ b/engine/src/flutter/impeller/aiks/canvas_pass.cc @@ -0,0 +1,21 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "impeller/aiks/canvas_pass.h" + +namespace impeller { + +CanvasPass::CanvasPass() = default; + +CanvasPass::~CanvasPass() = default; + +void CanvasPass::PushEntity(Entity entity) { + ops_.emplace_back(std::move(entity)); +} + +const std::vector& CanvasPass::GetPassEntities() const { + return ops_; +} + +} // namespace impeller diff --git a/engine/src/flutter/impeller/aiks/canvas_pass.h b/engine/src/flutter/impeller/aiks/canvas_pass.h new file mode 100644 index 0000000000..0183ade6c2 --- /dev/null +++ b/engine/src/flutter/impeller/aiks/canvas_pass.h @@ -0,0 +1,28 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#pragma once + +#include + +#include "flutter/fml/macros.h" +#include "impeller/entity/entity.h" + +namespace impeller { + +class CanvasPass { + public: + CanvasPass(); + + ~CanvasPass(); + + void PushEntity(Entity entity); + + const std::vector& GetPassEntities() const; + + private: + std::vector ops_; +}; + +} // namespace impeller diff --git a/engine/src/flutter/impeller/aiks/paint.cc b/engine/src/flutter/impeller/aiks/paint.cc index 05279a4ecc..e45f9a7645 100644 --- a/engine/src/flutter/impeller/aiks/paint.cc +++ b/engine/src/flutter/impeller/aiks/paint.cc @@ -6,6 +6,14 @@ namespace impeller { -// +std::shared_ptr Paint::CreateContentsForEntity() const { + if (!color.IsTransparent()) { + auto solid_color = std::make_shared(); + solid_color->SetColor(color); + return solid_color; + } + + return nullptr; +} } // namespace impeller diff --git a/engine/src/flutter/impeller/aiks/paint.h b/engine/src/flutter/impeller/aiks/paint.h index c3b947b8d8..7f59475fce 100644 --- a/engine/src/flutter/impeller/aiks/paint.h +++ b/engine/src/flutter/impeller/aiks/paint.h @@ -14,7 +14,8 @@ namespace impeller { struct Paint { Color color; Scalar stroke_width = 0.0; - std::shared_ptr contents; + + std::shared_ptr CreateContentsForEntity() const; }; } // namespace impeller diff --git a/engine/src/flutter/impeller/aiks/picture.h b/engine/src/flutter/impeller/aiks/picture.h index d65d272c48..048a81b98a 100644 --- a/engine/src/flutter/impeller/aiks/picture.h +++ b/engine/src/flutter/impeller/aiks/picture.h @@ -8,12 +8,13 @@ #include #include "flutter/fml/macros.h" +#include "impeller/aiks/canvas_pass.h" #include "impeller/entity/entity.h" namespace impeller { struct Picture { - std::vector entities; + std::vector passes; }; } // namespace impeller diff --git a/engine/src/flutter/impeller/aiks/picture_renderer.cc b/engine/src/flutter/impeller/aiks/picture_renderer.cc index ad613a0ccd..9f918a1837 100644 --- a/engine/src/flutter/impeller/aiks/picture_renderer.cc +++ b/engine/src/flutter/impeller/aiks/picture_renderer.cc @@ -29,10 +29,14 @@ bool PictureRenderer::Render(const Surface& surface, return false; } - return entity_renderer_.RenderEntities(surface, // - onscreen_pass, // - picture.entities // - ); + for (const auto& pass : picture.passes) { + if (!entity_renderer_.RenderEntities(surface, onscreen_pass, + pass.GetPassEntities())) { + return false; + } + } + + return true; } } // namespace impeller diff --git a/engine/src/flutter/impeller/entity/contents.cc b/engine/src/flutter/impeller/entity/contents.cc index dc2db4a477..7ce063119b 100644 --- a/engine/src/flutter/impeller/entity/contents.cc +++ b/engine/src/flutter/impeller/entity/contents.cc @@ -95,6 +95,10 @@ bool LinearGradientContents::Render(const ContentRenderer& renderer, ******* SolidColorContents ******************************************************************************/ +SolidColorContents::SolidColorContents() = default; + +SolidColorContents::~SolidColorContents() = default; + void SolidColorContents::SetColor(Color color) { color_ = color; } @@ -135,7 +139,7 @@ bool SolidColorContents::Render(const ContentRenderer& renderer, VS::FrameInfo frame_info; frame_info.mvp = Matrix::MakeOrthographic(surface.GetSize()) * entity.GetTransformation(); - frame_info.color = entity.GetBackgroundColor(); + frame_info.color = color_; VS::BindFrameInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frame_info)); cmd.primitive_type = PrimitiveType::kTriangle; diff --git a/engine/src/flutter/impeller/entity/contents.h b/engine/src/flutter/impeller/entity/contents.h index 0c04e5474c..2feedcfccf 100644 --- a/engine/src/flutter/impeller/entity/contents.h +++ b/engine/src/flutter/impeller/entity/contents.h @@ -84,7 +84,7 @@ class SolidStrokeContents final : public Contents { public: SolidStrokeContents(); - ~SolidStrokeContents(); + ~SolidStrokeContents() override; void SetColor(Color color); diff --git a/engine/src/flutter/impeller/entity/entity.cc b/engine/src/flutter/impeller/entity/entity.cc index bc8d81aae4..77ab4ccd27 100644 --- a/engine/src/flutter/impeller/entity/entity.cc +++ b/engine/src/flutter/impeller/entity/entity.cc @@ -18,14 +18,6 @@ void Entity::SetTransformation(const Matrix& transformation) { transformation_ = transformation; } -const Color& Entity::GetBackgroundColor() const { - return background_color_; -} - -void Entity::SetBackgroundColor(const Color& backgroundColor) { - background_color_ = backgroundColor; -} - const Color& Entity::GetStrokeColor() const { return stroke_color_; } diff --git a/engine/src/flutter/impeller/entity/entity.h b/engine/src/flutter/impeller/entity/entity.h index bb40679270..4ee9bf2e26 100644 --- a/engine/src/flutter/impeller/entity/entity.h +++ b/engine/src/flutter/impeller/entity/entity.h @@ -23,10 +23,6 @@ class Entity { void SetTransformation(const Matrix& transformation); - const Color& GetBackgroundColor() const; - - void SetBackgroundColor(const Color& backgroundColor); - const Color& GetStrokeColor() const; void SetStrokeColor(const Color& strokeColor); @@ -49,9 +45,7 @@ class Entity { private: Matrix transformation_; - Color background_color_; std::shared_ptr contents_; - Path path_; Color stroke_color_; double stroke_size_ = 1.0; diff --git a/engine/src/flutter/impeller/entity/entity_renderer.cc b/engine/src/flutter/impeller/entity/entity_renderer.cc index 77e1369754..0b35bb5ca8 100644 --- a/engine/src/flutter/impeller/entity/entity_renderer.cc +++ b/engine/src/flutter/impeller/entity/entity_renderer.cc @@ -37,9 +37,11 @@ bool EntityRenderer::RenderEntities(const Surface& surface, } for (const auto& entity : entities) { - if (auto contents = entity.GetContents(); - !contents->Render(*content_renderer_, entity, surface, onscreen_pass)) { - return false; + if (auto contents = entity.GetContents()) { + if (!contents->Render(*content_renderer_, entity, surface, + onscreen_pass)) { + return false; + } } }