Skip to content

Commit

Permalink
Renderer components no longer need a surface reference to function.
Browse files Browse the repository at this point in the history
  • Loading branch information
chinmaygarde authored and dnfield committed Apr 27, 2022
1 parent 65ffd04 commit 38d4aba
Show file tree
Hide file tree
Showing 23 changed files with 75 additions and 71 deletions.
4 changes: 2 additions & 2 deletions impeller/aiks/aiks_playground.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}

Expand Down
6 changes: 2 additions & 4 deletions impeller/aiks/picture_renderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 1 addition & 3 deletions impeller/aiks/picture_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down
23 changes: 9 additions & 14 deletions impeller/entity/contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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_;
Expand Down Expand Up @@ -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;
Expand All @@ -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));

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand All @@ -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_;
Expand Down Expand Up @@ -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;

Expand All @@ -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));

Expand Down
6 changes: 0 additions & 6 deletions impeller/entity/contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class Contents {

virtual bool Render(const ContentRenderer& renderer,
const Entity& entity,
const Surface& surface,
RenderPass& pass) const = 0;

private:
Expand All @@ -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);
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down
5 changes: 2 additions & 3 deletions impeller/entity/entity_playground.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
5 changes: 2 additions & 3 deletions impeller/entity/entity_renderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,15 @@ 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;
}

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;
}
}
Expand Down
3 changes: 1 addition & 2 deletions impeller/entity/entity_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 4 additions & 5 deletions impeller/playground/playground.mm
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,10 @@ static void PlaygroundKeyCallback(GLFWwindow* window,

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.";
Expand Down
4 changes: 2 additions & 2 deletions impeller/renderer/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion impeller/renderer/backend/metal/command_buffer_mtl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down
5 changes: 3 additions & 2 deletions impeller/renderer/backend/metal/command_buffer_mtl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@
}

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;
}
Expand Down
4 changes: 2 additions & 2 deletions impeller/renderer/backend/metal/render_pass_mtl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions impeller/renderer/backend/metal/render_pass_mtl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ static bool ConfigureStencilAttachment(
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;
Expand Down
5 changes: 3 additions & 2 deletions impeller/renderer/command_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
11 changes: 10 additions & 1 deletion impeller/renderer/render_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 10 additions & 1 deletion impeller/renderer/render_pass.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <string>

#include "impeller/renderer/command.h"
#include "impeller/renderer/render_target.h"

namespace impeller {

Expand All @@ -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;
Expand Down Expand Up @@ -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);
};

Expand Down
Loading

0 comments on commit 38d4aba

Please sign in to comment.