Skip to content

Icon is misaligned when using RTL with Impeller on iOS #151521

Closed
flutter-team-archive/engine
#53819

Description

@jiahaog

Internal Bug: b/352099353

Steps to reproduce

Run the app in the code sample below.

I only attempted this on iOS. Note that this issue is specific to Impeller. I'm not sure whether it's still possible to disable Impeller with the flutter cli, but internally this issue does not reproduce with Impeller disabled.

Expected results

The icon should be centered within the circle.
Simulator Screenshot - iPhone 15 Pro Max - 2024-07-10 at 14 30 58

Actual results

It is not centered within the circle.
Simulator Screenshot - iPhone 15 Pro Max - 2024-07-10 at 14 31 10

Code sample

Code sample
import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      home: Scaffold(
        body: Directionality(
          textDirection: TextDirection.rtl,
          child: Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                const Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: <Widget>[
                    CircleAvatar(
                      backgroundColor: Colors.blue,
                      child: Icon(
                        Icons.assignment,
                      ),
                    ),
                  ],
                ),
                const Text(
                  'The icon above should be centered within the circle.',
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}

Screenshots or Video

No response

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[✓] Flutter (Channel main, 3.23.0-13.0.pre.235, on macOS 14.5 23F79 darwin-arm64, locale en)
    • Flutter version 3.23.0-13.0.pre.235 on channel main at /Users/jiahaog/dev/flutter
    • Upstream repository [email protected]:flutter/flutter
    • Framework revision 349ec7183c (4 weeks ago), 2024-06-14 14:39:14 +0800
    • Engine revision 8167dffd19
    • Dart version 3.5.0 (build 3.5.0-254.0.dev)
    • DevTools version 2.36.0

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/jiahaog/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /Applications/Android Studio with Blaze.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)
    • All Android licenses accepted.

[!] Xcode - develop for iOS and macOS (Xcode 15.1)
    • Xcode at /Applications/Xcode_15.1.0.app/Contents/Developer
    • Build 15C65
    ! CocoaPods 1.12.1 out of date (1.13.0 is recommended).
        CocoaPods is a package manager for iOS or macOS platform code.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/platform-plugins
      To update CocoaPods, see https://guides.cocoapods.org/using/getting-started.html#updating-cocoapods

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

[✓] Android Studio (version 2023.2)
    • Android Studio at /Applications/Android Studio with Blaze.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.9+0-17.0.9b1087.7-11185874)

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

[✓] Connected device (5 available)
    • iPhone 15 Pro Max (mobile)      • D2A3A84D-8EF4-4A81-B33F-FC44A6430F2C • ios            • com.apple.CoreSimulator.SimRuntime.iOS-17-2 (simulator)
    ...
