This article is a reference to Flutter for Windows startup process analysis — nuggets (juejin. Cn), that is, to comb the internal code logic of Flutter for Windows. Learn about the startup mechanism of Flutter Engine in Windows.

This article had better cooperate with the authoritiesFlutter EngineSource code to eat!

Antecedents feed

Within the OnCreate function of FlutterWindow, we create a FlutterViewController constructed as follows.

Source code in the official Engine library: SRC \flutter\shell\platform\ Windows \client_wrapper\flutter_view_controller.cc

Get into the business

We see a number of functions with the name starting with FlutterDesktop, which is key to engine creation and startup, and follow the header to find their definition and implementation files:

  • Declare file path: SRC \flutter\shell\platform\ Windows \public\flutter_windows.h
  • Implementation file path: SRC \flutter\shell\platform\ Windows \flutter_windows.cc

Remember, this file is an interface between the desktop platform and the underlying engine! In most cases, the function is called embedder.

The creation of Engine

SRC \flutter\shell\platform\ Windows \client_wrapper\flutter_engine. Cc Found code similar to the official GLFW Example.

  1. First, on lines 16-18, copy the path address of DartProject into c_engine_properties.

    • Curious about the exact meaning of these paths? DartProjet parameter parsing (not yet written)
  2. Lines 20-31 are used to process the number and content of arguments passed from the command line.

    • If you are in theFlutterseen@vm-entrypointYou can see what he means. If you do not pass parameters, the default entry is dart sidemain.

  1. Lines 33 to 35 create an engine and get the engine creationMessengerLet’s take a closer lookFlutterDesktopEngineCreateWhat did

FlutterDesktopEngineCreate

The source code for this section is available under SRC \flutter\shell\platform\ Windows.

What FlutterProjectBundle does is convert some path properties to internally readable. HandleForEngine doesn’t do anything either, it’s just a type conversion. (flutter_project_bundle.cc)

  • flutter_winddows.ccThe inside of theHandleMost of the first ones are doing this job.

FlutterWindowsEngineThat’s what we createdEngineType.

What I’m interested in is the internal logic of lines 164-168, which is where my next shared texture article will come from.

Flutter for Windows Shared Texture conjecture – Nuggets

flutter_windows_engine.cc

At this point, the Windows platform engine is built, but not yet started!!

Back to the starting point

To create a good engine, we create FlutterDesktopViewControllerCreate, through annotations, that it contains the startup logic, as for implementation, here is not posted.

At this point, the engine is running, Wuhu!

Little Tail: Maybe you’ll see thisRunfunction

But direct call is failed, because has not yet set rendering, and so on properties of the engine, which is FlutterDesktopViewControllerCreate internal processing task for us.

Curious how it failed? The following article tells you the answer

– Start the Flutter Engine with VS2019 and Cmake

END

Further research, Flutter will not be written, after these several related articles are finished, learn algorithms and primitive, after all, I will find a class in the second half of the semester.