Cheaper frosted-glass blurs: sigma 4 and one backdrop read per bar
Blur sigma 16 -> 4 keeps CanvasKit on its direct blur path; under the 84% fill the look is unchanged (max 13/255 inside the pieces). SegmentedBar's pieces share a BackdropGroup so Impeller reads the content behind them once. Adds a scroll frame-time bench, a backdrop census and filler rows to the full-app probe. CPU CanvasKit, 560x900: run timeline p50 31.8 -> 22.1 ms, runs list 25.3 -> 19.9 ms.
This commit is contained in:
@@ -31,7 +31,12 @@ class GlassPill extends StatelessWidget {
|
||||
final Color? fill;
|
||||
|
||||
/// Blur radius of the content behind a piece.
|
||||
static const double blurSigma = 16;
|
||||
///
|
||||
/// Under the [fillOpacity] fill, 4 looks the same as a larger radius (the
|
||||
/// content behind is already an indistinct tint) and stays on the
|
||||
/// renderer's direct blur path: above about 4, Skia (CanvasKit) downscales,
|
||||
/// blurs and upscales every piece on every frame content scrolls behind it.
|
||||
static const double blurSigma = 4;
|
||||
|
||||
/// How much of the fill covers the blurred content.
|
||||
static const double fillOpacity = 0.84;
|
||||
@@ -65,8 +70,10 @@ class GlassPill extends StatelessWidget {
|
||||
: Material(type: MaterialType.transparency, child: child),
|
||||
);
|
||||
if (!solid) {
|
||||
// One blur per piece, clipped to it.
|
||||
surface = BackdropFilter(
|
||||
// One blur per piece, clipped to it. Pieces under a common
|
||||
// [BackdropGroup] (a bar's row) share one read of the content behind
|
||||
// them where the engine supports it (Impeller) instead of one each.
|
||||
surface = BackdropFilter.grouped(
|
||||
filter: ImageFilter.blur(sigmaX: blurSigma, sigmaY: blurSigma),
|
||||
child: surface,
|
||||
);
|
||||
|
||||
@@ -163,6 +163,12 @@ class _SegmentedBarState extends State<SegmentedBar> {
|
||||
final _titleLink = LayerLink();
|
||||
final _expandedTitle = OverlayPortalController();
|
||||
|
||||
/// The row's pieces sit side by side, so they share one read of the
|
||||
/// content behind them. The expanded title overlaps the content below the
|
||||
/// bar and is drawn later, in the overlay, so it reads its own.
|
||||
final _piecesBackdrop = BackdropKey();
|
||||
final _expandedTitleBackdrop = BackdropKey();
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant SegmentedBar oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
@@ -269,7 +275,10 @@ class _SegmentedBarState extends State<SegmentedBar> {
|
||||
constraints: BoxConstraints(
|
||||
maxWidth: titleSpace.maxWidth,
|
||||
),
|
||||
child: titlePill(true),
|
||||
child: BackdropGroup(
|
||||
backdropKey: _expandedTitleBackdrop,
|
||||
child: titlePill(true),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -365,7 +374,7 @@ class _SegmentedBarState extends State<SegmentedBar> {
|
||||
),
|
||||
child: MediaQuery.withClampedTextScaling(
|
||||
maxScaleFactor: SegmentedBar.maxTextScale,
|
||||
child: bar,
|
||||
child: BackdropGroup(backdropKey: _piecesBackdrop, child: bar),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user