Renderer components no longer need a surface reference to function.
This commit is contained in:
@@ -19,8 +19,8 @@ bool AiksPlayground::OpenPlaygroundHere(const Picture& picture) {
|
||||
}
|
||||
|
||||
return Playground::OpenPlaygroundHere(
|
||||
[renderer, &picture](const Surface& surface, RenderPass& pass) -> bool {
|
||||
return renderer->Render(surface, pass, picture);
|
||||
[renderer, &picture](RenderPass& pass) -> bool {
|
||||
return renderer->Render(pass, picture);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -22,16 +22,14 @@ bool PictureRenderer::IsValid() const {
|
||||
return is_valid_;
|
||||
}
|
||||
|
||||
bool PictureRenderer::Render(const Surface& surface,
|
||||
RenderPass& parent_pass,
|
||||
const Picture& picture) {
|
||||
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(surface, parent_pass,
|
||||
if (!entity_renderer_.RenderEntities(parent_pass,
|
||||
pass->GetPassEntities())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -22,9 +22,7 @@ class PictureRenderer {
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
[[nodiscard]] bool Render(const Surface& surface,
|
||||
RenderPass& parent_pass,
|
||||
const Picture& picture);
|
||||
[[nodiscard]] bool Render(RenderPass& parent_pass, const Picture& picture);
|
||||
|
||||
private:
|
||||
EntityRenderer entity_renderer_;
|
||||
|
||||
@@ -56,7 +56,6 @@ const std::vector<Color>& LinearGradientContents::GetColors() const {
|
||||
|
||||
bool LinearGradientContents::Render(const ContentRenderer& renderer,
|
||||
const Entity& entity,
|
||||
const Surface& surface,
|
||||
RenderPass& pass) const {
|
||||
using VS = GradientFillPipeline::VertexShader;
|
||||
using FS = GradientFillPipeline::FragmentShader;
|
||||
@@ -75,8 +74,8 @@ bool LinearGradientContents::Render(const ContentRenderer& renderer,
|
||||
}
|
||||
|
||||
VS::FrameInfo frame_info;
|
||||
frame_info.mvp =
|
||||
Matrix::MakeOrthographic(surface.GetSize()) * entity.GetTransformation();
|
||||
frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
|
||||
entity.GetTransformation();
|
||||
|
||||
FS::GradientInfo gradient_info;
|
||||
gradient_info.start_point = start_point_;
|
||||
@@ -134,7 +133,6 @@ static VertexBuffer CreateSolidFillVertices(const Path& path,
|
||||
|
||||
bool SolidColorContents::Render(const ContentRenderer& renderer,
|
||||
const Entity& entity,
|
||||
const Surface& surface,
|
||||
RenderPass& pass) const {
|
||||
if (color_.IsTransparent()) {
|
||||
return true;
|
||||
@@ -150,8 +148,8 @@ bool SolidColorContents::Render(const ContentRenderer& renderer,
|
||||
CreateSolidFillVertices(entity.GetPath(), pass.GetTransientsBuffer()));
|
||||
|
||||
VS::FrameInfo frame_info;
|
||||
frame_info.mvp =
|
||||
Matrix::MakeOrthographic(surface.GetSize()) * entity.GetTransformation();
|
||||
frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
|
||||
entity.GetTransformation();
|
||||
frame_info.color = color_;
|
||||
VS::BindFrameInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frame_info));
|
||||
|
||||
@@ -188,7 +186,6 @@ std::shared_ptr<Texture> TextureContents::GetTexture() const {
|
||||
|
||||
bool TextureContents::Render(const ContentRenderer& renderer,
|
||||
const Entity& entity,
|
||||
const Surface& surface,
|
||||
RenderPass& pass) const {
|
||||
if (texture_ == nullptr) {
|
||||
return true;
|
||||
@@ -234,8 +231,8 @@ bool TextureContents::Render(const ContentRenderer& renderer,
|
||||
auto& host_buffer = pass.GetTransientsBuffer();
|
||||
|
||||
VS::FrameInfo frame_info;
|
||||
frame_info.mvp =
|
||||
Matrix::MakeOrthographic(surface.GetSize()) * entity.GetTransformation();
|
||||
frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
|
||||
entity.GetTransformation();
|
||||
|
||||
Command cmd;
|
||||
cmd.label = "TextureFill";
|
||||
@@ -316,7 +313,6 @@ static VertexBuffer CreateSolidStrokeVertices(const Path& path,
|
||||
|
||||
bool SolidStrokeContents::Render(const ContentRenderer& renderer,
|
||||
const Entity& entity,
|
||||
const Surface& surface,
|
||||
RenderPass& pass) const {
|
||||
if (color_.IsTransparent() || stroke_size_ <= 0.0) {
|
||||
return true;
|
||||
@@ -325,8 +321,8 @@ bool SolidStrokeContents::Render(const ContentRenderer& renderer,
|
||||
using VS = SolidStrokeVertexShader;
|
||||
|
||||
VS::FrameInfo frame_info;
|
||||
frame_info.mvp =
|
||||
Matrix::MakeOrthographic(surface.GetSize()) * entity.GetTransformation();
|
||||
frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
|
||||
entity.GetTransformation();
|
||||
|
||||
VS::StrokeInfo stroke_info;
|
||||
stroke_info.color = color_;
|
||||
@@ -366,7 +362,6 @@ ClipContents::~ClipContents() = default;
|
||||
|
||||
bool ClipContents::Render(const ContentRenderer& renderer,
|
||||
const Entity& entity,
|
||||
const Surface& surface,
|
||||
RenderPass& pass) const {
|
||||
using VS = ClipPipeline::VertexShader;
|
||||
|
||||
@@ -380,7 +375,7 @@ bool ClipContents::Render(const ContentRenderer& renderer,
|
||||
VS::FrameInfo info;
|
||||
// The color really doesn't matter.
|
||||
info.color = Color::SkyBlue();
|
||||
info.mvp = Matrix::MakeOrthographic(surface.GetSize());
|
||||
info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize());
|
||||
|
||||
VS::BindFrameInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(info));
|
||||
|
||||
|
||||
@@ -28,7 +28,6 @@ class Contents {
|
||||
|
||||
virtual bool Render(const ContentRenderer& renderer,
|
||||
const Entity& entity,
|
||||
const Surface& surface,
|
||||
RenderPass& pass) const = 0;
|
||||
|
||||
private:
|
||||
@@ -44,7 +43,6 @@ class LinearGradientContents final : public Contents {
|
||||
// |Contents|
|
||||
bool Render(const ContentRenderer& renderer,
|
||||
const Entity& entity,
|
||||
const Surface& surface,
|
||||
RenderPass& pass) const override;
|
||||
|
||||
void SetEndPoints(Point start_point, Point end_point);
|
||||
@@ -76,7 +74,6 @@ class SolidColorContents final : public Contents {
|
||||
// |Contents|
|
||||
bool Render(const ContentRenderer& renderer,
|
||||
const Entity& entity,
|
||||
const Surface& surface,
|
||||
RenderPass& pass) const override;
|
||||
|
||||
private:
|
||||
@@ -102,7 +99,6 @@ class TextureContents final : public Contents {
|
||||
// |Contents|
|
||||
bool Render(const ContentRenderer& renderer,
|
||||
const Entity& entity,
|
||||
const Surface& surface,
|
||||
RenderPass& pass) const override;
|
||||
|
||||
public:
|
||||
@@ -129,7 +125,6 @@ class SolidStrokeContents final : public Contents {
|
||||
// |Contents|
|
||||
bool Render(const ContentRenderer& renderer,
|
||||
const Entity& entity,
|
||||
const Surface& surface,
|
||||
RenderPass& pass) const override;
|
||||
|
||||
private:
|
||||
@@ -148,7 +143,6 @@ class ClipContents final : public Contents {
|
||||
// |Contents|
|
||||
bool Render(const ContentRenderer& renderer,
|
||||
const Entity& entity,
|
||||
const Surface& surface,
|
||||
RenderPass& pass) const override;
|
||||
|
||||
private:
|
||||
|
||||
@@ -17,10 +17,9 @@ bool EntityPlayground::OpenPlaygroundHere(Entity entity) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Renderer::RenderCallback callback = [&](const Surface& surface,
|
||||
RenderPass& pass) -> bool {
|
||||
Renderer::RenderCallback callback = [&](RenderPass& pass) -> bool {
|
||||
std::vector<Entity> entities = {entity};
|
||||
return renderer_->RenderEntities(surface, pass, entities);
|
||||
return renderer_->RenderEntities(pass, entities);
|
||||
};
|
||||
return Playground::OpenPlaygroundHere(callback);
|
||||
}
|
||||
|
||||
@@ -29,8 +29,7 @@ bool EntityRenderer::IsValid() const {
|
||||
return is_valid_;
|
||||
}
|
||||
|
||||
bool EntityRenderer::RenderEntities(const Surface& surface,
|
||||
RenderPass& parent_pass,
|
||||
bool EntityRenderer::RenderEntities(RenderPass& parent_pass,
|
||||
const std::vector<Entity>& entities) {
|
||||
if (!IsValid()) {
|
||||
return false;
|
||||
@@ -38,7 +37,7 @@ bool EntityRenderer::RenderEntities(const Surface& surface,
|
||||
|
||||
for (const auto& entity : entities) {
|
||||
if (auto contents = entity.GetContents()) {
|
||||
if (!contents->Render(*content_renderer_, entity, surface, parent_pass)) {
|
||||
if (!contents->Render(*content_renderer_, entity, parent_pass)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,8 +23,7 @@ class EntityRenderer {
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
[[nodiscard]] bool RenderEntities(const Surface& surface,
|
||||
RenderPass& parent_pass,
|
||||
[[nodiscard]] bool RenderEntities(RenderPass& parent_pass,
|
||||
const std::vector<Entity>& entities);
|
||||
|
||||
private:
|
||||
|
||||
@@ -180,11 +180,10 @@ bool Playground::OpenPlaygroundHere(Renderer::RenderCallback render_callback) {
|
||||
|
||||
Surface surface(desc);
|
||||
|
||||
Renderer::RenderCallback wrapped_callback =
|
||||
[render_callback](const auto& surface, auto& pass) {
|
||||
pass.SetLabel("Playground Main Render Pass");
|
||||
return render_callback(surface, pass);
|
||||
};
|
||||
Renderer::RenderCallback wrapped_callback = [render_callback](auto& pass) {
|
||||
pass.SetLabel("Playground Main Render Pass");
|
||||
return render_callback(pass);
|
||||
};
|
||||
|
||||
if (!renderer_.Render(surface, wrapped_callback)) {
|
||||
FML_LOG(ERROR) << "Could not render into the surface.";
|
||||
|
||||
@@ -72,8 +72,8 @@ impeller_component("renderer") {
|
||||
"range.h",
|
||||
"render_pass.h",
|
||||
"render_pass.cc",
|
||||
"render_pass_descriptor.h",
|
||||
"render_pass_descriptor.cc",
|
||||
"render_target.h",
|
||||
"render_target.cc",
|
||||
"renderer.h",
|
||||
"renderer.cc",
|
||||
"sampler.h",
|
||||
|
||||
@@ -34,7 +34,7 @@ class CommandBufferMTL final : public CommandBuffer {
|
||||
|
||||
// |CommandBuffer|
|
||||
std::shared_ptr<RenderPass> CreateRenderPass(
|
||||
const RenderTarget& desc) const override;
|
||||
RenderTarget target) const override;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(CommandBufferMTL);
|
||||
};
|
||||
|
||||
@@ -53,12 +53,13 @@ void CommandBufferMTL::SubmitCommands(CompletionCallback callback) {
|
||||
}
|
||||
|
||||
std::shared_ptr<RenderPass> CommandBufferMTL::CreateRenderPass(
|
||||
const RenderTarget& desc) const {
|
||||
RenderTarget target) const {
|
||||
if (!buffer_) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto pass = std::shared_ptr<RenderPassMTL>(new RenderPassMTL(buffer_, desc));
|
||||
auto pass = std::shared_ptr<RenderPassMTL>(
|
||||
new RenderPassMTL(buffer_, std::move(target)));
|
||||
if (!pass->IsValid()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "impeller/renderer/render_pass.h"
|
||||
#include "impeller/renderer/render_pass_descriptor.h"
|
||||
#include "impeller/renderer/render_target.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
@@ -27,7 +27,7 @@ class RenderPassMTL final : public RenderPass {
|
||||
std::string label_;
|
||||
bool is_valid_ = false;
|
||||
|
||||
RenderPassMTL(id<MTLCommandBuffer> buffer, const RenderTarget& desc);
|
||||
RenderPassMTL(id<MTLCommandBuffer> buffer, RenderTarget target);
|
||||
|
||||
// |RenderPass|
|
||||
bool IsValid() const override;
|
||||
|
||||
@@ -92,10 +92,10 @@ static MTLRenderPassDescriptor* ToMTLRenderPassDescriptor(
|
||||
return result;
|
||||
}
|
||||
|
||||
RenderPassMTL::RenderPassMTL(id<MTLCommandBuffer> buffer,
|
||||
const RenderTarget& desc)
|
||||
: buffer_(buffer),
|
||||
desc_(ToMTLRenderPassDescriptor(desc)),
|
||||
RenderPassMTL::RenderPassMTL(id<MTLCommandBuffer> buffer, RenderTarget target)
|
||||
: RenderPass(std::move(target)),
|
||||
buffer_(buffer),
|
||||
desc_(ToMTLRenderPassDescriptor(GetRenderTarget())),
|
||||
transients_buffer_(HostBuffer::Create()) {
|
||||
if (!buffer_ || !desc_) {
|
||||
return;
|
||||
|
||||
@@ -54,12 +54,13 @@ class CommandBuffer {
|
||||
//----------------------------------------------------------------------------
|
||||
/// @brief Create a render pass to record render commands into.
|
||||
///
|
||||
/// @param[in] desc The description of the render pass.
|
||||
/// @param[in] desc The description of the render target this pass will
|
||||
/// target.
|
||||
///
|
||||
/// @return A valid render pass or null.
|
||||
///
|
||||
virtual std::shared_ptr<RenderPass> CreateRenderPass(
|
||||
const RenderTarget& desc) const = 0;
|
||||
RenderTarget render_target) const = 0;
|
||||
|
||||
protected:
|
||||
CommandBuffer();
|
||||
|
||||
@@ -6,8 +6,17 @@
|
||||
|
||||
namespace impeller {
|
||||
|
||||
RenderPass::RenderPass() = default;
|
||||
RenderPass::RenderPass(RenderTarget target)
|
||||
: render_target_(std::move(target)) {}
|
||||
|
||||
RenderPass::~RenderPass() = default;
|
||||
|
||||
const RenderTarget& RenderPass::GetRenderTarget() const {
|
||||
return render_target_;
|
||||
}
|
||||
|
||||
ISize RenderPass::GetRenderTargetSize() const {
|
||||
return render_target_.GetRenderTargetSize();
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "impeller/renderer/command.h"
|
||||
#include "impeller/renderer/render_target.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
@@ -20,10 +21,16 @@ class Allocator;
|
||||
/// Render passes can be obtained from the command buffer in which
|
||||
/// the pass is meant to encode commands into.
|
||||
///
|
||||
/// @see `CommandBuffer`
|
||||
///
|
||||
class RenderPass {
|
||||
public:
|
||||
virtual ~RenderPass();
|
||||
|
||||
const RenderTarget& GetRenderTarget() const;
|
||||
|
||||
ISize GetRenderTargetSize() const;
|
||||
|
||||
virtual bool IsValid() const = 0;
|
||||
|
||||
virtual void SetLabel(std::string label) = 0;
|
||||
@@ -52,9 +59,11 @@ class RenderPass {
|
||||
virtual bool EncodeCommands(Allocator& transients_allocator) const = 0;
|
||||
|
||||
protected:
|
||||
RenderPass();
|
||||
RenderPass(RenderTarget target);
|
||||
|
||||
private:
|
||||
const RenderTarget render_target_;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(RenderPass);
|
||||
};
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "impeller/renderer/render_pass_descriptor.h"
|
||||
#include "impeller/renderer/render_target.h"
|
||||
|
||||
#include "impeller/renderer/texture.h"
|
||||
|
||||
@@ -29,6 +29,11 @@ std::optional<ISize> RenderTarget::GetColorAttachmentSize(size_t index) const {
|
||||
return found->second.texture->GetSize();
|
||||
}
|
||||
|
||||
ISize RenderTarget::GetRenderTargetSize() const {
|
||||
auto size = GetColorAttachmentSize(0u);
|
||||
return size.has_value() ? size.value() : ISize{};
|
||||
}
|
||||
|
||||
RenderTarget& RenderTarget::SetColorAttachment(ColorAttachment attachment,
|
||||
size_t index) {
|
||||
if (attachment) {
|
||||
@@ -21,6 +21,8 @@ class RenderTarget {
|
||||
|
||||
bool HasColorAttachment(size_t index) const;
|
||||
|
||||
ISize GetRenderTargetSize() const;
|
||||
|
||||
std::optional<ISize> GetColorAttachmentSize(size_t index) const;
|
||||
|
||||
RenderTarget& SetColorAttachment(ColorAttachment attachment, size_t index);
|
||||
@@ -51,7 +51,7 @@ bool Renderer::Render(const Surface& surface,
|
||||
return false;
|
||||
}
|
||||
|
||||
if (render_callback && !render_callback(surface, *render_pass)) {
|
||||
if (render_callback && !render_callback(*render_pass)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,8 +21,7 @@ class RenderPass;
|
||||
|
||||
class Renderer {
|
||||
public:
|
||||
using RenderCallback =
|
||||
std::function<bool(const Surface& surface, RenderPass& pass)>;
|
||||
using RenderCallback = std::function<bool(RenderPass& pass)>;
|
||||
|
||||
Renderer(std::shared_ptr<Context> context);
|
||||
|
||||
|
||||
@@ -60,8 +60,7 @@ TEST_F(RendererTest, CanCreateBoxPrimitive) {
|
||||
ASSERT_TRUE(bridge && boston);
|
||||
auto sampler = context->GetSamplerLibrary()->GetSampler({});
|
||||
ASSERT_TRUE(sampler);
|
||||
Renderer::RenderCallback callback = [&](const Surface& surface,
|
||||
RenderPass& pass) {
|
||||
Renderer::RenderCallback callback = [&](RenderPass& pass) {
|
||||
Command cmd;
|
||||
cmd.label = "Box";
|
||||
cmd.pipeline = box_pipeline;
|
||||
@@ -69,7 +68,7 @@ TEST_F(RendererTest, CanCreateBoxPrimitive) {
|
||||
cmd.BindVertices(vertex_buffer);
|
||||
|
||||
VS::UniformBuffer uniforms;
|
||||
uniforms.mvp = Matrix::MakeOrthographic(surface.GetSize());
|
||||
uniforms.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize());
|
||||
VS::BindUniformBuffer(cmd,
|
||||
pass.GetTransientsBuffer().EmplaceUniform(uniforms));
|
||||
|
||||
@@ -125,8 +124,7 @@ TEST_F(RendererTest, CanRenderMultiplePrimitives) {
|
||||
auto sampler = context->GetSamplerLibrary()->GetSampler({});
|
||||
ASSERT_TRUE(sampler);
|
||||
|
||||
Renderer::RenderCallback callback = [&](const Surface& surface,
|
||||
RenderPass& pass) {
|
||||
Renderer::RenderCallback callback = [&](RenderPass& pass) {
|
||||
Command cmd;
|
||||
cmd.label = "Box";
|
||||
cmd.pipeline = box_pipeline;
|
||||
@@ -149,7 +147,7 @@ TEST_F(RendererTest, CanRenderMultiplePrimitives) {
|
||||
for (size_t i = 0; i < 1; i++) {
|
||||
for (size_t j = 0; j < 1; j++) {
|
||||
VS::UniformBuffer uniforms;
|
||||
uniforms.mvp = Matrix::MakeOrthographic(surface.GetSize()) *
|
||||
uniforms.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
|
||||
Matrix::MakeTranslation({i * 50.0f, j * 50.0f, 0.0f});
|
||||
VS::BindUniformBuffer(
|
||||
cmd, pass.GetTransientsBuffer().EmplaceUniform(uniforms));
|
||||
@@ -301,8 +299,7 @@ TEST_F(RendererTest, CanRenderPath) {
|
||||
auto sampler = context->GetSamplerLibrary()->GetSampler({});
|
||||
ASSERT_TRUE(sampler);
|
||||
|
||||
Renderer::RenderCallback callback = [&](const Surface& surface,
|
||||
RenderPass& pass) {
|
||||
Renderer::RenderCallback callback = [&](RenderPass& pass) {
|
||||
Command cmd;
|
||||
cmd.label = "Box";
|
||||
cmd.pipeline = box_pipeline.WaitAndGet();
|
||||
@@ -324,7 +321,7 @@ TEST_F(RendererTest, CanRenderPath) {
|
||||
cmd.winding = tessellator.GetFrontFaceWinding();
|
||||
|
||||
VS::UniformBuffer uniforms;
|
||||
uniforms.mvp = Matrix::MakeOrthographic(surface.GetSize());
|
||||
uniforms.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize());
|
||||
VS::BindUniformBuffer(cmd,
|
||||
pass.GetTransientsBuffer().EmplaceUniform(uniforms));
|
||||
if (!pass.AddCommand(cmd)) {
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "impeller/renderer/context.h"
|
||||
#include "impeller/renderer/render_pass.h"
|
||||
#include "impeller/renderer/render_pass_descriptor.h"
|
||||
#include "impeller/renderer/render_target.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user