Skip to content

[Impeller] Validation errors and no output for saveLayer with drawPaint #135766

@flar

Description

@flar

I discovered this while updating the DL rendering tests to render with Impeller. There appears to be a coverage bounds calculation gone awry in this case. My suspicion is this line of code which looks like it is missing a ! on the translation test:

https://github.com/flutter/engine/blob/48973d7f9bebaa5f850e35a75b2549c2534c3e95/impeller/entity/entity_pass.cc#L205

(Patching the missing ! on top of my Impeller test harness update indeed eliminates the problem).

sample code
import 'dart:ui' as ui;

import '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: 'SaveLayer DrawPaint issue'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: SizedBox(
          width: 200,
          height: 200,
          child: CustomPaint(
            painter: _MyPainter(),
          ),
        ),
      ),
    );
  }
}

class _MyPainter extends CustomPainter {
  @override
  void paint(Canvas canvas, Size size) {
    Paint savePaint = Paint()
      ..imageFilter = ui.ImageFilter.blur(sigmaX: 5, sigmaY: 5);
    canvas.saveLayer(null, savePaint);
    Paint paint = Paint()
      ..shader = ui.Gradient.linear(
        Offset.zero,
        const Offset(2, 2),
        <Color>[
          Colors.blue,
          Colors.green,
        ],
        null,
        TileMode.mirror,
      );
    canvas.drawPaint(paint);
    canvas.restore();
  }

  @override
  bool shouldRepaint(covariant CustomPainter oldDelegate) => true;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    e: impellerImpeller rendering backend issues and features requestsengineflutter/engine related. See also e: labels.

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions