Skip to content

[Impeller] CustomPaint cannot use ImageShader with TileMode.clamp #128328

@Erfa

Description

@Erfa

Is there an existing issue for this?

Steps to reproduce

  1. Create a CustomPainter
  2. Draw a path painted with an ImageShader
  3. Set the TileMode to TileMode.clamp in both dimensions
  4. Apply a translation transform

Expected results

The image is painted with the given translation, parts outside of the image are clamped.

Actual results

With Impeller, just a single color is painted on the canvas. Without Impeller the translation and clamp is applied as expected.

Code sample

Code sample
import 'dart:ui' as ui;

import 'package:flutter/foundation.dart';
import "package:flutter/material.dart";
import 'package:http/http.dart' as http;

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

class MyPainter extends CustomPainter {
  final ui.Image image;

  MyPainter({required this.image});

  @override
  void paint(Canvas canvas, Size size) {
    Matrix4 transform = Matrix4.identity();
    transform.translate(128.0, 128.0);

    canvas.drawPath(
      Path()
        ..moveTo(0, 0)
        ..lineTo(0, 256)
        ..lineTo(256, 256)
        ..lineTo(256, 0),
      Paint()
        ..shader = ui.ImageShader(
          image,
          TileMode.clamp,
          TileMode.clamp,
          Float64List.fromList(transform.storage),
        ),
    );
  }

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

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

  @override
  Widget build(BuildContext context) => MaterialApp(
        theme: ThemeData.light(),
        home: Scaffold(
          appBar: AppBar(),
          body: SizedBox.square(
            dimension: 256,
            child: FutureBuilder<ui.Image>(
              future: http
                  .get(Uri.parse("https://picsum.photos/256/256"))
                  .then((resp) => decodeImageFromList(resp.bodyBytes)),
              builder: (context, snapshot) {
                final data = snapshot.data;
                if (data == null) return Container();
                return CustomPaint(
                  painter: MyPainter(image: data),
                );
              },
            ),
          ),
        ),
      );
}

Screenshots or Video

Screenshots / Video demonstration
Impeller No Impeller
impeller no-enable-impeller

Logs

Logs
> flutter run --enable-impeller
Launching lib\main.dart on SM G970F in debug mode...
Running Gradle task 'assembleDebug'...                           1,474ms
√  Built build\app\outputs\flutter-apk\app-debug.apk.
E/flutter ( 9218): [ERROR:flutter/shell/platform/android/android_surface_gl_impeller.cc(78)] Using the Impeller rendering 
backend.
Syncing files to device SM G970F...                                 53ms

Flutter run key commands.
r Hot reload. 
R Hot restart.
h List all available interactive commands.
d Detach (terminate "flutter run" but leave application running).       
c Clear the screen
q Quit (terminate the application on the device).

