summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorbruvzg <7645683+bruvzg@users.noreply.github.com>2020-08-05 09:25:28 +0300
committerbruvzg <7645683+bruvzg@users.noreply.github.com>2020-11-26 13:55:26 +0200
commit493da99269b3a111cf58e0352495e25ee49c5f84 (patch)
treebc34af12b8f3697ee6da79c1c44e2cfcd8d4b90c /main
parenta8c2cc9028535aa6f474e93b71b09b5b7402c79d (diff)
[Complex Text Layouts] Implement TextServer interface. Implement Fallback TextServer.
Diffstat (limited to 'main')
-rw-r--r--main/main.cpp124
1 files changed, 117 insertions, 7 deletions
diff --git a/main/main.cpp b/main/main.cpp
index 82be327cbb..cd97e3282d 100644
--- a/main/main.cpp
+++ b/main/main.cpp
@@ -72,6 +72,7 @@
#include "servers/register_server_types.h"
#include "servers/rendering/rendering_server_raster.h"
#include "servers/rendering/rendering_server_wrap_mt.h"
+#include "servers/text_server.h"
#include "servers/xr_server.h"
#ifdef TESTS_ENABLED
@@ -113,6 +114,7 @@ static DisplayServer *display_server = nullptr;
static RenderingServer *rendering_server = nullptr;
static CameraServer *camera_server = nullptr;
static XRServer *xr_server = nullptr;
+static TextServerManager *tsman = nullptr;
static PhysicsServer3D *physics_server = nullptr;
static PhysicsServer2D *physics_2d_server = nullptr;
static NavigationServer3D *navigation_server = nullptr;
@@ -122,6 +124,7 @@ static bool _start_success = false;
// Drivers
+static int text_driver_idx = -1;
static int display_driver_idx = -1;
static int audio_driver_idx = -1;
@@ -304,7 +307,18 @@ void Main::print_help(const char *p_binary) {
OS::get_singleton()->print(")");
}
OS::get_singleton()->print("].\n");
+
OS::get_singleton()->print(" --rendering-driver <driver> Rendering driver (depends on display driver).\n");
+
+ OS::get_singleton()->print(" --text-driver <driver> Text driver (Fonts, BiDi, shaping) [");
+ for (int i = 0; i < TextServerManager::get_interface_count(); i++) {
+ if (i > 0) {
+ OS::get_singleton()->print(", ");
+ }
+ OS::get_singleton()->print("'%s'", TextServerManager::get_interface_name(i).utf8().get_data());
+ }
+ OS::get_singleton()->print("].\n");
+
OS::get_singleton()->print("\n");
#ifndef SERVER_ENABLED
@@ -544,6 +558,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
I = args.front();
+ String text_driver = "";
String display_driver = "";
String audio_driver = "";
String tablet_driver = "";
@@ -649,6 +664,40 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
OS::get_singleton()->print("Missing audio driver argument, aborting.\n");
goto error;
}
+ } else if (I->get() == "--text-driver") {
+ if (I->next()) {
+ text_driver = I->next()->get();
+ bool found = false;
+ for (int i = 0; i < TextServerManager::get_interface_count(); i++) {
+ if (text_driver == TextServerManager::get_interface_name(i)) {
+ found = true;
+ }
+ }
+
+ if (!found) {
+ OS::get_singleton()->print("Unknown text driver '%s', aborting.\nValid options are ",
+ text_driver.utf8().get_data());
+
+ for (int i = 0; i < TextServerManager::get_interface_count(); i++) {
+ if (i == TextServerManager::get_interface_count() - 1) {
+ OS::get_singleton()->print(" and ");
+ } else if (i != 0) {
+ OS::get_singleton()->print(", ");
+ }
+
+ OS::get_singleton()->print("'%s'", TextServerManager::get_interface_name(i).utf8().get_data());
+ }
+
+ OS::get_singleton()->print(".\n");
+
+ goto error;
+ }
+
+ N = I->next()->next();
+ } else {
+ OS::get_singleton()->print("Missing text driver argument, aborting.\n");
+ goto error;
+ }
} else if (I->get() == "--display-driver") { // force video driver
@@ -1159,6 +1208,11 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
OS::get_singleton()->set_cmdline(execpath, main_args);
+ GLOBAL_DEF("display/window/text_name", "");
+ if (text_driver == "") {
+ text_driver = GLOBAL_GET("display/window/text_name");
+ }
+
GLOBAL_DEF("rendering/quality/driver/driver_name", "Vulkan");
ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/driver/driver_name",
PropertyInfo(Variant::STRING,
@@ -1289,6 +1343,35 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
OS::get_singleton()->_render_thread_mode = OS::RenderThreadMode(rtm);
}
+ /* Determine text driver */
+
+ if (text_driver != "") {
+ /* Load user selected text server. */
+ for (int i = 0; i < TextServerManager::get_interface_count(); i++) {
+ if (text_driver == TextServerManager::get_interface_name(i)) {
+ text_driver_idx = i;
+ break;
+ }
+ }
+ }
+
+ if (text_driver_idx < 0) {
+ /* If not selected, use one with the most features available. */
+ int max_features = 0;
+ for (int i = 0; i < TextServerManager::get_interface_count(); i++) {
+ uint32_t ftrs = TextServerManager::get_interface_features(i);
+ int features = 0;
+ while (ftrs) {
+ features += ftrs & 1;
+ ftrs >>= 1;
+ }
+ if (features >= max_features) {
+ max_features = features;
+ text_driver_idx = i;
+ }
+ }
+ }
+
/* Determine audio and video drivers */
for (int i = 0; i < DisplayServer::get_create_function_count(); i++) {
@@ -1388,6 +1471,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
error:
+ text_driver = "";
display_driver = "";
audio_driver = "";
tablet_driver = "";
@@ -1449,6 +1533,30 @@ Error Main::setup2(Thread::ID p_main_tid_override) {
Thread::_main_thread_id = p_main_tid_override;
}
+ /* Initialize Text Server */
+
+ {
+ tsman = memnew(TextServerManager);
+ Error err;
+ TextServer *text_server = TextServerManager::initialize(text_driver_idx, err);
+ if (err != OK || text_server == nullptr) {
+ for (int i = 0; i < TextServerManager::get_interface_count(); i++) {
+ if (i == text_driver_idx) {
+ continue; //don't try the same twice
+ }
+ text_server = TextServerManager::initialize(i, err);
+ if (err == OK && text_server != nullptr) {
+ break;
+ }
+ }
+ }
+
+ if (err != OK || text_server == nullptr) {
+ ERR_PRINT("Unable to create TextServer, all text drivers failed.");
+ return err;
+ }
+ }
+
/* Initialize Input */
input = memnew(Input);
@@ -1459,23 +1567,21 @@ Error Main::setup2(Thread::ID p_main_tid_override) {
String rendering_driver; // temp broken
Error err;
- display_server = DisplayServer::create(display_driver_idx, rendering_driver, window_mode, window_flags,
- window_size, err);
- if (err != OK) {
+ display_server = DisplayServer::create(display_driver_idx, rendering_driver, window_mode, window_flags, window_size, err);
+ if (err != OK || display_server == nullptr) {
//ok i guess we can't use this display server, try other ones
for (int i = 0; i < DisplayServer::get_create_function_count(); i++) {
if (i == display_driver_idx) {
continue; //don't try the same twice
}
- display_server = DisplayServer::create(display_driver_idx, rendering_driver, window_mode, window_flags,
- window_size, err);
- if (err == OK) {
+ display_server = DisplayServer::create(i, rendering_driver, window_mode, window_flags, window_size, err);
+ if (err == OK && display_server != nullptr) {
break;
}
}
}
- if (!display_server || err != OK) {
+ if (err != OK || display_server == nullptr) {
ERR_PRINT("Unable to create DisplayServer, all display drivers failed.");
return err;
}
@@ -2572,6 +2678,10 @@ void Main::cleanup() {
finalize_navigation_server();
finalize_display();
+ if (tsman) {
+ memdelete(tsman);
+ }
+
if (input) {
memdelete(input);
}