[Bf-blender-cvs] [76385139cfb] soc-2019-openxr: Use friend class to access graphics data on Windows too

Julian Eisel noreply at git.blender.org
Wed Jun 19 18:31:46 CEST 2019


Commit: 76385139cfbb9c0a5ea1d04836870a0a8dc45a4e
Author: Julian Eisel
Date:   Wed Jun 19 18:30:19 2019 +0200
Branches: soc-2019-openxr
https://developer.blender.org/rB76385139cfbb9c0a5ea1d04836870a0a8dc45a4e

Use friend class to access graphics data on Windows too

Also fix memory leak.

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

M	intern/ghost/intern/GHOST_ContextD3D.cpp
M	intern/ghost/intern/GHOST_ContextD3D.h
M	intern/ghost/intern/GHOST_ContextWGL.cpp
M	intern/ghost/intern/GHOST_ContextWGL.h
M	intern/ghost/intern/GHOST_XR.cpp
M	intern/ghost/intern/GHOST_XRSession.cpp
M	release/scripts/addons

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

diff --git a/intern/ghost/intern/GHOST_ContextD3D.cpp b/intern/ghost/intern/GHOST_ContextD3D.cpp
index 2c4a5860ed9..2f3e28a28b2 100644
--- a/intern/ghost/intern/GHOST_ContextD3D.cpp
+++ b/intern/ghost/intern/GHOST_ContextD3D.cpp
@@ -383,8 +383,3 @@ static void drawTestTriangle(ID3D11Device *m_device,
   m_device_ctx->Draw(std::size(vertices), 0);
 }
 #endif
-
-ID3D11Device *GHOST_ContextD3D::getDevice()
-{
-  return m_device.Get();
-}
diff --git a/intern/ghost/intern/GHOST_ContextD3D.h b/intern/ghost/intern/GHOST_ContextD3D.h
index 2a28d03c9b5..c187dba757a 100644
--- a/intern/ghost/intern/GHOST_ContextD3D.h
+++ b/intern/ghost/intern/GHOST_ContextD3D.h
@@ -31,6 +31,9 @@
 #include "GHOST_Context.h"
 
 class GHOST_ContextD3D : public GHOST_Context {
+  /* XR code needs low level graphics data to send to OpenXR. */
+  friend class GHOST_XRGraphicsBinding;
+
  public:
   GHOST_ContextD3D(bool stereoVisual, HWND hWnd);
   ~GHOST_ContextD3D();
@@ -113,8 +116,6 @@ class GHOST_ContextD3D : public GHOST_Context {
     return true;
   }
 
-  ID3D11Device *getDevice();
-
  private:
   friend class SharedOpenGLContext;
 
diff --git a/intern/ghost/intern/GHOST_ContextWGL.cpp b/intern/ghost/intern/GHOST_ContextWGL.cpp
index 62e17359d71..a3d5d6f7edf 100644
--- a/intern/ghost/intern/GHOST_ContextWGL.cpp
+++ b/intern/ghost/intern/GHOST_ContextWGL.cpp
@@ -730,8 +730,3 @@ GHOST_TSuccess GHOST_ContextWGL::releaseNativeHandles()
 
   return success;
 }
