Skip to content

Commit

Permalink
Setup aiks for canvas subpasses.
Browse files Browse the repository at this point in the history
  • Loading branch information
chinmaygarde authored and dnfield committed Apr 27, 2022
1 parent 9359311 commit 3f41788
Show file tree
Hide file tree
Showing 15 changed files with 125 additions and 171 deletions.
4 changes: 2 additions & 2 deletions impeller/aiks/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import("../tools/impeller.gni")

impeller_component("aiks") {
sources = [
"aiks_renderer.cc",
"aiks_renderer.h",
"canvas.cc",
"canvas.h",
"canvas_pass.cc",
Expand All @@ -18,8 +20,6 @@ impeller_component("aiks") {
"picture.h",
"picture_recorder.cc",
"picture_recorder.h",
"picture_renderer.cc",
"picture_renderer.h",
]

public_deps = [
Expand Down
11 changes: 6 additions & 5 deletions impeller/aiks/aiks_playground.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "impeller/aiks/aiks_playground.h"

#include "impeller/aiks/picture_renderer.h"
#include "impeller/aiks/aiks_renderer.h"

namespace impeller {

Expand All @@ -13,14 +13,15 @@ AiksPlayground::AiksPlayground() = default;
AiksPlayground::~AiksPlayground() = default;

bool AiksPlayground::OpenPlaygroundHere(const Picture& picture) {
auto renderer = std::make_shared<PictureRenderer>(GetContext());
if (!renderer) {
AiksRenderer renderer(GetContext());

if (!renderer.IsValid()) {
return false;
}

return Playground::OpenPlaygroundHere(
[renderer, &picture](RenderPass& pass) -> bool {
return renderer->Render(pass, picture);
[&renderer, &picture](RenderPass& pass) -> bool {
return renderer.Render(picture, pass);
});
}

Expand Down
49 changes: 49 additions & 0 deletions impeller/aiks/aiks_renderer.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// 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/aiks_renderer.h"

#include "impeller/aiks/picture.h"

namespace impeller {

AiksRenderer::AiksRenderer(std::shared_ptr<Context> context)
: context_(std::move(context)) {
if (!context_ || !context_->IsValid()) {
return;
}

content_renderer_ = std::make_unique<ContentRenderer>(context_);
if (!content_renderer_->IsValid()) {
return;
}

is_valid_ = true;
}

AiksRenderer::~AiksRenderer() = default;

bool AiksRenderer::IsValid() const {
return is_valid_;
}

bool AiksRenderer::Render(const Picture& picture, RenderPass& parent_pass) {
if (!IsValid()) {
return false;
}

for (const auto& entry : picture.entries) {
if (!entry.pass.has_value()) {
continue;
;
}

if (!entry.pass->Render(*content_renderer_, parent_pass)) {
return false;
}
}
return true;
}

} // namespace impeller
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,30 @@
#include <memory>

#include "flutter/fml/macros.h"
#include "impeller/entity/entity.h"
#include "impeller/entity/content_renderer.h"
#include "impeller/renderer/context.h"
#include "impeller/renderer/surface.h"

namespace impeller {

class ContentRenderer;
struct Picture;
class RenderPass;

class EntityRenderer {
class AiksRenderer {
public:
EntityRenderer(std::shared_ptr<Context> context);
AiksRenderer(std::shared_ptr<Context> context);

~EntityRenderer();
~AiksRenderer();

bool IsValid() const;

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

private:
std::shared_ptr<Context> context_;
std::unique_ptr<ContentRenderer> content_renderer_;
bool is_valid_ = false;

FML_DISALLOW_COPY_AND_ASSIGN(EntityRenderer);
FML_DISALLOW_COPY_AND_ASSIGN(AiksRenderer);
};

} // namespace impeller
2 changes: 1 addition & 1 deletion impeller/aiks/canvas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void Canvas::DrawPicture(const Picture& picture) {
for (const auto& stack_entry : picture.entries) {
auto new_stack_entry = stack_entry;
if (auto pass = new_stack_entry.pass) {
for (auto entity : pass->GetPassEntities()) {
for (auto entity : pass->GetEntities()) {
entity.IncrementStencilDepth(GetStencilDepth());
entity.SetTransformation(GetCurrentTransformation() *
entity.GetTransformation());
Expand Down
37 changes: 25 additions & 12 deletions impeller/aiks/canvas_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,25 @@

#include "impeller/aiks/canvas_pass.h"

#include "impeller/entity/content_renderer.h"

namespace impeller {

CanvasPass::CanvasPass() = default;

CanvasPass::~CanvasPass() = default;

void CanvasPass::PushEntity(Entity entity) {
ops_.emplace_back(std::move(entity));
}

const std::vector<Entity>& CanvasPass::GetPassEntities() const {
return ops_;
entities_.emplace_back(std::move(entity));
}

void CanvasPass::SetPostProcessingEntity(Entity entity) {
post_processing_entity_ = std::move(entity);
}

const Entity& CanvasPass::GetPostProcessingEntity() const {
return post_processing_entity_;
const std::vector<Entity>& CanvasPass::GetEntities() const {
return entities_;
}

Rect CanvasPass::GetCoverageRect() const {
std::optional<Point> min, max;
for (const auto& entity : ops_) {
for (const auto& entity : entities_) {
auto coverage = entity.GetPath().GetMinMaxCoveragePoints();
if (!coverage.has_value()) {
continue;
Expand All @@ -49,4 +43,23 @@ Rect CanvasPass::GetCoverageRect() const {
return {min->x, min->y, diff.x, diff.y};
}

const CanvasPass::Subpasses& CanvasPass::GetSubpasses() const {
return subpasses_;
}

bool CanvasPass::AddSubpass(CanvasPass pass) {
subpasses_.emplace_back(std::move(pass));
return true;
}

bool CanvasPass::Render(ContentRenderer& renderer,
RenderPass& parent_pass) const {
for (const auto& entity : entities_) {
if (!entity.Render(renderer, parent_pass)) {
return false;
}
}
return true;
}

} // namespace impeller
17 changes: 12 additions & 5 deletions impeller/aiks/canvas_pass.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@

#include <memory>
#include <optional>
#include <vector>

#include "flutter/fml/macros.h"
#include "impeller/entity/contents.h"
#include "impeller/entity/entity.h"

namespace impeller {

class ContentRenderer;

class CanvasPass {
public:
using Subpasses = std::vector<CanvasPass>;

CanvasPass();

~CanvasPass();
Expand All @@ -23,15 +28,17 @@ class CanvasPass {

Rect GetCoverageRect() const;

const std::vector<Entity>& GetPassEntities() const;
const std::vector<Entity>& GetEntities() const;

const Subpasses& GetSubpasses() const;

void SetPostProcessingEntity(Entity entity);
bool AddSubpass(CanvasPass pass);

const Entity& GetPostProcessingEntity() const;
bool Render(ContentRenderer& renderer, RenderPass& parent_pass) const;

private:
std::vector<Entity> ops_;
Entity post_processing_entity_;
std::vector<Entity> entities_;
Subpasses subpasses_;
};

struct CanvasStackEntry {
Expand Down
42 changes: 0 additions & 42 deletions impeller/aiks/picture_renderer.cc

This file was deleted.

34 changes: 0 additions & 34 deletions impeller/aiks/picture_renderer.h

This file was deleted.

2 changes: 0 additions & 2 deletions impeller/entity/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ impeller_component("entity") {
"contents.h",
"entity.cc",
"entity.h",
"entity_renderer.cc",
"entity_renderer.h",
]

deps = [ ":entity_shaders" ]
Expand Down
11 changes: 11 additions & 0 deletions impeller/entity/entity.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

#include "impeller/entity/entity.h"

#include "impeller/entity/content_renderer.h"
#include "impeller/renderer/render_pass.h"

namespace impeller {

Entity::Entity() = default;
Expand Down Expand Up @@ -46,4 +49,12 @@ void Entity::IncrementStencilDepth(uint32_t increment) {
stencil_depth_ += increment;
}

bool Entity::Render(ContentRenderer& renderer, RenderPass& parent_pass) const {
if (!contents_) {
return true;
}

return contents_->Render(renderer, *this, parent_pass);
}

} // namespace impeller
5 changes: 5 additions & 0 deletions impeller/entity/entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

namespace impeller {

class Renderer;
class RenderPass;

class Entity {
public:
Entity();
Expand All @@ -37,6 +40,8 @@ class Entity {

uint32_t GetStencilDepth() const;

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

private:
Matrix transformation_;
std::shared_ptr<Contents> contents_;
Expand Down
Loading

0 comments on commit 3f41788

Please sign in to comment.