Remove D3D11Status flag in favor of FeatureStatus. (bug 1183910 part 3, r=mattwoodrow)

This commit is contained in:
David Anderson 2015-07-30 00:24:56 -07:00
parent 2c86262106
commit e031558cd1
4 changed files with 47 additions and 42 deletions

View File

@ -32,5 +32,12 @@ FeatureStatusToString(FeatureStatus aStatus)
}
}
bool
IsFeatureStatusFailure(FeatureStatus aStatus)
{
return aStatus != FeatureStatus::Unused &&
aStatus != FeatureStatus::Available;
}
} // namespace gfx
} // namespace mozilla

View File

@ -39,6 +39,7 @@ enum class FeatureStatus
};
const char* FeatureStatusToString(FeatureStatus aStatus);
bool IsFeatureStatusFailure(FeatureStatus aStatus);
} // namespace gfx
} // namespace mozilla

View File

@ -1911,35 +1911,40 @@ CanUseWARP()
return true;
}
auto
gfxWindowsPlatform::CheckD3D11Support() -> D3D11Status
FeatureStatus
gfxWindowsPlatform::CheckD3D11Support(bool* aCanUseHardware)
{
if (gfxPrefs::LayersD3D11ForceWARP()) {
return D3D11Status::OnlyWARP;
*aCanUseHardware = false;
return FeatureStatus::Available;
}
if (nsCOMPtr<nsIGfxInfo> gfxInfo = services::GetGfxInfo()) {
int32_t status;
if (NS_SUCCEEDED(gfxInfo->GetFeatureStatus(nsIGfxInfo::FEATURE_DIRECT3D_11_LAYERS, &status))) {
if (status != nsIGfxInfo::FEATURE_STATUS_OK) {
if (!CanUseWARP()) {
return D3D11Status::Blocked;
if (CanUseWARP()) {
*aCanUseHardware = false;
return FeatureStatus::Available;
}
return D3D11Status::OnlyWARP;
return FeatureStatus::Blacklisted;
}
}
}
if (!GetDXGIAdapter()) {
return D3D11Status::OnlyWARP;
// If we've used WARP once, we continue to use it after device resets.
if (!GetDXGIAdapter() || mIsWARP) {
*aCanUseHardware = false;
}
return D3D11Status::Ok;
return FeatureStatus::Available;
}
// We don't have access to the D3D11CreateDevice type in gfxWindowsPlatform.h,
// since it doesn't include d3d11.h, so we use a static here. It should only
// be used within InitD3D11Devices.
// be used within InitializeD3D11.
decltype(D3D11CreateDevice)* sD3D11CreateDeviceFn = nullptr;
bool
void
gfxWindowsPlatform::AttemptD3D11DeviceCreation()
{
RefPtr<IDXGIAdapter1> adapter = GetDXGIAdapter();
@ -1957,15 +1962,15 @@ gfxWindowsPlatform::AttemptD3D11DeviceCreation()
D3D11_SDK_VERSION, byRef(mD3D11Device), nullptr, nullptr);
} MOZ_SEH_EXCEPT (EXCEPTION_EXECUTE_HANDLER) {
gfxCriticalError() << "Crash during D3D11 device creation";
return false;
return;
}
if (FAILED(hr) || !DoesD3D11DeviceWork(mD3D11Device)) {
gfxCriticalError() << "D3D11 device creation failed" << hexa(hr);
return false;
return;
}
if (!mD3D11Device) {
return false;
return;
}
CheckIfRenderTargetViewNeedsRecreating(mD3D11Device);
@ -1975,10 +1980,9 @@ gfxWindowsPlatform::AttemptD3D11DeviceCreation()
mDoesD3D11TextureSharingWork = ::DoesD3D11TextureSharingWork(mD3D11Device);
mD3D11Device->SetExceptionMode(0);
mIsWARP = false;
return true;
}
bool
void
gfxWindowsPlatform::AttemptWARPDeviceCreation()
{
ScopedGfxFeatureReporter reporterWARP("D3D11-WARP", gfxPrefs::LayersD3D11ForceWARP());
@ -1996,13 +2000,13 @@ gfxWindowsPlatform::AttemptWARPDeviceCreation()
if (FAILED(hr)) {
// This should always succeed... in theory.
gfxCriticalError() << "Failed to initialize WARP D3D11 device! " << hexa(hr);
return false;
return;
}
reporterWARP.SetSuccessful();
} MOZ_SEH_EXCEPT (EXCEPTION_EXECUTE_HANDLER) {
gfxCriticalError() << "Exception occurred initializing WARP D3D11 device!";
return false;
return;
}
@ -2013,7 +2017,6 @@ gfxWindowsPlatform::AttemptWARPDeviceCreation()
}
mD3D11Device->SetExceptionMode(0);
mIsWARP = true;
return true;
}
bool
@ -2046,7 +2049,7 @@ gfxWindowsPlatform::AttemptD3D11ContentDeviceCreation()
return true;
}
bool
void
gfxWindowsPlatform::AttemptD3D11ImageBridgeDeviceCreation()
{
HRESULT hr = E_INVALIDARG;
@ -2057,19 +2060,18 @@ gfxWindowsPlatform::AttemptD3D11ImageBridgeDeviceCreation()
mFeatureLevels.Elements(), mFeatureLevels.Length(),
D3D11_SDK_VERSION, byRef(mD3D11ImageBridgeDevice), nullptr, nullptr);
} MOZ_SEH_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
return false;
return;
}
if (FAILED(hr)) {
return false;
return;
}
mD3D11ImageBridgeDevice->SetExceptionMode(0);
if (!DoesD3D11AlphaTextureSharingWork(mD3D11ImageBridgeDevice)) {
mD3D11ImageBridgeDevice = nullptr;
return false;
return;
}
return true;
}
void
@ -2117,9 +2119,9 @@ gfxWindowsPlatform::InitializeD3D11()
// a WARP device which should always be available on Windows 7 and higher.
// Check if D3D11 is supported on this hardware.
D3D11Status support = CheckD3D11Support();
if (support == D3D11Status::Blocked) {
mD3D11Status = FeatureStatus::Blacklisted;
bool canUseHardware = true;
mD3D11Status = CheckD3D11Support(&canUseHardware);
if (IsFeatureStatusFailure(mD3D11Status)) {
return;
}
@ -2133,12 +2135,13 @@ gfxWindowsPlatform::InitializeD3D11()
return;
}
// If hardware acceleration is allowed, attempt to create a device. If this
// fails, we fall back to WARP.
if (support == D3D11Status::Ok && !AttemptD3D11DeviceCreation()) {
support = D3D11Status::OnlyWARP;
// First try to create a hardware accelerated device.
if (canUseHardware) {
AttemptD3D11DeviceCreation();
}
if (support == D3D11Status::OnlyWARP && CanUseWARP()) {
// If that failed, see if we can use WARP.
if (!mD3D11Device && CanUseWARP()) {
AttemptWARPDeviceCreation();
}

View File

@ -307,16 +307,10 @@ private:
void DisableD2D();
// Used by InitializeD3D11().
enum class D3D11Status {
Ok,
OnlyWARP,
Blocked
};
D3D11Status CheckD3D11Support();
bool AttemptD3D11DeviceCreation();
bool AttemptWARPDeviceCreation();
bool AttemptD3D11ImageBridgeDeviceCreation();
mozilla::gfx::FeatureStatus CheckD3D11Support(bool* aCanUseHardware);
void AttemptD3D11DeviceCreation();
void AttemptWARPDeviceCreation();
void AttemptD3D11ImageBridgeDeviceCreation();
bool AttemptD3D11ContentDeviceCreation();
IDXGIAdapter1 *GetDXGIAdapter();