[Bf-blender-cvs] [c1e9cf00ac0] soc-2019-openxr: Refactor GHOST_XrContext into class + interface

Julian Eisel noreply at git.blender.org
Wed Jul 10 23:54:22 CEST 2019


Commit: c1e9cf00ac0a6eb860dda22e3ca05d204c2759b3
Author: Julian Eisel
Date:   Wed Jul 10 21:55:24 2019 +0200
Branches: soc-2019-openxr
https://developer.blender.org/rBc1e9cf00ac0a6eb860dda22e3ca05d204c2759b3

Refactor GHOST_XrContext into class + interface

Makes GHOST_Xr much more consistent with the rest of GHOST. Basically I
added a GHOST_IXrContext interface which can be called by the GHOST
C-API. The internal GHOST_XrContext class implements this.
Outside of GHOST only the opaque GHOST_XrContextHandle is accessible.

Kept GHOST_Xr_intern.h and GHOST_Xr.cpp for now. I'll probably remove
them soon. There's not much reason for both of them to be there.

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

M	intern/ghost/CMakeLists.txt
M	intern/ghost/GHOST_C-api.h
A	intern/ghost/GHOST_IXrContext.h
M	intern/ghost/GHOST_Types.h
M	intern/ghost/intern/GHOST_C-api.cpp
M	intern/ghost/intern/GHOST_Xr.cpp
A	intern/ghost/intern/GHOST_XrContext.cpp
A	intern/ghost/intern/GHOST_XrContext.h
M	intern/ghost/intern/GHOST_XrEvent.cpp
M	intern/ghost/intern/GHOST_XrSession.cpp
M	intern/ghost/intern/GHOST_XrSession.h
M	intern/ghost/intern/GHOST_Xr_intern.h
M	source/blender/makesdna/DNA_windowmanager_types.h
M	source/blender/windowmanager/intern/wm_xr.c
M	source/blender/windowmanager/wm.h

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

diff --git a/intern/ghost/CMakeLists.txt b/intern/ghost/CMakeLists.txt
index d40583977be..8661e10f3a1 100644
--- a/intern/ghost/CMakeLists.txt
+++ b/intern/ghost/CMakeLists.txt
@@ -350,12 +350,14 @@ endif()
 if(WITH_OPENXR)
   list(APPEND SRC
     intern/GHOST_Xr.cpp
+    intern/GHOST_XrContext.cpp
     intern/GHOST_XrEvent.cpp
     intern/GHOST_XrGraphicsBinding.cpp
     intern/GHOST_XrSession.cpp
 
     intern/GHOST_Xr_intern.h
     intern/GHOST_Xr_openxr_includes.h
+    intern/GHOST_XrContext.h
     intern/GHOST_IXrGraphicsBinding.h
     intern/GHOST_XrSession.h
   )
diff --git a/intern/ghost/GHOST_C-api.h b/intern/ghost/GHOST_C-api.h
index 7d67a7b37a8..c86902de3b1 100644
--- a/intern/ghost/GHOST_C-api.h
+++ b/intern/ghost/GHOST_C-api.h
@@ -981,24 +981,24 @@ extern void GHOST_EndIME(GHOST_WindowHandle windowhandle);
 #ifdef WITH_OPENXR
 
 /* xr-context */
-struct GHOST_XrContext *GHOST_XrContextCreate(const GHOST_XrContextCreateInfo *create_info);
-void GHOST_XrContextDestroy(struct GHOST_XrContext *xr_context);
+GHOST_XrContextHandle GHOST_XrContextCreate(const GHOST_XrContextCreateInfo *create_info);
+void GHOST_XrContextDestroy(GHOST_XrContextHandle xr_context);
 
-void GHOST_XrGraphicsContextBindFuncs(struct GHOST_XrContext *xr_context,
+void GHOST_XrGraphicsContextBindFuncs(GHOST_XrContextHandle xr_context,
                                       GHOST_XrGraphicsContextBindFn bind_fn,
                                       GHOST_XrGraphicsContextUnbindFn unbind_fn);
 
-void GHOST_XrDrawViewFunc(struct GHOST_XrContext *xr_context, GHOST_XrDrawViewFn draw_view_fn);
+void GHOST_XrDrawViewFunc(GHOST_XrContextHandle xr_context, GHOST_XrDrawViewFn draw_view_fn);
 
 /* sessions */
-GHOST_TSuccess GHOST_XrSessionIsRunning(const struct GHOST_XrContext *xr_context);
-void GHOST_XrSessionStart(struct GHOST_XrContext *xr_context,
+int GHOST_XrSessionIsRunning(const GHOST_XrContextHandle xr_context);
+void GHOST_XrSessionStart(GHOST_XrContextHandle xr_context,
                           const GHOST_XrSessionBeginInfo *begin_info);
-void GHOST_XrSessionEnd(struct GHOST_XrContext *xr_context);
-void GHOST_XrSessionDrawViews(struct GHOST_XrContext *xr_context, void *customdata);
+void GHOST_XrSessionEnd(GHOST_XrContextHandle xr_context);
+void GHOST_XrSessionDrawViews(GHOST_XrContextHandle xr_context, void *customdata);
 
 /* events */
-GHOST_TSuccess GHOST_XrEventsHandle(struct GHOST_XrContext *xr_context);
+GHOST_TSuccess GHOST_XrEventsHandle(GHOST_XrContextHandle xr_context);
 #endif
 
 #ifdef __cplusplus
diff --git a/intern/ghost/GHOST_IXrContext.h b/intern/ghost/GHOST_IXrContext.h
new file mode 100644
index 00000000000..796805121b5
--- /dev/null
+++ b/intern/ghost/GHOST_IXrContext.h
@@ -0,0 +1,40 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+/** \file
+ * \ingroup GHOST
+ */
+
+#ifndef __GHOST_IXRCONTEXT_H__
+#define __GHOST_IXRCONTEXT_H__
+
+#include "GHOST_Types.h"
+
+class GHOST_IXrContext {
+ public:
+  virtual ~GHOST_IXrContext() = default;
+
+  virtual void startSession(const GHOST_XrSessionBeginInfo *begin_info) = 0;
+  virtual void endSession() = 0;
+  virtual bool isSessionRunning() const = 0;
+  virtual void drawSessionViews(void *draw_customdata) = 0;
+
+  virtual void setGraphicsContextBindFuncs(GHOST_XrGraphicsContextBindFn bind_fn,
+                                           GHOST_XrGraphicsContextUnbindFn unbind_fn) = 0;
+  virtual void setDrawViewFunc(GHOST_XrDrawViewFn draw_view_fn) = 0;
+};
+
+#endif  // __GHOST_IXRCONTEXT_H__
diff --git a/intern/ghost/GHOST_Types.h b/intern/ghost/GHOST_Types.h
index 41840a5f0f5..06bd5ca8180 100644
--- a/intern/ghost/GHOST_Types.h
+++ b/intern/ghost/GHOST_Types.h
@@ -55,6 +55,7 @@ GHOST_DECLARE_HANDLE(GHOST_EventHandle);
 GHOST_DECLARE_HANDLE(GHOST_RectangleHandle);
 GHOST_DECLARE_HANDLE(GHOST_EventConsumerHandle);
 GHOST_DECLARE_HANDLE(GHOST_ContextHandle);
+GHOST_DECLARE_HANDLE(GHOST_XrContextHandle);
 
 typedef char GHOST_TInt8;
 typedef unsigned char GHOST_TUns8;
diff --git a/intern/ghost/intern/GHOST_C-api.cpp b/intern/ghost/intern/GHOST_C-api.cpp
index 16a6d515c1b..5d7a774336c 100644
--- a/intern/ghost/intern/GHOST_C-api.cpp
+++ b/intern/ghost/intern/GHOST_C-api.cpp
@@ -30,8 +30,8 @@
 #include "GHOST_ISystem.h"
 #include "GHOST_IEvent.h"
 #include "GHOST_IEventConsumer.h"
+#include "GHOST_IXrContext.h"
 #include "intern/GHOST_CallbackEventConsumer.h"
-#include "intern/GHOST_XrSession.h"
 
 GHOST_SystemHandle GHOST_CreateSystem(void)
 {
@@ -904,3 +904,46 @@ void GHOST_EndIME(GHOST_WindowHandle windowhandle)
 }
 
 #endif /* WITH_INPUT_IME */
+
+#ifdef WITH_OPENXR
+
+void GHOST_XrSessionStart(GHOST_XrContextHandle xr_contexthandle,
+                          const GHOST_XrSessionBeginInfo *begin_info)
+{
+  GHOST_IXrContext *xr_context = (GHOST_IXrContext *)xr_contexthandle;
+  xr_context->startSession(begin_info);
+}
+
+void GHOST_XrSessionEnd(GHOST_XrContextHandle xr_contexthandle)
+{
+  GHOST_IXrContext *xr_context = (GHOST_IXrContext *)xr_contexthandle;
+  xr_context->endSession();
+}
+
+int GHOST_XrSessionIsRunning(const GHOST_XrContextHandle xr_contexthandle)
+{
+  const GHOST_IXrContext *xr_context = (GHOST_IXrContext *)xr_contexthandle;
+  return xr_context->isSessionRunning();
+}
+
+void GHOST_XrSessionDrawViews(GHOST_XrContextHandle xr_contexthandle, void *draw_customdata)
+{
+  GHOST_IXrContext *xr_context = (GHOST_IXrContext *)xr_contexthandle;
+  xr_context->drawSessionViews(draw_customdata);
+}
+
+void GHOST_XrGraphicsContextBindFuncs(GHOST_XrContextHandle xr_contexthandle,
+                                      GHOST_XrGraphicsContextBindFn bind_fn,
+                                      GHOST_XrGraphicsContextUnbindFn unbind_fn)
+{
+  GHOST_IXrContext *xr_context = (GHOST_IXrContext *)xr_contexthandle;
+  xr_context->setGraphicsContextBindFuncs(bind_fn, unbind_fn);
+}
+
+void GHOST_XrDrawViewFunc(GHOST_XrContextHandle xr_contexthandle, GHOST_XrDrawViewFn draw_view_fn)
+{
+  GHOST_IXrContext *xr_context = (GHOST_IXrContext *)xr_contexthandle;
+  xr_context->setDrawViewFunc(draw_view_fn);
+}
+
+#endif
diff --git a/intern/ghost/intern/GHOST_Xr.cpp b/intern/ghost/intern/GHOST_Xr.cpp
index ebdf1636cf2..dfdd0d8c0cf 100644
--- a/intern/ghost/intern/GHOST_Xr.cpp
+++ b/intern/ghost/intern/GHOST_Xr.cpp
@@ -26,390 +26,25 @@
 #include "GHOST_C-api.h"
 
 #include "GHOST_Xr_intern.h"
-
-static PFN_xrCreateDebugUtilsMessengerEXT g_xrCreateDebugUtilsMessengerEXT_fn = nullptr;
-static PFN_xrDestroyDebugUtilsMessengerEXT g_xrDestroyDebugUtilsMessengerEXT_fn = nullptr;
-
-/**
- * \param layer_name May be NULL for extensions not belonging to a specific layer.
- */
-static bool openxr_gather_extensions_ex(const GHOST_XrContext *xr_context,
-                                        std::vector<XrExtensionProperties> &extensions,
-                                        const char *layer_name)
-{
-  const unsigned long old_extension_count = extensions.size();
-  uint32_t extension_count = 0;
-
-  /* Get count for array creation/init first. */
-  if (XR_FAILED(
-          xrEnumerateInstanceExtensionProperties(layer_name, 0, &extension_count, nullptr))) {
-    return false;
-  }
-
-  if (extension_count == 0) {
-    /* Extensions are optional, can successfully exit. */
-    return true;
-  }
-
-  for (uint32_t i = 0; i < extension_count; i++) {
-    XrExtensionProperties ext{};
-
-    ext.type = XR_TYPE_EXTENSION_PROPERTIES;
-    extensions.push_back(ext);
-  }
-
-  if (layer_name) {
-    XR_DEBUG_PRINTF(xr_context, "Layer: %s\n", layer_name);
-  }
-
-  /* Actually get the extensions. */
-  xrEnumerateInstanceExtensionProperties(
-      layer_name, extension_count, &extension_count, extensions.data());
-  XR_DEBUG_ONLY_BEGIN(xr_context);
-  for (uint32_t i = 0; i < extension_count; i++) {
-    XR_DEBUG_PRINTF(
-        xr_context, "Extension: %s\n", extensions[i + old_extension_count].extensionName);
-  }
-  XR_DEBUG_ONLY_END;
-
-  return true;
-}
-static bool openxr_gather_extensions(const GHOST_XrContext *xr_context, OpenXRData *oxr)
-{
-  return openxr_gather_extensions_ex(xr_context, oxr->extensions, nullptr);
-}
-
-static bool openxr_gather_api_layers(const GHOST_XrContext *xr_context, OpenXRData *oxr)
-{
-  uint32_t layer_count = 0;
-
-  /* Get count for array creation/init first. */
-  if (XR_FAILED(xrEnumerateApiLayerProperties(0, &layer_count, nullptr))) {
-    return false;
-  }
-
-  if (layer_count == 0) {
-    /* Layers are optional, can safely exit. */
-    return true;
-  }
-
-  oxr->layers = std::vector<XrApiLayerProperties>(layer_count);
-  for (XrApiLayerProperties &layer : oxr->layers) {
-    layer.type = XR_TYPE_API_LAYER_PROPERTIES;
-  }
-
-  /* Actually get the layers. */
-  xrEnumerateApiLayerProperties(layer_count, &layer_count, oxr->layers.data());
-  for (XrApiLayerProperties &layer : oxr->layers) {
-    XR_DEBUG_PRINTF(xr_context, "Layer: %s\n", layer.layerName);
-
-    /* Each layer may have own extensions */
-    openxr_gather_extensions_ex(xr_context, oxr->extensions, layer.layerName);
-  }
-
-  return true;
-}
-
-static bool openxr_layer_is_available(const OpenXRData *oxr, const std::string &layer_name)
-{
-  for (const XrApiLayerProperties &layer : oxr->layers) {
-    if (layer.layerName == layer_name) {
-      return true;
-    }
-  }
-
-  return false;
-}
-static bool openxr_extension_is_available(const OpenXRData *oxr, const std::string &extension_name)
-{
-  for (const XrExtensionProperties &ext : oxr->extensions) {
-    if (ext.extensionName == extension_name) {
-      return true;

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list