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

TEST_P(AiksTest, DrawAtlasPlusWideGamut) {
if (GetParam() != PlaygroundBackend::kMetal) {
GTEST_SKIP_("This backend doesn't yet support wide gamut.");
}

EXPECT_EQ(GetContext()->GetCapabilities()->GetDefaultColorFormat(),
PixelFormat::kR16G16B16A16Float);

// Draws the image as four squares stiched together.
auto atlas =
std::make_shared<Image>(CreateTextureForFixture("bay_bridge.jpg"));
auto size = atlas->GetSize();
// Divide image into four quadrants.
Scalar half_width = size.width / 2;
Scalar half_height = size.height / 2;
std::vector<Rect> texture_coordinates = {
Rect::MakeLTRB(0, 0, half_width, half_height),
Rect::MakeLTRB(half_width, 0, size.width, half_height),
Rect::MakeLTRB(0, half_height, half_width, size.height),
Rect::MakeLTRB(half_width, half_height, size.width, size.height)};
// Position quadrants adjacent to eachother.
std::vector<Matrix> transforms = {
Matrix::MakeTranslation({0, 0, 0}),
Matrix::MakeTranslation({half_width, 0, 0}),
Matrix::MakeTranslation({0, half_height, 0}),
Matrix::MakeTranslation({half_width, half_height, 0})};
std::vector<Color> colors = {Color::Red(), Color::Green(), Color::Blue(),
Color::Yellow()};

Canvas canvas;
canvas.DrawAtlas(atlas, transforms, texture_coordinates, colors,
BlendMode::kPlus, {}, std::nullopt, {});

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

} // namespace testing
} // namespace impeller

Expand Down
11 changes: 11 additions & 0 deletions impeller/entity/shaders/blending/porter_duff_blend.frag
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ f16vec4 Sample(f16sampler2D texture_sampler, vec2 texture_coords) {
return IPHalfSampleDecal(texture_sampler, texture_coords);
}

float16_t ClampAlpha(float16_t alpha) {
float16_t min = 0.0hf;
float16_t max = 1.0hf;
return clamp(alpha, min, max);
}

void main() {
f16vec4 dst =
texture(texture_sampler_dst, v_texture_coords) * frag_info.input_alpha;
Expand All @@ -45,4 +51,9 @@ void main() {
dst * (frag_info.dst_coeff + src.a * frag_info.dst_coeff_src_alpha +
src * frag_info.dst_coeff_src_color);
frag_color *= frag_info.output_alpha;
// This currently needs a clamp so that floating point textures blend
// correctly in wide gamut. Remove if we switch to a fixed point extended
// range format.
// See https://github.com/flutter/flutter/issues/145933 .
frag_color.a = ClampAlpha(frag_color.a);
}
12 changes: 6 additions & 6 deletions impeller/tools/malioc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8434,8 +8434,8 @@
"varying"
],
"longest_path_cycles": [
0.21875,
0.21875,
0.234375,
0.234375,
0.0,
0.0,
0.0,
Expand All @@ -8455,8 +8455,8 @@
"varying"
],
"shortest_path_cycles": [
0.21875,
0.21875,
0.234375,
0.234375,
0.0,
0.0,
0.0,
Expand All @@ -8467,8 +8467,8 @@
"varying"
],
"total_cycles": [
0.21875,
0.21875,
0.234375,
0.234375,
0.0,
0.0,
0.0,
Expand Down
1 change: 1 addition & 0 deletions testing/impeller_golden_tests_output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ impeller_Play_AiksTest_DrawAdvancedBlendPartlyOffscreen_Vulkan.png
impeller_Play_AiksTest_DrawAtlasAdvancedAndTransform_Metal.png
impeller_Play_AiksTest_DrawAtlasAdvancedAndTransform_OpenGLES.png
impeller_Play_AiksTest_DrawAtlasAdvancedAndTransform_Vulkan.png
impeller_Play_AiksTest_DrawAtlasPlusWideGamut_Metal.png
impeller_Play_AiksTest_DrawAtlasWithColorAdvancedAndTransform_Metal.png
impeller_Play_AiksTest_DrawAtlasWithColorAdvancedAndTransform_OpenGLES.png
impeller_Play_AiksTest_DrawAtlasWithColorAdvancedAndTransform_Vulkan.png
Expand Down