From 3f417887c4de44f9b150531a02e2c12b2f175ed0 Mon Sep 17 00:00:00 2001 From: Chinmay Garde Date: Tue, 23 Nov 2021 12:54:19 -0800 Subject: [PATCH] Setup aiks for canvas subpasses. --- impeller/aiks/BUILD.gn | 4 +- impeller/aiks/aiks_playground.cc | 11 +++-- impeller/aiks/aiks_renderer.cc | 49 +++++++++++++++++++ .../aiks_renderer.h} | 17 +++---- impeller/aiks/canvas.cc | 2 +- impeller/aiks/canvas_pass.cc | 37 +++++++++----- impeller/aiks/canvas_pass.h | 17 +++++-- impeller/aiks/picture_renderer.cc | 42 ---------------- impeller/aiks/picture_renderer.h | 34 ------------- impeller/entity/BUILD.gn | 2 - impeller/entity/entity.cc | 11 +++++ impeller/entity/entity.h | 5 ++ impeller/entity/entity_playground.cc | 13 +++-- impeller/entity/entity_playground.h | 3 -- impeller/entity/entity_renderer.cc | 49 ------------------- 15 files changed, 125 insertions(+), 171 deletions(-) create mode 100644 impeller/aiks/aiks_renderer.cc rename impeller/{entity/entity_renderer.h => aiks/aiks_renderer.h} (56%) delete mode 100644 impeller/aiks/picture_renderer.cc delete mode 100644 impeller/aiks/picture_renderer.h delete mode 100644 impeller/entity/entity_renderer.cc diff --git a/impeller/aiks/BUILD.gn b/impeller/aiks/BUILD.gn index 09fde1849cdfa..0c6bc01a00578 100644 --- a/impeller/aiks/BUILD.gn +++ b/impeller/aiks/BUILD.gn @@ -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", @@ -18,8 +20,6 @@ impeller_component("aiks") { "picture.h", "picture_recorder.cc", "picture_recorder.h", - "picture_renderer.cc", - "picture_renderer.h", ] public_deps = [ diff --git a/impeller/aiks/aiks_playground.cc b/impeller/aiks/aiks_playground.cc index 7928ead04cdb4..32c301b4ca913 100644 --- a/impeller/aiks/aiks_playground.cc +++ b/impeller/aiks/aiks_playground.cc @@ -4,7 +4,7 @@ #include "impeller/aiks/aiks_playground.h" -#include "impeller/aiks/picture_renderer.h" +#include "impeller/aiks/aiks_renderer.h" namespace impeller { @@ -13,14 +13,15 @@ AiksPlayground::AiksPlayground() = default; AiksPlayground::~AiksPlayground() = default; bool AiksPlayground::OpenPlaygroundHere(const Picture& picture) { - auto renderer = std::make_shared(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); }); } diff --git a/impeller/aiks/aiks_renderer.cc b/impeller/aiks/aiks_renderer.cc new file mode 100644 index 0000000000000..f491e4d083882 --- /dev/null +++ b/impeller/aiks/aiks_renderer.cc @@ -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_(std::move(context)) { + if (!context_ || !context_->IsValid()) { + return; + } + + content_renderer_ = std::make_unique(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 diff --git a/impeller/entity/entity_renderer.h b/impeller/aiks/aiks_renderer.h similarity index 56% rename from impeller/entity/entity_renderer.h rename to impeller/aiks/aiks_renderer.h index e453100ce0744..aa09a7ab4746b 100644 --- a/impeller/entity/entity_renderer.h +++ b/impeller/aiks/aiks_renderer.h @@ -7,31 +7,30 @@ #include #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); + AiksRenderer(std::shared_ptr context); - ~EntityRenderer(); + ~AiksRenderer(); bool IsValid() const; - [[nodiscard]] bool RenderEntities(RenderPass& parent_pass, - const std::vector& entities); + bool Render(const Picture& picture, RenderPass& parent_pass); private: std::shared_ptr context_; std::unique_ptr content_renderer_; bool is_valid_ = false; - FML_DISALLOW_COPY_AND_ASSIGN(EntityRenderer); + FML_DISALLOW_COPY_AND_ASSIGN(AiksRenderer); }; } // namespace impeller diff --git a/impeller/aiks/canvas.cc b/impeller/aiks/canvas.cc index 4d9c3d99a5f64..87ec026a6321f 100644 --- a/impeller/aiks/canvas.cc +++ b/impeller/aiks/canvas.cc @@ -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()); diff --git a/impeller/aiks/canvas_pass.cc b/impeller/aiks/canvas_pass.cc index d7e3773f2a73a..edada76473835 100644 --- a/impeller/aiks/canvas_pass.cc +++ b/impeller/aiks/canvas_pass.cc @@ -4,6 +4,8 @@ #include "impeller/aiks/canvas_pass.h" +#include "impeller/entity/content_renderer.h" + namespace impeller { CanvasPass::CanvasPass() = default; @@ -11,24 +13,16 @@ CanvasPass::CanvasPass() = default; CanvasPass::~CanvasPass() = default; void CanvasPass::PushEntity(Entity entity) { - ops_.emplace_back(std::move(entity)); -} - -const std::vector& 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& CanvasPass::GetEntities() const { + return entities_; } Rect CanvasPass::GetCoverageRect() const { std::optional min, max; - for (const auto& entity : ops_) { + for (const auto& entity : entities_) { auto coverage = entity.GetPath().GetMinMaxCoveragePoints(); if (!coverage.has_value()) { continue; @@ -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 diff --git a/impeller/aiks/canvas_pass.h b/impeller/aiks/canvas_pass.h index 5d7494bac133b..3aa7cb825c3eb 100644 --- a/impeller/aiks/canvas_pass.h +++ b/impeller/aiks/canvas_pass.h @@ -6,6 +6,7 @@ #include #include +#include #include "flutter/fml/macros.h" #include "impeller/entity/contents.h" @@ -13,8 +14,12 @@ namespace impeller { +class ContentRenderer; + class CanvasPass { public: + using Subpasses = std::vector; + CanvasPass(); ~CanvasPass(); @@ -23,15 +28,17 @@ class CanvasPass { Rect GetCoverageRect() const; - const std::vector& GetPassEntities() const; + const std::vector& 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 ops_; - Entity post_processing_entity_; + std::vector entities_; + Subpasses subpasses_; }; struct CanvasStackEntry { diff --git a/impeller/aiks/picture_renderer.cc b/impeller/aiks/picture_renderer.cc deleted file mode 100644 index 33db1008f364c..0000000000000 --- a/impeller/aiks/picture_renderer.cc +++ /dev/null @@ -1,42 +0,0 @@ -// 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/picture_renderer.h" - -#include "impeller/aiks/picture.h" - -namespace impeller { - -PictureRenderer::PictureRenderer(std::shared_ptr context) - : entity_renderer_(std::move(context)) { - if (!entity_renderer_.IsValid()) { - return; - } - is_valid_ = true; -} - -PictureRenderer::~PictureRenderer() = default; - -bool PictureRenderer::IsValid() const { - return is_valid_; -} - -bool PictureRenderer::Render(RenderPass& parent_pass, const Picture& picture) { - if (!IsValid()) { - return false; - } - - for (const auto& entry : picture.entries) { - if (auto pass = entry.pass) { - if (!entity_renderer_.RenderEntities(parent_pass, - pass->GetPassEntities())) { - return false; - } - } - } - - return true; -} - -} // namespace impeller diff --git a/impeller/aiks/picture_renderer.h b/impeller/aiks/picture_renderer.h deleted file mode 100644 index 269c321b29f70..0000000000000 --- a/impeller/aiks/picture_renderer.h +++ /dev/null @@ -1,34 +0,0 @@ -// 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. - -#pragma once - -#include "flutter/fml/macros.h" -#include "impeller/entity/entity_renderer.h" - -namespace impeller { - -class Surface; -class RenderPass; -class Context; -struct Picture; - -class PictureRenderer { - public: - PictureRenderer(std::shared_ptr context); - - ~PictureRenderer(); - - bool IsValid() const; - - [[nodiscard]] bool Render(RenderPass& parent_pass, const Picture& picture); - - private: - EntityRenderer entity_renderer_; - bool is_valid_ = false; - - FML_DISALLOW_COPY_AND_ASSIGN(PictureRenderer); -}; - -} // namespace impeller diff --git a/impeller/entity/BUILD.gn b/impeller/entity/BUILD.gn index e3c1d596ef58a..6dac3568748c8 100644 --- a/impeller/entity/BUILD.gn +++ b/impeller/entity/BUILD.gn @@ -27,8 +27,6 @@ impeller_component("entity") { "contents.h", "entity.cc", "entity.h", - "entity_renderer.cc", - "entity_renderer.h", ] deps = [ ":entity_shaders" ] diff --git a/impeller/entity/entity.cc b/impeller/entity/entity.cc index 9ff908721cb2d..fec6b9710b1fa 100644 --- a/impeller/entity/entity.cc +++ b/impeller/entity/entity.cc @@ -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; @@ -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 diff --git a/impeller/entity/entity.h b/impeller/entity/entity.h index ef5285c2dbc2e..26c354f00dc00 100644 --- a/impeller/entity/entity.h +++ b/impeller/entity/entity.h @@ -13,6 +13,9 @@ namespace impeller { +class Renderer; +class RenderPass; + class Entity { public: Entity(); @@ -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_; diff --git a/impeller/entity/entity_playground.cc b/impeller/entity/entity_playground.cc index 835cf655fbaa5..140a0d93d1479 100644 --- a/impeller/entity/entity_playground.cc +++ b/impeller/entity/entity_playground.cc @@ -4,6 +4,8 @@ #include "impeller/entity/entity_playground.h" +#include "impeller/entity/content_renderer.h" + namespace impeller { EntityPlayground::EntityPlayground() = default; @@ -11,15 +13,12 @@ EntityPlayground::EntityPlayground() = default; EntityPlayground::~EntityPlayground() = default; bool EntityPlayground::OpenPlaygroundHere(Entity entity) { - if (!renderer_) { - renderer_ = std::make_unique(GetContext()); - if (!renderer_) { - return false; - } + ContentRenderer renderer(GetContext()); + if (!renderer.IsValid()) { + return false; } Renderer::RenderCallback callback = [&](RenderPass& pass) -> bool { - std::vector entities = {entity}; - return renderer_->RenderEntities(pass, entities); + return entity.Render(renderer, pass); }; return Playground::OpenPlaygroundHere(callback); } diff --git a/impeller/entity/entity_playground.h b/impeller/entity/entity_playground.h index fdbc3c492a6c5..9d16caab30a95 100644 --- a/impeller/entity/entity_playground.h +++ b/impeller/entity/entity_playground.h @@ -6,7 +6,6 @@ #include "flutter/fml/macros.h" #include "impeller/entity/entity.h" -#include "impeller/entity/entity_renderer.h" #include "impeller/playground/playground.h" namespace impeller { @@ -20,8 +19,6 @@ class EntityPlayground : public Playground { bool OpenPlaygroundHere(Entity entity); private: - std::unique_ptr renderer_; - FML_DISALLOW_COPY_AND_ASSIGN(EntityPlayground); }; diff --git a/impeller/entity/entity_renderer.cc b/impeller/entity/entity_renderer.cc deleted file mode 100644 index 9572080b059f4..0000000000000 --- a/impeller/entity/entity_renderer.cc +++ /dev/null @@ -1,49 +0,0 @@ -// 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 "flutter/impeller/entity/entity_renderer.h" - -#include "flutter/fml/trace_event.h" -#include "impeller/entity/content_renderer.h" - -namespace impeller { - -EntityRenderer::EntityRenderer(std::shared_ptr context) - : context_(std::move(context)) { - if (!context_ || !context_->IsValid()) { - return; - } - - content_renderer_ = std::make_unique(context_); - if (!content_renderer_->IsValid()) { - return; - } - - is_valid_ = true; -} - -EntityRenderer::~EntityRenderer() = default; - -bool EntityRenderer::IsValid() const { - return is_valid_; -} - -bool EntityRenderer::RenderEntities(RenderPass& parent_pass, - const std::vector& entities) { - if (!IsValid()) { - return false; - } - - for (const auto& entity : entities) { - if (auto contents = entity.GetContents()) { - if (!contents->Render(*content_renderer_, entity, parent_pass)) { - return false; - } - } - } - - return true; -} - -} // namespace impeller