summaryrefslogtreecommitdiff
path: root/servers
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2020-03-14 13:06:39 -0300
committerJuan Linietsky <reduzio@gmail.com>2020-03-26 15:49:43 +0100
commitc7b4dcae2f3b75ad7146e36f196893731f403144 (patch)
treed6223521b246aa36d0e0b78d6ed626fa2a0e3769 /servers
parent441f1a5fe9a3bf0e4e5dab578f793500b1ff6e3d (diff)
Open sub-windows as embedded if the OS does not support them
Diffstat (limited to 'servers')
-rw-r--r--servers/display_server.cpp2
-rw-r--r--servers/display_server.h2
-rw-r--r--servers/visual/visual_server_viewport.cpp37
-rw-r--r--servers/visual/visual_server_viewport.h8
-rw-r--r--servers/visual_server.cpp1
-rw-r--r--servers/visual_server.h1
6 files changed, 43 insertions, 8 deletions
diff --git a/servers/display_server.cpp b/servers/display_server.cpp
index 5b030be5a6..efa3c8af7b 100644
--- a/servers/display_server.cpp
+++ b/servers/display_server.cpp
@@ -276,7 +276,7 @@ void DisplayServer::_bind_methods() {
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_resize_callback", "callback", "window_id"), &DisplayServer::window_set_resize_callback, 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));
diff --git a/servers/display_server.h b/servers/display_server.h
index 69e110d2b1..dfa98e350f 100644
--- a/servers/display_server.h
+++ b/servers/display_server.h
@@ -182,7 +182,7 @@ public:
virtual WindowID create_sub_window(WindowMode p_mode, uint32_t p_flags, const Rect2i & = Rect2i());
virtual void delete_sub_window(WindowID p_id);
- virtual void window_set_resize_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) = 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,
diff --git a/servers/visual/visual_server_viewport.cpp b/servers/visual/visual_server_viewport.cpp
index aca96d6552..555d5f99c7 100644
--- a/servers/visual/visual_server_viewport.cpp
+++ b/servers/visual/visual_server_viewport.cpp
@@ -316,7 +316,10 @@ void VisualServerViewport::draw_viewports() {
//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));
diff --git a/servers/visual/visual_server_viewport.h b/servers/visual/visual_server_viewport.h
index 38983d5e8a..06372376f8 100644
--- a/servers/visual/visual_server_viewport.h
+++ b/servers/visual/visual_server_viewport.h
@@ -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;
@@ -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);
}
};
diff --git a/servers/visual_server.cpp b/servers/visual_server.cpp
index 62c3704f5b..1e4ee5cb50 100644
--- a/servers/visual_server.cpp
+++ b/servers/visual_server.cpp
@@ -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 d41c80dfa1..506800cc7d 100644
--- a/servers/visual_server.h
+++ b/servers/visual_server.h
@@ -592,6 +592,7 @@ public:
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
};