static HRESULT STDMETHODCALLTYPE dxgi_device_GetParent(IWineDXGIDevice *iface, REFIID riid, void **parent) { IDXGIAdapter *adapter; HRESULT hr; TRACE("iface %p, riid %s, parent %p.\n", iface, debugstr_guid(riid), parent); hr = IWineDXGIDevice_GetAdapter(iface, &adapter); if (FAILED(hr)) { ERR("Failed to get adapter, hr %#x.\n", hr); return hr; } hr = IDXGIAdapter_QueryInterface(adapter, riid, parent); IDXGIAdapter_Release(adapter); return hr; }
static IDXGISwapChain *create_swapchain(ID3D10Device1 *device, HWND window, BOOL windowed) { IDXGISwapChain *swapchain; DXGI_SWAP_CHAIN_DESC desc; IDXGIDevice *dxgi_device; IDXGIAdapter *adapter; IDXGIFactory *factory; HRESULT hr; hr = ID3D10Device1_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device); ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr); hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter); ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr); IDXGIDevice_Release(dxgi_device); hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory); ok(SUCCEEDED(hr), "Failed to get factory, hr %#x.\n", hr); IDXGIAdapter_Release(adapter); desc.BufferDesc.Width = 640; desc.BufferDesc.Height = 480; desc.BufferDesc.RefreshRate.Numerator = 60; desc.BufferDesc.RefreshRate.Denominator = 1; desc.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; desc.SampleDesc.Count = 1; desc.SampleDesc.Quality = 0; desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; desc.BufferCount = 1; desc.OutputWindow = window; desc.Windowed = windowed; desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; desc.Flags = 0; hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &desc, &swapchain); ok(SUCCEEDED(hr), "Failed to create swapchain, hr %#x.\n", hr); IDXGIFactory_Release(factory); return swapchain; }
HRESULT WINAPI D3D10CreateDevice(IDXGIAdapter *adapter, D3D10_DRIVER_TYPE driver_type, HMODULE swrast, UINT flags, UINT sdk_version, ID3D10Device **device) { IDXGIFactory *factory; HRESULT hr; TRACE("adapter %p, driver_type %s, swrast %p, flags %#x, sdk_version %d, device %p\n", adapter, debug_d3d10_driver_type(driver_type), swrast, flags, sdk_version, device); if (adapter) { IDXGIAdapter_AddRef(adapter); hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory); if (FAILED(hr)) { WARN("Failed to get dxgi factory, returning %#x\n", hr); return hr; } } else { hr = CreateDXGIFactory(&IID_IDXGIFactory, (void **)&factory); if (FAILED(hr)) { WARN("Failed to create dxgi factory, returning %#x\n", hr); return hr; } switch(driver_type) { case D3D10_DRIVER_TYPE_HARDWARE: { hr = IDXGIFactory_EnumAdapters(factory, 0, &adapter); if (FAILED(hr)) { WARN("No adapters found, returning %#x\n", hr); IDXGIFactory_Release(factory); return hr; } break; } case D3D10_DRIVER_TYPE_NULL: FIXME("NULL device not implemented, falling back to refrast\n"); /* fall through, for now */ case D3D10_DRIVER_TYPE_REFERENCE: { HMODULE refrast = LoadLibraryA("d3d10ref.dll"); if (!refrast) { WARN("Failed to load refrast, returning E_FAIL\n"); IDXGIFactory_Release(factory); return E_FAIL; } hr = IDXGIFactory_CreateSoftwareAdapter(factory, refrast, &adapter); FreeLibrary(refrast); if (FAILED(hr)) { WARN("Failed to create a software adapter, returning %#x\n", hr); IDXGIFactory_Release(factory); return hr; } break; } case D3D10_DRIVER_TYPE_SOFTWARE: { if (!swrast) { WARN("Software device requested, but NULL swrast passed, returning E_FAIL\n"); IDXGIFactory_Release(factory); return E_FAIL; } hr = IDXGIFactory_CreateSoftwareAdapter(factory, swrast, &adapter); if (FAILED(hr)) { WARN("Failed to create a software adapter, returning %#x\n", hr); IDXGIFactory_Release(factory); return hr; } break; } default: FIXME("Unhandled driver type %#x.\n", driver_type); IDXGIFactory_Release(factory); return E_FAIL; } } hr = D3D10CoreCreateDevice(factory, adapter, flags, NULL, device); IDXGIAdapter_Release(adapter); IDXGIFactory_Release(factory); if (FAILED(hr)) { WARN("Failed to create a device, returning %#x\n", hr); return hr; } TRACE("Created ID3D10Device %p\n", *device); return hr; }
HRESULT WINAPI D3D10CreateDeviceAndSwapChain(IDXGIAdapter *adapter, D3D10_DRIVER_TYPE driver_type, HMODULE swrast, UINT flags, UINT sdk_version, DXGI_SWAP_CHAIN_DESC *swapchain_desc, IDXGISwapChain **swapchain, ID3D10Device **device) { IDXGIDevice *dxgi_device; IDXGIFactory *factory; HRESULT hr; TRACE("adapter %p, driver_type %s, swrast %p, flags %#x, sdk_version %d,\n" "\tswapchain_desc %p, swapchain %p, device %p\n", adapter, debug_d3d10_driver_type(driver_type), swrast, flags, sdk_version, swapchain_desc, swapchain, device); hr = D3D10CreateDevice(adapter, driver_type, swrast, flags, sdk_version, device); if (FAILED(hr)) { WARN("Failed to create a device, returning %#x\n", hr); *device = NULL; return hr; } TRACE("Created ID3D10Device %p\n", *device); hr = ID3D10Device_QueryInterface(*device, &IID_IDXGIDevice, (void **)&dxgi_device); if (FAILED(hr)) { ERR("Failed to get a dxgi device from the d3d10 device, returning %#x\n", hr); ID3D10Device_Release(*device); *device = NULL; return hr; } hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter); IDXGIDevice_Release(dxgi_device); if (FAILED(hr)) { ERR("Failed to get the device adapter, returning %#x\n", hr); ID3D10Device_Release(*device); *device = NULL; return hr; } hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory); IDXGIAdapter_Release(adapter); if (FAILED(hr)) { ERR("Failed to get the adapter factory, returning %#x\n", hr); ID3D10Device_Release(*device); *device = NULL; return hr; } hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)*device, swapchain_desc, swapchain); IDXGIFactory_Release(factory); if (FAILED(hr)) { ID3D10Device_Release(*device); *device = NULL; WARN("Failed to create a swapchain, returning %#x\n", hr); return hr; } TRACE("Created IDXGISwapChain %p\n", *swapchain); return S_OK; }
static inline bool gl_shtex_init_d3d11(void) { D3D_FEATURE_LEVEL level_used; IDXGIFactory1 *factory; IDXGIAdapter *adapter; HRESULT hr; HMODULE d3d11 = load_system_library("d3d11.dll"); if (!d3d11) { hlog("gl_shtex_init_d3d11: failed to load D3D11.dll: %d", GetLastError()); return false; } HMODULE dxgi = load_system_library("dxgi.dll"); if (!dxgi) { hlog("gl_shtex_init_d3d11: failed to load DXGI.dll: %d", GetLastError()); return false; } DXGI_SWAP_CHAIN_DESC desc = {0}; desc.BufferCount = 2; desc.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; desc.BufferDesc.Width = 2; desc.BufferDesc.Height = 2; desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; desc.SampleDesc.Count = 1; desc.Windowed = true; desc.OutputWindow = data.hwnd; create_dxgi_factory1_t create_factory = (void*)GetProcAddress(dxgi, "CreateDXGIFactory1"); if (!create_factory) { hlog("gl_shtex_init_d3d11: failed to load CreateDXGIFactory1 " "procedure: %d", GetLastError()); return false; } PFN_D3D11_CREATE_DEVICE_AND_SWAP_CHAIN create = (void*)GetProcAddress( d3d11, "D3D11CreateDeviceAndSwapChain"); if (!create) { hlog("gl_shtex_init_d3d11: failed to load " "D3D11CreateDeviceAndSwapChain procedure: %d", GetLastError()); return false; } hr = create_factory(&GUID_IDXGIFactory1, (void**)&factory); if (FAILED(hr)) { hlog_hr("gl_shtex_init_d3d11: failed to create factory", hr); return false; } hr = IDXGIFactory1_EnumAdapters1(factory, 0, (IDXGIAdapter1**)&adapter); IDXGIFactory1_Release(factory); if (FAILED(hr)) { hlog_hr("gl_shtex_init_d3d11: failed to create adapter", hr); return false; } hr = create(adapter, D3D_DRIVER_TYPE_UNKNOWN, NULL, 0, feature_levels, sizeof(feature_levels) / sizeof(D3D_FEATURE_LEVEL), D3D11_SDK_VERSION, &desc, &data.dxgi_swap, &data.d3d11_device, &level_used, &data.d3d11_context); IDXGIAdapter_Release(adapter); if (FAILED(hr)) { hlog_hr("gl_shtex_init_d3d11: failed to create device", hr); return false; } return true; }
HRESULT WINAPI D3D10CreateDevice1(IDXGIAdapter *adapter, D3D10_DRIVER_TYPE driver_type, HMODULE swrast, UINT flags, D3D10_FEATURE_LEVEL1 hw_level, UINT sdk_version, ID3D10Device1 **device) { IDXGIFactory *factory; HRESULT hr; TRACE("adapter %p, driver_type %s, swrast %p, flags %#x, hw_level %s, sdk_version %d, device %p.\n", adapter, debug_d3d10_driver_type(driver_type), swrast, flags, debug_d3d10_feature_level(hw_level), sdk_version, device); if (!device) return E_INVALIDARG; *device = NULL; if (!hw_level) return E_INVALIDARG; if (adapter) { IDXGIAdapter_AddRef(adapter); if (FAILED(hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory))) { WARN("Failed to get dxgi factory, hr %#x.\n", hr); return hr; } } else { if (FAILED(hr = CreateDXGIFactory(&IID_IDXGIFactory, (void **)&factory))) { WARN("Failed to create dxgi factory, hr %#x.\n", hr); return hr; } switch (driver_type) { case D3D10_DRIVER_TYPE_WARP: FIXME("WARP driver not implemented, falling back to hardware.\n"); case D3D10_DRIVER_TYPE_HARDWARE: { if (FAILED(hr = IDXGIFactory_EnumAdapters(factory, 0, &adapter))) { WARN("No adapters found, hr %#x.\n", hr); IDXGIFactory_Release(factory); return hr; } break; } case D3D10_DRIVER_TYPE_NULL: FIXME("NULL device not implemented, falling back to refrast.\n"); /* Fall through, for now. */ case D3D10_DRIVER_TYPE_REFERENCE: { HMODULE refrast; if (!(refrast = LoadLibraryA("d3d10ref.dll"))) { WARN("Failed to load refrast, returning E_FAIL.\n"); IDXGIFactory_Release(factory); return E_FAIL; } hr = IDXGIFactory_CreateSoftwareAdapter(factory, refrast, &adapter); FreeLibrary(refrast); if (FAILED(hr)) { WARN("Failed to create a software adapter, hr %#x.\n", hr); IDXGIFactory_Release(factory); return hr; } break; } case D3D10_DRIVER_TYPE_SOFTWARE: { if (!swrast) { WARN("Software device requested, but NULL swrast passed, returning E_FAIL.\n"); IDXGIFactory_Release(factory); return E_FAIL; } if (FAILED(hr = IDXGIFactory_CreateSoftwareAdapter(factory, swrast, &adapter))) { WARN("Failed to create a software adapter, hr %#x.\n", hr); IDXGIFactory_Release(factory); return hr; } break; } default: FIXME("Unhandled driver type %#x.\n", driver_type); IDXGIFactory_Release(factory); return E_FAIL; } } hr = D3D10CoreCreateDevice(factory, adapter, flags, hw_level, (ID3D10Device **)device); IDXGIAdapter_Release(adapter); IDXGIFactory_Release(factory); if (FAILED(hr)) { WARN("Failed to create a device, hr %#x.\n", hr); return hr; } TRACE("Created device %p.\n", *device); return hr; }
HRESULT WINAPI D3D10CreateDeviceAndSwapChain1(IDXGIAdapter *adapter, D3D10_DRIVER_TYPE driver_type, HMODULE swrast, UINT flags, D3D10_FEATURE_LEVEL1 feature_level, UINT sdk_version, DXGI_SWAP_CHAIN_DESC *swapchain_desc, IDXGISwapChain **swapchain, ID3D10Device1 **device) { IDXGIDevice *dxgi_device; IDXGIFactory *factory; HRESULT hr; TRACE("adapter %p, driver_type %s, swrast %p, flags %#x, " "feature_level %s, sdk_version %d, swapchain_desc %p, swapchain %p, device %p.\n", adapter, debug_d3d10_driver_type(driver_type), swrast, flags, debug_d3d10_feature_level(feature_level), sdk_version, swapchain_desc, swapchain, device); if (swapchain) *swapchain = NULL; if (!device) return E_INVALIDARG; if (FAILED(hr = D3D10CreateDevice1(adapter, driver_type, swrast, flags, feature_level, sdk_version, device))) { WARN("Failed to create a device, returning %#x.\n", hr); *device = NULL; return hr; } if (swapchain) { if (FAILED(hr = ID3D10Device1_QueryInterface(*device, &IID_IDXGIDevice, (void **)&dxgi_device))) { ERR("Failed to get a dxgi device from the d3d10 device, returning %#x.\n", hr); goto cleanup; } hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter); IDXGIDevice_Release(dxgi_device); if (FAILED(hr)) { ERR("Failed to get the device adapter, returning %#x.\n", hr); goto cleanup; } hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory); IDXGIAdapter_Release(adapter); if (FAILED(hr)) { ERR("Failed to get the adapter factory, returning %#x.\n", hr); goto cleanup; } hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)*device, swapchain_desc, swapchain); IDXGIFactory_Release(factory); if (FAILED(hr)) { WARN("Failed to create a swapchain, returning %#x.\n", hr); goto cleanup; } TRACE("Created IDXGISwapChain %p.\n", *swapchain); } return S_OK; cleanup: ID3D10Device1_Release(*device); *device = NULL; return hr; }
static void test_device_interfaces(void) { IDXGIAdapter *dxgi_adapter; IDXGIDevice *dxgi_device; ID3D10Device1 *device; IUnknown *iface; ULONG refcount; unsigned int i; HRESULT hr; for (i = 0; i < sizeof(d3d10_feature_levels) / sizeof(*d3d10_feature_levels); ++i) { struct device_desc device_desc; device_desc.feature_level = d3d10_feature_levels[i]; device_desc.flags = 0; if (!(device = create_device(&device_desc))) { skip("Failed to create device for feature level %#x.\n", d3d10_feature_levels[i]); continue; } hr = ID3D10Device1_QueryInterface(device, &IID_IUnknown, (void **)&iface); ok(SUCCEEDED(hr), "Device should implement IUnknown interface, hr %#x.\n", hr); IUnknown_Release(iface); hr = ID3D10Device1_QueryInterface(device, &IID_IDXGIObject, (void **)&iface); ok(SUCCEEDED(hr), "Device should implement IDXGIObject interface, hr %#x.\n", hr); IUnknown_Release(iface); hr = ID3D10Device1_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device); ok(SUCCEEDED(hr), "Device should implement IDXGIDevice.\n"); hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter, (void **)&dxgi_adapter); ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter.\n"); hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory, (void **)&iface); ok(SUCCEEDED(hr), "Adapter parent should implement IDXGIFactory.\n"); IUnknown_Release(iface); IDXGIAdapter_Release(dxgi_adapter); hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter1, (void **)&dxgi_adapter); ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter1.\n"); hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory1, (void **)&iface); ok(hr == E_NOINTERFACE, "Adapter parent should not implement IDXGIFactory1.\n"); IDXGIAdapter_Release(dxgi_adapter); IDXGIDevice_Release(dxgi_device); hr = ID3D10Device1_QueryInterface(device, &IID_IDXGIDevice1, (void **)&iface); ok(SUCCEEDED(hr), "Device should implement IDXGIDevice1.\n"); IUnknown_Release(iface); hr = ID3D10Device1_QueryInterface(device, &IID_ID3D10Multithread, (void **)&iface); ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */, "Device should implement ID3D10Multithread interface, hr %#x.\n", hr); if (SUCCEEDED(hr)) IUnknown_Release(iface); hr = ID3D10Device1_QueryInterface(device, &IID_ID3D10InfoQueue, (void **)&iface); ok(hr == E_NOINTERFACE, "Found ID3D10InfoQueue interface in non-debug mode, hr %#x.\n", hr); hr = ID3D10Device1_QueryInterface(device, &IID_ID3D10Device, (void **)&iface); ok(SUCCEEDED(hr), "Device should implement ID3D10Device interface, hr %#x.\n", hr); IUnknown_Release(iface); hr = ID3D10Device1_QueryInterface(device, &IID_ID3D11Device, (void **)&iface); ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */, "Device should implement ID3D11Device interface, hr %#x.\n", hr); if (SUCCEEDED(hr)) IUnknown_Release(iface); refcount = ID3D10Device1_Release(device); ok(!refcount, "Device has %u references left.\n", refcount); } for (i = 0; i < sizeof(d3d10_feature_levels) / sizeof(*d3d10_feature_levels); ++i) { struct device_desc device_desc; device_desc.feature_level = d3d10_feature_levels[i]; device_desc.flags = D3D10_CREATE_DEVICE_DEBUG; if (!(device = create_device(&device_desc))) { skip("Failed to create device for feature level %#x.\n", d3d10_feature_levels[i]); continue; } hr = ID3D10Device1_QueryInterface(device, &IID_ID3D10InfoQueue, (void **)&iface); todo_wine ok(hr == S_OK, "Device should implement ID3D10InfoQueue interface, hr %#x.\n", hr); if (SUCCEEDED(hr)) IUnknown_Release(iface); refcount = ID3D10Device1_Release(device); ok(!refcount, "Device has %u references left.\n", refcount); } }
HRESULT WINAPI D3D11CreateDeviceAndSwapChain(IDXGIAdapter *adapter, D3D_DRIVER_TYPE driver_type, HMODULE swrast, UINT flags, const D3D_FEATURE_LEVEL *feature_levels, UINT levels, UINT sdk_version, const DXGI_SWAP_CHAIN_DESC *swapchain_desc, IDXGISwapChain **swapchain, ID3D11Device **device_out, D3D_FEATURE_LEVEL *obtained_feature_level, ID3D11DeviceContext **immediate_context) { DXGI_SWAP_CHAIN_DESC desc; IDXGIDevice *dxgi_device; IDXGIFactory *factory; ID3D11Device *device; HRESULT hr; TRACE("adapter %p, driver_type %s, swrast %p, flags %#x, feature_levels %p, levels %u, sdk_version %u, " "swapchain_desc %p, swapchain %p, device %p, obtained_feature_level %p, immediate_context %p.\n", adapter, debug_d3d_driver_type(driver_type), swrast, flags, feature_levels, levels, sdk_version, swapchain_desc, swapchain, device_out, obtained_feature_level, immediate_context); if (swapchain) *swapchain = NULL; if (device_out) *device_out = NULL; if (FAILED(hr = D3D11CreateDevice(adapter, driver_type, swrast, flags, feature_levels, levels, sdk_version, &device, obtained_feature_level, immediate_context))) { WARN("Failed to create a device, returning %#x.\n", hr); return hr; } if (swapchain) { if (FAILED(hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device))) { ERR("Failed to get a dxgi device from the d3d11 device, returning %#x.\n", hr); goto cleanup; } hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter); IDXGIDevice_Release(dxgi_device); if (FAILED(hr)) { ERR("Failed to get the device adapter, returning %#x.\n", hr); goto cleanup; } hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory); IDXGIAdapter_Release(adapter); if (FAILED(hr)) { ERR("Failed to get the adapter factory, returning %#x.\n", hr); goto cleanup; } desc = *swapchain_desc; hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &desc, swapchain); IDXGIFactory_Release(factory); if (FAILED(hr)) { WARN("Failed to create a swapchain, returning %#x.\n", hr); goto cleanup; } TRACE("Created IDXGISwapChain %p.\n", swapchain); } if (device_out) *device_out = device; else ID3D11Device_Release(device); return S_OK; cleanup: if (device) ID3D11Device_Release(device); if (obtained_feature_level) *obtained_feature_level = 0; if (immediate_context) { /* FIXME: Remove the following NULL check once the d3d11_device_GetImmediateContext() is implemented. */ if (*immediate_context) ID3D11DeviceContext_Release(*immediate_context); *immediate_context = NULL; } return hr; }
HRESULT WINAPI D3D11CreateDevice(IDXGIAdapter *adapter, D3D_DRIVER_TYPE driver_type, HMODULE swrast, UINT flags, const D3D_FEATURE_LEVEL *feature_levels, UINT levels, UINT sdk_version, ID3D11Device **device_out, D3D_FEATURE_LEVEL *obtained_feature_level, ID3D11DeviceContext **immediate_context) { IDXGIFactory *factory; ID3D11Device *device; HRESULT hr; TRACE("adapter %p, driver_type %s, swrast %p, flags %#x, feature_levels %p, levels %u, sdk_version %u, " "device %p, obtained_feature_level %p, immediate_context %p.\n", adapter, debug_d3d_driver_type(driver_type), swrast, flags, feature_levels, levels, sdk_version, device_out, obtained_feature_level, immediate_context); if (device_out) *device_out = NULL; if (obtained_feature_level) *obtained_feature_level = 0; if (immediate_context) *immediate_context = NULL; if (adapter) { IDXGIAdapter_AddRef(adapter); hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory); if (FAILED(hr)) { WARN("Failed to get dxgi factory, returning %#x.\n", hr); return hr; } } else { hr = CreateDXGIFactory(&IID_IDXGIFactory, (void **)&factory); if (FAILED(hr)) { WARN("Failed to create dxgi factory, returning %#x.\n", hr); return hr; } switch(driver_type) { case D3D_DRIVER_TYPE_HARDWARE: { hr = IDXGIFactory_EnumAdapters(factory, 0, &adapter); if (FAILED(hr)) { WARN("No adapters found, returning %#x.\n", hr); IDXGIFactory_Release(factory); return hr; } break; } case D3D_DRIVER_TYPE_NULL: FIXME("NULL device not implemented, falling back to refrast.\n"); /* fall through, for now */ case D3D_DRIVER_TYPE_REFERENCE: { HMODULE refrast = LoadLibraryA("d3d11ref.dll"); if (!refrast) { WARN("Failed to load refrast, returning E_FAIL.\n"); IDXGIFactory_Release(factory); return E_FAIL; } hr = IDXGIFactory_CreateSoftwareAdapter(factory, refrast, &adapter); FreeLibrary(refrast); if (FAILED(hr)) { WARN("Failed to create a software adapter, returning %#x.\n", hr); IDXGIFactory_Release(factory); return hr; } break; } case D3D_DRIVER_TYPE_SOFTWARE: { if (!swrast) { WARN("Software device requested, but NULL swrast passed, returning E_FAIL.\n"); IDXGIFactory_Release(factory); return E_FAIL; } hr = IDXGIFactory_CreateSoftwareAdapter(factory, swrast, &adapter); if (FAILED(hr)) { WARN("Failed to create a software adapter, returning %#x.\n", hr); IDXGIFactory_Release(factory); return hr; } break; } default: FIXME("Unhandled driver type %#x.\n", driver_type); IDXGIFactory_Release(factory); return E_FAIL; } } hr = D3D11CoreCreateDevice(factory, adapter, flags, feature_levels, levels, &device); IDXGIAdapter_Release(adapter); IDXGIFactory_Release(factory); if (FAILED(hr)) { WARN("Failed to create a device, returning %#x.\n", hr); return hr; } TRACE("Created ID3D11Device %p.\n", device); if (obtained_feature_level) *obtained_feature_level = ID3D11Device_GetFeatureLevel(device); if (immediate_context) ID3D11Device_GetImmediateContext(device, immediate_context); if (device_out) *device_out = device; else ID3D11Device_Release(device); return S_OK; }
static void test_swapchain_resize(void) { DXGI_SWAP_CHAIN_DESC swapchain_desc; D3D10_TEXTURE2D_DESC texture_desc; DXGI_SURFACE_DESC surface_desc; IDXGISwapChain *swapchain; ID3D10Texture2D *texture; IDXGISurface *surface; IDXGIAdapter *adapter; IDXGIFactory *factory; IDXGIDevice *device; RECT client_rect, r; ULONG refcount; HWND window; HRESULT hr; BOOL ret; if (!(device = create_device())) { skip("Failed to create device, skipping tests.\n"); return; } window = CreateWindowA("static", "dxgi_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0, 0, 640, 480, NULL, NULL, NULL, NULL); ret = GetClientRect(window, &client_rect); ok(ret, "Failed to get client rect.\n"); hr = IDXGIDevice_GetAdapter(device, &adapter); ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr); hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory); ok(SUCCEEDED(hr), "Failed to get factory, hr %#x.\n", hr); IDXGIAdapter_Release(adapter); swapchain_desc.BufferDesc.Width = 640; swapchain_desc.BufferDesc.Height = 480; swapchain_desc.BufferDesc.RefreshRate.Numerator = 60; swapchain_desc.BufferDesc.RefreshRate.Denominator = 1; swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; swapchain_desc.SampleDesc.Count = 1; swapchain_desc.SampleDesc.Quality = 0; swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; swapchain_desc.BufferCount = 1; swapchain_desc.OutputWindow = window; swapchain_desc.Windowed = TRUE; swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; swapchain_desc.Flags = 0; hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain); ok(SUCCEEDED(hr), "Failed to create swapchain, hr %#x.\n", hr); IDXGIFactory_Release(factory); hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_IDXGISurface, (void **)&surface); ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr); hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D10Texture2D, (void **)&texture); ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr); ret = GetClientRect(window, &r); ok(ret, "Failed to get client rect.\n"); ok(EqualRect(&r, &client_rect), "Got unexpected rect {%d, %d, %d, %d}, expected {%d, %d, %d, %d}.\n", r.left, r.top, r.right, r.bottom, client_rect.left, client_rect.top, client_rect.right, client_rect.bottom); hr = IDXGISwapChain_GetDesc(swapchain, &swapchain_desc); ok(SUCCEEDED(hr), "Failed to get swapchain desc, hr %#x.\n", hr); ok(swapchain_desc.BufferDesc.Width == 640, "Got unexpected BufferDesc.Width %u.\n", swapchain_desc.BufferDesc.Width); ok(swapchain_desc.BufferDesc.Height == 480, "Got unexpected bufferDesc.Height %u.\n", swapchain_desc.BufferDesc.Height); ok(swapchain_desc.BufferDesc.RefreshRate.Numerator == 60, "Got unexpected BufferDesc.RefreshRate.Numerator %u.\n", swapchain_desc.BufferDesc.RefreshRate.Numerator); ok(swapchain_desc.BufferDesc.RefreshRate.Denominator == 1, "Got unexpected BufferDesc.RefreshRate.Denominator %u.\n", swapchain_desc.BufferDesc.RefreshRate.Denominator); ok(swapchain_desc.BufferDesc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected BufferDesc.Format %#x.\n", swapchain_desc.BufferDesc.Format); ok(swapchain_desc.BufferDesc.ScanlineOrdering == DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED, "Got unexpected BufferDesc.ScanlineOrdering %#x.\n", swapchain_desc.BufferDesc.ScanlineOrdering); ok(swapchain_desc.BufferDesc.Scaling == DXGI_MODE_SCALING_UNSPECIFIED, "Got unexpected BufferDesc.Scaling %#x.\n", swapchain_desc.BufferDesc.Scaling); ok(swapchain_desc.SampleDesc.Count == 1, "Got unexpected SampleDesc.Count %u.\n", swapchain_desc.SampleDesc.Count); ok(!swapchain_desc.SampleDesc.Quality, "Got unexpected SampleDesc.Quality %u.\n", swapchain_desc.SampleDesc.Quality); ok(swapchain_desc.BufferUsage == DXGI_USAGE_RENDER_TARGET_OUTPUT, "Got unexpected BufferUsage %#x.\n", swapchain_desc.BufferUsage); ok(swapchain_desc.BufferCount == 1, "Got unexpected BufferCount %u.\n", swapchain_desc.BufferCount); ok(swapchain_desc.OutputWindow == window, "Got unexpected OutputWindow %p, expected %p.\n", swapchain_desc.OutputWindow, window); ok(swapchain_desc.Windowed, "Got unexpected Windowed %#x.\n", swapchain_desc.Windowed); ok(swapchain_desc.SwapEffect == DXGI_SWAP_EFFECT_DISCARD, "Got unexpected SwapEffect %#x.\n", swapchain_desc.SwapEffect); ok(!swapchain_desc.Flags, "Got unexpected Flags %#x.\n", swapchain_desc.Flags); hr = IDXGISurface_GetDesc(surface, &surface_desc); ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr); ok(surface_desc.Width == 640, "Got unexpected Width %u.\n", surface_desc.Width); ok(surface_desc.Height == 480, "Got unexpected Height %u.\n", surface_desc.Height); ok(surface_desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", surface_desc.Format); ok(surface_desc.SampleDesc.Count == 1, "Got unexpected SampleDesc.Count %u.\n", surface_desc.SampleDesc.Count); ok(!surface_desc.SampleDesc.Quality, "Got unexpected SampleDesc.Quality %u.\n", surface_desc.SampleDesc.Quality); ID3D10Texture2D_GetDesc(texture, &texture_desc); ok(texture_desc.Width == 640, "Got unexpected Width %u.\n", texture_desc.Width); ok(texture_desc.Height == 480, "Got unexpected Height %u.\n", texture_desc.Height); ok(texture_desc.MipLevels == 1, "Got unexpected MipLevels %u.\n", texture_desc.MipLevels); ok(texture_desc.ArraySize == 1, "Got unexpected ArraySize %u.\n", texture_desc.ArraySize); ok(texture_desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", texture_desc.Format); ok(texture_desc.SampleDesc.Count == 1, "Got unexpected SampleDesc.Count %u.\n", texture_desc.SampleDesc.Count); ok(!texture_desc.SampleDesc.Quality, "Got unexpected SampleDesc.Quality %u.\n", texture_desc.SampleDesc.Quality); ok(texture_desc.Usage == D3D10_USAGE_DEFAULT, "Got unexpected Usage %#x.\n", texture_desc.Usage); ok(texture_desc.BindFlags == D3D10_BIND_RENDER_TARGET, "Got unexpected BindFlags %#x.\n", texture_desc.BindFlags); ok(!texture_desc.CPUAccessFlags, "Got unexpected CPUAccessFlags %#x.\n", texture_desc.CPUAccessFlags); ok(!texture_desc.MiscFlags, "Got unexpected MiscFlags %#x.\n", texture_desc.MiscFlags); hr = IDXGISwapChain_ResizeBuffers(swapchain, 1, 320, 240, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, 0); ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr); ret = GetClientRect(window, &r); ok(ret, "Failed to get client rect.\n"); ok(EqualRect(&r, &client_rect), "Got unexpected rect {%d, %d, %d, %d}, expected {%d, %d, %d, %d}.\n", r.left, r.top, r.right, r.bottom, client_rect.left, client_rect.top, client_rect.right, client_rect.bottom); hr = IDXGISwapChain_GetDesc(swapchain, &swapchain_desc); ok(SUCCEEDED(hr), "Failed to get swapchain desc, hr %#x.\n", hr); ok(swapchain_desc.BufferDesc.Width == 640, "Got unexpected BufferDesc.Width %u.\n", swapchain_desc.BufferDesc.Width); ok(swapchain_desc.BufferDesc.Height == 480, "Got unexpected bufferDesc.Height %u.\n", swapchain_desc.BufferDesc.Height); ok(swapchain_desc.BufferDesc.RefreshRate.Numerator == 60, "Got unexpected BufferDesc.RefreshRate.Numerator %u.\n", swapchain_desc.BufferDesc.RefreshRate.Numerator); ok(swapchain_desc.BufferDesc.RefreshRate.Denominator == 1, "Got unexpected BufferDesc.RefreshRate.Denominator %u.\n", swapchain_desc.BufferDesc.RefreshRate.Denominator); ok(swapchain_desc.BufferDesc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected BufferDesc.Format %#x.\n", swapchain_desc.BufferDesc.Format); ok(swapchain_desc.BufferDesc.ScanlineOrdering == DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED, "Got unexpected BufferDesc.ScanlineOrdering %#x.\n", swapchain_desc.BufferDesc.ScanlineOrdering); ok(swapchain_desc.BufferDesc.Scaling == DXGI_MODE_SCALING_UNSPECIFIED, "Got unexpected BufferDesc.Scaling %#x.\n", swapchain_desc.BufferDesc.Scaling); ok(swapchain_desc.SampleDesc.Count == 1, "Got unexpected SampleDesc.Count %u.\n", swapchain_desc.SampleDesc.Count); ok(!swapchain_desc.SampleDesc.Quality, "Got unexpected SampleDesc.Quality %u.\n", swapchain_desc.SampleDesc.Quality); ok(swapchain_desc.BufferUsage == DXGI_USAGE_RENDER_TARGET_OUTPUT, "Got unexpected BufferUsage %#x.\n", swapchain_desc.BufferUsage); ok(swapchain_desc.BufferCount == 1, "Got unexpected BufferCount %u.\n", swapchain_desc.BufferCount); ok(swapchain_desc.OutputWindow == window, "Got unexpected OutputWindow %p, expected %p.\n", swapchain_desc.OutputWindow, window); ok(swapchain_desc.Windowed, "Got unexpected Windowed %#x.\n", swapchain_desc.Windowed); ok(swapchain_desc.SwapEffect == DXGI_SWAP_EFFECT_DISCARD, "Got unexpected SwapEffect %#x.\n", swapchain_desc.SwapEffect); ok(!swapchain_desc.Flags, "Got unexpected Flags %#x.\n", swapchain_desc.Flags); hr = IDXGISurface_GetDesc(surface, &surface_desc); ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr); ok(surface_desc.Width == 640, "Got unexpected Width %u.\n", surface_desc.Width); ok(surface_desc.Height == 480, "Got unexpected Height %u.\n", surface_desc.Height); ok(surface_desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", surface_desc.Format); ok(surface_desc.SampleDesc.Count == 1, "Got unexpected SampleDesc.Count %u.\n", surface_desc.SampleDesc.Count); ok(!surface_desc.SampleDesc.Quality, "Got unexpected SampleDesc.Quality %u.\n", surface_desc.SampleDesc.Quality); ID3D10Texture2D_GetDesc(texture, &texture_desc); ok(texture_desc.Width == 640, "Got unexpected Width %u.\n", texture_desc.Width); ok(texture_desc.Height == 480, "Got unexpected Height %u.\n", texture_desc.Height); ok(texture_desc.MipLevels == 1, "Got unexpected MipLevels %u.\n", texture_desc.MipLevels); ok(texture_desc.ArraySize == 1, "Got unexpected ArraySize %u.\n", texture_desc.ArraySize); ok(texture_desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", texture_desc.Format); ok(texture_desc.SampleDesc.Count == 1, "Got unexpected SampleDesc.Count %u.\n", texture_desc.SampleDesc.Count); ok(!texture_desc.SampleDesc.Quality, "Got unexpected SampleDesc.Quality %u.\n", texture_desc.SampleDesc.Quality); ok(texture_desc.Usage == D3D10_USAGE_DEFAULT, "Got unexpected Usage %#x.\n", texture_desc.Usage); ok(texture_desc.BindFlags == D3D10_BIND_RENDER_TARGET, "Got unexpected BindFlags %#x.\n", texture_desc.BindFlags); ok(!texture_desc.CPUAccessFlags, "Got unexpected CPUAccessFlags %#x.\n", texture_desc.CPUAccessFlags); ok(!texture_desc.MiscFlags, "Got unexpected MiscFlags %#x.\n", texture_desc.MiscFlags); ID3D10Texture2D_Release(texture); IDXGISurface_Release(surface); hr = IDXGISwapChain_ResizeBuffers(swapchain, 1, 320, 240, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, 0); ok(SUCCEEDED(hr), "Failed to resize buffers, hr %#x.\n", hr); hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_IDXGISurface, (void **)&surface); ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr); hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D10Texture2D, (void **)&texture); ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr); ret = GetClientRect(window, &r); ok(ret, "Failed to get client rect.\n"); ok(EqualRect(&r, &client_rect), "Got unexpected rect {%d, %d, %d, %d}, expected {%d, %d, %d, %d}.\n", r.left, r.top, r.right, r.bottom, client_rect.left, client_rect.top, client_rect.right, client_rect.bottom); hr = IDXGISwapChain_GetDesc(swapchain, &swapchain_desc); ok(SUCCEEDED(hr), "Failed to get swapchain desc, hr %#x.\n", hr); ok(swapchain_desc.BufferDesc.Width == 320, "Got unexpected BufferDesc.Width %u.\n", swapchain_desc.BufferDesc.Width); ok(swapchain_desc.BufferDesc.Height == 240, "Got unexpected bufferDesc.Height %u.\n", swapchain_desc.BufferDesc.Height); ok(swapchain_desc.BufferDesc.RefreshRate.Numerator == 60, "Got unexpected BufferDesc.RefreshRate.Numerator %u.\n", swapchain_desc.BufferDesc.RefreshRate.Numerator); ok(swapchain_desc.BufferDesc.RefreshRate.Denominator == 1, "Got unexpected BufferDesc.RefreshRate.Denominator %u.\n", swapchain_desc.BufferDesc.RefreshRate.Denominator); ok(swapchain_desc.BufferDesc.Format == DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, "Got unexpected BufferDesc.Format %#x.\n", swapchain_desc.BufferDesc.Format); ok(swapchain_desc.BufferDesc.ScanlineOrdering == DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED, "Got unexpected BufferDesc.ScanlineOrdering %#x.\n", swapchain_desc.BufferDesc.ScanlineOrdering); ok(swapchain_desc.BufferDesc.Scaling == DXGI_MODE_SCALING_UNSPECIFIED, "Got unexpected BufferDesc.Scaling %#x.\n", swapchain_desc.BufferDesc.Scaling); ok(swapchain_desc.SampleDesc.Count == 1, "Got unexpected SampleDesc.Count %u.\n", swapchain_desc.SampleDesc.Count); ok(!swapchain_desc.SampleDesc.Quality, "Got unexpected SampleDesc.Quality %u.\n", swapchain_desc.SampleDesc.Quality); ok(swapchain_desc.BufferUsage == DXGI_USAGE_RENDER_TARGET_OUTPUT, "Got unexpected BufferUsage %#x.\n", swapchain_desc.BufferUsage); ok(swapchain_desc.BufferCount == 1, "Got unexpected BufferCount %u.\n", swapchain_desc.BufferCount); ok(swapchain_desc.OutputWindow == window, "Got unexpected OutputWindow %p, expected %p.\n", swapchain_desc.OutputWindow, window); ok(swapchain_desc.Windowed, "Got unexpected Windowed %#x.\n", swapchain_desc.Windowed); ok(swapchain_desc.SwapEffect == DXGI_SWAP_EFFECT_DISCARD, "Got unexpected SwapEffect %#x.\n", swapchain_desc.SwapEffect); ok(!swapchain_desc.Flags, "Got unexpected Flags %#x.\n", swapchain_desc.Flags); hr = IDXGISurface_GetDesc(surface, &surface_desc); ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr); ok(surface_desc.Width == 320, "Got unexpected Width %u.\n", surface_desc.Width); ok(surface_desc.Height == 240, "Got unexpected Height %u.\n", surface_desc.Height); ok(surface_desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, "Got unexpected Format %#x.\n", surface_desc.Format); ok(surface_desc.SampleDesc.Count == 1, "Got unexpected SampleDesc.Count %u.\n", surface_desc.SampleDesc.Count); ok(!surface_desc.SampleDesc.Quality, "Got unexpected SampleDesc.Quality %u.\n", surface_desc.SampleDesc.Quality); ID3D10Texture2D_GetDesc(texture, &texture_desc); ok(texture_desc.Width == 320, "Got unexpected Width %u.\n", texture_desc.Width); ok(texture_desc.Height == 240, "Got unexpected Height %u.\n", texture_desc.Height); ok(texture_desc.MipLevels == 1, "Got unexpected MipLevels %u.\n", texture_desc.MipLevels); ok(texture_desc.ArraySize == 1, "Got unexpected ArraySize %u.\n", texture_desc.ArraySize); ok(texture_desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, "Got unexpected Format %#x.\n", texture_desc.Format); ok(texture_desc.SampleDesc.Count == 1, "Got unexpected SampleDesc.Count %u.\n", texture_desc.SampleDesc.Count); ok(!texture_desc.SampleDesc.Quality, "Got unexpected SampleDesc.Quality %u.\n", texture_desc.SampleDesc.Quality); ok(texture_desc.Usage == D3D10_USAGE_DEFAULT, "Got unexpected Usage %#x.\n", texture_desc.Usage); ok(texture_desc.BindFlags == D3D10_BIND_RENDER_TARGET, "Got unexpected BindFlags %#x.\n", texture_desc.BindFlags); ok(!texture_desc.CPUAccessFlags, "Got unexpected CPUAccessFlags %#x.\n", texture_desc.CPUAccessFlags); ok(!texture_desc.MiscFlags, "Got unexpected MiscFlags %#x.\n", texture_desc.MiscFlags); ID3D10Texture2D_Release(texture); IDXGISurface_Release(surface); hr = IDXGISwapChain_ResizeBuffers(swapchain, 0, 0, 0, DXGI_FORMAT_UNKNOWN, 0); ok(SUCCEEDED(hr), "Failed to resize buffers, hr %#x.\n", hr); hr = IDXGISwapChain_GetDesc(swapchain, &swapchain_desc); ok(SUCCEEDED(hr), "Failed to get swapchain desc, hr %#x.\n", hr); ok(swapchain_desc.BufferDesc.Width == client_rect.right - client_rect.left, "Got unexpected BufferDesc.Width %u, expected %u.\n", swapchain_desc.BufferDesc.Width, client_rect.right - client_rect.left); ok(swapchain_desc.BufferDesc.Height == client_rect.bottom - client_rect.top, "Got unexpected bufferDesc.Height %u, expected %u.\n", swapchain_desc.BufferDesc.Height, client_rect.bottom - client_rect.top); ok(swapchain_desc.BufferDesc.RefreshRate.Numerator == 60, "Got unexpected BufferDesc.RefreshRate.Numerator %u.\n", swapchain_desc.BufferDesc.RefreshRate.Numerator); ok(swapchain_desc.BufferDesc.RefreshRate.Denominator == 1, "Got unexpected BufferDesc.RefreshRate.Denominator %u.\n", swapchain_desc.BufferDesc.RefreshRate.Denominator); ok(swapchain_desc.BufferDesc.Format == DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, "Got unexpected BufferDesc.Format %#x.\n", swapchain_desc.BufferDesc.Format); ok(swapchain_desc.BufferDesc.ScanlineOrdering == DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED, "Got unexpected BufferDesc.ScanlineOrdering %#x.\n", swapchain_desc.BufferDesc.ScanlineOrdering); ok(swapchain_desc.BufferDesc.Scaling == DXGI_MODE_SCALING_UNSPECIFIED, "Got unexpected BufferDesc.Scaling %#x.\n", swapchain_desc.BufferDesc.Scaling); ok(swapchain_desc.SampleDesc.Count == 1, "Got unexpected SampleDesc.Count %u.\n", swapchain_desc.SampleDesc.Count); ok(!swapchain_desc.SampleDesc.Quality, "Got unexpected SampleDesc.Quality %u.\n", swapchain_desc.SampleDesc.Quality); ok(swapchain_desc.BufferUsage == DXGI_USAGE_RENDER_TARGET_OUTPUT, "Got unexpected BufferUsage %#x.\n", swapchain_desc.BufferUsage); ok(swapchain_desc.BufferCount == 1, "Got unexpected BufferCount %u.\n", swapchain_desc.BufferCount); ok(swapchain_desc.OutputWindow == window, "Got unexpected OutputWindow %p, expected %p.\n", swapchain_desc.OutputWindow, window); ok(swapchain_desc.Windowed, "Got unexpected Windowed %#x.\n", swapchain_desc.Windowed); ok(swapchain_desc.SwapEffect == DXGI_SWAP_EFFECT_DISCARD, "Got unexpected SwapEffect %#x.\n", swapchain_desc.SwapEffect); ok(!swapchain_desc.Flags, "Got unexpected Flags %#x.\n", swapchain_desc.Flags); IDXGISwapChain_Release(swapchain); refcount = IDXGIDevice_Release(device); ok(!refcount, "Device has %u references left.\n", refcount); DestroyWindow(window); }
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); }
static void test_parents(void) { DXGI_SURFACE_DESC surface_desc; IDXGISurface *surface; IDXGIFactory *factory; IDXGIAdapter *adapter; IDXGIDevice *device; IDXGIOutput *output; IUnknown *parent; ULONG refcount; HRESULT hr; if (!(device = create_device())) { skip("Failed to create device, skipping tests.\n"); return; } 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); refcount = IDXGIDevice_Release(device); ok(!refcount, "Device has %u references left.\n", refcount); }
static void test_adapter_desc(void) { DXGI_ADAPTER_DESC1 desc1; IDXGIAdapter1 *adapter1; DXGI_ADAPTER_DESC desc; IDXGIAdapter *adapter; IDXGIDevice *device; ULONG refcount; HRESULT hr; 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_GetDesc(adapter, NULL); ok(hr == E_INVALIDARG, "GetDesc returned %#x, expected %#x.\n", hr, E_INVALIDARG); hr = IDXGIAdapter_GetDesc(adapter, &desc); ok(SUCCEEDED(hr), "GetDesc failed, hr %#x.\n", hr); trace("%s.\n", wine_dbgstr_w(desc.Description)); trace("%04x: %04x:%04x (rev %02x).\n", desc.SubSysId, desc.VendorId, desc.DeviceId, desc.Revision); trace("Dedicated video memory: %lu (%lu MB).\n", desc.DedicatedVideoMemory, desc.DedicatedVideoMemory / (1024 * 1024)); trace("Dedicated system memory: %lu (%lu MB).\n", desc.DedicatedSystemMemory, desc.DedicatedSystemMemory / (1024 * 1024)); trace("Shared system memory: %lu (%lu MB).\n", desc.SharedSystemMemory, desc.SharedSystemMemory / (1024 * 1024)); trace("LUID: %08x:%08x.\n", desc.AdapterLuid.HighPart, desc.AdapterLuid.LowPart); hr = IDXGIAdapter_QueryInterface(adapter, &IID_IDXGIAdapter1, (void **)&adapter1); ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE), "Got unexpected hr %#x.\n", hr); if (hr == E_NOINTERFACE) goto done; hr = IDXGIAdapter1_GetDesc1(adapter1, &desc1); ok(SUCCEEDED(hr), "GetDesc1 failed, hr %#x.\n", hr); ok(!lstrcmpW(desc.Description, desc1.Description), "Got unexpected description %s.\n", wine_dbgstr_w(desc1.Description)); ok(desc1.VendorId == desc.VendorId, "Got unexpected vendor ID %04x.\n", desc1.VendorId); ok(desc1.DeviceId == desc.DeviceId, "Got unexpected device ID %04x.\n", desc1.DeviceId); ok(desc1.SubSysId == desc.SubSysId, "Got unexpected sub system ID %04x.\n", desc1.SubSysId); ok(desc1.Revision == desc.Revision, "Got unexpected revision %02x.\n", desc1.Revision); ok(desc1.DedicatedVideoMemory == desc.DedicatedVideoMemory, "Got unexpected dedicated video memory %lu.\n", desc1.DedicatedVideoMemory); ok(desc1.DedicatedSystemMemory == desc.DedicatedSystemMemory, "Got unexpected dedicated system memory %lu.\n", desc1.DedicatedSystemMemory); ok(desc1.SharedSystemMemory == desc.SharedSystemMemory, "Got unexpected shared system memory %lu.\n", desc1.SharedSystemMemory); ok(!memcmp(&desc.AdapterLuid, &desc1.AdapterLuid, sizeof(desc.AdapterLuid)), "Got unexpected adapter LUID %08x:%08x.\n", desc1.AdapterLuid.HighPart, desc1.AdapterLuid.LowPart); trace("Flags: %08x.\n", desc1.Flags); IDXGIAdapter1_Release(adapter1); done: IDXGIAdapter_Release(adapter); refcount = IDXGIDevice_Release(device); ok(!refcount, "Device has %u references left.\n", refcount); }
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); }
static void test_createswapchain(IDXGIDevice *device) { IUnknown *obj; IDXGIAdapter *adapter; IDXGIFactory *factory; IDXGISwapChain *swapchain; DXGI_SWAP_CHAIN_DESC creation_desc, result_desc; HRESULT hr; WNDCLASSA wc = {0}; UINT i; const struct refresh_rates refresh_list[] = { {60, 60, FALSE, FALSE}, {60, 0, TRUE, FALSE}, {60, 1, TRUE, TRUE}, { 0, 60, TRUE, FALSE}, { 0, 0, TRUE, FALSE}, }; wc.lpfnWndProc = DefWindowProcA; wc.lpszClassName = "dxgi_test_wc"; RegisterClassA(&wc); creation_desc.OutputWindow = 0; creation_desc.BufferDesc.Width = 800; creation_desc.BufferDesc.Height = 600; creation_desc.BufferDesc.RefreshRate.Numerator = 60; creation_desc.BufferDesc.RefreshRate.Denominator = 60; creation_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; creation_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; creation_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; creation_desc.SampleDesc.Count = 1; creation_desc.SampleDesc.Quality = 0; creation_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; creation_desc.BufferCount = 1; creation_desc.OutputWindow = CreateWindowA("dxgi_test_wc", "dxgi_test", 0, 0, 0, 0, 0, 0, 0, 0, 0); creation_desc.Windowed = TRUE; creation_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; creation_desc.Flags = 0; hr = IDXGIDevice_QueryInterface(device, &IID_IUnknown, (void **)&obj); ok(SUCCEEDED(hr), "IDXGIDevice does not implement IUnknown\n"); hr = IDXGIDevice_GetAdapter(device, &adapter); ok(SUCCEEDED(hr), "GetAdapter failed, hr %#x.\n", hr); hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory); ok(SUCCEEDED(hr), "GetParent failed, hr %#x.\n", hr); hr = IDXGIFactory_CreateSwapChain(factory, obj, &creation_desc, &swapchain); ok(SUCCEEDED(hr), "CreateSwapChain failed, hr %#x.\n", hr); hr = IDXGISwapChain_GetDesc(swapchain, NULL); ok(hr == E_INVALIDARG, "GetDesc unexpectedly returned %#x.\n", hr); IDXGISwapChain_Release(swapchain); for (i = 0; i < sizeof(refresh_list)/sizeof(refresh_list[0]); i++) { creation_desc.BufferDesc.RefreshRate.Numerator = refresh_list[i].numerator; creation_desc.BufferDesc.RefreshRate.Denominator = refresh_list[i].denominator; hr = IDXGIFactory_CreateSwapChain(factory, obj, &creation_desc, &swapchain); ok(SUCCEEDED(hr), "CreateSwapChain failed, hr %#x.\n", hr); hr = IDXGISwapChain_GetDesc(swapchain, &result_desc); ok(SUCCEEDED(hr), "GetDesc failed, hr %#x.\n", hr); if (refresh_list[i].numerator_should_pass) ok(result_desc.BufferDesc.RefreshRate.Numerator == refresh_list[i].numerator, "Numerator %u is %u.\n", i, result_desc.BufferDesc.RefreshRate.Numerator); else todo_wine ok(result_desc.BufferDesc.RefreshRate.Numerator == refresh_list[i].numerator, "Numerator %u is %u.\n", i, result_desc.BufferDesc.RefreshRate.Numerator); if (refresh_list[i].denominator_should_pass) ok(result_desc.BufferDesc.RefreshRate.Denominator == refresh_list[i].denominator, "Denominator %u is %u.\n", i ,result_desc.BufferDesc.RefreshRate.Denominator); else todo_wine ok(result_desc.BufferDesc.RefreshRate.Denominator == refresh_list[i].denominator, "Denominator %u is %u.\n", i, result_desc.BufferDesc.RefreshRate.Denominator); IDXGISwapChain_Release(swapchain); } creation_desc.Windowed = FALSE; for (i = 0; i < sizeof(refresh_list)/sizeof(refresh_list[0]); i++) { creation_desc.BufferDesc.RefreshRate.Numerator = refresh_list[i].numerator; creation_desc.BufferDesc.RefreshRate.Denominator = refresh_list[i].denominator; hr = IDXGIFactory_CreateSwapChain(factory, obj, &creation_desc, &swapchain); ok(SUCCEEDED(hr), "CreateSwapChain failed, hr %#x.\n", hr); hr = IDXGISwapChain_GetDesc(swapchain, &result_desc); ok(SUCCEEDED(hr), "GetDesc failed, hr %#x.\n", hr); if (refresh_list[i].numerator_should_pass) ok(result_desc.BufferDesc.RefreshRate.Numerator == refresh_list[i].numerator, "Numerator %u is %u.\n", i, result_desc.BufferDesc.RefreshRate.Numerator); else todo_wine ok(result_desc.BufferDesc.RefreshRate.Numerator == refresh_list[i].numerator, "Numerator %u is %u.\n", i, result_desc.BufferDesc.RefreshRate.Numerator); if (refresh_list[i].denominator_should_pass) ok(result_desc.BufferDesc.RefreshRate.Denominator == refresh_list[i].denominator, "Denominator %u is %u.\n", i ,result_desc.BufferDesc.RefreshRate.Denominator); else todo_wine ok(result_desc.BufferDesc.RefreshRate.Denominator == refresh_list[i].denominator, "Denominator %u is %u.\n", i, result_desc.BufferDesc.RefreshRate.Denominator); hr = IDXGISwapChain_SetFullscreenState(swapchain, FALSE, NULL); todo_wine ok(SUCCEEDED(hr), "SetFullscreenState failed, hr %#x.\n", hr); IDXGISwapChain_Release(swapchain); } IDXGIFactory_Release(factory); IDXGIAdapter_Release(adapter); IUnknown_Release(obj); }
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 d3d_init(struct MPGLContext *ctx) { HRESULT hr; struct priv *p = ctx->priv; struct vo *vo = ctx->vo; IDXGIDevice *dxgi_dev = NULL; IDXGIAdapter *dxgi_adapter = NULL; IDXGIAdapter1 *dxgi_adapter1 = NULL; IDXGIFactory *dxgi_factory = NULL; PFNEGLQUERYDISPLAYATTRIBEXTPROC eglQueryDisplayAttribEXT = (PFNEGLQUERYDISPLAYATTRIBEXTPROC)eglGetProcAddress("eglQueryDisplayAttribEXT"); PFNEGLQUERYDEVICEATTRIBEXTPROC eglQueryDeviceAttribEXT = (PFNEGLQUERYDEVICEATTRIBEXTPROC)eglGetProcAddress("eglQueryDeviceAttribEXT"); if (!eglQueryDisplayAttribEXT || !eglQueryDeviceAttribEXT) { MP_VERBOSE(vo, "Missing EGL_EXT_device_query\n"); goto done; } EGLAttrib dev_attr; if (!eglQueryDisplayAttribEXT(p->egl_display, EGL_DEVICE_EXT, &dev_attr)) { MP_VERBOSE(vo, "Missing EGL_EXT_device_query\n"); goto done; } // If ANGLE is in D3D11 mode, get the underlying ID3D11Device EGLDeviceEXT dev = (EGLDeviceEXT)dev_attr; EGLAttrib d3d11_dev_attr; if (eglQueryDeviceAttribEXT(dev, EGL_D3D11_DEVICE_ANGLE, &d3d11_dev_attr)) { ID3D11Device *d3d11_dev = (ID3D11Device*)d3d11_dev_attr; hr = ID3D11Device_QueryInterface(d3d11_dev, &IID_IDXGIDevice, (void**)&dxgi_dev); if (FAILED(hr)) { MP_ERR(vo, "Device is not a IDXGIDevice\n"); goto done; } hr = IDXGIDevice_GetAdapter(dxgi_dev, &dxgi_adapter); if (FAILED(hr)) { MP_ERR(vo, "Couldn't get IDXGIAdapter\n"); goto done; } // Windows 8 can choose a software adapter even if mpv didn't ask for // one. If this is the case, show a warning message. hr = IDXGIAdapter_QueryInterface(dxgi_adapter, &IID_IDXGIAdapter1, (void**)&dxgi_adapter1); if (SUCCEEDED(hr)) { DXGI_ADAPTER_DESC1 desc; hr = IDXGIAdapter1_GetDesc1(dxgi_adapter1, &desc); if (SUCCEEDED(hr)) { if (desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) show_sw_adapter_msg(ctx); // If the primary display adapter is a software adapter, the // DXGI_ADAPTER_FLAG_SOFTWARE won't be set, but the device IDs // should still match the Microsoft Basic Render Driver if (desc.VendorId == 0x1414 && desc.DeviceId == 0x8c) show_sw_adapter_msg(ctx); } } hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory, (void**)&dxgi_factory); if (FAILED(hr)) { MP_ERR(vo, "Couldn't get IDXGIFactory\n"); goto done; } // Prevent DXGI from making changes to the VO window, otherwise in // non-DirectComposition mode it will hook the Alt+Enter keystroke and // make it trigger an ugly transition to exclusive fullscreen mode // instead of running the user-set command. IDXGIFactory_MakeWindowAssociation(dxgi_factory, vo_w32_hwnd(vo), DXGI_MWA_NO_WINDOW_CHANGES | DXGI_MWA_NO_ALT_ENTER | DXGI_MWA_NO_PRINT_SCREEN); } done: if (dxgi_dev) IDXGIDevice_Release(dxgi_dev); if (dxgi_adapter) IDXGIAdapter_Release(dxgi_adapter); if (dxgi_adapter1) IDXGIAdapter1_Release(dxgi_adapter1); if (dxgi_factory) IDXGIFactory_Release(dxgi_factory); }
HRESULT dxgi_factory_init(struct dxgi_factory *factory) { HRESULT hr; UINT i; factory->vtbl = &dxgi_factory_vtbl; factory->refcount = 1; EnterCriticalSection(&dxgi_cs); factory->wined3d = WineDirect3DCreate(10, (IUnknown *)factory); if (!factory->wined3d) { LeaveCriticalSection(&dxgi_cs); return DXGI_ERROR_UNSUPPORTED; } factory->adapter_count = IWineD3D_GetAdapterCount(factory->wined3d); LeaveCriticalSection(&dxgi_cs); factory->adapters = HeapAlloc(GetProcessHeap(), 0, factory->adapter_count * sizeof(*factory->adapters)); if (!factory->adapters) { ERR("Failed to allocate DXGI adapter array memory.\n"); hr = E_OUTOFMEMORY; goto fail; } for (i = 0; i < factory->adapter_count; ++i) { struct dxgi_adapter *adapter = HeapAlloc(GetProcessHeap(), 0, sizeof(*adapter)); if (!adapter) { UINT j; ERR("Failed to allocate DXGI adapter memory.\n"); for (j = 0; j < i; ++j) { IDXGIAdapter_Release(factory->adapters[j]); } hr = E_OUTOFMEMORY; goto fail; } hr = dxgi_adapter_init(adapter, (IWineDXGIFactory *)factory, i); if (FAILED(hr)) { UINT j; ERR("Failed to initialize adapter, hr %#x.\n", hr); HeapFree(GetProcessHeap(), 0, adapter); for (j = 0; j < i; ++j) { IDXGIAdapter_Release(factory->adapters[j]); } goto fail; } factory->adapters[i] = (IDXGIAdapter *)adapter; } return S_OK; fail: HeapFree(GetProcessHeap(), 0, factory->adapters); EnterCriticalSection(&dxgi_cs); IWineD3D_Release(factory->wined3d); LeaveCriticalSection(&dxgi_cs); return hr; }