Skip to content

[Impeller] When painting with a MaskFilter, subsequent calls to drawVertices use the same MaskFilter #170480

@luccasclezar

Description

@luccasclezar

Steps to reproduce

  1. Call canvas.drawRect with a Paint that uses a MaskFilter
  2. Call canvas.drawVertices with another paint that does not use a MaskFilter
  3. Run the app on Impeller (Skia doesn't have this issue)

Expected results

The rect is painted with a MaskFilter, the vertices are not.

Actual results

Both the rect and the vertices are painted with the same MaskFilter.

Code sample

I've added a Switch in the sample to toggle the MaskFilter, this way it's possible to verify that the filter is actually what's causing the issue.

Code sample
class MainApp extends StatefulWidget {
  const MainApp({super.key});

  @override
  State<MainApp> createState() => _MainAppState();
}

class _MainAppState extends State<MainApp> {
  bool renderShadow = true;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            SwitchListTile(
              value: renderShadow,
              onChanged: (value) => setState(() => renderShadow = value),
              title: const Text('Render Shadow'),
            ),
            CustomPaint(
              painter: TwoRectsPainter(renderShadow: renderShadow),
              size: Size(200, 200),
            ),
          ],
        ),
      ),
    );
  }
}

class TwoRectsPainter extends CustomPainter {
  TwoRectsPainter({this.renderShadow = true});

  final bool renderShadow;

  @override
  void paint(Canvas canvas, Size size) {
    final paint1 = Paint()
      ..color = Colors.black45
      ..style = PaintingStyle.fill;

    if (renderShadow) {
      paint1.maskFilter = MaskFilter.blur(BlurStyle.outer, 10.0);

      // Changing maskFilter to imageFilter fixes the issue.
      // paint1.imageFilter = ImageFilter.blur(sigmaX: 10.0, sigmaY: 10.0);
    }

    final paint2 = Paint()
      ..color = Colors.red
      ..style = PaintingStyle.fill;

    // First rectangle (top-left)
    canvas.drawRect(Rect.fromLTWH(100, 80, 100, 80), paint1);

    // Second rectangle (bottom-right)
    canvas.drawVertices(createVertices(), BlendMode.dst, paint2);
  }

  Vertices createVertices() {
    final vertices = Vertices.raw(
      VertexMode.triangles,
      Float32List.fromList([0, 0, 100, 0, 100, 80, 0, 0, 100, 80, 0, 80]),
    );
    return vertices;
  }

  @override
  bool shouldRepaint(covariant CustomPainter oldDelegate) =>
      oldDelegate is TwoRectsPainter &&
      oldDelegate.renderShadow != renderShadow;
}

Screenshots or Video

Screenshots / Video demonstration
Expected result Actual result
Image Image

Logs

Logs

Flutter Doctor output

Doctor output
[√] Flutter (Channel master, 3.33.0-1.0.pre.458, on Microsoft Windows [Version 10.0.26100.4061], locale en-150) [2.7s]
    • Flutter version 3.33.0-1.0.pre.458 on channel master at C:\dev\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision a4a2ef6d1e (2 hours ago), 2025-06-11 20:50:54 +0200
    • Engine revision a4a2ef6d1e
    • Dart version 3.9.0 (build 3.9.0-220.0.dev)
    • DevTools version 2.48.0-dev.0

[√] Windows Version (11 Pro 64-bit, 24H2, 2009) [2.8s]

[√] Android toolchain - develop for Android devices (Android SDK version 35.0.0) [2.3s]
    • Android SDK at C:\dev\AndroidSDK\
    • Emulator version 35.2.10.0 (build_id 12414864) (CL:N/A)
    • Platform android-36, build-tools 35.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
      This is the JDK bundled with the latest Android Studio installation on this machine.
      To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment (build 21.0.3+-12282718-b509.11)
    • All Android licenses accepted.

[√] Chrome - develop for the web [84ms]
    • CHROME_EXECUTABLE = C:\Program Files\Google\Chrome Beta\Application\chrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.12.3) [84ms]
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.12.35527.113
    • Windows 10 SDK version 10.0.22621.0

[√] Android Studio (version 2024.2) [16ms]
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 21.0.3+-12282718-b509.11)

[√] VS Code, 64-bit edition (version 1.100.2) [15ms]
    • VS Code at C:\Program Files\Microsoft VS Code
    • Flutter extension version 3.112.0

[√] Connected device (4 available) [302ms]
    • sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64    • Android 15 (API 35) (emulator)
    • Windows (desktop)            • windows       • windows-x64    • Microsoft Windows [Version 10.0.26100.4061]
    • Chrome (web)                 • chrome        • web-javascript • unknown
    • Edge (web)                   • edge          • web-javascript • Microsoft Edge 137.0.3296.68

[√] Network resources [572ms]
    • All expected network resources are available.

• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    e: impellerImpeller rendering backend issues and features requestsengineflutter/engine related. See also e: labels.found in release: 3.32Found to occur in 3.32found in release: 3.33Found to occur in 3.33has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-androidAndroid applications specificallyplatform-iosiOS applications specificallyr: fixedIssue is closed as already fixed in a newer versionteam-engineOwned by Engine team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions