Skip to content

[Flutter Web] Incorrect render result when having the nested same mask-filter #133443

@Kingtous

Description

@Kingtous

Is there an existing issue for this?

Steps to reproduce

  1. clone this repo https://github.com/Kingtous/dora_demo with branch bug/same_mask_filter
  2. flutter run -d chrome --renderer html
  3. see the bug

Expected results

Which the canvaskit does.

Actual results

the nested filter seems disappeared when having the same blur value.

image

Code sample

Code sample
import 'dart:math';
import 'dart:typed_data';

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'dart:ui' as ui;
import 'dart:js' as js;
final isCanvasKit = js.context['flutterCanvasKit'] != null;

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

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

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: Stack(
        children: [
          Home(),
        ],
      ),
    );
  }
}

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

  @override
  State<Home> createState() => _HomeState();
}

class _HomeState extends State<Home> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: Colors.black,
        body: Center(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text(isCanvasKit? 'CanvasKit' : 'HTML', style: TextStyle(
                color: Colors.white
              ),),
              Container(
                decoration: BoxDecoration(
                    color: Colors.white,
                    border: Border.all(color: Colors.yellow, width: 8.0)),
                child: Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: SizedBox(
                      width: 300,
                      height: 300,
                      child: RepaintBoundary(
                        child: CustomPaint(
                          painter: NestPainter(),
                        ),
                      )),
                ),
              ),
            ],
          ),
        ));
  }
}

class NestPainter extends CustomPainter {
  @override
  void paint(Canvas canvas, Size size) {
    final p = Paint();
    final r = Rect.fromLTWH(0, 0, size.width, size.height);
    canvas.save();
    canvas.clipRect(r);
    canvas.drawRect(
        r,
        p
          ..color = Colors.red
          ..maskFilter = MaskFilter.blur(BlurStyle.normal, 20));
    canvas.restore();

    canvas.save();
    canvas.clipRect(r);
    canvas.drawRect(
        r.translate(0, 50),
        p
          ..color = Colors.blue
          ..maskFilter = MaskFilter.blur(BlurStyle.normal, 20));
    // canvas.saveLayer(null, p);
    canvas.restore();
    // canvas.drawRect(
    //     r.translate(50, 50),
    //     p
    //       ..color = Colors.blue
    //       ..maskFilter = MaskFilter.blur(BlurStyle.inner, 0));
    // canvas.restore();
  }

  @override
  bool shouldRepaint(covariant CustomPainter oldDelegate) {
    return true;
  }
}

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
nothing here.
![image](https://github.com/flutter/flutter/assets/39793325/807b06c0-9bd3-4700-b635-3fa7fe076749)

Flutter Doctor output

Doctor output
$ flutter doctor -v
[✓] Flutter (Channel stable, 3.10.3, on macOS 13.5.1
    22G90 darwin-x64, locale zh-Hans-CN)
    • Flutter version 3.10.3 on channel stable at
      /Users/kingtous/flutter
    • Upstream repository
      https://github.com/flutter/flutter.git
    • Framework revision f92f44110e (3 months ago),
      2023-06-01 18:17:33 -0500
    • Engine revision 2a3401c9bb
    • Dart version 3.0.3
    • DevTools version 2.23.1
    • Pub download mirror https://pub.flutter-io.cn
    • Flutter download mirror
      https://storage.flutter-io.cn

[✓] Android toolchain - develop for Android devices          (Android SDK version 33.0.2)
    • Android SDK at /Users/kingtous/Library/Android/sdk
    • Platform android-33, build-tools 33.0.2
    • Java binary at: /usr/local/opt/openjdk@11/bin/java
    • Java version OpenJDK Runtime Environment Homebrew
      (build 11.0.20+0)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.3.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14E300c
    • CocoaPods version 1.12.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google
      Chrome.app/Contents/MacOS/Google Chrome

[!] Android Studio
    • Android Studio at
      /Users/kingtous/Library/Application
      Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/2
      22.4459.24.2221.9526055/Android Studio
      Preview.app/Contents
    • 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
    ✗ Unable to find bundled Java version.
    • Try updating or re-installing Android Studio.

[✓] VS Code (version 1.81.1)
    • VS Code at /Applications/Visual Studio
      Code.app/Contents
    • Flutter extension version 3.70.0

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-x64     • macOS
      13.5.1 22G90 darwin-x64
    • Chrome (web)    • chrome • web-javascript • Google
      Chrome 116.0.5845.110

Metadata

Metadata

Assignees

No one assigned

    Labels

    r: duplicateIssue is closed as a duplicate of an existing issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions