Skip to content

Commit 38d4aba

Browse files
chinmaygardednfield
authored andcommitted
Renderer components no longer need a surface reference to function.
1 parent 65ffd04 commit 38d4aba

23 files changed

+75
-71
lines changed

impeller/aiks/aiks_playground.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ bool AiksPlayground::OpenPlaygroundHere(const Picture& picture) {
1919
}
2020

2121
return Playground::OpenPlaygroundHere(
22-
[renderer, &picture](const Surface& surface, RenderPass& pass) -> bool {
23-
return renderer->Render(surface, pass, picture);
22+
[renderer, &picture](RenderPass& pass) -> bool {
23+
return renderer->Render(pass, picture);
2424
});
2525
}
2626

impeller/aiks/picture_renderer.cc

+2-4
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,14 @@ bool PictureRenderer::IsValid() const {
2222
return is_valid_;
2323
}
2424

25-
bool PictureRenderer::Render(const Surface& surface,
26-
RenderPass& parent_pass,
27-
const Picture& picture) {
25+
bool PictureRenderer::Render(RenderPass& parent_pass, const Picture& picture) {
2826
if (!IsValid()) {
2927
return false;
3028
}
3129

3230
for (const auto& entry : picture.entries) {
3331
if (auto pass = entry.pass) {
34-
if (!entity_renderer_.RenderEntities(surface, parent_pass,
32+
if (!entity_renderer_.RenderEntities(parent_pass,
3533
pass->GetPassEntities())) {
3634
return false;
3735
}

impeller/aiks/picture_renderer.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ class PictureRenderer {
2222

2323
bool IsValid() const;
2424

25-
[[nodiscard]] bool Render(const Surface& surface,
26-
RenderPass& parent_pass,
27-
const Picture& picture);
25+
[[nodiscard]] bool Render(RenderPass& parent_pass, const Picture& picture);
2826

2927
private:
3028
EntityRenderer entity_renderer_;

impeller/entity/contents.cc

+9-14
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ const std::vector<Color>& LinearGradientContents::GetColors() const {
5656

5757
bool LinearGradientContents::Render(const ContentRenderer& renderer,
5858
const Entity& entity,
59-
const Surface& surface,
6059
RenderPass& pass) const {
6160
using VS = GradientFillPipeline::VertexShader;
6261
using FS = GradientFillPipeline::FragmentShader;
@@ -75,8 +74,8 @@ bool LinearGradientContents::Render(const ContentRenderer& renderer,
7574
}
7675

7776
VS::FrameInfo frame_info;
78-
frame_info.mvp =
79-
Matrix::MakeOrthographic(surface.GetSize()) * entity.GetTransformation();
77+
frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
78+
entity.GetTransformation();
8079

8180
FS::GradientInfo gradient_info;
8281
gradient_info.start_point = start_point_;
@@ -134,7 +133,6 @@ static VertexBuffer CreateSolidFillVertices(const Path& path,
134133

135134
bool SolidColorContents::Render(const ContentRenderer& renderer,
136135
const Entity& entity,
137-
const Surface& surface,
138136
RenderPass& pass) const {
139137
if (color_.IsTransparent()) {
140138
return true;
@@ -150,8 +148,8 @@ bool SolidColorContents::Render(const ContentRenderer& renderer,
150148
CreateSolidFillVertices(entity.GetPath(), pass.GetTransientsBuffer()));
151149

152150
VS::FrameInfo frame_info;
153-
frame_info.mvp =
154-
Matrix::MakeOrthographic(surface.GetSize()) * entity.GetTransformation();
151+
frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
152+
entity.GetTransformation();
155153
frame_info.color = color_;
156154
VS::BindFrameInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frame_info));
157155

@@ -188,7 +186,6 @@ std::shared_ptr<Texture> TextureContents::GetTexture() const {
188186

189187
bool TextureContents::Render(const ContentRenderer& renderer,
190188
const Entity& entity,
191-
const Surface& surface,
192189
RenderPass& pass) const {
193190
if (texture_ == nullptr) {
194191
return true;
@@ -234,8 +231,8 @@ bool TextureContents::Render(const ContentRenderer& renderer,
234231
auto& host_buffer = pass.GetTransientsBuffer();
235232

236233
VS::FrameInfo frame_info;
237-
frame_info.mvp =
238-
Matrix::MakeOrthographic(surface.GetSize()) * entity.GetTransformation();
234+
frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
235+
entity.GetTransformation();
239236

240237
Command cmd;
241238
cmd.label = "TextureFill";
@@ -316,7 +313,6 @@ static VertexBuffer CreateSolidStrokeVertices(const Path& path,
316313

317314
bool SolidStrokeContents::Render(const ContentRenderer& renderer,
318315
const Entity& entity,
319-
const Surface& surface,
320316
RenderPass& pass) const {
321317
if (color_.IsTransparent() || stroke_size_ <= 0.0) {
322318
return true;
@@ -325,8 +321,8 @@ bool SolidStrokeContents::Render(const ContentRenderer& renderer,
325321
using VS = SolidStrokeVertexShader;
326322

327323
VS::FrameInfo frame_info;
328-
frame_info.mvp =
329-
Matrix::MakeOrthographic(surface.GetSize()) * entity.GetTransformation();
324+
frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
325+
entity.GetTransformation();
330326

331327
VS::StrokeInfo stroke_info;
332328
stroke_info.color = color_;
@@ -366,7 +362,6 @@ ClipContents::~ClipContents() = default;
366362

367363
bool ClipContents::Render(const ContentRenderer& renderer,
368364
const Entity& entity,
369-
const Surface& surface,
370365
RenderPass& pass) const {
371366
using VS = ClipPipeline::VertexShader;
372367

@@ -380,7 +375,7 @@ bool ClipContents::Render(const ContentRenderer& renderer,
380375
VS::FrameInfo info;
381376
// The color really doesn't matter.
382377
info.color = Color::SkyBlue();
383-
info.mvp = Matrix::MakeOrthographic(surface.GetSize());
378+
info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize());
384379

385380
VS::BindFrameInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(info));
386381

impeller/entity/contents.h

-6
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class Contents {
2828

2929
virtual bool Render(const ContentRenderer& renderer,
3030
const Entity& entity,
31-
const Surface& surface,
3231
RenderPass& pass) const = 0;
3332

3433
private:
@@ -44,7 +43,6 @@ class LinearGradientContents final : public Contents {
4443
// |Contents|
4544
bool Render(const ContentRenderer& renderer,
4645
const Entity& entity,
47-
const Surface& surface,
4846
RenderPass& pass) const override;
4947

5048
void SetEndPoints(Point start_point, Point end_point);
@@ -76,7 +74,6 @@ class SolidColorContents final : public Contents {
7674
// |Contents|
7775
bool Render(const ContentRenderer& renderer,
7876
const Entity& entity,
79-
const Surface& surface,
8077
RenderPass& pass) const override;
8178

8279
private:
@@ -102,7 +99,6 @@ class TextureContents final : public Contents {
10299
// |Contents|
103100
bool Render(const ContentRenderer& renderer,
104101
const Entity& entity,
105-
const Surface& surface,
106102
RenderPass& pass) const override;
107103

108104
public:
@@ -129,7 +125,6 @@ class SolidStrokeContents final : public Contents {
129125
// |Contents|
130126
bool Render(const ContentRenderer& renderer,
131127
const Entity& entity,
132-
const Surface& surface,
133128
RenderPass& pass) const override;
134129

135130
private:
@@ -148,7 +143,6 @@ class ClipContents final : public Contents {
148143
// |Contents|
149144
bool Render(const ContentRenderer& renderer,
150145
const Entity& entity,
151-
const Surface& surface,
152146
RenderPass& pass) const override;
153147

154148
private:

impeller/entity/entity_playground.cc

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ bool EntityPlayground::OpenPlaygroundHere(Entity entity) {
1717
return false;
1818
}
1919
}
20-
Renderer::RenderCallback callback = [&](const Surface& surface,
21-
RenderPass& pass) -> bool {
20+
Renderer::RenderCallback callback = [&](RenderPass& pass) -> bool {
2221
std::vector<Entity> entities = {entity};
23-
return renderer_->RenderEntities(surface, pass, entities);
22+
return renderer_->RenderEntities(pass, entities);
2423
};
2524
return Playground::OpenPlaygroundHere(callback);
2625
}

impeller/entity/entity_renderer.cc

+2-3
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,15 @@ bool EntityRenderer::IsValid() const {
2929
return is_valid_;
3030
}
3131

32-
bool EntityRenderer::RenderEntities(const Surface& surface,
33-
RenderPass& parent_pass,
32+
bool EntityRenderer::RenderEntities(RenderPass& parent_pass,
3433
const std::vector<Entity>& entities) {
3534
if (!IsValid()) {
3635
return false;
3736
}
3837

3938
for (const auto& entity : entities) {
4039
if (auto contents = entity.GetContents()) {
41-
if (!contents->Render(*content_renderer_, entity, surface, parent_pass)) {
40+
if (!contents->Render(*content_renderer_, entity, parent_pass)) {
4241
return false;
4342
}
4443
}

impeller/entity/entity_renderer.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ class EntityRenderer {
2323

2424
bool IsValid() const;
2525

26-
[[nodiscard]] bool RenderEntities(const Surface& surface,
27-
RenderPass& parent_pass,
26+
[[nodiscard]] bool RenderEntities(RenderPass& parent_pass,
2827
const std::vector<Entity>& entities);
2928

3029
private:

impeller/playground/playground.mm

+4-5
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,10 @@ static void PlaygroundKeyCallback(GLFWwindow* window,
180180

181181
Surface surface(desc);
182182

183-
Renderer::RenderCallback wrapped_callback =
184-
[render_callback](const auto& surface, auto& pass) {
185-
pass.SetLabel("Playground Main Render Pass");
186-
return render_callback(surface, pass);
187-
};
183+
Renderer::RenderCallback wrapped_callback = [render_callback](auto& pass) {
184+
pass.SetLabel("Playground Main Render Pass");
185+
return render_callback(pass);
186+
};
188187

189188
if (!renderer_.Render(surface, wrapped_callback)) {
190189
FML_LOG(ERROR) << "Could not render into the surface.";

impeller/renderer/BUILD.gn

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ impeller_component("renderer") {
7272
"range.h",
7373
"render_pass.h",
7474
"render_pass.cc",
75-
"render_pass_descriptor.h",
76-
"render_pass_descriptor.cc",
75+
"render_target.h",
76+
"render_target.cc",
7777
"renderer.h",
7878
"renderer.cc",
7979
"sampler.h",

impeller/renderer/backend/metal/command_buffer_mtl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class CommandBufferMTL final : public CommandBuffer {
3434

3535
// |CommandBuffer|
3636
std::shared_ptr<RenderPass> CreateRenderPass(
37-
const RenderTarget& desc) const override;
37+
RenderTarget target) const override;
3838

3939
FML_DISALLOW_COPY_AND_ASSIGN(CommandBufferMTL);
4040
};

impeller/renderer/backend/metal/command_buffer_mtl.mm

+3-2
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,13 @@
5353
}
5454

5555
std::shared_ptr<RenderPass> CommandBufferMTL::CreateRenderPass(
56-
const RenderTarget& desc) const {
56+
RenderTarget target) const {
5757
if (!buffer_) {
5858
return nullptr;
5959
}
6060

61-
auto pass = std::shared_ptr<RenderPassMTL>(new RenderPassMTL(buffer_, desc));
61+
auto pass = std::shared_ptr<RenderPassMTL>(
62+
new RenderPassMTL(buffer_, std::move(target)));
6263
if (!pass->IsValid()) {
6364
return nullptr;
6465
}

impeller/renderer/backend/metal/render_pass_mtl.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include "flutter/fml/macros.h"
1010
#include "impeller/renderer/render_pass.h"
11-
#include "impeller/renderer/render_pass_descriptor.h"
11+
#include "impeller/renderer/render_target.h"
1212

1313
namespace impeller {
1414

@@ -27,7 +27,7 @@ class RenderPassMTL final : public RenderPass {
2727
std::string label_;
2828
bool is_valid_ = false;
2929

30-
RenderPassMTL(id<MTLCommandBuffer> buffer, const RenderTarget& desc);
30+
RenderPassMTL(id<MTLCommandBuffer> buffer, RenderTarget target);
3131

3232
// |RenderPass|
3333
bool IsValid() const override;

impeller/renderer/backend/metal/render_pass_mtl.mm

+4-4
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,10 @@ static bool ConfigureStencilAttachment(
9292
return result;
9393
}
9494

95-
RenderPassMTL::RenderPassMTL(id<MTLCommandBuffer> buffer,
96-
const RenderTarget& desc)
97-
: buffer_(buffer),
98-
desc_(ToMTLRenderPassDescriptor(desc)),
95+
RenderPassMTL::RenderPassMTL(id<MTLCommandBuffer> buffer, RenderTarget target)
96+
: RenderPass(std::move(target)),
97+
buffer_(buffer),
98+
desc_(ToMTLRenderPassDescriptor(GetRenderTarget())),
9999
transients_buffer_(HostBuffer::Create()) {
100100
if (!buffer_ || !desc_) {
101101
return;

impeller/renderer/command_buffer.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,13 @@ class CommandBuffer {
5454
//----------------------------------------------------------------------------
5555
/// @brief Create a render pass to record render commands into.
5656
///
57-
/// @param[in] desc The description of the render pass.
57+
/// @param[in] desc The description of the render target this pass will
58+
/// target.
5859
///
5960
/// @return A valid render pass or null.
6061
///
6162
virtual std::shared_ptr<RenderPass> CreateRenderPass(
62-
const RenderTarget& desc) const = 0;
63+
RenderTarget render_target) const = 0;
6364

6465
protected:
6566
CommandBuffer();

impeller/renderer/render_pass.cc

+10-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,17 @@
66

77
namespace impeller {
88

9-
RenderPass::RenderPass() = default;
9+
RenderPass::RenderPass(RenderTarget target)
10+
: render_target_(std::move(target)) {}
1011

1112
RenderPass::~RenderPass() = default;
1213

14+
const RenderTarget& RenderPass::GetRenderTarget() const {
15+
return render_target_;
16+
}
17+
18+
ISize RenderPass::GetRenderTargetSize() const {
19+
return render_target_.GetRenderTargetSize();
20+
}
21+
1322
} // namespace impeller

impeller/renderer/render_pass.h

+10-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <string>
88

99
#include "impeller/renderer/command.h"
10+
#include "impeller/renderer/render_target.h"
1011

1112
namespace impeller {
1213

@@ -20,10 +21,16 @@ class Allocator;
2021
/// Render passes can be obtained from the command buffer in which
2122
/// the pass is meant to encode commands into.
2223
///
24+
/// @see `CommandBuffer`
25+
///
2326
class RenderPass {
2427
public:
2528
virtual ~RenderPass();
2629

30+
const RenderTarget& GetRenderTarget() const;
31+
32+
ISize GetRenderTargetSize() const;
33+
2734
virtual bool IsValid() const = 0;
2835

2936
virtual void SetLabel(std::string label) = 0;
@@ -52,9 +59,11 @@ class RenderPass {
5259
virtual bool EncodeCommands(Allocator& transients_allocator) const = 0;
5360

5461
protected:
55-
RenderPass();
62+
RenderPass(RenderTarget target);
5663

5764
private:
65+
const RenderTarget render_target_;
66+
5867
FML_DISALLOW_COPY_AND_ASSIGN(RenderPass);
5968
};
6069

0 commit comments

Comments
 (0)