[Bf-blender-cvs] [916efac0c89] soc-2019-openxr: Cleanup: Address various review comments

Julian Eisel noreply at git.blender.org
Tue Mar 10 16:34:45 CET 2020


Commit: 916efac0c89b5f5eec909271f6653f4922b9bcad
Author: Julian Eisel
Date:   Mon Mar 9 18:47:31 2020 +0100
Branches: soc-2019-openxr
https://developer.blender.org/rB916efac0c89b5f5eec909271f6653f4922b9bcad

Cleanup: Address various review comments

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

M	intern/ghost/intern/GHOST_XrContext.cpp
M	intern/ghost/intern/GHOST_XrContext.h
M	intern/ghost/intern/GHOST_XrException.h
M	intern/ghost/intern/GHOST_XrGraphicsBinding.cpp
M	intern/ghost/intern/GHOST_XrSession.cpp
M	intern/ghost/intern/GHOST_XrSession.h
M	intern/ghost/intern/GHOST_Xr_intern.h

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

diff --git a/intern/ghost/intern/GHOST_XrContext.cpp b/intern/ghost/intern/GHOST_XrContext.cpp
index 0c533939b8c..e1a6911e788 100644
--- a/intern/ghost/intern/GHOST_XrContext.cpp
+++ b/intern/ghost/intern/GHOST_XrContext.cpp
@@ -32,8 +32,8 @@
 #include "GHOST_XrContext.h"
 
 struct OpenXRInstanceData {
-  XrInstance instance{XR_NULL_HANDLE};
-  XrInstanceProperties instance_properties;
+  XrInstance instance = XR_NULL_HANDLE;
+  XrInstanceProperties instance_properties = {};
 
   std::vector<XrExtensionProperties> extensions;
   std::vector<XrApiLayerProperties> layers;
@@ -41,7 +41,7 @@ struct OpenXRInstanceData {
   static PFN_xrCreateDebugUtilsMessengerEXT s_xrCreateDebugUtilsMessengerEXT_fn;
   static PFN_xrDestroyDebugUtilsMessengerEXT s_xrDestroyDebugUtilsMessengerEXT_fn;
 
-  XrDebugUtilsMessengerEXT debug_messenger{XR_NULL_HANDLE};
+  XrDebugUtilsMessengerEXT debug_messenger = XR_NULL_HANDLE;
 };
 
 PFN_xrCreateDebugUtilsMessengerEXT OpenXRInstanceData::s_xrCreateDebugUtilsMessengerEXT_fn =
@@ -63,6 +63,7 @@ GHOST_XrContext::GHOST_XrContext(const GHOST_XrContextCreateInfo *create_info)
       m_debug_time(create_info->context_flag & GHOST_kXrContextDebugTime)
 {
 }
+
 GHOST_XrContext::~GHOST_XrContext()
 {
   /* Destroy session data first. Otherwise xrDestroyInstance will implicitly do it, before the
@@ -81,8 +82,8 @@ GHOST_XrContext::~GHOST_XrContext()
 
 void GHOST_XrContext::initialize(const GHOST_XrContextCreateInfo *create_info)
 {
-  enumerateApiLayers();
-  enumerateExtensions();
+  initApiLayers();
+  initExtensions();
   XR_DEBUG_ONLY_CALL(this, printAvailableAPILayersAndExtensionsInfo());
 
   m_gpu_binding_type = determineGraphicsBindingTypeToEnable(create_info);
@@ -96,7 +97,7 @@ void GHOST_XrContext::initialize(const GHOST_XrContextCreateInfo *create_info)
 
 void GHOST_XrContext::createOpenXRInstance()
 {
-  XrInstanceCreateInfo create_info{XR_TYPE_INSTANCE_CREATE_INFO};
+  XrInstanceCreateInfo create_info = {XR_TYPE_INSTANCE_CREATE_INFO};
 
   std::string("Blender").copy(create_info.applicationInfo.applicationName,
                               XR_MAX_APPLICATION_NAME_SIZE);
@@ -116,7 +117,7 @@ void GHOST_XrContext::createOpenXRInstance()
 
 void GHOST_XrContext::storeInstanceProperties()
 {
-  const std::map<std::string, GHOST_TXrOpenXRRuntimeID> runtime_map{
+  const std::map<std::string, GHOST_TXrOpenXRRuntimeID> runtime_map = {
       {"Monado(XRT) by Collabora et al", OPENXR_RUNTIME_MONADO},
       {"Oculus", OPENXR_RUNTIME_OCULUS},
       {"Windows Mixed Reality Runtime", OPENXR_RUNTIME_WMR}};
@@ -183,7 +184,7 @@ static XrBool32 debug_messenger_func(XrDebugUtilsMessageSeverityFlagsEXT /*messa
 
 void GHOST_XrContext::initDebugMessenger()
 {
-  XrDebugUtilsMessengerCreateInfoEXT create_info{XR_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT};
+  XrDebugUtilsMessengerCreateInfoEXT create_info = {XR_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT};
 
   /* Extension functions need to be obtained through xrGetInstanceProcAddr(). */
   if (XR_FAILED(xrGetInstanceProcAddr(
@@ -245,7 +246,7 @@ void GHOST_XrContext::dispatchErrorMessage(const GHOST_XrException *exception) c
                      fprintf(stderr,
                              "Error: \t%s\n\tOpenXR error value: %i\n\tSource: (%s)\n",
                              error.user_message,
-                             exception->m_res,
+                             exception->m_result,
                              error.source_location));
 
   /* Potentially destroys GHOST_XrContext */
@@ -268,8 +269,8 @@ void GHOST_XrContext::setErrorHandler(GHOST_XrErrorHandlerFn handler_fn, void *c
 /**
  * \param layer_name May be NULL for extensions not belonging to a specific layer.
  */
-void GHOST_XrContext::enumerateExtensionsEx(std::vector<XrExtensionProperties> &extensions,
-                                            const char *layer_name)
+void GHOST_XrContext::initExtensionsEx(std::vector<XrExtensionProperties> &extensions,
+                                       const char *layer_name)
 {
   uint32_t extension_count = 0;
 
@@ -283,7 +284,7 @@ void GHOST_XrContext::enumerateExtensionsEx(std::vector<XrExtensionProperties> &
   }
 
   for (uint32_t i = 0; i < extension_count; i++) {
-    XrExtensionProperties ext{XR_TYPE_EXTENSION_PROPERTIES};
+    XrExtensionProperties ext = {XR_TYPE_EXTENSION_PROPERTIES};
     extensions.push_back(ext);
   }
 
@@ -292,12 +293,13 @@ void GHOST_XrContext::enumerateExtensionsEx(std::vector<XrExtensionProperties> &
                layer_name, extension_count, &extension_count, extensions.data()),
            "Failed to query OpenXR runtime information. Do you have an active runtime set up?");
 }
-void GHOST_XrContext::enumerateExtensions()
+
+void GHOST_XrContext::initExtensions()
 {
-  enumerateExtensionsEx(m_oxr->extensions, nullptr);
+  initExtensionsEx(m_oxr->extensions, nullptr);
 }
 
-void GHOST_XrContext::enumerateApiLayers()
+void GHOST_XrContext::initApiLayers()
 {
   uint32_t layer_count = 0;
 
@@ -320,7 +322,7 @@ void GHOST_XrContext::enumerateApiLayers()
            "Failed to query OpenXR runtime information. Do you have an active runtime set up?");
   for (XrApiLayerProperties &layer : m_oxr->layers) {
     /* Each layer may have own extensions. */
-    enumerateExtensionsEx(m_oxr->extensions, layer.layerName);
+    initExtensionsEx(m_oxr->extensions, layer.layerName);
   }
 }
 
@@ -335,6 +337,7 @@ static bool openxr_layer_is_available(const std::vector<XrApiLayerProperties> la
 
   return false;
 }
+
 static bool openxr_extension_is_available(const std::vector<XrExtensionProperties> extensions_info,
                                           const std::string &extension_name)
 {
@@ -453,6 +456,7 @@ void GHOST_XrContext::startSession(const GHOST_XrSessionBeginInfo *begin_info)
 
   m_session->start(begin_info);
 }
+
 void GHOST_XrContext::endSession()
 {
   m_session->requestEnd();
@@ -514,9 +518,9 @@ GHOST_TXrOpenXRRuntimeID GHOST_XrContext::getOpenXRRuntimeID() const
   return m_runtime_id;
 }
 
-const GHOST_XrCustomFuncs *GHOST_XrContext::getCustomFuncs() const
+const GHOST_XrCustomFuncs &GHOST_XrContext::getCustomFuncs() const
 {
-  return &m_custom_funcs;
+  return m_custom_funcs;
 }
 
 GHOST_TXrGraphicsBinding GHOST_XrContext::getGraphicsBindingType() const
diff --git a/intern/ghost/intern/GHOST_XrContext.h b/intern/ghost/intern/GHOST_XrContext.h
index 8ebca096def..b361fb5caf8 100644
--- a/intern/ghost/intern/GHOST_XrContext.h
+++ b/intern/ghost/intern/GHOST_XrContext.h
@@ -25,14 +25,16 @@
 #include <vector>
 #include "GHOST_IXrContext.h"
 
+struct OpenXRInstanceData;
+
 struct GHOST_XrCustomFuncs {
   /** Function to retrieve (possibly create) a graphics context. */
-  GHOST_XrGraphicsContextBindFn gpu_ctx_bind_fn{nullptr};
+  GHOST_XrGraphicsContextBindFn gpu_ctx_bind_fn = nullptr;
   /** Function to release (possibly free) a graphics context. */
-  GHOST_XrGraphicsContextUnbindFn gpu_ctx_unbind_fn{nullptr};
+  GHOST_XrGraphicsContextUnbindFn gpu_ctx_unbind_fn = nullptr;
 
   /** Custom per-view draw function for Blender side drawing. */
-  GHOST_XrDrawViewFn draw_view_fn{nullptr};
+  GHOST_XrDrawViewFn draw_view_fn = nullptr;
 };
 
 /**
@@ -74,35 +76,36 @@ class GHOST_XrContext : public GHOST_IXrContext {
   void handleSessionStateChange(const XrEventDataSessionStateChanged *lifecycle);
 
   GHOST_TXrOpenXRRuntimeID getOpenXRRuntimeID() const;
-  const GHOST_XrCustomFuncs *getCustomFuncs() const;
+  const GHOST_XrCustomFuncs &getCustomFuncs() const;
   GHOST_TXrGraphicsBinding getGraphicsBindingType() const;
   XrInstance getInstance() const;
   bool isDebugMode() const;
   bool isDebugTimeMode() const;
 
  private:
-  std::unique_ptr<struct OpenXRInstanceData> m_oxr;
+  static GHOST_XrErrorHandlerFn s_error_handler;
+  static void *s_error_handler_customdata;
 
-  GHOST_TXrOpenXRRuntimeID m_runtime_id{OPENXR_RUNTIME_UNKNOWN};
+  std::unique_ptr<OpenXRInstanceData> m_oxr;
+
+  GHOST_TXrOpenXRRuntimeID m_runtime_id = OPENXR_RUNTIME_UNKNOWN;
 
   /* The active GHOST XR Session. Null while no session runs. */
   std::unique_ptr<class GHOST_XrSession> m_session;
 
   /** Active graphics binding type. */
-  GHOST_TXrGraphicsBinding m_gpu_binding_type{GHOST_kXrGraphicsUnknown};
+  GHOST_TXrGraphicsBinding m_gpu_binding_type = GHOST_kXrGraphicsUnknown;
 
   /** Names of enabled extensions. */
   std::vector<const char *> m_enabled_extensions;
   /** Names of enabled API-layers. */
   std::vector<const char *> m_enabled_layers;
 
-  static GHOST_XrErrorHandlerFn s_error_handler;
-  static void *s_error_handler_customdata;
   GHOST_XrCustomFuncs m_custom_funcs;
 
   /** Enable debug message prints and OpenXR API validation layers. */
-  bool m_debug{false};
-  bool m_debug_time{false};
+  bool m_debug = false;
+  bool m_debug_time = false;
 
   void createOpenXRInstance();
   void storeInstanceProperties();
@@ -112,10 +115,9 @@ class GHOST_XrContext : public GHOST_IXrContext {
   void printAvailableAPILayersAndExtensionsInfo();
   void printExtensionsAndAPILayersToEnable();
 
-  void enumerateApiLayers();
-  void enumerateExtensions();
-  void enumerateExtensionsEx(std::vector<XrExtensionProperties> &extensions,
-                             const char *layer_name);
+  void initApiLayers();
+  void initExtensions();
+  void initExtensionsEx(std::vector<XrExtensionProperties> &extensions, const char *layer_name);
   void getAPILayersToEnable(std::vector<const char *> &r_ext_names);
   void getExtensionsToEnable(std::vector<const char *> &r_ext_names);
   GHOST_TXrGraphicsBinding determineGraphicsBindingTypeToEnable(
diff --git a/intern/ghost/intern/GHOST_XrException.h b/intern/ghost/intern/GHOST_XrException.h
index 9682c7a81d9..abcd57b6ce0 100644
--- a/intern/ghost/intern/GHOST_XrException.h
+++ b/intern/ghost/intern/GHOST_XrException.h
@@ -27,8 +27,8 @@ class GHOST_XrException : public std::exception {
   friend class GHOST_XrContext;
 
  public:
-  GHOST_XrException(const char *msg, const char *file, int line, int res = 0)
-      : std::exception(), m_msg(msg), m_file(file), m_line(line), m_res(res)
+  GHOST_XrException(const char *msg, const char *file, int line, int result = 0)
+      : std::exception(), m_msg(msg), m_file(file)

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list