summaryrefslogtreecommitdiff
path: root/servers
diff options
context:
space:
mode:
authorJuan Linietsky <juan@godotengine.org>2020-03-03 10:36:29 -0300
committerJuan Linietsky <reduzio@gmail.com>2020-03-26 15:49:34 +0100
commitf8a79a97c7d12da43b111a756f09ee7ad5ea28e9 (patch)
tree6728478a8e3bb2669ee4096cf354e87475b4469d /servers
parent4396e98834f159da59ec790f2ff64fb65dacd9ce (diff)
Effective DisplayServer separation, rename X11 -> LinuxBSD
Diffstat (limited to 'servers')
-rw-r--r--servers/display_server.cpp107
-rw-r--r--servers/display_server.h85
-rw-r--r--servers/visual/visual_server_raster.cpp2
-rw-r--r--servers/visual/visual_server_wrap_mt.cpp7
4 files changed, 179 insertions, 22 deletions
diff --git a/servers/display_server.cpp b/servers/display_server.cpp
index c3ecf302c3..b1ace561df 100644
--- a/servers/display_server.cpp
+++ b/servers/display_server.cpp
@@ -29,8 +29,13 @@
/*************************************************************************/
#include "display_server.h"
+#include "core/input/input.h"
DisplayServer *DisplayServer::singleton = nullptr;
+DisplayServer::SwitchVSyncCallbackInThread DisplayServer::switch_vsync_function = nullptr;
+
+DisplayServer::DisplayServerCreate DisplayServer::server_create_functions[DisplayServer::MAX_SERVERS];
+int DisplayServer::server_create_count = 0;
void DisplayServer::global_menu_add_item(const String &p_menu, const String &p_label, const Variant &p_signal, const Variant &p_meta) {
WARN_PRINT("Global menus not supported by this display server.");
@@ -76,6 +81,18 @@ DisplayServer::ScreenOrientation DisplayServer::screen_get_orientation(int p_scr
return SCREEN_LANDSCAPE;
}
+bool DisplayServer::screen_is_touchscreen(int p_screen) const {
+ //return false;
+ return Input::get_singleton() && Input::get_singleton()->is_emulating_touch_from_mouse();
+}
+
+void DisplayServer::screen_set_keep_on(bool p_enable) {
+ WARN_PRINT("Keeping screen on not supported by this display server.");
+}
+bool DisplayServer::screen_is_kept_on() const {
+ return false;
+}
+
DisplayServer::WindowID DisplayServer::create_sub_window(WindowMode p_mode, uint32_t p_flags, const Rect2i) {
ERR_FAIL_V_MSG(INVALID_WINDOW_ID, "Sub-windows not supported by this display server.");
}
@@ -104,7 +121,7 @@ bool DisplayServer::is_console_visible() const {
return false;
}
-void DisplayServer::virtual_keyboard_show(const String &p_existing_text, const Rect2 &p_screen_rect) {
+void DisplayServer::virtual_keyboard_show(const String &p_existing_text, const Rect2 &p_screen_rect, int p_max_legth) {
WARN_PRINT("Virtual keyboard not supported by this display server.");
}
void DisplayServer::virtual_keyboard_hide() {
@@ -180,7 +197,32 @@ void DisplayServer::set_native_icon(const String &p_filename) {
WARN_PRINT("Native icon not supported by this display server.");
}
void DisplayServer::set_icon(const Ref<Image> &p_icon) {
- WARN_PRINT("Iconnot supported by this display server.");
+ WARN_PRINT("Icon not supported by this display server.");
+}
+
+void DisplayServer::_set_use_vsync(bool p_enable) {
+ WARN_PRINT("VSync not supported by this display server.");
+}
+void DisplayServer::vsync_set_enabled(bool p_enable) {
+ vsync_enabled = p_enable;
+ if (switch_vsync_function) { //if a function was set, use function
+ switch_vsync_function(p_enable);
+ } else { //otherwise just call here
+ _set_use_vsync(p_enable);
+ }
+}
+bool DisplayServer::vsync_is_enabled() const {
+ return vsync_enabled;
+}
+
+void DisplayServer::vsync_set_use_via_compositor(bool p_enable) {
+ WARN_PRINT("VSync via compositor not supported by this display server.");
+}
+bool DisplayServer::vsync_is_using_via_compositor() const {
+ return false;
+}
+
+void DisplayServer::set_context(Context p_context) {
}
void DisplayServer::_bind_methods() {
@@ -214,6 +256,9 @@ void DisplayServer::_bind_methods() {
ClassDB::bind_method(D_METHOD("screen_set_orientation", "orientation", "screen"), &DisplayServer::screen_set_orientation, DEFVAL(SCREEN_OF_MAIN_WINDOW));
ClassDB::bind_method(D_METHOD("screen_get_orientation", "screen"), &DisplayServer::screen_get_orientation, DEFVAL(SCREEN_OF_MAIN_WINDOW));
+ ClassDB::bind_method(D_METHOD("screen_set_keep_on", "enable"), &DisplayServer::screen_set_keep_on);
+ ClassDB::bind_method(D_METHOD("screen_is_kept_on"), &DisplayServer::screen_is_kept_on);
+
ClassDB::bind_method(D_METHOD("get_window_list"), &DisplayServer::get_window_list);
ClassDB::bind_method(D_METHOD("create_sub_window", "mode", "rect"), &DisplayServer::create_sub_window, DEFVAL(Rect2i()));
@@ -258,14 +303,14 @@ void DisplayServer::_bind_methods() {
ClassDB::bind_method(D_METHOD("console_set_visible", "console_visible"), &DisplayServer::console_set_visible);
ClassDB::bind_method(D_METHOD("is_console_visible"), &DisplayServer::is_console_visible);
- ClassDB::bind_method(D_METHOD("virtual_keyboard_show", "existing_text", "position"), &DisplayServer::virtual_keyboard_show, DEFVAL(Rect2i()));
+ ClassDB::bind_method(D_METHOD("virtual_keyboard_show", "existing_text", "position", "max_length"), &DisplayServer::virtual_keyboard_show, DEFVAL(Rect2i()), DEFVAL(-1));
ClassDB::bind_method(D_METHOD("virtual_keyboard_hide"), &DisplayServer::virtual_keyboard_hide);
ClassDB::bind_method(D_METHOD("virtual_keyboard_get_height"), &DisplayServer::virtual_keyboard_get_height);
ClassDB::bind_method(D_METHOD("cursor_set_shape", "shape"), &DisplayServer::cursor_set_shape);
ClassDB::bind_method(D_METHOD("cursor_get_shape"), &DisplayServer::cursor_get_shape);
- ClassDB::bind_method(D_METHOD("cursor_set_custom_image", "cursor", "shape", "hotspot"), &DisplayServer::cursor_set_custom_image);
+ ClassDB::bind_method(D_METHOD("cursor_set_custom_image", "cursor", "shape", "hotspot"), &DisplayServer::cursor_set_custom_image, DEFVAL(CURSOR_ARROW), DEFVAL(Vector2()));
ClassDB::bind_method(D_METHOD("get_swap_ok_cancel"), &DisplayServer::get_swap_ok_cancel);
@@ -285,6 +330,12 @@ void DisplayServer::_bind_methods() {
ClassDB::bind_method(D_METHOD("process_events"), &DisplayServer::process_events);
ClassDB::bind_method(D_METHOD("force_process_and_drop_events"), &DisplayServer::force_process_and_drop_events);
+ ClassDB::bind_method(D_METHOD("vsync_set_enabled", "enabled"), &DisplayServer::vsync_set_enabled);
+ ClassDB::bind_method(D_METHOD("vsync_is_enabled"), &DisplayServer::vsync_is_enabled);
+
+ ClassDB::bind_method(D_METHOD("vsync_set_use_via_compositor", "enabled"), &DisplayServer::vsync_set_use_via_compositor);
+ ClassDB::bind_method(D_METHOD("vsync_is_using_via_compositor"), &DisplayServer::vsync_is_using_via_compositor);
+
ClassDB::bind_method(D_METHOD("set_native_icon", "filename"), &DisplayServer::set_native_icon);
ClassDB::bind_method(D_METHOD("set_icon", "image"), &DisplayServer::set_icon);
@@ -367,8 +418,56 @@ void DisplayServer::_bind_methods() {
BIND_ENUM_CONSTANT(LATIN_KEYBOARD_NEO);
BIND_ENUM_CONSTANT(LATIN_KEYBOARD_COLEMAK);
}
+
+void DisplayServer::register_create_function(const char *p_name, CreateFunction p_function, GetVideoDriversFunction p_get_drivers) {
+ ERR_FAIL_COND(server_create_count == MAX_SERVERS);
+ server_create_functions[server_create_count].create_function = p_function;
+ server_create_functions[server_create_count].name = p_name;
+ server_create_count++;
+}
+int DisplayServer::get_create_function_count() {
+ return server_create_count;
+}
+const char *DisplayServer::get_create_function_name(int p_index) {
+ ERR_FAIL_INDEX_V(p_index, server_create_count, nullptr);
+ return server_create_functions[p_index].name;
+}
+
+Vector<String> DisplayServer::get_create_function_rendering_drivers(int p_index) {
+ ERR_FAIL_INDEX_V(p_index, server_create_count, Vector<String>());
+ return server_create_functions[p_index].get_rendering_drivers_function();
+}
+
+DisplayServer *DisplayServer::create(int p_index, const String &p_rendering_driver, WindowMode p_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error) {
+ ERR_FAIL_INDEX_V(p_index, server_create_count, nullptr);
+ return server_create_functions[p_index].create_function(p_rendering_driver, p_mode, p_flags, p_resolution, r_error);
+}
+
+void DisplayServer::_input_set_mouse_mode(Input::MouseMode p_mode) {
+ singleton->mouse_set_mode(MouseMode(p_mode));
+}
+Input::MouseMode DisplayServer::_input_get_mouse_mode() {
+ return Input::MouseMode(singleton->mouse_get_mode());
+}
+
+void DisplayServer::_input_warp(const Vector2 &p_to_pos) {
+ singleton->mouse_warp_to_position(p_to_pos);
+}
+
+Input::CursorShape DisplayServer::_input_get_current_cursor_shape() {
+ return (Input::CursorShape)singleton->cursor_get_shape();
+}
+void DisplayServer::_input_set_custom_mouse_cursor_func(const RES &p_image, Input::CursorShape p_shape, const Vector2 &p_hostspot) {
+ singleton->cursor_set_custom_image(p_image, (CursorShape)p_shape, p_hostspot);
+}
+
DisplayServer::DisplayServer() {
singleton = this;
+ Input::set_mouse_mode_func = _input_set_mouse_mode;
+ Input::get_mouse_mode_func = _input_get_mouse_mode;
+ Input::warp_mouse_func = _input_warp;
+ Input::get_current_cursor_shape_func = _input_get_current_cursor_shape;
+ Input::set_custom_mouse_cursor_func = _input_set_custom_mouse_cursor_func;
}
DisplayServer::~DisplayServer() {
}
diff --git a/servers/display_server.h b/servers/display_server.h
index c05a7fadbd..94848153ce 100644
--- a/servers/display_server.h
+++ b/servers/display_server.h
@@ -31,6 +31,7 @@
#ifndef DISPLAY_SERVER_H
#define DISPLAY_SERVER_H
+#include "core/input/input.h"
#include "core/os/os.h"
#include "core/resource.h"
@@ -38,9 +39,45 @@ class DisplayServer : public Object {
GDCLASS(DisplayServer, Object)
static DisplayServer *singleton;
+ bool vsync_enabled = true;
+
+public:
+ _FORCE_INLINE_ static DisplayServer *get_singleton() {
+ return singleton;
+ }
+ enum WindowMode {
+ WINDOW_MODE_WINDOWED,
+ WINDOW_MODE_MINIMIZED,
+ WINDOW_MODE_MAXIMIZED,
+ WINDOW_MODE_FULLSCREEN
+ };
+
+ typedef DisplayServer *(*CreateFunction)(const String &, WindowMode, uint32_t, const Size2i &, Error &r_error); //video driver, window mode, resolution
+ typedef Vector<String> (*GetVideoDriversFunction)(); //video driver, window mode, resolution
+private:
+ static void _input_set_mouse_mode(Input::MouseMode p_mode);
+ static Input::MouseMode _input_get_mouse_mode();
+ static void _input_warp(const Vector2 &p_to_pos);
+ static Input::CursorShape _input_get_current_cursor_shape();
+ static void _input_set_custom_mouse_cursor_func(const RES &, Input::CursorShape, const Vector2 &p_hostspot);
protected:
static void _bind_methods();
+ enum {
+ MAX_SERVERS = 64
+ };
+
+ struct DisplayServerCreate {
+ const char *name;
+ GetVideoDriversFunction get_rendering_drivers_function;
+ CreateFunction create_function;
+ };
+
+ static DisplayServerCreate server_create_functions[MAX_SERVERS];
+ static int server_create_count;
+
+ friend class VisualServerRaster;
+ virtual void _set_use_vsync(bool p_enable);
public:
enum Feature {
@@ -62,7 +99,8 @@ public:
FEATURE_ICON,
FEATURE_NATIVE_ICON,
FEATURE_ORIENTATION,
- FEATURE_SWAP_BUFFERS
+ FEATURE_SWAP_BUFFERS,
+ FEATURE_KEEP_SCREEN_ON,
};
@@ -101,8 +139,7 @@ public:
virtual Point2i screen_get_position(int p_screen = SCREEN_OF_MAIN_WINDOW) const = 0;
virtual Size2i screen_get_size(int p_screen = SCREEN_OF_MAIN_WINDOW) const = 0;
virtual int screen_get_dpi(int p_screen = SCREEN_OF_MAIN_WINDOW) const = 0;
- virtual bool screen_is_touchscreen(int p_screen = SCREEN_OF_MAIN_WINDOW) const = 0;
-
+ virtual bool screen_is_touchscreen(int p_screen = SCREEN_OF_MAIN_WINDOW) const;
enum ScreenOrientation {
SCREEN_LANDSCAPE,
@@ -117,6 +154,8 @@ public:
virtual void screen_set_orientation(ScreenOrientation p_orientation, int p_screen = SCREEN_OF_MAIN_WINDOW);
ScreenOrientation screen_get_orientation(int p_screen = SCREEN_OF_MAIN_WINDOW) const;
+ virtual void screen_set_keep_on(bool p_enable); //disable screensaver
+ virtual bool screen_is_kept_on() const;
enum {
MAIN_WINDOW_ID = 0,
INVALID_WINDOW_ID = -1
@@ -126,13 +165,6 @@ public:
virtual Vector<int> get_window_list() const = 0;
- enum WindowMode {
- WINDOW_MODE_WINDOWED,
- WINDOW_MODE_MINIMIZED,
- WINDOW_MODE_MAXIMIZED,
- WINDOW_MODE_FULLSCREEN
- };
-
enum WindowFlags {
WINDOW_FLAG_RESIZE_DISABLED,
WINDOW_FLAG_BORDERLESS,
@@ -179,6 +211,8 @@ public:
virtual bool window_can_draw(WindowID p_window = MAIN_WINDOW_ID) const = 0;
+ virtual bool can_any_window_draw() const = 0;
+
virtual void window_set_ime_active(const bool p_active, WindowID p_window = MAIN_WINDOW_ID);
virtual void window_set_ime_position(const Point2i &p_pos, WindowID p_window = MAIN_WINDOW_ID);
@@ -188,7 +222,7 @@ public:
virtual void console_set_visible(bool p_enabled);
virtual bool is_console_visible() const;
- virtual void virtual_keyboard_show(const String &p_existing_text, const Rect2 &p_screen_rect = Rect2());
+ virtual void virtual_keyboard_show(const String &p_existing_text, const Rect2 &p_screen_rect = Rect2(), int p_max_legth = -1);
virtual void virtual_keyboard_hide();
// returns height of the currently shown virtual keyboard (0 if keyboard is hidden)
@@ -216,7 +250,7 @@ public:
};
virtual void cursor_set_shape(CursorShape p_shape);
virtual CursorShape cursor_get_shape() const;
- virtual void cursor_set_custom_image(const RES &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot);
+ virtual void cursor_set_custom_image(const RES &p_cursor, CursorShape p_shape = CURSOR_ARROW, const Vector2 &p_hotspot = Vector2());
virtual bool get_swap_ok_cancel();
@@ -255,8 +289,31 @@ public:
virtual void set_native_icon(const String &p_filename);
virtual void set_icon(const Ref<Image> &p_icon);
- typedef Vector<String> *(*GetSupportedVideoDriversFunction)();
- typedef DisplayServer *(*CreateFunction)(const String &, WindowMode, uint32_t, const Size2i &, Error &r_error); //video driver, window mode, resolution
+ typedef void (*SwitchVSyncCallbackInThread)(bool);
+
+ static SwitchVSyncCallbackInThread switch_vsync_function;
+
+ void vsync_set_enabled(bool p_enable);
+ bool vsync_is_enabled() const;
+
+ virtual void vsync_set_use_via_compositor(bool p_enable);
+ virtual bool vsync_is_using_via_compositor() const;
+
+ //real, actual overridable function to switch vsync, which needs to be called from graphics thread if needed
+
+ enum Context {
+ CONTEXT_EDITOR,
+ CONTEXT_PROJECTMAN,
+ CONTEXT_ENGINE,
+ };
+
+ virtual void set_context(Context p_context);
+
+ static void register_create_function(const char *p_name, CreateFunction p_function, GetVideoDriversFunction p_get_drivers);
+ static int get_create_function_count();
+ static const char *get_create_function_name(int p_index);
+ static Vector<String> get_create_function_rendering_drivers(int p_index);
+ static DisplayServer *create(int p_index, const String &p_rendering_driver, WindowMode p_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error);
DisplayServer();
~DisplayServer();
diff --git a/servers/visual/visual_server_raster.cpp b/servers/visual/visual_server_raster.cpp
index 35ec52a5c0..1026972a62 100644
--- a/servers/visual/visual_server_raster.cpp
+++ b/servers/visual/visual_server_raster.cpp
@@ -234,7 +234,7 @@ void VisualServerRaster::set_debug_generate_wireframes(bool p_generate) {
}
void VisualServerRaster::call_set_use_vsync(bool p_enable) {
- OS::get_singleton()->_set_use_vsync(p_enable);
+ DisplayServer::get_singleton()->_set_use_vsync(p_enable);
}
bool VisualServerRaster::is_low_end() const {
diff --git a/servers/visual/visual_server_wrap_mt.cpp b/servers/visual/visual_server_wrap_mt.cpp
index 90d301c0cd..4169144fc9 100644
--- a/servers/visual/visual_server_wrap_mt.cpp
+++ b/servers/visual/visual_server_wrap_mt.cpp
@@ -31,6 +31,7 @@
#include "visual_server_wrap_mt.h"
#include "core/os/os.h"
#include "core/project_settings.h"
+#include "servers/display_server.h"
void VisualServerWrapMT::thread_exit() {
@@ -61,7 +62,7 @@ void VisualServerWrapMT::thread_loop() {
server_thread = Thread::get_caller_id();
- OS::get_singleton()->make_rendering_thread();
+ DisplayServer::get_singleton()->make_rendering_thread();
visual_server->init();
@@ -108,7 +109,7 @@ void VisualServerWrapMT::init() {
if (create_thread) {
print_verbose("VisualServerWrapMT: Creating render thread");
- OS::get_singleton()->release_rendering_thread();
+ DisplayServer::get_singleton()->release_rendering_thread();
if (create_thread) {
thread = Thread::create(_thread_callback, this);
print_verbose("VisualServerWrapMT: Starting render thread");
@@ -173,7 +174,7 @@ VisualServerWrapMT::VisualServerWrapMT(VisualServer *p_contained, bool p_create_
command_queue(p_create_thread) {
singleton_mt = this;
- OS::switch_vsync_function = set_use_vsync_callback; //as this goes to another thread, make sure it goes properly
+ DisplayServer::switch_vsync_function = set_use_vsync_callback; //as this goes to another thread, make sure it goes properly
visual_server = p_contained;
create_thread = p_create_thread;