Bug 1146315 - Part 1: Create D3D media device on the ImageBridge thread. r=nical

--HG--
extra : rebase_source : 29a7c9e7fb5ab2726cb9a3868b85a5c0292a38b4
This commit is contained in:
Matt Woodrow 2015-03-26 13:04:42 +13:00
parent 69645b11a3
commit a5a35423f7
2 changed files with 46 additions and 19 deletions

View File

@ -412,6 +412,7 @@ NS_IMPL_ISUPPORTS(D3D9SharedTextureReporter, nsIMemoryReporter)
gfxWindowsPlatform::gfxWindowsPlatform()
: mD3D11DeviceInitialized(false)
, mIsWARP(false)
, mCanInitMediaDevice(false)
{
mUseClearTypeForDownloadableFonts = UNINITIALIZED_VALUE;
mUseClearTypeAlways = UNINITIALIZED_VALUE;
@ -1589,11 +1590,51 @@ gfxWindowsPlatform::GetD3D11ContentDevice()
ID3D11Device*
gfxWindowsPlatform::GetD3D11MediaDevice()
{
if (mD3D11DeviceInitialized) {
if (mD3D11MediaDevice) {
return mD3D11MediaDevice;
}
InitD3D11Devices();
if (!mCanInitMediaDevice) {
return nullptr;
}
mCanInitMediaDevice = false;
nsModuleHandle d3d11Module(LoadLibrarySystem32(L"d3d11.dll"));
decltype(D3D11CreateDevice)* d3d11CreateDevice = (decltype(D3D11CreateDevice)*)
GetProcAddress(d3d11Module, "D3D11CreateDevice");
MOZ_ASSERT(d3d11CreateDevice);
nsTArray<D3D_FEATURE_LEVEL> featureLevels;
if (IsWin8OrLater()) {
featureLevels.AppendElement(D3D_FEATURE_LEVEL_11_1);
}
featureLevels.AppendElement(D3D_FEATURE_LEVEL_11_0);
featureLevels.AppendElement(D3D_FEATURE_LEVEL_10_1);
featureLevels.AppendElement(D3D_FEATURE_LEVEL_10_0);
featureLevels.AppendElement(D3D_FEATURE_LEVEL_9_3);
RefPtr<IDXGIAdapter1> adapter = GetDXGIAdapter();
MOZ_ASSERT(adapter);
HRESULT hr = E_INVALIDARG;
MOZ_SEH_TRY{
hr = d3d11CreateDevice(adapter, D3D_DRIVER_TYPE_UNKNOWN, nullptr,
D3D11_CREATE_DEVICE_BGRA_SUPPORT,
featureLevels.Elements(), featureLevels.Length(),
D3D11_SDK_VERSION, byRef(mD3D11MediaDevice), nullptr, nullptr);
} MOZ_SEH_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
mD3D11MediaDevice = nullptr;
}
d3d11Module.disown();
if (FAILED(hr)) {
return nullptr;
}
mD3D11MediaDevice->SetExceptionMode(0);
return mD3D11MediaDevice;
}
@ -1959,23 +2000,8 @@ gfxWindowsPlatform::InitD3D11Devices()
Factory::SetDirect3D11Device(mD3D11ContentDevice);
}
if (!useWARP || gfxPrefs::LayersD3D11ForceWARP()) {
hr = E_INVALIDARG;
MOZ_SEH_TRY{
hr = d3d11CreateDevice(adapter, useWARP ? D3D_DRIVER_TYPE_WARP : D3D_DRIVER_TYPE_UNKNOWN, nullptr,
D3D11_CREATE_DEVICE_BGRA_SUPPORT,
featureLevels.Elements(), featureLevels.Length(),
D3D11_SDK_VERSION, byRef(mD3D11MediaDevice), nullptr, nullptr);
} MOZ_SEH_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
mD3D11MediaDevice = nullptr;
}
if (FAILED(hr)) {
d3d11Module.disown();
return;
}
mD3D11MediaDevice->SetExceptionMode(0);
if (!useWARP) {
mCanInitMediaDevice = true;
}
// We leak these everywhere and we need them our entire runtime anyway, let's

View File

@ -296,6 +296,7 @@ private:
bool mD3D11DeviceInitialized;
mozilla::RefPtr<mozilla::layers::ReadbackManagerD3D11> mD3D11ReadbackManager;
bool mIsWARP;
bool mCanInitMediaDevice;
virtual void GetPlatformCMSOutputProfile(void* &mem, size_t &size);
};