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 <memory> 9 #include <string> 10 #include <vector> 11 12 #include <flutter_glfw.h> 13 14 #include "flutter_window.h" 15 #include "plugin_registrar.h" 16 17 namespace flutter { 18 19 // A controller for a window displaying Flutter content. 20 // 21 // This is the primary wrapper class for the desktop C API. 22 // If you use this class, you should not call any of the setup or teardown 23 // methods in the C API directly, as this class will do that internally. 24 // 25 // Note: This is an early implementation (using GLFW internally) which 26 // requires control of the application's event loop, and is thus useful 27 // primarily for building a simple one-window shell hosting a Flutter 28 // application. The final implementation and API will be very different. 29 class FlutterWindowController { 30 public: 31 // There must be only one instance of this class in an application at any 32 // given time, as Flutter does not support multiple engines in one process, 33 // or multiple views in one engine. 34 explicit FlutterWindowController(const std::string& icu_data_path); 35 36 ~FlutterWindowController(); 37 38 // Prevent copying. 39 FlutterWindowController(FlutterWindowController const&) = delete; 40 FlutterWindowController& operator=(FlutterWindowController const&) = delete; 41 42 // Creates and displays a window for displaying Flutter content. 43 // 44 // The |assets_path| is the path to the flutter_assets folder for the Flutter 45 // application to be run. |icu_data_path| is the path to the icudtl.dat file 46 // for the version of Flutter you are using. 47 // 48 // The |arguments| are passed to the Flutter engine. See: 49 // https://github.com/flutter/engine/blob/master/shell/common/switches.h for 50 // for details. Not all arguments will apply to desktop. 51 // 52 // Only one Flutter window can exist at a time; see constructor comment. 53 bool CreateWindow(int width, 54 int height, 55 const std::string& title, 56 const std::string& assets_path, 57 const std::vector<std::string>& arguments); 58 59 // Returns the FlutterDesktopPluginRegistrarRef to register a plugin with the 60 // given name. 61 // 62 // The name must be unique across the application. 63 FlutterDesktopPluginRegistrarRef GetRegistrarForPlugin( 64 const std::string& plugin_name); 65 66 // The FlutterWindow managed by this controller, if any. Returns nullptr 67 // before CreateWindow is called, and after RunEventLoop returns; window()68 FlutterWindow* window() { return window_.get(); } 69 70 // Loops on Flutter window events until the window closes. 71 void RunEventLoop(); 72 73 private: 74 // The path to the ICU data file. Set at creation time since it is the same 75 // for any window created. 76 std::string icu_data_path_; 77 78 // Whether or not FlutterDesktopInit succeeded at creation time. 79 bool init_succeeded_ = false; 80 81 // The owned FlutterWindow, if any. 82 std::unique_ptr<FlutterWindow> window_; 83 84 // Handle for interacting with the C API's window controller, if any. 85 FlutterDesktopWindowControllerRef controller_ = nullptr; 86 }; 87 88 } // namespace flutter 89 90 #endif // FLUTTER_SHELL_PLATFORM_GLFW_CLIENT_WRAPPER_INCLUDE_FLUTTER_FLUTTER_WINDOW_CONTROLLER_H_ 91