Bug 1250244 - Part 6: Replace VRStateValidFlags with VRDisplayCapabilityFlags,r=gw280 draft
authorKearwood (Kip) Gilbert <kgilbert@mozilla.com>
Mon, 18 Apr 2016 12:12:33 -0700
changeset 398850 b0c9fbe4087485bf585fbd17098fd00bd838a3c7
parent 398849 3afd1281e17e638a7c984a724a9662073097c2d4
child 398851 70ca28a9960a4186e7c581fa31f25b8cb898ccb2
push id25655
push userkgilbert@mozilla.com
push dateTue, 09 Aug 2016 21:33:51 +0000
reviewersgw280
bugs1250244
milestone51.0a1
Bug 1250244 - Part 6: Replace VRStateValidFlags with VRDisplayCapabilityFlags,r=gw280 MozReview-Commit-ID: 2D4isWasWMz
dom/vr/VRDisplay.cpp
gfx/vr/gfxVR.h
gfx/vr/gfxVROSVR.cpp
gfx/vr/gfxVROculus.cpp
gfx/vr/ipc/VRMessageUtils.h
--- a/dom/vr/VRDisplay.cpp
+++ b/dom/vr/VRDisplay.cpp
@@ -42,20 +42,20 @@ VRDisplay::UpdateVRDisplays(nsTArray<Ref
       for (size_t j = 0; j < aDevices.Length(); j++) {
         if (aDevices[j]->GetHMD()->GetDeviceInfo() == proxyDevice->GetDeviceInfo()) {
           devices.AppendElement(aDevices[j]);
           isNewDevice = false;
         }
       }
 
       if (isNewDevice) {
-        gfx::VRStateValidFlags sensorBits = proxyDevice->GetDeviceInfo().GetSupportedSensorStateBits();
+        gfx::VRDisplayCapabilityFlags flags = proxyDevice->GetDeviceInfo().GetCapabilities();
         devices.AppendElement(new HMDInfoVRDisplay(aParent, proxyDevice));
-        if (sensorBits & (gfx::VRStateValidFlags::State_Position |
-            gfx::VRStateValidFlags::State_Orientation))
+        if (flags & (gfx::VRDisplayCapabilityFlags::Cap_Position |
+            gfx::VRDisplayCapabilityFlags::Cap_Orientation))
         {
           devices.AppendElement(new HMDPositionVRDisplay(aParent, proxyDevice));
         }
       }
     }
   }
 
   aDevices = devices;
