Skip to content

Canvas.drawImageRect draws incorrectly with BlendMode.screen with Impeller #148213

@blaugold

Description

@blaugold

Steps to reproduce

  1. git clone https://github.com/blaugold/impeller_draw_image_screen_issue
  2. cd impeller_draw_image_screen_issue
  3. flutter run (on a real iOS device)
  4. Image is drawn incorrectly with BlendMode.screen
  5. In main.dart use BlendMode.srcOver to verify what is the expected result

Expected results

IMG_0198

Actual results

IMG_0199

Code sample

Code sample
import 'dart:ui' as ui;

import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  final imageData = await rootBundle.load('asset/flash.webp');
  final image = await decodeImageFromList(Uint8List.sublistView(imageData));

  runApp(
    Builder(
      builder: (context) {
        return Center(
          child: CustomPaint(
            painter: _Painter(image),
            size: const Size(200, 200),
          ),
        );
      },
    ),
  );
}

class _Painter extends CustomPainter {
  _Painter(this.image);

  final ui.Image image;

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

  @override
  void paint(Canvas canvas, Size size) {
    canvas.drawImageRect(
      image,
      Rect.fromLTWH(0, 0, image.width.toDouble(), image.height.toDouble()),
      Offset.zero & size / 4,
      // Works as expected
      // Paint()..blendMode = BlendMode.srcOver,
      // Nothing is drawn or with other sizes some
      Paint()..blendMode = BlendMode.screen,
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
flutter doctor -v
[✓] Flutter (Channel master, 3.22.0-28.0.pre.11, on macOS 14.4.1 23E224 darwin-arm64, locale en-US)
    • Flutter version 3.22.0-28.0.pre.11 on channel master at /Users/terwesten/fvm/versions/master
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision b7a9e60850 (5 days ago), 2024-05-08 13:28:00 -0700
    • Engine revision 9cb60de37b
    • Dart version 3.5.0 (build 3.5.0-138.0.dev)
    • DevTools version 2.36.0-dev.5

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/terwesten/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • ANDROID_HOME = /Users/terwesten/Library/Android/sdk
    • Java binary at: /Users/terwesten/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15E204a
    • CocoaPods version 1.15.0

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

[✓] Android Studio (version 2023.3)
    • Android Studio at /Users/terwesten/Applications/Android Studio.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
    • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160)

[✓] IntelliJ IDEA Ultimate Edition (version 2024.1.1)
    • IntelliJ at /Users/terwesten/Applications/IntelliJ IDEA Ultimate.app
    • 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

[✓] IntelliJ IDEA Community Edition (version 2024.1.1)
    • IntelliJ at /Users/terwesten/Applications/IntelliJ IDEA Community Edition.app
    • Flutter plugin version 79.0.3
    • Dart plugin version 241.15989.9

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

[✓] Connected device (5 available)
    • iPhone von Gabriel (mobile)     • 00008130-001C71EC36B8001C            • ios            • iOS 17.4.1 21E236
    • iPhone 15 Pro (mobile)          • 0AB7761A-11F8-46CC-97DB-4A0DB33FCE07 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-17-2 (simulator)
    • macOS (desktop)                 • macos                                • darwin-arm64   • macOS 14.4.1 23E224 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad                • darwin         • macOS 14.4.1 23E224 darwin-arm64
    • Chrome (web)                    • chrome                               • web-javascript • Google Chrome 124.0.6367.202

[✓] Network resources
    • 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.22Found to occur in 3.22has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-iosiOS applications specificallyr: fixedIssue is closed as already fixed in a newer versionteam-engineOwned by Engine teamwaiting for PR to land (fixed)A fix is in flight

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions