Don't gfxDevCrash when video fails to acquire a SyncObject. (bug 1345735 part 2, r=mattwoodrow)
authorDavid Anderson <dvander@alliedmods.net>
Wed, 19 Apr 2017 07:24:44 -0700
changeset 565184 7c5628d40478bf50c4054acb5eb67871fa7168d5
parent 565183 d6348ea45c2db438ba01ecdcf3da981026f5ba4c
child 565185 336b737be49aed46ef67c6b2e54bc066b1abf934
push id54802
push userdgottwald@mozilla.com
push dateWed, 19 Apr 2017 15:26:27 +0000
reviewersmattwoodrow
bugs1345735
milestone55.0a1
Don't gfxDevCrash when video fails to acquire a SyncObject. (bug 1345735 part 2, r=mattwoodrow)
gfx/layers/d3d11/TextureD3D11.cpp
--- a/gfx/layers/d3d11/TextureD3D11.cpp
+++ b/gfx/layers/d3d11/TextureD3D11.cpp
@@ -1215,36 +1215,48 @@ SyncObjectD3D11::SyncObjectD3D11(SyncHan
   if (!aDevice) {
     mD3D11Device = DeviceManagerDx::Get()->GetContentDevice();
     return;
   }
 
   mD3D11Device = aDevice;
 }
 
+static inline bool
+ShouldDevCrashOnSyncInitFailure()
+{
+  // Compositor shutdown does not wait for video decoding to finish, so it is
+  // possible for the compositor to destroy the SyncObject before video has a
+  // chance to initialize it.
+  if (!NS_IsMainThread()) {
+    return false;
+  }
+
+  // Note: CompositorIsInGPUProcess is a main-thread-only function.
+  return !CompositorBridgeChild::CompositorIsInGPUProcess() &&
+         !DeviceManagerDx::Get()->HasDeviceReset();
+}
+
 bool
 SyncObjectD3D11::Init()
 {
   if (mKeyedMutex) {
     return true;
   }
 
   HRESULT hr = mD3D11Device->OpenSharedResource(
     mSyncHandle,
     __uuidof(ID3D11Texture2D),
     (void**)(ID3D11Texture2D**)getter_AddRefs(mD3D11Texture));
   if (FAILED(hr) || !mD3D11Texture) {
     gfxCriticalNote << "Failed to OpenSharedResource for SyncObjectD3D11: " << hexa(hr);
-    if (!CompositorBridgeChild::CompositorIsInGPUProcess() &&
-        !DeviceManagerDx::Get()->HasDeviceReset())
-    {
+    if (ShouldDevCrashOnSyncInitFailure()) {
       gfxDevCrash(LogReason::D3D11FinalizeFrame) << "Without device reset: " << hexa(hr);
-    } else {
-      return false;
     }
+    return false;
   }
 
   hr = mD3D11Texture->QueryInterface(__uuidof(IDXGIKeyedMutex), getter_AddRefs(mKeyedMutex));
   if (FAILED(hr) || !mKeyedMutex) {
     // Leave both the critical error and MOZ_CRASH for now; the critical error lets
     // us "save" the hr value.  We will probably eventuall replace this with gfxDevCrash.
     gfxCriticalError() << "Failed to get KeyedMutex (2): " << hexa(hr);
     MOZ_CRASH("GFX: Cannot get D3D11 KeyedMutex");