Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 006594d

Browse files
author
Jonah Williams
authored
Revert "Revert "[impeller] convert src over to src for solid color" (#41466)"
This reverts commit 8fe8e94.
1 parent aff8cbe commit 006594d

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

impeller/entity/contents/solid_color_contents.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ bool SolidColorContents::ShouldRender(
4646
return Contents::ShouldRender(entity, stencil_coverage);
4747
}
4848

49+
bool SolidColorContents::ConvertToSrc(const Entity& entity) const {
50+
return entity.GetBlendMode() == BlendMode::kSourceOver &&
51+
GetColor().alpha >= 1.0;
52+
}
53+
4954
bool SolidColorContents::Render(const ContentContext& renderer,
5055
const Entity& entity,
5156
RenderPass& pass) const {
@@ -60,6 +65,9 @@ bool SolidColorContents::Render(const ContentContext& renderer,
6065
GetGeometry()->GetPositionBuffer(renderer, entity, pass);
6166

6267
auto options = OptionsFromPassAndEntity(pass, entity);
68+
if (ConvertToSrc(entity)) {
69+
options.blend_mode = BlendMode::kSource;
70+
}
6371
if (geometry_result.prevent_overdraw) {
6472
options.stencil_compare = CompareFunction::kEqual;
6573
options.stencil_operation = StencilOperation::kIncrementClamp;

impeller/entity/contents/solid_color_contents.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ class SolidColorContents final : public ColorSourceContents {
4646
const Entity& entity,
4747
RenderPass& pass) const override;
4848

49+
/// @brief Convert SrcOver blend modes into Src blend modes if the color has
50+
/// no opacity.
51+
bool ConvertToSrc(const Entity& entity) const;
52+
4953
private:
5054
Color color_;
5155

impeller/entity/entity_unittests.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2547,5 +2547,25 @@ TEST_P(EntityTest, CoverageForStrokePathWithNegativeValuesInTransform) {
25472547
ASSERT_RECT_NEAR(coverage.value(), Rect::MakeXYWH(102.5, 342.5, 85, 155));
25482548
}
25492549

2550+
TEST_P(EntityTest, ConvertToSrcBlend) {
2551+
Entity entity;
2552+
entity.SetBlendMode(BlendMode::kSourceOver);
2553+
2554+
auto contents = SolidColorContents::Make(
2555+
PathBuilder{}.AddRect(Rect::MakeSize(Size(100, 100))).TakePath(),
2556+
Color::Red());
2557+
2558+
ASSERT_TRUE(contents->ConvertToSrc(entity));
2559+
2560+
// Color with alpha, should return false.
2561+
contents->SetInheritedOpacity(0.5);
2562+
ASSERT_FALSE(contents->ConvertToSrc(entity));
2563+
2564+
// Non source over blend mode, should return false.
2565+
contents->SetInheritedOpacity(1.0);
2566+
entity.SetBlendMode(BlendMode::kDestination);
2567+
ASSERT_FALSE(contents->ConvertToSrc(entity));
2568+
}
2569+
25502570
} // namespace testing
25512571
} // namespace impeller

0 commit comments

Comments
 (0)