Skip to content

Commit

Permalink
Migrate SweepGradientContents
Browse files Browse the repository at this point in the history
  • Loading branch information
bdero committed Feb 13, 2024
1 parent cc002a7 commit fa205f4
Showing 1 changed file with 66 additions and 96 deletions.
162 changes: 66 additions & 96 deletions impeller/entity/contents/sweep_gradient_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,57 +76,42 @@ bool SweepGradientContents::RenderSSBO(const ContentContext& renderer,
using VS = SweepGradientSSBOFillPipeline::VertexShader;
using FS = SweepGradientSSBOFillPipeline::FragmentShader;

FS::FragInfo frag_info;
frag_info.center = center_;
frag_info.bias = bias_;
frag_info.scale = scale_;
frag_info.tile_mode = static_cast<Scalar>(tile_mode_);
frag_info.decal_border_color = decal_border_color_;
frag_info.alpha = GetOpacityFactor();

auto& host_buffer = renderer.GetTransientsBuffer();
auto colors = CreateGradientColors(colors_, stops_);

frag_info.colors_length = colors.size();
auto color_buffer =
host_buffer.Emplace(colors.data(), colors.size() * sizeof(StopData),
DefaultUniformAlignment());

VS::FrameInfo frame_info;
frame_info.depth = entity.GetShaderClipDepth();
frame_info.mvp = pass.GetOrthographicTransform() * entity.GetTransform();
frame_info.matrix = GetInverseEffectTransform();

auto geometry_result =
GetGeometry()->GetPositionBuffer(renderer, entity, pass);

auto options = OptionsFromPassAndEntity(pass, entity);
if (geometry_result.prevent_overdraw) {
options.stencil_mode =
ContentContextOptions::StencilMode::kLegacyClipIncrement;
}
options.primitive_type = geometry_result.type;

pass.SetCommandLabel("SweepGradientSSBOFill");
pass.SetStencilReference(entity.GetClipDepth());
pass.SetPipeline(renderer.GetSweepGradientSSBOFillPipeline(options));
pass.SetVertexBuffer(std::move(geometry_result.vertex_buffer));
FS::BindFragInfo(pass,
renderer.GetTransientsBuffer().EmplaceUniform(frag_info));
FS::BindColorData(pass, color_buffer);
VS::BindFrameInfo(pass,
renderer.GetTransientsBuffer().EmplaceUniform(frame_info));

if (!pass.Draw().ok()) {
return false;
}

if (geometry_result.prevent_overdraw) {
auto restore = ClipRestoreContents();
restore.SetRestoreCoverage(GetCoverage(entity));
return restore.Render(renderer, entity, pass);
}
return true;
PipelineBuilderCallback pipeline_callback =
[&renderer](ContentContextOptions options) {
return renderer.GetSweepGradientSSBOFillPipeline(options);
};
return ColorSourceContents::DrawPositions<VS>(
renderer, entity, pass, pipeline_callback, frame_info,
[this, &renderer](RenderPass& pass) {
FS::FragInfo frag_info;
frag_info.center = center_;
frag_info.bias = bias_;
frag_info.scale = scale_;
frag_info.tile_mode = static_cast<Scalar>(tile_mode_);
frag_info.decal_border_color = decal_border_color_;
frag_info.alpha = GetOpacityFactor();

auto& host_buffer = renderer.GetTransientsBuffer();
auto colors = CreateGradientColors(colors_, stops_);

frag_info.colors_length = colors.size();
auto color_buffer =
host_buffer.Emplace(colors.data(), colors.size() * sizeof(StopData),
DefaultUniformAlignment());

pass.SetCommandLabel("SweepGradientSSBOFill");

FS::BindFragInfo(
pass, renderer.GetTransientsBuffer().EmplaceUniform(frag_info));
FS::BindColorData(pass, color_buffer);

return true;
});
}

