Bug 1291084: Unconditionally create all devices as threadsafe. r=mattwoodrow draft
authorBas Schouten <bschouten@mozilla.com>
Tue, 04 Oct 2016 20:33:47 +0200
changeset 420801 c141aec05d513825b1a57cc8ae325b508be7357e
parent 420009 4f435a5a9ad06c507d79637bcd336cf7f9d3f955
child 532899 6701d3acc0141cc72f96469cd8937b8442889620
push id31301
push userbschouten@mozilla.com
push dateTue, 04 Oct 2016 18:34:23 +0000
reviewersmattwoodrow
bugs1291084
milestone52.0a1
Bug 1291084: Unconditionally create all devices as threadsafe. r=mattwoodrow MozReview-Commit-ID: GWJWd7oXoOb
gfx/thebes/DeviceManagerDx.cpp
--- a/gfx/thebes/DeviceManagerDx.cpp
+++ b/gfx/thebes/DeviceManagerDx.cpp
@@ -12,16 +12,17 @@
 #include "mozilla/D3DMessageUtils.h"
 #include "mozilla/Telemetry.h"
 #include "mozilla/WindowsVersion.h"
 #include "mozilla/gfx/GraphicsMessages.h"
 #include "mozilla/gfx/Logging.h"
 #include "mozilla/layers/CompositorThread.h"
 #include "nsIGfxInfo.h"
 #include <d3d11.h>
+#include <d3d11_4.h>
 #include <ddraw.h>
 
 namespace mozilla {
 namespace gfx {
 
 using namespace mozilla::widget;
 
 StaticAutoPtr<DeviceManagerDx> DeviceManagerDx::sInstance;
@@ -369,19 +370,29 @@ DeviceManagerDx::CreateDevice(IDXGIAdapt
                                  RefPtr<ID3D11Device>& aOutDevice)
 {
   MOZ_SEH_TRY {
     aResOut = sD3D11CreateDeviceFn(
       aAdapter, aDriverType, nullptr,
       aFlags,
       mFeatureLevels.Elements(), mFeatureLevels.Length(),
       D3D11_SDK_VERSION, getter_AddRefs(aOutDevice), nullptr, nullptr);
+
   } MOZ_SEH_EXCEPT (EXCEPTION_EXECUTE_HANDLER) {
     return false;
   }
+
+  RefPtr<ID3D10Multithread> mt;
+  HRESULT hr = aOutDevice->QueryInterface((ID3D10Multithread**)getter_AddRefs(mt));
+  if (SUCCEEDED(hr) && mt) {
+    mt->SetMultithreadProtected(TRUE);
+  } else {
+    gfxCriticalError() << "Failed to set device safe for multithreading.";
+  }
+
   return true;
 }
 
 void
 DeviceManagerDx::CreateWARPCompositorDevice()
 {
   ScopedGfxFeatureReporter reporterWARP("D3D11-WARP", gfxPrefs::LayersD3D11ForceWARP());
   FeatureState& d3d11 = gfxConfig::GetFeature(Feature::D3D11_COMPOSITING);
@@ -478,35 +489,24 @@ DeviceManagerDx::CreateContentDevice()
   }
 
   {
     MutexAutoLock lock(mDeviceLock);
     mContentDevice = device;
   }
   mContentDevice->SetExceptionMode(0);
 
-  RefPtr<ID3D10Multithread> multi;
-  hr = mContentDevice->QueryInterface(__uuidof(ID3D10Multithread), getter_AddRefs(multi));
-  if (SUCCEEDED(hr) && multi) {
-    multi->SetMultithreadProtected(TRUE);
-  }
   return FeatureStatus::Available;
 }
 
 RefPtr<ID3D11Device>
 DeviceManagerDx::CreateDecoderDevice()
 {
   if (mCompositorDevice && mCompositorDeviceSupportsVideo && !mDecoderDevice) {
     mDecoderDevice = mCompositorDevice;
-
-    RefPtr<ID3D10Multithread> multi;
-    mDecoderDevice->QueryInterface(__uuidof(ID3D10Multithread), getter_AddRefs(multi));
-    if (multi) {
-      multi->SetMultithreadProtected(TRUE);
-    }
   }
 
   if (mDecoderDevice) {
     RefPtr<ID3D11Device> dev = mDecoderDevice;
     return dev.forget();
   }
 
    if (!sD3D11CreateDeviceFn) {
@@ -526,21 +526,16 @@ DeviceManagerDx::CreateDecoderDevice()
                D3D11_CREATE_DEVICE_VIDEO_SUPPORT;
   if (!CreateDevice(adapter, D3D_DRIVER_TYPE_UNKNOWN, flags, hr, device)) {
     return nullptr;
   }
   if (FAILED(hr) || !device || !D3D11Checks::DoesDeviceWork()) {
     return nullptr;
   }
 
-  RefPtr<ID3D10Multithread> multi;
-  device->QueryInterface(__uuidof(ID3D10Multithread), getter_AddRefs(multi));
-
-  multi->SetMultithreadProtected(TRUE);
-
   mDecoderDevice = device;
   return device;
 }
 
 void
 DeviceManagerDx::ResetDevices()
 {
   MutexAutoLock lock(mDeviceLock);