Flutter Engine
The Flutter Engine
flutter_window_controller.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_GLFW_CLIENT_WRAPPER_INCLUDE_FLUTTER_FLUTTER_WINDOW_CONTROLLER_H_
6#define FLUTTER_SHELL_PLATFORM_GLFW_CLIENT_WRAPPER_INCLUDE_FLUTTER_FLUTTER_WINDOW_CONTROLLER_H_
7
8#include <flutter_glfw.h>
9
10#include <chrono>
11#include <memory>
12#include <string>
13#include <vector>
14
15#include "flutter_window.h"
16#include "plugin_registrar.h"
17#include "plugin_registry.h"
18
19namespace flutter {
20
21// Properties for Flutter window creation.
23 // The display title.
24 std::string title;
25 // Width in screen coordinates.
26 int32_t width;
27 // Height in screen coordinates.
28 int32_t height;
29 // Whether or not the user is prevented from resizing the window.
30 // Reversed so that the default for a cleared struct is to allow resizing.
32};
33
34// A controller for a window displaying Flutter content.
35//
36// This is the primary wrapper class for the desktop C API.
37// If you use this class, you should not call any of the setup or teardown
38// methods in the C API directly, as this class will do that internally.
39//
40// Note: This is an early implementation (using GLFW internally) which
41// requires control of the application's event loop, and is thus useful
42// primarily for building a simple one-window shell hosting a Flutter
43// application. The final implementation and API will be very different.
45 public:
46 // There must be only one instance of this class in an application at any
47 // given time, as Flutter does not support multiple engines in one process,
48 // or multiple views in one engine.
49 //
50 // |icu_data_path| is the path to the icudtl.dat file for the version of
51 // Flutter you are using.
52 explicit FlutterWindowController(const std::string& icu_data_path);
53
55
56 // Prevent copying.
59
60 // Creates and displays a window for displaying Flutter content.
61 //
62 // The |assets_path| is the path to the flutter_assets folder for the Flutter
63 // application to be run.
64 //
65 // The |arguments| are passed to the Flutter engine. See:
66 // https://github.com/flutter/engine/blob/main/shell/common/switches.h for
67 // details. Not all arguments will apply to desktop.
68 //
69 // The |aot_library_path| is the path to the libapp.so file for the Flutter
70 // application to be run. While this parameter is only required in AOT mode,
71 // it is perfectly safe to provide the path in non-AOT mode too.
72 //
73 // Only one Flutter window can exist at a time; see constructor comment.
74 bool CreateWindow(const WindowProperties& window_properties,
75 const std::string& assets_path,
76 const std::vector<std::string>& arguments,
77 const std::string& aot_library_path = "");
78
79 // Destroys the current window, if any.
80 //
81 // Because only one window can exist at a time, this method must be called
82 // between calls to CreateWindow, or the second one will fail.
83 void DestroyWindow();
84
85 // The FlutterWindow managed by this controller, if any. Returns nullptr
86 // before CreateWindow is called, after DestroyWindow is called, and after
87 // RunEventLoop returns;
88 FlutterWindow* window() { return window_.get(); }
89
90 // Processes the next event on this window, or returns early if |timeout| is
91 // reached before the next event.
92 //
93 // Returns false if the window was closed as a result of event processing.
95 std::chrono::milliseconds timeout = std::chrono::milliseconds::max());
96
97 // Deprecated. Use RunEventLoopWithTimeout.
98 void RunEventLoop();
99
100 // flutter::PluginRegistry:
102 const std::string& plugin_name) override;
103
104 private:
105 // The path to the ICU data file. Set at creation time since it is the same
106 // for any window created.
107 std::string icu_data_path_;
108
109 // Whether or not FlutterDesktopInit succeeded at creation time.
110 bool init_succeeded_ = false;
111
112 // The owned FlutterWindow, if any.
113 std::unique_ptr<FlutterWindow> window_;
114
115 // Handle for interacting with the C API's window controller, if any.
116 FlutterDesktopWindowControllerRef controller_ = nullptr;
117};
118
119} // namespace flutter
120
121#endif // FLUTTER_SHELL_PLATFORM_GLFW_CLIENT_WRAPPER_INCLUDE_FLUTTER_FLUTTER_WINDOW_CONTROLLER_H_
bool RunEventLoopWithTimeout(std::chrono::milliseconds timeout=std::chrono::milliseconds::max())
FlutterWindowController(FlutterWindowController const &)=delete
bool CreateWindow(const WindowProperties &window_properties, const std::string &assets_path, const std::vector< std::string > &arguments, const std::string &aot_library_path="")
FlutterDesktopPluginRegistrarRef GetRegistrarForPlugin(const std::string &plugin_name) override
FlutterWindowController & operator=(FlutterWindowController const &)=delete
FlutterWindowController(const std::string &icu_data_path)
static float max(float r, float g, float b)
Definition: hsl.cpp:49
def timeout(deadline, cmd)