static void test_parents(IDXGIDevice *device) { DXGI_SURFACE_DESC surface_desc; IDXGISurface *surface; IDXGIFactory *factory; IDXGIAdapter *adapter; IDXGIOutput *output; IUnknown *parent; HRESULT hr; surface_desc.Width = 512; surface_desc.Height = 512; surface_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; surface_desc.SampleDesc.Count = 1; surface_desc.SampleDesc.Quality = 0; hr = IDXGIDevice_CreateSurface(device, &surface_desc, 1, DXGI_USAGE_RENDER_TARGET_OUTPUT, NULL, &surface); ok(SUCCEEDED(hr), "Failed to create a dxgi surface, hr %#x\n", hr); hr = IDXGISurface_GetParent(surface, &IID_IDXGIDevice, (void **)&parent); IDXGISurface_Release(surface); ok(SUCCEEDED(hr), "GetParent failed, hr %#x.\n", hr); ok(parent == (IUnknown *)device, "Got parent %p, expected %p.\n", parent, device); IUnknown_Release(parent); hr = IDXGIDevice_GetAdapter(device, &adapter); ok(SUCCEEDED(hr), "GetAdapter failed, hr %#x.\n", hr); hr = IDXGIAdapter_EnumOutputs(adapter, 0, &output); if (hr == DXGI_ERROR_NOT_FOUND) { skip("Adapter has not outputs, skipping output tests.\n"); } else { ok(SUCCEEDED(hr), "EnumOutputs failed, hr %#x.\n", hr); hr = IDXGIOutput_GetParent(output, &IID_IDXGIAdapter, (void **)&parent); IDXGIOutput_Release(output); ok(SUCCEEDED(hr), "GetParent failed, hr %#x.\n", hr); ok(parent == (IUnknown *)adapter, "Got parent %p, expected %p.\n", parent, adapter); IUnknown_Release(parent); } hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory); ok(SUCCEEDED(hr), "GetParent failed, hr %#x.\n", hr); hr = IDXGIFactory_GetParent(factory, &IID_IUnknown, (void **)&parent); ok(hr == E_NOINTERFACE, "GetParent returned %#x, expected %#x.\n", hr, E_NOINTERFACE); ok(parent == NULL, "Got parent %p, expected %p.\n", parent, NULL); IDXGIFactory_Release(factory); hr = IDXGIDevice_GetParent(device, &IID_IDXGIAdapter, (void **)&parent); ok(SUCCEEDED(hr), "GetParent failed, hr %#x.\n", hr); ok(parent == (IUnknown *)adapter, "Got parent %p, expected %p.\n", parent, adapter); IUnknown_Release(parent); IDXGIAdapter_Release(adapter); }
void SDL_DXGIGetOutputInfo( int displayIndex, int *adapterIndex, int *outputIndex ) { void *pDXGIDLL; IDXGIFactory *pDXGIFactory; *adapterIndex = -1; *outputIndex = -1; if (!DXGI_LoadDLL(&pDXGIDLL, &pDXGIFactory)) { SDL_SetError("Unable to create DXGI interface"); } else { SDL_DisplayData *pData = (SDL_DisplayData *)SDL_GetDisplayDriverData(displayIndex); if (!pData) { SDL_SetError("Invalid display index"); } else { char *displayName = WIN_StringToUTF8(pData->DeviceName); int nAdapter = 0, nOutput = 0; IDXGIAdapter* pDXGIAdapter; while ( *adapterIndex == -1 && IDXGIFactory_EnumAdapters(pDXGIFactory, nAdapter, &pDXGIAdapter) != DXGI_ERROR_NOT_FOUND ) { IDXGIOutput* pDXGIOutput; while ( *adapterIndex == -1 && IDXGIAdapter_EnumOutputs(pDXGIAdapter, nOutput, &pDXGIOutput) != DXGI_ERROR_NOT_FOUND ) { DXGI_OUTPUT_DESC outputDesc; if (SUCCEEDED(IDXGIOutput_GetDesc(pDXGIOutput, &outputDesc))) { char *outputName = WIN_StringToUTF8(outputDesc.DeviceName); if(!SDL_strcmp(outputName, displayName)) { *adapterIndex = nAdapter; *outputIndex = nOutput; } SDL_free( outputName ); } IDXGIOutput_Release( pDXGIOutput ); nOutput++; } IDXGIAdapter_Release( pDXGIAdapter ); nAdapter++; } SDL_free(displayName); } /* free up the D3D stuff we inited */ IDXGIFactory_AddRef( pDXGIFactory ); SDL_UnloadObject(pDXGIDLL); } }
static void test_output(IDXGIDevice *device) { IDXGIAdapter *adapter; HRESULT hr; IDXGIOutput *output; UINT mode_count, mode_count_comp, i; DXGI_MODE_DESC *modes; hr = IDXGIDevice_GetAdapter(device, &adapter); ok(SUCCEEDED(hr), "GetAdapter failed, hr %#x.\n", hr); hr = IDXGIAdapter_EnumOutputs(adapter, 0, &output); if (hr == DXGI_ERROR_NOT_FOUND) { skip("Adapter has not outputs, skipping output tests.\n"); IDXGIAdapter_Release(adapter); return; } ok(SUCCEEDED(hr), "EnumOutputs failed, hr %#x.\n", hr); IDXGIOutput_GetDisplayModeList(output, DXGI_FORMAT_R8G8B8A8_UNORM, 0, NULL, NULL); ok(SUCCEEDED(hr), "Failed to list modes, hr %#x.\n", hr); IDXGIOutput_GetDisplayModeList(output, DXGI_FORMAT_R8G8B8A8_UNORM, 0, &mode_count, NULL); ok(SUCCEEDED(hr), "Failed to list modes, hr %#x.\n", hr); mode_count_comp = mode_count; IDXGIOutput_GetDisplayModeList(output, 0, 0, &mode_count, NULL); ok(SUCCEEDED(hr), "Failed to list modes, hr %#x.\n", hr); ok(!mode_count, "Expected 0 got %d\n", mode_count); IDXGIOutput_GetDisplayModeList(output, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_SCALING, &mode_count, NULL); ok(SUCCEEDED(hr), "Failed to list modes, hr %#x.\n", hr); ok(mode_count >= mode_count_comp, "Flag implies trying to enumerate more modes\n"); mode_count_comp = mode_count; modes = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(DXGI_MODE_DESC) * mode_count+10); IDXGIOutput_GetDisplayModeList(output, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_SCALING, NULL, modes); ok(SUCCEEDED(hr), "Failed to list modes, hr %#x.\n", hr); ok(!modes[0].Height, "No output was expected\n"); mode_count = 0; IDXGIOutput_GetDisplayModeList(output, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_SCALING, &mode_count, modes); ok(SUCCEEDED(hr), "Failed to list modes, hr %#x.\n", hr); ok(!modes[0].Height, "No output was expected\n"); mode_count = mode_count_comp; IDXGIOutput_GetDisplayModeList(output, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_SCALING, &mode_count, modes); ok(SUCCEEDED(hr), "Failed to list modes, hr %#x.\n", hr); ok(mode_count == mode_count_comp, "Expected %d, got %d\n", mode_count_comp, mode_count); for (i = 0; i < mode_count; i++) { ok(modes[i].Height && modes[i].Width, "Proper mode was expected\n"); } mode_count += 5; IDXGIOutput_GetDisplayModeList(output, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_SCALING, &mode_count, modes); ok(SUCCEEDED(hr), "Failed to list modes, hr %#x.\n", hr); ok(mode_count == mode_count_comp, "Expected %d, got %d\n", mode_count_comp, mode_count); if (mode_count_comp) { mode_count = mode_count_comp - 1; IDXGIOutput_GetDisplayModeList(output, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_SCALING, &mode_count, modes); ok(SUCCEEDED(hr), "Failed to list modes, hr %#x.\n", hr); ok(mode_count == mode_count_comp -1, "Expected %d, got %d\n", mode_count_comp, mode_count); } else { skip("Not enough modes for test, skipping\n"); } HeapFree(GetProcessHeap(), 0, modes); IDXGIOutput_Release(output); IDXGIAdapter_Release(adapter); }
SDL_bool SDL_DXGIGetOutputInfo(int displayIndex, int *adapterIndex, int *outputIndex) { #if !HAVE_DXGI_H if (adapterIndex) *adapterIndex = -1; if (outputIndex) *outputIndex = -1; SDL_SetError("SDL was compiled without DXGI support due to missing dxgi.h header"); return SDL_FALSE; #else SDL_DisplayData *pData = (SDL_DisplayData *)SDL_GetDisplayDriverData(displayIndex); void *pDXGIDLL; char *displayName; int nAdapter, nOutput; IDXGIFactory *pDXGIFactory; IDXGIAdapter *pDXGIAdapter; IDXGIOutput* pDXGIOutput; if (!adapterIndex) { SDL_InvalidParamError("adapterIndex"); return SDL_FALSE; } if (!outputIndex) { SDL_InvalidParamError("outputIndex"); return SDL_FALSE; } *adapterIndex = -1; *outputIndex = -1; if (!pData) { SDL_SetError("Invalid display index"); return SDL_FALSE; } if (!DXGI_LoadDLL(&pDXGIDLL, &pDXGIFactory)) { SDL_SetError("Unable to create DXGI interface"); return SDL_FALSE; } displayName = WIN_StringToUTF8(pData->DeviceName); nAdapter = 0; while (*adapterIndex == -1 && SUCCEEDED(IDXGIFactory_EnumAdapters(pDXGIFactory, nAdapter, &pDXGIAdapter))) { nOutput = 0; while (*adapterIndex == -1 && SUCCEEDED(IDXGIAdapter_EnumOutputs(pDXGIAdapter, nOutput, &pDXGIOutput))) { DXGI_OUTPUT_DESC outputDesc; if (SUCCEEDED(IDXGIOutput_GetDesc(pDXGIOutput, &outputDesc))) { char *outputName = WIN_StringToUTF8(outputDesc.DeviceName); if (SDL_strcmp(outputName, displayName) == 0) { *adapterIndex = nAdapter; *outputIndex = nOutput; } SDL_free(outputName); } IDXGIOutput_Release(pDXGIOutput); nOutput++; } IDXGIAdapter_Release(pDXGIAdapter); nAdapter++; } SDL_free(displayName); /* free up the DXGI factory */ IDXGIFactory_Release(pDXGIFactory); SDL_UnloadObject(pDXGIDLL); if (*adapterIndex == -1) { return SDL_FALSE; } else { return SDL_TRUE; } #endif }
static void test_output(void) { IDXGIAdapter *adapter; IDXGIDevice *device; HRESULT hr; IDXGIOutput *output; ULONG refcount; UINT mode_count, mode_count_comp, i; DXGI_MODE_DESC *modes; if (!(device = create_device())) { skip("Failed to create device, skipping tests.\n"); return; } hr = IDXGIDevice_GetAdapter(device, &adapter); ok(SUCCEEDED(hr), "GetAdapter failed, hr %#x.\n", hr); hr = IDXGIAdapter_EnumOutputs(adapter, 0, &output); if (hr == DXGI_ERROR_NOT_FOUND) { skip("Adapter doesn't have any outputs, skipping tests.\n"); IDXGIAdapter_Release(adapter); IDXGIDevice_Release(device); return; } ok(SUCCEEDED(hr), "EnumOutputs failed, hr %#x.\n", hr); hr = IDXGIOutput_GetDisplayModeList(output, DXGI_FORMAT_R8G8B8A8_UNORM, 0, NULL, NULL); ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr); hr = IDXGIOutput_GetDisplayModeList(output, DXGI_FORMAT_R8G8B8A8_UNORM, 0, &mode_count, NULL); ok(SUCCEEDED(hr) || broken(hr == DXGI_ERROR_NOT_CURRENTLY_AVAILABLE), /* Remote Desktop Services / Win 7 testbot */ "Failed to list modes, hr %#x.\n", hr); if (hr == DXGI_ERROR_NOT_CURRENTLY_AVAILABLE) { skip("GetDisplayModeList() not supported, skipping tests.\n"); IDXGIOutput_Release(output); IDXGIAdapter_Release(adapter); IDXGIDevice_Release(device); return; } mode_count_comp = mode_count; hr = IDXGIOutput_GetDisplayModeList(output, 0, 0, &mode_count, NULL); ok(SUCCEEDED(hr), "Failed to list modes, hr %#x.\n", hr); ok(!mode_count, "Got unexpected mode_count %u.\n", mode_count); hr = IDXGIOutput_GetDisplayModeList(output, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_SCALING, &mode_count, NULL); ok(SUCCEEDED(hr), "Failed to list modes, hr %#x.\n", hr); ok(mode_count >= mode_count_comp, "Got unexpected mode_count %u, expected >= %u.\n", mode_count, mode_count_comp); mode_count_comp = mode_count; modes = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*modes) * (mode_count + 10)); hr = IDXGIOutput_GetDisplayModeList(output, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_SCALING, NULL, modes); ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr); ok(!modes[0].Height, "No output was expected.\n"); mode_count = 0; hr = IDXGIOutput_GetDisplayModeList(output, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_SCALING, &mode_count, modes); ok(hr == DXGI_ERROR_MORE_DATA, "Got unexpected hr %#x.\n", hr); ok(!modes[0].Height, "No output was expected.\n"); mode_count = mode_count_comp; hr = IDXGIOutput_GetDisplayModeList(output, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_SCALING, &mode_count, modes); ok(SUCCEEDED(hr), "Failed to list modes, hr %#x.\n", hr); ok(mode_count == mode_count_comp, "Got unexpected mode_count %u, expected %u.\n", mode_count, mode_count_comp); for (i = 0; i < mode_count; i++) { ok(modes[i].Height && modes[i].Width, "Proper mode was expected\n"); } mode_count += 5; hr = IDXGIOutput_GetDisplayModeList(output, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_SCALING, &mode_count, modes); ok(SUCCEEDED(hr), "Failed to list modes, hr %#x.\n", hr); ok(mode_count == mode_count_comp, "Got unexpected mode_count %u, expected %u.\n", mode_count, mode_count_comp); if (mode_count_comp) { mode_count = mode_count_comp - 1; hr = IDXGIOutput_GetDisplayModeList(output, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_SCALING, &mode_count, modes); ok(hr == DXGI_ERROR_MORE_DATA, "Got unexpected hr %#x.\n", hr); ok(mode_count == mode_count_comp - 1, "Got unexpected mode_count %u, expected %u.\n", mode_count, mode_count_comp - 1); } else { skip("Not enough modes for test, skipping.\n"); } HeapFree(GetProcessHeap(), 0, modes); IDXGIOutput_Release(output); IDXGIAdapter_Release(adapter); refcount = IDXGIDevice_Release(device); ok(!refcount, "Device has %u references left.\n", refcount); }