Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Impeller] Gaussian blur: Remove the current blur style implementation. #45520

Merged
merged 1 commit into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -1329,8 +1329,6 @@ ORIGIN: ../../../flutter/impeller/entity/shaders/debug/checkerboard.frag + ../..
ORIGIN: ../../../flutter/impeller/entity/shaders/debug/checkerboard.vert + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/gaussian_blur/gaussian_blur.glsl + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/gaussian_blur/gaussian_blur.vert + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/gaussian_blur/gaussian_blur_alpha_decal.frag + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/gaussian_blur/gaussian_blur_alpha_nodecal.frag + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/gaussian_blur/gaussian_blur_noalpha_decal.frag + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/gaussian_blur/gaussian_blur_noalpha_nodecal.frag + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/geometry/points.comp + ../../../flutter/LICENSE
Expand Down Expand Up @@ -4075,8 +4073,6 @@ FILE: ../../../flutter/impeller/entity/shaders/debug/checkerboard.frag
FILE: ../../../flutter/impeller/entity/shaders/debug/checkerboard.vert
FILE: ../../../flutter/impeller/entity/shaders/gaussian_blur/gaussian_blur.glsl
FILE: ../../../flutter/impeller/entity/shaders/gaussian_blur/gaussian_blur.vert
FILE: ../../../flutter/impeller/entity/shaders/gaussian_blur/gaussian_blur_alpha_decal.frag
FILE: ../../../flutter/impeller/entity/shaders/gaussian_blur/gaussian_blur_alpha_nodecal.frag
FILE: ../../../flutter/impeller/entity/shaders/gaussian_blur/gaussian_blur_noalpha_decal.frag
FILE: ../../../flutter/impeller/entity/shaders/gaussian_blur/gaussian_blur_noalpha_nodecal.frag
FILE: ../../../flutter/impeller/entity/shaders/geometry/points.comp
Expand Down
2 changes: 0 additions & 2 deletions impeller/entity/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ impeller_shaders("entity_shaders") {
"shaders/color_matrix_color_filter.vert",
"shaders/conical_gradient_fill.frag",
"shaders/gaussian_blur/gaussian_blur.vert",
"shaders/gaussian_blur/gaussian_blur_alpha_decal.frag",
"shaders/gaussian_blur/gaussian_blur_alpha_nodecal.frag",
"shaders/gaussian_blur/gaussian_blur_noalpha_decal.frag",
"shaders/gaussian_blur/gaussian_blur_noalpha_nodecal.frag",
"shaders/glyph_atlas.frag",
Expand Down
4 changes: 0 additions & 4 deletions impeller/entity/contents/content_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,6 @@ ContentContext::ContentContext(
CreateDefaultPipeline<PositionUVPipeline>(*context_);
tiled_texture_pipelines_[default_options_] =
CreateDefaultPipeline<TiledTexturePipeline>(*context_);
gaussian_blur_alpha_decal_pipelines_[default_options_] =
CreateDefaultPipeline<GaussianBlurAlphaDecalPipeline>(*context_);
gaussian_blur_alpha_nodecal_pipelines_[default_options_] =
CreateDefaultPipeline<GaussianBlurAlphaPipeline>(*context_);
gaussian_blur_noalpha_decal_pipelines_[default_options_] =
CreateDefaultPipeline<GaussianBlurDecalPipeline>(*context_);
gaussian_blur_noalpha_nodecal_pipelines_[default_options_] =
Expand Down
22 changes: 0 additions & 22 deletions impeller/entity/contents/content_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@
#include "impeller/entity/yuv_to_rgb_filter.vert.h"

#include "impeller/entity/gaussian_blur.vert.h"
#include "impeller/entity/gaussian_blur_alpha_decal.frag.h"
#include "impeller/entity/gaussian_blur_alpha_nodecal.frag.h"
#include "impeller/entity/gaussian_blur_noalpha_decal.frag.h"
#include "impeller/entity/gaussian_blur_noalpha_nodecal.frag.h"

Expand Down Expand Up @@ -158,12 +156,6 @@ using PositionUVPipeline =
RenderPipelineT<TextureFillVertexShader, TiledTextureFillFragmentShader>;
using TiledTexturePipeline =
RenderPipelineT<TextureFillVertexShader, TiledTextureFillFragmentShader>;
using GaussianBlurAlphaDecalPipeline =
RenderPipelineT<GaussianBlurVertexShader,
GaussianBlurAlphaDecalFragmentShader>;
using GaussianBlurAlphaPipeline =
RenderPipelineT<GaussianBlurVertexShader,
GaussianBlurAlphaNodecalFragmentShader>;
using GaussianBlurDecalPipeline =
RenderPipelineT<GaussianBlurVertexShader,
GaussianBlurNoalphaDecalFragmentShader>;
Expand Down Expand Up @@ -453,16 +445,6 @@ class ContentContext {
return GetPipeline(tiled_texture_pipelines_, opts);
}

std::shared_ptr<Pipeline<PipelineDescriptor>>
GetGaussianBlurAlphaDecalPipeline(ContentContextOptions opts) const {
return GetPipeline(gaussian_blur_alpha_decal_pipelines_, opts);
}

std::shared_ptr<Pipeline<PipelineDescriptor>> GetGaussianBlurAlphaPipeline(
ContentContextOptions opts) const {
return GetPipeline(gaussian_blur_alpha_nodecal_pipelines_, opts);
}

std::shared_ptr<Pipeline<PipelineDescriptor>> GetGaussianBlurDecalPipeline(
ContentContextOptions opts) const {
return GetPipeline(gaussian_blur_noalpha_decal_pipelines_, opts);
Expand Down Expand Up @@ -772,10 +754,6 @@ class ContentContext {
#endif // IMPELLER_ENABLE_OPENGLES
mutable Variants<PositionUVPipeline> position_uv_pipelines_;
mutable Variants<TiledTexturePipeline> tiled_texture_pipelines_;
mutable Variants<GaussianBlurAlphaDecalPipeline>
gaussian_blur_alpha_decal_pipelines_;
mutable Variants<GaussianBlurAlphaPipeline>
gaussian_blur_alpha_nodecal_pipelines_;
mutable Variants<GaussianBlurDecalPipeline>
gaussian_blur_noalpha_decal_pipelines_;
mutable Variants<GaussianBlurPipeline>
Expand Down
8 changes: 4 additions & 4 deletions impeller/entity/contents/filters/filter_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ std::shared_ptr<FilterContents> FilterContents::MakeDirectionalGaussianBlur(
Vector2 direction,
BlurStyle blur_style,
Entity::TileMode tile_mode,
FilterInput::Ref source_override,
bool is_second_pass,
Sigma secondary_sigma,
const Matrix& effect_transform) {
auto blur = std::make_shared<DirectionalGaussianBlurFilterContents>();
Expand All @@ -45,7 +45,7 @@ std::shared_ptr<FilterContents> FilterContents::MakeDirectionalGaussianBlur(
blur->SetDirection(direction);
blur->SetBlurStyle(blur_style);
blur->SetTileMode(tile_mode);
blur->SetSourceOverride(std::move(source_override));
blur->SetIsSecondPass(is_second_pass);
blur->SetSecondarySigma(secondary_sigma);
blur->SetEffectTransform(effect_transform);
return blur;
Expand All @@ -60,10 +60,10 @@ std::shared_ptr<FilterContents> FilterContents::MakeGaussianBlur(
const Matrix& effect_transform) {
auto x_blur = MakeDirectionalGaussianBlur(input, sigma_x, Point(1, 0),
BlurStyle::kNormal, tile_mode,
nullptr, {}, effect_transform);
false, {}, effect_transform);
auto y_blur = MakeDirectionalGaussianBlur(FilterInput::Make(x_blur), sigma_y,
Point(0, 1), blur_style, tile_mode,
input, sigma_x, effect_transform);
true, sigma_x, effect_transform);
return y_blur;
}

Expand Down
2 changes: 1 addition & 1 deletion impeller/entity/contents/filters/filter_contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class FilterContents : public Contents {
Vector2 direction,
BlurStyle blur_style = BlurStyle::kNormal,
Entity::TileMode tile_mode = Entity::TileMode::kDecal,
FilterInput::Ref alpha_mask = nullptr,
bool is_second_pass = false,
Sigma secondary_sigma = {},
const Matrix& effect_transform = Matrix());

Expand Down
100 changes: 17 additions & 83 deletions impeller/entity/contents/filters/gaussian_blur_filter_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,39 +46,16 @@ void DirectionalGaussianBlurFilterContents::SetDirection(Vector2 direction) {

void DirectionalGaussianBlurFilterContents::SetBlurStyle(BlurStyle blur_style) {
blur_style_ = blur_style;

switch (blur_style) {
case FilterContents::BlurStyle::kNormal:
src_color_factor_ = false;
inner_blur_factor_ = true;
outer_blur_factor_ = true;
break;
case FilterContents::BlurStyle::kSolid:
src_color_factor_ = true;
inner_blur_factor_ = false;
outer_blur_factor_ = true;
break;
case FilterContents::BlurStyle::kOuter:
src_color_factor_ = false;
inner_blur_factor_ = false;
outer_blur_factor_ = true;
break;
case FilterContents::BlurStyle::kInner:
src_color_factor_ = false;
inner_blur_factor_ = true;
outer_blur_factor_ = false;
break;
}
}

void DirectionalGaussianBlurFilterContents::SetTileMode(
Entity::TileMode tile_mode) {
tile_mode_ = tile_mode;
}

void DirectionalGaussianBlurFilterContents::SetSourceOverride(
FilterInput::Ref source_override) {
source_override_ = std::move(source_override);
void DirectionalGaussianBlurFilterContents::SetIsSecondPass(
bool is_second_pass) {
is_second_pass_ = is_second_pass;
}

std::optional<Entity> DirectionalGaussianBlurFilterContents::RenderFilter(
Expand All @@ -88,10 +65,8 @@ std::optional<Entity> DirectionalGaussianBlurFilterContents::RenderFilter(
const Matrix& effect_transform,
const Rect& coverage,
const std::optional<Rect>& coverage_hint) const {
using VS = GaussianBlurAlphaDecalPipeline::VertexShader;
using FS = GaussianBlurAlphaDecalPipeline::FragmentShader;

bool is_first_pass = !source_override_;
using VS = GaussianBlurPipeline::VertexShader;
using FS = GaussianBlurPipeline::FragmentShader;

//----------------------------------------------------------------------------
/// Handle inputs.
Expand All @@ -118,9 +93,9 @@ std::optional<Entity> DirectionalGaussianBlurFilterContents::RenderFilter(
Size(transformed_blur_radius_length, transformed_blur_radius_length)
.Abs();
expanded_coverage_hint =
is_first_pass ? Rect(coverage_hint.value().origin - r,
Size(coverage_hint.value().size + r * 2))
: coverage_hint;
is_second_pass_ ? coverage_hint
: Rect(coverage_hint.value().origin - r,
Size(coverage_hint.value().size + r * 2));
}
auto input_snapshot = inputs[0]->GetSnapshot("GaussianBlur", renderer, entity,
expanded_coverage_hint);
Expand Down Expand Up @@ -160,15 +135,6 @@ std::optional<Entity> DirectionalGaussianBlurFilterContents::RenderFilter(
pass_texture_rect.origin.x -= transformed_blur_radius_length;
pass_texture_rect.size.width += transformed_blur_radius_length * 2;

// Source override snapshot.

auto source = source_override_ ? source_override_ : inputs[0];
auto source_snapshot = source->GetSnapshot("GaussianBlur(Override)", renderer,
entity, GetCoverageHint());
if (!source_snapshot.has_value()) {
return std::nullopt;
}

// UV mapping.

auto pass_uv_project = [&texture_rotate,
Expand All @@ -180,8 +146,6 @@ std::optional<Entity> DirectionalGaussianBlurFilterContents::RenderFilter(

auto input_uvs = pass_uv_project(input_snapshot.value());

auto source_uvs = pass_uv_project(source_snapshot.value());

//----------------------------------------------------------------------------
/// Render to texture.
///
Expand All @@ -193,21 +157,19 @@ std::optional<Entity> DirectionalGaussianBlurFilterContents::RenderFilter(

VertexBufferBuilder<VS::PerVertexData> vtx_builder;
vtx_builder.AddVertices({
{Point(0, 0), input_uvs[0], source_uvs[0]},
{Point(1, 0), input_uvs[1], source_uvs[1]},
{Point(1, 1), input_uvs[3], source_uvs[3]},
{Point(0, 0), input_uvs[0], source_uvs[0]},
{Point(1, 1), input_uvs[3], source_uvs[3]},
{Point(0, 1), input_uvs[2], source_uvs[2]},
{Point(0, 0), input_uvs[0]},
{Point(1, 0), input_uvs[1]},
{Point(1, 1), input_uvs[3]},
{Point(0, 0), input_uvs[0]},
{Point(1, 1), input_uvs[3]},
{Point(0, 1), input_uvs[2]},
});
auto vtx_buffer = vtx_builder.CreateVertexBuffer(host_buffer);

VS::FrameInfo frame_info;
frame_info.mvp = Matrix::MakeOrthographic(ISize(1, 1));
frame_info.texture_sampler_y_coord_scale =
input_snapshot->texture->GetYCoordScale();
frame_info.alpha_mask_sampler_y_coord_scale =
source_snapshot->texture->GetYCoordScale();

FS::BlurInfo frag_info;
auto r = Radius{transformed_blur_radius_length};
Expand All @@ -227,50 +189,35 @@ std::optional<Entity> DirectionalGaussianBlurFilterContents::RenderFilter(
auto options = OptionsFromPass(pass);
options.blend_mode = BlendMode::kSource;
auto input_descriptor = input_snapshot->sampler_descriptor;
auto source_descriptor = source_snapshot->sampler_descriptor;
switch (tile_mode_) {
case Entity::TileMode::kDecal:
if (renderer.GetDeviceCapabilities()
.SupportsDecalSamplerAddressMode()) {
input_descriptor.width_address_mode = SamplerAddressMode::kDecal;
input_descriptor.height_address_mode = SamplerAddressMode::kDecal;
source_descriptor.width_address_mode = SamplerAddressMode::kDecal;
source_descriptor.height_address_mode = SamplerAddressMode::kDecal;
}
break;
case Entity::TileMode::kClamp:
input_descriptor.width_address_mode = SamplerAddressMode::kClampToEdge;
input_descriptor.height_address_mode = SamplerAddressMode::kClampToEdge;
source_descriptor.width_address_mode = SamplerAddressMode::kClampToEdge;
source_descriptor.height_address_mode =
SamplerAddressMode::kClampToEdge;
break;
case Entity::TileMode::kMirror:
input_descriptor.width_address_mode = SamplerAddressMode::kMirror;
input_descriptor.height_address_mode = SamplerAddressMode::kMirror;
source_descriptor.width_address_mode = SamplerAddressMode::kMirror;
source_descriptor.height_address_mode = SamplerAddressMode::kMirror;
break;
case Entity::TileMode::kRepeat:
input_descriptor.width_address_mode = SamplerAddressMode::kRepeat;
input_descriptor.height_address_mode = SamplerAddressMode::kRepeat;
source_descriptor.width_address_mode = SamplerAddressMode::kRepeat;
source_descriptor.height_address_mode = SamplerAddressMode::kRepeat;
break;
}
input_descriptor.mag_filter = MinMagFilter::kLinear;
input_descriptor.min_filter = MinMagFilter::kLinear;

bool has_alpha_mask = blur_style_ != BlurStyle::kNormal;
bool has_decal_specialization =
tile_mode_ == Entity::TileMode::kDecal &&
!renderer.GetDeviceCapabilities().SupportsDecalSamplerAddressMode();

if (has_alpha_mask && has_decal_specialization) {
cmd.pipeline = renderer.GetGaussianBlurAlphaDecalPipeline(options);
} else if (has_alpha_mask) {
cmd.pipeline = renderer.GetGaussianBlurAlphaPipeline(options);
} else if (has_decal_specialization) {
if (has_decal_specialization) {
cmd.pipeline = renderer.GetGaussianBlurDecalPipeline(options);
} else {
cmd.pipeline = renderer.GetGaussianBlurPipeline(options);
Expand All @@ -283,19 +230,6 @@ std::optional<Entity> DirectionalGaussianBlurFilterContents::RenderFilter(
VS::BindFrameInfo(cmd, host_buffer.EmplaceUniform(frame_info));
FS::BindBlurInfo(cmd, host_buffer.EmplaceUniform(frag_info));

if (has_alpha_mask) {
FS::MaskInfo mask_info;
mask_info.src_factor = src_color_factor_;
mask_info.inner_blur_factor = inner_blur_factor_;
mask_info.outer_blur_factor = outer_blur_factor_;

FS::BindAlphaMaskSampler(
cmd, source_snapshot->texture,
renderer.GetContext()->GetSamplerLibrary()->GetSampler(
source_descriptor));
FS::BindMaskInfo(cmd, host_buffer.EmplaceUniform(mask_info));
}

return pass.AddCommand(std::move(cmd));
};

Expand All @@ -310,8 +244,8 @@ std::optional<Entity> DirectionalGaussianBlurFilterContents::RenderFilter(
{
scale.x = scale_curve(transformed_blur_radius_length);

Scalar y_radius = std::abs(pass_transform.GetDirectionScale(
Vector2(0, !is_first_pass ? Radius{secondary_blur_sigma_}.radius : 1)));
Scalar y_radius = std::abs(pass_transform.GetDirectionScale(Vector2(
0, !is_second_pass_ ? 1 : Radius{secondary_blur_sigma_}.radius)));
scale.y = scale_curve(y_radius);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class DirectionalGaussianBlurFilterContents final : public FilterContents {

void SetTileMode(Entity::TileMode tile_mode);

void SetSourceOverride(FilterInput::Ref alpha_mask);
void SetIsSecondPass(bool is_second_pass);

// |FilterContents|
std::optional<Rect> GetFilterCoverage(
Expand All @@ -49,10 +49,7 @@ class DirectionalGaussianBlurFilterContents final : public FilterContents {
Vector2 blur_direction_;
BlurStyle blur_style_ = BlurStyle::kNormal;
Entity::TileMode tile_mode_ = Entity::TileMode::kDecal;
bool src_color_factor_ = false;
bool inner_blur_factor_ = true;
bool outer_blur_factor_ = true;
FilterInput::Ref source_override_;
bool is_second_pass_ = false;

FML_DISALLOW_COPY_AND_ASSIGN(DirectionalGaussianBlurFilterContents);
};
Expand Down
26 changes: 0 additions & 26 deletions impeller/entity/shaders/gaussian_blur/gaussian_blur.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,6 @@ uniform BlurInfo {
}
blur_info;

#if ENABLE_ALPHA_MASK
uniform f16sampler2D alpha_mask_sampler;

uniform MaskInfo {
float16_t src_factor;
float16_t inner_blur_factor;
float16_t outer_blur_factor;
}
mask_info;
#endif

f16vec4 Sample(f16sampler2D tex, vec2 coords) {
#if ENABLE_DECAL_SPECIALIZATION
return IPHalfSampleDecal(tex, coords);
Expand Down Expand Up @@ -76,19 +65,4 @@ void main() {
}

frag_color = total_color / gaussian_integral;

#if ENABLE_ALPHA_MASK
f16vec4 src_color = Sample(alpha_mask_sampler, // sampler
v_src_texture_coords // texture coordinates
);

float16_t blur_factor;
if (src_color.a > 0.0hf) {
blur_factor = mask_info.inner_blur_factor;
} else if (src_color.a == 0.0hf) {
blur_factor = mask_info.outer_blur_factor;
}

frag_color = frag_color * blur_factor + src_color * mask_info.src_factor;
#endif
}
Loading