os.h 21 KB

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