Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/platform/linuxbsd/os_linuxbsd.cpp
11351 views
1
/**************************************************************************/
2
/* os_linuxbsd.cpp */
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
#include "os_linuxbsd.h"
32
33
#include "core/io/certs_compressed.gen.h"
34
#include "core/io/dir_access.h"
35
#include "core/io/file_access.h"
36
#include "core/os/main_loop.h"
37
#ifdef SDL_ENABLED
38
#include "drivers/sdl/joypad_sdl.h"
39
#endif
40
#include "main/main.h"
41
#include "servers/display/display_server.h"
42
#include "servers/rendering/rendering_server.h"
43
44
#ifdef X11_ENABLED
45
#include "x11/detect_prime_x11.h"
46
#include "x11/display_server_x11.h"
47
#endif
48
49
#ifdef WAYLAND_ENABLED
50
#include "wayland/detect_prime_egl.h"
51
#include "wayland/display_server_wayland.h"
52
#endif
53
54
#include "modules/modules_enabled.gen.h" // For regex.
55
#ifdef MODULE_REGEX_ENABLED
56
#include "modules/regex/regex.h"
57
#endif
58
59
#if defined(RD_ENABLED)
60
#include "servers/rendering/rendering_device.h"
61
#endif
62
63
#if defined(VULKAN_ENABLED)
64
#ifdef X11_ENABLED
65
#include "x11/rendering_context_driver_vulkan_x11.h"
66
#endif
67
#ifdef WAYLAND_ENABLED
68
#include "wayland/rendering_context_driver_vulkan_wayland.h"
69
#endif
70
#endif
71
#if defined(GLES3_ENABLED)
72
#include "drivers/gles3/rasterizer_gles3.h"
73
#endif
74
75
#include <dlfcn.h>
76
#include <sys/stat.h>
77
#include <sys/types.h>
78
#include <sys/utsname.h>
79
#include <unistd.h>
80
#include <cstdio>
81
#include <cstdlib>
82
83
#if __has_include(<mntent.h>)
84
#include <mntent.h>
85
#endif
86
87
#if defined(__FreeBSD__)
88
#include <sys/sysctl.h>
89
#endif
90
91
void OS_LinuxBSD::alert(const String &p_alert, const String &p_title) {
92
const char *message_programs[] = { "zenity", "kdialog", "Xdialog", "xmessage" };
93
94
String path = get_environment("PATH");
95
Vector<String> path_elems = path.split(":", false);
96
String program;
97
98
for (int i = 0; i < path_elems.size(); i++) {
99
for (uint64_t k = 0; k < std_size(message_programs); k++) {
100
String tested_path = path_elems[i].path_join(message_programs[k]);
101
102
if (FileAccess::exists(tested_path)) {
103
program = tested_path;
104
break;
105
}
106
}
107
108
if (program.length()) {
109
break;
110
}
111
}
112
113
List<String> args;
114
115
if (program.ends_with("zenity")) {
116
args.push_back("--warning");
117
args.push_back("--width");
118
args.push_back("500");
119
args.push_back("--title");
120
args.push_back(p_title);
121
args.push_back("--text");
122
args.push_back(p_alert);
123
}
124
125
if (program.ends_with("kdialog")) {
126
// `--sorry` uses the same icon as `--warning` in Zenity.
127
// As of KDialog 22.12.1, its `--warning` options are only available for yes/no questions.
128
args.push_back("--sorry");
129
args.push_back(p_alert);
130
args.push_back("--title");
131
args.push_back(p_title);
132
}
133
134
if (program.ends_with("Xdialog")) {
135
args.push_back("--title");
136
args.push_back(p_title);
137
args.push_back("--msgbox");
138
args.push_back(p_alert);
139
args.push_back("0");
140
args.push_back("0");
141
}
142
143
if (program.ends_with("xmessage")) {
144
args.push_back("-center");
145
args.push_back("-title");
146
args.push_back(p_title);
147
args.push_back(p_alert);
148
}
149
150
if (program.length()) {
151
execute(program, args);
152
} else {
153
print_line(p_alert);
154
}
155
}
156
157
void OS_LinuxBSD::initialize() {
158
crash_handler.initialize();
159
160
OS_Unix::initialize_core();
161
162
system_dir_desktop_cache = get_system_dir(SYSTEM_DIR_DESKTOP);
163
}
164
165
void OS_LinuxBSD::initialize_joypads() {
166
#ifdef SDL_ENABLED
167
joypad_sdl = memnew(JoypadSDL());
168
if (joypad_sdl->initialize() != OK) {
169
ERR_PRINT("Couldn't initialize SDL joypad input driver.");
170
memdelete(joypad_sdl);
171
joypad_sdl = nullptr;
172
}
173
#endif
174
}
175
176
String OS_LinuxBSD::get_unique_id() const {
177
static String machine_id;
178
if (machine_id.is_empty()) {
179
#if defined(__FreeBSD__)
180
const int mib[2] = { CTL_KERN, KERN_HOSTUUID };
181
char buf[4096];
182
memset(buf, 0, sizeof(buf));
183
size_t len = sizeof(buf) - 1;
184
if (sysctl(mib, 2, buf, &len, 0x0, 0) != -1) {
185
machine_id = String::utf8(buf).remove_char('-');
186
}
187
#else
188
Ref<FileAccess> f = FileAccess::open("/etc/machine-id", FileAccess::READ);
189
if (f.is_valid()) {
190
while (machine_id.is_empty() && !f->eof_reached()) {
191
machine_id = f->get_line().strip_edges();
192
}
193
}
194
#endif
195
}
196
return machine_id;
197
}
198
199
String OS_LinuxBSD::get_processor_name() const {
200
#if defined(__FreeBSD__)
201
const int mib[2] = { CTL_HW, HW_MODEL };
202
char buf[4096];
203
memset(buf, 0, sizeof(buf));
204
size_t len = sizeof(buf) - 1;
205
if (sysctl(mib, 2, buf, &len, 0x0, 0) != -1) {
206
return String::utf8(buf);
207
}
208
#else
209
Ref<FileAccess> f = FileAccess::open("/proc/cpuinfo", FileAccess::READ);
210
ERR_FAIL_COND_V_MSG(f.is_null(), "", String("Couldn't open `/proc/cpuinfo` to get the CPU model name. Returning an empty string."));
211
212
while (!f->eof_reached()) {
213
const String line = f->get_line();
214
if (line.to_lower().contains("model name")) {
215
return line.get_slicec(':', 1).strip_edges();
216
}
217
}
218
#endif
219
220
ERR_FAIL_V_MSG("", String("Couldn't get the CPU model. Returning an empty string."));
221
}
222
223
bool OS_LinuxBSD::is_sandboxed() const {
224
// This function is derived from SDL:
225
// https://github.com/libsdl-org/SDL/blob/main/src/core/linux/SDL_sandbox.c#L28-L45
226
227
if (access("/.flatpak-info", F_OK) == 0) {
228
return true;
229
}
230
231
// For Snap, we check multiple variables because they might be set for
232
// unrelated reasons. This is the same thing WebKitGTK does.
233
if (has_environment("SNAP") && has_environment("SNAP_NAME") && has_environment("SNAP_REVISION")) {
234
return true;
235
}
236
237
if (access("/run/host/container-manager", F_OK) == 0) {
238
return true;
239
}
240
241
return false;
242
}
243
244
void OS_LinuxBSD::finalize() {
245
if (main_loop) {
246
memdelete(main_loop);
247
}
248
main_loop = nullptr;
249
250
#ifdef ALSAMIDI_ENABLED
251
driver_alsamidi.close();
252
#endif
253
254
#ifdef SDL_ENABLED
255
if (joypad_sdl) {
256
memdelete(joypad_sdl);
257
}
258
#endif
259
}
260
261
MainLoop *OS_LinuxBSD::get_main_loop() const {
262
return main_loop;
263
}
264
265
void OS_LinuxBSD::delete_main_loop() {
266
if (main_loop) {
267
memdelete(main_loop);
268
}
269
main_loop = nullptr;
270
}
271
272
void OS_LinuxBSD::set_main_loop(MainLoop *p_main_loop) {
273
main_loop = p_main_loop;
274
}
275
276
String OS_LinuxBSD::get_identifier() const {
277
return "linuxbsd";
278
}
279
280
String OS_LinuxBSD::get_name() const {
281
#ifdef __linux__
282
return "Linux";
283
#elif defined(__FreeBSD__)
284
return "FreeBSD";
285
#elif defined(__NetBSD__)
286
return "NetBSD";
287
#elif defined(__OpenBSD__)
288
return "OpenBSD";
289
#else
290
return "BSD";
291
#endif
292
}
293
294
String OS_LinuxBSD::get_systemd_os_release_info_value(const String &key) const {
295
Ref<FileAccess> f = FileAccess::open("/etc/os-release", FileAccess::READ);
296
if (f.is_valid()) {
297
while (!f->eof_reached()) {
298
const String line = f->get_line();
299
if (line.contains(key)) {
300
String value = line.get_slicec('=', 1).strip_edges();
301
value = value.trim_prefix("\"");
302
return value.trim_suffix("\"");
303
}
304
}
305
}
306
return "";
307
}
308
309
String OS_LinuxBSD::get_distribution_name() const {
310
static String distribution_name = get_systemd_os_release_info_value("NAME"); // returns a value for systemd users, otherwise an empty string.
311
if (!distribution_name.is_empty()) {
312
return distribution_name;
313
}
314
struct utsname uts; // returns a decent value for BSD family.
315
uname(&uts);
316
distribution_name = uts.sysname;
317
return distribution_name;
318
}
319
320
String OS_LinuxBSD::get_version() const {
321
static String release_version = get_systemd_os_release_info_value("VERSION"); // returns a value for systemd users, otherwise an empty string.
322
if (!release_version.is_empty()) {
323
return release_version;
324
}
325
struct utsname uts; // returns a decent value for BSD family.
326
uname(&uts);
327
release_version = uts.version;
328
return release_version;
329
}
330
331
Vector<String> OS_LinuxBSD::get_video_adapter_driver_info() const {
332
if (RenderingServer::get_singleton() == nullptr) {
333
return Vector<String>();
334
}
335
336
static Vector<String> info;
337
if (!info.is_empty()) {
338
return info;
339
}
340
341
const String rendering_device_name = RenderingServer::get_singleton()->get_video_adapter_name(); // e.g. `NVIDIA GeForce GTX 970`
342
const String rendering_device_vendor = RenderingServer::get_singleton()->get_video_adapter_vendor(); // e.g. `NVIDIA`
343
const String card_name = rendering_device_name.trim_prefix(rendering_device_vendor).strip_edges(); // -> `GeForce GTX 970`
344
345
String vendor_device_id_mappings;
346
List<String> lspci_args;
347
lspci_args.push_back("-n");
348
Error err = const_cast<OS_LinuxBSD *>(this)->execute("lspci", lspci_args, &vendor_device_id_mappings);
349
if (err != OK || vendor_device_id_mappings.is_empty()) {
350
return Vector<String>();
351
}
352
353
// Usually found under "VGA", but for example NVIDIA mobile/laptop adapters are often listed under "3D" and some AMD adapters are under "Display".
354
const String dc_vga = "0300"; // VGA compatible controller
355
const String dc_display = "0302"; // Display controller
356
const String dc_3d = "0380"; // 3D controller
357
358
// splitting results by device class allows prioritizing, if multiple devices are found.
359
Vector<String> class_vga_device_candidates;
360
Vector<String> class_display_device_candidates;
361
Vector<String> class_3d_device_candidates;
362
363
#ifdef MODULE_REGEX_ENABLED
364
RegEx regex_id_format = RegEx();
365
regex_id_format.compile("^[a-f0-9]{4}:[a-f0-9]{4}$"); // e.g. `10de:13c2`; IDs are always in hexadecimal
366
#endif
367
368
Vector<String> value_lines = vendor_device_id_mappings.split("\n", false); // example: `02:00.0 0300: 10de:13c2 (rev a1)`
369
for (const String &line : value_lines) {
370
Vector<String> columns = line.split(" ", false);
371
if (columns.size() < 3) {
372
continue;
373
}
374
String device_class = columns[1].trim_suffix(":");
375
const String &vendor_device_id_mapping = columns[2];
376
377
#ifdef MODULE_REGEX_ENABLED
378
if (regex_id_format.search(vendor_device_id_mapping).is_null()) {
379
continue;
380
}
381
#endif
382
383
if (device_class == dc_vga) {
384
class_vga_device_candidates.push_back(vendor_device_id_mapping);
385
} else if (device_class == dc_display) {
386
class_display_device_candidates.push_back(vendor_device_id_mapping);
387
} else if (device_class == dc_3d) {
388
class_3d_device_candidates.push_back(vendor_device_id_mapping);
389
}
390
}
391
392
// Check results against currently used device (`card_name`), in case the user has multiple graphics cards.
393
const String device_lit = "Device"; // line of interest
394
class_vga_device_candidates = OS_LinuxBSD::lspci_device_filter(class_vga_device_candidates, dc_vga, device_lit, card_name);
395
class_display_device_candidates = OS_LinuxBSD::lspci_device_filter(class_display_device_candidates, dc_display, device_lit, card_name);
396
class_3d_device_candidates = OS_LinuxBSD::lspci_device_filter(class_3d_device_candidates, dc_3d, device_lit, card_name);
397
398
// Get driver names and filter out invalid ones, because some adapters are dummys used only for passthrough.
399
// And they have no indicator besides certain driver names.
400
const String kernel_lit = "Kernel driver in use"; // line of interest
401
const String dummys = "vfio"; // for e.g. pci passthrough dummy kernel driver `vfio-pci`
402
Vector<String> class_vga_device_drivers = OS_LinuxBSD::lspci_get_device_value(class_vga_device_candidates, kernel_lit, dummys);
403
Vector<String> class_display_device_drivers = OS_LinuxBSD::lspci_get_device_value(class_display_device_candidates, kernel_lit, dummys);
404
Vector<String> class_3d_device_drivers = OS_LinuxBSD::lspci_get_device_value(class_3d_device_candidates, kernel_lit, dummys);
405
406
String driver_name;
407
String driver_version;
408
409
// Use first valid value:
410
for (const String &driver : class_3d_device_drivers) {
411
driver_name = driver;
412
break;
413
}
414
if (driver_name.is_empty()) {
415
for (const String &driver : class_display_device_drivers) {
416
driver_name = driver;
417
break;
418
}
419
}
420
if (driver_name.is_empty()) {
421
for (const String &driver : class_vga_device_drivers) {
422
driver_name = driver;
423
break;
424
}
425
}
426
427
info.push_back(driver_name);
428
429
String modinfo;
430
List<String> modinfo_args;
431
modinfo_args.push_back(driver_name);
432
err = const_cast<OS_LinuxBSD *>(this)->execute("modinfo", modinfo_args, &modinfo);
433
if (err != OK || modinfo.is_empty()) {
434
info.push_back(""); // So that this method always either returns an empty array, or an array of length 2.
435
return info;
436
}
437
Vector<String> lines = modinfo.split("\n", false);
438
for (const String &line : lines) {
439
Vector<String> columns = line.split(":", false, 1);
440
if (columns.size() < 2) {
441
continue;
442
}
443
if (columns[0].strip_edges() == "version") {
444
driver_version = columns[1].strip_edges(); // example value: `510.85.02` on Linux/BSD
445
break;
446
}
447
}
448
449
info.push_back(driver_version);
450
451
return info;
452
}
453
454
Vector<String> OS_LinuxBSD::lspci_device_filter(Vector<String> vendor_device_id_mapping, String class_suffix, String check_column, String whitelist) const {
455
// NOTE: whitelist can be changed to `Vector<String>`, if the need arises.
456
const String sep = ":";
457
Vector<String> devices;
458
for (const String &mapping : vendor_device_id_mapping) {
459
String device;
460
List<String> d_args;
461
d_args.push_back("-d");
462
d_args.push_back(mapping + sep + class_suffix);
463
d_args.push_back("-vmm");
464
Error err = const_cast<OS_LinuxBSD *>(this)->execute("lspci", d_args, &device); // e.g. `lspci -d 10de:13c2:0300 -vmm`
465
if (err != OK) {
466
return Vector<String>();
467
} else if (device.is_empty()) {
468
continue;
469
}
470
471
Vector<String> device_lines = device.split("\n", false);
472
for (const String &line : device_lines) {
473
Vector<String> columns = line.split(":", false, 1);
474
if (columns.size() < 2) {
475
continue;
476
}
477
if (columns[0].strip_edges() == check_column) {
478
// for `column[0] == "Device"` this may contain `GM204 [GeForce GTX 970]`
479
bool is_valid = true;
480
if (!whitelist.is_empty()) {
481
is_valid = columns[1].strip_edges().contains(whitelist);
482
}
483
if (is_valid) {
484
devices.push_back(mapping);
485
}
486
break;
487
}
488
}
489
}
490
return devices;
491
}
492
493
Vector<String> OS_LinuxBSD::lspci_get_device_value(Vector<String> vendor_device_id_mapping, String check_column, String blacklist) const {
494
// NOTE: blacklist can be changed to `Vector<String>`, if the need arises.
495
const String sep = ":";
496
Vector<String> values;
497
for (const String &mapping : vendor_device_id_mapping) {
498
String device;
499
List<String> d_args;
500
d_args.push_back("-d");
501
d_args.push_back(mapping);
502
d_args.push_back("-k");
503
Error err = const_cast<OS_LinuxBSD *>(this)->execute("lspci", d_args, &device); // e.g. `lspci -d 10de:13c2 -k`
504
if (err != OK) {
505
return Vector<String>();
506
} else if (device.is_empty()) {
507
continue;
508
}
509
510
Vector<String> device_lines = device.split("\n", false);
511
for (const String &line : device_lines) {
512
Vector<String> columns = line.split(":", false, 1);
513
if (columns.size() < 2) {
514
continue;
515
}
516
if (columns[0].strip_edges() == check_column) {
517
// for `column[0] == "Kernel driver in use"` this may contain `nvidia`
518
bool is_valid = true;
519
const String value = columns[1].strip_edges();
520
if (!blacklist.is_empty()) {
521
is_valid = !value.contains(blacklist);
522
}
523
if (is_valid) {
524
values.push_back(value);
525
}
526
break;
527
}
528
}
529
}
530
return values;
531
}
532
533
Error OS_LinuxBSD::shell_open(const String &p_uri) {
534
Error ok;
535
int err_code;
536
List<String> args;
537
args.push_back(p_uri);
538
539
// Agnostic
540
ok = execute("xdg-open", args, nullptr, &err_code);
541
if (ok == OK && !err_code) {
542
return OK;
543
} else if (err_code == 2) {
544
return ERR_FILE_NOT_FOUND;
545
}
546
// GNOME
547
args.push_front("open"); // The command is `gio open`, so we need to add it to args
548
ok = execute("gio", args, nullptr, &err_code);
549
if (ok == OK && !err_code) {
550
return OK;
551
} else if (err_code == 2) {
552
return ERR_FILE_NOT_FOUND;
553
}
554
args.pop_front();
555
ok = execute("gvfs-open", args, nullptr, &err_code);
556
if (ok == OK && !err_code) {
557
return OK;
558
} else if (err_code == 2) {
559
return ERR_FILE_NOT_FOUND;
560
}
561
// KDE
562
ok = execute("kde-open5", args, nullptr, &err_code);
563
if (ok == OK && !err_code) {
564
return OK;
565
}
566
ok = execute("kde-open", args, nullptr, &err_code);
567
return !err_code ? ok : FAILED;
568
}
569
570
bool OS_LinuxBSD::_check_internal_feature_support(const String &p_feature) {
571
#ifdef FONTCONFIG_ENABLED
572
if (p_feature == "system_fonts") {
573
return font_config_initialized;
574
}
575
#endif
576
577
#ifndef __linux__
578
// `bsd` includes **all** BSD, not only "other BSD" (see `get_name()`).
579
if (p_feature == "bsd") {
580
return true;
581
}
582
#endif
583
584
if (p_feature == "pc") {
585
return true;
586
}
587
588
// Match against the specific OS (`linux`, `freebsd`, `netbsd`, `openbsd`).
589
if (p_feature == get_name().to_lower()) {
590
return true;
591
}
592
593
return false;
594
}
595
596
uint64_t OS_LinuxBSD::get_embedded_pck_offset() const {
597
Ref<FileAccess> f = FileAccess::open(get_executable_path(), FileAccess::READ);
598
if (f.is_null()) {
599
return 0;
600
}
601
602
// Read and check ELF magic number.
603
{
604
uint32_t magic = f->get_32();
605
if (magic != 0x464c457f) { // 0x7F + "ELF"
606
return 0;
607
}
608
}
609
610
// Read program architecture bits from class field.
611
int bits = f->get_8() * 32;
612
613
// Get info about the section header table.
614
int64_t section_table_pos;
615
int64_t section_header_size;
616
if (bits == 32) {
617
section_header_size = 40;
618
f->seek(0x20);
619
section_table_pos = f->get_32();
620
f->seek(0x30);
621
} else { // 64
622
section_header_size = 64;
623
f->seek(0x28);
624
section_table_pos = f->get_64();
625
f->seek(0x3c);
626
}
627
int num_sections = f->get_16();
628
int string_section_idx = f->get_16();
629
630
// Load the strings table.
631
uint8_t *strings;
632
{
633
// Jump to the strings section header.
634
f->seek(section_table_pos + string_section_idx * section_header_size);
635
636
// Read strings data size and offset.
637
int64_t string_data_pos;
638
int64_t string_data_size;
639
if (bits == 32) {
640
f->seek(f->get_position() + 0x10);
641
string_data_pos = f->get_32();
642
string_data_size = f->get_32();
643
} else { // 64
644
f->seek(f->get_position() + 0x18);
645
string_data_pos = f->get_64();
646
string_data_size = f->get_64();
647
}
648
649
// Read strings data.
650
f->seek(string_data_pos);
651
strings = (uint8_t *)memalloc(string_data_size);
652
if (!strings) {
653
return 0;
654
}
655
f->get_buffer(strings, string_data_size);
656
}
657
658
// Search for the "pck" section.
659
int64_t off = 0;
660
for (int i = 0; i < num_sections; ++i) {
661
int64_t section_header_pos = section_table_pos + i * section_header_size;
662
f->seek(section_header_pos);
663
664
uint32_t name_offset = f->get_32();
665
if (strcmp((char *)strings + name_offset, "pck") == 0) {
666
if (bits == 32) {
667
f->seek(section_header_pos + 0x10);
668
off = f->get_32();
669
} else { // 64
670
f->seek(section_header_pos + 0x18);
671
off = f->get_64();
672
}
673
break;
674
}
675
}
676
memfree(strings);
677
678
return off;
679
}
680
681
Vector<String> OS_LinuxBSD::get_system_fonts() const {
682
#ifdef FONTCONFIG_ENABLED
683
if (!font_config_initialized) {
684
ERR_FAIL_V_MSG(Vector<String>(), "Unable to load fontconfig, system font support is disabled.");
685
}
686
687
HashSet<String> font_names;
688
Vector<String> ret;
689
static const char *allowed_formats[] = { "TrueType", "CFF" };
690
for (size_t i = 0; i < sizeof(allowed_formats) / sizeof(const char *); i++) {
691
FcPattern *pattern = FcPatternCreate();
692
ERR_CONTINUE(!pattern);
693
694
FcPatternAddBool(pattern, FC_SCALABLE, FcTrue);
695
FcPatternAddString(pattern, FC_FONTFORMAT, reinterpret_cast<const FcChar8 *>(allowed_formats[i]));
696
697
FcFontSet *font_set = FcFontList(config, pattern, object_set);
698
if (font_set) {
699
for (int j = 0; j < font_set->nfont; j++) {
700
char *family_name = nullptr;
701
if (FcPatternGetString(font_set->fonts[j], FC_FAMILY, 0, reinterpret_cast<FcChar8 **>(&family_name)) == FcResultMatch) {
702
if (family_name) {
703
font_names.insert(String::utf8(family_name));
704
}
705
}
706
}
707
FcFontSetDestroy(font_set);
708
}
709
FcPatternDestroy(pattern);
710
}
711
712
for (const String &E : font_names) {
713
ret.push_back(E);
714
}
715
return ret;
716
#else
717
ERR_FAIL_V_MSG(Vector<String>(), "Godot was compiled without fontconfig, system font support is disabled.");
718
#endif
719
}
720
721
#ifdef FONTCONFIG_ENABLED
722
int OS_LinuxBSD::_weight_to_fc(int p_weight) const {
723
if (p_weight < 150) {
724
return FC_WEIGHT_THIN;
725
} else if (p_weight < 250) {
726
return FC_WEIGHT_EXTRALIGHT;
727
} else if (p_weight < 325) {
728
return FC_WEIGHT_LIGHT;
729
} else if (p_weight < 375) {
730
return FC_WEIGHT_DEMILIGHT;
731
} else if (p_weight < 390) {
732
return FC_WEIGHT_BOOK;
733
} else if (p_weight < 450) {
734
return FC_WEIGHT_REGULAR;
735
} else if (p_weight < 550) {
736
return FC_WEIGHT_MEDIUM;
737
} else if (p_weight < 650) {
738
return FC_WEIGHT_DEMIBOLD;
739
} else if (p_weight < 750) {
740
return FC_WEIGHT_BOLD;
741
} else if (p_weight < 850) {
742
return FC_WEIGHT_EXTRABOLD;
743
} else if (p_weight < 925) {
744
return FC_WEIGHT_BLACK;
745
} else {
746
return FC_WEIGHT_EXTRABLACK;
747
}
748
}
749
750
int OS_LinuxBSD::_stretch_to_fc(int p_stretch) const {
751
if (p_stretch < 56) {
752
return FC_WIDTH_ULTRACONDENSED;
753
} else if (p_stretch < 69) {
754
return FC_WIDTH_EXTRACONDENSED;
755
} else if (p_stretch < 81) {
756
return FC_WIDTH_CONDENSED;
757
} else if (p_stretch < 93) {
758
return FC_WIDTH_SEMICONDENSED;
759
} else if (p_stretch < 106) {
760
return FC_WIDTH_NORMAL;
761
} else if (p_stretch < 137) {
762
return FC_WIDTH_SEMIEXPANDED;
763
} else if (p_stretch < 144) {
764
return FC_WIDTH_EXPANDED;
765
} else if (p_stretch < 162) {
766
return FC_WIDTH_EXTRAEXPANDED;
767
} else {
768
return FC_WIDTH_ULTRAEXPANDED;
769
}
770
}
771
#endif // FONTCONFIG_ENABLED
772
773
Vector<String> OS_LinuxBSD::get_system_font_path_for_text(const String &p_font_name, const String &p_text, const String &p_locale, const String &p_script, int p_weight, int p_stretch, bool p_italic) const {
774
#ifdef FONTCONFIG_ENABLED
775
if (!font_config_initialized) {
776
ERR_FAIL_V_MSG(Vector<String>(), "Unable to load fontconfig, system font support is disabled.");
777
}
778
779
Vector<String> ret;
780
static const char *allowed_formats[] = { "TrueType", "CFF" };
781
for (size_t i = 0; i < std_size(allowed_formats); i++) {
782
FcPattern *pattern = FcPatternCreate();
783
if (pattern) {
784
FcPatternAddBool(pattern, FC_SCALABLE, FcTrue);
785
FcPatternAddString(pattern, FC_FONTFORMAT, reinterpret_cast<const FcChar8 *>(allowed_formats[i]));
786
FcPatternAddString(pattern, FC_FAMILY, reinterpret_cast<const FcChar8 *>(p_font_name.utf8().get_data()));
787
FcPatternAddInteger(pattern, FC_WEIGHT, _weight_to_fc(p_weight));
788
FcPatternAddInteger(pattern, FC_WIDTH, _stretch_to_fc(p_stretch));
789
FcPatternAddInteger(pattern, FC_SLANT, p_italic ? FC_SLANT_ITALIC : FC_SLANT_ROMAN);
790
791
FcCharSet *char_set = FcCharSetCreate();
792
for (int j = 0; j < p_text.size(); j++) {
793
FcCharSetAddChar(char_set, p_text[j]);
794
}
795
FcPatternAddCharSet(pattern, FC_CHARSET, char_set);
796
797
FcLangSet *lang_set = FcLangSetCreate();
798
FcLangSetAdd(lang_set, reinterpret_cast<const FcChar8 *>(p_locale.utf8().get_data()));
799
FcPatternAddLangSet(pattern, FC_LANG, lang_set);
800
801
FcConfigSubstitute(nullptr, pattern, FcMatchPattern);
802
FcDefaultSubstitute(pattern);
803
804
FcResult result;
805
FcPattern *match = FcFontMatch(nullptr, pattern, &result);
806
if (match) {
807
char *file_name = nullptr;
808
if (FcPatternGetString(match, FC_FILE, 0, reinterpret_cast<FcChar8 **>(&file_name)) == FcResultMatch) {
809
if (file_name) {
810
ret.push_back(String::utf8(file_name));
811
}
812
}
813
FcPatternDestroy(match);
814
}
815
FcPatternDestroy(pattern);
816
FcCharSetDestroy(char_set);
817
FcLangSetDestroy(lang_set);
818
}
819
}
820
821
return ret;
822
#else
823
ERR_FAIL_V_MSG(Vector<String>(), "Godot was compiled without fontconfig, system font support is disabled.");
824
#endif
825
}
826
827
String OS_LinuxBSD::get_system_font_path(const String &p_font_name, int p_weight, int p_stretch, bool p_italic) const {
828
#ifdef FONTCONFIG_ENABLED
829
if (!font_config_initialized) {
830
ERR_FAIL_V_MSG(String(), "Unable to load fontconfig, system font support is disabled.");
831
}
832
833
static const char *allowed_formats[] = { "TrueType", "CFF" };
834
for (size_t i = 0; i < sizeof(allowed_formats) / sizeof(const char *); i++) {
835
FcPattern *pattern = FcPatternCreate();
836
if (pattern) {
837
bool allow_substitutes = (p_font_name.to_lower() == "sans-serif") || (p_font_name.to_lower() == "serif") || (p_font_name.to_lower() == "monospace") || (p_font_name.to_lower() == "cursive") || (p_font_name.to_lower() == "fantasy");
838
839
FcPatternAddBool(pattern, FC_SCALABLE, FcTrue);
840
FcPatternAddString(pattern, FC_FONTFORMAT, reinterpret_cast<const FcChar8 *>(allowed_formats[i]));
841
FcPatternAddString(pattern, FC_FAMILY, reinterpret_cast<const FcChar8 *>(p_font_name.utf8().get_data()));
842
FcPatternAddInteger(pattern, FC_WEIGHT, _weight_to_fc(p_weight));
843
FcPatternAddInteger(pattern, FC_WIDTH, _stretch_to_fc(p_stretch));
844
FcPatternAddInteger(pattern, FC_SLANT, p_italic ? FC_SLANT_ITALIC : FC_SLANT_ROMAN);
845
846
FcConfigSubstitute(nullptr, pattern, FcMatchPattern);
847
FcDefaultSubstitute(pattern);
848
849
FcResult result;
850
FcPattern *match = FcFontMatch(nullptr, pattern, &result);
851
if (match) {
852
if (!allow_substitutes) {
853
char *family_name = nullptr;
854
if (FcPatternGetString(match, FC_FAMILY, 0, reinterpret_cast<FcChar8 **>(&family_name)) == FcResultMatch) {
855
if (family_name && String::utf8(family_name).to_lower() != p_font_name.to_lower()) {
856
FcPatternDestroy(match);
857
FcPatternDestroy(pattern);
858
continue;
859
}
860
}
861
}
862
char *file_name = nullptr;
863
if (FcPatternGetString(match, FC_FILE, 0, reinterpret_cast<FcChar8 **>(&file_name)) == FcResultMatch) {
864
if (file_name) {
865
String ret = String::utf8(file_name);
866
FcPatternDestroy(match);
867
FcPatternDestroy(pattern);
868
return ret;
869
}
870
}
871
FcPatternDestroy(match);
872
}
873
FcPatternDestroy(pattern);
874
}
875
}
876
877
return String();
878
#else
879
ERR_FAIL_V_MSG(String(), "Godot was compiled without fontconfig, system font support is disabled.");
880
#endif
881
}
882
883
String OS_LinuxBSD::get_config_path() const {
884
if (has_environment("XDG_CONFIG_HOME")) {
885
if (get_environment("XDG_CONFIG_HOME").is_absolute_path()) {
886
return get_environment("XDG_CONFIG_HOME");
887
} else {
888
WARN_PRINT_ONCE("`XDG_CONFIG_HOME` is a relative path. Ignoring its value and falling back to `$HOME/.config` or `.` per the XDG Base Directory specification.");
889
return has_environment("HOME") ? get_environment("HOME").path_join(".config") : ".";
890
}
891
} else if (has_environment("HOME")) {
892
return get_environment("HOME").path_join(".config");
893
} else {
894
return ".";
895
}
896
}
897
898
String OS_LinuxBSD::get_data_path() const {
899
if (has_environment("XDG_DATA_HOME")) {
900
if (get_environment("XDG_DATA_HOME").is_absolute_path()) {
901
return get_environment("XDG_DATA_HOME");
902
} else {
903
WARN_PRINT_ONCE("`XDG_DATA_HOME` is a relative path. Ignoring its value and falling back to `$HOME/.local/share` or `get_config_path()` per the XDG Base Directory specification.");
904
return has_environment("HOME") ? get_environment("HOME").path_join(".local/share") : get_config_path();
905
}
906
} else if (has_environment("HOME")) {
907
return get_environment("HOME").path_join(".local/share");
908
} else {
909
return get_config_path();
910
}
911
}
912
913
String OS_LinuxBSD::get_cache_path() const {
914
if (has_environment("XDG_CACHE_HOME")) {
915
if (get_environment("XDG_CACHE_HOME").is_absolute_path()) {
916
return get_environment("XDG_CACHE_HOME");
917
} else {
918
WARN_PRINT_ONCE("`XDG_CACHE_HOME` is a relative path. Ignoring its value and falling back to `$HOME/.cache` or `get_config_path()` per the XDG Base Directory specification.");
919
return has_environment("HOME") ? get_environment("HOME").path_join(".cache") : get_config_path();
920
}
921
} else if (has_environment("HOME")) {
922
return get_environment("HOME").path_join(".cache");
923
} else {
924
return get_config_path();
925
}
926
}
927
928
String OS_LinuxBSD::get_system_dir(SystemDir p_dir, bool p_shared_storage) const {
929
if (p_dir == SYSTEM_DIR_DESKTOP && !system_dir_desktop_cache.is_empty()) {
930
return system_dir_desktop_cache;
931
}
932
933
String xdgparam;
934
935
switch (p_dir) {
936
case SYSTEM_DIR_DESKTOP: {
937
xdgparam = "DESKTOP";
938
} break;
939
case SYSTEM_DIR_DCIM: {
940
xdgparam = "PICTURES";
941
} break;
942
case SYSTEM_DIR_DOCUMENTS: {
943
xdgparam = "DOCUMENTS";
944
} break;
945
case SYSTEM_DIR_DOWNLOADS: {
946
xdgparam = "DOWNLOAD";
947
} break;
948
case SYSTEM_DIR_MOVIES: {
949
xdgparam = "VIDEOS";
950
} break;
951
case SYSTEM_DIR_MUSIC: {
952
xdgparam = "MUSIC";
953
} break;
954
case SYSTEM_DIR_PICTURES: {
955
xdgparam = "PICTURES";
956
} break;
957
case SYSTEM_DIR_RINGTONES: {
958
xdgparam = "MUSIC";
959
} break;
960
}
961
962
String pipe;
963
List<String> arg;
964
arg.push_back(xdgparam);
965
Error err = const_cast<OS_LinuxBSD *>(this)->execute("xdg-user-dir", arg, &pipe);
966
if (err != OK) {
967
return ".";
968
}
969
return pipe.strip_edges();
970
}
971
972
void OS_LinuxBSD::run() {
973
if (!main_loop) {
974
return;
975
}
976
977
main_loop->initialize();
978
979
//uint64_t last_ticks=get_ticks_usec();
980
981
//int frames=0;
982
//uint64_t frame=0;
983
984
while (true) {
985
DisplayServer::get_singleton()->process_events(); // get rid of pending events
986
#ifdef SDL_ENABLED
987
if (joypad_sdl) {
988
joypad_sdl->process_events();
989
}
990
#endif
991
if (Main::iteration()) {
992
break;
993
}
994
}
995
996
main_loop->finalize();
997
}
998
999
void OS_LinuxBSD::disable_crash_handler() {
1000
crash_handler.disable();
1001
}
1002
1003
bool OS_LinuxBSD::is_disable_crash_handler() const {
1004
return crash_handler.is_disabled();
1005
}
1006
1007
static String get_mountpoint(const String &p_path) {
1008
struct stat s;
1009
if (stat(p_path.utf8().get_data(), &s)) {
1010
return "";
1011
}
1012
1013
#if __has_include(<mntent.h>)
1014
dev_t dev = s.st_dev;
1015
FILE *fd = setmntent("/proc/mounts", "r");
1016
if (!fd) {
1017
return "";
1018
}
1019
1020
struct mntent mnt;
1021
char buf[1024];
1022
size_t buflen = 1024;
1023
while (getmntent_r(fd, &mnt, buf, buflen)) {
1024
if (!stat(mnt.mnt_dir, &s) && s.st_dev == dev) {
1025
endmntent(fd);
1026
return String(mnt.mnt_dir);
1027
}
1028
}
1029
1030
endmntent(fd);
1031
#endif
1032
return "";
1033
}
1034
1035
Error OS_LinuxBSD::move_to_trash(const String &p_path) {
1036
// We try multiple methods, until we find one that works.
1037
// So we only return on success until we exhausted possibilities.
1038
1039
String path = p_path.rstrip("/"); // Strip trailing slash when path points to a directory.
1040
int err_code;
1041
List<String> args;
1042
args.push_back(path);
1043
1044
args.push_front("trash"); // The command is `gio trash <file_name>` so we add it before the path.
1045
Error result = execute("gio", args, nullptr, &err_code); // For GNOME based machines.
1046
if (result == OK && err_code == 0) { // Success.
1047
return OK;
1048
}
1049
1050
args.pop_front();
1051
args.push_front("move");
1052
args.push_back("trash:/"); // The command is `kioclient5 move <file_name> trash:/`.
1053
result = execute("kioclient5", args, nullptr, &err_code); // For KDE based machines.
1054
if (result == OK && err_code == 0) {
1055
return OK;
1056
}
1057
1058
args.pop_front();
1059
args.pop_back();
1060
result = execute("gvfs-trash", args, nullptr, &err_code); // For older Linux machines.
1061
if (result == OK && err_code == 0) {
1062
return OK;
1063
}
1064
1065
// If the commands `kioclient5`, `gio` or `gvfs-trash` don't work on the system we do it manually.
1066
String trash_path = "";
1067
String mnt = get_mountpoint(path);
1068
1069
// If there is a directory "[Mountpoint]/.Trash-[UID], use it as the trash can.
1070
if (!mnt.is_empty()) {
1071
String mountpoint_trash_path(mnt + "/.Trash-" + itos(getuid()));
1072
struct stat s;
1073
if (!stat(mountpoint_trash_path.utf8().get_data(), &s)) {
1074
trash_path = mountpoint_trash_path;
1075
}
1076
}
1077
1078
// Otherwise, if ${XDG_DATA_HOME} is defined, use "${XDG_DATA_HOME}/Trash" as the trash can.
1079
if (trash_path.is_empty()) {
1080
char *dhome = getenv("XDG_DATA_HOME");
1081
if (dhome) {
1082
trash_path = String::utf8(dhome) + "/Trash";
1083
}
1084
}
1085
1086
// Otherwise, if ${HOME} is defined, use "${HOME}/.local/share/Trash" as the trash can.
1087
if (trash_path.is_empty()) {
1088
char *home = getenv("HOME");
1089
if (home) {
1090
trash_path = String::utf8(home) + "/.local/share/Trash";
1091
}
1092
}
1093
1094
// Issue an error if none of the previous locations is appropriate for the trash can.
1095
ERR_FAIL_COND_V_MSG(trash_path.is_empty(), FAILED, "Could not determine the trash can location");
1096
1097
// Create needed directories for decided trash can location.
1098
{
1099
Ref<DirAccess> dir_access = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
1100
Error err = dir_access->make_dir_recursive(trash_path);
1101
1102
// Issue an error if trash can is not created properly.
1103
ERR_FAIL_COND_V_MSG(err != OK, err, "Could not create the trash path \"" + trash_path + "\"");
1104
err = dir_access->make_dir_recursive(trash_path + "/files");
1105
ERR_FAIL_COND_V_MSG(err != OK, err, "Could not create the trash path \"" + trash_path + "/files\"");
1106
err = dir_access->make_dir_recursive(trash_path + "/info");
1107
ERR_FAIL_COND_V_MSG(err != OK, err, "Could not create the trash path \"" + trash_path + "/info\"");
1108
}
1109
1110
// The trash can is successfully created, now we check that we don't exceed our file name length limit.
1111
// If the file name is too long trim it so we can add the identifying number and ".trashinfo".
1112
// Assumes that the file name length limit is 255 characters.
1113
String file_name = path.get_file();
1114
if (file_name.length() > 240) {
1115
file_name = file_name.substr(0, file_name.length() - 15);
1116
}
1117
1118
String dest_path = trash_path + "/files/" + file_name;
1119
struct stat buff;
1120
int id_number = 0;
1121
String fn = file_name;
1122
1123
// Checks if a resource with the same name already exist in the trash can,
1124
// if there is, add an identifying number to our resource's name.
1125
while (stat(dest_path.utf8().get_data(), &buff) == 0) {
1126
id_number++;
1127
1128
// Added a limit to check for identically named files already on the trash can
1129
// if there are too many it could make the editor unresponsive.
1130
ERR_FAIL_COND_V_MSG(id_number > 99, FAILED, "Too many identically named resources already in the trash can.");
1131
fn = file_name + "." + itos(id_number);
1132
dest_path = trash_path + "/files/" + fn;
1133
}
1134
file_name = fn;
1135
1136
String renamed_path = path.get_base_dir() + "/" + file_name;
1137
1138
// Generates the .trashinfo file
1139
OS::DateTime dt = OS::get_singleton()->get_datetime(false);
1140
String timestamp = vformat("%04d-%02d-%02dT%02d:%02d:", dt.year, (int)dt.month, dt.day, dt.hour, dt.minute);
1141
timestamp = vformat("%s%02d", timestamp, dt.second); // vformat only supports up to 6 arguments.
1142
String trash_info = "[Trash Info]\nPath=" + path.uri_encode() + "\nDeletionDate=" + timestamp + "\n";
1143
{
1144
Error err;
1145
{
1146
Ref<FileAccess> file = FileAccess::open(trash_path + "/info/" + file_name + ".trashinfo", FileAccess::WRITE, &err);
1147
ERR_FAIL_COND_V_MSG(err != OK, err, "Can't create trashinfo file: \"" + trash_path + "/info/" + file_name + ".trashinfo\"");
1148
file->store_string(trash_info);
1149
}
1150
1151
// Rename our resource before moving it to the trash can.
1152
Ref<DirAccess> dir_access = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
1153
err = dir_access->rename(path, renamed_path);
1154
ERR_FAIL_COND_V_MSG(err != OK, err, "Can't rename file \"" + path + "\" to \"" + renamed_path + "\"");
1155
}
1156
1157
// Move the given resource to the trash can.
1158
// Do not use DirAccess:rename() because it can't move files across multiple mountpoints.
1159
List<String> mv_args;
1160
mv_args.push_back(renamed_path);
1161
mv_args.push_back(trash_path + "/files");
1162
{
1163
int retval;
1164
Error err = execute("mv", mv_args, nullptr, &retval);
1165
1166
// Issue an error if "mv" failed to move the given resource to the trash can.
1167
if (err != OK || retval != 0) {
1168
ERR_PRINT("move_to_trash: Could not move the resource \"" + path + "\" to the trash can \"" + trash_path + "/files\"");
1169
Ref<DirAccess> dir_access = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
1170
err = dir_access->rename(renamed_path, path);
1171
ERR_FAIL_COND_V_MSG(err != OK, err, "Could not rename \"" + renamed_path + "\" back to its original name: \"" + path + "\"");
1172
return FAILED;
1173
}
1174
}
1175
return OK;
1176
}
1177
1178
String OS_LinuxBSD::get_system_ca_certificates() {
1179
String certfile;
1180
Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
1181
1182
// Compile time preferred certificates path.
1183
if (!String(_SYSTEM_CERTS_PATH).is_empty() && da->file_exists(_SYSTEM_CERTS_PATH)) {
1184
certfile = _SYSTEM_CERTS_PATH;
1185
} else if (da->file_exists("/etc/ssl/certs/ca-certificates.crt")) {
1186
// Debian/Ubuntu
1187
certfile = "/etc/ssl/certs/ca-certificates.crt";
1188
} else if (da->file_exists("/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem")) {
1189
// Fedora
1190
certfile = "/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem";
1191
} else if (da->file_exists("/etc/ca-certificates/extracted/tls-ca-bundle.pem")) {
1192
// Arch Linux
1193
certfile = "/etc/ca-certificates/extracted/tls-ca-bundle.pem";
1194
} else if (da->file_exists("/var/lib/ca-certificates/ca-bundle.pem")) {
1195
// openSUSE
1196
certfile = "/var/lib/ca-certificates/ca-bundle.pem";
1197
} else if (da->file_exists("/etc/ssl/cert.pem")) {
1198
// FreeBSD/OpenBSD
1199
certfile = "/etc/ssl/cert.pem";
1200
}
1201
1202
if (certfile.is_empty()) {
1203
return "";
1204
}
1205
1206
Ref<FileAccess> f = FileAccess::open(certfile, FileAccess::READ);
1207
ERR_FAIL_COND_V_MSG(f.is_null(), "", vformat("Failed to open system CA certificates file: '%s'", certfile));
1208
1209
return f->get_as_text();
1210
}
1211
1212
#ifdef TOOLS_ENABLED
1213
bool OS_LinuxBSD::_test_create_rendering_device(const String &p_display_driver) const {
1214
// Tests Rendering Device creation.
1215
1216
bool ok = false;
1217
#if defined(RD_ENABLED)
1218
Error err;
1219
RenderingContextDriver *rcd = nullptr;
1220
1221
#if defined(VULKAN_ENABLED)
1222
#ifdef X11_ENABLED
1223
if (p_display_driver == "x11" || p_display_driver.is_empty()) {
1224
rcd = memnew(RenderingContextDriverVulkanX11);
1225
}
1226
#endif
1227
#ifdef WAYLAND_ENABLED
1228
if (p_display_driver == "wayland") {
1229
rcd = memnew(RenderingContextDriverVulkanWayland);
1230
}
1231
#endif
1232
#endif
1233
if (rcd != nullptr) {
1234
err = rcd->initialize();
1235
if (err == OK) {
1236
RenderingDevice *rd = memnew(RenderingDevice);
1237
err = rd->initialize(rcd);
1238
memdelete(rd);
1239
rd = nullptr;
1240
if (err == OK) {
1241
ok = true;
1242
}
1243
}
1244
memdelete(rcd);
1245
rcd = nullptr;
1246
}
1247
#endif
1248
return ok;
1249
}
1250
1251
bool OS_LinuxBSD::_test_create_rendering_device_and_gl(const String &p_display_driver) const {
1252
// Tests OpenGL context and Rendering Device simultaneous creation. This function is expected to crash on some drivers.
1253
1254
#ifdef GLES3_ENABLED
1255
#ifdef X11_ENABLED
1256
if (p_display_driver == "x11" || p_display_driver.is_empty()) {
1257
#ifdef SOWRAP_ENABLED
1258
if (initialize_xlib(0) != 0) {
1259
return false;
1260
}
1261
#endif
1262
DetectPrimeX11::create_context();
1263
}
1264
#endif
1265
#ifdef WAYLAND_ENABLED
1266
if (p_display_driver == "wayland") {
1267
#ifdef SOWRAP_ENABLED
1268
if (initialize_wayland_egl(0) != 0) {
1269
return false;
1270
}
1271
#endif
1272
DetectPrimeEGL::create_context(EGL_PLATFORM_WAYLAND_KHR);
1273
}
1274
#endif
1275
RasterizerGLES3::make_current(true);
1276
#endif
1277
return _test_create_rendering_device(p_display_driver);
1278
}
1279
#endif
1280
1281
OS_LinuxBSD::OS_LinuxBSD() {
1282
main_loop = nullptr;
1283
1284
#ifdef PULSEAUDIO_ENABLED
1285
AudioDriverManager::add_driver(&driver_pulseaudio);
1286
#endif
1287
1288
#ifdef ALSA_ENABLED
1289
AudioDriverManager::add_driver(&driver_alsa);
1290
#endif
1291
1292
#ifdef X11_ENABLED
1293
DisplayServerX11::register_x11_driver();
1294
#endif
1295
1296
#ifdef WAYLAND_ENABLED
1297
DisplayServerWayland::register_wayland_driver();
1298
#endif
1299
1300
#ifdef FONTCONFIG_ENABLED
1301
#ifdef SOWRAP_ENABLED
1302
#ifdef DEBUG_ENABLED
1303
int dylibloader_verbose = 1;
1304
#else
1305
int dylibloader_verbose = 0;
1306
#endif
1307
font_config_initialized = (initialize_fontconfig(dylibloader_verbose) == 0);
1308
#else
1309
font_config_initialized = true;
1310
#endif
1311
if (font_config_initialized) {
1312
bool ver_ok = false;
1313
int version = FcGetVersion();
1314
ver_ok = ((version / 100 / 100) == 2 && (version / 100 % 100) >= 11) || ((version / 100 / 100) > 2); // 2.11.0
1315
print_verbose(vformat("FontConfig %d.%d.%d detected.", version / 100 / 100, version / 100 % 100, version % 100));
1316
if (!ver_ok) {
1317
font_config_initialized = false;
1318
}
1319
}
1320
1321
if (font_config_initialized) {
1322
config = FcInitLoadConfigAndFonts();
1323
if (!config) {
1324
font_config_initialized = false;
1325
}
1326
object_set = FcObjectSetBuild(FC_FAMILY, FC_FILE, nullptr);
1327
if (!object_set) {
1328
font_config_initialized = false;
1329
}
1330
}
1331
#endif // FONTCONFIG_ENABLED
1332
}
1333
1334
OS_LinuxBSD::~OS_LinuxBSD() {
1335
#ifdef FONTCONFIG_ENABLED
1336
if (object_set) {
1337
FcObjectSetDestroy(object_set);
1338
}
1339
if (config) {
1340
FcConfigDestroy(config);
1341
}
1342
#endif // FONTCONFIG_ENABLED
1343
}
1344
1345