Skip to content

Commit 612b54f

Browse files
chinmaygardednfield
authored andcommitted
Start consolidating content rendering.
1 parent a093636 commit 612b54f

10 files changed

+164
-131
lines changed

impeller/.clang-format

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
# Defines the Chromium style for automatic reformatting.
22
# http://clang.llvm.org/docs/ClangFormatStyleOptions.html
33
BasedOnStyle: Chromium
4-
# This defaults to 'Auto'. Explicitly set it for a while, so that
5-
# 'vector<vector<int> >' in existing files gets formatted to
6-
# 'vector<vector<int>>'. ('Auto' means that clang-format will only use
7-
# 'int>>' if the file already contains at least one such instance.)
8-
Standard: Cpp11
4+
Standard: c++17
5+
EmptyLineBeforeAccessModifier: Always

impeller/entity/content_renderer.cc

+9
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ ContentRenderer::ContentRenderer(std::shared_ptr<Context> context)
1313
}
1414

1515
gradient_fill_pipeline_ = std::make_unique<GradientFillPipeline>(*context_);
16+
solid_fill_pipeline_ = std::make_unique<SolidFillPipeline>(*context_);
1617

1718
is_valid_ = true;
1819
}
@@ -34,4 +35,12 @@ std::shared_ptr<Pipeline> ContentRenderer::GetGradientFillPipeline() const {
3435
return gradient_fill_pipeline_->WaitAndGet();
3536
}
3637

38+
std::shared_ptr<Pipeline> ContentRenderer::GetSolidFillPipeline() const {
39+
if (!IsValid()) {
40+
return nullptr;
41+
}
42+
43+
return solid_fill_pipeline_->WaitAndGet();
44+
}
45+
3746
} // namespace impeller

impeller/entity/content_renderer.h

+7
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@
99
#include "flutter/fml/macros.h"
1010
#include "flutter/impeller/entity/gradient_fill.frag.h"
1111
#include "flutter/impeller/entity/gradient_fill.vert.h"
12+
#include "flutter/impeller/entity/solid_fill.frag.h"
13+
#include "flutter/impeller/entity/solid_fill.vert.h"
1214
#include "impeller/renderer/pipeline.h"
1315

