-
Notifications
You must be signed in to change notification settings - Fork 6k
[Impeller] match rrect_blur math to the gaussian math #53130
[Impeller] match rrect_blur math to the gaussian math #53130
Conversation
When we land this we should revisit the math for the rrect_blur halo since we should be able to make it even more constricted. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beautiful!
How do either of those 2 results compare to our legacy behavior on these shapes? |
The guassian blur matches skia's blur. That work happened here: #47405 |
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. |
That's not what I'm seeing on the current ToT - the fast blur matches Skia, not the other way around: test program
|
Oh interesting, #53130 was working with larger sigmas. Yet sigma 50 is super blurry. There is obviously some issue with dpi that needs to be resolved. I'm going to move this back to a draft as we sort through this. |
This is the framework commit that I was running against:
|
This pull request has been changed to a draft. The currently pending flutter-gold status will not be able to resolve until a new commit is pushed or the change is marked ready for review again. |
In |
I verified that the gaussian blur still looks correct for the reproduction code for issue flutter/flutter#127770. That has 164 for a sigma. But setting the sigma to 50 we see the same thing jim saw skia sigma = 164impeller sigma = 164skia sigma = 50impeller sigma = 50doctor
|
I modified my test case to do 4 columns
Note that I adjust the RRect and Path geometry to counter-act the scale so that they will be the same size shape in both cases, but the blur will be scaled. The left pair should look the same with about 1/2 the blurring compared to the right pair. As you can see, the blurring changes size for the RRect fast path version, but not for the Path (gaussian) version, confirming that the gaussian path is ignoring the transform for the sigma... (Updated the test case - I forgot to adjust the corner size for the fast RRect case - fixed now) New test codeimport 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
Widget makeRow(double cornerSize, double blurSize) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
CustomPaint(
painter: _RRectPainter(
cornerSize: cornerSize,
blurSize: blurSize,
scale: 0.5,
),
size: const Size(150, 150),
),
CustomPaint(
painter: _RRectPathPainter(
cornerSize: cornerSize,
blurSize: blurSize,
scale: 0.5,
),
size: const Size(150, 150),
),
CustomPaint(
painter: _RRectPainter(
cornerSize: cornerSize,
blurSize: blurSize,
scale: 1.0,
),
size: const Size(150, 150),
),
CustomPaint(
painter: _RRectPathPainter(
cornerSize: cornerSize,
blurSize: blurSize,
scale: 1.0,
),
size: const Size(150, 150),
),
],
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
makeRow(10, 10),
makeRow(10, 30),
makeRow(10, 50),
],
),
),
);
}
}
class _RRectPainter extends CustomPainter {
_RRectPainter({required this.cornerSize, required this.blurSize, required this.scale});
final double cornerSize;
final double blurSize;
final double scale;
@override
void paint(Canvas canvas, Size size) {
canvas.scale(scale, scale);
double w = size.width / scale;
double h = size.height / scale;
double c = cornerSize / scale;
Rect rect = Rect.fromLTRB(0, 0, w, h);
RRect rrect = RRect.fromRectXY(rect, c, c);
Paint paint = Paint()
..maskFilter = MaskFilter.blur(BlurStyle.normal, blurSize)
..color = Colors.blue;
canvas.drawRRect(rrect, paint);
}
@override
bool shouldRepaint(covariant CustomPainter oldDelegate) => true;
}
class _RRectPathPainter extends CustomPainter {
_RRectPathPainter({required this.cornerSize, required this.blurSize, required this.scale});
final double cornerSize;
final double blurSize;
final double scale;
@override
void paint(Canvas canvas, Size size) {
canvas.scale(scale, scale);
double w = size.width / scale;
double h = size.height / scale;
double c = cornerSize / scale;
Path path = Path();
path.addRect(Rect.fromLTRB(c, 0, w - c, h));
path.addRect(Rect.fromLTRB(0, c, w, h - c));
path.addOval(Rect.fromLTRB(0, 0, c * 2, c * 2));
path.addOval(Rect.fromLTRB(w - c * 2, 0, w, c * 2));
path.addOval(Rect.fromLTRB(0, h - c * 2, c * 2, h));
path.addOval(Rect.fromLTRB(w - c * 2, h - c * 2, w, h));
Paint paint = Paint()
..maskFilter = MaskFilter.blur(BlurStyle.normal, blurSize)
..color = Colors.blue;
canvas.drawPath(path, paint);
}
@override
bool shouldRepaint(covariant CustomPainter oldDelegate) => true;
} |
These 2 do not look the same to me. The Skia version is much blurrier than the Impeller version. I can still see the basic approximate shape in the Impeller version, but the Skia version is much more obscured.
|
Yea, they're not going to be the same. Check out flutter/flutter#127770 to see what incorrect looks like. |
Okay, I found the bug in the gaussian blur. We were scaling the sigma by the effect transform, but not the entity's transform. That made the rrect_blur and gaussian blur match so I could remove that 0.5 scalar from rrect_blur. I've also added a new golden that shows they are the same when scaled too. I still need to make sure that we are still good for that issue against 164 sigma and also make sure that the golden images are correct. |
With the most recent change, here is skia vs impeller with flutter/flutter#127770. Although they appear to agree they seem much more dissipated than in the expected result in the original bug. skiaimpeller |
Okay, the golden results look as expected. This is ready for review again. The bug was missing the entity transform when scaling the blur sigma. PTAL. |
Golden file changes are available for triage from new commit, Click here to view. |
The 2 new images for 164 look similar, but they are so big it's hard to eyeball them due to having to scroll back and forth... |
impeller/entity/contents/filters/gaussian_blur_filter_contents.cc
Outdated
Show resolved
Hide resolved
impeller/entity/contents/filters/gaussian_blur_filter_contents.cc
Outdated
Show resolved
Hide resolved
impeller/entity/contents/filters/gaussian_blur_filter_contents_unittests.cc
Show resolved
Hide resolved
Golden file changes are available for triage from new commit, Click here to view. |
This PR makes the halo the match the rrect_blur size, but it seems to also be diluting the blur as seen in flutter/flutter#149431 (comment) |
499477a
to
82a120b
Compare
I mistakenly took out the effect transform from the calculation of blur radius. I thought that was included in the entity transform, it turns out it wasn't. |
Golden file changes are available for triage from new commit, Click here to view. |
Golden file changes are available for triage from new commit, Click here to view. |
…149658) flutter/engine@a6aa5d8...e211c43 2024-06-04 skia-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from lKBLxel8iBaHpT5q6... to pagJoGS4kQ8Efa_if... (flutter/engine#53192) 2024-06-04 98614782+auto-submit[bot]@users.noreply.github.com Reverts "[display_list] allow applying opacity peephole to single glyph. (#53160)" (flutter/engine#53189) 2024-06-04 skia-flutter-autoroll@skia.org Roll Dart SDK from 49b5590c8d80 to 9dce57c343ec (1 revision) (flutter/engine#53187) 2024-06-04 jonahwilliams@google.com [Impeller] Use varying interpolation to compute some linear gradients. (flutter/engine#53166) 2024-06-03 30870216+gaaclarke@users.noreply.github.com [Impeller] match rrect_blur math to the gaussian math (flutter/engine#53130) 2024-06-03 ditman@gmail.com [web] Add Ethiopic font fallback. (flutter/engine#53180) 2024-06-03 robert.ancell@canonical.com Fix rendering corruption by Flutter and GDK sharing the same OpenGL context (flutter/engine#53103) 2024-06-03 jonahwilliams@google.com [display_list] allow applying opacity peephole to single glyph. (flutter/engine#53160) Also rolling transitive DEPS: fuchsia/sdk/core/linux-amd64 from lKBLxel8iBaH to pagJoGS4kQ8E 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 matanl@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://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
…3261) fixes flutter/flutter#149781 fixes flutter/flutter#149458 fixes flutter/flutter#140890 This works by performing the blur in the axis aligned "source space" (as opposed to "global space"). The rotation and scaling then is applied to the result of the gaussian blur. Previously the differences between rrect_blur and gaussian blur were "fixed" in #53130 which worked for blurring content that had no signal. This addresses that same problem but in a more correct way that is less prone to artifacts when translating a blur since the blur happens in "source space". [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
fixes flutter/flutter#149276
before
after
Pre-launch Checklist
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.