[Bf-blender-cvs] [8a87e48b18f] vr_scene_inspection: Refactor runtime data storage, for OpenXR side session ending

Julian Eisel noreply at git.blender.org
Mon Mar 16 11:22:36 CET 2020


Commit: 8a87e48b18ffb4531ae779696ef50dbfa466390b
Author: Julian Eisel
Date:   Sun Mar 15 02:02:42 2020 +0100
Branches: vr_scene_inspection
https://developer.blender.org/rB8a87e48b18ffb4531ae779696ef50dbfa466390b

Refactor runtime data storage, for OpenXR side session ending

Right now, ending the session via the OpenXR runtime (e.g. closing the
WinMR Portal while the Blender VR session runs) causes multiple issues.
We need a way to properly react to session end events. Changes here
prepare us for that.

===================================================================

M	source/blender/blenloader/intern/readfile.c
M	source/blender/makesdna/DNA_windowmanager_types.h
M	source/blender/makesrna/RNA_access.h
M	source/blender/makesrna/intern/rna_wm.c
M	source/blender/makesrna/intern/rna_xr.c
M	source/blender/windowmanager/intern/wm_operators.c
M	source/blender/windowmanager/intern/wm_window.c
M	source/blender/windowmanager/intern/wm_xr.c
M	source/blender/windowmanager/wm.h

===================================================================

diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index f1ac4db421b..9b8278943af 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -7662,8 +7662,7 @@ static void direct_link_windowmanager(FileData *fd, wmWindowManager *wm)
 
   wm->message_bus = NULL;
 
-  wm->xr.context = NULL;
-  wm->xr.session_state = NULL;
+  wm->xr.runtime = NULL;
 
   BLI_listbase_clear(&wm->jobs);
   BLI_listbase_clear(&wm->drags);
diff --git a/source/blender/makesdna/DNA_windowmanager_types.h b/source/blender/makesdna/DNA_windowmanager_types.h
index 3badbe379e4..321e3925155 100644
--- a/source/blender/makesdna/DNA_windowmanager_types.h
+++ b/source/blender/makesdna/DNA_windowmanager_types.h
@@ -43,7 +43,6 @@ struct wmKeyMap;
 struct wmMsgBus;
 struct wmOperator;
 struct wmOperatorType;
-struct GHOST_XrContext;
 
 /* forwards */
 struct PointerRNA;
@@ -123,14 +122,11 @@ typedef struct ReportTimerInfo {
 
 //#ifdef WITH_XR_OPENXR
 typedef struct wmXrData {
-  void *context; /* GHOST_XrContextHandle */
-
+  /** Runtime information for managing Blender specific behaviors. */
+  struct wmXrRuntimeData *runtime;
   /** Permanent session settings (draw mode, feature toggles, etc). Stored in files and accessible
    * even before the session runs. */
   XrSessionSettings session_settings;
-
-  /** Runtime state information for managing Blender specific behaviors. Not stored in files. */
-  struct XrRuntimeSessionState *session_state;
 } wmXrData;
 //#endif
 
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h
index b6e77b1005c..1e07da23429 100644
--- a/source/blender/makesrna/RNA_access.h
+++ b/source/blender/makesrna/RNA_access.h
@@ -695,7 +695,7 @@ extern StructRNA RNA_World;
 extern StructRNA RNA_WorldLighting;
 extern StructRNA RNA_WorldMistSettings;
 extern StructRNA RNA_XrSessionSettings;
-extern StructRNA RNA_XrRuntimeSessionState;
+extern StructRNA RNA_XrSessionState;
 extern StructRNA RNA_uiPopover;
 extern StructRNA RNA_wmOwnerIDs;
 
diff --git a/source/blender/makesrna/intern/rna_wm.c b/source/blender/makesrna/intern/rna_wm.c
index 6929238d67a..bbec2bb7c7e 100644
--- a/source/blender/makesrna/intern/rna_wm.c
+++ b/source/blender/makesrna/intern/rna_wm.c
@@ -1266,6 +1266,12 @@ static void rna_wmClipboard_set(PointerRNA *UNUSED(ptr), const char *value)
   WM_clipboard_text_set((void *)value, false);
 }
 
+static PointerRNA rna_WindowManager_xr_session_state_get(PointerRNA *ptr)
+{
+  wmWindowManager *wm = ptr->data;
+  return rna_pointer_inherit_refine(ptr, &RNA_XrSessionState, &wm->xr);
+}
+
 #  ifdef WITH_PYTHON
 
 static bool rna_operator_poll_cb(bContext *C, wmOperatorType *ot)
