d3drm: Implement IDirect3DRM::CreateDeviceFromClipper.

This commit is contained in:
Aaryaman Vasishta 2015-08-07 03:17:53 +05:30 committed by Alexandre Julliard
parent b6f197c7a8
commit 1075d71135
5 changed files with 190 additions and 14 deletions

View File

@ -1,6 +1,6 @@
MODULE = d3drm.dll
IMPORTLIB = d3drm
IMPORTS = dxguid uuid d3dxof
IMPORTS = dxguid uuid d3dxof ddraw
C_SRCS = \
d3drm.c \

View File

@ -283,17 +283,48 @@ static HRESULT WINAPI d3drm1_CreateDeviceFromClipper(IDirect3DRM *iface,
IDirect3DRMDevice **device)
{
struct d3drm_device *object;
IDirectDraw *ddraw;
IDirectDrawSurface *render_target;
HRESULT hr;
FIXME("iface %p, clipper %p, guid %s, width %d, height %d, device %p.\n",
TRACE("iface %p, clipper %p, guid %s, width %d, height %d, device %p.\n",
iface, clipper, debugstr_guid(guid), width, height, device);
hr = d3drm_device_create(&object);
if (!device)
return D3DRMERR_BADVALUE;
*device = NULL;
if (!clipper || !width || !height)
return D3DRMERR_BADVALUE;
hr = DirectDrawCreate(NULL, &ddraw, NULL);
if (FAILED(hr))
return hr;
*device = IDirect3DRMDevice_from_impl(object);
hr = d3drm_device_create(&object);
if (FAILED(hr))
{
IDirectDraw_Release(ddraw);
return hr;
}
return D3DRM_OK;
hr = d3drm_device_create_surfaces_from_clipper(object, ddraw, clipper, width, height, &render_target);
if (FAILED(hr))
{
IDirectDraw_Release(ddraw);
d3drm_device_destroy(object);
return hr;
}
hr = d3drm_device_init(object, 1, iface, ddraw, render_target);
IDirectDraw_Release(ddraw);
IDirectDrawSurface_Release(render_target);
if (FAILED(hr))
d3drm_device_destroy(object);
else
*device = IDirect3DRMDevice_from_impl(object);
return hr;
}
static HRESULT WINAPI d3drm1_CreateTextureFromSurface(IDirect3DRM *iface,

View File

@ -44,6 +44,11 @@ HRESULT load_mesh_data(IDirect3DRMMeshBuilder3 *iface, IDirectXFileData *data,
void d3drm_device_destroy(struct d3drm_device *device) DECLSPEC_HIDDEN;
HRESULT d3drm_device_create_surfaces_from_clipper(struct d3drm_device *object, IDirectDraw *ddraw, IDirectDrawClipper *clipper, int width, int height,
IDirectDrawSurface **surface) DECLSPEC_HIDDEN;
HRESULT d3drm_device_init(struct d3drm_device *device, UINT version, IDirect3DRM *d3drm, IDirectDraw *ddraw, IDirectDrawSurface *surface) DECLSPEC_HIDDEN;
struct d3drm_file_header
{
WORD major;

View File

@ -37,6 +37,11 @@ struct d3drm_device
IDirect3DRMDevice2 IDirect3DRMDevice2_iface;
IDirect3DRMDevice3 IDirect3DRMDevice3_iface;
IDirect3DRMWinDevice IDirect3DRMWinDevice_iface;
IDirect3DRM *d3drm;
IDirectDraw *ddraw;
IDirectDrawSurface *primary_surface, *render_target;
IDirectDrawClipper *clipper;
IDirect3DDevice *device;
LONG ref;
BOOL dither;
D3DRMRENDERQUALITY quality;
@ -77,6 +82,24 @@ IDirect3DRMDevice3 *IDirect3DRMDevice3_from_impl(struct d3drm_device *device)
void d3drm_device_destroy(struct d3drm_device *device)
{
if (device->device)
{
TRACE("Releasing attached ddraw interfaces.\n");
IDirect3DDevice_Release(device->device);
}
if (device->render_target)
IDirectDrawSurface_Release(device->render_target);
if (device->primary_surface)
{
TRACE("Releasing primary surface and attached clipper.\n");
IDirectDrawSurface_Release(device->primary_surface);
IDirectDrawClipper_Release(device->clipper);
}
if (device->ddraw)
{
IDirectDraw_Release(device->ddraw);
IDirect3DRM_Release(device->d3drm);
}
HeapFree(GetProcessHeap(), 0, device);
}
@ -85,6 +108,123 @@ static inline struct d3drm_device *impl_from_IDirect3DRMWinDevice(IDirect3DRMWin
return CONTAINING_RECORD(iface, struct d3drm_device, IDirect3DRMWinDevice_iface);
}
HRESULT d3drm_device_create_surfaces_from_clipper(struct d3drm_device *object, IDirectDraw *ddraw, IDirectDrawClipper *clipper, int width, int height, IDirectDrawSurface **surface)
{
DDSURFACEDESC surface_desc;
IDirectDrawSurface *primary_surface, *render_target;
HWND window;
HRESULT hr;
hr = IDirectDrawClipper_GetHWnd(clipper, &window);
if (FAILED(hr))
return hr;
hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
if (FAILED(hr))
return hr;
memset(&surface_desc, 0, sizeof(surface_desc));
surface_desc.dwSize = sizeof(surface_desc);
surface_desc.dwFlags = DDSD_CAPS;
surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &primary_surface, NULL);
if (FAILED(hr))
return hr;
hr = IDirectDrawSurface_SetClipper(primary_surface, clipper);
if (FAILED(hr))
{
IDirectDrawSurface_Release(primary_surface);
return hr;
}
memset(&surface_desc, 0, sizeof(surface_desc));
surface_desc.dwSize = sizeof(surface_desc);
surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
surface_desc.dwWidth = width;
surface_desc.dwHeight = height;
hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &render_target, NULL);
if (FAILED(hr))
{
IDirectDrawSurface_Release(primary_surface);
return hr;
}
object->primary_surface = primary_surface;
object->clipper = clipper;
IDirectDrawClipper_AddRef(clipper);
*surface = render_target;
return D3DRM_OK;
}
HRESULT d3drm_device_init(struct d3drm_device *device, UINT version, IDirect3DRM *d3drm, IDirectDraw *ddraw, IDirectDrawSurface *surface)
{
IDirectDrawSurface *ds = NULL;
IDirect3DDevice *device1 = NULL;
IDirect3DDevice2 *device2 = NULL;
IDirect3D2 *d3d2 = NULL;
DDSURFACEDESC desc, surface_desc;
HRESULT hr;
device->ddraw = ddraw;
IDirectDraw_AddRef(ddraw);
device->d3drm = d3drm;
IDirect3DRM_AddRef(d3drm);
device->render_target = surface;
IDirectDrawSurface_AddRef(surface);
desc.dwSize = sizeof(desc);
hr = IDirectDrawSurface_GetSurfaceDesc(surface, &desc);
if (FAILED(hr))
return hr;
memset(&surface_desc, 0, sizeof(surface_desc));
surface_desc.dwSize = sizeof(surface_desc);
surface_desc.dwFlags = DDSD_CAPS | DDSD_ZBUFFERBITDEPTH | DDSD_WIDTH | DDSD_HEIGHT;
surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
surface_desc.dwZBufferBitDepth = 16;
surface_desc.dwWidth = desc.dwWidth;
surface_desc.dwHeight = desc.dwHeight;
hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &ds, NULL);
if (FAILED(hr))
return hr;
hr = IDirectDrawSurface_AddAttachedSurface(surface, ds);
IDirectDrawSurface_Release(ds);
if (FAILED(hr))
return hr;
if (version == 1)
hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirect3DRGBDevice, (void **)&device1);
else
{
IDirectDraw_QueryInterface(ddraw, &IID_IDirect3D2, (void**)&d3d2);
hr = IDirect3D2_CreateDevice(d3d2, &IID_IDirect3DRGBDevice, surface, &device2);
IDirect3D2_Release(d3d2);
}
if (FAILED(hr))
{
IDirectDrawSurface_DeleteAttachedSurface(surface, 0, ds);
return hr;
}
if (version != 1)
{
hr = IDirect3DDevice2_QueryInterface(device2, &IID_IDirect3DDevice, (void**)&device1);
IDirect3DDevice2_Release(device2);
if (FAILED(hr))
{
IDirectDrawSurface_DeleteAttachedSurface(surface, 0, ds);
return hr;
}
}
device->device = device1;
return hr;
}
static HRESULT WINAPI d3drm_device1_QueryInterface(IDirect3DRMDevice *iface, REFIID riid, void **out)
{
struct d3drm_device *device = impl_from_IDirect3DRMDevice(iface);

View File

@ -1967,7 +1967,7 @@ static void test_create_device_from_clipper1(void)
IDirect3DRM *d3drm1 = NULL;
IDirectDraw *ddraw = NULL;
IUnknown *unknown = NULL;
IDirect3DRMDevice *device1 = NULL;
IDirect3DRMDevice *device1 = (IDirect3DRMDevice *)0xdeadbeef;
IDirect3DDevice *d3ddevice1 = NULL;
IDirectDrawClipper *clipper = NULL, *d3drm_clipper = NULL;
IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_primary = NULL;
@ -1993,22 +1993,22 @@ static void test_create_device_from_clipper1(void)
cref1 = get_refcount((IUnknown *)clipper);
hr = IDirect3DRM_CreateDeviceFromClipper(d3drm1, clipper, &driver, 0, 0, &device1);
todo_wine ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
if (SUCCEEDED(hr))
IDirect3DRMDevice_Release(device1);
ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
ok(device1 == NULL, "Expected device returned == NULL, got %p.\n", device1);
/* If NULL is passed for clipper, CreateDeviceFromClipper returns D3DRMERR_BADVALUE */
hr = IDirect3DRM_CreateDeviceFromClipper(d3drm1, NULL, &driver, 300, 200, &device1);
todo_wine ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
if (SUCCEEDED(hr))
IDirect3DRMDevice_Release(device1);
ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
hr = IDirect3DRM_CreateDeviceFromClipper(d3drm1, clipper, &driver, 300, 200, NULL);
ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
hr = IDirect3DRM_CreateDeviceFromClipper(d3drm1, clipper, &driver, 300, 200, &device1);
ok(hr == D3DRM_OK, "Cannot create IDirect3DRMDevice interface (hr = %x).\n", hr);
ref2 = get_refcount((IUnknown *)d3drm1);
todo_wine ok(ref2 > ref1, "expected ref2 > ref1, got ref1 = %u , ref2 = %u.\n", ref1, ref2);
ok(ref2 > ref1, "expected ref2 > ref1, got ref1 = %u , ref2 = %u.\n", ref1, ref2);
cref2 = get_refcount((IUnknown *)clipper);
todo_wine ok(cref2 > cref1, "expected cref2 > cref1, got cref1 = %u , cref2 = %u.\n", cref1, cref2);
ok(cref2 > cref1, "expected cref2 > cref1, got cref1 = %u , cref2 = %u.\n", cref1, cref2);
/* Fetch immediate mode device in order to access render target */
hr = IDirect3DRMDevice_GetDirect3DDevice(device1, &d3ddevice1);