Debian Codegraph @

platform/macos/os_macos.h

raw symbols SCIP
1 /**************************************************************************/
2 /* os_macos.h */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
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
31 #pragma once
32
33 #include "crash_handler_macos.h"
34
35 #include "core/input/input.h"
36 #import "drivers/coreaudio/audio_driver_coreaudio.h"
37 #import "drivers/coremidi/midi_driver_coremidi.h"
38 #include "drivers/unix/os_unix.h"
39 #include "servers/audio/audio_server.h"
40
41 class JoypadSDL;
42
43 class OS_MacOS : public OS_Unix {
44 #ifdef COREAUDIO_ENABLED
45 AudioDriverCoreAudio audio_driver;
46 #endif
47 #ifdef COREMIDI_ENABLED
48 MIDIDriverCoreMidi midi_driver;
49 #endif
50
51 CrashHandler crash_handler;
52
53 List<String> launch_service_args;
54
55 CGFloat _weight_to_ct(int p_weight) const;
56 CGFloat _stretch_to_ct(int p_stretch) const;
57 String _get_default_fontname(const String &p_font_name) const;
58
59 static _FORCE_INLINE_ String get_framework_executable(const String &p_path);
60
61 protected:
62 const char *execpath = nullptr;
63 int argc = 0;
64 char **argv = nullptr;
65
66 #ifdef SDL_ENABLED
67 JoypadSDL *joypad_sdl = nullptr;
68 #endif
69 MainLoop *main_loop = nullptr;
70 CFRunLoopTimerRef wait_timer = nil;
71
72 virtual void initialize_core() override;
73 virtual void initialize() override;
74 virtual void finalize() override;
75
76 virtual void initialize_joypads() override;
77
78 virtual void set_main_loop(MainLoop *p_main_loop) override;
79 virtual void delete_main_loop() override;
80
81 public:
82 static inline const char *headless_args[] = {
83 "--headless",
84 "-h",
85 "--help",
86 "/?",
87 "--version",
88 "--dump-gdextension-interface",
89 "--dump-extension-api",
90 "--dump-gdextension-interface-json",
91 "--dump-extension-api-with-docs",
92 "--validate-extension-api",
93 "--convert-3to4",
94 "--validate-conversion-3to4",
95 "--doctool",
96 "--test",
97 };
98
99 virtual void add_frame_delay(bool p_can_draw, bool p_wake_for_events) override;
100
101 virtual void set_cmdline_platform_args(const List<String> &p_args);
102 virtual List<String> get_cmdline_platform_args() const override;
103
104 virtual void load_shell_environment() const override;
105
106 virtual String get_name() const override;
107 virtual String get_distribution_name() const override;
108 virtual String get_version() const override;
109 virtual String get_version_alias() const override;
110
111 virtual void alert(const String &p_alert, const String &p_title = "ALERT!") override;
112
113 virtual Error open_dynamic_library(const String &p_path, void *&p_library_handle, GDExtensionData *p_data = nullptr) override;
114
115 virtual MainLoop *get_main_loop() const override;
116
117 virtual String get_config_path() const override;
118 virtual String get_data_path() const override;
119 virtual String get_cache_path() const override;
120 virtual String get_temp_path() const override;
121 virtual String get_bundle_resource_dir() const override;
122 virtual String get_bundle_icon_path() const override;
123 virtual String get_bundle_icon_name() const override;
124 virtual String get_godot_dir_name() const override;
125
126 virtual String get_system_dir(SystemDir p_dir, bool p_shared_storage = true) const override;
127
128 virtual Error shell_open(const String &p_uri) override;
129 virtual Error shell_show_in_file_manager(String p_path, bool p_open_folder) override;
130
131 virtual String get_locale() const override;
132
133 virtual Vector<String> get_system_fonts() const override;
134 virtual String get_system_font_path(const String &p_font_name, int p_weight = 400, int p_stretch = 100, bool p_italic = false) const override;
135 virtual Vector<String> get_system_font_path_for_text(const String &p_font_name, const String &p_text, const String &p_locale = String(), const String &p_script = String(), int p_weight = 400, int p_stretch = 100, bool p_italic = false) const override;
136 virtual String get_executable_path() const override;
137 virtual Error create_process(const String &p_path, const List<String> &p_arguments, ProcessID *r_child_id = nullptr, bool p_open_console = false) override;
138 virtual Error create_instance(const List<String> &p_arguments, ProcessID *r_child_id = nullptr) override;
139 virtual Error open_with_program(const String &p_program_path, const List<String> &p_paths) override;
140 virtual bool is_process_running(const ProcessID &p_pid) const override;
141
142 virtual String get_unique_id() const override;
143 virtual String get_processor_name() const override;
144
145 virtual String get_model_name() const override;
146
147 virtual bool is_sandboxed() const override;
148 virtual bool request_permission(const String &p_name) override;
149 virtual Vector<String> get_granted_permissions() const override;
150 virtual void revoke_granted_permissions() override;
151
152 #ifdef TOOLS_ENABLED
153 static bool is_debugger_attached();
154 void wait_for_debugger(uint32_t p_msec);
155 #endif
156
157 virtual bool _check_internal_feature_support(const String &p_feature) override;
158
159 virtual void disable_crash_handler() override;
160 virtual bool is_disable_crash_handler() const override;
161
162 virtual Error move_to_trash(const String &p_path) override;
163
164 virtual String get_system_ca_certificates() override;
165 virtual OS::PreferredTextureFormat get_preferred_texture_format() const override;
166
167 virtual void run() = 0;
168
169 OS_MacOS(const char *p_execpath, int p_argc, char **p_argv);
170 };
171
172 class OS_MacOS_NSApp : public OS_MacOS {
173 id delegate = nullptr;
174 bool should_terminate = false;
175 bool main_started = false;
176
177 CFRunLoopObserverRef pre_wait_observer = nil;
178
179 void terminate();
180
181 public:
182 void start_main(); // Initializes and runs Godot main loop.
183 void cleanup();
184 bool os_should_terminate() const { return should_terminate; }
185 int get_cmd_argc() const { return argc; }
186
187 virtual void run() override;
188
189 OS_MacOS_NSApp(const char *p_execpath, int p_argc, char **p_argv);
190 };
191
192 class OS_MacOS_Headless : public OS_MacOS {
193 public:
194 virtual void run() override;
195
196 OS_MacOS_Headless(const char *p_execpath, int p_argc, char **p_argv);
197 };
198
199 #ifdef TOOLS_ENABLED
200
201 class OS_MacOS_Embedded : public OS_MacOS {
202 public:
203 virtual void run() override;
204
205 OS_MacOS_Embedded(const char *p_execpath, int p_argc, char **p_argv);
206 };
207
208 #endif