bool SweepGradientContents::RenderTexture(const ContentContext& renderer,
Expand All @@ -142,59 +127,44 @@ bool SweepGradientContents::RenderTexture(const ContentContext& renderer,
return false;
}

FS::FragInfo frag_info;
frag_info.center = center_;
frag_info.bias = bias_;
frag_info.scale = scale_;
frag_info.texture_sampler_y_coord_scale = gradient_texture->GetYCoordScale();
frag_info.tile_mode = static_cast<Scalar>(tile_mode_);
frag_info.decal_border_color = decal_border_color_;
frag_info.alpha = GetOpacityFactor();
frag_info.half_texel = Vector2(0.5 / gradient_texture->GetSize().width,
0.5 / gradient_texture->GetSize().height);

auto geometry_result =
GetGeometry()->GetPositionBuffer(renderer, entity, pass);

VS::FrameInfo frame_info;
frame_info.depth = entity.GetShaderClipDepth();
frame_info.mvp = geometry_result.transform;
frame_info.matrix = GetInverseEffectTransform();

auto options = OptionsFromPassAndEntity(pass, entity);
if (geometry_result.prevent_overdraw) {
options.stencil_mode =
ContentContextOptions::StencilMode::kLegacyClipIncrement;
}
options.primitive_type = geometry_result.type;

SamplerDescriptor sampler_desc;
sampler_desc.min_filter = MinMagFilter::kLinear;
sampler_desc.mag_filter = MinMagFilter::kLinear;

pass.SetCommandLabel("SweepGradientFill");
pass.SetStencilReference(entity.GetClipDepth());
pass.SetPipeline(renderer.GetSweepGradientFillPipeline(options));
pass.SetVertexBuffer(std::move(geometry_result.vertex_buffer));

FS::BindFragInfo(pass,
renderer.GetTransientsBuffer().EmplaceUniform(frag_info));
VS::BindFrameInfo(pass,
renderer.GetTransientsBuffer().EmplaceUniform(frame_info));
FS::BindTextureSampler(
pass, gradient_texture,
renderer.GetContext()->GetSamplerLibrary()->GetSampler(sampler_desc));

if (!pass.Draw().ok()) {
return false;
}

if (geometry_result.prevent_overdraw) {
auto restore = ClipRestoreContents();
restore.SetRestoreCoverage(GetCoverage(entity));
return restore.Render(renderer, entity, pass);
}
return true;
PipelineBuilderCallback pipeline_callback =
[&renderer](ContentContextOptions options) {
return renderer.GetSweepGradientFillPipeline(options);
};
return ColorSourceContents::DrawPositions<VS>(
renderer, entity, pass, pipeline_callback, frame_info,
[this, &renderer, &gradient_texture](RenderPass& pass) {
FS::FragInfo frag_info;
frag_info.center = center_;
frag_info.bias = bias_;
frag_info.scale = scale_;
frag_info.texture_sampler_y_coord_scale =
gradient_texture->GetYCoordScale();
frag_info.tile_mode = static_cast<Scalar>(tile_mode_);
frag_info.decal_border_color = decal_border_color_;
frag_info.alpha = GetOpacityFactor();
frag_info.half_texel =
Vector2(0.5 / gradient_texture->GetSize().width,
0.5 / gradient_texture->GetSize().height);

SamplerDescriptor sampler_desc;
sampler_desc.min_filter = MinMagFilter::kLinear;
sampler_desc.mag_filter = MinMagFilter::kLinear;

pass.SetCommandLabel("SweepGradientFill");

FS::BindFragInfo(
pass, renderer.GetTransientsBuffer().EmplaceUniform(frag_info));
FS::BindTextureSampler(
pass, gradient_texture,
renderer.GetContext()->GetSamplerLibrary()->GetSampler(
sampler_desc));

return true;
});
}

bool SweepGradientContents::ApplyColorFilter(
Expand Down

0 comments on commit fa205f4

Please sign in to comment.