[Bf-blender-cvs] [798c33ab3bc] xr-actions-D9124: XR: Start refactoring internal API

Peter Kim noreply at git.blender.org
Sun Jan 31 14:32:01 CET 2021


Commit: 798c33ab3bc29e9d1bb290fa993300ce6fffbca4
Author: Peter Kim
Date:   Sat Jan 30 12:17:50 2021 +0900
Branches: xr-actions-D9124
https://developer.blender.org/rB798c33ab3bc29e9d1bb290fa993300ce6fffbca4

XR: Start refactoring internal API

Remove unnecessary data from GHOST types and mostly eliminate use of
GHOST types at RNA level. At the WM level, action creation functions
deal with single actions (instead of multiple actions at once) to
simplify the API.

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

M	intern/ghost/GHOST_C-api.h
M	intern/ghost/GHOST_Types.h
M	intern/ghost/intern/GHOST_C-api.cpp
M	intern/ghost/intern/GHOST_XrSession.cpp
M	intern/ghost/intern/GHOST_XrSession.h
M	source/blender/makesrna/intern/rna_wm.c
M	source/blender/makesrna/intern/rna_xr.c
M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/WM_types.h
M	source/blender/windowmanager/intern/wm_event_system.c
M	source/blender/windowmanager/xr/intern/wm_xr_actions.c
M	source/blender/windowmanager/xr/intern/wm_xr_draw.c
M	source/blender/windowmanager/xr/intern/wm_xr_intern.h
M	source/blender/windowmanager/xr/intern/wm_xr_operators.c
M	source/blender/windowmanager/xr/intern/wm_xr_session.c

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

diff --git a/intern/ghost/GHOST_C-api.h b/intern/ghost/GHOST_C-api.h
index e2efc971f49..2d15f67b327 100644
--- a/intern/ghost/GHOST_C-api.h
+++ b/intern/ghost/GHOST_C-api.h
@@ -1069,7 +1069,7 @@ GHOST_TSuccess GHOST_XrEventsHandle(GHOST_XrContextHandle xr_context);
 /**
  * Create an OpenXR action set for input/output.
  */