[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 1 category.

Activity

  1. danagbemava-nc commented on Jul 10, 2024

    @danagbemava-nc
    Member

    Reproducible on the latest master. This appears to be a regression and it works as expected on stable & beta but the bug reproduces on master.

    stable & beta master
    flutter doctor -v
    [✓] Flutter (Channel stable, 3.22.2, on macOS 14.4.1 23E224 darwin-arm64, locale en-GB)
        • Flutter version 3.22.2 on channel stable at /Users/nexus/dev/sdks/flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 761747bfc5 (5 weeks ago), 2024-06-05 22:15:13 +0200
        • Engine revision edd8546116
        • Dart version 3.4.3
        • DevTools version 2.34.3
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
        • Android SDK at /Users/nexus/Library/Android/sdk
        • Platform android-34, build-tools 34.0.0
        • Java binary at: /Users/nexus/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11609105)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 15.3)
        • Xcode at /Applications/Xcode-15.3.0.app/Contents/Developer
        • Build 15E204a
        • CocoaPods version 1.15.2
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2024.1)
        • Android Studio at /Users/nexus/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-11609105)
    
    [✓] IntelliJ IDEA Ultimate Edition (version 2023.2.5)
        • IntelliJ at /Users/nexus/Applications/IntelliJ IDEA Ultimate.app
        • Flutter plugin version 77.2.2
        • Dart plugin version 232.10286
    
    [✓] VS Code (version 1.90.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.92.0
    
    [✓] Connected device (4 available)
        • Nexus (mobile)                  • 00008020-001875E83A38002E • ios            • iOS 17.5.1 21F90
        • 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 126.0.6478.127
        ! Error: Browsing on the local area network for Dean’s iPad. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac.
          The device must be opted into Developer Mode to connect wirelessly. (code -27)
    
    [✓] Network resources
        • All expected network resources are available.
    
    • No issues found!
    
    [!] Flutter (Channel beta, 3.23.0-0.1.pre, on macOS 14.4.1 23E224 darwin-arm64, locale en-GB)
        • Flutter version 3.23.0-0.1.pre on channel beta at /Users/nexus/dev/sdks/flutter_beta
        ! Warning: `flutter` on your path resolves to /Users/nexus/dev/sdks/flutter/bin/flutter, which is not inside your current Flutter SDK
          checkout at /Users/nexus/dev/sdks/flutter_beta. Consider adding /Users/nexus/dev/sdks/flutter_beta/bin to the front of your path.
        ! Warning: `dart` on your path resolves to /Users/nexus/dev/sdks/flutter/bin/dart, which is not inside your current Flutter SDK
          checkout at /Users/nexus/dev/sdks/flutter_beta. Consider adding /Users/nexus/dev/sdks/flutter_beta/bin to the front of your path.
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 2feea7a407 (5 weeks ago), 2024-06-06 10:19:10 +0700
        • Engine revision bb10c54666
        • Dart version 3.5.0 (build 3.5.0-180.3.beta)
        • DevTools version 2.36.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.
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
        • Android SDK at /Users/nexus/Library/Android/sdk
        • Platform android-34, build-tools 34.0.0
        • Java binary at: /Users/nexus/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11609105)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 15.3)
        • Xcode at /Applications/Xcode-15.3.0.app/Contents/Developer
        • Build 15E204a
        • CocoaPods version 1.15.2
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2024.1)
        • Android Studio at /Users/nexus/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-11609105)
    
    [✓] IntelliJ IDEA Ultimate Edition (version 2023.2.5)
        • IntelliJ at /Users/nexus/Applications/IntelliJ IDEA Ultimate.app
        • Flutter plugin version 77.2.2
        • Dart plugin version 232.10286
    
    [✓] VS Code (version 1.90.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.92.0
    
    [✓] Connected device (4 available)
        • Nexus (mobile)                  • 00008020-001875E83A38002E • ios            • iOS 17.5.1 21F90
        • 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 126.0.6478.127
        ! Error: Browsing on the local area network for Dean’s iPad. Ensure the device is unlocked and attached with a cable or associated
          with the same local area network as this Mac.
          The device must be opted into Developer Mode to connect wirelessly. (code -27)
    
    [✓] Network resources
        • All expected network resources are available.
    
    ! Doctor found issues in 1 category.
    
    [!] Flutter (Channel master, 3.24.0-1.0.pre.68, on macOS 14.4.1 23E224 darwin-arm64, locale en-GB)
        • Flutter version 3.24.0-1.0.pre.68 on channel master at /Users/nexus/dev/sdks/flutters
        ! Warning: `flutter` on your path resolves to /Users/nexus/dev/sdks/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/nexus/dev/sdks/flutters. Consider adding /Users/nexus/dev/sdks/flutters/bin to the front of your path.
        ! Warning: `dart` on your path resolves to /Users/nexus/dev/sdks/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/nexus/dev/sdks/flutters. Consider adding /Users/nexus/dev/sdks/flutters/bin to the front of your path.
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision fe07fb4eba (3 hours ago), 2024-07-09 22:11:38 -0700
        • Engine revision 371db85f33
        • Dart version 3.5.0 (build 3.5.0-323.0.dev)
        • DevTools version 2.37.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.
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
        • Android SDK at /Users/nexus/Library/Android/sdk
        • Platform android-34, build-tools 34.0.0
        • Java binary at: /Users/nexus/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11609105)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 15.3)
        • Xcode at /Applications/Xcode-15.3.0.app/Contents/Developer
        • Build 15E204a
        • CocoaPods version 1.15.2
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2024.1)
        • Android Studio at /Users/nexus/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-11609105)
    
    [✓] IntelliJ IDEA Ultimate Edition (version 2023.2.5)
        • IntelliJ at /Users/nexus/Applications/IntelliJ IDEA Ultimate.app
        • Flutter plugin version 77.2.2
        • Dart plugin version 232.10286
    
    [✓] VS Code (version 1.90.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.92.0
    
    [✓] Connected device (4 available)
        • Nexus (mobile)                  • 00008020-001875E83A38002E • ios            • iOS 17.5.1 21F90
        • 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 126.0.6478.127
        ! Error: Browsing on the local area network for Dean’s iPad. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac.
          The device must be opted into Developer Mode to connect wirelessly. (code -27)
    
    [✓] Network resources
        • All expected network resources are available.
    
    ! Doctor found issues in 1 category.
    
  2. added
    c: regressionIt was better in the past than it is now
    platform-iosiOS applications specifically
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    engineflutter/engine related. See also e: labels.
    e: impellerImpeller rendering backend issues and features requests
    and removed
    in triagePresently being triaged by the triage team
    on Jul 10, 2024
  3. added
    P1High-priority issues at the top of the work list
    on Jul 11, 2024
  4. jonahwilliams commented on Jul 11, 2024

    @jonahwilliams
    Contributor

    Bisected this to flutter-team-archive/engine#53042 . Investigating what I did wrong here.

    One interesting note is that RTL mode causes the transform to be negative, and we offset from the left.

  5. jason-simmons commented on Jul 11, 2024

    @jason-simmons
    Member

    Not sure if this is exactly right, but the RTL text renders correctly with this patch to how the transform is applied in TextContents:

    diff --git a/impeller/entity/contents/text_contents.cc b/impeller/entity/contents/text
    _contents.cc
    index b4cbdbabf1..49568d7003 100644
    --- a/impeller/entity/contents/text_contents.cc
    +++ b/impeller/entity/contents/text_contents.cc
    @@ -231,6 +231,7 @@ bool TextContents::Render(const ContentContext& renderer,
                 const Rect& atlas_glyph_bounds =
                     maybe_atlas_glyph_bounds.value().first;
                 Rect glyph_bounds = maybe_atlas_glyph_bounds.value().second;
    +            Rect scaled_bounds = glyph_bounds.Scale(1.0 / rounded_scale);
                 // For each glyph, we compute two rectangles. One for the vertex
                 // positions and one for the texture coordinates (UVs). The atlas
                 // glyph bounds are used to compute UVs in cases where the
    @@ -243,19 +244,17 @@ bool TextContents::Render(const ContentContext& renderer,
                     (atlas_glyph_bounds.GetSize() + Point(1, 1)) / atlas_size;
     
                 Point unrounded_glyph_position =
    -                (basis_transform * glyph_position.position) +
    -                glyph_bounds.GetLeftTop();
    +                basis_transform *
    +                (glyph_position.position + scaled_bounds.GetLeftTop());
                 Point screen_glyph_position =
                     (screen_offset + unrounded_glyph_position + subpixel_adjustment)
                         .Floor();
     
    -            Size scaled_size = glyph_bounds.GetSize();
                 for (const Point& point : unit_points) {
                   Point position;
                   if (is_translation_scale) {
    -                position = screen_glyph_position + (point * scaled_size);
    +                position = screen_glyph_position + (basis_transform * point * scaled_bounds.GetSize());
                   } else {
    -                Rect scaled_bounds = glyph_bounds.Scale(1.0 / rounded_scale);
                     position = entity_transform * (glyph_position.position +
                                                    scaled_bounds.GetLeftTop() +
                                                    point * scaled_bounds.GetSize());
    
  6. jonahwilliams commented on Jul 11, 2024

    @jonahwilliams
    Contributor

    Ahh that makes sense. My change only absorbs the scaling portion of the transform - but that ignores other components and the sign bit.

  7. jmagman commented on Jul 11, 2024

    @jmagman
    Member

    @jonahwilliams it wouldn't be difficult to run relevant iOS scenario tests with a RTL language, if that would be helpful in detecting regressions.
    Screenshot 2024-07-11 at 4 51 00 PM

    https://github.com/flutter/engine/blob/main/testing/scenario_app/ios/Scenarios/ScenariosUITests/golden_bogus_font_text_impeller_iPhone%20SE%20(3rd%20generation)_17.0_simulator.png

  8. github-actions commented on Jul 26, 2024

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  9. locked as resolved and limited conversation to collaborators on Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P1High-priority issues at the top of the work listc: regressionIt was better in the past than it is nowcustomer: chalk (g3)e: impellerImpeller rendering backend issues and features requestsengineflutter/engine related. See also e: labels.found in release: 3.24Found to occur in 3.24has 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 team

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions