Bug 1407423 - Part 2: Update gfxVRGVR to match refactoring draft
authorKearwood "Kip" Gilbert <kgilbert@mozilla.com>
Tue, 14 Nov 2017 10:42:46 -0800
changeset 702164 0c606b5a0874dcd12fe25e859e9359a09c5b0f75
parent 702163 b146f885959829239818c7f3fca1696c8fa61da8
child 702165 6003d0c76c675aed32b2ac65ca8f9b49550ba589
push id90406
push userkgilbert@mozilla.com
push dateWed, 22 Nov 2017 21:05:43 +0000
bugs1407423
milestone59.0a1
Bug 1407423 - Part 2: Update gfxVRGVR to match refactoring MozReview-Commit-ID: DmKnEZanQ3f
gfx/vr/gfxVRGVR.cpp
gfx/vr/gfxVRGVR.h
--- a/gfx/vr/gfxVRGVR.cpp
+++ b/gfx/vr/gfxVRGVR.cpp
@@ -335,22 +335,16 @@ VRDisplayGVR::SubmitFrame(const mozilla:
     GVR_LOG("Unable to submit frame. Unable to extract EGLImage");
     return false;
   }
   GVR_CHECK(gvr_frame_unbind(frame));
   GVR_CHECK(gvr_frame_submit(&frame, mViewportList, mHeadMatrix));
   return true;
 }
 
-void
-VRDisplayGVR::NotifyVSync()
-{
-  VRDisplayHost::NotifyVSync();
-}
-
 static void
 FillMatrix(gfx::Matrix4x4 &target, const gvr_mat4f& source)
 {
   target._11 = source.m[0][0];
   target._12 = source.m[0][1];
   target._13 = source.m[0][2];
   target._14 = source.m[0][3];
   target._21 = source.m[1][0];
@@ -707,29 +701,50 @@ VRSystemManagerGVR::Destroy()
 }
 
 void
 VRSystemManagerGVR::Shutdown()
 {
 
 }
 
-bool
-VRSystemManagerGVR::GetHMDs(nsTArray<RefPtr<VRDisplayHost> >& aHMDResult)
+void
+VRSystemManagerGVR::Enumerate()
 {
   if (!GeckoVRManager::IsGVRPresent()) {
-    return false;
+    return;
   }
 
   if (!mGVRHMD) {
     mGVRHMD = new VRDisplayGVR();
   }
+}
 
-  aHMDResult.AppendElement(mGVRHMD);
-  return true;
+bool
+VRSystemManagerGVR::ShouldInhibitEnumeration()
+{
+  if (VRSystemManager::ShouldInhibitEnumeration()) {
+    return true;
+  }
+  if (mGVRHMD) {
+    // When we find an a VR device, don't
+    // allow any further enumeration as it
+    // may get picked up redundantly by other
+    // API's.
+    return true;
+  }
+  return false;
+}
+
+void
+VRSystemManagerGVR::GetHMDs(nsTArray<RefPtr<VRDisplayHost>>& aHMDResult)
+{
+  if (mGVRHMD) {
+    aHMDResult.AppendElement(mGVRHMD);
+  }
 }
 
 bool
 VRSystemManagerGVR::GetIsPresenting()
 {
   if (!mGVRHMD) {
     return false;
   }
--- a/gfx/vr/gfxVRGVR.h
+++ b/gfx/vr/gfxVRGVR.h
@@ -55,17 +55,16 @@ public:
 
   // BEGIN VRDisplayHost interface
   void ZeroSensor() override;
   void StartPresentation() override;
   void StopPresentation() override;
   bool SubmitFrame(const mozilla::layers::EGLImageDescriptor* aDescriptor,
                    const gfx::Rect& aLeftEyeRect,
                    const gfx::Rect& aRightEyeRect) override;
-  void NotifyVSync() override;
 protected:
   virtual VRHMDSensorState GetSensorState() override;
   // END VRDisplayHost interface
 
 public:
   void SetPaused(const bool aPaused);
   void SetPresentingContext(void* aGVRPresentingContext);
   void EnableControllers(const bool aEnable, VRSystemManager* aManager);
@@ -100,17 +99,19 @@ protected:
 
 class VRSystemManagerGVR : public VRSystemManager
 {
 public:
   static already_AddRefed<VRSystemManagerGVR> Create();
 
   void Destroy() override;
   void Shutdown() override;
-  bool GetHMDs(nsTArray<RefPtr<VRDisplayHost> >& aHMDResult) override;
+  void Enumerate() override;
+  bool ShouldInhibitEnumeration() override;
+  void GetHMDs(nsTArray<RefPtr<VRDisplayHost>>& aHMDResult) override;
   bool GetIsPresenting() override;
   void HandleInput() override;
   void GetControllers(nsTArray<RefPtr<VRControllerHost>>&
                       aControllerResult) override;
   void ScanForControllers() override;
   void RemoveControllers() override;
   void VibrateHaptic(uint32_t aControllerIdx,
                      uint32_t aHapticIndex,