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
36 changes: 34 additions & 2 deletions impeller/aiks/aiks_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1955,7 +1955,7 @@ TEST_P(AiksTest, TranslucentSaveLayerWithBlendColorFilterDrawsCorrectly) {
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_P(AiksTest, TranslucentSaveLayerWithBlendImageFilterAndDrawsCorrectly) {
TEST_P(AiksTest, TranslucentSaveLayerWithBlendImageFilterDrawsCorrectly) {
Canvas canvas;

canvas.DrawRect(Rect::MakeXYWH(100, 100, 300, 300), {.color = Color::Blue()});
Expand All @@ -1976,7 +1976,7 @@ TEST_P(AiksTest, TranslucentSaveLayerWithBlendImageFilterAndDrawsCorrectly) {
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_P(AiksTest, TranslucentSaveLayerWithColorImageFilterAndDrawsCorrectly) {
TEST_P(AiksTest, TranslucentSaveLayerWithColorAndImageFilterDrawsCorrectly) {
Canvas canvas;

canvas.DrawRect(Rect::MakeXYWH(100, 100, 300, 300), {.color = Color::Blue()});
Expand Down Expand Up @@ -2060,6 +2060,38 @@ TEST_P(AiksTest, TranslucentSaveLayerWithColorMatrixImageFilterDrawsCorrectly) {
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_P(AiksTest,
TranslucentSaveLayerWithColorFilterAndImageFilterDrawsCorrectly) {
Canvas canvas;

auto image = std::make_shared<Image>(CreateTextureForFixture("airplane.jpg"));
canvas.DrawImage(image, {100, 100}, {});

canvas.SaveLayer({
.color = Color::Black().WithAlpha(0.5),
.image_filter =
[](FilterInput::Ref input, const Matrix& effect_transform,
bool is_subpass) {
return ColorFilterContents::MakeColorMatrix(
{std::move(input)}, {.array = {
1, 0, 0, 0, 0, //
0, 1, 0, 0, 0, //
0, 0.2, 1, 0, 0, //
0, 0, 0, 0.5, 0 //
}});
},
.color_filter =
[](FilterInput::Ref input) {
return ColorFilterContents::MakeBlend(
BlendMode::kModulate, {std::move(input)}, Color::Green());
},
});
canvas.DrawImage(image, {100, 500}, {});
canvas.Restore();

ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

/// This is a regression check for https://github.com/flutter/engine/pull/41129
/// The entire screen is green if successful. If failing, no frames will render,
/// or the entire screen will be transparent black.
Expand Down
12 changes: 6 additions & 6 deletions impeller/entity/contents/filters/blend_filter_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,8 @@ std::optional<Entity> BlendFilterContents::CreateForegroundAdvancedBlend(
auto blend_uniform = host_buffer.EmplaceUniform(blend_info);
FS::BindBlendInfo(cmd, blend_uniform);

frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize());
frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
entity.GetTransformation();

auto uniform_view = host_buffer.EmplaceUniform(frame_info);
VS::BindFrameInfo(cmd, uniform_view);
Expand All @@ -313,15 +314,14 @@ std::optional<Entity> BlendFilterContents::CreateForegroundAdvancedBlend(
};
CoverageProc coverage_proc =
[coverage](const Entity& entity) -> std::optional<Rect> {
return coverage;
return coverage.TransformBounds(entity.GetTransformation());
};

auto contents = AnonymousContents::Make(render_proc, coverage_proc);

Entity sub_entity;
sub_entity.SetContents(std::move(contents));
sub_entity.SetStencilDepth(entity.GetStencilDepth());
sub_entity.SetTransformation(entity.GetTransformation());

return sub_entity;
}
Expand Down Expand Up @@ -442,7 +442,8 @@ std::optional<Entity> BlendFilterContents::CreateForegroundPorterDuffBlend(

FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_info));

frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize());
frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
entity.GetTransformation();

auto uniform_view = host_buffer.EmplaceUniform(frame_info);
VS::BindFrameInfo(cmd, uniform_view);
Expand All @@ -452,15 +453,14 @@ std::optional<Entity> BlendFilterContents::CreateForegroundPorterDuffBlend(

CoverageProc coverage_proc =
[coverage](const Entity& entity) -> std::optional<Rect> {
return coverage;
return coverage.TransformBounds(entity.GetTransformation());
};

auto contents = AnonymousContents::Make(render_proc, coverage_proc);

Entity sub_entity;
sub_entity.SetContents(std::move(contents));
sub_entity.SetStencilDepth(entity.GetStencilDepth());
sub_entity.SetTransformation(entity.GetTransformation());

return sub_entity;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ std::optional<Entity> BorderMaskBlurFilterContents::RenderFilter(
cmd.stencil_reference = entity.GetStencilDepth();

VS::FrameInfo frame_info;
frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize());
frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
entity.GetTransformation();
frame_info.texture_sampler_y_coord_scale =
input_snapshot->texture->GetYCoordScale();

Expand All @@ -136,15 +137,14 @@ std::optional<Entity> BorderMaskBlurFilterContents::RenderFilter(

CoverageProc coverage_proc =
[coverage](const Entity& entity) -> std::optional<Rect> {
return coverage;
return coverage.TransformBounds(entity.GetTransformation());
};

auto contents = AnonymousContents::Make(render_proc, coverage_proc);

Entity sub_entity;
sub_entity.SetContents(std::move(contents));
sub_entity.SetStencilDepth(entity.GetStencilDepth());
sub_entity.SetTransformation(entity.GetTransformation());
sub_entity.SetBlendMode(entity.GetBlendMode());
return sub_entity;
}
Expand Down
30 changes: 13 additions & 17 deletions impeller/entity/contents/filters/color_matrix_filter_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ std::optional<Entity> ColorMatrixFilterContents::RenderFilter(
//----------------------------------------------------------------------------
/// Create AnonymousContents for rendering.
///
RenderProc render_proc = [input_snapshot, color_matrix = matrix_, coverage,
RenderProc render_proc = [input_snapshot, color_matrix = matrix_,
absorb_opacity = GetAbsorbOpacity()](
const ContentContext& renderer,
const Entity& entity, RenderPass& pass) -> bool {
Expand All @@ -60,27 +60,25 @@ std::optional<Entity> ColorMatrixFilterContents::RenderFilter(
auto options = OptionsFromPassAndEntity(pass, entity);
cmd.pipeline = renderer.GetColorMatrixColorFilterPipeline(options);

auto size = input_snapshot->texture->GetSize();

VertexBufferBuilder<VS::PerVertexData> vtx_builder;
vtx_builder.AddVertices({
{coverage.origin, Point(0, 0)},
{{coverage.origin.x + coverage.size.width, coverage.origin.y},
Point(1, 0)},
{{coverage.origin.x + coverage.size.width,
coverage.origin.y + coverage.size.height},
Point(1, 1)},
{coverage.origin, Point(0, 0)},
{{coverage.origin.x + coverage.size.width,
coverage.origin.y + coverage.size.height},
Point(1, 1)},
{{coverage.origin.x, coverage.origin.y + coverage.size.height},
Point(0, 1)},
{Point(0, 0)},
{Point(1, 0)},
{Point(1, 1)},
{Point(0, 0)},
{Point(1, 1)},
{Point(0, 1)},
});
auto& host_buffer = pass.GetTransientsBuffer();
auto vtx_buffer = vtx_builder.CreateVertexBuffer(host_buffer);
cmd.BindVertices(vtx_buffer);

VS::FrameInfo frame_info;
frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize());
frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
entity.GetTransformation() * input_snapshot->transform *
Matrix::MakeScale(Vector2(size));
frame_info.texture_sampler_y_coord_scale =
input_snapshot->texture->GetYCoordScale();

Expand All @@ -107,16 +105,14 @@ std::optional<Entity> ColorMatrixFilterContents::RenderFilter(

CoverageProc coverage_proc =
[coverage](const Entity& entity) -> std::optional<Rect> {
return coverage;
return coverage.TransformBounds(entity.GetTransformation());
};

auto contents = AnonymousContents::Make(render_proc, coverage_proc);

Entity sub_entity;
sub_entity.SetContents(std::move(contents));
sub_entity.SetStencilDepth(entity.GetStencilDepth());
sub_entity.SetTransformation(Matrix::MakeTranslation(coverage.origin) *
entity.GetTransformation());
sub_entity.SetBlendMode(entity.GetBlendMode());
return sub_entity;
}
Expand Down
35 changes: 13 additions & 22 deletions impeller/entity/contents/filters/linear_to_srgb_filter_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,10 @@ std::optional<Entity> LinearToSrgbFilterContents::RenderFilter(
return std::nullopt;
}

auto maybe_input_uvs = input_snapshot->GetCoverageUVs(coverage);
if (!maybe_input_uvs.has_value()) {
return std::nullopt;
}
auto input_uvs = maybe_input_uvs.value();

//----------------------------------------------------------------------------
/// Create AnonymousContents for rendering.
///
RenderProc render_proc = [input_snapshot, coverage, input_uvs,
RenderProc render_proc = [input_snapshot,
absorb_opacity = GetAbsorbOpacity()](
const ContentContext& renderer,
const Entity& entity, RenderPass& pass) -> bool {
Expand All @@ -56,28 +50,26 @@ std::optional<Entity> LinearToSrgbFilterContents::RenderFilter(
auto options = OptionsFromPassAndEntity(pass, entity);
cmd.pipeline = renderer.GetLinearToSrgbFilterPipeline(options);

auto size = input_snapshot->texture->GetSize();

VertexBufferBuilder<VS::PerVertexData> vtx_builder;
vtx_builder.AddVertices({
{coverage.origin, input_uvs[0]},
{{coverage.origin.x + coverage.size.width, coverage.origin.y},
input_uvs[1]},
{{coverage.origin.x + coverage.size.width,
coverage.origin.y + coverage.size.height},
input_uvs[3]},
{coverage.origin, input_uvs[0]},
{{coverage.origin.x + coverage.size.width,
coverage.origin.y + coverage.size.height},
input_uvs[3]},
{{coverage.origin.x, coverage.origin.y + coverage.size.height},
input_uvs[2]},
{Point(0, 0)},
{Point(1, 0)},
{Point(1, 1)},
{Point(0, 0)},
{Point(1, 1)},
{Point(0, 1)},
});

auto& host_buffer = pass.GetTransientsBuffer();
auto vtx_buffer = vtx_builder.CreateVertexBuffer(host_buffer);
cmd.BindVertices(vtx_buffer);

VS::FrameInfo frame_info;
frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize());
frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
entity.GetTransformation() * input_snapshot->transform *
Matrix::MakeScale(Vector2(size));
frame_info.texture_sampler_y_coord_scale =
input_snapshot->texture->GetYCoordScale();

Expand All @@ -94,15 +86,14 @@ std::optional<Entity> LinearToSrgbFilterContents::RenderFilter(

CoverageProc coverage_proc =
[coverage](const Entity& entity) -> std::optional<Rect> {
return coverage;
return coverage.TransformBounds(entity.GetTransformation());
};

auto contents = AnonymousContents::Make(render_proc, coverage_proc);

Entity sub_entity;
sub_entity.SetContents(std::move(contents));
sub_entity.SetStencilDepth(entity.GetStencilDepth());
sub_entity.SetTransformation(entity.GetTransformation());
sub_entity.SetBlendMode(entity.GetBlendMode());
return sub_entity;
}
Expand Down
35 changes: 13 additions & 22 deletions impeller/entity/contents/filters/srgb_to_linear_filter_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,10 @@ std::optional<Entity> SrgbToLinearFilterContents::RenderFilter(
return std::nullopt;
}

auto maybe_input_uvs = input_snapshot->GetCoverageUVs(coverage);
if (!maybe_input_uvs.has_value()) {
return std::nullopt;
}
auto input_uvs = maybe_input_uvs.value();

//----------------------------------------------------------------------------
/// Create AnonymousContents for rendering.
///
RenderProc render_proc = [input_snapshot, coverage, input_uvs,
RenderProc render_proc = [input_snapshot,
absorb_opacity = GetAbsorbOpacity()](
const ContentContext& renderer,
const Entity& entity, RenderPass& pass) -> bool {
Expand All @@ -56,28 +50,26 @@ std::optional<Entity> SrgbToLinearFilterContents::RenderFilter(
auto options = OptionsFromPassAndEntity(pass, entity);
cmd.pipeline = renderer.GetSrgbToLinearFilterPipeline(options);

auto size = input_snapshot->texture->GetSize();

VertexBufferBuilder<VS::PerVertexData> vtx_builder;
vtx_builder.AddVertices({
{coverage.origin, input_uvs[0]},
{{coverage.origin.x + coverage.size.width, coverage.origin.y},
input_uvs[1]},
{{coverage.origin.x + coverage.size.width,
coverage.origin.y + coverage.size.height},
input_uvs[3]},
{coverage.origin, input_uvs[0]},
{{coverage.origin.x + coverage.size.width,
coverage.origin.y + coverage.size.height},
input_uvs[3]},
{{coverage.origin.x, coverage.origin.y + coverage.size.height},
input_uvs[2]},
{Point(0, 0)},
{Point(1, 0)},
{Point(1, 1)},
{Point(0, 0)},
{Point(1, 1)},
{Point(0, 1)},
});

auto& host_buffer = pass.GetTransientsBuffer();
auto vtx_buffer = vtx_builder.CreateVertexBuffer(host_buffer);
cmd.BindVertices(vtx_buffer);

VS::FrameInfo frame_info;
frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize());
frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
entity.GetTransformation() * input_snapshot->transform *
Matrix::MakeScale(Vector2(size));
frame_info.texture_sampler_y_coord_scale =
input_snapshot->texture->GetYCoordScale();

Expand All @@ -94,15 +86,14 @@ std::optional<Entity> SrgbToLinearFilterContents::RenderFilter(

CoverageProc coverage_proc =
[coverage](const Entity& entity) -> std::optional<Rect> {
return coverage;
return coverage.TransformBounds(entity.GetTransformation());
};

auto contents = AnonymousContents::Make(render_proc, coverage_proc);

Entity sub_entity;
sub_entity.SetContents(std::move(contents));
sub_entity.SetStencilDepth(entity.GetStencilDepth());
sub_entity.SetTransformation(entity.GetTransformation());
sub_entity.SetBlendMode(entity.GetBlendMode());
return sub_entity;
}
Expand Down
Loading