Bug 1374393 - Build OpenVR on macOS and Linux draft
authorKearwood Gilbert <kgilbert@mozilla.com>
Wed, 31 May 2017 11:14:55 -0700
changeset 598634 9982aaa8c7791b272e53c4ee8049ca947fa11ea3
parent 598633 e916ab827babb677ce5ab2cac0390c1401eaca0e
child 598635 7a4de32952fd39d88de370abf3026b654a7b097c
push id65263
push userkgilbert@mozilla.com
push dateWed, 21 Jun 2017 23:09:52 +0000
bugs1374393
milestone56.0a1
Bug 1374393 - Build OpenVR on macOS and Linux - OpenVR was previously only being built for Windows builds it will now be built additionally on macOS and Linux. MozReview-Commit-ID: 68ZUNmdybd1
gfx/vr/VRManager.cpp
gfx/vr/gfxVROpenVR.h
gfx/vr/moz.build
gfx/vr/openvr/README.mozilla
gfx/vr/openvr/moz.build
gfx/vr/openvr/src/strtools_public.h
--- a/gfx/vr/VRManager.cpp
+++ b/gfx/vr/VRManager.cpp
@@ -12,19 +12,19 @@
 #include "mozilla/dom/GamepadEventTypes.h"
 #include "mozilla/layers/TextureHost.h"
 #include "mozilla/Unused.h"
 
 #include "gfxPrefs.h"
 #include "gfxVR.h"
 #if defined(XP_WIN)
 #include "gfxVROculus.h"
+#endif
+#if defined(XP_WIN) || defined(XP_MACOSX) || (defined(XP_LINUX) && !defined(MOZ_WIDGET_ANDROID))
 #include "gfxVROpenVR.h"
-#endif
-#if defined(XP_WIN) || defined(XP_MACOSX) || defined(XP_LINUX)
 #include "gfxVROSVR.h"
 #endif
 #include "gfxVRPuppet.h"
 #include "ipc/VRLayerParent.h"
 
 using namespace mozilla;
 using namespace mozilla::gfx;
 using namespace mozilla::layers;
@@ -70,24 +70,25 @@ VRManager::VRManager()
    */
 
 #if defined(XP_WIN)
   // The Oculus runtime is supported only on Windows
   mgr = VRSystemManagerOculus::Create();
   if (mgr) {
     mManagers.AppendElement(mgr);
   }
-  // OpenVR is cross platform compatible, but supported only on Windows for now
+#endif
+
+#if defined(XP_WIN) || defined(XP_MACOSX) || (defined(XP_LINUX) && !defined(MOZ_WIDGET_ANDROID))
+  // OpenVR is cross platform compatible
   mgr = VRSystemManagerOpenVR::Create();
   if (mgr) {
     mManagers.AppendElement(mgr);
   }
-#endif
 
-#if defined(XP_WIN) || defined(XP_MACOSX) || defined(XP_LINUX)
   // OSVR is cross platform compatible
   mgr = VRSystemManagerOSVR::Create();
   if (mgr) {
       mManagers.AppendElement(mgr);
   }
 #endif
   // Enable gamepad extensions while VR is enabled.
   // Preference only can be set at the Parent process.
--- a/gfx/vr/gfxVROpenVR.h
+++ b/gfx/vr/gfxVROpenVR.h
@@ -3,16 +3,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef GFX_VR_OPENVR_H
 #define GFX_VR_OPENVR_H
 
 #include "nsTArray.h"
 #include "nsIScreen.h"
+#include "nsIThread.h"
 #include "nsCOMPtr.h"
 #include "mozilla/RefPtr.h"
 
 #include "mozilla/gfx/2D.h"
 #include "mozilla/EnumeratedArray.h"
 
 #include "openvr.h"
 #include "gfxVR.h"
--- a/gfx/vr/moz.build
+++ b/gfx/vr/moz.build
@@ -30,23 +30,28 @@ UNIFIED_SOURCES += [
     'ipc/VRManagerChild.cpp',
     'ipc/VRManagerParent.cpp',
     'VRDisplayClient.cpp',
     'VRDisplayHost.cpp',
     'VRDisplayPresentation.cpp',
     'VRManager.cpp',
 ]
 
-if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows':
+# Build OpenVR on Windows, Linux, and macOS desktop targets
+if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('cocoa', 'uikit', 'windows', 'gtk2', 'gtk3'):
     DIRS += [
         'openvr',
     ]
     SOURCES += [
+        'gfxVROpenVR.cpp',
+    ]
+
+if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows':
+    SOURCES += [
         'gfxVROculus.cpp',
-        'gfxVROpenVR.cpp',
     ]
 
 IPDL_SOURCES = [
     'ipc/PVRLayer.ipdl',
     'ipc/PVRManager.ipdl',
 ]
 
 # For building with the real SDK instead of our local hack
--- a/gfx/vr/openvr/README.mozilla
+++ b/gfx/vr/openvr/README.mozilla
@@ -32,18 +32,21 @@ Steps to update the library:
   in this directory can be ignored.
 
 - The rest of the files in the "src" directory and the "src/vrcommon" are copied
   to the "gfx/vr/openvr/src" directory.
 
 - Update "gfx/vr/openvr/moz.build" when files are added or removed.
 
 - Update the "strtools_public.h" and "strtools_public.cpp" files, commenting out
-  the "Uint64ToString" function. This function name conflicts with another used
-  in Gecko. Fortunately, the OpenVR SDK does not use this function either.
+  the "Uint64ToString", "wcsncpy_s", and "strncpy_s" functions.
+  The "Uint64ToString" function name conflicts with another used in Gecko and
+  the "errno_t" return type returned by the other functions is not defined in
+  Mozilla's macOS continuous integration build environments.  Fortunately, the
+  OpenVR SDK does not use these functions.
 
 - Replace the #define VR_INTERFACE in openvr.h to avoid extern'ing the functions.
   Unlike the usual OpenVR API builds, we are not building a separate dll.
 
 - Update this README.mozilla file with the new OpenVR SDK version and any
   additional steps needed for newer versions.
 
 - Ensure that any changes made within the OpenVR files have comments including
--- a/gfx/vr/openvr/moz.build
+++ b/gfx/vr/openvr/moz.build
@@ -9,23 +9,29 @@ FINAL_LIBRARY = 'xul'
 DEFINES['VR_API_PUBLIC'] = True
 
 if CONFIG['OS_ARCH'] == 'WINNT':
     if CONFIG['HAVE_64BIT_BUILD']:
         DEFINES['WIN64'] = True
     else:
         DEFINES['WIN32'] = True
 
-# When we support platforms other than Windows, we
-# will also need to define these:
-#
-#   LINUX64
-#   LINUX
-#   OSX
-#   POSIX
+if CONFIG['OS_ARCH'] == 'Darwin':
+    DEFINES['POSIX'] = True
+    DEFINES['OSX'] = True
+    if CONFIG['GNU_CXX']:
+        CXXFLAGS += ['-xobjective-c++']
+
+if CONFIG['OS_ARCH'] == 'Linux':
+    DEFINES['POSIX'] = True
+    DEFINES['LINUX'] = True
+    if CONFIG['HAVE_64BIT_BUILD']:
+        DEFINES['LINUX64'] = True
+    else:
+        DEFINES['LINUX32'] = True
 
 LOCAL_INCLUDES += [
     '/toolkit/components/jsoncpp/include',
 ]
 
 USE_LIBS += [
     'jsoncpp',
 ]
@@ -40,8 +46,14 @@ SOURCES += [
     'src/hmderrors_public.cpp',
     'src/openvr_api_public.cpp',
     'src/pathtools_public.cpp',
     'src/sharedlibtools_public.cpp',
     'src/strtools_public.cpp',
     'src/vrpathregistry_public.cpp',
 ]
 
+if CONFIG['CLANG_CXX'] or CONFIG['GNU_CXX']:
+    # Harmless warnings in 3rd party code
+    CXXFLAGS += [
+        '-Wno-error=parentheses',
+        '-Wno-error=unused-variable',
+    ]
--- a/gfx/vr/openvr/src/strtools_public.h
+++ b/gfx/vr/openvr/src/strtools_public.h
@@ -47,26 +47,28 @@ inline int strnicmp( const char *pStr1, 
 
 #define _TRUNCATE ((size_t)-1)
 
 #endif
 
 #if defined( OSX )
 // behaviors ensure NULL-termination at least as well as _TRUNCATE does, but
 // wcsncpy_s/strncpy_s can non-NULL-terminate, wcslcpy/strlcpy can not.
+/*
+// Commented out by Mozilla, please see README.mozilla
 inline errno_t wcsncpy_s(wchar_t *strDest, size_t numberOfElements, const wchar_t *strSource, size_t count)
 {
 	return wcslcpy(strDest, strSource, numberOfElements);
 }
 
 inline errno_t strncpy_s(char *strDest, size_t numberOfElements, const char *strSource, size_t count)
 {
 	return strlcpy(strDest, strSource, numberOfElements);
 }
-
+*/
 #endif
 
 #if defined( LINUX )
 // this implementation does not return whether or not the destination was 
 // truncated, but that is straightforward to fix if anybody actually needs the
 // return code. 
 #include "string.h"
 inline void wcsncpy_s(wchar_t *strDest, size_t numberOfElements, const wchar_t *strSource, size_t count)