@@ -171,21 +171,21 @@ NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(VRP
 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(VRPositionState, Release)
 
 VRPositionState::VRPositionState(nsISupports* aParent, const gfx::VRHMDSensorState& aState)
   : mParent(aParent)
   , mVRState(aState)
 {
   mTimeStamp = aState.timestamp;
 
-  if (aState.flags & gfx::VRStateValidFlags::State_Position) {
+  if (aState.flags & gfx::VRDisplayCapabilityFlags::Cap_Position) {
     mPosition = new DOMPoint(mParent, aState.position[0], aState.position[1], aState.position[2], 0.0);
   }
 
-  if (aState.flags & gfx::VRStateValidFlags::State_Orientation) {
+  if (aState.flags & gfx::VRDisplayCapabilityFlags::Cap_Orientation) {
     mOrientation = new DOMPoint(mParent, aState.orientation[0], aState.orientation[1], aState.orientation[2], aState.orientation[3]);
   }
 }
 
 DOMPoint*
 VRPositionState::GetLinearVelocity()
 {
   if (!mLinearVelocity) {
--- a/gfx/vr/gfxVR.h
+++ b/gfx/vr/gfxVR.h
@@ -26,24 +26,49 @@ class CompositingRenderTarget;
 namespace gfx {
 
 enum class VRHMDType : uint16_t {
   Oculus,
   OSVR,
   NumHMDTypes
 };
 
-enum class VRStateValidFlags : uint16_t {
-  State_None = 0,
-  State_Position = 1 << 1,
-  State_Orientation = 1 << 2,
-  // State_All used for validity checking during IPC serialization
-  State_All = (1 << 3) - 1
+enum class VRDisplayCapabilityFlags : uint16_t {
+  Cap_None = 0,
+  /**
+   * Cap_Position is set if the VRDisplay is capable of tracking its position.
+   */
+  Cap_Position = 1 << 1,
+  /**
+    * Cap_Orientation is set if the VRDisplay is capable of tracking its orientation.
+    */
+  Cap_Orientation = 1 << 2,
+  /**
+   * Cap_Present is set if the VRDisplay is capable of presenting content to an
+   * HMD or similar device.  Can be used to indicate "magic window" devices that
+   * are capable of 6DoF tracking but for which requestPresent is not meaningful.
+   * If false then calls to requestPresent should always fail, and
+   * getEyeParameters should return null.
+   */
+  Cap_Present = 1 << 3,
+  /**
+   * Cap_External is set if the VRDisplay is separate from the device's
+   * primary display. If presenting VR content will obscure
+   * other content on the device, this should be un-set. When
+   * un-set, the application should not attempt to mirror VR content
+   * or update non-VR UI because that content will not be visible.
+   */
+  Cap_External = 1 << 4,
+  /**
+   * Cap_All used for validity checking during IPC serialization
+   */
+  Cap_All = (1 << 5) - 1
 };
-MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(VRStateValidFlags)
+
+MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(VRDisplayCapabilityFlags)
 
 struct VRFieldOfView {
   VRFieldOfView() {}
   VRFieldOfView(double up, double right, double down, double left)
     : upDegrees(up), rightDegrees(right), downDegrees(down), leftDegrees(left)
   {}
 
   bool operator==(const VRFieldOfView& other) const {
@@ -88,17 +113,17 @@ struct VRDistortionConstants {
   float destinationScaleAndOffset[4];
 };
 
 struct VRDisplayInfo
 {
   VRHMDType GetType() const { return mType; }
   uint32_t GetDeviceID() const { return mDeviceID; }
   const nsCString& GetDeviceName() const { return mDeviceName; }
-  VRStateValidFlags GetSupportedSensorStateBits() const { return mSupportedSensorBits; }
+  VRDisplayCapabilityFlags GetCapabilities() const { return mCapabilityFlags; }
   const VRFieldOfView& GetRecommendedEyeFOV(uint32_t whichEye) const { return mRecommendedEyeFOV[whichEye]; }
   const VRFieldOfView& GetMaximumEyeFOV(uint32_t whichEye) const { return mMaximumEyeFOV[whichEye]; }
 
   const IntSize& SuggestedEyeResolution() const { return mEyeResolution; }
   const Point3D& GetEyeTranslation(uint32_t whichEye) const { return mEyeTranslation[whichEye]; }
   const Matrix4x4& GetEyeProjectionMatrix(uint32_t whichEye) const { return mEyeProjectionMatrix[whichEye]; }
   const VRFieldOfView& GetEyeFOV(uint32_t whichEye) const { return mEyeFOV[whichEye]; }
 
@@ -106,17 +131,17 @@ struct VRDisplayInfo
     Eye_Left,
     Eye_Right,
     NumEyes
   };
 
   uint32_t mDeviceID;
   VRHMDType mType;
   nsCString mDeviceName;
-  VRStateValidFlags mSupportedSensorBits;
+  VRDisplayCapabilityFlags mCapabilityFlags;
   VRFieldOfView mMaximumEyeFOV[VRDisplayInfo::NumEyes];
   VRFieldOfView mRecommendedEyeFOV[VRDisplayInfo::NumEyes];
   VRFieldOfView mEyeFOV[VRDisplayInfo::NumEyes];
   Point3D mEyeTranslation[VRDisplayInfo::NumEyes];
   Matrix4x4 mEyeProjectionMatrix[VRDisplayInfo::NumEyes];
   /* Suggested resolution for rendering a single eye.
    * Assumption is that left/right rendering will be 2x of this size.
    * XXX fix this for vertical displays
@@ -127,17 +152,17 @@ struct VRDisplayInfo
   bool mIsFakeScreen;
 
 
 
   bool operator==(const VRDisplayInfo& other) const {
     return mType == other.mType &&
            mDeviceID == other.mDeviceID &&
            mDeviceName == other.mDeviceName &&
-           mSupportedSensorBits == other.mSupportedSensorBits &&
+           mCapabilityFlags == other.mCapabilityFlags &&
            mEyeResolution == other.mEyeResolution &&
            mScreenRect == other.mScreenRect &&
            mIsFakeScreen == other.mIsFakeScreen &&
            mMaximumEyeFOV[0] == other.mMaximumEyeFOV[0] &&
            mMaximumEyeFOV[1] == other.mMaximumEyeFOV[1] &&
            mRecommendedEyeFOV[0] == other.mRecommendedEyeFOV[0] &&
            mRecommendedEyeFOV[1] == other.mRecommendedEyeFOV[1] &&
            mEyeFOV[0] == other.mEyeFOV[0] &&
@@ -153,17 +178,17 @@ struct VRDisplayInfo
   }
 };
 
 
 
 struct VRHMDSensorState {
   double timestamp;
   int32_t inputFrameID;
-  VRStateValidFlags flags;
+  VRDisplayCapabilityFlags flags;
   float orientation[4];
   float position[3];
   float angularVelocity[3];
   float angularAcceleration[3];
   float linearVelocity[3];
   float linearAcceleration[3];
 
   void Clear() {
--- a/gfx/vr/gfxVROSVR.cpp
+++ b/gfx/vr/gfxVROSVR.cpp
@@ -207,19 +207,22 @@ HMDInfoOSVR::HMDInfoOSVR(OSVR_ClientCont
   , m_ctx(context)
   , m_iface(iface)
   , m_display(display)
 {
 
   MOZ_COUNT_CTOR_INHERITED(HMDInfoOSVR, VRHMDInfo);
 
   mDeviceInfo.mDeviceName.AssignLiteral("OSVR HMD");
-  mDeviceInfo.mSupportedSensorBits = VRStateValidFlags::State_None;
-  mDeviceInfo.mSupportedSensorBits =
-    VRStateValidFlags::State_Orientation | VRStateValidFlags::State_Position;
+  mDeviceInfo.mCapabilityFlags = VRDisplayCapabilityFlags::Cap_None;
+  mDeviceInfo.mCapabilityFlags =
+    VRDisplayCapabilityFlags::Cap_Orientation | VRDisplayCapabilityFlags::Cap_Position;
+
+  mDeviceInfo.mCapabilityFlags |= VRDisplayCapabilityFlags::Cap_External;
+  mDeviceInfo.mCapabilityFlags |= VRDisplayCapabilityFlags::Cap_Present;
 
   // XXX OSVR display topology allows for more than one viewer
   // will assume only one viewer for now (most likely stay that way)
 
   OSVR_EyeCount numEyes;
   osvr_ClientGetNumEyesForViewer(*m_display, 0, &numEyes);
 
   for (uint8_t eye = 0; eye < numEyes; eye++) {
@@ -332,27 +335,27 @@ HMDInfoOSVR::GetSensorState()
   OSVR_OrientationState orientation;
 
   OSVR_ReturnCode ret =
     osvr_GetOrientationState(*m_iface, &timestamp, &orientation);
 
   result.timestamp = timestamp.seconds;
 
   if (ret == OSVR_RETURN_SUCCESS) {
-    result.flags |= VRStateValidFlags::State_Orientation;
+    result.flags |= VRDisplayCapabilityFlags::Cap_Orientation;
     result.orientation[0] = orientation.data[1];
     result.orientation[1] = orientation.data[2];
     result.orientation[2] = orientation.data[3];
     result.orientation[3] = orientation.data[0];
   }
 
   OSVR_PositionState position;
   ret = osvr_GetPositionState(*m_iface, &timestamp, &position);
   if (ret == OSVR_RETURN_SUCCESS) {
-    result.flags |= VRStateValidFlags::State_Position;
+    result.flags |= VRDisplayCapabilityFlags::Cap_Position;
     result.position[0] = position.data[0];
     result.position[1] = position.data[1];
     result.position[2] = position.data[2];
   }
 
   return result;
 }
 
--- a/gfx/vr/gfxVROculus.cpp
+++ b/gfx/vr/gfxVROculus.cpp
@@ -301,23 +301,25 @@ HMDInfoOculus::HMDInfoOculus(ovrSession 
              "HMDInfoOculus::DistortionVertex must match the size of VRDistortionVertex");
 
   MOZ_COUNT_CTOR_INHERITED(HMDInfoOculus, VRHMDInfo);
 
   mDeviceInfo.mDeviceName.AssignLiteral("Oculus VR HMD");
 
   mDesc = ovr_GetHmdDesc(aSession);
 
-  mDeviceInfo.mSupportedSensorBits = VRStateValidFlags::State_None;
+  mDeviceInfo.mCapabilityFlags = VRDisplayCapabilityFlags::Cap_None;
   if (mDesc.AvailableTrackingCaps & ovrTrackingCap_Orientation) {
-    mDeviceInfo.mSupportedSensorBits |= VRStateValidFlags::State_Orientation;
+    mDeviceInfo.mCapabilityFlags |= VRDisplayCapabilityFlags::Cap_Orientation;
   }
   if (mDesc.AvailableTrackingCaps & ovrTrackingCap_Position) {
-    mDeviceInfo.mSupportedSensorBits |= VRStateValidFlags::State_Position;
+    mDeviceInfo.mCapabilityFlags |= VRDisplayCapabilityFlags::Cap_Position;
   }
+  mDeviceInfo.mCapabilityFlags |= VRDisplayCapabilityFlags::Cap_External;
+  mDeviceInfo.mCapabilityFlags |= VRDisplayCapabilityFlags::Cap_Present;
 
   mDeviceInfo.mRecommendedEyeFOV[VRDisplayInfo::Eye_Left] = FromFovPort(mDesc.DefaultEyeFov[ovrEye_Left]);
   mDeviceInfo.mRecommendedEyeFOV[VRDisplayInfo::Eye_Right] = FromFovPort(mDesc.DefaultEyeFov[ovrEye_Right]);
 
   mDeviceInfo.mMaximumEyeFOV[VRDisplayInfo::Eye_Left] = FromFovPort(mDesc.MaxEyeFov[ovrEye_Left]);
   mDeviceInfo.mMaximumEyeFOV[VRDisplayInfo::Eye_Right] = FromFovPort(mDesc.MaxEyeFov[ovrEye_Right]);
 
   uint32_t w = mDesc.Resolution.w;
@@ -435,47 +437,49 @@ HMDInfoOculus::GetSensorState(double tim
   result.Clear();
 
   ovrTrackingState state = ovr_GetTrackingState(mSession, timeOffset, true);
   ovrPoseStatef& pose(state.HeadPose);
 
   result.timestamp = pose.TimeInSeconds;
 
   if (state.StatusFlags & ovrStatus_OrientationTracked) {
-    result.flags |= VRStateValidFlags::State_Orientation;
+    result.flags |= VRDisplayCapabilityFlags::Cap_Orientation;
 
     result.orientation[0] = pose.ThePose.Orientation.x;
     result.orientation[1] = pose.ThePose.Orientation.y;
     result.orientation[2] = pose.ThePose.Orientation.z;
     result.orientation[3] = pose.ThePose.Orientation.w;
     
     result.angularVelocity[0] = pose.AngularVelocity.x;
     result.angularVelocity[1] = pose.AngularVelocity.y;
     result.angularVelocity[2] = pose.AngularVelocity.z;
 
     result.angularAcceleration[0] = pose.AngularAcceleration.x;
     result.angularAcceleration[1] = pose.AngularAcceleration.y;
     result.angularAcceleration[2] = pose.AngularAcceleration.z;
   }
 
   if (state.StatusFlags & ovrStatus_PositionTracked) {
-    result.flags |= VRStateValidFlags::State_Position;
+    result.flags |= VRDisplayCapabilityFlags::Cap_Position;
 
     result.position[0] = pose.ThePose.Position.x;
     result.position[1] = pose.ThePose.Position.y;
     result.position[2] = pose.ThePose.Position.z;
     
     result.linearVelocity[0] = pose.LinearVelocity.x;
     result.linearVelocity[1] = pose.LinearVelocity.y;
     result.linearVelocity[2] = pose.LinearVelocity.z;
 
     result.linearAcceleration[0] = pose.LinearAcceleration.x;
     result.linearAcceleration[1] = pose.LinearAcceleration.y;
     result.linearAcceleration[2] = pose.LinearAcceleration.z;
   }
+  result.flags |= VRDisplayCapabilityFlags::Cap_External;
+  result.flags |= VRDisplayCapabilityFlags::Cap_Present;
   
   return result;
 }
 
 struct RenderTargetSetOculus : public VRHMDRenderingSupport::RenderTargetSet
 {
   RenderTargetSetOculus(ovrSession aSession,
                         const IntSize& aSize,
--- a/gfx/vr/ipc/VRMessageUtils.h
+++ b/gfx/vr/ipc/VRMessageUtils.h
@@ -17,19 +17,19 @@ namespace IPC {
 
 template<>
 struct ParamTraits<mozilla::gfx::VRHMDType> :
   public ContiguousEnumSerializer<mozilla::gfx::VRHMDType,
                                   mozilla::gfx::VRHMDType(0),
                                   mozilla::gfx::VRHMDType(mozilla::gfx::VRHMDType::NumHMDTypes)> {};
 
 template<>
-struct ParamTraits<mozilla::gfx::VRStateValidFlags> :
-  public BitFlagsEnumSerializer<mozilla::gfx::VRStateValidFlags,
-                                mozilla::gfx::VRStateValidFlags::State_All> {};
+struct ParamTraits<mozilla::gfx::VRDisplayCapabilityFlags> :
+  public BitFlagsEnumSerializer<mozilla::gfx::VRDisplayCapabilityFlags,
+                                mozilla::gfx::VRDisplayCapabilityFlags::Cap_All> {};
 
 template <>
 struct ParamTraits<mozilla::gfx::VRDisplayUpdate>
 {
   typedef mozilla::gfx::VRDisplayUpdate paramType;
 
   static void Write(Message* aMsg, const paramType& aParam)
   {
@@ -73,17 +73,17 @@ struct ParamTraits<mozilla::gfx::VRDispl
 {
   typedef mozilla::gfx::VRDisplayInfo paramType;
 
   static void Write(Message* aMsg, const paramType& aParam)
   {
     WriteParam(aMsg, aParam.mType);
     WriteParam(aMsg, aParam.mDeviceID);
     WriteParam(aMsg, aParam.mDeviceName);
-    WriteParam(aMsg, aParam.mSupportedSensorBits);
+    WriteParam(aMsg, aParam.mCapabilityFlags);
     WriteParam(aMsg, aParam.mEyeResolution);
     WriteParam(aMsg, aParam.mScreenRect);
     WriteParam(aMsg, aParam.mIsFakeScreen);
     for (int i = 0; i < mozilla::gfx::VRDisplayInfo::NumEyes; i++) {
       WriteParam(aMsg, aParam.mMaximumEyeFOV[i]);
       WriteParam(aMsg, aParam.mRecommendedEyeFOV[i]);
       WriteParam(aMsg, aParam.mEyeFOV[i]);
       WriteParam(aMsg, aParam.mEyeTranslation[i]);
@@ -91,17 +91,17 @@ struct ParamTraits<mozilla::gfx::VRDispl
     }
   }
 
   static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
   {
     if (!ReadParam(aMsg, aIter, &(aResult->mType)) ||
         !ReadParam(aMsg, aIter, &(aResult->mDeviceID)) ||
         !ReadParam(aMsg, aIter, &(aResult->mDeviceName)) ||
-        !ReadParam(aMsg, aIter, &(aResult->mSupportedSensorBits)) ||
+        !ReadParam(aMsg, aIter, &(aResult->mCapabilityFlags)) ||
         !ReadParam(aMsg, aIter, &(aResult->mEyeResolution)) ||
         !ReadParam(aMsg, aIter, &(aResult->mScreenRect)) ||
         !ReadParam(aMsg, aIter, &(aResult->mIsFakeScreen))) {
       return false;
     }
     for (int i = 0; i < mozilla::gfx::VRDisplayInfo::NumEyes; i++) {
       if (!ReadParam(aMsg, aIter, &(aResult->mMaximumEyeFOV[i])) ||
           !ReadParam(aMsg, aIter, &(aResult->mRecommendedEyeFOV[i])) ||