Repository: flutter
Issue: Canvas.drawLine with a rotated perspective transform shows artifacts near flat
Labels: framework,engine,dependency: skia,c: rendering,has reproducible steps,P2,found in release: 3.3,found in release: 3.7,team-engine,triaged-engine

<!-- Thank you for using Flutter!

     If you are looking for support, please check out our documentation
     or consider asking a question on Stack Overflow:
      * https://flutter.dev/
      * https://api.flutter.dev/
      * https://stackoverflow.com/questions/tagged/flutter?sort=frequent

     If you have found a bug or if our documentation doesn't have an answer
     to what you're looking for, then fill out the template below. Please read
     our guide to filing a bug first: https://flutter.dev/docs/resources/bug-reports
-->

## Steps to Reproduce

<!-- Please include full steps to reproduce so that we can reproduce the problem. -->

This seems to repro when a `CustomPainter` that uses `drawLine` is in a `Transform` with a perspective matrix rotated such that the canvas is close to flat (near 90° or pi / 2 about the x or y axis).

https://dartpad.dev/?id=8ba56fdffe916070b83dacf03be08e21

This repros on Android and DartPad.

**Expected results:** <!-- what did you want to see? -->
Show a flat line segment, or nothing.
<img width="243" alt="image" src="https://user-images.githubusercontent.com/13222934/208817683-c7e3fa2b-4797-4e81-9e48-bdd3821634c8.png">

**Actual results:** <!-- what did you see? -->
Shows a large shaded area.
<img width="266" alt="image" src="https://user-images.githubusercontent.com/13222934/208817625-73741306-c289-43fb-9c8e-06a74b5d1805.png">

<details>
<summary>Code sample</summary>

<!--
      Please create a minimal reproducible sample that shows the problem
      and attach it below between the lines with the backticks.

      To create it you can use `flutter create bug` command and update the `main.dart` file.

      Alternatively, you can use https://dartpad.dev/
      which is capable of creating and running small Flutter apps.

      Without this we will unlikely be able to progress on the issue, and because of that
      we regretfully will have to close it.
-->

```dart
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:vector_math/vector_math_64.dart';

void main() {
  runApp(
    MaterialApp(
      home: Scaffold(
        body: Transform(
          transform: Matrix4.identity()
            ..setEntry(3, 2, .002)
            ..rotate(Vector3(1, 0, 0), pi / 2 + .001),
          alignment: Alignment.center,
          child: CustomPaint(size: Size.infinite, painter: TestPainter()),
        ),
      ),
    ),
  );
}

class TestPainter extends CustomPainter {
  @override
  void paint(Canvas canvas, Size size) {
    final center = size.center(Offset.zero);
    const offset = Offset(32, 32);
    canvas.drawLine(center - offset, center + offset, Paint());
  }

  @override
  bool shouldRepaint(covariant TestPainter oldDelegate) => true;
}

```

</details>

<details>
  <summary>Logs</summary>

<!--
      Run your application with `flutter run --verbose` and attach all the
      log output below between the lines with the backticks. If there is an
      exception, please see if the error message includes enough information
      to explain how to solve the issue. If there is a crash, please include
      the entirety of the crash log including the backtrace.
-->

<!--
     Run `flutter analyze` and attach any output of that command below.
     If there are any analysis errors, try resolving them before filing this issue.
-->

```
PS C:\Users\imagi\Documents\projects\trip_planner_aquamarine> flutter analyze
Analyzing trip_planner_aquamarine...                                    
No issues found! (ran in 32.2s)
```

<!-- Finally, paste the output of running `flutter doctor -v` here. -->

```
PS C:\Users\imagi\Documents\projects\trip_planner_aquamarine> flutter doctor -v
[!] Flutter (Channel rosswang, 3.7.0-2.0.pre.13, on Microsoft Windows [Version 10.0.22621.674], locale en-US)
    • Flutter version 3.7.0-2.0.pre.13 on channel rosswang at C:\Users\imagi\flutter
    ! Upstream repository git@github.com:AsturaPhoenix/flutter.git is not a standard remote.
      Set environment variable "FLUTTER_GIT_URL" to git@github.com:AsturaPhoenix/flutter.git to dismiss this error.
    • Framework revision 8c81ff7fde (3 weeks ago), 2022-12-02 04:30:14 -0800
    • Engine revision 025aefc7af
    • Dart version 2.19.0 (build 2.19.0-444.0.dev)
    • DevTools version 2.20.0
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.

[√] 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\imagi\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.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[!] Visual Studio - develop for Windows (Visual Studio Community 2019 16.11.16)
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
    • Visual Studio Community 2019 version 16.11.32602.291
    • Windows 10 SDK version 10.0.16299.0
    X Visual Studio is missing necessary components. Please re-run the Visual Studio installer for the "Desktop development with C++" workload, and include these components:      
        MSVC v142 - VS 2019 C++ x64/x86 build tools
         - If there are multiple build tool versions available, install the latest
        C++ CMake tools for Windows
        Windows 10 SDK

[√] Android Studio (version 2021.3)
    • 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.13+0-b1751.21-8125866)

[√] VS Code (version 1.74.1)
    • VS Code at C:\Users\imagi\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.54.0

[√] Connected device (4 available)
    • Pixel 5 (mobile)  • 10.0.0.16:37003 • android-arm64  • Android 13 (API 33)
    • Windows (desktop) • windows         • windows-x64    • Microsoft Windows [Version 10.0.22621.674]
    • Chrome (web)      • chrome          • web-javascript • Google Chrome 108.0.5359.100
    • Edge (web)        • edge            • web-javascript • Microsoft Edge 108.0.1462.54

[√] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 2 categories.
```

</details>


<!--
      Consider also attaching screenshots and/or videos to better
      illustrate the issue.

      You can upload them directly on GitHub.
      Beware that video file size is limited to 10MB.
-->

https://user-images.githubusercontent.com/13222934/208819740-2af12e5e-5401-432e-8166-97e746227b54.mp4