Skip to content

Impeller MaskFilter.blur isn't invariant over scale transforms #152778

@Hixie

Description

@Hixie

When drawing a blurred circle whose radius and blur sigma are scaled inversely with the scale applied to the canvas, one would expect a more or less identical result regardless of the scale. This works with Skia, however, with Impeller, there are significant discontinuities with the applied blur.

Sample code
import 'dart:async';

import 'package:flutter/material.dart';

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

class Test extends StatefulWidget {
  const Test({super.key});

  @override
  State<Test> createState() => _TestState();
}

class _TestState extends State<Test> {
  Timer? _timer;
  double _x = 1.0;
  
  @override
  void initState() {
    super.initState();
    _timer = Timer.periodic(const Duration(milliseconds: 200), _update);
  }

  void _update(Timer timer) {
    setState(() {
      _x *= 10;
      if (_x > 1e20) {
        _x = 1e-20;
      }
    });
  }
  
  @override
  void dispose() {
    _timer?.cancel();
    super.dispose();
  }
  
  @override
  Widget build(BuildContext context) {
    return Stack(
      textDirection: TextDirection.ltr,
      children: [
        CustomPaint(
          painter: Painter(_x),
        ),
        Positioned(
          top: 60.0,
          left: 20.0,
          child: Text(_x.toStringAsExponential(1), textDirection: TextDirection.ltr),
        ),
      ],
    );
  }
}

class Painter extends CustomPainter {
  Painter(this.x);

  final double x;
  
  @override
  void paint(Canvas canvas, Size size) {
    canvas.scale(1.0 / x);
    final Paint paint = Paint()
      ..color = const Color(0xFF66BBFF)
      ..maskFilter = MaskFilter.blur(BlurStyle.normal, 100.0 * x);
    canvas.drawCircle(Offset.zero, 500 * x, paint);
  }

  @override
  bool shouldRepaint(Painter oldDelegate) => x != oldDelegate.x;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work liste: impellerImpeller rendering backend issues and features requeststeam-engineOwned by Engine teamtriaged-engineTriaged by Engine team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions