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

[Impeller] Implement Color blend mode#36120

Merged
JsouLiang merged 5 commits into
flutter-team-archive:mainfrom
JsouLiang:blend-color-for-vertices-atlas
Sep 19, 2022
Merged

[Impeller] Implement Color blend mode#36120
JsouLiang merged 5 commits into
flutter-team-archive:mainfrom
JsouLiang:blend-color-for-vertices-atlas

Conversation

@JsouLiang

Copy link
Copy Markdown
Contributor

Implement blend param in DrawVertices and DrawAtlas
Association issue: flutter/flutter#108047

Comment thread impeller/entity/entity.cc Outdated
std::min(value.z, threshold), std::min(value.w, threshold));
}

Color blendColor(const Color& src,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not an expert about rendering here, but I wonder whether this is efficient or not? Seems that the cost of a switch has to be performed for each and every color.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't worry about the performance until we have traces that show performance here is a bottleneck. That said, if we did need to change things, we could always up this function to operate over an entire vector at once.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't worry about the performance until we have traces that show performance here is a bottleneck.

You are right!

we could always up this function to operate over an entire vector at once

That is what I was thinking :)

Comment thread impeller/entity/entity.cc Outdated
auto sample_rect = texture_coords_[i];
auto matrix = transforms_[i];
auto color = (colors_.size() > 0 ? colors_[i] : Color::Black());
auto color = (colors_.size() > 0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe that this is correct - for drawAtlas we blend the colors with the texture sample which must be done in the shader: https://api.flutter.dev/flutter/dart-ui/Canvas/drawAtlas.html

Blend each rectangular portion of the image specified by an entry in the rects argument with its associated entry in the colors list using the blendMode argument (if a color is specified). In this part of the operation, the image part will be considered the source of the operation and the associated color will be considered the destination.

@bdero bdero left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good so far -- mostly comments about where stuff should live.

Comment thread impeller/entity/entity.cc Outdated
Comment thread impeller/entity/entity.cc Outdated
Comment thread impeller/entity/entity.cc Outdated
Comment thread impeller/entity/entity.h Outdated
Comment thread impeller/entity/entity.h Outdated
Comment thread impeller/entity/entity.cc Outdated
@JsouLiang
JsouLiang requested review from bdero, fzyzcjy and jonahwilliams and removed request for fzyzcjy September 14, 2022 13:38
@JsouLiang
JsouLiang force-pushed the blend-color-for-vertices-atlas branch from 92c86f6 to 2e2ff17 Compare September 14, 2022 13:40
Comment thread impeller/entity/entity_unittests.cc Outdated
}
};

auto generator_expected_colors = [](Color& src,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not use a closure like this to generate the expected colors. A frequent mistake made with this sorts of tests, is that someone writes some code (with a bug), copies and pastes the implementation into the test generator (with the same bug) and asserts that they are the same - which they will be, but still wrong.

Instead each test case should have a specified color that a developer could easily cross reference with an external source

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@bdero bdero left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM after addressing final comments, thanks!

Comment thread impeller/geometry/color.h Outdated
Comment thread impeller/geometry/color.cc Outdated
@JsouLiang
JsouLiang force-pushed the blend-color-for-vertices-atlas branch from d334e58 to 9695976 Compare September 15, 2022 06:49
Comment thread impeller/entity/entity_unittests.cc Outdated
Comment thread impeller/entity/entity_unittests.cc Outdated

@jonahwilliams jonahwilliams left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@JsouLiang
JsouLiang force-pushed the blend-color-for-vertices-atlas branch from 11e82a2 to 8ad01de Compare September 19, 2022 03:08
@JsouLiang
JsouLiang merged commit ba7eee9 into flutter-team-archive:main Sep 19, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 19, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 19, 2022
Oleh-Sv pushed a commit to Oleh-Sv/engine that referenced this pull request Sep 28, 2022
* Add color blend mode

* Move Entrity::BlendMode to Color file; Add unittest for blendMode color

* Fix some comments

* fix comments

* delete the redundancy code
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Development

Successfully merging this pull request may close these issues.

5 participants