• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_PUBLIC_FLUTTER_H_
6 #define FLUTTER_SHELL_PLATFORM_WINDOWS_PUBLIC_FLUTTER_H_
7 
8 #include <stddef.h>
9 #include <stdint.h>
10 
11 #include "flutter_export.h"
12 #include "flutter_messenger.h"
13 #include "flutter_plugin_registrar.h"
14 
15 #if defined(__cplusplus)
16 extern "C" {
17 #endif
18 
19 // Opaque reference to a Flutter window controller.
20 typedef struct FlutterDesktopWindowControllerState*
21     FlutterDesktopWindowControllerRef;
22 
23 // Opaque reference to a Flutter window.
24 typedef struct FlutterDesktopWindow* FlutterDesktopWindowRef;
25 
26 // Opaque reference to a Flutter engine instance.
27 typedef struct FlutterDesktopEngineState* FlutterDesktopEngineRef;
28 
29 // TODO: remove once the embedder project has swiched to native windows
30 FLUTTER_EXPORT bool FlutterDesktopInit();
31 
32 // TODO: remove once the embedder project has swiched to native windows
33 FLUTTER_EXPORT void FlutterDesktopTerminate();
34 
35 // Creates a Window running a Flutter Application.
36 //
37 // FlutterDesktopInit() must be called prior to this function.
38 //
39 // The |assets_path| is the path to the flutter_assets folder for the Flutter
40 // application to be run. |icu_data_path| is the path to the icudtl.dat file
41 // for the version of Flutter you are using.
42 //
43 // The |arguments| are passed to the Flutter engine. See:
44 // https://github.com/flutter/engine/blob/master/shell/common/switches.h for
45 // for details. Not all arguments will apply to desktop.
46 //
47 // Returns a null pointer in the event of an error. Otherwise, the pointer is
48 // valid until FlutterDesktopRunWindowLoop has been called and returned.
49 // Note that calling FlutterDesktopCreateWindow without later calling
50 // FlutterDesktopRunWindowLoop on the returned reference is a memory leak.
51 FLUTTER_EXPORT FlutterDesktopWindowControllerRef
52 FlutterDesktopCreateWindow(int initial_width,
53                            int initial_height,
54                            const char* title,
55                            const char* assets_path,
56                            const char* icu_data_path,
57                            const char** arguments,
58                            size_t argument_count);
59 
60 // Shuts down the engine instance associated with |controller|, and cleans up
61 // associated state.
62 //
63 // |controller| is no longer valid after this call.
64 FLUTTER_EXPORT void FlutterDesktopDestroyWindow(
65     FlutterDesktopWindowControllerRef controller);
66 
67 // Loops on Flutter window events until the window is closed.
68 //
69 // Once this function returns, |controller| is no longer valid, and must not be
70 // be used again, as it calls FlutterDesktopDestroyWindow internally.
71 //
72 // TODO: Replace this with a method that allows running the runloop
73 // incrementally.
74 FLUTTER_EXPORT void FlutterDesktopRunWindowLoop(
75     FlutterDesktopWindowControllerRef controller);
76 
77 // Returns the window handle for the window associated with
78 // FlutterDesktopWindowControllerRef.
79 //
80 // Its lifetime is the same as the |controller|'s.
81 FLUTTER_EXPORT FlutterDesktopWindowRef
82 FlutterDesktopGetWindow(FlutterDesktopWindowControllerRef controller);
83 
84 // Returns the plugin registrar handle for the plugin with the given name.
85 //
86 // The name must be unique across the application.
87 FLUTTER_EXPORT FlutterDesktopPluginRegistrarRef
88 FlutterDesktopGetPluginRegistrar(FlutterDesktopWindowControllerRef controller,
89                                  const char* plugin_name);
90 
91 // Enables or disables hover tracking.
92 //
93 // If hover is enabled, mouse movement will send hover events to the Flutter
94 // engine, rather than only tracking the mouse while the button is pressed.
95 // Defaults to on.
96 FLUTTER_EXPORT void FlutterDesktopWindowSetHoverEnabled(
97     FlutterDesktopWindowRef flutter_window,
98     bool enabled);
99 
100 // Sets the displayed title for |flutter_window|.
101 FLUTTER_EXPORT void FlutterDesktopWindowSetTitle(
102     FlutterDesktopWindowRef flutter_window,
103     const char* title);
104 
105 // Sets the displayed icon for |flutter_window|.
106 //
107 // The pixel format is 32-bit RGBA. The provided image data only needs to be
108 // valid for the duration of the call to this method. Pass a nullptr to revert
109 // to the default icon.
110 FLUTTER_EXPORT void FlutterDesktopWindowSetIcon(
111     FlutterDesktopWindowRef flutter_window,
112     uint8_t* pixel_data,
113     int width,
114     int height);
115 
116 // Gets the position and size of |flutter_window| in screen coordinates.
117 FLUTTER_EXPORT void FlutterDesktopWindowGetFrame(
118     FlutterDesktopWindowRef flutter_window,
119     int* x,
120     int* y,
121     int* width,
122     int* height);
123 
124 // Sets the position and size of |flutter_window| in screen coordinates.
125 FLUTTER_EXPORT void FlutterDesktopWindowSetFrame(
126     FlutterDesktopWindowRef flutter_window,
127     int x,
128     int y,
129     int width,
130     int height);
131 
132 // Returns the scale factor--the number of pixels per screen coordinate--for
133 // |flutter_window|.
134 FLUTTER_EXPORT double FlutterDesktopWindowGetScaleFactor(
135     FlutterDesktopWindowRef flutter_window);
136 
137 // Runs an instance of a headless Flutter engine.
138 //
139 // The |assets_path| is the path to the flutter_assets folder for the Flutter
140 // application to be run. |icu_data_path| is the path to the icudtl.dat file
141 // for the version of Flutter you are using.
142 //
143 // The |arguments| are passed to the Flutter engine. See:
144 // https://github.com/flutter/engine/blob/master/shell/common/switches.h for
145 // for details. Not all arguments will apply to desktop.
146 //
147 // Returns a null pointer in the event of an error.
148 FLUTTER_EXPORT FlutterDesktopEngineRef
149 FlutterDesktopRunEngine(const char* assets_path,
150                         const char* icu_data_path,
151                         const char** arguments,
152                         size_t argument_count);
153 
154 // Shuts down the given engine instance. Returns true if the shutdown was
155 // successful. |engine_ref| is no longer valid after this call.
156 FLUTTER_EXPORT bool FlutterDesktopShutDownEngine(
157     FlutterDesktopEngineRef engine_ref);
158 
159 // TODO: remove once embedder project has switched to native windows
160 // imlpementation
161 FLUTTER_EXPORT FlutterDesktopWindowRef
162 FlutterDesktopRegistrarGetWindow(FlutterDesktopPluginRegistrarRef registrar);
163 
164 #if defined(__cplusplus)
165 }  // extern "C"
166 #endif
167 
168 #endif  // FLUTTER_SHELL_PLATFORM_WINDOWS_PUBLIC_FLUTTER_WINDOWS_H_
169