Bug 1426031 - Ensure gfxVRGVR SubmitFrame is called on the correct thread r=daoshengmu draft
authorRandall Barker <rbarker@mozilla.com>
Mon, 18 Dec 2017 17:40:47 -0800
changeset 712899 b19e52b020bbdd15bf757e59b0b39e3c6ce557f9
parent 712898 8c561020a91898d31d36beddacd1979e9010a947
child 744177 83b92178d4d04079722e2e86c2aaf631e2befdb5
push id93472
push userbmo:rbarker@mozilla.com
push dateTue, 19 Dec 2017 02:02:55 +0000
reviewersdaoshengmu
bugs1426031
milestone59.0a1
Bug 1426031 - Ensure gfxVRGVR SubmitFrame is called on the correct thread r=daoshengmu MozReview-Commit-ID: D1beQMO5n2E
gfx/vr/VRDisplayHost.cpp
--- a/gfx/vr/VRDisplayHost.cpp
+++ b/gfx/vr/VRDisplayHost.cpp
@@ -21,16 +21,21 @@
 #include "mozilla/layers/TextureD3D11.h"
 
 #elif defined(XP_MACOSX)
 
 #include "mozilla/gfx/MacIOSurface.h"
 
 #endif
 
+#if defined(MOZ_ANDROID_GOOGLE_VR)
+#include "mozilla/layers/CompositorThread.h"
+#endif // defined(MOZ_ANDROID_GOOGLE_VR)
+
+
 using namespace mozilla;
 using namespace mozilla::gfx;
 using namespace mozilla::layers;
 
 VRDisplayHost::AutoRestoreRenderState::AutoRestoreRenderState(VRDisplayHost* aDisplay)
   : mDisplay(aDisplay)
   , mSuccess(true)
 {
@@ -257,17 +262,19 @@ VRDisplayHost::NotifyVSync()
 }
 
 void
 VRDisplayHost::SubmitFrameInternal(const layers::SurfaceDescriptor &aTexture,
                                    uint64_t aFrameId,
                                    const gfx::Rect& aLeftEyeRect,
                                    const gfx::Rect& aRightEyeRect)
 {
+#if !defined(MOZ_ANDROID_GOOGLE_VR)
   MOZ_ASSERT(mSubmitThread->GetThread() == NS_GetCurrentThread());
+#endif // !defined(MOZ_ANDROID_GOOGLE_VR)
   AUTO_PROFILER_TRACING("VR", "SubmitFrameAtVRDisplayHost");
 
   mFrameStarted = false;
   switch (aTexture.type()) {
 
 #if defined(XP_WIN)
     case SurfaceDescriptor::TSurfaceDescriptorD3D10: {
       if (!CreateD3DObjects()) {
@@ -368,36 +375,43 @@ VRDisplayHost::SubmitFrameInternal(const
 
 void
 VRDisplayHost::SubmitFrame(VRLayerParent* aLayer,
                            const layers::SurfaceDescriptor &aTexture,
                            uint64_t aFrameId,
                            const gfx::Rect& aLeftEyeRect,
                            const gfx::Rect& aRightEyeRect)
 {
+#if !defined(MOZ_ANDROID_GOOGLE_VR)
   if (!mSubmitThread) {
     mSubmitThread = new VRThread(NS_LITERAL_CSTRING("VR_SubmitFrame"));
   }
+#endif // !defined(MOZ_ANDROID_GOOGLE_VR)
 
   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) {
     return;
   }
 
-  mSubmitThread->Start();
-  mSubmitThread->PostTask(
+  RefPtr<nsIRunnable> submit =
     NewRunnableMethod<StoreCopyPassByConstLRef<layers::SurfaceDescriptor>, uint64_t,
       StoreCopyPassByConstLRef<gfx::Rect>, StoreCopyPassByConstLRef<gfx::Rect>>(
       "gfx::VRDisplayHost::SubmitFrameInternal", this, &VRDisplayHost::SubmitFrameInternal,
-      aTexture, aFrameId, aLeftEyeRect, aRightEyeRect));
+      aTexture, aFrameId, aLeftEyeRect, aRightEyeRect);
+#if !defined(MOZ_ANDROID_GOOGLE_VR)
+  mSubmitThread->Start();
+  mSubmitThread->PostTask(submit.forget());
+#else
+  CompositorThreadHolder::Loop()->PostTask(submit.forget());
+#endif // defined(MOZ_ANDROID_GOOGLE_VR)
 }
 
 bool
 VRDisplayHost::CheckClearDisplayInfoDirty()
 {
   if (mDisplayInfo == mLastUpdateDisplayInfo) {
     return false;
   }