-
-GHOST_ContextWGL::Info GHOST_ContextWGL::getInfo()
-{
-  return Info{m_hDC, m_hGLRC};
-}
diff --git a/intern/ghost/intern/GHOST_ContextWGL.h b/intern/ghost/intern/GHOST_ContextWGL.h
index ed230591912..e1b43d36d4c 100644
--- a/intern/ghost/intern/GHOST_ContextWGL.h
+++ b/intern/ghost/intern/GHOST_ContextWGL.h
@@ -35,6 +35,9 @@
 #endif
 
 class GHOST_ContextWGL : public GHOST_Context {
+  /* XR code needs low level graphics data to send to OpenXR. */
+  friend class GHOST_XRGraphicsBinding;
+
  public:
   /**
    * Constructor.
@@ -101,15 +104,6 @@ class GHOST_ContextWGL : public GHOST_Context {
 
   GHOST_TSuccess setDefaultFramebufferSize(GHOST_TUns32 width, GHOST_TUns32 height);
 
-  /**
-   * Helper to get low level system specific info out of the context.
-   */
-  struct Info {
-    HDC hDC;
-    HGLRC hGLRC;
-  };
-  Info getInfo();
-
  private:
   int choose_pixel_format(bool stereoVisual, bool needAlpha);
   int choose_pixel_format_arb(bool stereoVisual, bool needAlpha);
diff --git a/intern/ghost/intern/GHOST_XR.cpp b/intern/ghost/intern/GHOST_XR.cpp
index 0561df3809d..c769ebac280 100644
--- a/intern/ghost/intern/GHOST_XR.cpp
+++ b/intern/ghost/intern/GHOST_XR.cpp
@@ -255,6 +255,7 @@ void GHOST_XR_context_destroy(GHOST_XRContext *xr_context)
 
   /* Unbinding may involve destruction, so call here too */
   GHOST_XR_graphics_context_unbind(*xr_context);
+  delete xr_context->gpu_binding;
 
   if (oxr->session != XR_NULL_HANDLE) {
     xrDestroySession(oxr->session);
diff --git a/intern/ghost/intern/GHOST_XRSession.cpp b/intern/ghost/intern/GHOST_XRSession.cpp
index d975bc1874f..9255450e604 100644
--- a/intern/ghost/intern/GHOST_XRSession.cpp
+++ b/intern/ghost/intern/GHOST_XRSession.cpp
@@ -89,11 +89,10 @@ class GHOST_XRGraphicsBinding {
         oxr_binding.glx.xDisplay = ctx_glx->m_display;
 #elif defined(WIN32)
         GHOST_ContextWGL *ctx_wgl = static_cast<GHOST_ContextWGL *>(ghost_ctx);
-        GHOST_ContextWGL::Info info = ctx_wgl->getInfo();
 
         oxr_binding.wgl.type = XR_TYPE_GRAPHICS_BINDING_OPENGL_WIN32_KHR;
-        oxr_binding.wgl.hDC = info.hDC;
-        oxr_binding.wgl.hGLRC = info.hGLRC;
+        oxr_binding.wgl.hDC = ctx_wgl->m_hDC;
+        oxr_binding.wgl.hGLRC = ctx_wgl->m_hGLRC;
 #endif
 
         break;
@@ -103,7 +102,7 @@ class GHOST_XRGraphicsBinding {
         GHOST_ContextD3D *ctx_d3d = static_cast<GHOST_ContextD3D *>(ghost_ctx);
 
         oxr_binding.d3d11.type = XR_TYPE_GRAPHICS_BINDING_D3D11_KHR;
-        oxr_binding.d3d11.device = ctx_d3d->getDevice();
+        oxr_binding.d3d11.device = ctx_d3d->m_device.Get();
 
         break;
       }
@@ -154,6 +153,7 @@ void GHOST_XR_session_end(GHOST_XRContext *xr_context)
 {
   xrEndSession(xr_context->oxr.session);
   GHOST_XR_graphics_context_unbind(*xr_context);
+  delete xr_context->gpu_binding;
 }
 
 void GHOST_XR_session_state_change(OpenXRData *oxr,
diff --git a/release/scripts/addons b/release/scripts/addons
index 6cad544cb30..a5a236df5f6 160000
--- a/release/scripts/addons
+++ b/release/scripts/addons
@@ -1 +1 @@
-Subproject commit 6cad544cb30364ac14954a9c050d83c6fcbe50dd
+Subproject commit a5a236df5f6630ea17958e3006070ef609c6a4b8



More information about the Bf-blender-cvs mailing list