@@ -2490,8 +2496,8 @@ static void rna_def_windowmanager(BlenderRNA *brna)
   RNA_def_property_ui_text(prop, "XR Session Settings", "");
 
   prop = RNA_def_property(srna, "xr_session_state", PROP_POINTER, PROP_NONE);
-  RNA_def_property_struct_type(prop, "XrRuntimeSessionState");
-  RNA_def_property_pointer_sdna(prop, NULL, "xr.session_state");
+  RNA_def_property_struct_type(prop, "XrSessionState");
+  RNA_def_property_pointer_funcs(prop, "rna_WindowManager_xr_session_state_get", NULL, NULL, NULL);
   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
   RNA_def_property_ui_text(
       prop, "XR Session State", "Runtime state information about the VR session");
diff --git a/source/blender/makesrna/intern/rna_xr.c b/source/blender/makesrna/intern/rna_xr.c
index 27ef32524c6..577f2d36a1d 100644
--- a/source/blender/makesrna/intern/rna_xr.c
+++ b/source/blender/makesrna/intern/rna_xr.c
@@ -34,7 +34,7 @@
 
 #  include "WM_api.h"
 
-static bool rna_XrRuntimeSessionState_is_running(bContext *C)
+static bool rna_XrSessionState_is_running(bContext *C)
 {
 #  ifdef WITH_XR_OPENXR
   const wmWindowManager *wm = CTX_wm_manager(C);
@@ -46,12 +46,12 @@ static bool rna_XrRuntimeSessionState_is_running(bContext *C)
 }
 
 #  ifdef WITH_XR_OPENXR
-static wmXrData *rna_XrRuntimeSessionState_wm_xr_data_get(PointerRNA *ptr)
+static wmXrData *rna_XrSessionState_wm_xr_data_get(PointerRNA *ptr)
 {
-  /* Callers could also get XrRuntimeSessionState pointer through ptr->data, but prefer if we just
+  /* Callers could also get XrSessionState pointer through ptr->data, but prefer if we just
    * consistently pass wmXrData pointers to the WM_xr_xxx() API. */
 
-  BLI_assert(ptr->type == &RNA_XrRuntimeSessionState);
+  BLI_assert(ptr->type == &RNA_XrSessionState);
 
   wmWindowManager *wm = (wmWindowManager *)ptr->owner_id;
   BLI_assert(wm && (GS(wm->id.name) == ID_WM));
@@ -60,10 +60,10 @@ static wmXrData *rna_XrRuntimeSessionState_wm_xr_data_get(PointerRNA *ptr)
 }
 #  endif
 
