• 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_GLFW_PUBLIC_FLUTTER_GLFW_H_
6 #define FLUTTER_SHELL_PLATFORM_GLFW_PUBLIC_FLUTTER_GLFW_H_
7 
8 #include <stddef.h>
9 #include <stdint.h>
10 #include <memory>
11 
12 #include "flutter_export.h"
13 
14 #if defined(__cplusplus)
15 #include <functional>
16 namespace flutter {
17 class KeyboardHookHandler;
18 }
19 extern "C" {
20 #endif
21 
22 // Opaque reference to a Flutter window controller.
23 typedef struct FlutterDesktopWindowControllerState*
24     FlutterDesktopWindowControllerRef;
25 
26 // Opaque reference to a Flutter window.
27 typedef struct FlutterDesktopWindow* FlutterDesktopWindowRef;
28 
29 // Opaque reference to a Flutter engine instance.
30 typedef struct FlutterDesktopEngineState* FlutterDesktopEngineRef;
31 
32 // For PC preivew
33 using IdleCallback = std::function<void(int64_t)>;
34 using SurfacePresentCallback = bool (*)(const void*, const size_t, const int32_t, const int32_t);
35 
36 // Sets up the library's graphic context. Must be called before any other
37 // methods.
38 //
39 // Note: Internally, this library uses GLFW, which does not support multiple
40 // copies within the same process. Internally this calls glfwInit, which will
41 // fail if you have called glfwInit elsewhere in the process.
42 FLUTTER_EXPORT bool FlutterDesktopInit();
43 
44 // Tears down library state. Must be called before the process terminates.
45 FLUTTER_EXPORT void FlutterDesktopTerminate();
46 
47 // Creates a Window running a Flutter Application.
48 //
49 // FlutterDesktopInit() must be called prior to this function.
50 //
51 // The |assets_path| is the path to the flutter_assets folder for the Flutter
52 // application to be run. |icu_data_path| is the path to the icudtl.dat file
53 // for the version of Flutter you are using.
54 //
55 // The |arguments| are passed to the Flutter engine. See:
56 // https://github.com/flutter/engine/blob/master/shell/common/switches.h for
57 // for details. Not all arguments will apply to desktop.
58 //
59 // Returns a null pointer in the event of an error. Otherwise, the pointer is
60 // valid until FlutterDesktopRunWindowLoop has been called and returned, or
61 // FlutterDesktopDestroyWindow is called.
62 // Note that calling FlutterDesktopCreateWindow without later calling
63 // one of those two methods on the returned reference is a memory leak.
64 FLUTTER_EXPORT FlutterDesktopWindowControllerRef
65 FlutterDesktopCreateWindow(int &initial_width,
66                            int &initial_height,
67                            const char* title,
68                            const SurfacePresentCallback& sendSurface);
69 
70 // Shuts down the engine instance associated with |controller|, and cleans up
71 // associated state.
72 //
73 // |controller| is no longer valid after this call.
74 FLUTTER_EXPORT void FlutterDesktopDestroyWindow(
75     FlutterDesktopWindowControllerRef controller);
76 
77 // Ace PC preview.
78 FLUTTER_EXPORT void FlutterDesktopSetIdleCallback(
79     FlutterDesktopWindowControllerRef controller,
80     const IdleCallback& idleCallback);
81 
82 FLUTTER_EXPORT void FlutterDesktopAddKeyboardHookHandler(
83     FlutterDesktopWindowControllerRef controller,
84     std::unique_ptr<flutter::KeyboardHookHandler> keyboardHookHandler);
85 
86 FLUTTER_EXPORT void FlutterDesktopSetClipboardData(
87     FlutterDesktopWindowControllerRef controller, const char* data);
88 
89 FLUTTER_EXPORT const char* FlutterDesktopGetClipboardData(
90     FlutterDesktopWindowControllerRef controller);
91 
92 FLUTTER_EXPORT void FlutterDesktopGetFramebufferSize(
93     FlutterDesktopWindowRef flutter_window,
94     int* width,
95     int* height);
96 
97 FLUTTER_EXPORT void FlutterDesktopGetWindowSize(
98     FlutterDesktopWindowRef flutter_window,
99     int* width,
100     int* height);
101 
102 FLUTTER_EXPORT void FlutterDesktopSetWindowSize(
103     FlutterDesktopWindowRef flutter_window,
104     int& width,
105     int& height);
106 
107 // Loops on Flutter window events until the window is closed.
108 //
109 // Once this function returns, |controller| is no longer valid, and must not be
110 // be used again, as it calls FlutterDesktopDestroyWindow internally.
111 //
112 // TODO: Replace this with a method that allows running the runloop
113 // incrementally.
114 FLUTTER_EXPORT void FlutterDesktopRunWindowLoop(
115     FlutterDesktopWindowControllerRef controller);
116 
117 FLUTTER_EXPORT void FlutterDesktopWaitForEvents(
118     FlutterDesktopWindowControllerRef controller);
119 
120 FLUTTER_EXPORT bool FlutterDesktopWindowShouldClose(
121     FlutterDesktopWindowControllerRef controller);
122 
123 // Returns the window handle for the window associated with
124 // FlutterDesktopWindowControllerRef.
125 //
126 // Its lifetime is the same as the |controller|'s.
127 FLUTTER_EXPORT FlutterDesktopWindowRef
128 FlutterDesktopGetWindow(FlutterDesktopWindowControllerRef controller);
129 
130 // Enables or disables hover tracking.
131 //
132 // If hover is enabled, mouse movement will send hover events to the Flutter
133 // engine, rather than only tracking the mouse while the button is pressed.
134 // Defaults to on.
135 FLUTTER_EXPORT void FlutterDesktopWindowSetHoverEnabled(
136     FlutterDesktopWindowRef flutter_window,
137     bool enabled);
138 
139 // Sets the displayed title for |flutter_window|.
140 FLUTTER_EXPORT void FlutterDesktopWindowSetTitle(
141     FlutterDesktopWindowRef flutter_window,
142     const char* title);
143 
144 // Sets the displayed icon for |flutter_window|.
145 //
146 // The pixel format is 32-bit RGBA. The provided image data only needs to be
147 // valid for the duration of the call to this method. Pass a nullptr to revert
148 // to the default icon.
149 FLUTTER_EXPORT void FlutterDesktopWindowSetIcon(
150     FlutterDesktopWindowRef flutter_window,
151     uint8_t* pixel_data,
152     int width,
153     int height);
154 
155 // Gets the position and size of |flutter_window| in screen coordinates.
156 FLUTTER_EXPORT void FlutterDesktopWindowGetFrame(
157     FlutterDesktopWindowRef flutter_window,
158     int* x,
159     int* y,
160     int* width,
161     int* height);
162 
163 // Sets the position and size of |flutter_window| in screen coordinates.
164 FLUTTER_EXPORT void FlutterDesktopWindowSetFrame(
165     FlutterDesktopWindowRef flutter_window,
166     int x,
167     int y,
168     int width,
169     int height);
170 
171 // Returns the scale factor--the number of pixels per screen coordinate--for
172 // |flutter_window|.
173 FLUTTER_EXPORT double FlutterDesktopWindowGetScaleFactor(
174     FlutterDesktopWindowRef flutter_window);
175 
176 // Runs an instance of a headless Flutter engine.
177 //
178 // The |assets_path| is the path to the flutter_assets folder for the Flutter
179 // application to be run. |icu_data_path| is the path to the icudtl.dat file
180 // for the version of Flutter you are using.
181 //
182 // The |arguments| are passed to the Flutter engine. See:
183 // https://github.com/flutter/engine/blob/master/shell/common/switches.h for
184 // for details. Not all arguments will apply to desktop.
185 //
186 // Returns a null pointer in the event of an error.
187 FLUTTER_EXPORT FlutterDesktopEngineRef
188 FlutterDesktopRunEngine(const char* assets_path,
189                         const char* icu_data_path,
190                         const char** arguments,
191                         size_t argument_count);
192 
193 // Shuts down the given engine instance. Returns true if the shutdown was
194 // successful. |engine_ref| is no longer valid after this call.
195 FLUTTER_EXPORT bool FlutterDesktopShutDownEngine(
196     FlutterDesktopEngineRef engine_ref);
197 
198 #if defined(__cplusplus)
199 }  // extern "C"
200 #endif
201 
202 #endif  // FLUTTER_SHELL_PLATFORM_GLFW_PUBLIC_FLUTTER_GLFW_H_
203