Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
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
20 changes: 12 additions & 8 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -1246,10 +1246,12 @@ ORIGIN: ../../../flutter/impeller/entity/shaders/color_matrix_color_filter.frag
ORIGIN: ../../../flutter/impeller/entity/shaders/color_matrix_color_filter.vert + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/conical_gradient_fill.frag + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/conical_gradient_ssbo_fill.frag + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/gaussian_blur.frag + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/gaussian_blur.glsl + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/gaussian_blur.vert + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/gaussian_blur_decal.frag + ../../../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/glyph_atlas.frag + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/glyph_atlas.vert + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/glyph_atlas_sdf.frag + ../../../flutter/LICENSE
Expand Down Expand Up @@ -3809,10 +3811,12 @@ FILE: ../../../flutter/impeller/entity/shaders/color_matrix_color_filter.frag
FILE: ../../../flutter/impeller/entity/shaders/color_matrix_color_filter.vert
FILE: ../../../flutter/impeller/entity/shaders/conical_gradient_fill.frag
FILE: ../../../flutter/impeller/entity/shaders/conical_gradient_ssbo_fill.frag
FILE: ../../../flutter/impeller/entity/shaders/gaussian_blur.frag
FILE: ../../../flutter/impeller/entity/shaders/gaussian_blur.glsl
FILE: ../../../flutter/impeller/entity/shaders/gaussian_blur.vert
FILE: ../../../flutter/impeller/entity/shaders/gaussian_blur_decal.frag
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/glyph_atlas.frag
FILE: ../../../flutter/impeller/entity/shaders/glyph_atlas.vert
FILE: ../../../flutter/impeller/entity/shaders/glyph_atlas_sdf.frag
Expand Down
8 changes: 5 additions & 3 deletions impeller/entity/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ impeller_shaders("entity_shaders") {
"shaders/color_matrix_color_filter.frag",
"shaders/color_matrix_color_filter.vert",
"shaders/conical_gradient_fill.frag",
"shaders/gaussian_blur.frag",
"shaders/gaussian_blur_decal.frag",
"shaders/gaussian_blur.vert",
"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",
"shaders/glyph_atlas.vert",
"shaders/glyph_atlas_sdf.frag",
Expand Down
10 changes: 7 additions & 3 deletions impeller/entity/contents/content_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,14 @@ ContentContext::ContentContext(std::shared_ptr<Context> context)
CreateDefaultPipeline<PositionUVPipeline>(*context_);
tiled_texture_pipelines_[{}] =
CreateDefaultPipeline<TiledTexturePipeline>(*context_);
gaussian_blur_pipelines_[{}] =
CreateDefaultPipeline<GaussianBlurPipeline>(*context_);
gaussian_blur_decal_pipelines_[{}] =
gaussian_blur_alpha_decal_pipelines_[{}] =
CreateDefaultPipeline<GaussianBlurAlphaDecalPipeline>(*context_);
gaussian_blur_alpha_nodecal_pipelines_[{}] =
CreateDefaultPipeline<GaussianBlurAlphaPipeline>(*context_);
gaussian_blur_noalpha_decal_pipelines_[{}] =
CreateDefaultPipeline<GaussianBlurDecalPipeline>(*context_);
gaussian_blur_noalpha_nodecal_pipelines_[{}] =
CreateDefaultPipeline<GaussianBlurPipeline>(*context_);
border_mask_blur_pipelines_[{}] =
CreateDefaultPipeline<BorderMaskBlurPipeline>(*context_);
morphology_filter_pipelines_[{}] =
Expand Down
60 changes: 44 additions & 16 deletions impeller/entity/contents/content_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,19 @@
#include "flutter/fml/logging.h"
#include "flutter/fml/macros.h"
#include "impeller/base/validation.h"
#include "impeller/entity/entity.h"
#include "impeller/renderer/capabilities.h"
#include "impeller/renderer/formats.h"
#include "impeller/renderer/pipeline.h"
#include "impeller/scene/scene_context.h"

#include "impeller/entity/blend.frag.h"
#include "impeller/entity/blend.vert.h"
#include "impeller/entity/border_mask_blur.frag.h"
#include "impeller/entity/border_mask_blur.vert.h"
#include "impeller/entity/color_matrix_color_filter.frag.h"
#include "impeller/entity/color_matrix_color_filter.vert.h"
#include "impeller/entity/conical_gradient_fill.frag.h"
#include "impeller/entity/entity.h"
#include "impeller/entity/gaussian_blur.frag.h"
#include "impeller/entity/gaussian_blur.vert.h"
#include "impeller/entity/gaussian_blur_decal.frag.h"
#include "impeller/entity/glyph_atlas.frag.h"
#include "impeller/entity/glyph_atlas.vert.h"
#include "impeller/entity/glyph_atlas_sdf.frag.h"
Expand All @@ -48,10 +50,12 @@
#include "impeller/entity/vertices.frag.h"
#include "impeller/entity/yuv_to_rgb_filter.frag.h"
#include "impeller/entity/yuv_to_rgb_filter.vert.h"
#include "impeller/renderer/capabilities.h"
#include "impeller/renderer/formats.h"
#include "impeller/renderer/pipeline.h"
#include "impeller/scene/scene_context.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"

#include "impeller/entity/position_color.vert.h"

Expand Down Expand Up @@ -132,10 +136,18 @@ using PositionUVPipeline =
RenderPipelineT<TextureFillVertexShader, TiledTextureFillFragmentShader>;
using TiledTexturePipeline = RenderPipelineT<TiledTextureFillVertexShader,
TiledTextureFillFragmentShader>;
using GaussianBlurPipeline =
RenderPipelineT<GaussianBlurVertexShader, GaussianBlurFragmentShader>;
using GaussianBlurAlphaDecalPipeline =
RenderPipelineT<GaussianBlurVertexShader,
GaussianBlurAlphaDecalFragmentShader>;
using GaussianBlurAlphaPipeline =
RenderPipelineT<GaussianBlurVertexShader,
GaussianBlurAlphaNodecalFragmentShader>;
using GaussianBlurDecalPipeline =
RenderPipelineT<GaussianBlurVertexShader, GaussianBlurDecalFragmentShader>;
RenderPipelineT<GaussianBlurVertexShader,
GaussianBlurNoalphaDecalFragmentShader>;
using GaussianBlurPipeline =
RenderPipelineT<GaussianBlurVertexShader,
GaussianBlurNoalphaNodecalFragmentShader>;
using BorderMaskBlurPipeline =
RenderPipelineT<BorderMaskBlurVertexShader, BorderMaskBlurFragmentShader>;
using MorphologyFilterPipeline =
Expand Down Expand Up @@ -388,14 +400,24 @@ class ContentContext {
return GetPipeline(tiled_texture_pipelines_, opts);
}

std::shared_ptr<Pipeline<PipelineDescriptor>> GetGaussianBlurPipeline(
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_pipelines_, opts);
return GetPipeline(gaussian_blur_alpha_nodecal_pipelines_, opts);
}

