Skip to content

[Impeller] drawing path with image shader is not correct #127183

@ColdPaleLight

Description

@ColdPaleLight

Is there an existing issue for this?

Steps to reproduce

run the sample code on master channel

Expected results

See part of an owl in a pentagon

Actual results

Pentagons are approximately pure colors

Code sample

Code sample
import 'dart:async';
import 'dart:math';
import 'dart:ui' as ui;
import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: FutureBuilder<ui.Image>(
          future: _loadImage('https://flutter.github.io/assets-for-api-docs/assets/widgets/owl.jpg'),
          builder: (BuildContext context, AsyncSnapshot<ui.Image> snapshot) {
            if (snapshot.hasData) {
              return CustomPaint(
                painter: StarPainter(snapshot.data!),
                child: Container(),
              );
            } else {
              return Center(child: CircularProgressIndicator());
            }
          },
        ),
      ),
    );
  }

  Future<ui.Image> _loadImage(String imageUrl) async {
    var completer = Completer<ImageInfo>();
    var img = NetworkImage(imageUrl);
    img.resolve(const ImageConfiguration()).addListener(ImageStreamListener((info, _) {
      completer.complete(info);
    }));
    ImageInfo imageInfo = await completer.future;
    return imageInfo.image;
  }

}

class StarPainter extends CustomPainter {
  final ui.Image image;

  StarPainter(this.image);

  @override
  void paint(Canvas canvas, Size size) {
    final paint = Paint();
    paint.shader = ImageShader(image, TileMode.repeated, TileMode.repeated, Matrix4.identity().storage);

    final path = Path();
    final radius = size.width / 2;
    final angle = 2 * 3.1416 / 5;
    Offset center = Offset(size.width / 2, size.height / 2);

    for (int i = 0; i <= 5; i++) {
      final currentAngle = angle * i - 3.1416 / 2;
      final pointX = center.dx + radius * cos(currentAngle);
      final pointY = center.dy + radius * sin(currentAngle);

      if (i == 0) {
        path.moveTo(pointX, pointY);
      } else {
        path.lineTo(pointX, pointY);
      }
    }

    path.close();

    canvas.drawPath(path, paint);
  }

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

Screenshots or Video

Screenshots / Video demonstration

expect

IMG_0056

actual

IMG_0055

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[✓] Flutter (Channel master, 3.11.0-6.0.pre.157, on macOS 13.0.1 22A400 darwin-arm64 (Rosetta), locale zh-Hans-CN)
    • Flutter version 3.11.0-6.0.pre.157 on channel master at /Users/z/Develop/upstream/flutter
    • Upstream repository [email protected]:flutter/flutter.git
    • Framework revision 2f299f2aa7 (2 hours ago), 2023-05-19 04:58:38 -0400
    • Engine revision 5a57ff52f0
    • Dart version 3.1.0 (build 3.1.0-126.0.dev)
    • DevTools version 2.23.1
    • Pub download mirror https://dart-pub.byted.org

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at /Users/z/Library/Android/sdk
    • Platform android-33, build-tools 33.0.0
    • ANDROID_HOME = /Users/z/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

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

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

[✓] Android Studio (version 2021.3)
    • Android Studio at /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 11.0.13+0-b1751.21-8125866)

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

[✓] Connected device (3 available)
    • iPhone SE (2nd generation) (mobile) • 00008030-0018042E2E46802E • ios            • iOS 15.0 19A346
    • macOS (desktop)                     • macos                     • darwin-arm64   • macOS 13.0.1 22A400 darwin-arm64 (Rosetta)
    • Chrome (web)                        • chrome                    • web-javascript • Google Chrome 113.0.5672.126

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

• No issues found!

Metadata

Metadata

Assignees

Labels

e: impellerImpeller rendering backend issues and features requests

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions