Skip to content

Commit 3f41788

Browse files
chinmaygardednfield
authored andcommitted
Setup aiks for canvas subpasses.
1 parent 9359311 commit 3f41788

15 files changed

+125
-171
lines changed

impeller/aiks/BUILD.gn

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import("../tools/impeller.gni")
66

77
impeller_component("aiks") {
88
sources = [
9+
"aiks_renderer.cc",
10+
"aiks_renderer.h",
911
"canvas.cc",
1012
"canvas.h",
1113
"canvas_pass.cc",
@@ -18,8 +20,6 @@ impeller_component("aiks") {
1820
"picture.h",
1921
"picture_recorder.cc",
2022
"picture_recorder.h",
21-
"picture_renderer.cc",
22-
"picture_renderer.h",
2323
]
2424

2525
public_deps = [

impeller/aiks/aiks_playground.cc

+6-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#include "impeller/aiks/aiks_playground.h"
66

7-
#include "impeller/aiks/picture_renderer.h"
7+
#include "impeller/aiks/aiks_renderer.h"
88

99
namespace impeller {
1010

@@ -13,14 +13,15 @@ AiksPlayground::AiksPlayground() = default;
1313
AiksPlayground::~AiksPlayground() = default;
1414

1515
bool AiksPlayground::OpenPlaygroundHere(const Picture& picture) {
16-
auto renderer = std::make_shared<PictureRenderer>(GetContext());
17-
if (!renderer) {
16+
AiksRenderer renderer(GetContext());
17+
18+
if (!renderer.IsValid()) {
1819
return false;
1920
}
2021

2122
return Playground::OpenPlaygroundHere(
22-
[renderer, &picture](RenderPass& pass) -> bool {
23-
return renderer->Render(pass, picture);
23+
[&renderer, &picture](RenderPass& pass) -> bool {
24+
return renderer.Render(picture, pass);
2425
});
2526
}
2627

impeller/aiks/aiks_renderer.cc

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "impeller/aiks/aiks_renderer.h"
6+
7+
#include "impeller/aiks/picture.h"
8+
9+
namespace impeller {
10+
11+
AiksRenderer::AiksRenderer(std::shared_ptr<Context> context)
12+
: context_(std::move(context)) {
13+
if (!context_ || !context_->IsValid()) {
14+
return;
15+
}
16+
17+
content_renderer_ = std::make_unique<ContentRenderer>(context_);
18+
if (!content_renderer_->IsValid()) {
19+
return;
20+
}
21+
22+
is_valid_ = true;
23+
}
24+
25+
AiksRenderer::~AiksRenderer() = default;
26+
27+
bool AiksRenderer::IsValid() const {
28+
return is_valid_;
29+
}
30+
31+
bool AiksRenderer::Render(const Picture& picture, RenderPass& parent_pass) {
32+
if (!IsValid()) {
33+
return false;
34+
}
35+
36+
for (const auto& entry : picture.entries) {
37+
if (!entry.pass.has_value()) {
38+
continue;
39+
;
40+
}
41+
42+
if (!entry.pass->Render(*content_renderer_, parent_pass)) {
43+
return false;
44+
}
45+
}
46+
return true;
47+
}
48+
49+
} // namespace impeller

impeller/entity/entity_renderer.h renamed to impeller/aiks/aiks_renderer.h

+8-9
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,30 @@
77
#include <memory>
88

99
#include "flutter/fml/macros.h"
10-
#include "impeller/entity/entity.h"
10+
#include "impeller/entity/content_renderer.h"
1111
#include "impeller/renderer/context.h"
12-
#include "impeller/renderer/surface.h"
1312

1413
namespace impeller {
1514

16-
class ContentRenderer;
15+
struct Picture;
16+
class RenderPass;
1717

18-
class EntityRenderer {
18+
class AiksRenderer {
1919
public:
20-
EntityRenderer(std::shared_ptr<Context> context);
20+
AiksRenderer(std::shared_ptr<Context> context);
2121

22-
~EntityRenderer();
22+
~AiksRenderer();
2323

2424
bool IsValid() const;
2525

26-
[[nodiscard]] bool RenderEntities(RenderPass& parent_pass,
27-
const std::vector<Entity>& entities);
26+
bool Render(const Picture& picture, RenderPass& parent_pass);
2827

2928
private:
3029
std::shared_ptr<Context> context_;
3130
std::unique_ptr<ContentRenderer> content_renderer_;
3231
bool is_valid_ = false;
3332

34-
FML_DISALLOW_COPY_AND_ASSIGN(EntityRenderer);
33+
FML_DISALLOW_COPY_AND_ASSIGN(AiksRenderer);
3534
};
3635

3736
} // namespace impeller

impeller/aiks/canvas.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ void Canvas::DrawPicture(const Picture& picture) {
9494
for (const auto& stack_entry : picture.entries) {
9595
auto new_stack_entry = stack_entry;
9696
if (auto pass = new_stack_entry.pass) {
97-
for (auto entity : pass->GetPassEntities()) {
97+
for (auto entity : pass->GetEntities()) {
9898
entity.IncrementStencilDepth(GetStencilDepth());
9999
entity.SetTransformation(GetCurrentTransformation() *
100100
entity.GetTransformation());

impeller/aiks/canvas_pass.cc

+25-12
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,25 @@
44

55
#include "impeller/aiks/canvas_pass.h"
66

7+
#include "impeller/entity/content_renderer.h"
8+
79
namespace impeller {
810

911
CanvasPass::CanvasPass() = default;
1012

1113
CanvasPass::~CanvasPass() = default;
1214

1315
void CanvasPass::PushEntity(Entity entity) {
14-
ops_.emplace_back(std::move(entity));
15-
}
16-
17-
const std::vector<Entity>& CanvasPass::GetPassEntities() const {
18-
return ops_;
16+
entities_.emplace_back(std::move(entity));
1917
}
2018

21-
void CanvasPass::SetPostProcessingEntity(Entity entity) {
22-
post_processing_entity_ = std::move(entity);
23-
}
24-
25-
const Entity& CanvasPass::GetPostProcessingEntity() const {
26-
return post_processing_entity_;
19+
const std::vector<Entity>& CanvasPass::GetEntities() const {
20+
return entities_;
2721
}
2822

2923
Rect CanvasPass::GetCoverageRect() const {
3024
std::optional<Point> min, max;
31-
for (const auto& entity : ops_) {
25+
for (const auto& entity : entities_) {
3226
auto coverage = entity.GetPath().GetMinMaxCoveragePoints();
3327
if (!coverage.has_value()) {
3428
continue;
@@ -49,4 +43,23 @@ Rect CanvasPass::GetCoverageRect() const {
4943
return {min->x, min->y, diff.x, diff.y};
5044
}
5145

46+
const CanvasPass::Subpasses& CanvasPass::GetSubpasses() const {
47+
return subpasses_;
48+
}
49+
50+
bool CanvasPass::AddSubpass(CanvasPass pass) {
51+
subpasses_.emplace_back(std::move(pass));
52+
return true;
53+
}
54+
55+
bool CanvasPass::Render(ContentRenderer& renderer,
56+
RenderPass& parent_pass) const {
57+
for (const auto& entity : entities_) {
58+
if (!entity.Render(renderer, parent_pass)) {
59+
return false;
60+
}
61+
}
62+
return true;
63+
}
64+
5265
} // namespace impeller

impeller/aiks/canvas_pass.h

+12-5
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,20 @@
66

77
#include <memory>
88
#include <optional>
9+
#include <vector>
910

1011
#include "flutter/fml/macros.h"
1112
#include "impeller/entity/contents.h"
1213
#include "impeller/entity/entity.h"
1314

1415
namespace impeller {
1516

17+
class ContentRenderer;
18+
1619
class CanvasPass {
1720
public:
21+
using Subpasses = std::vector<CanvasPass>;
22+
1823
CanvasPass();
1924

2025
~CanvasPass();
@@ -23,15 +28,17 @@ class CanvasPass {
2328

2429
Rect GetCoverageRect() const;
2530

26-
const std::vector<Entity>& GetPassEntities() const;
31+
const std::vector<Entity>& GetEntities() const;
32+
33+
const Subpasses& GetSubpasses() const;
2734

28-
void SetPostProcessingEntity(Entity entity);
35+
bool AddSubpass(CanvasPass pass);
2936

30-
const Entity& GetPostProcessingEntity() const;
37+
bool Render(ContentRenderer& renderer, RenderPass& parent_pass) const;
3138

3239
private:
33-
std::vector<Entity> ops_;
34-
Entity post_processing_entity_;
40+
std::vector<Entity> entities_;
41+
Subpasses subpasses_;
3542
};
3643

3744
struct CanvasStackEntry {

impeller/aiks/picture_renderer.cc

-42
This file was deleted.

impeller/aiks/picture_renderer.h

-34
This file was deleted.

impeller/entity/BUILD.gn

-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ impeller_component("entity") {
2727
"contents.h",
2828
"entity.cc",
2929
"entity.h",
30-
"entity_renderer.cc",
31-
"entity_renderer.h",
3230
]
3331

3432
deps = [ ":entity_shaders" ]

impeller/entity/entity.cc

+11
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
#include "impeller/entity/entity.h"
66

7+
#include "impeller/entity/content_renderer.h"
8+
#include "impeller/renderer/render_pass.h"
9+
710
namespace impeller {
811

912
Entity::Entity() = default;
@@ -46,4 +49,12 @@ void Entity::IncrementStencilDepth(uint32_t increment) {
4649
stencil_depth_ += increment;
4750
}
4851

52+
bool Entity::Render(ContentRenderer& renderer, RenderPass& parent_pass) const {
53+
if (!contents_) {
54+
return true;
55+
}
56+
57+
return contents_->Render(renderer, *this, parent_pass);
58+
}
59+
4960
} // namespace impeller

impeller/entity/entity.h

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
namespace impeller {
1515

16+
class Renderer;
17+
class RenderPass;
18+
1619
class Entity {
1720
public:
1821
Entity();
@@ -37,6 +40,8 @@ class Entity {
3740

3841
uint32_t GetStencilDepth() const;
3942

43+
bool Render(ContentRenderer& renderer, RenderPass& parent_pass) const;
44+
4045
private:
4146
Matrix transformation_;
4247
std::shared_ptr<Contents> contents_;

0 commit comments

Comments
 (0)