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

[CP][Impeller] Fix framebuffer blend UVs. (#46489) #46775

Merged
merged 1 commit into from
Oct 17, 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
20 changes: 20 additions & 0 deletions impeller/aiks/aiks_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1580,6 +1580,26 @@ TEST_P(AiksTest, DrawPaintWithAdvancedBlendOverFilter) {
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_P(AiksTest, DrawAdvancedBlendPartlyOffscreen) {
std::vector<Color> colors = {Color{0.9568, 0.2627, 0.2118, 1.0},
Color{0.1294, 0.5882, 0.9529, 1.0}};
std::vector<Scalar> stops = {0.0, 1.0};

Paint paint = {
.color_source = ColorSource::MakeLinearGradient(
{0, 0}, {100, 100}, std::move(colors), std::move(stops),
Entity::TileMode::kRepeat, Matrix::MakeScale(Vector3(0.3, 0.3, 0.3))),
.blend_mode = BlendMode::kLighten,
};

Canvas canvas;
canvas.DrawPaint({.color = Color::Blue()});
canvas.Scale(Vector2(2, 2));
canvas.ClipRect(Rect::MakeLTRB(0, 0, 200, 200));
canvas.DrawCircle({100, 100}, 100, paint);
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

#define BLEND_MODE_TUPLE(blend_mode) {#blend_mode, BlendMode::k##blend_mode},

struct BlendModeSelection {
Expand Down
21 changes: 8 additions & 13 deletions impeller/entity/contents/framebuffer_blend_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ bool FramebufferBlendContents::Render(const ContentContext& renderer,
std::nullopt, // sampler_descriptor
true, // msaa_enabled
"FramebufferBlendContents Snapshot"); // label

if (!src_snapshot.has_value()) {
return true;
}
Expand All @@ -56,21 +57,16 @@ bool FramebufferBlendContents::Render(const ContentContext& renderer,
return true;
}
Rect src_coverage = coverage.value();
auto maybe_src_uvs = src_snapshot->GetCoverageUVs(src_coverage);
if (!maybe_src_uvs.has_value()) {
return true;
}
std::array<Point, 4> src_uvs = maybe_src_uvs.value();

auto size = src_coverage.size;
VertexBufferBuilder<VS::PerVertexData> vtx_builder;
vtx_builder.AddVertices({
{Point(0, 0), src_uvs[0]},
{Point(size.width, 0), src_uvs[1]},
{Point(size.width, size.height), src_uvs[3]},
{Point(0, 0), src_uvs[0]},
{Point(size.width, size.height), src_uvs[3]},
{Point(0, size.height), src_uvs[2]},
{Point(0, 0), Point(0, 0)},
{Point(size.width, 0), Point(1, 0)},
{Point(size.width, size.height), Point(1, 1)},
{Point(0, 0), Point(0, 0)},
{Point(size.width, size.height), Point(1, 1)},
{Point(0, size.height), Point(0, 1)},
});
auto vtx_buffer = vtx_builder.CreateVertexBuffer(host_buffer);

Expand Down Expand Up @@ -147,8 +143,7 @@ bool FramebufferBlendContents::Render(const ContentContext& renderer,
FS::BindTextureSamplerSrc(cmd, src_snapshot->texture, src_sampler);

frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
entity.GetTransformation() *
Matrix::MakeTranslation(src_coverage.origin);
src_snapshot->transform;
frame_info.src_y_coord_scale = src_snapshot->texture->GetYCoordScale();
VS::BindFrameInfo(cmd, host_buffer.EmplaceUniform(frame_info));

Expand Down