Skip to content

Commit 56bf47d

Browse files
author
jonahwilliams
committed
++
1 parent b2cc708 commit 56bf47d

7 files changed

Lines changed: 134 additions & 73 deletions

File tree

impeller/entity/BUILD.gn

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ impeller_shaders("entity_shaders") {
88
name = "entity"
99

1010
shaders = [
11-
"shaders/atlas_fill.frag",
12-
"shaders/atlas_fill.vert",
1311
"shaders/blending/advanced_blend.vert",
1412
"shaders/blending/advanced_blend_color.frag",
1513
"shaders/blending/advanced_blend_colorburn.frag",

impeller/entity/contents/atlas_contents.cc

Lines changed: 126 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
#include "impeller/renderer/sampler_library.h"
1010
#include "impeller/renderer/vertex_buffer_builder.h"
1111

12-
#include "impeller/entity/atlas_fill.frag.h"
13-
#include "impeller/entity/atlas_fill.vert.h"
1412
#include "impeller/entity/contents/atlas_contents.h"
1513
#include "impeller/entity/contents/content_context.h"
1614
#include "impeller/entity/entity.h"
15+
#include "impeller/entity/texture_fill.frag.h"
16+
#include "impeller/entity/texture_fill.vert.h"
1717
#include "impeller/renderer/render_pass.h"
1818

1919
namespace impeller {
@@ -47,7 +47,6 @@ void AtlasContents::SetAlpha(Scalar alpha) {
4747
}
4848

4949
void AtlasContents::SetBlendMode(BlendMode blend_mode) {
50-
// TODO(jonahwilliams): blending of colors with texture.
5150
blend_mode_ = blend_mode;
5251
}
5352

@@ -81,12 +80,19 @@ const SamplerDescriptor& AtlasContents::GetSamplerDescriptor() const {
8180
bool AtlasContents::Render(const ContentContext& renderer,
8281
const Entity& entity,
8382
RenderPass& pass) const {
84-
if (texture_ == nullptr) {
83+
if (texture_ == nullptr || blend_mode_ == BlendMode::kClear) {
8584
return true;
8685
}
8786

88-
using VS = AtlasFillVertexShader;
89-
using FS = AtlasFillFragmentShader;
87+
if (blend_mode_ == BlendMode::kSource || colors_.size() == 0) {
88+
return RenderNoColor(renderer, entity, pass);
89+
}
90+
if (blend_mode_ == BlendMode::kDestination) {
91+
return RenderOnlyColor(renderer, entity, pass);
92+
}
93+
94+
using VS = AtlasBlendSrcOverPipeline::VertexShader;
95+
using FS = AtlasBlendSrcOverPipeline::FragmentShader;
9096

9197
const auto texture_size = texture_->GetSize();
9298
if (texture_size.IsEmpty()) {
@@ -101,7 +107,7 @@ bool AtlasContents::Render(const ContentContext& renderer,
101107
for (size_t i = 0; i < texture_coords_.size(); i++) {
102108
auto sample_rect = texture_coords_[i];
103109
auto matrix = transforms_[i];
104-
auto color = colors_.size() > 0 ? colors_[i] : Color::Black();
110+
auto color = colors_[i];
105111
auto transformed_points =
106112
Rect::MakeSize(sample_rect.size).GetTransformedPoints(matrix);
107113

@@ -135,11 +141,10 @@ bool AtlasContents::Render(const ContentContext& renderer,
135141
cmd.label = "DrawAtlas";
136142
switch (blend_mode_) {
137143
case BlendMode::kClear:
138-
return true;
139144
case BlendMode::kSource:
140-
// Color only, just use vertices.
141145
case BlendMode::kDestination:
142-
// Image only, same as no color.
146+
// All handled above.
147+
return true;
143148
case BlendMode::kSourceOver:
144149
cmd.pipeline = renderer.GetAtlasBlendSrcOverPipeline(
145150
OptionsFromPassAndEntity(pass, entity));
@@ -254,9 +259,118 @@ bool AtlasContents::Render(const ContentContext& renderer,
254259
cmd, texture_,
255260
renderer.GetContext()->GetSamplerLibrary()->GetSampler(
256261
sampler_descriptor_));
257-
pass.AddCommand(std::move(cmd));
262+
return pass.AddCommand(std::move(cmd));
263+
}
264+
265+
bool AtlasContents::RenderOnlyColor(const ContentContext& renderer,
266+
const Entity& entity,
267+
RenderPass& pass) const {
268+
using VS = GeometryColorPipeline::VertexShader;
269+
;
270+
271+
const auto texture_size = texture_->GetSize();
272+
if (texture_size.IsEmpty()) {
273+
return true;
274+
}
275+
276+
VertexBufferBuilder<VS::PerVertexData> vertex_builder;
277+
vertex_builder.Reserve(texture_coords_.size() * 6);
278+
constexpr size_t indices[6] = {0, 1, 2, 1, 2, 3};
279+
for (size_t i = 0; i < texture_coords_.size(); i++) {
280+
auto sample_rect = texture_coords_[i];
281+
auto matrix = transforms_[i];
282+
auto transformed_points =
283+
Rect::MakeSize(sample_rect.size).GetTransformedPoints(matrix);
284+
285+
for (size_t j = 0; j < 6; j++) {
286+
VS::PerVertexData data;
287+
data.position = transformed_points[indices[j]];
288+
data.color = colors_[i].Premultiply();
289+
vertex_builder.AppendVertex(data);
290+
}
291+
}
292+
293+
if (!vertex_builder.HasVertices()) {
294+
return true;
295+
}
296+
297+
Command cmd;
298+
cmd.label = "DrawAtlas";
299+
300+
auto& host_buffer = pass.GetTransientsBuffer();
301+
302+
VS::VertInfo vert_info;
303+
vert_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
304+
entity.GetTransformation();
305+
306+
cmd.pipeline =
307+
renderer.GetGeometryColorPipeline(OptionsFromPassAndEntity(pass, entity));
308+
cmd.stencil_reference = entity.GetStencilDepth();
309+
cmd.BindVertices(vertex_builder.CreateVertexBuffer(host_buffer));
310+
VS::BindVertInfo(cmd, host_buffer.EmplaceUniform(vert_info));
311+
return pass.AddCommand(std::move(cmd));
312+
}
313+
314+
bool AtlasContents::RenderNoColor(const ContentContext& renderer,
315+
const Entity& entity,
316+
RenderPass& pass) const {
317+
using VS = TextureFillVertexShader;
318+
using FS = TextureFillFragmentShader;
258319

259-
return true;
320+
const auto texture_size = texture_->GetSize();
321+
if (texture_size.IsEmpty()) {
322+
return true;
323+
}
324+
325+
VertexBufferBuilder<VS::PerVertexData> vertex_builder;
326+
vertex_builder.Reserve(texture_coords_.size() * 6);
327+
constexpr size_t indices[6] = {0, 1, 2, 1, 2, 3};
328+
constexpr Scalar width[6] = {0, 1, 0, 1, 0, 1};
329+
constexpr Scalar height[6] = {0, 0, 1, 0, 1, 1};
330+
for (size_t i = 0; i < texture_coords_.size(); i++) {
331+
auto sample_rect = texture_coords_[i];
332+
auto matrix = transforms_[i];
333+
auto transformed_points =
334+
Rect::MakeSize(sample_rect.size).GetTransformedPoints(matrix);
335+
336+
for (size_t j = 0; j < 6; j++) {
337+
VS::PerVertexData data;
338+
data.position = transformed_points[indices[j]];
339+
data.texture_coords =
340+
(sample_rect.origin + Point(sample_rect.size.width * width[j],
341+
sample_rect.size.height * height[j])) /
342+
texture_size;
343+
vertex_builder.AppendVertex(data);
344+
}
345+
}
346+
347+
if (!vertex_builder.HasVertices()) {
348+
return true;
349+
}
350+
351+
Command cmd;
352+
cmd.label = "DrawAtlas";
353+
354+
auto& host_buffer = pass.GetTransientsBuffer();
355+
356+
VS::VertInfo vert_info;
357+
vert_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
358+
entity.GetTransformation();
359+
360+
FS::FragInfo frag_info;
361+
frag_info.texture_sampler_y_coord_scale = texture_->GetYCoordScale();
362+
frag_info.alpha = alpha_;
363+
364+
cmd.pipeline =
365+
renderer.GetTexturePipeline(OptionsFromPassAndEntity(pass, entity));
366+
cmd.stencil_reference = entity.GetStencilDepth();
367+
cmd.BindVertices(vertex_builder.CreateVertexBuffer(host_buffer));
368+
VS::BindVertInfo(cmd, host_buffer.EmplaceUniform(vert_info));
369+
FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_info));
370+
FS::BindTextureSampler(cmd, texture_,
371+
renderer.GetContext()->GetSamplerLibrary()->GetSampler(
372+
sampler_descriptor_));
373+
return pass.AddCommand(std::move(cmd));
260374
}
261375

262376
} // namespace impeller

impeller/entity/contents/atlas_contents.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ class AtlasContents final : public Contents {
5050
RenderPass& pass) const override;
5151

5252
private:
53+
bool RenderNoColor(const ContentContext& renderer,
54+
const Entity& entity,
55+
RenderPass& pass) const;
56+
57+
bool RenderOnlyColor(const ContentContext& renderer,
58+
const Entity& entity,
59+
RenderPass& pass) const;
60+
5361
std::shared_ptr<Texture> texture_;
5462
std::vector<Rect> texture_coords_;
5563
std::vector<Color> colors_;

impeller/entity/contents/content_context.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,6 @@ ContentContext::ContentContext(std::shared_ptr<Context> context)
225225
CreateDefaultPipeline<GeometryColorPipeline>(*context_);
226226
geometry_position_pipelines_[{}] =
227227
CreateDefaultPipeline<GeometryPositionPipeline>(*context_);
228-
atlas_pipelines_[{}] = CreateDefaultPipeline<AtlasPipeline>(*context_);
229228
yuv_to_rgb_filter_pipelines_[{}] =
230229
CreateDefaultPipeline<YUVToRGBFilterPipeline>(*context_);
231230

impeller/entity/contents/content_context.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@
5656
#include "impeller/entity/atlas_blend_src_over.frag.h"
5757
#include "impeller/entity/atlas_blend_xor.frag.h"
5858

59-
#include "impeller/entity/atlas_fill.frag.h"
60-
#include "impeller/entity/atlas_fill.vert.h"
6159
#include "impeller/entity/blend.frag.h"
6260
#include "impeller/entity/blend.vert.h"
6361
#include "impeller/entity/border_mask_blur.frag.h"
@@ -195,8 +193,6 @@ using GlyphAtlasPipeline =
195193
RenderPipelineT<GlyphAtlasVertexShader, GlyphAtlasFragmentShader>;
196194
using GlyphAtlasSdfPipeline =
197195
RenderPipelineT<GlyphAtlasSdfVertexShader, GlyphAtlasSdfFragmentShader>;
198-
using AtlasPipeline =
199-
RenderPipelineT<AtlasBlendVertexShader, AtlasFillFragmentShader>;
200196
// Instead of requiring new shaders for clips, the solid fill stages are used
201197
// to redirect writing to the stencil instead of color attachments.
202198
using ClipPipeline =
@@ -433,11 +429,6 @@ class ContentContext {
433429
return GetPipeline(geometry_position_pipelines_, opts);
434430
}
435431

436-
std::shared_ptr<Pipeline<PipelineDescriptor>> GetAtlasPipeline(
437-
ContentContextOptions opts) const {
438-
return GetPipeline(atlas_pipelines_, opts);
439-
}
440-
441432
std::shared_ptr<Pipeline<PipelineDescriptor>> GetYUVToRGBFilterPipeline(
442433
ContentContextOptions opts) const {
443434
return GetPipeline(yuv_to_rgb_filter_pipelines_, opts);
@@ -694,7 +685,6 @@ class ContentContext {
694685
mutable Variants<ClipPipeline> clip_pipelines_;
695686
mutable Variants<GlyphAtlasPipeline> glyph_atlas_pipelines_;
696687
mutable Variants<GlyphAtlasSdfPipeline> glyph_atlas_sdf_pipelines_;
697-
mutable Variants<AtlasPipeline> atlas_pipelines_;
698688
mutable Variants<GeometryPositionPipeline> geometry_position_pipelines_;
699689
mutable Variants<GeometryColorPipeline> geometry_color_pipelines_;
700690
mutable Variants<YUVToRGBFilterPipeline> yuv_to_rgb_filter_pipelines_;

impeller/entity/shaders/atlas_fill.frag

Lines changed: 0 additions & 25 deletions
This file was deleted.

impeller/entity/shaders/atlas_fill.vert

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)