From 8cdef21d6ceae643481eb5b81a0e9dfb44279c04 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Tue, 1 Jun 2021 16:40:08 +0200 Subject: [PATCH] Move remaining dummy drivers to servers. --- drivers/register_driver_types.cpp | 3 -- .../javascript/display_server_javascript.cpp | 2 +- servers/display_server.cpp | 16 ++++++--- .../display_server_headless.h | 33 +++++++++---------- .../rendering}/rasterizer_dummy.h | 0 5 files changed, 28 insertions(+), 26 deletions(-) rename {drivers/dummy => servers}/display_server_headless.h (97%) rename {drivers/dummy => servers/rendering}/rasterizer_dummy.h (100%) diff --git a/drivers/register_driver_types.cpp b/drivers/register_driver_types.cpp index b7342694c82..18262c74c44 100644 --- a/drivers/register_driver_types.cpp +++ b/drivers/register_driver_types.cpp @@ -30,7 +30,6 @@ #include "register_driver_types.h" -#include "drivers/dummy/display_server_headless.h" #include "drivers/png/image_loader_png.h" #include "drivers/png/resource_saver_png.h" @@ -38,8 +37,6 @@ static ImageLoaderPNG *image_loader_png; static Ref resource_saver_png; void register_core_driver_types() { - DisplayServerHeadless::register_headless_driver(); - image_loader_png = memnew(ImageLoaderPNG); ImageLoader::add_image_format_loader(image_loader_png); diff --git a/platform/javascript/display_server_javascript.cpp b/platform/javascript/display_server_javascript.cpp index dae0b5f7e7b..cce1f8dca77 100644 --- a/platform/javascript/display_server_javascript.cpp +++ b/platform/javascript/display_server_javascript.cpp @@ -30,8 +30,8 @@ #include "platform/javascript/display_server_javascript.h" -#include "drivers/dummy/rasterizer_dummy.h" #include "platform/javascript/os_javascript.h" +#include "servers/rendering/rasterizer_dummy.h" #include #include diff --git a/servers/display_server.cpp b/servers/display_server.cpp index 7bd1075006b..c7d444c993a 100644 --- a/servers/display_server.cpp +++ b/servers/display_server.cpp @@ -32,14 +32,18 @@ #include "core/input/input.h" #include "scene/resources/texture.h" +#include "servers/display_server_headless.h" DisplayServer *DisplayServer::singleton = nullptr; DisplayServer::SwitchVSyncCallbackInThread DisplayServer::switch_vsync_function = nullptr; bool DisplayServer::hidpi_allowed = false; -DisplayServer::DisplayServerCreate DisplayServer::server_create_functions[DisplayServer::MAX_SERVERS]; -int DisplayServer::server_create_count = 0; +DisplayServer::DisplayServerCreate DisplayServer::server_create_functions[DisplayServer::MAX_SERVERS] = { + { "headless", &DisplayServerHeadless::create_func, &DisplayServerHeadless::get_rendering_drivers_func } +}; + +int DisplayServer::server_create_count = 1; void DisplayServer::global_menu_add_item(const String &p_menu_root, const String &p_label, const Callable &p_callback, const Variant &p_tag) { WARN_PRINT("Global menus not supported by this display server."); @@ -560,9 +564,11 @@ void DisplayServer::_bind_methods() { void DisplayServer::register_create_function(const char *p_name, CreateFunction p_function, GetRenderingDriversFunction p_get_drivers) { ERR_FAIL_COND(server_create_count == MAX_SERVERS); - server_create_functions[server_create_count].name = p_name; - server_create_functions[server_create_count].create_function = p_function; - server_create_functions[server_create_count].get_rendering_drivers_function = p_get_drivers; + // Headless display server is always last + server_create_functions[server_create_count] = server_create_functions[server_create_count - 1]; + server_create_functions[server_create_count - 1].name = p_name; + server_create_functions[server_create_count - 1].create_function = p_function; + server_create_functions[server_create_count - 1].get_rendering_drivers_function = p_get_drivers; server_create_count++; } diff --git a/drivers/dummy/display_server_headless.h b/servers/display_server_headless.h similarity index 97% rename from drivers/dummy/display_server_headless.h rename to servers/display_server_headless.h index ee19abda29d..8b386c8d9cf 100644 --- a/drivers/dummy/display_server_headless.h +++ b/servers/display_server_headless.h @@ -33,9 +33,24 @@ #include "servers/display_server.h" -#include "drivers/dummy/rasterizer_dummy.h" +#include "servers/rendering/rasterizer_dummy.h" class DisplayServerHeadless : public DisplayServer { +private: + friend class DisplayServer; + + static Vector get_rendering_drivers_func() { + Vector drivers; + drivers.push_back("dummy"); + return drivers; + } + + static DisplayServer *create_func(const String &p_rendering_driver, DisplayServer::WindowMode p_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error) { + r_error = OK; + RasterizerDummy::make_current(); + return memnew(DisplayServerHeadless()); + } + public: bool has_feature(Feature p_feature) const override { return false; } String get_name() const override { return "headless"; } @@ -105,22 +120,6 @@ public: void set_icon(const Ref &p_icon) override {} - static void register_headless_driver() { - register_create_function("headless", create_func, get_rendering_drivers_func); - } - - static Vector get_rendering_drivers_func() { - Vector drivers; - drivers.push_back("dummy"); - return drivers; - } - - static DisplayServer *create_func(const String &p_rendering_driver, DisplayServer::WindowMode p_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error) { - r_error = OK; - RasterizerDummy::make_current(); - return memnew(DisplayServerHeadless()); - } - DisplayServerHeadless() {} ~DisplayServerHeadless() {} }; diff --git a/drivers/dummy/rasterizer_dummy.h b/servers/rendering/rasterizer_dummy.h similarity index 100% rename from drivers/dummy/rasterizer_dummy.h rename to servers/rendering/rasterizer_dummy.h