d3d9: Implement Direct3DCreate9Ex + tests.

This commit is contained in:
Stefan Dösinger 2008-02-28 21:31:25 +01:00 committed by Alexandre Julliard
parent c1a0037b88
commit d7098076e1
4 changed files with 221 additions and 0 deletions

View File

@ -9,3 +9,4 @@
@ stdcall D3DPERF_QueryRepeatFrame() @ stdcall D3DPERF_QueryRepeatFrame()
@ stdcall D3DPERF_SetMarker(long wstr) @ stdcall D3DPERF_SetMarker(long wstr)
@ stdcall D3DPERF_SetRegion(long wstr) @ stdcall D3DPERF_SetRegion(long wstr)
@ stdcall Direct3DCreate9Ex(long ptr)

View File

@ -61,6 +61,23 @@ IDirect3D9* WINAPI Direct3DCreate9(UINT SDKVersion) {
return (IDirect3D9*) object; return (IDirect3D9*) object;
} }
HRESULT WINAPI Direct3DCreate9Ex(UINT SDKVersion, IDirect3D9Ex **direct3d9ex) {
IDirect3D9 *ret;
IDirect3D9Impl* object;
TRACE("Calling Direct3DCreate9\n");
ret = Direct3DCreate9(SDKVersion);
if(!ret) {
*direct3d9ex = NULL;
return D3DERR_NOTAVAILABLE;
}
object = (IDirect3D9Impl *) ret;
object->extended = TRUE; /* Enables QI for extended interfaces */
*direct3d9ex = (IDirect3D9Ex *) object;
return D3D_OK;
}
/******************************************************************* /*******************************************************************
* Direct3DShaderValidatorCreate9 (D3D9.@) * Direct3DShaderValidatorCreate9 (D3D9.@)
* *

View File

@ -7,6 +7,7 @@ IMPORTS = user32 kernel32
EXTRALIBS = -ldxerr9 -luuid -ldxguid EXTRALIBS = -ldxerr9 -luuid -ldxguid
CTESTS = \ CTESTS = \
d3d9ex.c \
device.c \ device.c \
query.c \ query.c \
shader.c \ shader.c \

202
dlls/d3d9/tests/d3d9ex.c Normal file
View File

@ -0,0 +1,202 @@
/*
* Copyright (C) 2008 Stefan Dösinger(for CodeWeavers)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
/* This file contains tests specific to IDirect3D9Ex and IDirect3DDevice9Ex, like
* how to obtain them. For testing rendering with extended functions use visual.c
*/
#define COBJMACROS
#include <d3d9.h>
#include <dxerr9.h>
#include "wine/test.h"
static HMODULE d3d9_handle = 0;
static IDirect3D9 * (WINAPI *pDirect3DCreate9)(UINT SDKVersion);
static HRESULT (WINAPI *pDirect3DCreate9Ex)(UINT SDKVersion, IDirect3D9Ex **d3d9ex);
static HWND create_window(void)
{
WNDCLASS wc = {0};
HWND ret;
wc.lpfnWndProc = &DefWindowProc;
wc.lpszClassName = "d3d9_test_wc";
RegisterClass(&wc);
ret = CreateWindow("d3d9_test_wc", "d3d9_test",
WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION , 0, 0, 640, 480, 0, 0, 0, 0);
return ret;
}
static unsigned long getref(IUnknown *obj) {
IUnknown_AddRef(obj);
return IUnknown_Release(obj);
}
static void test_qi_base_to_ex(void)
{
IDirect3D9 *d3d9 = pDirect3DCreate9(D3D_SDK_VERSION);
IDirect3D9Ex *d3d9ex = (void *) 0xdeadbeef;
IDirect3DDevice9 *device;
IDirect3DDevice9Ex *deviceEx = (void *) 0xdeadbeef;
HRESULT hr;
HWND window = create_window();
D3DPRESENT_PARAMETERS present_parameters;
hr = IDirect3D9_QueryInterface(d3d9, &IID_IDirect3D9Ex, (void **) &d3d9ex);
ok(hr == E_NOINTERFACE,
"IDirect3D9::QueryInterface for IID_IDirect3D9Ex returned %s, expected E_NOINTERFACE\n",
DXGetErrorString9(hr));
ok(d3d9ex == NULL, "QueryInterface returned interface %p, expected NULL\n", d3d9ex);
if(d3d9ex) IDirect3D9Ex_Release(d3d9ex);
memset(&present_parameters, 0, sizeof(present_parameters));
present_parameters.Windowed = TRUE;
present_parameters.hDeviceWindow = window;
present_parameters.SwapEffect = D3DSWAPEFFECT_COPY;
present_parameters.BackBufferWidth = 640;
present_parameters.BackBufferHeight = 480;
present_parameters.EnableAutoDepthStencil = FALSE;
present_parameters.AutoDepthStencilFormat = D3DFMT_D16;
hr = IDirect3D9_CreateDevice(d3d9, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, present_parameters.hDeviceWindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device);
if(FAILED(hr)) {
skip("Failed to create a regular Direct3DDevice9, skipping QI tests\n");
goto out;
}
hr = IDirect3DDevice9_QueryInterface(device, &IID_IDirect3DDevice9Ex, (void **) &deviceEx);
ok(hr == E_NOINTERFACE,
"IDirect3D9Device::QueryInterface for IID_IDirect3DDevice9Ex returned %s, expected E_NOINTERFACE\n",
DXGetErrorString9(hr));
ok(deviceEx == NULL, "QueryInterface returned interface %p, expected NULL\n", deviceEx);
if(deviceEx) IDirect3DDevice9Ex_Release(deviceEx);
IDirect3DDevice9_Release(device);
out:
IDirect3D9_Release(d3d9);
DestroyWindow(window);
}
static void test_qi_ex_to_base(void)
{
IDirect3D9 *d3d9 = (void *) 0xdeadbeef;
IDirect3D9Ex *d3d9ex;
IDirect3DDevice9 *device;
IDirect3DDevice9Ex *deviceEx = (void *) 0xdeadbeef;
HRESULT hr;
HWND window = create_window();
D3DPRESENT_PARAMETERS present_parameters;
unsigned long ref;
hr = pDirect3DCreate9Ex(D3D_SDK_VERSION, &d3d9ex);
ok(hr == D3D_OK || hr == D3DERR_NOTAVAILABLE, "Direct3DCreate9Ex returned %s\n", DXGetErrorString9(hr));
if(FAILED(hr)) {
skip("Direct3D9Ex is not available\n");
goto out;
}
hr = IDirect3D9Ex_QueryInterface(d3d9ex, &IID_IDirect3D9, (void **) &d3d9);
ok(hr == D3D_OK,
"IDirect3D9Ex::QueryInterface for IID_IDirect3D9 returned %s, expected D3D_OK\n",
DXGetErrorString9(hr));
ok(d3d9 != NULL && d3d9 != (void *) 0xdeadbeef,
"QueryInterface returned interface %p, expected != NULL && != 0xdeadbeef\n", d3d9);
ref = getref((IUnknown *) d3d9ex);
ok(ref == 2, "IDirect3D9Ex refcount is %ld, expected 2\n", ref);
ref = getref((IUnknown *) d3d9);
ok(ref == 2, "IDirect3D9 refcount is %ld, expected 2\n", ref);
memset(&present_parameters, 0, sizeof(present_parameters));
present_parameters.Windowed = TRUE;
present_parameters.hDeviceWindow = window;
present_parameters.SwapEffect = D3DSWAPEFFECT_COPY;
present_parameters.BackBufferWidth = 640;
present_parameters.BackBufferHeight = 480;
present_parameters.EnableAutoDepthStencil = FALSE;
present_parameters.AutoDepthStencilFormat = D3DFMT_D16;
/* First, try to create a normal device with IDirect3D9Ex::CreateDevice and QI it for IDirect3DDevice9Ex */
hr = IDirect3D9Ex_CreateDevice(d3d9ex, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, present_parameters.hDeviceWindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device);
if(FAILED(hr)) {
skip("Failed to create a regular Direct3DDevice9, skipping QI tests\n");
goto out;
}
hr = IDirect3DDevice9_QueryInterface(device, &IID_IDirect3DDevice9Ex, (void **) &deviceEx);
ok(hr == D3D_OK,
"IDirect3D9Device::QueryInterface for IID_IDirect3DDevice9Ex returned %s, expected D3D_OK\n",
DXGetErrorString9(hr));
ok(deviceEx != NULL && deviceEx != (void *) 0xdeadbeef,
"QueryInterface returned interface %p, expected != NULL && != 0xdeadbeef\n", deviceEx);
ref = getref((IUnknown *) device);
ok(ref == 2, "IDirect3DDevice9 refcount is %ld, expected 2\n", ref);
ref = getref((IUnknown *) deviceEx);
ok(ref == 2, "IDirect3DDevice9Ex refcount is %ld, expected 2\n", ref);
if(deviceEx) IDirect3DDevice9Ex_Release(deviceEx);
IDirect3DDevice9_Release(device);
/* Next, try to create a normal device with IDirect3D9::CreateDevice(non-ex) and QI it */
hr = IDirect3D9_CreateDevice(d3d9, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, present_parameters.hDeviceWindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device);
if(FAILED(hr)) {
skip("Failed to create a regular Direct3DDevice9, skipping QI tests\n");
goto out;
}
hr = IDirect3DDevice9_QueryInterface(device, &IID_IDirect3DDevice9Ex, (void **) &deviceEx);
ok(hr == D3D_OK,
"IDirect3D9Device::QueryInterface for IID_IDirect3DDevice9Ex returned %s, expected D3D_OK\n",
DXGetErrorString9(hr));
ok(deviceEx != NULL && deviceEx != (void *) 0xdeadbeef,
"QueryInterface returned interface %p, expected != NULL && != 0xdeadbeef\n", deviceEx);
ref = getref((IUnknown *) device);
ok(ref == 2, "IDirect3DDevice9 refcount is %ld, expected 2\n", ref);
ref = getref((IUnknown *) deviceEx);
ok(ref == 2, "IDirect3DDevice9Ex refcount is %ld, expected 2\n", ref);
if(deviceEx) IDirect3DDevice9Ex_Release(deviceEx);
IDirect3DDevice9_Release(device);
IDirect3D9_Release(d3d9);
out:
DestroyWindow(window);
}
START_TEST(d3d9ex)
{
d3d9_handle = LoadLibraryA("d3d9.dll");
if (!d3d9_handle)
{
skip("Could not load d3d9.dll\n");
return;
}
pDirect3DCreate9 = (void *)GetProcAddress(d3d9_handle, "Direct3DCreate9");
ok(pDirect3DCreate9 != NULL, "Failed to get address of Direct3DCreate9\n");
if(!pDirect3DCreate9) {
return;
}
pDirect3DCreate9Ex = (void *)GetProcAddress(d3d9_handle, "Direct3DCreate9Ex");
if (!pDirect3DCreate9Ex) {
skip("Failed to get address of Direct3DCreate9Ex\n");
return;
}
test_qi_base_to_ex();
test_qi_ex_to_base();
}