mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-25 14:57:20 +00:00
[c-host] dxgi: cleanup init code failure path
This commit is contained in:
parent
6f545483c9
commit
925a93686b
@ -134,41 +134,38 @@ static bool dxgi_init()
|
|||||||
os_signalEvent(this->copyEvent);
|
os_signalEvent(this->copyEvent);
|
||||||
|
|
||||||
HRESULT status;
|
HRESULT status;
|
||||||
IDXGIFactory1 * factory;
|
|
||||||
IDXGIAdapter1 * adapter;
|
|
||||||
IDXGIOutput * output;
|
|
||||||
DXGI_OUTPUT_DESC outputDesc;
|
DXGI_OUTPUT_DESC outputDesc;
|
||||||
|
|
||||||
status = CreateDXGIFactory1(&IID_IDXGIFactory1, (void **)&factory);
|
status = CreateDXGIFactory1(&IID_IDXGIFactory1, (void **)&this->factory);
|
||||||
if (FAILED(status))
|
if (FAILED(status))
|
||||||
{
|
{
|
||||||
DEBUG_WINERROR("Failed to create DXGIFactory1", status);
|
DEBUG_WINERROR("Failed to create DXGIFactory1", status);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 0; IDXGIFactory1_EnumAdapters1(factory, i, &adapter) != DXGI_ERROR_NOT_FOUND; ++i)
|
for(int i = 0; IDXGIFactory1_EnumAdapters1(this->factory, i, &this->adapter) != DXGI_ERROR_NOT_FOUND; ++i)
|
||||||
{
|
{
|
||||||
for(int n = 0; IDXGIAdapter1_EnumOutputs(adapter, n, &output) != DXGI_ERROR_NOT_FOUND; ++n)
|
for(int n = 0; IDXGIAdapter1_EnumOutputs(this->adapter, n, &this->output) != DXGI_ERROR_NOT_FOUND; ++n)
|
||||||
{
|
{
|
||||||
IDXGIOutput_GetDesc(output, &outputDesc);
|
IDXGIOutput_GetDesc(this->output, &outputDesc);
|
||||||
if (outputDesc.AttachedToDesktop)
|
if (outputDesc.AttachedToDesktop)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
IDXGIOutput_Release(output);
|
IDXGIOutput_Release(this->output);
|
||||||
output = NULL;
|
this->output = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (output)
|
if (this->output)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
IDXGIAdapter1_Release(adapter);
|
IDXGIAdapter1_Release(this->adapter);
|
||||||
adapter = NULL;
|
this->adapter = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!output)
|
if (!this->output)
|
||||||
{
|
{
|
||||||
DEBUG_ERROR("Failed to locate a valid output device");
|
DEBUG_ERROR("Failed to locate a valid output device");
|
||||||
goto fail_release_factory;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const D3D_FEATURE_LEVEL featureLevels[] =
|
static const D3D_FEATURE_LEVEL featureLevels[] =
|
||||||
@ -185,11 +182,11 @@ static bool dxgi_init()
|
|||||||
};
|
};
|
||||||
|
|
||||||
IDXGIAdapter * tmp;
|
IDXGIAdapter * tmp;
|
||||||
status = IDXGIAdapter1_QueryInterface(adapter, &IID_IDXGIAdapter, (void **)&tmp);
|
status = IDXGIAdapter1_QueryInterface(this->adapter, &IID_IDXGIAdapter, (void **)&tmp);
|
||||||
if (FAILED(status))
|
if (FAILED(status))
|
||||||
{
|
{
|
||||||
DEBUG_ERROR("Failed to query IDXGIAdapter interface");
|
DEBUG_ERROR("Failed to query IDXGIAdapter interface");
|
||||||
goto fail_release;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = D3D11CreateDevice(
|
status = D3D11CreateDevice(
|
||||||
@ -208,11 +205,11 @@ static bool dxgi_init()
|
|||||||
if (FAILED(status))
|
if (FAILED(status))
|
||||||
{
|
{
|
||||||
DEBUG_WINERROR("Failed to create D3D11 device", status);
|
DEBUG_WINERROR("Failed to create D3D11 device", status);
|
||||||
goto fail_release;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
DXGI_ADAPTER_DESC1 adapterDesc;
|
DXGI_ADAPTER_DESC1 adapterDesc;
|
||||||
IDXGIAdapter1_GetDesc1(adapter, &adapterDesc);
|
IDXGIAdapter1_GetDesc1(this->adapter, &adapterDesc);
|
||||||
this->width = outputDesc.DesktopCoordinates.right - outputDesc.DesktopCoordinates.left;
|
this->width = outputDesc.DesktopCoordinates.right - outputDesc.DesktopCoordinates.left;
|
||||||
this->height = outputDesc.DesktopCoordinates.bottom - outputDesc.DesktopCoordinates.top;
|
this->height = outputDesc.DesktopCoordinates.bottom - outputDesc.DesktopCoordinates.top;
|
||||||
|
|
||||||
@ -232,7 +229,7 @@ static bool dxgi_init()
|
|||||||
if (FAILED(status))
|
if (FAILED(status))
|
||||||
{
|
{
|
||||||
DEBUG_WINERROR("failed to query DXGI interface from device", status);
|
DEBUG_WINERROR("failed to query DXGI interface from device", status);
|
||||||
goto fail_release_device;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
IDXGIDevice_SetGPUThreadPriority(dxgi, 7);
|
IDXGIDevice_SetGPUThreadPriority(dxgi, 7);
|
||||||
@ -240,18 +237,18 @@ static bool dxgi_init()
|
|||||||
}
|
}
|
||||||
|
|
||||||
IDXGIOutput5 * output5 = NULL;
|
IDXGIOutput5 * output5 = NULL;
|
||||||
status = IDXGIOutput_QueryInterface(output, &IID_IDXGIOutput5, (void **)&output5);
|
status = IDXGIOutput_QueryInterface(this->output, &IID_IDXGIOutput5, (void **)&output5);
|
||||||
if (FAILED(status))
|
if (FAILED(status))
|
||||||
{
|
{
|
||||||
DEBUG_WARN("IDXGIOutput5 is not available, please update windows for improved performance!");
|
DEBUG_WARN("IDXGIOutput5 is not available, please update windows for improved performance!");
|
||||||
DEBUG_WARN("Falling back to IDXIGOutput1");
|
DEBUG_WARN("Falling back to IDXIGOutput1");
|
||||||
|
|
||||||
IDXGIOutput1 * output1 = NULL;
|
IDXGIOutput1 * output1 = NULL;
|
||||||
status = IDXGIOutput_QueryInterface(output, &IID_IDXGIOutput1, (void **)&output1);
|
status = IDXGIOutput_QueryInterface(this->output, &IID_IDXGIOutput1, (void **)&output1);
|
||||||
if (FAILED(status))
|
if (FAILED(status))
|
||||||
{
|
{
|
||||||
DEBUG_ERROR("Failed to query IDXGIOutput1 from the output");
|
DEBUG_ERROR("Failed to query IDXGIOutput1 from the output");
|
||||||
goto fail_release_device;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
// we try this twice in case we still get an error on re-initialization
|
// we try this twice in case we still get an error on re-initialization
|
||||||
@ -267,7 +264,7 @@ static bool dxgi_init()
|
|||||||
{
|
{
|
||||||
DEBUG_WINERROR("DuplicateOutput Failed", status);
|
DEBUG_WINERROR("DuplicateOutput Failed", status);
|
||||||
IDXGIOutput1_Release(output1);
|
IDXGIOutput1_Release(output1);
|
||||||
goto fail_release_device;
|
goto fail;
|
||||||
}
|
}
|
||||||
IDXGIOutput1_Release(output1);
|
IDXGIOutput1_Release(output1);
|
||||||
}
|
}
|
||||||
@ -305,7 +302,7 @@ static bool dxgi_init()
|
|||||||
{
|
{
|
||||||
DEBUG_WINERROR("DuplicateOutput1 Failed", status);
|
DEBUG_WINERROR("DuplicateOutput1 Failed", status);
|
||||||
IDXGIOutput5_Release(output5);
|
IDXGIOutput5_Release(output5);
|
||||||
goto fail_release_device;
|
goto fail;
|
||||||
}
|
}
|
||||||
IDXGIOutput5_Release(output5);
|
IDXGIOutput5_Release(output5);
|
||||||
}
|
}
|
||||||
@ -321,7 +318,7 @@ static bool dxgi_init()
|
|||||||
case DXGI_FORMAT_R10G10B10A2_UNORM: this->format = CAPTURE_FMT_RGBA10; break;
|
case DXGI_FORMAT_R10G10B10A2_UNORM: this->format = CAPTURE_FMT_RGBA10; break;
|
||||||
default:
|
default:
|
||||||
DEBUG_ERROR("Unsupported source format");
|
DEBUG_ERROR("Unsupported source format");
|
||||||
goto fail_release_output;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
D3D11_TEXTURE2D_DESC texDesc;
|
D3D11_TEXTURE2D_DESC texDesc;
|
||||||
@ -342,7 +339,7 @@ static bool dxgi_init()
|
|||||||
if (FAILED(status))
|
if (FAILED(status))
|
||||||
{
|
{
|
||||||
DEBUG_WINERROR("Failed to create texture", status);
|
DEBUG_WINERROR("Failed to create texture", status);
|
||||||
goto fail_release_output;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
// map the texture simply to get the pitch and stride
|
// map the texture simply to get the pitch and stride
|
||||||
@ -351,35 +348,17 @@ static bool dxgi_init()
|
|||||||
if (FAILED(status))
|
if (FAILED(status))
|
||||||
{
|
{
|
||||||
DEBUG_WINERROR("Failed to map the texture", status);
|
DEBUG_WINERROR("Failed to map the texture", status);
|
||||||
goto fail_release_texture;
|
goto fail;
|
||||||
}
|
}
|
||||||
this->pitch = mapping.RowPitch;
|
this->pitch = mapping.RowPitch;
|
||||||
this->stride = mapping.RowPitch / 4;
|
this->stride = mapping.RowPitch / 4;
|
||||||
ID3D11DeviceContext_Unmap(this->deviceContext, (ID3D11Resource *)this->texture, 0);
|
ID3D11DeviceContext_Unmap(this->deviceContext, (ID3D11Resource *)this->texture, 0);
|
||||||
|
|
||||||
this->factory = factory;
|
|
||||||
this->adapter = adapter;
|
|
||||||
this->output = output;
|
|
||||||
this->initialized = true;
|
this->initialized = true;
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
fail_release_texture:
|
|
||||||
ID3D11Texture2D_Release(this->texture);
|
|
||||||
this->texture = NULL;
|
|
||||||
fail_release_output:
|
|
||||||
IDXGIOutputDuplication_Release(this->dup);
|
|
||||||
this->dup = NULL;
|
|
||||||
fail_release_device:
|
|
||||||
ID3D11Device_Release (this->device );
|
|
||||||
ID3D11DeviceContext_Release(this->deviceContext);
|
|
||||||
this->device = NULL;
|
|
||||||
this->deviceContext = NULL;
|
|
||||||
fail_release:
|
|
||||||
IDXGIOutput_Release (output );
|
|
||||||
IDXGIAdapter1_Release(adapter);
|
|
||||||
fail_release_factory:
|
|
||||||
IDXGIFactory1_Release(factory);
|
|
||||||
fail:
|
fail:
|
||||||
|
dxgi_deinit();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user