std::shared_ptr<Pipeline<PipelineDescriptor>> GetGaussianBlurDecalPipeline(
ContentContextOptions opts) const {
return GetPipeline(gaussian_blur_decal_pipelines_, opts);
return GetPipeline(gaussian_blur_noalpha_decal_pipelines_, opts);
}

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

std::shared_ptr<Pipeline<PipelineDescriptor>> GetBorderMaskBlurPipeline(
Expand Down Expand Up @@ -665,8 +687,14 @@ class ContentContext {
mutable Variants<TexturePipeline> texture_pipelines_;
mutable Variants<PositionUVPipeline> position_uv_pipelines_;
mutable Variants<TiledTexturePipeline> tiled_texture_pipelines_;
mutable Variants<GaussianBlurPipeline> gaussian_blur_pipelines_;
mutable Variants<GaussianBlurDecalPipeline> gaussian_blur_decal_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>
gaussian_blur_noalpha_nodecal_pipelines_;
mutable Variants<BorderMaskBlurPipeline> border_mask_blur_pipelines_;
mutable Variants<MorphologyFilterPipeline> morphology_filter_pipelines_;
mutable Variants<ColorMatrixColorFilterPipeline>
Expand Down
45 changes: 30 additions & 15 deletions impeller/entity/contents/filters/gaussian_blur_filter_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ std::optional<Entity> DirectionalGaussianBlurFilterContents::RenderFilter(
const Entity& entity,
const Matrix& effect_transform,
const Rect& coverage) const {
using VS = GaussianBlurPipeline::VertexShader;
using FS = GaussianBlurPipeline::FragmentShader;
using VS = GaussianBlurAlphaDecalPipeline::VertexShader;
using FS = GaussianBlurAlphaDecalPipeline::FragmentShader;

//----------------------------------------------------------------------------
/// Handle inputs.
Expand Down Expand Up @@ -192,7 +192,7 @@ std::optional<Entity> DirectionalGaussianBlurFilterContents::RenderFilter(
frame_info.alpha_mask_sampler_y_coord_scale =
source_snapshot->texture->GetYCoordScale();

FS::FragInfo frag_info;
FS::BlurInfo frag_info;
auto r = Radius{transformed_blur_radius_length};
frag_info.blur_sigma = Sigma{r}.sigma;
frag_info.blur_radius = r.radius;
Expand All @@ -201,9 +201,6 @@ std::optional<Entity> DirectionalGaussianBlurFilterContents::RenderFilter(
frag_info.blur_direction =
pass_transform.Invert().TransformDirection(Vector2(1, 0)).Normalize();

frag_info.src_factor = src_color_factor_;
frag_info.inner_blur_factor = inner_blur_factor_;
frag_info.outer_blur_factor = outer_blur_factor_;
frag_info.texture_size = Point(input_snapshot->GetCoverage().value().size);

Command cmd;
Expand All @@ -217,42 +214,60 @@ std::optional<Entity> DirectionalGaussianBlurFilterContents::RenderFilter(
auto source_descriptor = source_snapshot->sampler_descriptor;
switch (tile_mode_) {
case Entity::TileMode::kDecal:
cmd.pipeline = renderer.GetGaussianBlurDecalPipeline(options);
break;
case Entity::TileMode::kClamp:
cmd.pipeline = renderer.GetGaussianBlurPipeline(options);
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:
cmd.pipeline = renderer.GetGaussianBlurPipeline(options);
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:
cmd.pipeline = renderer.GetGaussianBlurPipeline(options);
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;
}

bool has_alpha_mask = blur_style_ != BlurStyle::kNormal;
bool has_decal_specialization = tile_mode_ == Entity::TileMode::kDecal;

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) {
cmd.pipeline = renderer.GetGaussianBlurDecalPipeline(options);
} else {
cmd.pipeline = renderer.GetGaussianBlurPipeline(options);
}

FS::BindTextureSampler(
cmd, input_snapshot->texture,
renderer.GetContext()->GetSamplerLibrary()->GetSampler(
input_descriptor));
FS::BindAlphaMaskSampler(
cmd, source_snapshot->texture,
renderer.GetContext()->GetSamplerLibrary()->GetSampler(
source_descriptor));
VS::BindFrameInfo(cmd, host_buffer.EmplaceUniform(frame_info));
FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_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(cmd);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
#include <impeller/types.glsl>

uniform sampler2D texture_sampler;
uniform sampler2D alpha_mask_sampler;

uniform FragInfo {
uniform BlurInfo {
vec2 texture_size;
vec2 blur_direction;

Expand All @@ -31,12 +30,27 @@ uniform FragInfo {
// radius is used to limit how much of the function is integrated.
float blur_sigma;
float blur_radius;
}
blur_info;

#if ENABLE_ALPHA_MASK
uniform sampler2D alpha_mask_sampler;

uniform MaskInfo {
float src_factor;
float inner_blur_factor;
float outer_blur_factor;
}
frag_info;
mask_info;
#endif

vec4 Sample(sampler2D tex, vec2 coords) {
#if ENABLE_DECAL_SPECIALIZATION
return IPSampleDecal(tex, coords);
#else
return texture(tex, coords);
#endif
}

in vec2 v_texture_coords;
in vec2 v_src_texture_coords;
Expand All @@ -46,10 +60,10 @@ out vec4 frag_color;
void main() {
vec4 total_color = vec4(0);
float gaussian_integral = 0;
vec2 blur_uv_offset = frag_info.blur_direction / frag_info.texture_size;
vec2 blur_uv_offset = blur_info.blur_direction / blur_info.texture_size;

for (float i = -frag_info.blur_radius; i <= frag_info.blur_radius; i++) {
float gaussian = IPGaussian(i, frag_info.blur_sigma);
for (float i = -blur_info.blur_radius; i <= blur_info.blur_radius; i++) {
float gaussian = IPGaussian(i, blur_info.blur_sigma);
gaussian_integral += gaussian;
total_color +=
gaussian *
Expand All @@ -58,13 +72,15 @@ void main() {
);
}

vec4 blur_color = total_color / gaussian_integral;
frag_color = total_color / gaussian_integral;

#if ENABLE_ALPHA_MASK
vec4 src_color = Sample(alpha_mask_sampler, // sampler
v_src_texture_coords // texture coordinates
);
float blur_factor = frag_info.inner_blur_factor * float(src_color.a > 0) +
frag_info.outer_blur_factor * float(src_color.a == 0);
float blur_factor = mask_info.inner_blur_factor * float(src_color.a > 0) +
mask_info.outer_blur_factor * float(src_color.a == 0);

frag_color = blur_color * blur_factor + src_color * frag_info.src_factor;
frag_color = frag_color * blur_factor + src_color * mask_info.src_factor;
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <impeller/texture.glsl>

vec4 Sample(sampler2D tex, vec2 coords) {
return texture(tex, coords);
}
#define ENABLE_ALPHA_MASK 1
#define ENABLE_DECAL_SPECIALIZATION 1

#include "gaussian_blur.glsl"
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <impeller/texture.glsl>

vec4 Sample(sampler2D tex, vec2 coords) {
return IPSampleDecal(tex, coords);
}
#define ENABLE_ALPHA_MASK 1
#define ENABLE_DECAL_SPECIALIZATION 0

#include "gaussian_blur.glsl"
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#define ENABLE_ALPHA_MASK 0
#define ENABLE_DECAL_SPECIALIZATION 1

#include "gaussian_blur.glsl"
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#define ENABLE_ALPHA_MASK 0
#define ENABLE_DECAL_SPECIALIZATION 0

#include "gaussian_blur.glsl"
Loading