diff options
Diffstat (limited to 'servers')
-rw-r--r-- | servers/arvr/arvr_interface.h | 2 | ||||
-rw-r--r-- | servers/arvr/arvr_positional_tracker.cpp | 2 | ||||
-rw-r--r-- | servers/display_server.cpp | 594 | ||||
-rw-r--r-- | servers/display_server.h | 383 | ||||
-rw-r--r-- | servers/register_server_types.cpp | 3 | ||||
-rw-r--r-- | servers/visual/rasterizer.h | 2 | ||||
-rw-r--r-- | servers/visual/rasterizer_rd/rasterizer_rd.cpp | 2 | ||||
-rw-r--r-- | servers/visual/rasterizer_rd/rasterizer_rd.h | 2 | ||||
-rw-r--r-- | servers/visual/rendering_device.h | 7 | ||||
-rw-r--r-- | servers/visual/visual_server_raster.cpp | 2 | ||||
-rw-r--r-- | servers/visual/visual_server_raster.h | 1 | ||||
-rw-r--r-- | servers/visual/visual_server_viewport.cpp | 105 | ||||
-rw-r--r-- | servers/visual/visual_server_viewport.h | 15 | ||||
-rw-r--r-- | servers/visual/visual_server_wrap_mt.cpp | 7 | ||||
-rw-r--r-- | servers/visual/visual_server_wrap_mt.h | 3 | ||||
-rw-r--r-- | servers/visual_server.cpp | 5 | ||||
-rw-r--r-- | servers/visual_server.h | 5 |
17 files changed, 1079 insertions, 61 deletions
diff --git a/servers/arvr/arvr_interface.h b/servers/arvr/arvr_interface.h index f33ddb2411..861061cbf5 100644 --- a/servers/arvr/arvr_interface.h +++ b/servers/arvr/arvr_interface.h @@ -33,7 +33,7 @@ #include "core/math/camera_matrix.h" #include "core/os/thread_safe.h" -#include "scene/main/viewport.h" +#include "scene/main/window.h" #include "servers/arvr_server.h" /** diff --git a/servers/arvr/arvr_positional_tracker.cpp b/servers/arvr/arvr_positional_tracker.cpp index a64e36b6a2..dabeb7b86f 100644 --- a/servers/arvr/arvr_positional_tracker.cpp +++ b/servers/arvr/arvr_positional_tracker.cpp @@ -29,7 +29,7 @@ /*************************************************************************/ #include "arvr_positional_tracker.h" -#include "core/os/input.h" +#include "core/input/input_filter.h" void ARVRPositionalTracker::_bind_methods() { BIND_ENUM_CONSTANT(TRACKER_HAND_UNKNOWN); diff --git a/servers/display_server.cpp b/servers/display_server.cpp new file mode 100644 index 0000000000..1685328cbe --- /dev/null +++ b/servers/display_server.cpp @@ -0,0 +1,594 @@ +/*************************************************************************/ +/* display_server.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "display_server.h" +#include "core/input/input_filter.h" +#include "scene/resources/texture.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; + +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."); +} + +void DisplayServer::global_menu_add_check_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."); +} + +void DisplayServer::global_menu_add_submenu_item(const String &p_menu_root, const String &p_label, const String &p_submenu) { + WARN_PRINT("Global menus not supported by this display server."); +} + +void DisplayServer::global_menu_add_separator(const String &p_menu_root) { + WARN_PRINT("Global menus not supported by this display server."); +} + +void DisplayServer::global_menu_set_item_callback(const String &p_menu_root, int p_idx, const Callable &p_callback) { + WARN_PRINT("Global menus not supported by this display server."); +} + +bool DisplayServer::global_menu_is_item_checked(const String &p_menu_root, int p_idx) const { + WARN_PRINT("Global menus not supported by this display server."); + return false; +} + +bool DisplayServer::global_menu_is_item_checkable(const String &p_menu_root, int p_idx) const { + WARN_PRINT("Global menus not supported by this display server."); + return false; +} + +Callable DisplayServer::global_menu_get_item_callback(const String &p_menu_root, int p_idx) { + WARN_PRINT("Global menus not supported by this display server."); + return Callable(); +} + +Variant DisplayServer::global_menu_get_item_tag(const String &p_menu_root, int p_idx) { + WARN_PRINT("Global menus not supported by this display server."); + return Variant(); +} + +String DisplayServer::global_menu_get_item_text(const String &p_menu_root, int p_idx) { + WARN_PRINT("Global menus not supported by this display server."); + return String(); +} + +String DisplayServer::global_menu_get_item_submenu(const String &p_menu_root, int p_idx) { + WARN_PRINT("Global menus not supported by this display server."); + return String(); +} + +void DisplayServer::global_menu_set_item_checked(const String &p_menu_root, int p_idx, bool p_checked) { + WARN_PRINT("Global menus not supported by this display server."); +} + +void DisplayServer::global_menu_set_item_checkable(const String &p_menu_root, int p_idx, bool p_checkable) { + WARN_PRINT("Global menus not supported by this display server."); +} + +void DisplayServer::global_menu_set_item_tag(const String &p_menu_root, int p_idx, const Variant &p_tag) { + WARN_PRINT("Global menus not supported by this display server."); +} + +void DisplayServer::global_menu_set_item_text(const String &p_menu_root, int p_idx, const String &p_text) { + WARN_PRINT("Global menus not supported by this display server."); +} + +void DisplayServer::global_menu_set_item_submenu(const String &p_menu_root, int p_idx, const String &p_submenu) { + WARN_PRINT("Global menus not supported by this display server."); +} + +int DisplayServer::global_menu_get_item_count(const String &p_menu_root) const { + WARN_PRINT("Global menus not supported by this display server."); + return 0; +} + +void DisplayServer::global_menu_remove_item(const String &p_menu_root, int p_idx) { + WARN_PRINT("Global menus not supported by this display server."); +} + +void DisplayServer::global_menu_clear(const String &p_menu_root) { + WARN_PRINT("Global menus not supported by this display server."); +} + +void DisplayServer::mouse_set_mode(MouseMode p_mode) { + WARN_PRINT("Mouse is not supported by this display server."); +} +DisplayServer::MouseMode DisplayServer::mouse_get_mode() const { + return MOUSE_MODE_VISIBLE; +} + +void DisplayServer::mouse_warp_to_position(const Point2i &p_to) { + WARN_PRINT("Mouse warping is not supported by this display server."); +} +Point2i DisplayServer::mouse_get_absolute_position() const { + ERR_FAIL_V_MSG(Point2i(), "Mouse is not supported by this display server."); +} +Point2i DisplayServer::mouse_get_position() const { + ERR_FAIL_V_MSG(Point2i(), "Mouse is not supported by this display server."); +} +int DisplayServer::mouse_get_button_state() const { + ERR_FAIL_V_MSG(0, "Mouse is not supported by this display server."); +} + +void DisplayServer::clipboard_set(const String &p_text) { + WARN_PRINT("Clipboard is not supported by this display server."); +} +String DisplayServer::clipboard_get() const { + ERR_FAIL_V_MSG(String(), "Clipboard is not supported by this display server."); +} + +void DisplayServer::screen_set_orientation(ScreenOrientation p_orientation, int p_screen) { + WARN_PRINT("Orientation not supported by this display server."); +} +DisplayServer::ScreenOrientation DisplayServer::screen_get_orientation(int p_screen) const { + return SCREEN_LANDSCAPE; +} + +float DisplayServer::screen_get_scale(int p_screen) const { + return 1.0f; +}; + +bool DisplayServer::screen_is_touchscreen(int p_screen) const { + //return false; + return InputFilter::get_singleton() && InputFilter::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."); +} +void DisplayServer::delete_sub_window(WindowID p_id) { + ERR_FAIL_MSG("Sub-windows not supported by this display server."); +} + +void DisplayServer::window_set_ime_active(const bool p_active, WindowID p_window) { + WARN_PRINT("IME not supported by this display server."); +} +void DisplayServer::window_set_ime_position(const Point2i &p_pos, WindowID p_window) { + WARN_PRINT("IME not supported by this display server."); +} + +Point2i DisplayServer::ime_get_selection() const { + ERR_FAIL_V_MSG(Point2i(), "IME or NOTIFICATION_WM_IME_UPDATE not supported by this display server."); +} +String DisplayServer::ime_get_text() const { + ERR_FAIL_V_MSG(String(), "IME or NOTIFICATION_WM_IME_UPDATEnot supported by this display server."); +} + +void DisplayServer::console_set_visible(bool p_enabled) { + WARN_PRINT("Console window not supported by this display server."); +} +bool DisplayServer::is_console_visible() const { + return false; +} + +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() { + WARN_PRINT("Virtual keyboard not supported by this display server."); +} + +// returns height of the currently shown keyboard (0 if keyboard is hidden) +int DisplayServer::virtual_keyboard_get_height() const { + ERR_FAIL_V_MSG(0, "Virtual keyboad not supported by this display server."); +} + +void DisplayServer::cursor_set_shape(CursorShape p_shape) { + WARN_PRINT("Cursor shape not supported by this display server."); +} +DisplayServer::CursorShape DisplayServer::cursor_get_shape() const { + return CURSOR_ARROW; +} +void DisplayServer::cursor_set_custom_image(const RES &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) { + WARN_PRINT("Custom cursor shape not supported by this display server."); +} + +bool DisplayServer::get_swap_ok_cancel() { + return false; +} + +void DisplayServer::enable_for_stealing_focus(OS::ProcessID pid) { +} + +//plays video natively, in fullscreen, only implemented in mobile for now, likely not possible to implement on linux also. +Error DisplayServer::native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track, int p_screen) { + ERR_FAIL_V_MSG(ERR_UNAVAILABLE, "Native video not supported by this display server."); +} +bool DisplayServer::native_video_is_playing() const { + return false; +} +void DisplayServer::native_video_pause() { + WARN_PRINT("Native video not supported by this display server."); +} +void DisplayServer::native_video_unpause() { + WARN_PRINT("Native video not supported by this display server."); +} +void DisplayServer::native_video_stop() { + WARN_PRINT("Native video not supported by this display server."); +} + +Error DisplayServer::dialog_show(String p_title, String p_description, Vector<String> p_buttons, const Callable &p_callback) { + WARN_PRINT("Native dialogs not supported by this display server."); + return OK; +} +Error DisplayServer::dialog_input_text(String p_title, String p_description, String p_partial, const Callable &p_callback) { + WARN_PRINT("Native dialogs not supported by this display server."); + return OK; +} + +DisplayServer::LatinKeyboardVariant DisplayServer::get_latin_keyboard_variant() const { + return LATIN_KEYBOARD_QWERTY; +} + +void DisplayServer::force_process_and_drop_events() { +} + +void DisplayServer::release_rendering_thread() { + WARN_PRINT("Rendering thread not supported by this display server."); +} +void DisplayServer::make_rendering_thread() { + WARN_PRINT("Rendering thread not supported by this display server."); +} +void DisplayServer::swap_buffers() { + WARN_PRINT("Swap buffers not supported by this display server."); +} + +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("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() { + + ClassDB::bind_method(D_METHOD("has_feature", "feature"), &DisplayServer::has_feature); + ClassDB::bind_method(D_METHOD("get_name"), &DisplayServer::get_name); + + ClassDB::bind_method(D_METHOD("global_menu_add_item", "menu_root", "label", "callback", "tag"), &DisplayServer::global_menu_add_item, DEFVAL(Variant())); + ClassDB::bind_method(D_METHOD("global_menu_add_check_item", "menu_root", "label", "callback", "tag"), &DisplayServer::global_menu_add_check_item, DEFVAL(Variant())); + ClassDB::bind_method(D_METHOD("global_menu_add_submenu_item", "menu_root", "label", "submenu"), &DisplayServer::global_menu_add_submenu_item); + ClassDB::bind_method(D_METHOD("global_menu_add_separator", "menu_root"), &DisplayServer::global_menu_add_separator); + + ClassDB::bind_method(D_METHOD("global_menu_is_item_checked", "menu_root", "idx"), &DisplayServer::global_menu_is_item_checked); + ClassDB::bind_method(D_METHOD("global_menu_is_item_checkable", "menu_root", "idx"), &DisplayServer::global_menu_is_item_checkable); + ClassDB::bind_method(D_METHOD("global_menu_get_item_callback", "menu_root", "idx"), &DisplayServer::global_menu_get_item_callback); + ClassDB::bind_method(D_METHOD("global_menu_get_item_tag", "menu_root", "idx"), &DisplayServer::global_menu_get_item_tag); + ClassDB::bind_method(D_METHOD("global_menu_get_item_text", "menu_root", "idx"), &DisplayServer::global_menu_get_item_text); + ClassDB::bind_method(D_METHOD("global_menu_get_item_submenu", "menu_root", "idx"), &DisplayServer::global_menu_get_item_submenu); + + ClassDB::bind_method(D_METHOD("global_menu_set_item_checked", "menu_root", "idx", "checked"), &DisplayServer::global_menu_set_item_checked); + ClassDB::bind_method(D_METHOD("global_menu_set_item_checkable", "menu_root", "idx", "checkable"), &DisplayServer::global_menu_set_item_checkable); + ClassDB::bind_method(D_METHOD("global_menu_set_item_callback", "menu_root", "idx", "callback"), &DisplayServer::global_menu_set_item_callback); + ClassDB::bind_method(D_METHOD("global_menu_set_item_tag", "menu_root", "idx", "tag"), &DisplayServer::global_menu_set_item_tag); + ClassDB::bind_method(D_METHOD("global_menu_set_item_text", "menu_root", "idx", "text"), &DisplayServer::global_menu_set_item_text); + ClassDB::bind_method(D_METHOD("global_menu_set_item_submenu", "menu_root", "idx", "submenu"), &DisplayServer::global_menu_set_item_submenu); + + ClassDB::bind_method(D_METHOD("global_menu_remove_item", "menu_root", "idx"), &DisplayServer::global_menu_remove_item); + ClassDB::bind_method(D_METHOD("global_menu_clear", "menu_root"), &DisplayServer::global_menu_clear); + + ClassDB::bind_method(D_METHOD("alert", "text", "title"), &DisplayServer::alert, DEFVAL("Alert!")); + + ClassDB::bind_method(D_METHOD("mouse_set_mode", "mouse_mode"), &DisplayServer::mouse_set_mode); + ClassDB::bind_method(D_METHOD("mouse_get_mode"), &DisplayServer::mouse_get_mode); + + ClassDB::bind_method(D_METHOD("mouse_warp_to_position", "position"), &DisplayServer::mouse_warp_to_position); + ClassDB::bind_method(D_METHOD("mouse_get_position"), &DisplayServer::mouse_get_position); + ClassDB::bind_method(D_METHOD("mouse_get_absolute_position"), &DisplayServer::mouse_get_absolute_position); + ClassDB::bind_method(D_METHOD("mouse_get_button_state"), &DisplayServer::mouse_get_button_state); + + ClassDB::bind_method(D_METHOD("clipboard_set", "clipboard"), &DisplayServer::clipboard_set); + ClassDB::bind_method(D_METHOD("clipboard_get"), &DisplayServer::clipboard_get); + + ClassDB::bind_method(D_METHOD("get_screen_count"), &DisplayServer::get_screen_count); + ClassDB::bind_method(D_METHOD("screen_get_position", "screen"), &DisplayServer::screen_get_position, DEFVAL(SCREEN_OF_MAIN_WINDOW)); + ClassDB::bind_method(D_METHOD("screen_get_size", "screen"), &DisplayServer::screen_get_size, DEFVAL(SCREEN_OF_MAIN_WINDOW)); + ClassDB::bind_method(D_METHOD("screen_get_usable_rect", "screen"), &DisplayServer::screen_get_usable_rect, DEFVAL(SCREEN_OF_MAIN_WINDOW)); + ClassDB::bind_method(D_METHOD("screen_get_dpi", "screen"), &DisplayServer::screen_get_dpi, DEFVAL(SCREEN_OF_MAIN_WINDOW)); + ClassDB::bind_method(D_METHOD("screen_get_scale", "screen"), &DisplayServer::screen_get_scale, DEFVAL(SCREEN_OF_MAIN_WINDOW)); + ClassDB::bind_method(D_METHOD("screen_is_touchscreen", "screen"), &DisplayServer::screen_is_touchscreen, DEFVAL(SCREEN_OF_MAIN_WINDOW)); + + 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("get_window_at_screen_position", "position"), &DisplayServer::get_window_at_screen_position); + + ClassDB::bind_method(D_METHOD("create_sub_window", "mode", "rect"), &DisplayServer::create_sub_window, DEFVAL(Rect2i())); + ClassDB::bind_method(D_METHOD("delete_sub_window", "window_id"), &DisplayServer::delete_sub_window); + + ClassDB::bind_method(D_METHOD("window_set_title", "title", "window_id"), &DisplayServer::window_set_title, DEFVAL(MAIN_WINDOW_ID)); + + ClassDB::bind_method(D_METHOD("window_get_current_screen", "window_id"), &DisplayServer::window_get_current_screen, DEFVAL(MAIN_WINDOW_ID)); + ClassDB::bind_method(D_METHOD("window_set_current_screen", "screen", "window_id"), &DisplayServer::window_set_current_screen, DEFVAL(MAIN_WINDOW_ID)); + + ClassDB::bind_method(D_METHOD("window_get_position", "window_id"), &DisplayServer::window_get_position, DEFVAL(MAIN_WINDOW_ID)); + ClassDB::bind_method(D_METHOD("window_set_position", "position", "window_id"), &DisplayServer::window_set_position, DEFVAL(MAIN_WINDOW_ID)); + + ClassDB::bind_method(D_METHOD("window_get_size", "window_id"), &DisplayServer::window_get_size, DEFVAL(MAIN_WINDOW_ID)); + ClassDB::bind_method(D_METHOD("window_set_size", "size", "window_id"), &DisplayServer::window_set_size, DEFVAL(MAIN_WINDOW_ID)); + ClassDB::bind_method(D_METHOD("window_set_rect_changed_callback", "callback", "window_id"), &DisplayServer::window_set_rect_changed_callback, DEFVAL(MAIN_WINDOW_ID)); + ClassDB::bind_method(D_METHOD("window_set_window_event_callback", "callback", "window_id"), &DisplayServer::window_set_window_event_callback, DEFVAL(MAIN_WINDOW_ID)); + ClassDB::bind_method(D_METHOD("window_set_input_event_callback", "callback", "window_id"), &DisplayServer::window_set_input_event_callback, DEFVAL(MAIN_WINDOW_ID)); + ClassDB::bind_method(D_METHOD("window_set_input_text_callback", "callback", "window_id"), &DisplayServer::window_set_input_text_callback, DEFVAL(MAIN_WINDOW_ID)); + ClassDB::bind_method(D_METHOD("window_set_drop_files_callback", "callback", "window_id"), &DisplayServer::window_set_drop_files_callback, DEFVAL(MAIN_WINDOW_ID)); + + ClassDB::bind_method(D_METHOD("window_attach_instance_id", "instance_id", "window_id"), &DisplayServer::window_attach_instance_id, DEFVAL(MAIN_WINDOW_ID)); + ClassDB::bind_method(D_METHOD("window_get_attached_instance_id", "window_id"), &DisplayServer::window_get_attached_instance_id, DEFVAL(MAIN_WINDOW_ID)); + + ClassDB::bind_method(D_METHOD("window_get_max_size", "window_id"), &DisplayServer::window_get_max_size, DEFVAL(MAIN_WINDOW_ID)); + ClassDB::bind_method(D_METHOD("window_set_max_size", "max_size", "window_id"), &DisplayServer::window_set_max_size, DEFVAL(MAIN_WINDOW_ID)); + + ClassDB::bind_method(D_METHOD("window_get_min_size", "window_id"), &DisplayServer::window_get_min_size, DEFVAL(MAIN_WINDOW_ID)); + ClassDB::bind_method(D_METHOD("window_set_min_size", "min_size", "window_id"), &DisplayServer::window_set_min_size, DEFVAL(MAIN_WINDOW_ID)); + + ClassDB::bind_method(D_METHOD("window_get_real_size", "window_id"), &DisplayServer::window_get_real_size, DEFVAL(MAIN_WINDOW_ID)); + + ClassDB::bind_method(D_METHOD("window_get_mode", "window_id"), &DisplayServer::window_get_mode, DEFVAL(MAIN_WINDOW_ID)); + ClassDB::bind_method(D_METHOD("window_set_mode", "mode", "window_id"), &DisplayServer::window_set_mode, DEFVAL(MAIN_WINDOW_ID)); + + ClassDB::bind_method(D_METHOD("window_set_flag", "flag", "enabled", "window_id"), &DisplayServer::window_set_flag, DEFVAL(MAIN_WINDOW_ID)); + ClassDB::bind_method(D_METHOD("window_get_flag", "flag", "window_id"), &DisplayServer::window_get_flag, DEFVAL(MAIN_WINDOW_ID)); + + ClassDB::bind_method(D_METHOD("window_request_attention", "window_id"), &DisplayServer::window_request_attention, DEFVAL(MAIN_WINDOW_ID)); + + ClassDB::bind_method(D_METHOD("window_move_to_foreground", "window_id"), &DisplayServer::window_move_to_foreground, DEFVAL(MAIN_WINDOW_ID)); + ClassDB::bind_method(D_METHOD("window_can_draw", "window_id"), &DisplayServer::window_can_draw, DEFVAL(MAIN_WINDOW_ID)); + + ClassDB::bind_method(D_METHOD("window_set_transient", "window_id", "parent_window_id"), &DisplayServer::window_set_transient); + + ClassDB::bind_method(D_METHOD("window_set_ime_active", "active", "window_id"), &DisplayServer::window_set_ime_active, DEFVAL(MAIN_WINDOW_ID)); + ClassDB::bind_method(D_METHOD("window_set_ime_position", "position", "window_id"), &DisplayServer::window_set_ime_position, DEFVAL(MAIN_WINDOW_ID)); + + ClassDB::bind_method(D_METHOD("ime_get_selection"), &DisplayServer::ime_get_selection); + ClassDB::bind_method(D_METHOD("ime_get_text"), &DisplayServer::ime_get_text); + + 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", "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, DEFVAL(CURSOR_ARROW), DEFVAL(Vector2())); + + ClassDB::bind_method(D_METHOD("get_swap_ok_cancel"), &DisplayServer::get_swap_ok_cancel); + + ClassDB::bind_method(D_METHOD("enable_for_stealing_focus", "process_id"), &DisplayServer::enable_for_stealing_focus); + + ClassDB::bind_method(D_METHOD("native_video_play", "path", "volume", "audio_track", "subtitle_track"), &DisplayServer::native_video_play); + ClassDB::bind_method(D_METHOD("native_video_is_playing"), &DisplayServer::native_video_is_playing); + ClassDB::bind_method(D_METHOD("native_video_stop"), &DisplayServer::native_video_stop); + ClassDB::bind_method(D_METHOD("native_video_pause"), &DisplayServer::native_video_pause); + ClassDB::bind_method(D_METHOD("native_video_unpause"), &DisplayServer::native_video_unpause); + + ClassDB::bind_method(D_METHOD("dialog_show", "title", "description", "buttons", "callback"), &DisplayServer::dialog_show); + ClassDB::bind_method(D_METHOD("dialog_input_text", "title", "description", "existing_text", "callback"), &DisplayServer::dialog_show); + + ClassDB::bind_method(D_METHOD("get_latin_keyboard_variant"), &DisplayServer::get_latin_keyboard_variant); + + 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); + + BIND_ENUM_CONSTANT(FEATURE_GLOBAL_MENU); + BIND_ENUM_CONSTANT(FEATURE_SUBWINDOWS); + BIND_ENUM_CONSTANT(FEATURE_TOUCHSCREEN); + BIND_ENUM_CONSTANT(FEATURE_MOUSE); + BIND_ENUM_CONSTANT(FEATURE_MOUSE_WARP); + BIND_ENUM_CONSTANT(FEATURE_CLIPBOARD); + BIND_ENUM_CONSTANT(FEATURE_VIRTUAL_KEYBOARD); + BIND_ENUM_CONSTANT(FEATURE_CURSOR_SHAPE); + BIND_ENUM_CONSTANT(FEATURE_CUSTOM_CURSOR_SHAPE); + BIND_ENUM_CONSTANT(FEATURE_NATIVE_VIDEO); + BIND_ENUM_CONSTANT(FEATURE_NATIVE_DIALOG); + BIND_ENUM_CONSTANT(FEATURE_CONSOLE_WINDOW); + BIND_ENUM_CONSTANT(FEATURE_IME); + BIND_ENUM_CONSTANT(FEATURE_WINDOW_TRANSPARENCY); + BIND_ENUM_CONSTANT(FEATURE_HIDPI); + BIND_ENUM_CONSTANT(FEATURE_ICON); + BIND_ENUM_CONSTANT(FEATURE_NATIVE_ICON); + BIND_ENUM_CONSTANT(FEATURE_ORIENTATION); + BIND_ENUM_CONSTANT(FEATURE_SWAP_BUFFERS); + + BIND_ENUM_CONSTANT(MOUSE_MODE_VISIBLE); + BIND_ENUM_CONSTANT(MOUSE_MODE_HIDDEN); + BIND_ENUM_CONSTANT(MOUSE_MODE_CAPTURED); + BIND_ENUM_CONSTANT(MOUSE_MODE_CONFINED); + + BIND_CONSTANT(SCREEN_OF_MAIN_WINDOW); + BIND_CONSTANT(MAIN_WINDOW_ID); + BIND_CONSTANT(INVALID_WINDOW_ID); + + BIND_ENUM_CONSTANT(SCREEN_LANDSCAPE); + BIND_ENUM_CONSTANT(SCREEN_PORTRAIT); + BIND_ENUM_CONSTANT(SCREEN_REVERSE_LANDSCAPE); + BIND_ENUM_CONSTANT(SCREEN_REVERSE_PORTRAIT); + BIND_ENUM_CONSTANT(SCREEN_SENSOR_LANDSCAPE); + BIND_ENUM_CONSTANT(SCREEN_SENSOR_PORTRAIT); + BIND_ENUM_CONSTANT(SCREEN_SENSOR); + + BIND_ENUM_CONSTANT(CURSOR_ARROW); + BIND_ENUM_CONSTANT(CURSOR_IBEAM); + BIND_ENUM_CONSTANT(CURSOR_POINTING_HAND); + BIND_ENUM_CONSTANT(CURSOR_CROSS); + BIND_ENUM_CONSTANT(CURSOR_WAIT); + BIND_ENUM_CONSTANT(CURSOR_BUSY); + BIND_ENUM_CONSTANT(CURSOR_DRAG); + BIND_ENUM_CONSTANT(CURSOR_CAN_DROP); + BIND_ENUM_CONSTANT(CURSOR_FORBIDDEN); + BIND_ENUM_CONSTANT(CURSOR_VSIZE); + BIND_ENUM_CONSTANT(CURSOR_HSIZE); + BIND_ENUM_CONSTANT(CURSOR_BDIAGSIZE); + BIND_ENUM_CONSTANT(CURSOR_FDIAGSIZE); + BIND_ENUM_CONSTANT(CURSOR_MOVE); + BIND_ENUM_CONSTANT(CURSOR_VSPLIT); + BIND_ENUM_CONSTANT(CURSOR_HSPLIT); + BIND_ENUM_CONSTANT(CURSOR_HELP); + BIND_ENUM_CONSTANT(CURSOR_MAX); + + BIND_ENUM_CONSTANT(WINDOW_MODE_WINDOWED); + BIND_ENUM_CONSTANT(WINDOW_MODE_MINIMIZED); + BIND_ENUM_CONSTANT(WINDOW_MODE_MAXIMIZED); + BIND_ENUM_CONSTANT(WINDOW_MODE_FULLSCREEN); + + BIND_ENUM_CONSTANT(WINDOW_FLAG_RESIZE_DISABLED); + BIND_ENUM_CONSTANT(WINDOW_FLAG_BORDERLESS); + BIND_ENUM_CONSTANT(WINDOW_FLAG_ALWAYS_ON_TOP); + BIND_ENUM_CONSTANT(WINDOW_FLAG_TRANSPARENT); + BIND_ENUM_CONSTANT(WINDOW_FLAG_NO_FOCUS); + BIND_ENUM_CONSTANT(WINDOW_FLAG_MAX); + BIND_ENUM_CONSTANT(WINDOW_FLAG_RESIZE_DISABLED_BIT); + BIND_ENUM_CONSTANT(WINDOW_FLAG_BORDERLESS_BIT); + BIND_ENUM_CONSTANT(WINDOW_FLAG_ALWAYS_ON_TOP_BIT); + BIND_ENUM_CONSTANT(WINDOW_FLAG_TRANSPARENT_BIT); + BIND_ENUM_CONSTANT(WINDOW_FLAG_NO_FOCUS_BIT); + + BIND_ENUM_CONSTANT(LATIN_KEYBOARD_QWERTY); + BIND_ENUM_CONSTANT(LATIN_KEYBOARD_QWERTZ); + BIND_ENUM_CONSTANT(LATIN_KEYBOARD_AZERTY); + BIND_ENUM_CONSTANT(LATIN_KEYBOARD_QZERTY); + BIND_ENUM_CONSTANT(LATIN_KEYBOARD_DVORAK); + BIND_ENUM_CONSTANT(LATIN_KEYBOARD_NEO); + BIND_ENUM_CONSTANT(LATIN_KEYBOARD_COLEMAK); + + BIND_ENUM_CONSTANT(WINDOW_EVENT_MOUSE_ENTER); + BIND_ENUM_CONSTANT(WINDOW_EVENT_MOUSE_EXIT); + BIND_ENUM_CONSTANT(WINDOW_EVENT_FOCUS_IN); + BIND_ENUM_CONSTANT(WINDOW_EVENT_FOCUS_OUT); + BIND_ENUM_CONSTANT(WINDOW_EVENT_CLOSE_REQUEST); + BIND_ENUM_CONSTANT(WINDOW_EVENT_GO_BACK_REQUEST); + BIND_ENUM_CONSTANT(WINDOW_EVENT_DPI_CHANGE); +} + +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(InputFilter::MouseMode p_mode) { + singleton->mouse_set_mode(MouseMode(p_mode)); +} +InputFilter::MouseMode DisplayServer::_input_get_mouse_mode() { + return InputFilter::MouseMode(singleton->mouse_get_mode()); +} + +void DisplayServer::_input_warp(const Vector2 &p_to_pos) { + singleton->mouse_warp_to_position(p_to_pos); +} + +InputFilter::CursorShape DisplayServer::_input_get_current_cursor_shape() { + return (InputFilter::CursorShape)singleton->cursor_get_shape(); +} +void DisplayServer::_input_set_custom_mouse_cursor_func(const RES &p_image, InputFilter::CursorShape p_shape, const Vector2 &p_hostspot) { + singleton->cursor_set_custom_image(p_image, (CursorShape)p_shape, p_hostspot); +} + +DisplayServer::DisplayServer() { + singleton = this; + InputFilter::set_mouse_mode_func = _input_set_mouse_mode; + InputFilter::get_mouse_mode_func = _input_get_mouse_mode; + InputFilter::warp_mouse_func = _input_warp; + InputFilter::get_current_cursor_shape_func = _input_get_current_cursor_shape; + InputFilter::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 new file mode 100644 index 0000000000..8ed0b11d03 --- /dev/null +++ b/servers/display_server.h @@ -0,0 +1,383 @@ +/*************************************************************************/ +/* display_server.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef DISPLAY_SERVER_H +#define DISPLAY_SERVER_H + +#include "core/callable.h" +#include "core/input/input_filter.h" +#include "core/os/os.h" +#include "core/resource.h" + +class Texture2D; + +class DisplayServer : public Object { + GDCLASS(DisplayServer, Object) + + static DisplayServer *singleton; + bool vsync_enabled = true; + static bool hidpi_allowed; + +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(InputFilter::MouseMode p_mode); + static InputFilter::MouseMode _input_get_mouse_mode(); + static void _input_warp(const Vector2 &p_to_pos); + static InputFilter::CursorShape _input_get_current_cursor_shape(); + static void _input_set_custom_mouse_cursor_func(const RES &, InputFilter::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 { + FEATURE_GLOBAL_MENU, + FEATURE_SUBWINDOWS, + FEATURE_TOUCHSCREEN, + FEATURE_MOUSE, + FEATURE_MOUSE_WARP, + FEATURE_CLIPBOARD, + FEATURE_VIRTUAL_KEYBOARD, + FEATURE_CURSOR_SHAPE, + FEATURE_CUSTOM_CURSOR_SHAPE, + FEATURE_NATIVE_VIDEO, + FEATURE_NATIVE_DIALOG, + FEATURE_CONSOLE_WINDOW, + FEATURE_IME, + FEATURE_WINDOW_TRANSPARENCY, + FEATURE_HIDPI, + FEATURE_ICON, + FEATURE_NATIVE_ICON, + FEATURE_ORIENTATION, + FEATURE_SWAP_BUFFERS, + FEATURE_KEEP_SCREEN_ON, + }; + + virtual bool has_feature(Feature p_feature) const = 0; + virtual String get_name() const = 0; + + virtual void global_menu_add_item(const String &p_menu_root, const String &p_label, const Callable &p_callback, const Variant &p_tag = Variant()); + virtual void global_menu_add_check_item(const String &p_menu_root, const String &p_label, const Callable &p_callback, const Variant &p_tag = Variant()); + virtual void global_menu_add_submenu_item(const String &p_menu_root, const String &p_label, const String &p_submenu); + virtual void global_menu_add_separator(const String &p_menu_root); + + virtual bool global_menu_is_item_checked(const String &p_menu_root, int p_idx) const; + virtual bool global_menu_is_item_checkable(const String &p_menu_root, int p_idx) const; + virtual Callable global_menu_get_item_callback(const String &p_menu_root, int p_idx); + virtual Variant global_menu_get_item_tag(const String &p_menu_root, int p_idx); + virtual String global_menu_get_item_text(const String &p_menu_root, int p_idx); + virtual String global_menu_get_item_submenu(const String &p_menu_root, int p_idx); + + virtual void global_menu_set_item_checked(const String &p_menu_root, int p_idx, bool p_checked); + virtual void global_menu_set_item_checkable(const String &p_menu_root, int p_idx, bool p_checkable); + virtual void global_menu_set_item_callback(const String &p_menu_root, int p_idx, const Callable &p_callback); + virtual void global_menu_set_item_tag(const String &p_menu_root, int p_idx, const Variant &p_tag); + virtual void global_menu_set_item_text(const String &p_menu_root, int p_idx, const String &p_text); + virtual void global_menu_set_item_submenu(const String &p_menu_root, int p_idx, const String &p_submenu); + + virtual int global_menu_get_item_count(const String &p_menu_root) const; + + virtual void global_menu_remove_item(const String &p_menu_root, int p_idx); + virtual void global_menu_clear(const String &p_menu_root); + + virtual void alert(const String &p_alert, const String &p_title = "ALERT!") = 0; + + enum MouseMode { + MOUSE_MODE_VISIBLE, + MOUSE_MODE_HIDDEN, + MOUSE_MODE_CAPTURED, + MOUSE_MODE_CONFINED + }; + + virtual void mouse_set_mode(MouseMode p_mode); + virtual MouseMode mouse_get_mode() const; + + virtual void mouse_warp_to_position(const Point2i &p_to); + virtual Point2i mouse_get_position() const; + virtual Point2i mouse_get_absolute_position() const; + virtual int mouse_get_button_state() const; + + virtual void clipboard_set(const String &p_text); + virtual String clipboard_get() const; + + enum { + SCREEN_OF_MAIN_WINDOW = -1 + }; + + virtual int get_screen_count() const = 0; + 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 Rect2i screen_get_usable_rect(int p_screen = SCREEN_OF_MAIN_WINDOW) const = 0; + virtual int screen_get_dpi(int p_screen = SCREEN_OF_MAIN_WINDOW) const = 0; + virtual float screen_get_scale(int p_screen = SCREEN_OF_MAIN_WINDOW) const; + virtual bool screen_is_touchscreen(int p_screen = SCREEN_OF_MAIN_WINDOW) const; + enum ScreenOrientation { + + SCREEN_LANDSCAPE, + SCREEN_PORTRAIT, + SCREEN_REVERSE_LANDSCAPE, + SCREEN_REVERSE_PORTRAIT, + SCREEN_SENSOR_LANDSCAPE, + SCREEN_SENSOR_PORTRAIT, + SCREEN_SENSOR, + }; + + 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 + }; + + typedef int WindowID; + + virtual Vector<DisplayServer::WindowID> get_window_list() const = 0; + + enum WindowFlags { + WINDOW_FLAG_RESIZE_DISABLED, + WINDOW_FLAG_BORDERLESS, + WINDOW_FLAG_ALWAYS_ON_TOP, + WINDOW_FLAG_TRANSPARENT, + WINDOW_FLAG_NO_FOCUS, + WINDOW_FLAG_MAX, + WINDOW_FLAG_RESIZE_DISABLED_BIT = (1 << WINDOW_FLAG_RESIZE_DISABLED), + WINDOW_FLAG_BORDERLESS_BIT = (1 << WINDOW_FLAG_BORDERLESS), + WINDOW_FLAG_ALWAYS_ON_TOP_BIT = (1 << WINDOW_FLAG_ALWAYS_ON_TOP), + WINDOW_FLAG_TRANSPARENT_BIT = (1 << WINDOW_FLAG_TRANSPARENT), + WINDOW_FLAG_NO_FOCUS_BIT = (1 << WINDOW_FLAG_NO_FOCUS) + }; + + virtual WindowID create_sub_window(WindowMode p_mode, uint32_t p_flags, const Rect2i & = Rect2i()); + virtual void delete_sub_window(WindowID p_id); + + virtual WindowID get_window_at_screen_position(const Point2i &p_position) const = 0; + + virtual void window_attach_instance_id(ObjectID p_instance, WindowID p_window = MAIN_WINDOW_ID) = 0; + virtual ObjectID window_get_attached_instance_id(WindowID p_window = MAIN_WINDOW_ID) const = 0; + + virtual void window_set_rect_changed_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) = 0; + + enum WindowEvent { + WINDOW_EVENT_MOUSE_ENTER, + WINDOW_EVENT_MOUSE_EXIT, + WINDOW_EVENT_FOCUS_IN, + WINDOW_EVENT_FOCUS_OUT, + WINDOW_EVENT_CLOSE_REQUEST, + WINDOW_EVENT_GO_BACK_REQUEST, + WINDOW_EVENT_DPI_CHANGE, + }; + virtual void window_set_window_event_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) = 0; + virtual void window_set_input_event_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) = 0; + virtual void window_set_input_text_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) = 0; + + virtual void window_set_drop_files_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) = 0; + + virtual void window_set_title(const String &p_title, WindowID p_window = MAIN_WINDOW_ID) = 0; + + virtual int window_get_current_screen(WindowID p_window = MAIN_WINDOW_ID) const = 0; + virtual void window_set_current_screen(int p_screen, WindowID p_window = MAIN_WINDOW_ID) = 0; + + virtual Point2i window_get_position(WindowID p_window = MAIN_WINDOW_ID) const = 0; + virtual void window_set_position(const Point2i &p_position, WindowID p_window = MAIN_WINDOW_ID) = 0; + + virtual void window_set_transient(WindowID p_window, WindowID p_parent) = 0; + + virtual void window_set_max_size(const Size2i p_size, WindowID p_window = MAIN_WINDOW_ID) = 0; + virtual Size2i window_get_max_size(WindowID p_window = MAIN_WINDOW_ID) const = 0; + + virtual void window_set_min_size(const Size2i p_size, WindowID p_window = MAIN_WINDOW_ID) = 0; + virtual Size2i window_get_min_size(WindowID p_window = MAIN_WINDOW_ID) const = 0; + + virtual void window_set_size(const Size2i p_size, WindowID p_window = MAIN_WINDOW_ID) = 0; + virtual Size2i window_get_size(WindowID p_window = MAIN_WINDOW_ID) const = 0; + virtual Size2i window_get_real_size(WindowID p_window = MAIN_WINDOW_ID) const = 0; // FIXME: Find clearer name for this. + + virtual void window_set_mode(WindowMode p_mode, WindowID p_window = MAIN_WINDOW_ID) = 0; + virtual WindowMode window_get_mode(WindowID p_window = MAIN_WINDOW_ID) const = 0; + + virtual bool window_is_maximize_allowed(WindowID p_window = MAIN_WINDOW_ID) const = 0; + + virtual void window_set_flag(WindowFlags p_flag, bool p_enabled, WindowID p_window = MAIN_WINDOW_ID) = 0; + virtual bool window_get_flag(WindowFlags p_flag, WindowID p_window = MAIN_WINDOW_ID) const = 0; + + virtual void window_request_attention(WindowID p_window = MAIN_WINDOW_ID) = 0; + virtual void window_move_to_foreground(WindowID p_window = MAIN_WINDOW_ID) = 0; + + 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); + + virtual Point2i ime_get_selection() const; + virtual String ime_get_text() const; + + 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(), int p_max_legth = -1); + virtual void virtual_keyboard_hide(); + + // returns height of the currently shown virtual keyboard (0 if keyboard is hidden) + virtual int virtual_keyboard_get_height() const; + + enum CursorShape { + CURSOR_ARROW, + CURSOR_IBEAM, + CURSOR_POINTING_HAND, + CURSOR_CROSS, + CURSOR_WAIT, + CURSOR_BUSY, + CURSOR_DRAG, + CURSOR_CAN_DROP, + CURSOR_FORBIDDEN, + CURSOR_VSIZE, + CURSOR_HSIZE, + CURSOR_BDIAGSIZE, + CURSOR_FDIAGSIZE, + CURSOR_MOVE, + CURSOR_VSPLIT, + CURSOR_HSPLIT, + CURSOR_HELP, + CURSOR_MAX + }; + 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 = CURSOR_ARROW, const Vector2 &p_hotspot = Vector2()); + + virtual bool get_swap_ok_cancel(); + + virtual void enable_for_stealing_focus(OS::ProcessID pid); + + //plays video natively, in fullscreen, only implemented in mobile for now, likely not possible to implement on linux also. + virtual Error native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track, int p_screen = SCREEN_OF_MAIN_WINDOW); + virtual bool native_video_is_playing() const; + virtual void native_video_pause(); + virtual void native_video_unpause(); + virtual void native_video_stop(); + + virtual Error dialog_show(String p_title, String p_description, Vector<String> p_buttons, const Callable &p_callback); + virtual Error dialog_input_text(String p_title, String p_description, String p_partial, const Callable &p_callback); + + enum LatinKeyboardVariant { + LATIN_KEYBOARD_QWERTY, + LATIN_KEYBOARD_QWERTZ, + LATIN_KEYBOARD_AZERTY, + LATIN_KEYBOARD_QZERTY, + LATIN_KEYBOARD_DVORAK, + LATIN_KEYBOARD_NEO, + LATIN_KEYBOARD_COLEMAK, + }; + + virtual LatinKeyboardVariant get_latin_keyboard_variant() const; + + virtual void process_events() = 0; + + virtual void force_process_and_drop_events(); + + virtual void release_rendering_thread(); + virtual void make_rendering_thread(); + virtual void swap_buffers(); + + virtual void set_native_icon(const String &p_filename); + virtual void set_icon(const Ref<Image> &p_icon); + + 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(); +}; + +VARIANT_ENUM_CAST(DisplayServer::WindowEvent) +VARIANT_ENUM_CAST(DisplayServer::Feature) +VARIANT_ENUM_CAST(DisplayServer::MouseMode) +VARIANT_ENUM_CAST(DisplayServer::ScreenOrientation) +VARIANT_ENUM_CAST(DisplayServer::WindowMode) +VARIANT_ENUM_CAST(DisplayServer::WindowFlags) +VARIANT_ENUM_CAST(DisplayServer::CursorShape) +VARIANT_ENUM_CAST(DisplayServer::LatinKeyboardVariant) + +#endif // DISPLAY_SERVER_H diff --git a/servers/register_server_types.cpp b/servers/register_server_types.cpp index fd65f57380..574b373c30 100644 --- a/servers/register_server_types.cpp +++ b/servers/register_server_types.cpp @@ -29,6 +29,7 @@ /*************************************************************************/ #include "register_server_types.h" + #include "core/engine.h" #include "core/project_settings.h" @@ -56,6 +57,7 @@ #include "audio_server.h" #include "camera/camera_feed.h" #include "camera_server.h" +#include "display_server.h" #include "navigation_2d_server.h" #include "navigation_server.h" #include "physics/physics_server_sw.h" @@ -95,6 +97,7 @@ void register_server_types() { OS::get_singleton()->set_has_server_feature_callback(has_server_feature_callback); + ClassDB::register_virtual_class<DisplayServer>(); ClassDB::register_virtual_class<VisualServer>(); ClassDB::register_class<AudioServer>(); ClassDB::register_virtual_class<PhysicsServer>(); diff --git a/servers/visual/rasterizer.h b/servers/visual/rasterizer.h index 84eda2d80c..d5d32c8d47 100644 --- a/servers/visual/rasterizer.h +++ b/servers/visual/rasterizer.h @@ -1294,7 +1294,7 @@ public: }; virtual void prepare_for_blitting_render_targets() = 0; - virtual void blit_render_targets_to_screen(int p_screen, const BlitToScreen *p_render_targets, int p_amount) = 0; + virtual void blit_render_targets_to_screen(DisplayServer::WindowID p_screen, const BlitToScreen *p_render_targets, int p_amount) = 0; virtual void end_frame(bool p_swap_buffers) = 0; virtual void finalize() = 0; diff --git a/servers/visual/rasterizer_rd/rasterizer_rd.cpp b/servers/visual/rasterizer_rd/rasterizer_rd.cpp index 206320376b..9c54f0caae 100644 --- a/servers/visual/rasterizer_rd/rasterizer_rd.cpp +++ b/servers/visual/rasterizer_rd/rasterizer_rd.cpp @@ -34,7 +34,7 @@ void RasterizerRD::prepare_for_blitting_render_targets() { RD::get_singleton()->prepare_screen_for_drawing(); } -void RasterizerRD::blit_render_targets_to_screen(int p_screen, const BlitToScreen *p_render_targets, int p_amount) { +void RasterizerRD::blit_render_targets_to_screen(DisplayServer::WindowID p_screen, const BlitToScreen *p_render_targets, int p_amount) { RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin_for_screen(p_screen); diff --git a/servers/visual/rasterizer_rd/rasterizer_rd.h b/servers/visual/rasterizer_rd/rasterizer_rd.h index d14e9fb36e..bbcf9bfefe 100644 --- a/servers/visual/rasterizer_rd/rasterizer_rd.h +++ b/servers/visual/rasterizer_rd/rasterizer_rd.h @@ -66,7 +66,7 @@ public: void initialize(); void begin_frame(double frame_step); void prepare_for_blitting_render_targets(); - void blit_render_targets_to_screen(int p_screen, const BlitToScreen *p_render_targets, int p_amount); + void blit_render_targets_to_screen(DisplayServer::WindowID p_screen, const BlitToScreen *p_render_targets, int p_amount); void end_frame(bool p_swap_buffers); void finalize(); diff --git a/servers/visual/rendering_device.h b/servers/visual/rendering_device.h index ed55afd961..4705bcaa75 100644 --- a/servers/visual/rendering_device.h +++ b/servers/visual/rendering_device.h @@ -32,6 +32,7 @@ #define RENDERING_DEVICE_H #include "core/object.h" +#include "servers/display_server.h" class RenderingDevice : public Object { GDCLASS(RenderingDevice, Object) @@ -896,8 +897,8 @@ public: /**** SCREEN ****/ /****************/ - virtual int screen_get_width(int p_screen = 0) const = 0; - virtual int screen_get_height(int p_screen = 0) const = 0; + virtual int screen_get_width(DisplayServer::WindowID p_screen = 0) const = 0; + virtual int screen_get_height(DisplayServer::WindowID p_screen = 0) const = 0; virtual FramebufferFormatID screen_get_framebuffer_format() const = 0; /********************/ @@ -920,7 +921,7 @@ public: typedef int64_t DrawListID; - virtual DrawListID draw_list_begin_for_screen(int p_screen = 0, const Color &p_clear_color = Color()) = 0; + virtual DrawListID draw_list_begin_for_screen(DisplayServer::WindowID p_screen = 0, const Color &p_clear_color = Color()) = 0; virtual DrawListID draw_list_begin(RID p_framebuffer, InitialAction p_initial_color_action, FinalAction p_final_color_action, InitialAction p_initial_depth_action, FinalAction p_final_depth_action, const Vector<Color> &p_clear_color_values = Vector<Color>(), float p_clear_depth = 1.0, uint32_t p_clear_stencil = 0, const Rect2 &p_region = Rect2()) = 0; virtual Error draw_list_begin_split(RID p_framebuffer, uint32_t p_splits, DrawListID *r_split_ids, InitialAction p_initial_color_action, FinalAction p_final_color_action, InitialAction p_initial_depth_action, FinalAction p_final_depth_action, const Vector<Color> &p_clear_color_values = Vector<Color>(), float p_clear_depth = 1.0, uint32_t p_clear_stencil = 0, const Rect2 &p_region = Rect2()) = 0; 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_raster.h b/servers/visual/visual_server_raster.h index b6afbbff93..1a40fc96a2 100644 --- a/servers/visual/visual_server_raster.h +++ b/servers/visual/visual_server_raster.h @@ -466,7 +466,6 @@ public: BIND3(viewport_attach_to_screen, RID, const Rect2 &, int) BIND2(viewport_set_render_direct_to_screen, RID, bool) - BIND1(viewport_detach, RID) BIND2(viewport_set_update_mode, RID, ViewportUpdateMode) BIND2(viewport_set_vflip, RID, bool) diff --git a/servers/visual/visual_server_viewport.cpp b/servers/visual/visual_server_viewport.cpp index 43262042cc..555d5f99c7 100644 --- a/servers/visual/visual_server_viewport.cpp +++ b/servers/visual/visual_server_viewport.cpp @@ -312,11 +312,14 @@ void VisualServerViewport::draw_viewports() { //sort viewports active_viewports.sort_custom<ViewportSort>(); - Map<int, Vector<Rasterizer::BlitToScreen>> blit_to_screen_list; + Map<DisplayServer::WindowID, Vector<Rasterizer::BlitToScreen>> blit_to_screen_list; //draw viewports RENDER_TIMESTAMP(">Render Viewports"); - for (int i = 0; i < active_viewports.size(); i++) { + //determine what is visible + draw_viewports_pass++; + + for (int i = active_viewports.size() - 1; i >= 0; i--) { //to compute parent dependency, must go in reverse draw order Viewport *vp = active_viewports[i]; @@ -328,11 +331,37 @@ void VisualServerViewport::draw_viewports() { } //ERR_CONTINUE(!vp->render_target.is_valid()); - bool visible = vp->viewport_to_screen_rect != Rect2() || vp->update_mode == VS::VIEWPORT_UPDATE_ALWAYS || vp->update_mode == VS::VIEWPORT_UPDATE_ONCE || (vp->update_mode == VS::VIEWPORT_UPDATE_WHEN_VISIBLE && VSG::storage->render_target_was_used(vp->render_target)); + bool visible = vp->viewport_to_screen_rect != Rect2(); + + if (vp->update_mode == VS::VIEWPORT_UPDATE_ALWAYS || vp->update_mode == VS::VIEWPORT_UPDATE_ONCE) { + visible = true; + } + + if (vp->update_mode == VS::VIEWPORT_UPDATE_WHEN_VISIBLE && VSG::storage->render_target_was_used(vp->render_target)) { + visible = true; + } + + if (vp->update_mode == VS::VIEWPORT_UPDATE_WHEN_PARENT_VISIBLE) { + Viewport *parent = viewport_owner.getornull(vp->parent); + if (parent && parent->last_pass == draw_viewports_pass) { + visible = true; + } + } + visible = visible && vp->size.x > 1 && vp->size.y > 1; - if (!visible) - continue; + if (visible) { + vp->last_pass = draw_viewports_pass; + } + } + + for (int i = 0; i < active_viewports.size(); i++) { + + Viewport *vp = active_viewports[i]; + + if (vp->last_pass != draw_viewports_pass) { + continue; //should not draw + } RENDER_TIMESTAMP(">Rendering Viewport " + itos(i)); @@ -389,11 +418,16 @@ void VisualServerViewport::draw_viewports() { vp->render_info[VS::VIEWPORT_RENDER_INFO_SURFACE_CHANGES_IN_FRAME] = VSG::storage->get_captured_render_info(VS::INFO_SURFACE_CHANGES_IN_FRAME); vp->render_info[VS::VIEWPORT_RENDER_INFO_DRAW_CALLS_IN_FRAME] = VSG::storage->get_captured_render_info(VS::INFO_DRAW_CALLS_IN_FRAME); - if (vp->viewport_to_screen_rect != Rect2() && (!vp->viewport_render_direct_to_screen || !VSG::rasterizer->is_low_end())) { + if (vp->viewport_to_screen != DisplayServer::INVALID_WINDOW_ID && (!vp->viewport_render_direct_to_screen || !VSG::rasterizer->is_low_end())) { //copy to screen if set as such Rasterizer::BlitToScreen blit; blit.render_target = vp->render_target; - blit.rect = vp->viewport_to_screen_rect; + if (vp->viewport_to_screen_rect != Rect2()) { + blit.rect = vp->viewport_to_screen_rect; + } else { + blit.rect.position = Vector2(); + blit.rect.size = vp->size; + } if (!blit_to_screen_list.has(vp->viewport_to_screen)) { blit_to_screen_list[vp->viewport_to_screen] = Vector<Rasterizer::BlitToScreen>(); @@ -450,13 +484,15 @@ void VisualServerViewport::viewport_set_size(RID p_viewport, int p_width, int p_ Viewport *viewport = viewport_owner.getornull(p_viewport); ERR_FAIL_COND(!viewport); - // if (viewport->size.width == p_width && viewport->size.height == p_height) { - // return; //nothing to do - // } viewport->size = Size2(p_width, p_height); VSG::storage->render_target_set_size(viewport->render_target, p_width, p_height); if (viewport->render_buffers.is_valid()) { - VSG::scene_render->render_buffers_configure(viewport->render_buffers, viewport->render_target, viewport->size.width, viewport->size.height, viewport->msaa); + if (p_width == 0 || p_height == 0) { + VSG::scene_render->free(viewport->render_buffers); + viewport->render_buffers = RID(); + } else { + VSG::scene_render->render_buffers_configure(viewport->render_buffers, viewport->render_target, viewport->size.width, viewport->size.height, viewport->msaa); + } } } @@ -489,21 +525,34 @@ void VisualServerViewport::viewport_set_clear_mode(RID p_viewport, VS::ViewportC viewport->clear_mode = p_clear_mode; } -void VisualServerViewport::viewport_attach_to_screen(RID p_viewport, const Rect2 &p_rect, int p_screen) { +void VisualServerViewport::viewport_attach_to_screen(RID p_viewport, const Rect2 &p_rect, DisplayServer::WindowID p_screen) { Viewport *viewport = viewport_owner.getornull(p_viewport); ERR_FAIL_COND(!viewport); - // If using GLES2 we can optimize this operation by rendering directly to system_fbo - // instead of rendering to fbo and copying to system_fbo after - if (VSG::rasterizer->is_low_end() && viewport->viewport_render_direct_to_screen) { + if (p_screen != DisplayServer::INVALID_WINDOW_ID) { + // If using GLES2 we can optimize this operation by rendering directly to system_fbo + // instead of rendering to fbo and copying to system_fbo after + if (VSG::rasterizer->is_low_end() && viewport->viewport_render_direct_to_screen) { - VSG::storage->render_target_set_size(viewport->render_target, p_rect.size.x, p_rect.size.y); - VSG::storage->render_target_set_position(viewport->render_target, p_rect.position.x, p_rect.position.y); - } + VSG::storage->render_target_set_size(viewport->render_target, p_rect.size.x, p_rect.size.y); + VSG::storage->render_target_set_position(viewport->render_target, p_rect.position.x, p_rect.position.y); + } + + viewport->viewport_to_screen_rect = p_rect; + viewport->viewport_to_screen = p_screen; + } else { - viewport->viewport_to_screen_rect = p_rect; - viewport->viewport_to_screen = p_screen; + // if render_direct_to_screen was used, reset size and position + if (VSG::rasterizer->is_low_end() && viewport->viewport_render_direct_to_screen) { + + VSG::storage->render_target_set_position(viewport->render_target, 0, 0); + VSG::storage->render_target_set_size(viewport->render_target, viewport->size.x, viewport->size.y); + } + + viewport->viewport_to_screen_rect = Rect2(); + viewport->viewport_to_screen = DisplayServer::INVALID_WINDOW_ID; + } } void VisualServerViewport::viewport_set_render_direct_to_screen(RID p_viewport, bool p_enable) { @@ -531,22 +580,6 @@ void VisualServerViewport::viewport_set_render_direct_to_screen(RID p_viewport, } } -void VisualServerViewport::viewport_detach(RID p_viewport) { - - Viewport *viewport = viewport_owner.getornull(p_viewport); - ERR_FAIL_COND(!viewport); - - // if render_direct_to_screen was used, reset size and position - if (VSG::rasterizer->is_low_end() && viewport->viewport_render_direct_to_screen) { - - VSG::storage->render_target_set_position(viewport->render_target, 0, 0); - VSG::storage->render_target_set_size(viewport->render_target, viewport->size.x, viewport->size.y); - } - - viewport->viewport_to_screen_rect = Rect2(); - viewport->viewport_to_screen = 0; -} - void VisualServerViewport::viewport_set_update_mode(RID p_viewport, VS::ViewportUpdateMode p_mode) { Viewport *viewport = viewport_owner.getornull(p_viewport); diff --git a/servers/visual/visual_server_viewport.h b/servers/visual/visual_server_viewport.h index 30b53f3935..06372376f8 100644 --- a/servers/visual/visual_server_viewport.h +++ b/servers/visual/visual_server_viewport.h @@ -60,7 +60,7 @@ public: VS::ViewportMSAA msaa; - int viewport_to_screen; + DisplayServer::WindowID viewport_to_screen; Rect2 viewport_to_screen_rect; bool viewport_render_direct_to_screen; @@ -73,6 +73,8 @@ public: RID shadow_atlas; int shadow_atlas_size; + uint64_t last_pass = 0; + int render_info[VS::VIEWPORT_RENDER_INFO_MAX]; VS::ViewportDebugDraw debug_draw; @@ -117,7 +119,7 @@ public: clear_mode = VS::VIEWPORT_CLEAR_ALWAYS; transparent_bg = false; disable_environment = false; - viewport_to_screen = 0; + viewport_to_screen = DisplayServer::INVALID_WINDOW_ID; shadow_atlas_size = 0; keep_3d_linear = false; debug_draw = VS::VIEWPORT_DEBUG_DRAW_DISABLED; @@ -129,6 +131,8 @@ public: } }; + uint64_t draw_viewports_pass = 0; + mutable RID_PtrOwner<Viewport> viewport_owner; struct ViewportSort { @@ -139,9 +143,9 @@ public: if (left_to_screen == right_to_screen) { - return p_left->parent == p_right->self; + return p_right->parent == p_left->self; } - return right_to_screen; + return (right_to_screen ? 0 : 1) < (left_to_screen ? 0 : 1); } }; @@ -158,9 +162,8 @@ public: void viewport_set_size(RID p_viewport, int p_width, int p_height); - void viewport_attach_to_screen(RID p_viewport, const Rect2 &p_rect = Rect2(), int p_screen = 0); + void viewport_attach_to_screen(RID p_viewport, const Rect2 &p_rect = Rect2(), DisplayServer::WindowID p_screen = DisplayServer::MAIN_WINDOW_ID); void viewport_set_render_direct_to_screen(RID p_viewport, bool p_enable); - void viewport_detach(RID p_viewport); void viewport_set_active(RID p_viewport, bool p_active); void viewport_set_parent_viewport(RID p_viewport, RID p_parent_viewport); 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; diff --git a/servers/visual/visual_server_wrap_mt.h b/servers/visual/visual_server_wrap_mt.h index 0d4683e43d..e043ac5214 100644 --- a/servers/visual/visual_server_wrap_mt.h +++ b/servers/visual/visual_server_wrap_mt.h @@ -379,9 +379,8 @@ public: FUNC2(viewport_set_clear_mode, RID, ViewportClearMode) - FUNC3(viewport_attach_to_screen, RID, const Rect2 &, int) + FUNC3(viewport_attach_to_screen, RID, const Rect2 &, DisplayServer::WindowID) FUNC2(viewport_set_render_direct_to_screen, RID, bool) - FUNC1(viewport_detach, RID) FUNC2(viewport_set_update_mode, RID, ViewportUpdateMode) diff --git a/servers/visual_server.cpp b/servers/visual_server.cpp index b50ad89b1e..1e4ee5cb50 100644 --- a/servers/visual_server.cpp +++ b/servers/visual_server.cpp @@ -1769,9 +1769,9 @@ void VisualServer::_bind_methods() { ClassDB::bind_method(D_METHOD("viewport_set_size", "viewport", "width", "height"), &VisualServer::viewport_set_size); ClassDB::bind_method(D_METHOD("viewport_set_active", "viewport", "active"), &VisualServer::viewport_set_active); ClassDB::bind_method(D_METHOD("viewport_set_parent_viewport", "viewport", "parent_viewport"), &VisualServer::viewport_set_parent_viewport); - ClassDB::bind_method(D_METHOD("viewport_attach_to_screen", "viewport", "rect", "screen"), &VisualServer::viewport_attach_to_screen, DEFVAL(Rect2()), DEFVAL(0)); + ClassDB::bind_method(D_METHOD("viewport_attach_to_screen", "viewport", "rect", "screen"), &VisualServer::viewport_attach_to_screen, DEFVAL(Rect2()), DEFVAL(DisplayServer::MAIN_WINDOW_ID)); ClassDB::bind_method(D_METHOD("viewport_set_render_direct_to_screen", "viewport", "enabled"), &VisualServer::viewport_set_render_direct_to_screen); - ClassDB::bind_method(D_METHOD("viewport_detach", "viewport"), &VisualServer::viewport_detach); + ClassDB::bind_method(D_METHOD("viewport_set_update_mode", "viewport", "update_mode"), &VisualServer::viewport_set_update_mode); ClassDB::bind_method(D_METHOD("viewport_set_clear_mode", "viewport", "clear_mode"), &VisualServer::viewport_set_clear_mode); ClassDB::bind_method(D_METHOD("viewport_get_texture", "viewport"), &VisualServer::viewport_get_texture); @@ -2060,6 +2060,7 @@ void VisualServer::_bind_methods() { BIND_ENUM_CONSTANT(VIEWPORT_UPDATE_DISABLED); BIND_ENUM_CONSTANT(VIEWPORT_UPDATE_ONCE); BIND_ENUM_CONSTANT(VIEWPORT_UPDATE_WHEN_VISIBLE); + BIND_ENUM_CONSTANT(VIEWPORT_UPDATE_WHEN_PARENT_VISIBLE); BIND_ENUM_CONSTANT(VIEWPORT_UPDATE_ALWAYS); BIND_ENUM_CONSTANT(VIEWPORT_CLEAR_ALWAYS); diff --git a/servers/visual_server.h b/servers/visual_server.h index dfe5e7feed..506800cc7d 100644 --- a/servers/visual_server.h +++ b/servers/visual_server.h @@ -37,6 +37,7 @@ #include "core/object.h" #include "core/rid.h" #include "core/variant.h" +#include "servers/display_server.h" class VisualServer : public Object { @@ -584,14 +585,14 @@ public: virtual void viewport_set_active(RID p_viewport, bool p_active) = 0; virtual void viewport_set_parent_viewport(RID p_viewport, RID p_parent_viewport) = 0; - virtual void viewport_attach_to_screen(RID p_viewport, const Rect2 &p_rect = Rect2(), int p_screen = 0) = 0; + virtual void viewport_attach_to_screen(RID p_viewport, const Rect2 &p_rect = Rect2(), DisplayServer::WindowID p_screen = DisplayServer::MAIN_WINDOW_ID) = 0; virtual void viewport_set_render_direct_to_screen(RID p_viewport, bool p_enable) = 0; - virtual void viewport_detach(RID p_viewport) = 0; enum ViewportUpdateMode { VIEWPORT_UPDATE_DISABLED, VIEWPORT_UPDATE_ONCE, //then goes to disabled, must be manually updated VIEWPORT_UPDATE_WHEN_VISIBLE, // default + VIEWPORT_UPDATE_WHEN_PARENT_VISIBLE, VIEWPORT_UPDATE_ALWAYS }; |