Skip to content

Commit

Permalink
Move entity pass management to the entity framework.
Browse files Browse the repository at this point in the history
  • Loading branch information
chinmaygarde authored and dnfield committed Apr 27, 2022
1 parent 18f8e72 commit d00efdd
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 56 deletions.
4 changes: 0 additions & 4 deletions impeller/aiks/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions impeller/aiks/canvas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -173,7 +173,7 @@ Picture Canvas::EndRecordingAsPicture() {
return picture;
}

CanvasPass& Canvas::GetCurrentPass() {
EntityPass& Canvas::GetCurrentPass() {
FML_DCHECK(current_pass_ != nullptr);
return *current_pass_;
}
Expand All @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions impeller/aiks/canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions impeller/aiks/picture.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions impeller/entity/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
Expand Down
36 changes: 18 additions & 18 deletions impeller/aiks/canvas_pass.cc → impeller/entity/entity_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 =
Expand All @@ -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();
Expand All @@ -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;
}
Expand All @@ -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)) {
Expand Down Expand Up @@ -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;
}
Expand All @@ -188,20 +188,20 @@ 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());
}
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;
}

Expand Down
24 changes: 13 additions & 11 deletions impeller/aiks/canvas_pass.h → impeller/entity/entity_pass.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;

Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@

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;

virtual std::shared_ptr<Contents> CreateContentsForSubpassTarget(
const Texture& target) = 0;

private:
FML_DISALLOW_COPY_AND_ASSIGN(CanvasPassDelegate);
FML_DISALLOW_COPY_AND_ASSIGN(EntityPassDelegate);
};

} // namespace impeller

0 comments on commit d00efdd

Please sign in to comment.