Skip to content

Commit d00efdd

Browse files
chinmaygardednfield
authored andcommitted
Move entity pass management to the entity framework.
1 parent 18f8e72 commit d00efdd

9 files changed

+58
-56
lines changed

impeller/aiks/BUILD.gn

-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ impeller_component("aiks") {
1010
"aiks_renderer.h",
1111
"canvas.cc",
1212
"canvas.h",
13-
"canvas_pass.cc",
14-
"canvas_pass.h",
15-
"canvas_pass_delegate.cc",
16-
"canvas_pass_delegate.h",
1713
"image.cc",
1814
"image.h",
1915
"paint.cc",

impeller/aiks/canvas.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Canvas::Canvas() {
1818
Canvas::~Canvas() = default;
1919

2020
void Canvas::Initialize() {
21-
base_pass_ = std::make_unique<CanvasPass>();
21+
base_pass_ = std::make_unique<EntityPass>();
2222
current_pass_ = base_pass_.get();
2323
xformation_stack_.emplace_back(CanvasStackEntry{});
2424
FML_DCHECK(GetSaveCount() == 1u);
@@ -173,7 +173,7 @@ Picture Canvas::EndRecordingAsPicture() {
173173
return picture;
174174
}
175175

176-
CanvasPass& Canvas::GetCurrentPass() {
176+
EntityPass& Canvas::GetCurrentPass() {
177177
FML_DCHECK(current_pass_ != nullptr);
178178
return *current_pass_;
179179
}
@@ -194,7 +194,7 @@ void Canvas::Save(bool create_subpass) {
194194
auto entry = CanvasStackEntry{};
195195
if (create_subpass) {
196196
entry.is_subpass = true;
197-
current_pass_ = GetCurrentPass().AddSubpass(std::make_unique<CanvasPass>());
197+
current_pass_ = GetCurrentPass().AddSubpass(std::make_unique<EntityPass>());
198198
current_pass_->SetTransformation(xformation_stack_.back().xformation);
199199
current_pass_->SetStencilDepth(xformation_stack_.back().stencil_depth);
200200
} else {

impeller/aiks/canvas.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
#include <vector>
1111

1212
#include "flutter/fml/macros.h"
13-
#include "impeller/aiks/canvas_pass.h"
1413
#include "impeller/aiks/image.h"
1514
#include "impeller/aiks/paint.h"
1615
#include "impeller/aiks/picture.h"
16+
#include "impeller/entity/entity_pass.h"
1717
#include "impeller/geometry/matrix.h"
1818
#include "impeller/geometry/path.h"
1919
#include "impeller/geometry/point.h"
@@ -69,15 +69,15 @@ class Canvas {
6969
Picture EndRecordingAsPicture();
7070

7171
private:
72-
std::unique_ptr<CanvasPass> base_pass_;
73-
CanvasPass* current_pass_ = nullptr;
72+
std::unique_ptr<EntityPass> base_pass_;
73+
EntityPass* current_pass_ = nullptr;
7474
std::deque<CanvasStackEntry> xformation_stack_;
7575

7676
void Initialize();
7777

7878
void Reset();
7979

80-
CanvasPass& GetCurrentPass();
80+
EntityPass& GetCurrentPass();
8181

8282
void IncrementStencilDepth();
8383

impeller/aiks/picture.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
#include <memory>
99

1010
#include "flutter/fml/macros.h"
11-
#include "impeller/aiks/canvas_pass.h"
1211
#include "impeller/entity/entity.h"
12+
#include "impeller/entity/entity_pass.h"
1313

1414
namespace impeller {
1515

1616
struct Picture {
17-
std::unique_ptr<CanvasPass> pass;
17+
std::unique_ptr<EntityPass> pass;
1818
};
1919

2020
} // namespace impeller

impeller/entity/BUILD.gn

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ impeller_component("entity") {
2727
"contents.h",
2828
"entity.cc",
2929
"entity.h",
30+
"entity_pass.cc",
31+
"entity_pass.h",
32+
"entity_pass_delegate.cc",
33+
"entity_pass_delegate.h",
3034
]
3135

3236
deps = [ ":entity_shaders" ]

impeller/aiks/canvas_pass.cc renamed to impeller/entity/entity_pass.cc

+18-18
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
#include "impeller/aiks/canvas_pass.h"
5+
#include "impeller/entity/entity_pass.h"
66

77
#include "impeller/entity/content_renderer.h"
88
#include "impeller/geometry/path_builder.h"
@@ -11,28 +11,28 @@
1111

1212
namespace impeller {
1313

14-
CanvasPass::CanvasPass(std::unique_ptr<CanvasPassDelegate> delegate)
14+
EntityPass::EntityPass(std::unique_ptr<EntityPassDelegate> delegate)
1515
: delegate_(std::move(delegate)) {
1616
if (!delegate_) {
17-
delegate_ = CanvasPassDelegate::MakeDefault();
17+
delegate_ = EntityPassDelegate::MakeDefault();
1818
}
1919
}
2020

21-
CanvasPass::~CanvasPass() = default;
21+
EntityPass::~EntityPass() = default;
2222

23-
void CanvasPass::AddEntity(Entity entity) {
23+
void EntityPass::AddEntity(Entity entity) {
2424
entities_.emplace_back(std::move(entity));
2525
}
2626

27-
const std::vector<Entity>& CanvasPass::GetEntities() const {
27+
const std::vector<Entity>& EntityPass::GetEntities() const {
2828
return entities_;
2929
}
3030

31-
void CanvasPass::SetEntities(Entities entities) {
31+
void EntityPass::SetEntities(Entities entities) {
3232
entities_ = std::move(entities);
3333
}
3434

35-
size_t CanvasPass::GetSubpassesDepth() const {
35+
size_t EntityPass::GetSubpassesDepth() const {
3636
size_t max_subpass_depth = 0u;
3737
for (const auto& subpass : subpasses_) {
3838
max_subpass_depth =
@@ -41,7 +41,7 @@ size_t CanvasPass::GetSubpassesDepth() const {
4141
return max_subpass_depth + 1u;
4242
}
4343

44-
Rect CanvasPass::GetCoverageRect() const {
44+
Rect EntityPass::GetCoverageRect() const {
4545
std::optional<Point> min, max;
4646
for (const auto& entity : entities_) {
4747
auto coverage = entity.GetPath().GetMinMaxCoveragePoints();
@@ -64,15 +64,15 @@ Rect CanvasPass::GetCoverageRect() const {
6464
return {min->x, min->y, diff.x, diff.y};
6565
}
6666

67-
CanvasPass* CanvasPass::GetSuperpass() const {
67+
EntityPass* EntityPass::GetSuperpass() const {
6868
return superpass_;
6969
}
7070

71-
const CanvasPass::Subpasses& CanvasPass::GetSubpasses() const {
71+
const EntityPass::Subpasses& EntityPass::GetSubpasses() const {
7272
return subpasses_;
7373
}
7474

75-
CanvasPass* CanvasPass::AddSubpass(std::unique_ptr<CanvasPass> pass) {
75+
EntityPass* EntityPass::AddSubpass(std::unique_ptr<EntityPass> pass) {
7676
if (!pass) {
7777
return nullptr;
7878
}
@@ -81,7 +81,7 @@ CanvasPass* CanvasPass::AddSubpass(std::unique_ptr<CanvasPass> pass) {
8181
return subpasses_.emplace_back(std::move(pass)).get();
8282
}
8383

84-
bool CanvasPass::Render(ContentRenderer& renderer,
84+
bool EntityPass::Render(ContentRenderer& renderer,
8585
RenderPass& parent_pass) const {
8686
for (const auto& entity : entities_) {
8787
if (!entity.Render(renderer, parent_pass)) {
@@ -172,7 +172,7 @@ bool CanvasPass::Render(ContentRenderer& renderer,
172172
return true;
173173
}
174174

175-
void CanvasPass::IterateAllEntities(std::function<bool(Entity&)> iterator) {
175+
void EntityPass::IterateAllEntities(std::function<bool(Entity&)> iterator) {
176176
if (!iterator) {
177177
return;
178178
}
@@ -188,20 +188,20 @@ void CanvasPass::IterateAllEntities(std::function<bool(Entity&)> iterator) {
188188
}
189189
}
190190

191-
std::unique_ptr<CanvasPass> CanvasPass::Clone() const {
192-
auto pass = std::make_unique<CanvasPass>();
191+
std::unique_ptr<EntityPass> EntityPass::Clone() const {
192+
auto pass = std::make_unique<EntityPass>();
193193
pass->SetEntities(entities_);
194194
for (const auto& subpass : subpasses_) {
195195
pass->AddSubpass(subpass->Clone());
196196
}
197197
return pass;
198198
}
199199

200-
void CanvasPass::SetTransformation(Matrix xformation) {
200+
void EntityPass::SetTransformation(Matrix xformation) {
201201
xformation_ = std::move(xformation);
202202
}
203203

204-
void CanvasPass::SetStencilDepth(size_t stencil_depth) {
204+
void EntityPass::SetStencilDepth(size_t stencil_depth) {
205205
stencil_depth_ = stencil_depth;
206206
}
207207

impeller/aiks/canvas_pass.h renamed to impeller/entity/entity_pass.h

+13-11
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,32 @@
99
#include <vector>
1010

1111
#include "flutter/fml/macros.h"
12-
#include "impeller/aiks/canvas_pass_delegate.h"
1312
#include "impeller/entity/contents.h"
1413
#include "impeller/entity/entity.h"
14+
#include "impeller/entity/entity_pass_delegate.h"
1515
#include "impeller/renderer/render_target.h"
1616

1717
namespace impeller {
1818

1919
class ContentRenderer;
2020

21-
class CanvasPass {
21+
class EntityPass {
2222
public:
2323
using Entities = std::vector<Entity>;
24-
using Subpasses = std::vector<std::unique_ptr<CanvasPass>>;
24+
using Subpasses = std::vector<std::unique_ptr<EntityPass>>;
2525

26-
CanvasPass(std::unique_ptr<CanvasPassDelegate> delegate = nullptr);
26+
EntityPass(std::unique_ptr<EntityPassDelegate> delegate = nullptr);
2727

28-
~CanvasPass();
28+
~EntityPass();
2929

3030
size_t GetSubpassesDepth() const;
3131

32-
std::unique_ptr<CanvasPass> Clone() const;
32+
std::unique_ptr<EntityPass> Clone() const;
3333

3434
Rect GetCoverageRect() const;
3535

36+
// TODO(csg): This prevents an optimization where the coverage can be
37+
// calculated once in SetEntities an memoized.
3638
void AddEntity(Entity entity);
3739

3840
void SetEntities(Entities entities);
@@ -41,9 +43,9 @@ class CanvasPass {
4143

4244
const Subpasses& GetSubpasses() const;
4345

44-
CanvasPass* AddSubpass(std::unique_ptr<CanvasPass> pass);
46+
EntityPass* AddSubpass(std::unique_ptr<EntityPass> pass);
4547

46-
CanvasPass* GetSuperpass() const;
48+
EntityPass* GetSuperpass() const;
4749

4850
bool Render(ContentRenderer& renderer, RenderPass& parent_pass) const;
4951

@@ -56,12 +58,12 @@ class CanvasPass {
5658
private:
5759
Entities entities_;
5860
Subpasses subpasses_;
59-
CanvasPass* superpass_ = nullptr;
61+
EntityPass* superpass_ = nullptr;
6062
Matrix xformation_;
6163
size_t stencil_depth_ = 0u;
62-
std::unique_ptr<CanvasPassDelegate> delegate_;
64+
std::unique_ptr<EntityPassDelegate> delegate_;
6365

64-
FML_DISALLOW_COPY_AND_ASSIGN(CanvasPass);
66+
FML_DISALLOW_COPY_AND_ASSIGN(EntityPass);
6567
};
6668

6769
struct CanvasStackEntry {

impeller/aiks/canvas_pass_delegate.cc renamed to impeller/entity/entity_pass_delegate.cc

+9-9
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
#include "impeller/aiks/canvas_pass_delegate.h"
5+
#include "impeller/entity/entity_pass_delegate.h"
66

77
namespace impeller {
88

9-
CanvasPassDelegate::CanvasPassDelegate() = default;
9+
EntityPassDelegate::EntityPassDelegate() = default;
1010

11-
CanvasPassDelegate::~CanvasPassDelegate() = default;
11+
EntityPassDelegate::~EntityPassDelegate() = default;
1212

13-
class DefaultCanvasPassDelegate final : public CanvasPassDelegate {
13+
class DefaultEntityPassDelegate final : public EntityPassDelegate {
1414
public:
15-
DefaultCanvasPassDelegate() = default;
15+
DefaultEntityPassDelegate() = default;
1616

17-
~DefaultCanvasPassDelegate() override = default;
17+
~DefaultEntityPassDelegate() override = default;
1818

1919
bool CanCollapseIntoParentPass() override { return true; }
2020

@@ -25,11 +25,11 @@ class DefaultCanvasPassDelegate final : public CanvasPassDelegate {
2525
}
2626

2727
private:
28-
FML_DISALLOW_COPY_AND_ASSIGN(DefaultCanvasPassDelegate);
28+
FML_DISALLOW_COPY_AND_ASSIGN(DefaultEntityPassDelegate);
2929
};
3030

31-
std::unique_ptr<CanvasPassDelegate> CanvasPassDelegate::MakeDefault() {
32-
return std::make_unique<DefaultCanvasPassDelegate>();
31+
std::unique_ptr<EntityPassDelegate> EntityPassDelegate::MakeDefault() {
32+
return std::make_unique<DefaultEntityPassDelegate>();
3333
}
3434

3535
} // namespace impeller

impeller/aiks/canvas_pass_delegate.h renamed to impeller/entity/entity_pass_delegate.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@
1212

1313
namespace impeller {
1414

15-
class CanvasPassDelegate {
15+
class EntityPassDelegate {
1616
public:
17-
static std::unique_ptr<CanvasPassDelegate> MakeDefault();
17+
static std::unique_ptr<EntityPassDelegate> MakeDefault();
1818

19-
CanvasPassDelegate();
19+
EntityPassDelegate();
2020

21-
virtual ~CanvasPassDelegate();
21+
virtual ~EntityPassDelegate();
2222

2323
virtual bool CanCollapseIntoParentPass() = 0;
2424

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

2828
private:
29-
FML_DISALLOW_COPY_AND_ASSIGN(CanvasPassDelegate);
29+
FML_DISALLOW_COPY_AND_ASSIGN(EntityPassDelegate);
3030
};
3131

3232
} // namespace impeller

0 commit comments

Comments
 (0)