Bug 1426031 - Ensure gfxVRGVR SubmitFrame is called on the correct thread r=daoshengmu
MozReview-Commit-ID: D1beQMO5n2E
--- 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;
}