A Dart VM Service on SM G970F is available at: http://127.0.0.1:57184/N994m1Mrw88=/
The Flutter DevTools debugger and profiler on SM G970F is available at:
http://127.0.0.1:9107?uri=http://127.0.0.1:57184/N994m1Mrw88=/
I/Gralloc4( 9218): mapper 4.x is not supported   
W/Gralloc3( 9218): mapper 3.x is not supported   
I/gralloc ( 9218): Arm Module v1.0
W/Gralloc4( 9218): allocator 4.x is not supported
W/Gralloc3( 9218): allocator 3.x is not supported
D/ViewRootImpl@da01bb0[MainActivity]( 9218): Creating frameDrawingCallback nextDrawUseBlastSync=false reportNextDraw=true 
hasBlurUpdates=false
D/ViewRootImpl@da01bb0[MainActivity]( 9218): Creating frameCompleteCallback
I/SurfaceView@a1c3f7b( 9218): uSP: rtp = Rect(0, 0 - 1080, 2235) rtsw = 1080 rtsh = 2235
I/SurfaceView@a1c3f7b( 9218): onSSPAndSRT: pl = 0 pt = 0 sx = 1.0 sy = 1.0
I/SurfaceView@a1c3f7b( 9218): aOrMT: uB = true t = android.view.SurfaceControl$Transaction@418c10d fN = 1 android.view.SurfaceView.access$500:124 android.view.SurfaceView$SurfaceViewPositionUpdateListener.positionChanged:1728 android.graphics.RenderNode$CompositePositionUpdateListener.positionChanged:319 
I/SurfaceView@a1c3f7b( 9218): aOrMT: vR.mWNT, vR = ViewRootImpl@da01bb0[MainActivity]
I/ViewRootImpl@da01bb0[MainActivity]( 9218): mWNT: t = android.view.SurfaceControl$Transaction@418c10d fN = 1 android.view.SurfaceView.applyOrMergeTransaction:1628 android.view.SurfaceView.access$500:124 android.view.SurfaceView$SurfaceViewPositionUpdateListener.positionChanged:1728
I/ViewRootImpl@da01bb0[MainActivity]( 9218): mWNT: merge t to BBQ
D/ViewRootImpl@da01bb0[MainActivity]( 9218): Received frameDrawingCallback frameNum=1. Creating transactionCompleteCallback=false
D/ViewRootImpl@da01bb0[MainActivity]( 9218): Received frameCompleteCallback  lastAcquiredFrameNum=1 lastAttemptedDrawFrameNum=1
I/ViewRootImpl@da01bb0[MainActivity]( 9218): [DP] pdf(0) 1 android.view.ViewRootImpl.lambda$addFrameCompleteCallbackIfNeeded$3$ViewRootImpl:5000 android.view.ViewRootImpl$$ExternalSyntheticLambda16.run:6 android.os.Handler.handleCallback:938   
I/ViewRootImpl@da01bb0[MainActivity]( 9218): [DP] rdf()
D/ViewRootImpl@da01bb0[MainActivity]( 9218): reportDrawFinished (fn: -1)
I/ViewRootImpl@da01bb0[MainActivity]( 9218): MSG_WINDOW_FOCUS_CHANGED 1 1
D/InputMethodManager( 9218): startInputInner - Id : 0
I/InputMethodManager( 9218): startInputInner - mService.startInputOrWindowGainedFocus
D/InputMethodManager( 9218): startInputInner - Id : 0

Flutter Doctor output

Doctor output
[√] Flutter (Channel stable, 3.10.3, on Microsoft Windows [Version 10.0.19044.2965], locale en-SE)
    • Flutter version 3.10.3 on channel stable at E:\projects\apps\flutter 
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision f92f44110e (5 days ago), 2023-06-01 18:17:33 -0500
    • Engine revision 2a3401c9bb
    • Dart version 3.0.3
    • DevTools version 2.23.1

[√] Windows Version (Installed version of Windows is version 10 or higher) 

[√] Android toolchain - develop for Android devices (Android SDK version 33.0.0)     
    • Android SDK at C:\Users\Erfa\AppData\Local\Android\sdk
    • Platform android-33, build-tools 33.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.12+7-b1504.28-7817840)    
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop for Windows (Visual Studio Build Tools 2022 17.2.6)      
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools
    • Visual Studio Build Tools 2022 version 17.2.32630.192
    • Windows 10 SDK version 10.0.22621.0

[√] Android Studio (version 2021.2)
    • 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 11.0.12+7-b1504.28-7817840)

[√] VS Code (version 1.78.2)
    • VS Code at C:\Users\Erfa\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.66.0

[√] Connected device (4 available)
    • SM G970F (mobile) • RF8N321H6QW • android-arm64  • Android 12 (API 31)
    • Windows (desktop) • windows     • windows-x64    • Microsoft Windows [Version 10.0.19044.2965]
    • Chrome (web)      • chrome      • web-javascript • Google Chrome 113.0.5672.94
    • Edge (web)        • edge        • web-javascript • Microsoft Edge 113.0.1774.50

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

• No issues found!

Metadata

Metadata

Assignees

Labels

e: impellerImpeller rendering backend issues and features requestsengineflutter/engine related. See also e: labels.found in release: 3.10Found to occur in 3.10found in release: 3.11Found to occur in 3.11has reproducible stepsThe issue has been confirmed reproducible and is ready to work on

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions