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

Use PorterDuff blend mode when below Android 29 #34800

Merged
merged 6 commits into from
Jul 21, 2022

Conversation

bparrishMines
Copy link
Contributor

@bparrishMines bparrishMines commented Jul 21, 2022

Engine fix for flutter/flutter#104686.

As of now, this is solved at the plugin level by switching to Hybrid Composition when the view has a transparent/translucent background: flutter/plugins#6063

This should hopefully remove the need to do this. I tested it locally and the previous rendering issue was fixed when this flag was used.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See testing the engine for instructions on
    writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@bparrishMines bparrishMines changed the title Blend mode Use PorterDuff blend mode when below Android 29 Jul 21, 2022
@@ -308,7 +309,7 @@ public void draw(Canvas canvas) {
if (Build.VERSION.SDK_INT >= 29) {
surfaceCanvas.drawColor(Color.TRANSPARENT, BlendMode.CLEAR);
} else {
surfaceCanvas.drawColor(Color.TRANSPARENT);
surfaceCanvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
Copy link
Contributor

Choose a reason for hiding this comment

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

These blocks can be simplified by using drawPaint and setting the color and blend mode on the paint. That's all the Android impl is doing here anyway

Copy link
Contributor

Choose a reason for hiding this comment

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

You then won't have the branch here or need extra tests for different api levels

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are you referring to this method? https://developer.android.com/reference/android/graphics/Paint#setBlendMode(android.graphics.BlendMode).

Unfortunately, it also requires API 29.

Although, I agree that we don't need both methods. The PorterDuf blend mode isn't deprecated so I think we could just switch to that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ahh ok, I didn't realize that. This looks good to me though.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
autosubmit Merge PR when tree becomes green via auto submit App platform-android
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants