Skip to content

'AndroidSurfaceGL::CreatePbufferSurface' may cause the app to only display a blank screen. #95957

@ColdPaleLight

Description

@ColdPaleLight

flutter/engine#27141 will provide a Pbuffer surface when on screen surface is not available. It applies to Android and it is for background specific.

However, there is another scenario that needs to be considered here. When method PlatformViewAndroid::NotifyCreated is called, there will be a situation where AndroidSurfaceGL::on_screen_surface_ is set, but Rasterizer::surface_ has not been set.

void PlatformViewAndroid::NotifyCreated(
    fml::RefPtr<AndroidNativeWindow> native_window) {
  if (android_surface_) {
    InstallFirstFrameCallback();

    fml::AutoResetWaitableEvent latch;
    fml::TaskRunner::RunNowOrPostTask(
        task_runners_.GetRasterTaskRunner(),
        [&latch, surface = android_surface_.get(),
         native_window = std::move(native_window)]() {
          surface->SetNativeWindow(native_window);  // 1. Setup AndroidSurfaceGL::on_screen_surface_
          latch.Signal();
        });
    latch.Wait();
  }

  PlatformView::NotifyCreated();  // 2. Setup Rasterizer::surface_
}

If Rasterizer::DoMakeRasterSnapshot is called at this time, because Rasterizer::surface_ has not been set yet, it will call AndroidSurfaceGL::CreatePbufferSurface to generate Pbuffer. At this time, the AndroidSurfaceGL::on_screen_surface_ will be replaced by the new one which size is 1x1.

In fact, my application encountered this issue. I was using Flutter 2.5.3. When I opened the first flutter screen, the entire screen did not display any content, it was blank screen. Eventually I found out that the reason caused this problem is above. Unfortunately, it is difficult for me to give a reproducible sample. But I suspect that this problem still exists on the 'main' branch.

/cc @dnfield

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listcustomer: alibabaengineflutter/engine related. See also e: labels.platform-androidAndroid applications specificallyr: fixedIssue is closed as already fixed in a newer version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions