os.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. /*************************************************************************/
  2. /* os.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #ifndef OS_H
  31. #define OS_H
  32. #include "core/engine.h"
  33. #include "core/image.h"
  34. #include "core/io/logger.h"
  35. #include "core/list.h"
  36. #include "core/os/main_loop.h"
  37. #include "core/ustring.h"
  38. #include "core/vector.h"
  39. #include <stdarg.h>
  40. #include <stdlib.h>
  41. class OS {
  42. static OS *singleton;
  43. static uint64_t target_ticks;
  44. String _execpath;
  45. List<String> _cmdline;
  46. bool _keep_screen_on;
  47. bool low_processor_usage_mode;
  48. int low_processor_usage_mode_sleep_usec;
  49. bool _verbose_stdout;
  50. bool _debug_stdout;
  51. String _local_clipboard;
  52. uint64_t _msec_splash;
  53. bool _no_window;
  54. int _exit_code = EXIT_FAILURE; // unexpected exit is marked as failure
  55. bool _is_custom_exit_code = false;
  56. int _orientation;
  57. bool _allow_hidpi;
  58. bool _allow_layered;
  59. bool _use_vsync;
  60. bool _vsync_via_compositor;
  61. char *last_error;
  62. void *_stack_bottom;
  63. CompositeLogger *_logger;
  64. bool restart_on_exit;
  65. List<String> restart_commandline;
  66. protected:
  67. void _set_logger(CompositeLogger *p_logger);
  68. public:
  69. typedef void (*ImeCallback)(void *p_inp, String p_text, Point2 p_selection);
  70. typedef bool (*HasServerFeatureCallback)(const String &p_feature);
  71. enum PowerState {
  72. POWERSTATE_UNKNOWN, /**< cannot determine power status */
  73. POWERSTATE_ON_BATTERY, /**< Not plugged in, running on the battery */
  74. POWERSTATE_NO_BATTERY, /**< Plugged in, no battery available */
  75. POWERSTATE_CHARGING, /**< Plugged in, charging battery */
  76. POWERSTATE_CHARGED /**< Plugged in, battery charged */
  77. };
  78. enum RenderThreadMode {
  79. RENDER_THREAD_UNSAFE,
  80. RENDER_THREAD_SAFE,
  81. RENDER_SEPARATE_THREAD
  82. };
  83. struct VideoMode {
  84. int width, height;
  85. bool fullscreen;
  86. bool resizable;
  87. bool borderless_window;
  88. bool maximized;
  89. bool always_on_top;
  90. bool use_vsync;
  91. bool vsync_via_compositor;
  92. bool layered;
  93. float get_aspect() const { return (float)width / (float)height; }
  94. VideoMode(int p_width = 1024, int p_height = 600, bool p_fullscreen = false, bool p_resizable = true, bool p_borderless_window = false, bool p_maximized = false, bool p_always_on_top = false, bool p_use_vsync = false, bool p_vsync_via_compositor = false) {
  95. width = p_width;
  96. height = p_height;
  97. fullscreen = p_fullscreen;
  98. resizable = p_resizable;
  99. borderless_window = p_borderless_window;
  100. maximized = p_maximized;
  101. always_on_top = p_always_on_top;
  102. use_vsync = p_use_vsync;
  103. vsync_via_compositor = p_vsync_via_compositor;
  104. layered = false;
  105. }
  106. };
  107. protected:
  108. friend class Main;
  109. HasServerFeatureCallback has_server_feature_callback;
  110. RenderThreadMode _render_thread_mode;
  111. // functions used by main to initialize/deinitialize the OS
  112. void add_logger(Logger *p_logger);
  113. virtual void initialize_core() = 0;
  114. virtual Error initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) = 0;
  115. virtual void set_main_loop(MainLoop *p_main_loop) = 0;
  116. virtual void delete_main_loop() = 0;
  117. virtual void finalize() = 0;
  118. virtual void finalize_core() = 0;
  119. virtual void set_cmdline(const char *p_execpath, const List<String> &p_args);
  120. virtual bool _check_internal_feature_support(const String &p_feature) = 0;
  121. public:
  122. typedef int64_t ProcessID;
  123. static OS *get_singleton();
  124. virtual void global_menu_add_item(const String &p_menu, const String &p_label, const Variant &p_signal, const Variant &p_meta){};
  125. virtual void global_menu_add_separator(const String &p_menu){};
  126. virtual void global_menu_remove_item(const String &p_menu, int p_idx){};
  127. virtual void global_menu_clear(const String &p_menu){};
  128. void print_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, Logger::ErrorType p_type = Logger::ERR_ERROR);
  129. void print(const char *p_format, ...) _PRINTF_FORMAT_ATTRIBUTE_2_3;
  130. void printerr(const char *p_format, ...) _PRINTF_FORMAT_ATTRIBUTE_2_3;
  131. virtual void alert(const String &p_alert, const String &p_title = "ALERT!") = 0;
  132. virtual String get_stdin_string(bool p_block = true) = 0;
  133. enum MouseMode {
  134. MOUSE_MODE_VISIBLE,
  135. MOUSE_MODE_HIDDEN,
  136. MOUSE_MODE_CAPTURED,
  137. MOUSE_MODE_CONFINED
  138. };
  139. virtual void set_mouse_mode(MouseMode p_mode);
  140. virtual MouseMode get_mouse_mode() const;
  141. virtual void warp_mouse_position(const Point2 &p_to) {}
  142. virtual Point2 get_mouse_position() const = 0;
  143. virtual int get_mouse_button_state() const = 0;
  144. virtual void set_window_title(const String &p_title) = 0;
  145. virtual void set_window_mouse_passthrough(const PoolVector2Array &p_region){};
  146. virtual void set_clipboard(const String &p_text);
  147. virtual String get_clipboard() const;
  148. virtual void set_video_mode(const VideoMode &p_video_mode, int p_screen = 0) = 0;
  149. virtual VideoMode get_video_mode(int p_screen = 0) const = 0;
  150. virtual void get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen = 0) const = 0;
  151. enum VideoDriver {
  152. VIDEO_DRIVER_GLES3,
  153. VIDEO_DRIVER_GLES2,
  154. VIDEO_DRIVER_MAX,
  155. };
  156. virtual int get_video_driver_count() const;
  157. virtual const char *get_video_driver_name(int p_driver) const;
  158. virtual int get_current_video_driver() const = 0;
  159. virtual int get_audio_driver_count() const;
  160. virtual const char *get_audio_driver_name(int p_driver) const;
  161. virtual int get_tablet_driver_count() const { return 0; };
  162. virtual String get_tablet_driver_name(int p_driver) const { return ""; };
  163. virtual String get_current_tablet_driver() const { return ""; };
  164. virtual void set_current_tablet_driver(const String &p_driver){};
  165. virtual PoolStringArray get_connected_midi_inputs();
  166. virtual void open_midi_inputs();
  167. virtual void close_midi_inputs();
  168. virtual int get_screen_count() const { return 1; }
  169. virtual int get_current_screen() const { return 0; }
  170. virtual void set_current_screen(int p_screen) {}
  171. virtual Point2 get_screen_position(int p_screen = -1) const { return Point2(); }
  172. virtual Size2 get_screen_size(int p_screen = -1) const { return get_window_size(); }
  173. virtual int get_screen_dpi(int p_screen = -1) const { return 72; }
  174. virtual float get_screen_scale(int p_screen = -1) const { return 1.0; }
  175. virtual float get_screen_max_scale() const { return 1.0; };
  176. virtual Point2 get_window_position() const { return Vector2(); }
  177. virtual void set_window_position(const Point2 &p_position) {}
  178. virtual Size2 get_max_window_size() const { return Size2(); };
  179. virtual Size2 get_min_window_size() const { return Size2(); };
  180. virtual Size2 get_window_size() const = 0;
  181. virtual Size2 get_real_window_size() const { return get_window_size(); }
  182. virtual void set_min_window_size(const Size2 p_size) {}
  183. virtual void set_max_window_size(const Size2 p_size) {}
  184. virtual void set_window_size(const Size2 p_size) {}
  185. virtual void set_window_fullscreen(bool p_enabled) {}
  186. virtual bool is_window_fullscreen() const { return true; }
  187. virtual void set_window_resizable(bool p_enabled) {}
  188. virtual bool is_window_resizable() const { return false; }
  189. virtual void set_window_minimized(bool p_enabled) {}
  190. virtual bool is_window_minimized() const { return false; }
  191. virtual void set_window_maximized(bool p_enabled) {}
  192. virtual bool is_window_maximized() const { return true; }
  193. virtual void set_window_always_on_top(bool p_enabled) {}
  194. virtual bool is_window_always_on_top() const { return false; }
  195. virtual bool is_window_focused() const { return true; }
  196. virtual void set_console_visible(bool p_enabled) {}
  197. virtual bool is_console_visible() const { return false; }
  198. virtual void request_attention() {}
  199. virtual void center_window();
  200. // Returns internal pointers and handles.
  201. // While exposed to GDScript this is mostly to give GDNative plugins access to this information.
  202. // Note that whether a valid handle is returned depends on whether it applies to the given
  203. // platform and often to the chosen render driver.
  204. // NULL will be returned if a handle is not available.
  205. enum HandleType {
  206. APPLICATION_HANDLE, // HINSTANCE, NSApplication*, UIApplication*, JNIEnv* ...
  207. DISPLAY_HANDLE, // X11::Display* ...
  208. WINDOW_HANDLE, // HWND, X11::Window*, NSWindow*, UIWindow*, Android activity ...
  209. WINDOW_VIEW, // HDC, NSView*, UIView*, Android surface ...
  210. OPENGL_CONTEXT, // HGLRC, X11::GLXContext, NSOpenGLContext*, EGLContext* ...
  211. };
  212. virtual void *get_native_handle(int p_handle_type) { return NULL; };
  213. // Returns window area free of hardware controls and other obstacles.
  214. // The application should use this to determine where to place UI elements.
  215. //
  216. // Keep in mind the area returned is in window coordinates rather than
  217. // viewport coordinates - you should perform the conversion on your own.
  218. //
  219. // The maximum size of the area is Rect2(0, 0, window_size.width, window_size.height).
  220. virtual Rect2 get_window_safe_area() const {
  221. Size2 window_size = get_window_size();
  222. return Rect2(0, 0, window_size.width, window_size.height);
  223. }
  224. virtual void set_borderless_window(bool p_borderless) {}
  225. virtual bool get_borderless_window() { return 0; }
  226. virtual bool get_window_per_pixel_transparency_enabled() const { return false; }
  227. virtual void set_window_per_pixel_transparency_enabled(bool p_enabled) {}
  228. virtual void set_ime_active(const bool p_active) {}
  229. virtual void set_ime_position(const Point2 &p_pos) {}
  230. virtual Point2 get_ime_selection() const { return Point2(); }
  231. virtual String get_ime_text() const { return String(); }
  232. virtual Error open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path = false) { return ERR_UNAVAILABLE; }
  233. virtual Error close_dynamic_library(void *p_library_handle) { return ERR_UNAVAILABLE; }
  234. virtual Error get_dynamic_library_symbol_handle(void *p_library_handle, const String p_name, void *&p_symbol_handle, bool p_optional = false) { return ERR_UNAVAILABLE; }
  235. virtual void set_keep_screen_on(bool p_enabled);
  236. virtual bool is_keep_screen_on() const;
  237. virtual void set_low_processor_usage_mode(bool p_enabled);
  238. virtual bool is_in_low_processor_usage_mode() const;
  239. virtual void set_low_processor_usage_mode_sleep_usec(int p_usec);
  240. virtual int get_low_processor_usage_mode_sleep_usec() const;
  241. virtual String get_executable_path() const;
  242. virtual Error execute(const String &p_path, const List<String> &p_arguments, bool p_blocking = true, ProcessID *r_child_id = NULL, String *r_pipe = NULL, int *r_exitcode = NULL, bool read_stderr = false, Mutex *p_pipe_mutex = NULL) = 0;
  243. virtual Error kill(const ProcessID &p_pid) = 0;
  244. virtual int get_process_id() const;
  245. virtual void vibrate_handheld(int p_duration_ms = 500);
  246. virtual Error shell_open(String p_uri);
  247. virtual Error set_cwd(const String &p_cwd);
  248. virtual bool has_environment(const String &p_var) const = 0;
  249. virtual String get_environment(const String &p_var) const = 0;
  250. virtual bool set_environment(const String &p_var, const String &p_value) const = 0;
  251. virtual String get_name() const = 0;
  252. virtual List<String> get_cmdline_args() const { return _cmdline; }
  253. virtual String get_model_name() const;
  254. void ensure_user_data_dir();
  255. virtual MainLoop *get_main_loop() const = 0;
  256. virtual void yield();
  257. enum Weekday {
  258. DAY_SUNDAY,
  259. DAY_MONDAY,
  260. DAY_TUESDAY,
  261. DAY_WEDNESDAY,
  262. DAY_THURSDAY,
  263. DAY_FRIDAY,
  264. DAY_SATURDAY
  265. };
  266. enum Month {
  267. /// Start at 1 to follow Windows SYSTEMTIME structure
  268. /// https://msdn.microsoft.com/en-us/library/windows/desktop/ms724950(v=vs.85).aspx
  269. MONTH_JANUARY = 1,
  270. MONTH_FEBRUARY,
  271. MONTH_MARCH,
  272. MONTH_APRIL,
  273. MONTH_MAY,
  274. MONTH_JUNE,
  275. MONTH_JULY,
  276. MONTH_AUGUST,
  277. MONTH_SEPTEMBER,
  278. MONTH_OCTOBER,
  279. MONTH_NOVEMBER,
  280. MONTH_DECEMBER
  281. };
  282. struct Date {
  283. int year;
  284. Month month;
  285. int day;
  286. Weekday weekday;
  287. bool dst;
  288. };
  289. struct Time {
  290. int hour;
  291. int min;
  292. int sec;
  293. };
  294. struct TimeZoneInfo {
  295. int bias;
  296. String name;
  297. };
  298. virtual Date get_date(bool local = false) const = 0;
  299. virtual Time get_time(bool local = false) const = 0;
  300. virtual TimeZoneInfo get_time_zone_info() const = 0;
  301. virtual String get_iso_date_time(bool local = false) const;
  302. virtual uint64_t get_unix_time() const;
  303. virtual uint64_t get_system_time_secs() const;
  304. virtual uint64_t get_system_time_msecs() const;
  305. virtual void delay_usec(uint32_t p_usec) const = 0;
  306. virtual void add_frame_delay(bool p_can_draw);
  307. virtual uint64_t get_ticks_usec() const = 0;
  308. uint32_t get_ticks_msec() const;
  309. uint64_t get_splash_tick_msec() const;
  310. virtual bool can_draw() const = 0;
  311. virtual bool is_userfs_persistent() const { return true; }
  312. bool is_stdout_verbose() const;
  313. bool is_stdout_debug_enabled() const;
  314. virtual void disable_crash_handler() {}
  315. virtual bool is_disable_crash_handler() const { return false; }
  316. virtual void initialize_debugging() {}
  317. enum CursorShape {
  318. CURSOR_ARROW,
  319. CURSOR_IBEAM,
  320. CURSOR_POINTING_HAND,
  321. CURSOR_CROSS,
  322. CURSOR_WAIT,
  323. CURSOR_BUSY,
  324. CURSOR_DRAG,
  325. CURSOR_CAN_DROP,
  326. CURSOR_FORBIDDEN,
  327. CURSOR_VSIZE,
  328. CURSOR_HSIZE,
  329. CURSOR_BDIAGSIZE,
  330. CURSOR_FDIAGSIZE,
  331. CURSOR_MOVE,
  332. CURSOR_VSPLIT,
  333. CURSOR_HSPLIT,
  334. CURSOR_HELP,
  335. CURSOR_MAX
  336. };
  337. virtual bool has_virtual_keyboard() const;
  338. virtual void show_virtual_keyboard(const String &p_existing_text, const Rect2 &p_screen_rect = Rect2(), bool p_multiline = false, int p_max_input_length = -1, int p_cursor_start = -1, int p_cursor_end = -1);
  339. virtual void hide_virtual_keyboard();
  340. // returns height of the currently shown virtual keyboard (0 if keyboard is hidden)
  341. virtual int get_virtual_keyboard_height() const;
  342. virtual void set_cursor_shape(CursorShape p_shape);
  343. virtual CursorShape get_cursor_shape() const;
  344. virtual void set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot);
  345. virtual bool get_swap_ok_cancel() { return false; }
  346. virtual void dump_memory_to_file(const char *p_file);
  347. virtual void dump_resources_to_file(const char *p_file);
  348. virtual void print_resources_in_use(bool p_short = false);
  349. virtual void print_all_resources(String p_to_file = "");
  350. virtual uint64_t get_static_memory_usage() const;
  351. virtual uint64_t get_static_memory_peak_usage() const;
  352. virtual uint64_t get_dynamic_memory_usage() const;
  353. virtual uint64_t get_free_static_memory() const;
  354. RenderThreadMode get_render_thread_mode() const { return _render_thread_mode; }
  355. virtual String get_locale() const;
  356. String get_safe_dir_name(const String &p_dir_name, bool p_allow_dir_separator = false) const;
  357. virtual String get_godot_dir_name() const;
  358. virtual String get_data_path() const;
  359. virtual String get_config_path() const;
  360. virtual String get_cache_path() const;
  361. virtual String get_bundle_resource_dir() const;
  362. virtual String get_user_data_dir() const;
  363. virtual String get_resource_dir() const;
  364. enum SystemDir {
  365. SYSTEM_DIR_DESKTOP,
  366. SYSTEM_DIR_DCIM,
  367. SYSTEM_DIR_DOCUMENTS,
  368. SYSTEM_DIR_DOWNLOADS,
  369. SYSTEM_DIR_MOVIES,
  370. SYSTEM_DIR_MUSIC,
  371. SYSTEM_DIR_PICTURES,
  372. SYSTEM_DIR_RINGTONES,
  373. };
  374. virtual String get_system_dir(SystemDir p_dir, bool p_shared_storage = true) const;
  375. virtual Error move_to_trash(const String &p_path) { return FAILED; }
  376. virtual void set_no_window_mode(bool p_enable);
  377. virtual bool is_no_window_mode_enabled() const;
  378. virtual bool has_touchscreen_ui_hint() const;
  379. enum ScreenOrientation {
  380. SCREEN_LANDSCAPE,
  381. SCREEN_PORTRAIT,
  382. SCREEN_REVERSE_LANDSCAPE,
  383. SCREEN_REVERSE_PORTRAIT,
  384. SCREEN_SENSOR_LANDSCAPE,
  385. SCREEN_SENSOR_PORTRAIT,
  386. SCREEN_SENSOR,
  387. };
  388. virtual void set_screen_orientation(ScreenOrientation p_orientation);
  389. virtual ScreenOrientation get_screen_orientation() const;
  390. ScreenOrientation get_screen_orientation_from_string(const String &p_orientation) const;
  391. virtual void enable_for_stealing_focus(ProcessID pid) {}
  392. virtual void move_window_to_foreground() {}
  393. virtual void debug_break();
  394. virtual void release_rendering_thread();
  395. virtual void make_rendering_thread();
  396. virtual void swap_buffers();
  397. virtual void set_native_icon(const String &p_filename);
  398. virtual void set_icon(const Ref<Image> &p_icon);
  399. virtual int get_exit_code() const;
  400. virtual void set_exit_code(int p_code);
  401. virtual bool is_custom_exit_code();
  402. virtual int get_processor_count() const;
  403. virtual String get_unique_id() const;
  404. virtual Error native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track);
  405. virtual bool native_video_is_playing() const;
  406. virtual void native_video_pause();
  407. virtual void native_video_unpause();
  408. virtual void native_video_stop();
  409. virtual bool can_use_threads() const;
  410. virtual Error dialog_show(String p_title, String p_description, Vector<String> p_buttons, Object *p_obj, String p_callback);
  411. virtual Error dialog_input_text(String p_title, String p_description, String p_partial, Object *p_obj, String p_callback);
  412. enum LatinKeyboardVariant {
  413. LATIN_KEYBOARD_QWERTY,
  414. LATIN_KEYBOARD_QWERTZ,
  415. LATIN_KEYBOARD_AZERTY,
  416. LATIN_KEYBOARD_QZERTY,
  417. LATIN_KEYBOARD_DVORAK,
  418. LATIN_KEYBOARD_NEO,
  419. LATIN_KEYBOARD_COLEMAK,
  420. };
  421. virtual LatinKeyboardVariant get_latin_keyboard_variant() const;
  422. virtual int keyboard_get_layout_count() const;
  423. virtual int keyboard_get_current_layout() const;
  424. virtual void keyboard_set_current_layout(int p_index);
  425. virtual String keyboard_get_layout_language(int p_index) const;
  426. virtual String keyboard_get_layout_name(int p_index) const;
  427. virtual bool is_joy_known(int p_device);
  428. virtual String get_joy_guid(int p_device) const;
  429. enum EngineContext {
  430. CONTEXT_EDITOR,
  431. CONTEXT_PROJECTMAN,
  432. CONTEXT_ENGINE,
  433. };
  434. virtual void set_context(int p_context);
  435. //amazing hack because OpenGL needs this to be set on a separate thread..
  436. //also core can't access servers, so a callback must be used
  437. typedef void (*SwitchVSyncCallbackInThread)(bool);
  438. static SwitchVSyncCallbackInThread switch_vsync_function;
  439. void set_use_vsync(bool p_enable);
  440. bool is_vsync_enabled() const;
  441. //real, actual overridable function to switch vsync, which needs to be called from graphics thread if needed
  442. virtual void _set_use_vsync(bool p_enable) {}
  443. void set_vsync_via_compositor(bool p_enable);
  444. bool is_vsync_via_compositor_enabled() const;
  445. virtual OS::PowerState get_power_state();
  446. virtual int get_power_seconds_left();
  447. virtual int get_power_percent_left();
  448. virtual void force_process_input(){};
  449. bool has_feature(const String &p_feature);
  450. void set_has_server_feature_callback(HasServerFeatureCallback p_callback);
  451. bool is_layered_allowed() const { return _allow_layered; }
  452. bool is_hidpi_allowed() const { return _allow_hidpi; }
  453. void set_restart_on_exit(bool p_restart, const List<String> &p_restart_arguments);
  454. bool is_restart_on_exit_set() const;
  455. List<String> get_restart_on_exit_arguments() const;
  456. virtual bool request_permission(const String &p_name) { return true; }
  457. virtual bool request_permissions() { return true; }
  458. virtual Vector<String> get_granted_permissions() const { return Vector<String>(); }
  459. virtual void process_and_drop_events() {}
  460. OS();
  461. virtual ~OS();
  462. };
  463. VARIANT_ENUM_CAST(OS::PowerState);
  464. #endif