[Impeller] Support 'texture_sampler_y_coord_scale' in more filters (flutter/engine#36412)

This commit is contained in:
ColdPaleLight
2022-09-27 06:08:16 +08:00
committed by GitHub
parent 5d1110205d
commit 47da6f206d
8 changed files with 50 additions and 11 deletions

View File

@@ -192,9 +192,11 @@ static std::optional<Snapshot> PipelineBlend(
frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
Matrix::MakeTranslation(-coverage.origin) *
input->transform;
auto uniform_view = host_buffer.EmplaceUniform(frame_info);
VS::BindFrameInfo(cmd, uniform_view);
FS::FragInfo frag_info;
frag_info.texture_sampler_y_coord_scale =
input->texture->GetYCoordScale();
FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_info));
VS::BindFrameInfo(cmd, host_buffer.EmplaceUniform(frame_info));
pass.AddCommand(cmd);
return true;

View File

@@ -108,8 +108,11 @@ std::optional<Snapshot> BorderMaskBlurFilterContents::RenderFilter(
frame_info.src_factor = src_color_factor_;
frame_info.inner_blur_factor = inner_blur_factor_;
frame_info.outer_blur_factor = outer_blur_factor_;
auto uniform_view = host_buffer.EmplaceUniform(frame_info);
VS::BindFrameInfo(cmd, uniform_view);
FS::FragInfo frag_info;
frag_info.texture_sampler_y_coord_scale =
input_snapshot->texture->GetYCoordScale();
FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_info));
VS::BindFrameInfo(cmd, host_buffer.EmplaceUniform(frame_info));
auto sampler = renderer.GetContext()->GetSamplerLibrary()->GetSampler({});
FS::BindTextureSampler(cmd, input_snapshot->texture, sampler);

View File

@@ -61,9 +61,13 @@ std::optional<Snapshot> LinearToSrgbFilterContents::RenderFilter(
VS::FrameInfo frame_info;
frame_info.mvp = Matrix::MakeOrthographic(ISize(1, 1));
FS::FragInfo frag_info;
frag_info.texture_sampler_y_coord_scale =
input_snapshot->texture->GetYCoordScale();
auto sampler = renderer.GetContext()->GetSamplerLibrary()->GetSampler({});
FS::BindInputTexture(cmd, input_snapshot->texture, sampler);
FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_info));
VS::BindFrameInfo(cmd, host_buffer.EmplaceUniform(frame_info));
return pass.AddCommand(std::move(cmd));

View File

@@ -61,9 +61,13 @@ std::optional<Snapshot> SrgbToLinearFilterContents::RenderFilter(
VS::FrameInfo frame_info;
frame_info.mvp = Matrix::MakeOrthographic(ISize(1, 1));
FS::FragInfo frag_info;
frag_info.texture_sampler_y_coord_scale =
input_snapshot->texture->GetYCoordScale();
auto sampler = renderer.GetContext()->GetSamplerLibrary()->GetSampler({});
FS::BindInputTexture(cmd, input_snapshot->texture, sampler);
FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_info));
VS::BindFrameInfo(cmd, host_buffer.EmplaceUniform(frame_info));
return pass.AddCommand(std::move(cmd));

View File

@@ -2,12 +2,19 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <impeller/texture.glsl>
uniform sampler2D texture_sampler_src;
uniform FragInfo {
float texture_sampler_y_coord_scale;
} frag_info;
in vec2 v_texture_coords;
out vec4 frag_color;
void main() {
frag_color = texture(texture_sampler_src, v_texture_coords);
frag_color = IPSample(texture_sampler_src, v_texture_coords,
frag_info.texture_sampler_y_coord_scale);
}

View File

@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <impeller/texture.glsl>
// Constant time mask blur for image borders.
//
// This mask blur extends the geometry of the source image (with clamp border
@@ -13,6 +15,10 @@
uniform sampler2D texture_sampler;
uniform FragInfo {
float texture_sampler_y_coord_scale;
} frag_info;
in vec2 v_texture_coords;
in vec2 v_sigma_uv;
in float v_src_factor;
@@ -48,7 +54,8 @@ float BoxBlurMask(vec2 uv) {
}
void main() {
vec4 image_color = texture(texture_sampler, v_texture_coords);
vec4 image_color = IPSample(texture_sampler, v_texture_coords,
frag_info.texture_sampler_y_coord_scale);
float blur_factor = BoxBlurMask(v_texture_coords);
float within_bounds =

View File

@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include <impeller/color.glsl>
#include <impeller/texture.glsl>
// A color filter that applies the sRGB gamma curve to the color.
//
@@ -10,11 +11,16 @@
uniform sampler2D input_texture;
uniform FragInfo {
float texture_sampler_y_coord_scale;
} frag_info;
in vec2 v_position;
out vec4 frag_color;
void main() {
vec4 input_color = texture(input_texture, v_position);
vec4 input_color = IPSample(input_texture, v_position,
frag_info.texture_sampler_y_coord_scale);
for (int i = 0; i < 4; i++) {
if (input_color[i] <= 0.0031308) {

View File

@@ -3,17 +3,23 @@
// found in the LICENSE file.
#include <impeller/color.glsl>
#include <impeller/texture.glsl>
// Creates a color filter that applies the inverse of the sRGB gamma curve
// to the RGB channels.
uniform sampler2D input_texture;
uniform FragInfo {
float texture_sampler_y_coord_scale;
} frag_info;
in vec2 v_position;
out vec4 frag_color;
void main() {
vec4 input_color = texture(input_texture, v_position);
vec4 input_color = IPSample(input_texture, v_position,
frag_info.texture_sampler_y_coord_scale);
for (int i = 0; i < 4; i++) {
if (input_color[i] <= 0.04045) {