-int GHOST_XrCreateActionSet(GHOST_XrContextHandle xr_context, const GHOST_XrActionSetInfo *info);
+int GHOST_XrCreateActionSet(GHOST_XrContextHandle xr_context, const char *action_set_name);
 
 /**
  * Destroy a previously created OpenXR action set.
@@ -1139,15 +1139,11 @@ int GHOST_XrSyncActions(GHOST_XrContextHandle xr_context, const char *action_set
 
 /**
  * Get the states of OpenXR actions.
- *
- * \param r_infos: An array of action info pointers (NOT an array of action infos) that will
- * receive state data. The reason r_infos is an array of pointers is to allow writing to
- * previously created actions which may not be stored in contiguous memory.
  */
 int GHOST_XrGetActionStates(GHOST_XrContextHandle xr_context,
                             const char *action_set_name,
                             GHOST_TUns32 count,
-                            GHOST_XrActionInfo *const *r_infos);
+                            GHOST_XrActionInfo *r_infos);
 
 /**
  * Apply an OpenXR haptic output action.
diff --git a/intern/ghost/GHOST_Types.h b/intern/ghost/GHOST_Types.h
index c3b5c80ea4b..ce61fcf6388 100644
--- a/intern/ghost/GHOST_Types.h
+++ b/intern/ghost/GHOST_Types.h
@@ -694,12 +694,6 @@ typedef struct GHOST_XrError {
   void *customdata;
 } GHOST_XrError;
 
-typedef struct GHOST_XrActionSetInfo {
-  const char *name;
-  /** Larger values take precedence over smaller values. */
-  GHOST_TUns32 priority;
-} GHOST_XrActionSetInfo;
-
 /** XR action type. Enum values match those in OpenXR's
  * XrActionType enum for consistency. */
 typedef enum GHOST_XrActionType {
@@ -717,19 +711,6 @@ typedef struct GHOST_XrActionInfo {
   const char **subaction_paths;
   /** States for each subaction path. */
   void *states;
-  /** Previous states, stored to determine XR events. */
-  void *states_prev;
-
-  /** Input threshold for float actions (only used by wm). */
-  float threshold;
-
-  /** The currently active subaction path (if any) for modal actions (only used by wm). */
-  char **active_modal_path;
-
-  /** Operator to be called on XR events (only used by wm). */
-  void *ot;
-  void *op_properties;
-  char op_flag;
 } GHOST_XrActionInfo;
 
 typedef struct GHOST_XrActionSpaceInfo {
@@ -737,7 +718,7 @@ typedef struct GHOST_XrActionSpaceInfo {
   GHOST_TUns32 count_subaction_paths;
   const char **subaction_paths;
   /** Poses for each subaction path. */
-  GHOST_XrPose *poses;
+  const GHOST_XrPose *poses;
 } GHOST_XrActionSpaceInfo;
 
 typedef struct GHOST_XrActionBinding {
diff --git a/intern/ghost/intern/GHOST_C-api.cpp b/intern/ghost/intern/GHOST_C-api.cpp
index c383505a148..ff6bb222a92 100644
--- a/intern/ghost/intern/GHOST_C-api.cpp
+++ b/intern/ghost/intern/GHOST_C-api.cpp
@@ -969,12 +969,11 @@ int GHOST_XrSessionNeedsUpsideDownDrawing(const GHOST_XrContextHandle xr_context
   return 0; /* Only reached if exception is thrown. */
 }
 
-int GHOST_XrCreateActionSet(GHOST_XrContextHandle xr_contexthandle,
-                            const GHOST_XrActionSetInfo *info)
+int GHOST_XrCreateActionSet(GHOST_XrContextHandle xr_contexthandle, const char *action_set_name)
 {
   GHOST_IXrContext *xr_context = (GHOST_IXrContext *)xr_contexthandle;
   GHOST_XrSession *xr_session = xr_context->getSession();
-  GHOST_XR_CAPI_CALL_RET(xr_session->createActionSet(info), xr_context);
+  GHOST_XR_CAPI_CALL_RET(xr_session->createActionSet(action_set_name), xr_context);
   return 0;
 }
 
@@ -1069,7 +1068,7 @@ int GHOST_XrSyncActions(GHOST_XrContextHandle xr_contexthandle, const char *acti
 int GHOST_XrGetActionStates(GHOST_XrContextHandle xr_contexthandle,
                             const char *action_set_name,
                             GHOST_TUns32 count,
-                            GHOST_XrActionInfo *const *r_infos)
+                            GHOST_XrActionInfo *r_infos)
 {
   GHOST_IXrContext *xr_context = (GHOST_IXrContext *)xr_contexthandle;
   GHOST_XrSession *xr_session = xr_context->getSession();
diff --git a/intern/ghost/intern/GHOST_XrSession.cpp b/intern/ghost/intern/GHOST_XrSession.cpp
index dfea506a57a..4eb86470bfa 100644
--- a/intern/ghost/intern/GHOST_XrSession.cpp
+++ b/intern/ghost/intern/GHOST_XrSession.cpp
@@ -297,10 +297,9 @@ GHOST_XrSession::LifeExpectancy GHOST_XrSession::handleStateChangeEvent(
   assert(m_oxr->session == XR_NULL_HANDLE || m_oxr->session == lifecycle.session);
 
   switch (lifecycle.state) {
-    case XR_SESSION_STATE_READY: {
+    case XR_SESSION_STATE_READY:
       beginSession();
       break;
-    }
     case XR_SESSION_STATE_STOPPING:
       endSession();
       break;
@@ -635,28 +634,28 @@ static OpenXRActionProfile *find_action_profile(OpenXRAction *action,
   return &profile->second;
 }
 
-bool GHOST_XrSession::createActionSet(const GHOST_XrActionSetInfo *info)
+bool GHOST_XrSession::createActionSet(const char *action_set_name)
 {
   XrActionSetCreateInfo action_set_info{XR_TYPE_ACTION_SET_CREATE_INFO};
-  strcpy(action_set_info.actionSetName, info->name);
+  strcpy(action_set_info.actionSetName, action_set_name);
   strcpy(action_set_info.localizedActionSetName,
-         info->name); /* Just use same name for localized. This can be changed in the future if
-                         necessary. */
-  action_set_info.priority = info->priority;
+         action_set_name); /* Just use same name for localized. This can be changed in the future
+                              if necessary. */
+  action_set_info.priority = 0; /* Use same (default) priority for all action sets. */
 
   OpenXRActionSet action_set;
   CHECK_XR(xrCreateActionSet(m_context->getInstance(), &action_set_info, &action_set.set),
-           (m_error_msg = std::string("Failed to create action set \"") + info->name +
+           (m_error_msg = std::string("Failed to create action set \"") + action_set_name +
                           "\". Name must not contain upper case letters or special characters "
                           "other than '-', '_', or '.'.")
                .c_str());
 
   std::map<std::string, OpenXRActionSet> &action_sets = m_oxr->action_sets;
-  if (action_sets.find(info->name) == action_sets.end()) {
-    action_sets.insert({info->name, std::move(action_set)});
+  if (action_sets.find(action_set_name) == action_sets.end()) {
+    action_sets.insert({action_set_name, std::move(action_set)});
   }
   else {
-    action_sets[info->name] = std::move(action_set);
+    action_sets[action_set_name] = std::move(action_set);
   }
 
   return true;
@@ -717,29 +716,21 @@ bool GHOST_XrSession::createActions(const char *action_set_name,
                           necessary. */
 
     switch (info.type) {
-      case GHOST_kXrActionTypeBooleanInput: {
+      case GHOST_kXrActionTypeBooleanInput:
         action_info.actionType = XR_ACTION_TYPE_BOOLEAN_INPUT;
         break;
-      }
-      case GHOST_kXrActionTypeFloatInput: {
+      case GHOST_kXrActionTypeFloatInput:
         action_info.actionType = XR_ACTION_TYPE_FLOAT_INPUT;
         break;
-      }
-      case GHOST_kXrActionTypeVector2fInput: {
+      case GHOST_kXrActionTypeVector2fInput:
         action_info.actionType = XR_ACTION_TYPE_VECTOR2F_INPUT;
         break;
-      }
-      case GHOST_kXrActionTypePoseInput: {
+      case GHOST_kXrActionTypePoseInput:
         action_info.actionType = XR_ACTION_TYPE_POSE_INPUT;
         break;
-      }
-      case GHOST_kXrActionTypeVibrationOutput: {
+      case GHOST_kXrActionTypeVibrationOutput:
         action_info.actionType = XR_ACTION_TYPE_VIBRATION_OUTPUT;
         break;
-      }
-      default: {
-        continue;
-      }
     }
     action_info.countSubactionPaths = info.count_subaction_paths;
     action_info.subactionPaths = subaction_paths.data();
@@ -1182,7 +1173,7 @@ bool GHOST_XrSession::syncActions(const char *action_set_name)
 
 bool GHOST_XrSession::getActionStates(const char *action_set_name,
                                       uint32_t count,
-                                      GHOST_XrActionInfo *const *infos)
+                                      GHOST_XrActionInfo *r_infos)
 {
   OpenXRActionSet *action_set = find_action_set(m_oxr.get(), action_set_name);
   if (action_set == nullptr) {
@@ -1193,9 +1184,9 @@ bool GHOST_XrSession::getActionStates(const char *action_set_name,
   XrSession &session = m_oxr->session;
 
   for (uint32_t action_idx = 0; action_idx < count; ++action_idx) {
-    GHOST_XrActionInfo *info = infos[action_idx];
+    GHOST_XrActionInfo &info = r_infos[action_idx];
 
-    OpenXRAction *action = find_action(action_set, info->name);
+    OpenXRAction *action = find_action(action_set, info.name);
     if (action == nullptr) {
       continue;
     }
@@ -1203,22 +1194,21 @@ bool GHOST_XrSession::getActionStates(const char *action_set_name,
     XrActionStateGetInfo state_info{XR_TYPE_ACTION_STATE_GET_INFO};
     state_info.action = action->action;
 
-    for (uint32_t subaction_idx = 0; subaction_idx < info->count_subaction_paths;
-         ++subaction_idx) {
-      const char *subaction_path = info->subaction_paths[subaction_idx];
+    for (uint32_t subaction_idx = 0; subaction_idx < info.count_subaction_paths; ++subaction_idx) {
+      const char *subaction_path = info.subaction_paths[subaction_idx];
       CHECK_XR(xrStringToPath(instance, subaction_path, &state_info.subactionPath),
                (m_error_msg = std::string("Failed to get user path \"") + subaction_path + "\".")
                    .c_str());
 
-      switch (info->type) {
+      switch (info.type) {
         case GHOST_kXrActionTypeBooleanInput: {
           XrActionStateBoolean state{XR_TYPE_ACTION_STATE_BOOLEAN};
           CHECK_XR(xrGetActionStateBoolean(session, &state_info, &state),
                    (m_error_msg = std::string("Failed to get state for boolean action \"") +
-                                  info->name + "\".")
+                                  info.name + "\".")
       

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list