-static void rna_XrRuntimeSessionState_viewer_location_get(PointerRNA *ptr, float *r_values)
+static void rna_XrSessionState_viewer_location_get(PointerRNA *ptr, float *r_values)
 {
 #  ifdef WITH_XR_OPENXR
-  const wmXrData *xr = rna_XrRuntimeSessionState_wm_xr_data_get(ptr);
+  const wmXrData *xr = rna_XrSessionState_wm_xr_data_get(ptr);
   WM_xr_session_state_viewer_location_get(xr, r_values);
 #  else
   UNUSED_VARS(ptr);
@@ -71,10 +71,10 @@ static void rna_XrRuntimeSessionState_viewer_location_get(PointerRNA *ptr, float
 #  endif
 }
 
-static void rna_XrRuntimeSessionState_viewer_rotation_get(PointerRNA *ptr, float *r_values)
+static void rna_XrSessionState_viewer_rotation_get(PointerRNA *ptr, float *r_values)
 {
 #  ifdef WITH_XR_OPENXR
-  const wmXrData *xr = rna_XrRuntimeSessionState_wm_xr_data_get(ptr);
+  const wmXrData *xr = rna_XrSessionState_wm_xr_data_get(ptr);
   WM_xr_session_state_viewer_rotation_get(xr, r_values);
 #  else
   UNUSED_VARS(ptr);
@@ -184,11 +184,11 @@ static void rna_def_xr_session_state(BlenderRNA *brna)
   FunctionRNA *func;
   PropertyRNA *parm, *prop;
 
-  srna = RNA_def_struct(brna, "XrRuntimeSessionState", NULL);
+  srna = RNA_def_struct(brna, "XrSessionState", NULL);
   RNA_def_struct_clear_flag(srna, STRUCT_UNDO);
   RNA_def_struct_ui_text(srna, "Session State", "Runtime state information about the VR session");
 
-  func = RNA_def_function(srna, "is_running", "rna_XrRuntimeSessionState_is_running");
+  func = RNA_def_function(srna, "is_running", "rna_XrSessionState_is_running");
   RNA_def_function_ui_description(func, "Query if the VR session is currently running");
   RNA_def_function_flag(func, FUNC_NO_SELF);
   parm = RNA_def_pointer(func, "context", "Context", "", "");
@@ -198,7 +198,7 @@ static void rna_def_xr_session_state(BlenderRNA *brna)
 
   prop = RNA_def_property(srna, "viewer_location", PROP_FLOAT, PROP_TRANSLATION);
   RNA_def_property_array(prop, 3);
-  RNA_def_property_float_funcs(prop, "rna_XrRuntimeSessionState_viewer_location_get", NULL, NULL);
+  RNA_def_property_float_funcs(prop, "rna_XrSessionState_viewer_location_get", NULL, NULL);
   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
   RNA_def_property_ui_text(
       prop,
@@ -207,7 +207,7 @@ static void rna_def_xr_session_state(BlenderRNA *brna)
 
   prop = RNA_def_property(srna, "viewer_rotation", PROP_FLOAT, PROP_QUATERNION);
   RNA_def_property_array(prop, 4);
-  RNA_def_property_float_funcs(prop, "rna_XrRuntimeSessionState_viewer_rotation_get", NULL, NULL);
+  RNA_def_property_float_funcs(prop, "rna_XrSessionState_viewer_rotation_get", NULL, NULL);
   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
   RNA_def_property_ui_text(
       prop,
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index 1fae8bb42b0..2e6e1856461 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -3675,7 +3675,7 @@ static int wm_xr_session_toggle_exec(bContext *C, wmOperator *UNUSED(op))
     return OPERATOR_CANCELLED;
   }
 
-  wm_xr_session_toggle(&wm->xr);
+  wm_xr_session_toggle(wm);
 
   wm_xr_session_update_mirror_views(CTX_data_main(C), wm);
 
diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c
index a6893300900..eaa0fa7b7a5 100644
--- a/source/blender/windowmanager/intern/wm_window.c
+++ b/source/blender/windowmanager/intern/wm_window.c
@@ -1632,7 +1632,9 @@ void wm_window_process_events(const bContext *C)
   }
   hasevent |= wm_window_timer(C);
 #ifdef WITH_XR_OPENXR
-  hasevent |= GHOST_XrEventsHandle(CTX_wm_manager(C)->xr.context);
+  /* XR events don't use the regular window queues. So here we don't only trigger
+   * processing/dispatching but also handling. */
+  hasevent |= wm_xr_events_handle(CTX_wm_manager(C));
 #endif
 
   /* no event, we sleep 5 milliseconds */
diff --git a/source/blender/windowmanager/intern/wm_xr.c b/source/blender/windowmanager/intern/wm_xr.c
index bcf56b6448f..3231d7f5847 100644
--- a/source/blender/windowmanager/intern/wm_xr.c
+++ b/source/blender/windowmanager/intern/wm_xr.c
@@ -65,7 +65,8 @@
 #include "wm_surface.h"
 #include "wm_window.h"
 
-void wm_xr_runtime_session_state_free(struct XrRuntimeSessionState **state);
+struct wmXrRuntimeData *wm_xr_runtime_data_create(void);
+void wm_xr_runtime_data_free(struct wmXrRuntimeData **runtime);
 void wm_xr_draw_view(const GHOST_XrDrawViewInfo *, void *);
 void *wm_xr_session_gpu_binding_context_create(GHOST_TXrGraphicsBinding);
 void wm_xr_session_gpu_binding_context_destroy(GHOST_TXrGraphicsBinding, void *);
@@ -74,7 +75,9 @@ void wm_xr_pose_to_viewmat(const GHOST_XrPose *pose, float r_viewmat[4][4]);
 
 /* -------------------------------------------------------------------- */
 
-typedef struct XrRuntimeSessionState {
+typedef struct wmXrSessionState {
+  bool is_started;
+
   /** Last known viewer pose (centroid of eyes, in world space) stored for queries. */
   GHOST_XrPose viewer_pose;
   /** The last known view matrix, calculated from above's viewer pose. */
@@ -87,7 +90,14 @@ typedef struct XrRuntimeSessionState {
   float prev_eye_position_ofs[3];
 
   bool is_initialized;
-} XrRuntimeSessionState;
+} wmXrSessionState;
+
+typedef struct wmXrRuntimeData {
+  GHOST_XrContextHandle context;
+
+  /* Although this struct is internal, RNA gets a handle to this for state information queries. */
+  wmXrSessionState sess

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list