Skip to content

[Impeller] [Android] Native views not rendering on some devices #153228

@DjordjeMancic97

Description

@DjordjeMancic97

What target platforms are you seeing this bug on?

Android

Steps to reproduce

  1. Enable Impeller on Android

<meta-data android:name="io.flutter.embedding.android.EnableImpeller" android:value="true" />

  1. Use native views directly or through plugin

Expected results

Native view is rendered

Actual results

Native view is not displayed, screen is either empty or black with weird "glitch artifacts".
Issue seems to be device related and so far I can consistently reproduce it on:

  • Samsung Galaxy Note 10 Lite (Android 13)
  • Honor 10 (HarmonyOS 3.0)

Code sample

Flutter code sample
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(
          seedColor: Colors.deepPurple,
          brightness: Brightness.dark,
        ),
        useMaterial3: true,
      ),
      home: const MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    // This is used in the platform side to register the view.
    const String viewType = '<platform-view-type>';
    // Pass parameters to the platform side.
    const Map<String, dynamic> creationParams = <String, dynamic>{};

    return SafeArea(
      child: Scaffold(
        body: Column(
          children: [
            Expanded(
              child: Container(
                padding: const EdgeInsets.all(16),
                color: Colors.blue,
                height: MediaQuery.of(context).size.height / 2,
                width: MediaQuery.of(context).size.width,
                child: Container(
                  color: Colors.white,
                  child: const Center(
                    child: Text(
                      'Flutter view',
                      style: TextStyle(
                        fontSize: 20,
                        color: Colors.black,
                      ),
                    ),
                  ),
                ),
              ),
            ),
            Expanded(
              child: Container(
                padding: const EdgeInsets.all(16),
                color: Colors.green,
                height: MediaQuery.of(context).size.height / 2,
                width: MediaQuery.of(context).size.width,
                child: PlatformViewLink(
                  viewType: viewType,
                  surfaceFactory: (context, controller) {
                    return AndroidViewSurface(
                      controller: controller as AndroidViewController,
                      gestureRecognizers: const <Factory<
                          OneSequenceGestureRecognizer>>{},
                      hitTestBehavior: PlatformViewHitTestBehavior.opaque,
                    );
                  },
                  onCreatePlatformView: (params) {
                    return PlatformViewsService.initSurfaceAndroidView(
                      id: params.id,
                      viewType: viewType,
                      layoutDirection: TextDirection.ltr,
                      creationParams: creationParams,
                      creationParamsCodec: const StandardMessageCodec(),
                      onFocus: () {
                        params.onFocusChanged(true);
                      },
                    )
                      ..addOnPlatformViewCreatedListener(
                          params.onPlatformViewCreated)
                      ..create();
                  },
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

Native code sample
package com.example.google_maps_impeller_issue

import android.content.Context
import android.graphics.Color
import android.view.View
import android.widget.TextView
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.StandardMessageCodec
import io.flutter.plugin.platform.PlatformView
import io.flutter.plugin.platform.PlatformViewFactory

class MainActivity: FlutterActivity() {
    override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
        super.configureFlutterEngine(flutterEngine)
        flutterEngine
            .platformViewsController
            .registry
            .registerViewFactory("<platform-view-type>",
                NativeViewFactory())
    }
}

internal class NativeView(context: Context, id: Int, creationParams: Map<String?, Any?>?) :
    PlatformView {
    private val textView: TextView

    override fun getView(): View {
        return textView
    }

    override fun dispose() {}

    init {
        textView = TextView(context)
        textView.textSize = 42f
        textView.setBackgroundColor(Color.rgb(255, 255, 255))
        textView.text = "Rendered on a native Android view"
    }
}

class NativeViewFactory : PlatformViewFactory(StandardMessageCodec.INSTANCE) {
    override fun create(context: Context, viewId: Int, args: Any?): PlatformView {
        val creationParams = args as Map<String?, Any?>?
        return NativeView(context, viewId, creationParams)
    }
}

Screenshots or Videos

Impeller Off:
impeller-off (2)

Impeller On:
impeller-on (2)

Logs

Logs
D/zzcc    (17186): preferredRenderer: null
I/Google Maps Android API(17186): Google Play services package version: 210613039
W/_impeller_issu(17186): Accessing hidden method Lsun/misc/Unsafe;->putLong(Ljava/lang/Object;JJ)V (greylist, linking, allowed)
I/PlatformViewsController(17186): Hosting view in a virtual display for platform view: 0
I/PlatformViewsController(17186): PlatformView is using SurfaceProducer backend
I/DecorView[](17186): pkgName:com.example.google_maps_impeller_issue old windowMode:0 new windoMode:1, isFixedSize:false
D/MouseWheelSynthesizer(17186): mMoveStepInDp: 64, mMoveStepInPixel: 192, mUpTimeDelayed: 100
D/ViewRootImpl(17186): ViewRootImpl mIsInProductivePCDisplay: false
D/InputEventReceiver(17186): dispatchInputInterval 1000000
I/GoogleMapController(17186): No TextureView found. Likely using the LEGACY renderer.
E/GoogleMapController(17186): Cannot enable MyLocation layer as location permissions are not granted
D/OpenGLRenderer(17186): disableOutlineDraw is true
I/HiTouch_HiTouchSensor(17186): HiTouch restricted: Sub windows restricted.
D/HiTouch_PressGestureDetector(17186): onAttached, package=com.example.google_maps_impeller_issue, windowType=2030, mIsHiTouchRestricted=true
2
D/mali_winsys(17186): EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, EGLBoolean) returns 0x3000
W/vulkan  (17186): vkAcquireNextImageKHR: non-infinite timeouts not yet implemented
W/ImageReaderSurfaceProducer(17186): ImageTextureEntry can't wait on the fence on Android < 33
W/vulkan  (17186): vkAcquireNextImageKHR: non-infinite timeouts not yet implemented
I/chatty  (17186): uid=10235(com.example.google_maps_impeller_issue) 1.raster identical 5 lines
2
W/vulkan  (17186): vkAcquireNextImageKHR: non-infinite timeouts not yet implemented
I/chatty  (17186): uid=10235(com.example.google_maps_impeller_issue) 1.raster identical 17 lines
8
W/vulkan  (17186): vkAcquireNextImageKHR: non-infinite timeouts not yet implemented
W/_impeller_issu(17186): Accessing hidden method Lsun/misc/Unsafe;->putLong(Ljava/lang/Object;JJ)V (greylist, linking, allowed)
W/_impeller_issu(17186): Accessing hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J (greylist,core-platform-api, linking, allowed)
W/_impeller_issu(17186): Accessing hidden method Lsun/misc/Unsafe;->putLong(Ljava/lang/Object;JJ)V (greylist, linking, allowed)
I/chatty  (17186): uid=10235(com.example.google_maps_impeller_issue) GoogleApiHandle identical 25 lines
W/_impeller_issu(17186): Accessing hidden method Lsun/misc/Unsafe;->putLong(Ljava/lang/Object;JJ)V (greylist, linking, allowed)
26
W/vulkan  (17186): vkAcquireNextImageKHR: non-infinite timeouts not yet implemented

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.22.3, on macOS 14.2.1 23C71 darwin-arm64, locale en-US)
    • Flutter version 3.22.3 on channel stable at /Users/djordje/Development Tools/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision b0850beeb2 (4 weeks ago), 2024-07-16 21:43:41 -0700
    • Engine revision 235db911ba
    • Dart version 3.4.4
    • DevTools version 2.34.3

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/djordje/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • ANDROID_HOME = /Users/djordje/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15C65
    • CocoaPods version 1.14.2

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

[✓] Android Studio (version 2022.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 17.0.6+0-17.0.6b829.9-10027231)

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

[✓] Connected device (5 available)
    • COL AL10 (mobile)                    • 9YE0218711000121      • android-arm64  • Android 10 (API 29)
    • Android SDK built for arm64 (mobile) • emulator-5554         • android-arm64  • Android 9 (API 28) (emulator)
    • macOS (desktop)                      • macos                 • darwin-arm64   • macOS 14.2.1 23C71 darwin-arm64
    • Mac Designed for iPad (desktop)      • mac-designed-for-ipad • darwin         • macOS 14.2.1 23C71 darwin-arm64
    • Chrome (web)                         • chrome                • web-javascript • Google Chrome 127.0.6533.100

[✓] Network resources
    • All expected network resources are available.
Doctor output updated
[✓] Flutter (Channel stable, 3.24.0, on macOS 14.2.1 23C71 darwin-arm64, locale en-US)
    • Flutter version 3.24.0 on channel stable at /Users/djordje/Development Tools/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 80c2e84975 (13 days ago), 2024-07-30 23:06:49 +0700
    • Engine revision b8800d88be
    • Dart version 3.5.0
    • DevTools version 2.37.2

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/djordje/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • ANDROID_HOME = /Users/djordje/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15C65
    • CocoaPods version 1.14.2

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

[✓] Android Studio (version 2022.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 17.0.6+0-17.0.6b829.9-10027231)

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

[✓] Connected device (4 available)
    • SM A127F (mobile)               • R58RA18NREM           • android-arm64  • Android 12 (API 31)
    • macOS (desktop)                 • macos                 • darwin-arm64   • macOS 14.2.1 23C71 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin         • macOS 14.2.1 23C71 darwin-arm64
    • Chrome (web)                    • chrome                • web-javascript • Google Chrome 127.0.6533.100

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

• No issues found!

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work lista: platform-viewsEmbedding Android/iOS views in Flutter appsc: renderingUI glitches reported at the engine/skia or impeller rendering levele: device-specificOnly manifests on certain devicese: impellerImpeller rendering backend issues and features requestse: impeller-naughty-driverDevices & drivers that may be behaving unexpectedly and may need workarounds.engineflutter/engine related. See also e: labels.platform-androidAndroid applications specificallyteam-engineOwned by Engine teamtriaged-engineTriaged by Engine team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions