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

[web] Fix rendering of gradients in html mode #40345

Merged
merged 11 commits into from
Aug 9, 2023

Conversation

xtyxtyx
Copy link
Contributor

@xtyxtyx xtyxtyx commented Mar 16, 2023

CleanShot 2023-03-16 at 20 44 01@2x

Code Example
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class DemoGradientTransform implements GradientTransform {
  @override
  Matrix4? transform(Rect bounds, {TextDirection? textDirection}) {
    return Matrix4.identity()
      ..scale(1.2, 1.7)
      ..rotateZ(0.25);
  }
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    var colors = <Color>[
      Colors.red,
      Colors.green,
      Colors.blue,
      Colors.yellow,
    ];

    const stops = <double>[0.0, 0.25, 0.5, 1.0];

    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: GridView(
        gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
          crossAxisCount: TileMode.values.length,
        ),
        children: <Widget>[
          for (final mode in TileMode.values)
            DecoratedBox(
              decoration: BoxDecoration(
                gradient: LinearGradient(
                  colors: colors,
                  stops: stops,
                  tileMode: mode,
                  transform: DemoGradientTransform(),
                ),
              ),
            ),
          for (final mode in TileMode.values)
            DecoratedBox(
              decoration: BoxDecoration(
                gradient: RadialGradient(
                  center: Alignment.topLeft,
                  radius: 0.5,
                  colors: colors,
                  stops: stops,
                  tileMode: mode,
                  transform: DemoGradientTransform(),
                ),
              ),
            ),
          for (final mode in TileMode.values)
            DecoratedBox(
              decoration: BoxDecoration(
                gradient: SweepGradient(
                  center: Alignment.topLeft,
                  startAngle: 0.0,
                  endAngle: 3.14,
                  colors: colors,
                  stops: stops,
                  tileMode: mode,
                  transform: DemoGradientTransform(),
                ),
              ),
            ),
        ],
      ),
    );
  }
}

Fixes: flutter/flutter#84245

@flutter-dashboard flutter-dashboard bot added the platform-web Code specifically for the web engine label Mar 16, 2023
@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.

@flutter-dashboard
Copy link

Golden file changes have been found for this pull request. Click here to view and triage (e.g. because this is an intentional change).

If you are still iterating on this change and are not ready to resolve the images on the Flutter Gold dashboard, consider marking this PR as a draft pull request above. You will still be able to view image results on the dashboard, commenting will be silenced, and the check will not try to resolve itself until marked ready for review.

Changes reported for pull request #40345 at sha b3623fe

@flutter-dashboard
Copy link

Golden file changes are available for triage from new commit, Click here to view.

Changes reported for pull request #40345 at sha 093e0b5

@flutter-dashboard
Copy link

This pull request executed golden file tests, but it has not been updated in a while (20+ days). Test results from Gold expire after as many days, so this pull request will need to be updated with a fresh commit in order to get results from Gold.

@Hixie
Copy link
Contributor

Hixie commented May 30, 2023

@xtyxtyx This looks like a great contribution, sorry we have been slacking on reviewing it. Let me see if I can find a reviewer.

@Hixie
Copy link
Contributor

Hixie commented May 30, 2023

@xtyxtyx If you don't get a review for this in the next few days, please join our Discord (the link is in the contributing guide, link to which is below) and ping me (Hixie) in the #hackers-web channel.

@kevmoo
Copy link
Contributor

kevmoo commented May 30, 2023

CC @yjbanov ?

@@ -86,7 +86,7 @@ Future<void> testMain() async {
}
expect(rc.renderStrategy.hasArbitraryPaint, isTrue);
await canvasScreenshot(rc, 'linear_gradient_oval_matrix');
});
}, skip: isFirefox);
Copy link
Contributor

Choose a reason for hiding this comment

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

Did this suddenly start failing on Firefox? Thoughts @yjbanov ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm surprised this wasn't failing before. We don't have infra to golden-test Firefox. @eyebrowsoffire reorged our tests recently and might know more.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think these tests will fail on Firefox, but they will not take screenshots or send them to skia gold. However, it may be of at least some utility to just run the tests on Firefox anyway just to make sure you can actually do the drawing commands and not crash or throw an exception. I'll leave it up to you though, it might not be worthwhile to run them.

@yjbanov yjbanov requested a review from eyebrowsoffire May 30, 2023 23:56
@yjbanov
Copy link
Contributor

yjbanov commented May 30, 2023

LGTM but I'd like @eyebrowsoffire, who looked into this code before and also recently mentioned something to me about it, to take a second look.

Copy link
Contributor

@eyebrowsoffire eyebrowsoffire left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for fixing this.

@@ -86,7 +86,7 @@ Future<void> testMain() async {
}
expect(rc.renderStrategy.hasArbitraryPaint, isTrue);
await canvasScreenshot(rc, 'linear_gradient_oval_matrix');
});
}, skip: isFirefox);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think these tests will fail on Firefox, but they will not take screenshots or send them to skia gold. However, it may be of at least some utility to just run the tests on Firefox anyway just to make sure you can actually do the drawing commands and not crash or throw an exception. I'll leave it up to you though, it might not be worthwhile to run them.

@flutter-dashboard
Copy link

Golden file changes are available for triage from new commit, Click here to view.

Changes reported for pull request #40345 at sha a63f2b6

@eyebrowsoffire
Copy link
Contributor

@xtyxtyx This has been sitting for a while, and I noticed there are some untriaged goldens sitting here. I went to triage them, but some of the new ones don't look correct to me. For example https://flutter-engine-gold.skia.org/detail?grouping=name%3Dradial_gradient_clamp_transformed%26source_type%3Dflutter-engine&digest=fb78cbd08ab084418a97c2bfe060a503&changelist_id=40345&crs=github

Which just shows a gray oval. I have to assume that's supposed to be rendering some kind of gradient there? Not sure if it's an issue with the test, an issue with the rendering code, or whether it's actually expected to just draw a gray oval.

@flutter-dashboard
Copy link

Golden file changes are available for triage from new commit, Click here to view.

Changes reported for pull request #40345 at sha 9e809b4

@flutter-dashboard
Copy link

Golden file changes are available for triage from new commit, Click here to view.

Changes reported for pull request #40345 at sha c2e3185

@xtyxtyx
Copy link
Contributor Author

xtyxtyx commented Aug 7, 2023

@eyebrowsoffire Thanks for your help! After some investigation I found these gray ovals were painted because the center of the gradient was too far away. I've fixed the test and the new these golden files look correct now.

@eyebrowsoffire
Copy link
Contributor

Great! I approved the new goldens, they look sane to me now.

@kevmoo kevmoo added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 9, 2023
@auto-submit auto-submit bot merged commit f260e6d into flutter:main Aug 9, 2023
@kevmoo
Copy link
Contributor

kevmoo commented Aug 9, 2023

Thanks so much for your contribution @xtyxtyx !!

engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 9, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 9, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 10, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 10, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 10, 2023
zanderso pushed a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 10, 2023
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Aug 10, 2023
…132284)

flutter/engine@b5b41ff...9117ff2

2023-08-10 zanderso@users.noreply.github.com Revert "Android a11y bridge sets importantness" (flutter/engine#44569)
2023-08-10 skia-flutter-autoroll@skia.org Roll Skia from 491f67637e6e to 7c5f6b17a998 (2 revisions) (flutter/engine#44568)
2023-08-10 matanlurey@users.noreply.github.com [Impeller] Replace Vulkan rotation checks with polling (flutter/engine#44361)
2023-08-10 31859944+LongCatIsLooong@users.noreply.github.com Disable text rounding hack by default (flutter/engine#44544)
2023-08-09 skia-flutter-autoroll@skia.org Roll Skia from 3d5a6138b7e5 to 491f67637e6e (4 revisions) (flutter/engine#44563)
2023-08-09 skia-flutter-autoroll@skia.org Manual roll Dart SDK from f664f4b9c50d to d89e4ead966d (11 revisions) (flutter/engine#44560)
2023-08-09 58529443+srujzs@users.noreply.github.com Make toJS'd function use JS types (flutter/engine#44469)
2023-08-09 xty50337@hotmail.com [web] Fix rendering of gradients in html mode (flutter/engine#40345)
2023-08-09 55360120+Matt2D@users.noreply.github.com Flutter iOS Interactive Keyboard: Fixing Animation Issue (flutter/engine#44514)
2023-08-09 skia-flutter-autoroll@skia.org Roll Skia from 8c9a8d3e073c to 3d5a6138b7e5 (4 revisions) (flutter/engine#44557)
2023-08-09 skia-flutter-autoroll@skia.org Roll Skia from d210bab77137 to 8c9a8d3e073c (1 revision) (flutter/engine#44555)
2023-08-09 skia-flutter-autoroll@skia.org Roll Skia from 25aedb939915 to d210bab77137 (2 revisions) (flutter/engine#44550)
2023-08-09 skia-flutter-autoroll@skia.org Roll Fuchsia Mac SDK from e7bMhkfY-RPMrSMhB... to zoCGnScKZWbm5s9Hy... (flutter/engine#44548)
2023-08-09 skia-flutter-autoroll@skia.org Roll Skia from 17ba2122707b to 25aedb939915 (3 revisions) (flutter/engine#44547)
2023-08-09 47866232+chunhtai@users.noreply.github.com Android a11y bridge sets importantness (flutter/engine#44452)
2023-08-09 skia-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from tO6r8iQqnmsYkLcvZ... to ZCP8LDbKF4LTBFz_W... (flutter/engine#44545)

Also rolling transitive DEPS:
  fuchsia/sdk/core/linux-amd64 from tO6r8iQqnmsY to ZCP8LDbKF4LT
  fuchsia/sdk/core/mac-amd64 from e7bMhkfY-RPM to zoCGnScKZWbm

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC chinmaygarde@google.com,rmistry@google.com,zra@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
gaaclarke pushed a commit to gaaclarke/engine that referenced this pull request Aug 30, 2023
![CleanShot 2023-03-16 at 20 44 01@2x](https://user-images.githubusercontent.com/15033141/225620947-18fe19aa-c5e2-45a5-a0cc-151275844af7.png)

<details>
<summary> Code  Example</summary>

```dart
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class DemoGradientTransform implements GradientTransform {
  @OverRide
  Matrix4? transform(Rect bounds, {TextDirection? textDirection}) {
    return Matrix4.identity()
      ..scale(1.2, 1.7)
      ..rotateZ(0.25);
  }
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @OverRide
  Widget build(BuildContext context) {
    var colors = <Color>[
      Colors.red,
      Colors.green,
      Colors.blue,
      Colors.yellow,
    ];

    const stops = <double>[0.0, 0.25, 0.5, 1.0];

    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: GridView(
        gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
          crossAxisCount: TileMode.values.length,
        ),
        children: <Widget>[
          for (final mode in TileMode.values)
            DecoratedBox(
              decoration: BoxDecoration(
                gradient: LinearGradient(
                  colors: colors,
                  stops: stops,
                  tileMode: mode,
                  transform: DemoGradientTransform(),
                ),
              ),
            ),
          for (final mode in TileMode.values)
            DecoratedBox(
              decoration: BoxDecoration(
                gradient: RadialGradient(
                  center: Alignment.topLeft,
                  radius: 0.5,
                  colors: colors,
                  stops: stops,
                  tileMode: mode,
                  transform: DemoGradientTransform(),
                ),
              ),
            ),
          for (final mode in TileMode.values)
            DecoratedBox(
              decoration: BoxDecoration(
                gradient: SweepGradient(
                  center: Alignment.topLeft,
                  startAngle: 0.0,
                  endAngle: 3.14,
                  colors: colors,
                  stops: stops,
                  tileMode: mode,
                  transform: DemoGradientTransform(),
                ),
              ),
            ),
        ],
      ),
    );
  }
}
```
</details>

Fixes: flutter/flutter#84245
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 needs tests platform-web Code specifically for the web engine will affect goldens
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LinearGradient transform parameter not applied on web version
5 participants