flutter-tizen / engine

The Flutter engine
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
6 stars 19 forks source link

Supports the scenario of setting the engine on the view after the engine is running. #316

Closed bbrto21 closed 2 years ago

bbrto21 commented 2 years ago

Unfortunately, if you run the engine before you set it on the view, nothing will be shown on the device's screen.

Below is a brief scenario.

  1. create and run the engine.
  2. create the view.
  3. set the engine on the view(or app) when you want.
  4. the rendering results are displayed normally on the device screen.

If this is possible, this means the engine can be pre-warmed. I think this can be used for improving app launch times, also this can be used for caching pre-warmed engines.

swift-kim commented 2 years ago

On Android: https://docs.flutter.dev/development/add-to-app/android/add-flutter-screen#step-3-optional-use-a-cached-flutterengine

Be sure to keep in mind that:

  • If your Dart entrypoint invokes runApp() to run a Flutter app, then your Flutter app behaves as if it were running in a window of zero size until this FlutterEngine is attached to a FlutterActivity, FlutterFragment, or FlutterView.
  • To stop executing and clear resources, obtain your FlutterEngine from the FlutterEngineCache and destroy the FlutterEngine with FlutterEngine.destroy().
  • A pre-warmed FlutterEngine executes Dart code independent from a FlutterActivity, which allows such a FlutterEngine to be used to execute arbitrary Dart code at any moment.

This page might also be helpful: https://docs.flutter.dev/development/add-to-app/performance

swift-kim commented 2 years ago

Here is my attempt: https://github.com/flutter-tizen/engine/compare/flutter-3.0.0-tizen...swift-kim:engine:evas-vsync-waiter

I managed to remove all renderer-related checks from FlutterTizenEngine::RunEngine. When I launched an app however, the engine tried to initialize a rendering surface during FlutterEngineRunInitialized and failed.

[WARNING:flutter/common/graphics/persistent_cache.cc(283)] Could not acquire the persistent cache directory. Caching of GPU resources on disk is disabled.
[ERROR:flutter/shell/gpu/gpu_surface_gl.cc(42)] Could not make the context current to set up the Gr context.
[ERROR:flutter/shell/gpu/gpu_surface_gl.cc(80)] Could not make the context current to set up the Gr context.
[ERROR:flutter/shell/common/platform_view.cc(76)] Failed to create platform view rendering surface

A surface must be created (even if it has a size of zero) before the engine is run, but it's not possible for our case because the renderer type is decided right before a view is created. Will moving the renderer_type property from FlutterDesktopWindowProperties to FlutterDesktopEngineProperties help this situation?

bbrto21 commented 2 years ago

Will moving the renderer_type property from FlutterDesktopWindowProperties to FlutterDesktopEngineProperties help this situation?

I think it will help. I guess a valid renderer must exist before running the engine... therefore, it seems necessary to create a renderer before running the engine using something like a dummy view. so, I think it's a good alternative to solve this issue.

bbrto21 commented 2 years ago

I tried to create a dummy view and use it to run the engine, and replace it with a view that would actually be used later. but it didn't work well. I think we need to find a new way.... :(

swift-kim commented 2 years ago

We couldn't find a way to implement this feature. Please reopen if there's any update.