Bug 1392216 - Part 3: VRPuppet dispatch submit frame result to VRListener thread; r?kip draft
authorDaosheng Mu <daoshengmu@gmail.com>
Fri, 06 Oct 2017 10:38:17 +0000
changeset 676189 9b1b74c6c6ff214a81797d1afa24d9e8fde212c2
parent 676188 fdbdcfe5613beb54e64f6d10a278f2c56bcb6918
child 734871 dee7721e7813d02a0cdd65935595408ec79a2797
push id83418
push userbmo:dmu@mozilla.com
push dateFri, 06 Oct 2017 20:10:44 +0000
reviewerskip
bugs1392216
milestone58.0a1
Bug 1392216 - Part 3: VRPuppet dispatch submit frame result to VRListener thread; r?kip MozReview-Commit-ID: IihJVXxDxT2
gfx/vr/VRDisplayHost.cpp
gfx/vr/gfxVRPuppet.cpp
gfx/vr/ipc/VRLayerParent.cpp
--- a/gfx/vr/VRDisplayHost.cpp
+++ b/gfx/vr/VRDisplayHost.cpp
@@ -266,16 +266,19 @@ VRDisplayHost::SubmitFrame(VRLayerParent
 
   if ((mDisplayInfo.mGroupMask & aLayer->GetGroup()) == 0) {
     // Suppress layers hidden by the group mask
     return;
   }
 
   // Ensure that we only accept the first SubmitFrame call per RAF cycle.
   if (!mFrameStarted || aFrameId != mDisplayInfo.mFrameId) {
+    // Reset frameId when mDisplayInfo.mFrameId updates too many times
+    // in VR threads.
+    mDisplayInfo.mFrameId = aFrameId;
     return;
   }
   mFrameStarted = false;
 
   switch (aTexture.type()) {
 
 #if defined(XP_WIN)
     case SurfaceDescriptor::TSurfaceDescriptorD3D10: {
--- a/gfx/vr/gfxVRPuppet.cpp
+++ b/gfx/vr/gfxVRPuppet.cpp
@@ -12,16 +12,17 @@
 #endif
 
 #include "mozilla/Base64.h"
 #include "mozilla/gfx/DataSurfaceHelpers.h"
 #include "gfxPrefs.h"
 #include "gfxUtils.h"
 #include "gfxVRPuppet.h"
 #include "VRManager.h"
+#include "VRThread.h"
 
 #include "mozilla/dom/GamepadEventTypes.h"
 #include "mozilla/dom/GamepadBinding.h"
 
 // See CompositorD3D11Shaders.h
 namespace mozilla {
 namespace layers {
 struct ShaderBytes { const void* mData; size_t mLength; };
@@ -372,17 +373,21 @@ VRDisplayPuppet::SubmitFrame(ID3D11Textu
       nsCString rawString(Substring(srcData, mapInfo.RowPitch * desc.Height));
 
       if (Base64Encode(rawString, result.mBase64Image) != NS_OK) {
         MOZ_ASSERT(false, "Failed to encode base64 images.");
       }
       mContext->Unmap(mappedTexture, 0);
       // Dispatch the base64 encoded string to the DOM side. Then, it will be decoded
       // and convert to a PNG image there.
-      vm->DispatchSubmitFrameResult(mDisplayInfo.mDisplayID, result);
+      MessageLoop* loop = VRListenerThreadHolder::Loop();
+      loop->PostTask(NewRunnableMethod<const uint32_t, VRSubmitFrameResultInfo>(
+        "VRManager::DispatchSubmitFrameResult",
+        vm, &VRManager::DispatchSubmitFrameResult, mDisplayInfo.mDisplayID, result
+      ));
       break;
     }
     case 2:
     {
       // The VR compositor sumbmit frame to the screen window,
       // the current coordinate is at (0, 0, width, height).
       Matrix viewMatrix = Matrix::Translation(-1.0, 1.0);
       viewMatrix.PreScale(2.0f / float(aSize.width), 2.0f / float(aSize.height));
@@ -513,17 +518,21 @@ VRDisplayPuppet::SubmitFrame(MacIOSurfac
         }
         dataSurf->Unmap();
 
         if (Base64Encode(rawString, result.mBase64Image) != NS_OK) {
           MOZ_ASSERT(false, "Failed to encode base64 images.");
         }
         // Dispatch the base64 encoded string to the DOM side. Then, it will be decoded
         // and convert to a PNG image there.
-        vm->DispatchSubmitFrameResult(mDisplayInfo.mDisplayID, result);
+        MessageLoop* loop = VRListenerThreadHolder::Loop();
+        loop->PostTask(NewRunnableMethod<const uint32_t, VRSubmitFrameResultInfo>(
+          "VRManager::DispatchSubmitFrameResult",
+          vm, &VRManager::DispatchSubmitFrameResult, mDisplayInfo.mDisplayID, result
+        ));
       }
       break;
     }
     case 2:
     {
       MOZ_ASSERT(false, "No support for showing VR frames on MacOSX yet.");
       break;
     }
--- a/gfx/vr/ipc/VRLayerParent.cpp
+++ b/gfx/vr/ipc/VRLayerParent.cpp
@@ -66,17 +66,17 @@ VRLayerParent::RecvSubmitFrame(const lay
   if (mVRDisplayID) {
     MessageLoop* loop = layers::CompositorThreadHolder::Loop();
     VRManager* vm = VRManager::Get();
     RefPtr<VRDisplayHost> display = vm->GetDisplay(mVRDisplayID);
     if (display) {
       // Because VR compositor still shares the same graphics device with Compositor thread.
       // We have to post sumbit frame tasks to Compositor thread.
       // TODO: Move SubmitFrame to Bug 1392217.
-      loop->PostTask(NewRunnableMethod<VRDisplayHost*, const layers::SurfaceDescriptor&, uint64_t,
+      loop->PostTask(NewRunnableMethod<VRDisplayHost*, const layers::SurfaceDescriptor, uint64_t,
                                        const gfx::Rect&, const gfx::Rect&>(
                      "gfx::VRLayerParent::SubmitFrame",
                      this,
                      &VRLayerParent::SubmitFrame, display, aTexture, aFrameId, aLeftEyeRect, aRightEyeRect));
     }
   }
 
   return IPC_OK();