Repository: flutter
Issue: drawPaint not invariant across scale transforms (skia and impeller)
Labels: engine,has reproducible steps,P3,team-engine,triaged-engine,found in release: 3.24

This app should paint solid green (with a changing number in the corner). Tested on Android (impeller) and Linux (skia). It renders green for scales around 1e-13 .. 1e13, but nothing outside of that.

<details>

<summary> Code </summary>

```dart
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';

void main() async {
  runApp(const Root());
}

class Root extends StatefulWidget {
  const Root({super.key});

  @override
  State<Root> createState() => _RootState();
}

class _RootState extends State<Root> {
  Timer? _timer;
  double _scale = 1.0;
  
  @override
  void initState() {
    super.initState();
    _timer = Timer.periodic(const Duration(milliseconds: 100), _update);
  }

  void _update(Timer timer) {
    setState(() {
      _scale *= 10;
      if (_scale > 1e38) {
        _scale = 1e-38;
      }
    });
  }

  @override
  void dispose() {
    _timer?.cancel();
    super.dispose();
  }
  
  @override
  Widget build(BuildContext context) {
    return Stack(
      textDirection: TextDirection.ltr,
      children: [
        TestWidget(
          scale: _scale,
        ),
        Positioned(
          top: 60.0,
          left: 20.0,
          child: Text('scale: ${_scale.toStringAsExponential(1)}', textDirection: TextDirection.ltr),
        ),
      ],
    );
  }
}

class TestWidget extends LeafRenderObjectWidget {
  const TestWidget({
    super.key,
    this.scale = 1.0,
  });

  final double scale;
  
  @override
  RenderTest createRenderObject(BuildContext context) {
    return RenderTest(
      scale: scale,
    );
  }

  @override
  void updateRenderObject(BuildContext context, RenderTest renderObject) {
    renderObject
      ..scale = scale;
  }
}

class RenderTest extends RenderBox {
  RenderTest({ double scale = 1.0 }) : _scale = scale;

  double get scale => _scale;
  double _scale;
  set scale(double value) {
    if (_scale != value) {
      _scale = value;
      markNeedsPaint();
    }
  }
  
  @override
  void performLayout() {
    size = constraints.biggest;
  }

  final LayerHandle<TransformLayer> _transformLayer = LayerHandle<TransformLayer>();
  
  @override
  void paint(PaintingContext context, Offset offset) {
    final transform = Matrix4.identity()
      ..scale(scale);
    _transformLayer.layer = context.pushTransform(
      needsCompositing,
      offset,
      transform,
      _paintTest,
      oldLayer: _transformLayer.layer,
    );
  }
  
  void _paintTest(PaintingContext context, Offset offset) {
    context.canvas.drawPaint(Paint()..color=const Color(0xFF009933));
  }

  @override
  void dispose() {
    _transformLayer.layer = null;
    super.dispose();
  }
}
```

</details>

<details>

<summary> flutter doctor -v </summary>

```console
[✓] Flutter (Channel main, 3.24.0-1.0.pre.451, on Ubuntu 22.04.3 LTS 5.15.0-94-generic,
    locale C.UTF-8)
    • Flutter version 3.24.0-1.0.pre.451 on channel main at /home/ianh/dev/flutter
    • Upstream repository git@github.com:flutter/flutter.git
    • Framework revision 84eb378180 (4 days ago), 2024-08-05 17:11:23 -0400
    • Engine revision e073ad2e3a
    • Dart version 3.6.0 (build 3.6.0-116.0.dev)
    • DevTools version 2.38.0

[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
    • Android SDK at /home/ianh/Android/Sdk
    • Platform android-35, build-tools 35.0.0
    • Java binary at: /home/ianh/bin/android-studio/jbr/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.11+0-17.0.11b1207.24-11852314)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✓] Linux toolchain - develop for Linux desktop
    • Ubuntu clang version 14.0.0-1ubuntu1.1
    • cmake version 3.22.1
    • ninja version 1.10.1
    • pkg-config version 0.29.2

[✓] Android Studio (version 2024.1)
    • Android Studio at /home/ianh/bin/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 17.0.11+0-17.0.11b1207.24-11852314)

[✓] IntelliJ IDEA Community Edition (version 2022.1)
    • IntelliJ at /home/ianh/bin/idea-IC-221.5921.22
    • 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

[✓] Connected device (3 available)
    • Pixel 6a (mobile) • 35301JEGR05976 • android-arm64  • Android 13 (API 33)
    • Linux (desktop)   • linux          • linux-x64      • Ubuntu 22.04.3 LTS
      5.15.0-94-generic
    • Chrome (web)      • chrome         • web-javascript • Google Chrome 123.0.6312.58

[✓] Network resources
    • All expected network resources are available.

• No issues found!
```

</details>