Move entity pass management to the entity framework.

This commit is contained in:
Chinmay Garde 2021-11-28 13:38:17 -08:00 committed by Dan Field
parent 30b243cdf7
commit eef8ccc51c
9 changed files with 58 additions and 56 deletions

View File

@ -10,10 +10,6 @@ impeller_component("aiks") {
"aiks_renderer.h",
"canvas.cc",
"canvas.h",
"canvas_pass.cc",
"canvas_pass.h",
"canvas_pass_delegate.cc",
"canvas_pass_delegate.h",
"image.cc",
"image.h",
"paint.cc",

View File

@ -18,7 +18,7 @@ Canvas::Canvas() {
Canvas::~Canvas() = default;
void Canvas::Initialize() {
base_pass_ = std::make_unique<CanvasPass>();
base_pass_ = std::make_unique<EntityPass>();
current_pass_ = base_pass_.get();
xformation_stack_.emplace_back(CanvasStackEntry{});
FML_DCHECK(GetSaveCount() == 1u);
@ -173,7 +173,7 @@ Picture Canvas::EndRecordingAsPicture() {
return picture;
}
CanvasPass& Canvas::GetCurrentPass() {
EntityPass& Canvas::GetCurrentPass() {
FML_DCHECK(current_pass_ != nullptr);
return *current_pass_;
}
@ -194,7 +194,7 @@ void Canvas::Save(bool create_subpass) {
auto entry = CanvasStackEntry{};
if (create_subpass) {
entry.is_subpass = true;
current_pass_ = GetCurrentPass().AddSubpass(std::make_unique<CanvasPass>());
current_pass_ = GetCurrentPass().AddSubpass(std::make_unique<EntityPass>());
current_pass_->SetTransformation(xformation_stack_.back().xformation);
current_pass_->SetStencilDepth(xformation_stack_.back().stencil_depth);
} else {

View File

@ -10,10 +10,10 @@
#include <vector>
#include "flutter/fml/macros.h"
#include "impeller/aiks/canvas_pass.h"
#include "impeller/aiks/image.h"
#include "impeller/aiks/paint.h"
#include "impeller/aiks/picture.h"
#include "impeller/entity/entity_pass.h"
#include "impeller/geometry/matrix.h"
#include "impeller/geometry/path.h"
#include "impeller/geometry/point.h"
@ -69,15 +69,15 @@ class Canvas {
Picture EndRecordingAsPicture();
private:
std::unique_ptr<CanvasPass> base_pass_;
CanvasPass* current_pass_ = nullptr;
std::unique_ptr<EntityPass> base_pass_;
EntityPass* current_pass_ = nullptr;
std::deque<CanvasStackEntry> xformation_stack_;
void Initialize();
void Reset();
CanvasPass& GetCurrentPass();
EntityPass& GetCurrentPass();
void IncrementStencilDepth();

View File

@ -8,13 +8,13 @@
#include <memory>
#include "flutter/fml/macros.h"
#include "impeller/aiks/canvas_pass.h"
#include "impeller/entity/entity.h"
#include "impeller/entity/entity_pass.h"
namespace impeller {
struct Picture {
std::unique_ptr<CanvasPass> pass;
std::unique_ptr<EntityPass> pass;
};
} // namespace impeller

View File

@ -27,6 +27,10 @@ impeller_component("entity") {
"contents.h",
"entity.cc",
"entity.h",
"entity_pass.cc",
"entity_pass.h",
"entity_pass_delegate.cc",
"entity_pass_delegate.h",
]
deps = [ ":entity_shaders" ]

View File

@ -2,7 +2,7 @@
// 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"
#include "impeller/entity/entity_pass.h"
#include "impeller/entity/content_renderer.h"
#include "impeller/geometry/path_builder.h"
@ -11,28 +11,28 @@
namespace impeller {
CanvasPass::CanvasPass(std::unique_ptr<CanvasPassDelegate> delegate)
EntityPass::EntityPass(std::unique_ptr<EntityPassDelegate> delegate)
: delegate_(std::move(delegate)) {
if (!delegate_) {
delegate_ = CanvasPassDelegate::MakeDefault();
delegate_ = EntityPassDelegate::MakeDefault();
}
}
CanvasPass::~CanvasPass() = default;
EntityPass::~EntityPass() = default;
void CanvasPass::AddEntity(Entity entity) {
void EntityPass::AddEntity(Entity entity) {
entities_.emplace_back(std::move(entity));
}
const std::vector<Entity>& CanvasPass::GetEntities() const {
const std::vector<Entity>& EntityPass::GetEntities() const {
return entities_;
}
void CanvasPass::SetEntities(Entities entities) {
void EntityPass::SetEntities(Entities entities) {
entities_ = std::move(entities);
}
size_t CanvasPass::GetSubpassesDepth() const {
size_t EntityPass::GetSubpassesDepth() const {
size_t max_subpass_depth = 0u;
for (const auto& subpass : subpasses_) {
max_subpass_depth =
@ -41,7 +41,7 @@ size_t CanvasPass::GetSubpassesDepth() const {
return max_subpass_depth + 1u;
}
Rect CanvasPass::GetCoverageRect() const {
Rect EntityPass::GetCoverageRect() const {
std::optional<Point> min, max;
for (const auto& entity : entities_) {
auto coverage = entity.GetPath().GetMinMaxCoveragePoints();
@ -64,15 +64,15 @@ Rect CanvasPass::GetCoverageRect() const {
return {min->x, min->y, diff.x, diff.y};
}
CanvasPass* CanvasPass::GetSuperpass() const {
EntityPass* EntityPass::GetSuperpass() const {
return superpass_;
}
const CanvasPass::Subpasses& CanvasPass::GetSubpasses() const {
const EntityPass::Subpasses& EntityPass::GetSubpasses() const {
return subpasses_;
}
CanvasPass* CanvasPass::AddSubpass(std::unique_ptr<CanvasPass> pass) {
EntityPass* EntityPass::AddSubpass(std::unique_ptr<EntityPass> pass) {
if (!pass) {
return nullptr;
}
@ -81,7 +81,7 @@ CanvasPass* CanvasPass::AddSubpass(std::unique_ptr<CanvasPass> pass) {
return subpasses_.emplace_back(std::move(pass)).get();
}
bool CanvasPass::Render(ContentRenderer& renderer,
bool EntityPass::Render(ContentRenderer& renderer,
RenderPass& parent_pass) const {
for (const auto& entity : entities_) {
if (!entity.Render(renderer, parent_pass)) {
@ -172,7 +172,7 @@ bool CanvasPass::Render(ContentRenderer& renderer,
return true;
}
void CanvasPass::IterateAllEntities(std::function<bool(Entity&)> iterator) {
void EntityPass::IterateAllEntities(std::function<bool(Entity&)> iterator) {
if (!iterator) {
return;
}
@ -188,8 +188,8 @@ void CanvasPass::IterateAllEntities(std::function<bool(Entity&)> iterator) {
}
}
std::unique_ptr<CanvasPass> CanvasPass::Clone() const {
auto pass = std::make_unique<CanvasPass>();
std::unique_ptr<EntityPass> EntityPass::Clone() const {
auto pass = std::make_unique<EntityPass>();
pass->SetEntities(entities_);
for (const auto& subpass : subpasses_) {
pass->AddSubpass(subpass->Clone());
@ -197,11 +197,11 @@ std::unique_ptr<CanvasPass> CanvasPass::Clone() const {
return pass;
}
void CanvasPass::SetTransformation(Matrix xformation) {
void EntityPass::SetTransformation(Matrix xformation) {
xformation_ = std::move(xformation);
}
void CanvasPass::SetStencilDepth(size_t stencil_depth) {
void EntityPass::SetStencilDepth(size_t stencil_depth) {
stencil_depth_ = stencil_depth;
}

View File

@ -9,30 +9,32 @@
#include <vector>
#include "flutter/fml/macros.h"
#include "impeller/aiks/canvas_pass_delegate.h"
#include "impeller/entity/contents.h"
#include "impeller/entity/entity.h"
#include "impeller/entity/entity_pass_delegate.h"
#include "impeller/renderer/render_target.h"
namespace impeller {
class ContentRenderer;
class CanvasPass {
class EntityPass {
public:
using Entities = std::vector<Entity>;
using Subpasses = std::vector<std::unique_ptr<CanvasPass>>;
using Subpasses = std::vector<std::unique_ptr<EntityPass>>;
CanvasPass(std::unique_ptr<CanvasPassDelegate> delegate = nullptr);
EntityPass(std::unique_ptr<EntityPassDelegate> delegate = nullptr);
~CanvasPass();
~EntityPass();
size_t GetSubpassesDepth() const;
std::unique_ptr<CanvasPass> Clone() const;
std::unique_ptr<EntityPass> Clone() const;
Rect GetCoverageRect() const;
// TODO(csg): This prevents an optimization where the coverage can be
// calculated once in SetEntities an memoized.
void AddEntity(Entity entity);
void SetEntities(Entities entities);
@ -41,9 +43,9 @@ class CanvasPass {
const Subpasses& GetSubpasses() const;
CanvasPass* AddSubpass(std::unique_ptr<CanvasPass> pass);
EntityPass* AddSubpass(std::unique_ptr<EntityPass> pass);
CanvasPass* GetSuperpass() const;
EntityPass* GetSuperpass() const;
bool Render(ContentRenderer& renderer, RenderPass& parent_pass) const;
@ -56,12 +58,12 @@ class CanvasPass {
private:
Entities entities_;
Subpasses subpasses_;
CanvasPass* superpass_ = nullptr;
EntityPass* superpass_ = nullptr;
Matrix xformation_;
size_t stencil_depth_ = 0u;
std::unique_ptr<CanvasPassDelegate> delegate_;
std::unique_ptr<EntityPassDelegate> delegate_;
FML_DISALLOW_COPY_AND_ASSIGN(CanvasPass);
FML_DISALLOW_COPY_AND_ASSIGN(EntityPass);
};
struct CanvasStackEntry {

View File

@ -2,19 +2,19 @@
// 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_delegate.h"
#include "impeller/entity/entity_pass_delegate.h"
namespace impeller {
CanvasPassDelegate::CanvasPassDelegate() = default;
EntityPassDelegate::EntityPassDelegate() = default;
CanvasPassDelegate::~CanvasPassDelegate() = default;
EntityPassDelegate::~EntityPassDelegate() = default;
class DefaultCanvasPassDelegate final : public CanvasPassDelegate {
class DefaultEntityPassDelegate final : public EntityPassDelegate {
public:
DefaultCanvasPassDelegate() = default;
DefaultEntityPassDelegate() = default;
~DefaultCanvasPassDelegate() override = default;
~DefaultEntityPassDelegate() override = default;
bool CanCollapseIntoParentPass() override { return true; }
@ -25,11 +25,11 @@ class DefaultCanvasPassDelegate final : public CanvasPassDelegate {
}
private:
FML_DISALLOW_COPY_AND_ASSIGN(DefaultCanvasPassDelegate);
FML_DISALLOW_COPY_AND_ASSIGN(DefaultEntityPassDelegate);
};
std::unique_ptr<CanvasPassDelegate> CanvasPassDelegate::MakeDefault() {
return std::make_unique<DefaultCanvasPassDelegate>();
std::unique_ptr<EntityPassDelegate> EntityPassDelegate::MakeDefault() {
return std::make_unique<DefaultEntityPassDelegate>();
}
} // namespace impeller

View File

@ -12,13 +12,13 @@
namespace impeller {
class CanvasPassDelegate {
class EntityPassDelegate {
public:
static std::unique_ptr<CanvasPassDelegate> MakeDefault();
static std::unique_ptr<EntityPassDelegate> MakeDefault();
CanvasPassDelegate();
EntityPassDelegate();
virtual ~CanvasPassDelegate();
virtual ~EntityPassDelegate();
virtual bool CanCollapseIntoParentPass() = 0;
@ -26,7 +26,7 @@ class CanvasPassDelegate {
const Texture& target) = 0;
private:
FML_DISALLOW_COPY_AND_ASSIGN(CanvasPassDelegate);
FML_DISALLOW_COPY_AND_ASSIGN(EntityPassDelegate);
};
} // namespace impeller