1416
namespace impeller {
1517

1618
using GradientFillPipeline =
1719
PipelineT<GradientFillVertexShader, GradientFillFragmentShader>;
20+
using SolidFillPipeline =
21+
PipelineT<SolidFillVertexShader, SolidFillFragmentShader>;
1822

1923
class ContentRenderer {
2024
public:
@@ -26,11 +30,14 @@ class ContentRenderer {
2630

2731
std::shared_ptr<Pipeline> GetGradientFillPipeline() const;
2832

33+
std::shared_ptr<Pipeline> GetSolidFillPipeline() const;
34+
2935
std::shared_ptr<Context> GetContext() const;
3036

3137
private:
3238
std::shared_ptr<Context> context_;
3339
std::unique_ptr<GradientFillPipeline> gradient_fill_pipeline_;
40+
std::unique_ptr<SolidFillPipeline> solid_fill_pipeline_;
3441
bool is_valid_ = false;
3542

3643
FML_DISALLOW_COPY_AND_ASSIGN(ContentRenderer);

impeller/entity/contents.cc

+76-1
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,18 @@
1414

1515
namespace impeller {
1616

17+
/*******************************************************************************
18+
******* Contents
19+
******************************************************************************/
20+
1721
Contents::Contents() = default;
1822

1923
Contents::~Contents() = default;
2024

25+
/*******************************************************************************
26+
******* Linear Gradient Contents
27+
******************************************************************************/
28+
2129
LinearGradientContents::LinearGradientContents() = default;
2230

2331
LinearGradientContents::~LinearGradientContents() = default;
@@ -41,7 +49,6 @@ const std::vector<Color>& LinearGradientContents::GetColors() const {
4149
return colors_;
4250
}
4351

44-
// |Contents|
4552
bool LinearGradientContents::Render(const ContentRenderer& renderer,
4653
const Entity& entity,
4754
const Surface& surface,
@@ -84,4 +91,72 @@ bool LinearGradientContents::Render(const ContentRenderer& renderer,
8491
return pass.AddCommand(std::move(cmd));
8592
}
8693

94+
/*******************************************************************************
95+
******* SolidColorContents
96+
******************************************************************************/
97+
98+
void SolidColorContents::SetColor(Color color) {
99+
color_ = color;
100+
}
101+
102+
const Color& SolidColorContents::GetColor() const {
103+
return color_;
104+
}
105+
106+
bool SolidColorContents::Render(const ContentRenderer& renderer,
107+
const Entity& entity,
108+
const Surface& surface,
109+
RenderPass& pass) const {
110+
using VS = SolidFillPipeline::VertexShader;
111+
112+
Command cmd;
113+
cmd.label = "SolidFill";
114+
cmd.pipeline = renderer.GetSolidFillPipeline();
115+
if (cmd.pipeline == nullptr) {
116+
return false;
117+
}
118+
119+
VertexBufferBuilder<VS::PerVertexData> vtx_builder;
120+
{
121+
auto tesselation_result = Tessellator{}.Tessellate(
122+
entity.GetPath().CreatePolyline(), [&vtx_builder](auto point) {
123+
VS::PerVertexData vtx;
124+
vtx.vertices = point;
125+
vtx_builder.AppendVertex(vtx);
126+
});
127+
if (!tesselation_result) {
128+
return false;
129+
}
130+
}
131+
132+
cmd.BindVertices(vtx_builder.CreateVertexBuffer(
133+
*renderer.GetContext()->GetPermanentsAllocator()));
134+
135+
VS::FrameInfo frame_info;
136+
frame_info.mvp =
137+
Matrix::MakeOrthographic(surface.GetSize()) * entity.GetTransformation();
138+
frame_info.color = entity.GetBackgroundColor();
139+
VS::BindFrameInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frame_info));
140+
141+
cmd.primitive_type = PrimitiveType::kTriangle;
142+
143+
if (!pass.AddCommand(std::move(cmd))) {
144+
return false;
145+
}
146+
147+
return true;
148+
}
149+
150+
/*******************************************************************************
151+
******* SolidStrokeContents
152+
******************************************************************************/
153+
154+
void SolidStrokeContents::SetColor(Color color) {
155+
color_ = color;
156+
}
157+
158+
const Color& SolidStrokeContents::GetColor() const {
159+
return color_;
160+
}
161+
87162
} // namespace impeller

impeller/entity/contents.h

+51-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Contents {
2121
public:
2222
Contents();
2323

24-
~Contents();
24+
virtual ~Contents();
2525

2626
virtual bool Render(const ContentRenderer& renderer,
2727
const Entity& entity,
@@ -36,7 +36,7 @@ class LinearGradientContents final : public Contents {
3636
public:
3737
LinearGradientContents();
3838

39-
~LinearGradientContents();
39+
~LinearGradientContents() override;
4040

4141
// |Contents|
4242
bool Render(const ContentRenderer& renderer,
@@ -58,4 +58,53 @@ class LinearGradientContents final : public Contents {
5858
FML_DISALLOW_COPY_AND_ASSIGN(LinearGradientContents);
5959
};
6060

61+
class SolidColorContents final : public Contents {
62+
public:
63+
SolidColorContents();
64+
65+
~SolidColorContents() override;
66+
67+
void SetColor(Color color);
68+
69+
const Color& GetColor() const;
70+
71+
// |Contents|
72+
bool Render(const ContentRenderer& renderer,
73+
const Entity& entity,
74+
const Surface& surface,
75+
RenderPass& pass) const override;
76+
77+
private:
78+
Color color_;
79+
80+
FML_DISALLOW_COPY_AND_ASSIGN(SolidColorContents);
81+
};
82+
83+
class SolidStrokeContents final : public Contents {
84+
public:
85+
SolidStrokeContents();
86+
87+
~SolidStrokeContents();
88+
89+
void SetColor(Color color);
90+
91+
const Color& GetColor() const;
92+
93+
void SetStrokeSize(Scalar size) { stroke_size_ = size; }
94+
95+
Scalar GetStrokeSize() const { return stroke_size_; }
96+
97+
// |Contents|
98+
bool Render(const ContentRenderer& renderer,
99+
const Entity& entity,
100+
const Surface& surface,
101+
RenderPass& pass) const override;
102+
103+
private:
104+
Color color_;
105+
Scalar stroke_size_ = 0.0;
106+
107+
FML_DISALLOW_COPY_AND_ASSIGN(SolidStrokeContents);
108+
};
109+
61110
} // namespace impeller

impeller/entity/entity.cc

-33
Original file line numberDiff line numberDiff line change
@@ -66,37 +66,4 @@ const std::shared_ptr<Contents>& Entity::GetContents() const {
6666
return contents_;
6767
}
6868

69-
bool Entity::HasStroke() const {
70-
return stroke_size_ > 0.0 && !stroke_color_.IsTransparent();
71-
}
72-
73-
bool Entity::HasContents() const {
74-
if (contents_) {
75-
return true;
76-
}
77-
return !background_color_.IsTransparent();
78-
}
79-
80-
bool Entity::HasRenderableContents() const {
81-
const bool has_empty_path = path_.GetBoundingBox().IsZero();
82-
83-
if (has_empty_path) {
84-
return false;
85-
}
86-
87-
if (IsClip()) {
88-
return true;
89-
}
90-
91-
if (HasStroke()) {
92-
return true;
93-
}
94-
95-
if (HasContents()) {
96-
return true;
97-
}
98-
99-
return false;
100-
}
101-
10269
} // namespace impeller

impeller/entity/entity.h

-6
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,6 @@ class Entity {
4343

4444
bool IsClip() const;
4545

46-
bool HasStroke() const;
47-
48-
bool HasContents() const;
49-
50-
bool HasRenderableContents() const;
51-
5246
void SetContents(std::shared_ptr<Contents> contents);
5347

5448
const std::shared_ptr<Contents>& GetContents() const;

impeller/entity/entity_renderer.cc

+3-63
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
#include "flutter/impeller/entity/entity_renderer.h"
66

77
#include "flutter/fml/trace_event.h"
8-
#include "impeller/renderer/tessellator.h"
9-
#include "impeller/renderer/vertex_buffer_builder.h"
8+
#include "impeller/entity/content_renderer.h"
109

1110
namespace impeller {
1211

@@ -21,8 +20,6 @@ EntityRenderer::EntityRenderer(std::shared_ptr<Context> context)
2120
return;
2221
}
2322

24-
solid_fill_pipeline_ = std::make_unique<SolidFillPipeline>(*context_);
25-
2623
is_valid_ = true;
2724
}
2825

@@ -40,70 +37,13 @@ bool EntityRenderer::RenderEntities(const Surface& surface,
4037
}
4138

4239
for (const auto& entity : entities) {
43-
if (RenderEntity(surface, onscreen_pass, entity) ==
44-
EntityRenderer::RenderResult::kFailure) {
40+
if (auto contents = entity.GetContents();
41+
!contents->Render(*content_renderer_, entity, surface, onscreen_pass)) {
4542
return false;
4643
}
4744
}
4845

4946
return true;
5047
}
5148

52-
EntityRenderer::RenderResult EntityRenderer::RenderEntity(
53-
const Surface& surface,
54-
RenderPass& pass,
55-
const Entity& entity) {
56-
if (!entity.HasRenderableContents()) {
57-
return RenderResult::kSkipped;
58-
}
59-
60-
if (entity.HasContents() && !entity.IsClip() && !entity.GetContents()) {
61-
using VS = SolidFillPipeline::VertexShader;
62-
63-
Command cmd;
64-
cmd.label = "SolidFill";
65-
cmd.pipeline = solid_fill_pipeline_->WaitAndGet();
66-
if (cmd.pipeline == nullptr) {
67-
return RenderResult::kFailure;
68-
}
69-
70-
VertexBufferBuilder<VS::PerVertexData> vtx_builder;
71-
{
72-
auto tesselation_result = Tessellator{}.Tessellate(
73-
entity.GetPath().CreatePolyline(), [&vtx_builder](auto point) {
74-
VS::PerVertexData vtx;
75-
vtx.vertices = point;
76-
vtx_builder.AppendVertex(vtx);
77-
});
78-
if (!tesselation_result) {
79-
return RenderResult::kFailure;
80-
}
81-
}
82-
83-
cmd.BindVertices(
84-
vtx_builder.CreateVertexBuffer(*context_->GetPermanentsAllocator()));
85-
86-
VS::FrameInfo frame_info;
87-
frame_info.mvp = Matrix::MakeOrthographic(surface.GetSize()) *
88-
entity.GetTransformation();
89-
frame_info.color = entity.GetBackgroundColor();
90-
VS::BindFrameInfo(cmd,
91-
pass.GetTransientsBuffer().EmplaceUniform(frame_info));
92-
93-
cmd.primitive_type = PrimitiveType::kTriangle;
94-
95-
if (!pass.AddCommand(std::move(cmd))) {
96-
return RenderResult::kFailure;
97-
}
98-
} else if (entity.GetContents()) {
99-
auto result =
100-
entity.GetContents()->Render(*content_renderer_, entity, surface, pass);
101-
if (!result) {
102-
return RenderResult::kFailure;
103-
}
104-
}
105-
106-
return RenderResult::kSuccess;
107-
}
108-
10949
} // namespace impeller

0 commit comments

Comments
 (0)