mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Setup aiks for canvas subpasses.
This commit is contained in:
parent
c73218bee1
commit
80a7c32a8e
@ -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 = [
|
||||
|
||||
@ -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<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);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
49
engine/src/flutter/impeller/aiks/aiks_renderer.cc
Normal file
49
engine/src/flutter/impeller/aiks/aiks_renderer.cc
Normal file
@ -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
|
||||
@ -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
|
||||
@ -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());
|
||||
|
||||
@ -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));
|
||||
entities_.emplace_back(std::move(entity));
|
||||
}
|
||||
|
||||
const std::vector<Entity>& CanvasPass::GetPassEntities() const {
|
||||
return ops_;
|
||||
}
|
||||
|
||||
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;
|
||||
@ -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
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
#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();
|
||||
|
||||
~CanvasPass();
|
||||
@ -23,15 +28,17 @@ class CanvasPass {
|
||||
|
||||
Rect GetCoverageRect() const;
|
||||
|
||||
const std::vector<Entity>& GetPassEntities() const;
|
||||
const std::vector<Entity>& GetEntities() const;
|
||||
|
||||
void SetPostProcessingEntity(Entity entity);
|
||||
const Subpasses& GetSubpasses() const;
|
||||
|
||||
const Entity& GetPostProcessingEntity() const;
|
||||
bool AddSubpass(CanvasPass pass);
|
||||
|
||||
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 {
|
||||
|
||||
@ -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> 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
|
||||
@ -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> 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
|
||||
@ -27,8 +27,6 @@ impeller_component("entity") {
|
||||
"contents.h",
|
||||
"entity.cc",
|
||||
"entity.h",
|
||||
"entity_renderer.cc",
|
||||
"entity_renderer.h",
|
||||
]
|
||||
|
||||
deps = [ ":entity_shaders" ]
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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> contents_;
|
||||
|
||||
@ -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<EntityRenderer>(GetContext());
|
||||
if (!renderer_) {
|
||||
return false;
|
||||
}
|
||||
ContentRenderer renderer(GetContext());
|
||||
if (!renderer.IsValid()) {
|
||||
return false;
|
||||
}
|
||||
Renderer::RenderCallback callback = [&](RenderPass& pass) -> bool {
|
||||
std::vector<Entity> entities = {entity};
|
||||
return renderer_->RenderEntities(pass, entities);
|
||||
return entity.Render(renderer, pass);
|
||||
};
|
||||
return Playground::OpenPlaygroundHere(callback);
|
||||
}
|
||||
|
||||
@ -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<EntityRenderer> renderer_;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(EntityPlayground);
|
||||
};
|
||||
|
||||
|
||||
@ -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)
|
||||
: context_(std::move(context)) {
|
||||
if (!context_ || !context_->IsValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
content_renderer_ = std::make_unique<ContentRenderer>(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<Entity>& 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
|
||||
Loading…
x
Reference in New Issue
Block a user