Flutter Engine
flutter_windows_engine.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_FLUTTER_WINDOWS_ENGINE_H_
6 #define FLUTTER_SHELL_PLATFORM_WINDOWS_FLUTTER_WINDOWS_ENGINE_H_
7 
8 #include <map>
9 #include <memory>
10 #include <optional>
11 #include <vector>
12 
13 #include "flutter/shell/platform/common/cpp/incoming_message_dispatcher.h"
14 #include "flutter/shell/platform/windows/flutter_project_bundle.h"
15 #include "flutter/shell/platform/windows/public/flutter_windows.h"
16 #include "flutter/shell/platform/windows/win32_task_runner.h"
17 #include "flutter/shell/platform/windows/win32_window_proc_delegate_manager.h"
18 #include "flutter/shell/platform/windows/window_state.h"
19 
20 namespace flutter {
21 
22 class FlutterWindowsView;
23 
24 // Manages state associated with the underlying FlutterEngine that isn't
25 // related to its display.
26 //
27 // In most cases this will be associated with a FlutterView, but if not will
28 // run in headless mode.
30  public:
31  // Creates a new Flutter engine object configured to run |project|.
32  explicit FlutterWindowsEngine(const FlutterProjectBundle& project);
33 
34  virtual ~FlutterWindowsEngine();
35 
36  // Prevent copying.
39 
40  // Starts running the engine with the given entrypoint. If null, defaults to
41  // main().
42  //
43  // Returns false if the engine couldn't be started.
44  bool RunWithEntrypoint(const char* entrypoint);
45 
46  // Returns true if the engine is currently running.
47  bool running() { return engine_ != nullptr; }
48 
49  // Stops the engine. This invalidates the pointer returned by engine().
50  //
51  // Returns false if stopping the engine fails, or if it was not running.
52  bool Stop();
53 
54  // Sets the view that is displaying this engine's content.
56 
57  // The view displaying this engine's content, if any. This will be null for
58  // headless engines.
59  FlutterWindowsView* view() { return view_; }
60 
61  // Returns the currently configured Plugin Registrar.
63 
64  // Sets |callback| to be called when the plugin registrar is destroyed.
67 
68  FLUTTER_API_SYMBOL(FlutterEngine) engine() { return engine_; }
69 
70  FlutterDesktopMessengerRef messenger() { return messenger_.get(); }
71 
73  return message_dispatcher_.get();
74  }
75 
76  Win32TaskRunner* task_runner() { return task_runner_.get(); }
77 
79  return window_proc_delegate_manager_.get();
80  }
81 
82  // Callback passed to Flutter engine for notifying window of platform
83  // messages.
85 
86  private:
87  // Sends system settings (e.g., locale) to the engine.
88  //
89  // Should be called just after the engine is run, and after any relevant
90  // system changes.
91  void SendSystemSettings();
92 
93  // The handle to the embedder.h engine instance.
94  FLUTTER_API_SYMBOL(FlutterEngine) engine_ = nullptr;
95 
96  std::unique_ptr<FlutterProjectBundle> project_;
97 
98  // AOT data, if any.
99  UniqueAotDataPtr aot_data_;
100 
101  // The view displaying the content running in this engine, if any.
102  FlutterWindowsView* view_ = nullptr;
103 
104  // Task runner for tasks posted from the engine.
105  std::unique_ptr<Win32TaskRunner> task_runner_;
106 
107  // The plugin messenger handle given to API clients.
108  std::unique_ptr<FlutterDesktopMessenger> messenger_;
109 
110  // Message dispatch manager for messages from engine_.
111  std::unique_ptr<IncomingMessageDispatcher> message_dispatcher_;
112 
113  // The plugin registrar handle given to API clients.
114  std::unique_ptr<FlutterDesktopPluginRegistrar> plugin_registrar_;
115 
116  // A callback to be called when the engine (and thus the plugin registrar)
117  // is being destroyed.
119  plugin_registrar_destruction_callback_;
120 
121  // The manager for WindowProc delegate registration and callbacks.
122  std::unique_ptr<Win32WindowProcDelegateManager> window_proc_delegate_manager_;
123 };
124 
125 } // namespace flutter
126 
127 #endif // FLUTTER_SHELL_PLATFORM_WINDOWS_FLUTTER_WINDOWS_ENGINE_H_
void SetPluginRegistrarDestructionCallback(FlutterDesktopOnPluginRegistrarDestroyed callback)
FLUTTER_API_SYMBOL(FlutterEngine) engine()
FlutterWindowsEngine(const FlutterProjectBundle &project)
bool RunWithEntrypoint(const char *entrypoint)
FlutterDesktopPluginRegistrarRef GetRegistrar()
IncomingMessageDispatcher * message_dispatcher()
Win32WindowProcDelegateManager * window_proc_delegate_manager()
FlutterDesktopMessengerRef messenger()
FlutterWindowsEngine & operator=(FlutterWindowsEngine const &)=delete
void HandlePlatformMessage(const FlutterPlatformMessage *)
void(* FlutterDesktopOnPluginRegistrarDestroyed)(FlutterDesktopPluginRegistrarRef)
void SetView(FlutterWindowsView *view)
std::unique_ptr< _FlutterEngineAOTData, AotDataDeleter > UniqueAotDataPtr