Commit 12967d88 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

d3drm: Consolidate GetClassName() implementation, reduce tests duplication.

parent 292f8266
......@@ -39,11 +39,12 @@ BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, void *reserved)
return TRUE;
}
void d3drm_object_init(struct d3drm_object *object)
void d3drm_object_init(struct d3drm_object *object, const char *classname)
{
object->ref = 1;
object->appdata = 0;
list_init(&object->destroy_callbacks);
object->classname = classname;
}
struct destroy_callback
......@@ -91,6 +92,25 @@ HRESULT d3drm_object_delete_destroy_callback(struct d3drm_object *object, D3DRMO
return D3DRM_OK;
}
HRESULT d3drm_object_get_class_name(struct d3drm_object *object, DWORD *size, char *name)
{
DWORD req_size;
if (!size)
return E_INVALIDARG;
req_size = strlen(object->classname) + 1;
if (name && *size < req_size)
return E_INVALIDARG;
*size = req_size;
if (name)
memcpy(name, object->classname, req_size);
return D3DRM_OK;
}
void d3drm_object_cleanup(IDirect3DRMObject *iface, struct d3drm_object *object)
{
struct destroy_callback *callback, *callback2;
......
......@@ -41,6 +41,7 @@ struct d3drm_object
LONG ref;
DWORD appdata;
struct list destroy_callbacks;
const char *classname;
};
struct d3drm_texture
......@@ -56,6 +57,7 @@ struct d3drm_texture
struct d3drm_frame
{
struct d3drm_object obj;
IDirect3DRMFrame IDirect3DRMFrame_iface;
IDirect3DRMFrame2 IDirect3DRMFrame2_iface;
IDirect3DRMFrame3 IDirect3DRMFrame3_iface;
......@@ -117,9 +119,10 @@ void d3drm_device_destroy(struct d3drm_device *device) DECLSPEC_HIDDEN;
HRESULT d3drm_device_init(struct d3drm_device *device, UINT version, IDirectDraw *ddraw,
IDirectDrawSurface *surface, BOOL create_z_surface) DECLSPEC_HIDDEN;
void d3drm_object_init(struct d3drm_object *object) DECLSPEC_HIDDEN;
void d3drm_object_init(struct d3drm_object *object, const char *classname) DECLSPEC_HIDDEN;
HRESULT d3drm_object_add_destroy_callback(struct d3drm_object *object, D3DRMOBJECTCALLBACK cb, void *ctx) DECLSPEC_HIDDEN;
HRESULT d3drm_object_delete_destroy_callback(struct d3drm_object *object, D3DRMOBJECTCALLBACK cb, void *ctx) DECLSPEC_HIDDEN;
HRESULT d3drm_object_get_class_name(struct d3drm_object *object, DWORD *size, char *name) DECLSPEC_HIDDEN;
void d3drm_object_cleanup(IDirect3DRMObject *iface, struct d3drm_object *object) DECLSPEC_HIDDEN;
struct d3drm_frame *unsafe_impl_from_IDirect3DRMFrame(IDirect3DRMFrame *iface) DECLSPEC_HIDDEN;
......
......@@ -554,15 +554,11 @@ static HRESULT WINAPI d3drm_device1_GetName(IDirect3DRMDevice *iface, DWORD *siz
static HRESULT WINAPI d3drm_device3_GetClassName(IDirect3DRMDevice3 *iface, DWORD *size, char *name)
{
TRACE("iface %p, size %p, name %p.\n", iface, size, name);
if (!size || *size < strlen("Device") || !name)
return E_INVALIDARG;
struct d3drm_device *device = impl_from_IDirect3DRMDevice3(iface);
strcpy(name, "Device");
*size = sizeof("Device");
TRACE("iface %p, size %p, name %p.\n", iface, size, name);
return D3DRM_OK;
return d3drm_object_get_class_name(&device->obj, size, name);
}
static HRESULT WINAPI d3drm_device2_GetClassName(IDirect3DRMDevice2 *iface, DWORD *size, char *name)
......@@ -1630,6 +1626,7 @@ struct d3drm_device *unsafe_impl_from_IDirect3DRMDevice3(IDirect3DRMDevice3 *ifa
HRESULT d3drm_device_create(struct d3drm_device **device, IDirect3DRM *d3drm)
{
static const char classname[] = "Device";
struct d3drm_device *object;
TRACE("device %p, d3drm %p.\n", device, d3drm);
......@@ -1642,7 +1639,7 @@ HRESULT d3drm_device_create(struct d3drm_device **device, IDirect3DRM *d3drm)
object->IDirect3DRMDevice3_iface.lpVtbl = &d3drm_device3_vtbl;
object->IDirect3DRMWinDevice_iface.lpVtbl = &d3drm_device_win_vtbl;
object->d3drm = d3drm;
d3drm_object_init(&object->obj);
d3drm_object_init(&object->obj, classname);
*device = object;
......
......@@ -27,6 +27,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(d3drm);
struct d3drm_face
{
struct d3drm_object obj;
IDirect3DRMFace IDirect3DRMFace_iface;
IDirect3DRMFace2 IDirect3DRMFace2_iface;
LONG ref;
......@@ -402,15 +403,11 @@ static HRESULT WINAPI d3drm_face2_GetName(IDirect3DRMFace2 *iface, DWORD *size,
static HRESULT WINAPI d3drm_face2_GetClassName(IDirect3DRMFace2 *iface, DWORD *size, char *name)
{
TRACE("iface %p, size %p, name %p.\n", iface, size, name);
if (!size || *size < strlen("Face") || !name)
return E_INVALIDARG;
struct d3drm_face *face = impl_from_IDirect3DRMFace2(iface);
strcpy(name, "Face");
*size = sizeof("Face");
TRACE("iface %p, size %p, name %p.\n", iface, size, name);
return D3DRM_OK;
return d3drm_object_get_class_name(&face->obj, size, name);
}
static HRESULT WINAPI d3drm_face2_AddVertex(IDirect3DRMFace2 *iface, D3DVALUE x, D3DVALUE y, D3DVALUE z)
......@@ -588,6 +585,7 @@ static const struct IDirect3DRMFace2Vtbl d3drm_face2_vtbl =
HRESULT Direct3DRMFace_create(REFIID riid, IUnknown **out)
{
static const char classname[] = "Face";
struct d3drm_face *object;
TRACE("riid %s, out %p.\n", debugstr_guid(riid), out);
......@@ -599,6 +597,8 @@ HRESULT Direct3DRMFace_create(REFIID riid, IUnknown **out)
object->IDirect3DRMFace2_iface.lpVtbl = &d3drm_face2_vtbl;
object->ref = 1;
d3drm_object_init(&object->obj, classname);
if (IsEqualGUID(riid, &IID_IDirect3DRMFace2))
*out = (IUnknown*)&object->IDirect3DRMFace2_iface;
else
......
......@@ -730,15 +730,11 @@ static HRESULT WINAPI d3drm_frame1_GetName(IDirect3DRMFrame *iface, DWORD *size,
static HRESULT WINAPI d3drm_frame3_GetClassName(IDirect3DRMFrame3 *iface, DWORD *size, char *name)
{
TRACE("iface %p, size %p, name %p.\n", iface, size, name);
if (!size || *size < strlen("Frame") || !name)
return E_INVALIDARG;
struct d3drm_frame *frame = impl_from_IDirect3DRMFrame3(iface);
strcpy(name, "Frame");
*size = sizeof("Frame");
TRACE("iface %p, size %p, name %p.\n", iface, size, name);
return D3DRM_OK;
return d3drm_object_get_class_name(&frame->obj, size, name);
}
static HRESULT WINAPI d3drm_frame2_GetClassName(IDirect3DRMFrame2 *iface, DWORD *size, char *name)
......@@ -2930,6 +2926,7 @@ struct d3drm_frame *unsafe_impl_from_IDirect3DRMFrame(IDirect3DRMFrame *iface)
HRESULT d3drm_frame_create(struct d3drm_frame **frame, IUnknown *parent_frame, IDirect3DRM *d3drm)
{
static const char classname[] = "Frame";
struct d3drm_frame *object;
HRESULT hr = D3DRM_OK;
......@@ -2945,6 +2942,8 @@ HRESULT d3drm_frame_create(struct d3drm_frame **frame, IUnknown *parent_frame, I
object->ref = 1;
d3drm_set_color(&object->scenebackground, 0.0f, 0.0f, 0.0f, 1.0f);
d3drm_object_init(&object->obj, classname);
memcpy(object->transform, identity, sizeof(D3DRMMATRIX4D));
if (parent_frame)
......
......@@ -27,6 +27,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(d3drm);
struct d3drm_light
{
struct d3drm_object obj;
IDirect3DRMLight IDirect3DRMLight_iface;
LONG ref;
D3DRMLIGHTTYPE type;
......@@ -139,15 +140,11 @@ static HRESULT WINAPI d3drm_light_GetName(IDirect3DRMLight *iface, DWORD *size,
static HRESULT WINAPI d3drm_light_GetClassName(IDirect3DRMLight *iface, DWORD *size, char *name)
{
TRACE("iface %p, size %p, name %p.\n", iface, size, name);
if (!size || *size < strlen("Light") || !name)
return E_INVALIDARG;
struct d3drm_light *light = impl_from_IDirect3DRMLight(iface);
strcpy(name, "Light");
*size = sizeof("Light");
TRACE("iface %p, size %p, name %p.\n", iface, size, name);
return D3DRM_OK;
return d3drm_object_get_class_name(&light->obj, size, name);
}
static HRESULT WINAPI d3drm_light_SetType(IDirect3DRMLight *iface, D3DRMLIGHTTYPE type)
......@@ -372,6 +369,7 @@ static const struct IDirect3DRMLightVtbl d3drm_light_vtbl =
HRESULT Direct3DRMLight_create(IUnknown **out)
{
static const char classname[] = "Light";
struct d3drm_light *object;
TRACE("out %p.\n", out);
......@@ -382,6 +380,8 @@ HRESULT Direct3DRMLight_create(IUnknown **out)
object->IDirect3DRMLight_iface.lpVtbl = &d3drm_light_vtbl;
object->ref = 1;
d3drm_object_init(&object->obj, classname);
*out = (IUnknown *)&object->IDirect3DRMLight_iface;
return S_OK;
......
......@@ -34,6 +34,7 @@ struct color_rgb
struct d3drm_material
{
struct d3drm_object obj;
IDirect3DRMMaterial2 IDirect3DRMMaterial2_iface;
LONG ref;
struct color_rgb emissive;
......@@ -143,15 +144,11 @@ static HRESULT WINAPI d3drm_material_GetName(IDirect3DRMMaterial2 *iface, DWORD
static HRESULT WINAPI d3drm_material_GetClassName(IDirect3DRMMaterial2 *iface, DWORD *size, char *name)
{
TRACE("iface %p, size %p, name %p.\n", iface, size, name);
if (!size || *size < strlen("Material") || !name)
return E_INVALIDARG;
struct d3drm_material *material = impl_from_IDirect3DRMMaterial2(iface);
strcpy(name, "Material");
*size = sizeof("Material");
TRACE("iface %p, size %p, name %p.\n", iface, size, name);
return D3DRM_OK;
return d3drm_object_get_class_name(&material->obj, size, name);
}
static HRESULT WINAPI d3drm_material_SetPower(IDirect3DRMMaterial2 *iface, D3DVALUE power)
......@@ -283,6 +280,7 @@ static const struct IDirect3DRMMaterial2Vtbl d3drm_material_vtbl =
HRESULT Direct3DRMMaterial_create(IDirect3DRMMaterial2 **out)
{
static const char classname[] = "Material";
struct d3drm_material *object;
TRACE("out %p.\n", out);
......@@ -297,6 +295,8 @@ HRESULT Direct3DRMMaterial_create(IDirect3DRMMaterial2 **out)
object->specular.g = 1.0f;
object->specular.b = 1.0f;
d3drm_object_init(&object->obj, classname);
*out = &object->IDirect3DRMMaterial2_iface;
return S_OK;
......
......@@ -41,6 +41,7 @@ struct mesh_group
struct d3drm_mesh
{
struct d3drm_object obj;
IDirect3DRMMesh IDirect3DRMMesh_iface;
LONG ref;
DWORD groups_capacity;
......@@ -63,6 +64,7 @@ struct mesh_material
struct d3drm_mesh_builder
{
struct d3drm_object obj;
IDirect3DRMMeshBuilder2 IDirect3DRMMeshBuilder2_iface;
IDirect3DRMMeshBuilder3 IDirect3DRMMeshBuilder3_iface;
LONG ref;
......@@ -1017,15 +1019,11 @@ static HRESULT WINAPI d3drm_mesh_builder3_GetName(IDirect3DRMMeshBuilder3 *iface
static HRESULT WINAPI d3drm_mesh_builder3_GetClassName(IDirect3DRMMeshBuilder3 *iface,
DWORD *size, char *name)
{
TRACE("iface %p, size %p, name %p.\n", iface, size, name);
if (!size || *size < strlen("Builder") || !name)
return E_INVALIDARG;
struct d3drm_mesh_builder *meshbuilder = impl_from_IDirect3DRMMeshBuilder3(iface);
strcpy(name, "Builder");
*size = sizeof("Builder");
TRACE("iface %p, size %p, name %p.\n", iface, size, name);
return D3DRM_OK;
return d3drm_object_get_class_name(&meshbuilder->obj, size, name);
}
HRESULT load_mesh_data(IDirect3DRMMeshBuilder3 *iface, IDirectXFileData *pData,
......@@ -2300,6 +2298,7 @@ static const struct IDirect3DRMMeshBuilder3Vtbl d3drm_mesh_builder3_vtbl =
HRESULT Direct3DRMMeshBuilder_create(REFIID riid, IUnknown **out)
{
static const char classname[] = "Builder";
struct d3drm_mesh_builder *object;
TRACE("riid %s, out %p.\n", debugstr_guid(riid), out);
......@@ -2311,6 +2310,8 @@ HRESULT Direct3DRMMeshBuilder_create(REFIID riid, IUnknown **out)
object->IDirect3DRMMeshBuilder3_iface.lpVtbl = &d3drm_mesh_builder3_vtbl;
object->ref = 1;
d3drm_object_init(&object->obj, classname);
if (IsEqualGUID(riid, &IID_IDirect3DRMMeshBuilder3))
*out = (IUnknown *)&object->IDirect3DRMMeshBuilder3_iface;
else
......@@ -2430,15 +2431,11 @@ static HRESULT WINAPI d3drm_mesh_GetName(IDirect3DRMMesh *iface, DWORD *size, ch
static HRESULT WINAPI d3drm_mesh_GetClassName(IDirect3DRMMesh *iface, DWORD *size, char *name)
{
TRACE("iface %p, size %p, name %p.\n", iface, size, name);
if (!size || *size < strlen("Mesh") || !name)
return E_INVALIDARG;
struct d3drm_mesh *mesh = impl_from_IDirect3DRMMesh(iface);
strcpy(name, "Mesh");
*size = sizeof("Mesh");
TRACE("iface %p, size %p, name %p.\n", iface, size, name);
return D3DRM_OK;
return d3drm_object_get_class_name(&mesh->obj, size, name);
}
static HRESULT WINAPI d3drm_mesh_Scale(IDirect3DRMMesh *iface,
......@@ -2808,6 +2805,7 @@ static const struct IDirect3DRMMeshVtbl d3drm_mesh_vtbl =
HRESULT Direct3DRMMesh_create(IDirect3DRMMesh **mesh)
{
static const char classname[] = "Mesh";
struct d3drm_mesh *object;
TRACE("mesh %p.\n", mesh);
......@@ -2818,6 +2816,8 @@ HRESULT Direct3DRMMesh_create(IDirect3DRMMesh **mesh)
object->IDirect3DRMMesh_iface.lpVtbl = &d3drm_mesh_vtbl;
object->ref = 1;
d3drm_object_init(&object->obj, classname);
*mesh = &object->IDirect3DRMMesh_iface;
return S_OK;
......
......@@ -820,15 +820,11 @@ static HRESULT WINAPI d3drm_texture3_GetName(IDirect3DRMTexture3 *iface, DWORD *
static HRESULT WINAPI d3drm_texture3_GetClassName(IDirect3DRMTexture3 *iface, DWORD *size, char *name)
{
TRACE("iface %p, size %p, name %p.\n", iface, size, name);
if (!size || *size < sizeof("Texture") || !name)
return E_INVALIDARG;
struct d3drm_texture *texture = impl_from_IDirect3DRMTexture3(iface);
strcpy(name, "Texture");
*size = sizeof("Texture");
TRACE("iface %p, size %p, name %p.\n", iface, size, name);
return D3DRM_OK;
return d3drm_object_get_class_name(&texture->obj, size, name);
}
static HRESULT WINAPI d3drm_texture3_InitFromFile(IDirect3DRMTexture3 *iface, const char *filename)
......@@ -1114,6 +1110,7 @@ static const struct IDirect3DRMTexture3Vtbl d3drm_texture3_vtbl =
HRESULT d3drm_texture_create(struct d3drm_texture **texture, IDirect3DRM *d3drm)
{
static const char classname[] = "Texture";
struct d3drm_texture *object;
TRACE("texture %p.\n", texture);
......@@ -1126,7 +1123,7 @@ HRESULT d3drm_texture_create(struct d3drm_texture **texture, IDirect3DRM *d3drm)
object->IDirect3DRMTexture3_iface.lpVtbl = &d3drm_texture3_vtbl;
object->d3drm = d3drm;
d3drm_object_init(&object->obj);
d3drm_object_init(&object->obj, classname);
*texture = object;
......
......@@ -278,15 +278,11 @@ static HRESULT WINAPI d3drm_viewport1_GetName(IDirect3DRMViewport *iface, DWORD
static HRESULT WINAPI d3drm_viewport2_GetClassName(IDirect3DRMViewport2 *iface, DWORD *size, char *name)
{
TRACE("iface %p, size %p, name %p.\n", iface, size, name);
if (!size || *size < strlen("Viewport") || !name)
return E_INVALIDARG;
struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport2(iface);
strcpy(name, "Viewport");
*size = sizeof("Viewport");
TRACE("iface %p, size %p, name %p.\n", iface, size, name);
return D3DRM_OK;
return d3drm_object_get_class_name(&viewport->obj, size, name);
}
static HRESULT WINAPI d3drm_viewport1_GetClassName(IDirect3DRMViewport *iface, DWORD *size, char *name)
......@@ -1013,6 +1009,7 @@ static const struct IDirect3DRMViewportVtbl d3drm_viewport1_vtbl =
HRESULT d3drm_viewport_create(struct d3drm_viewport **viewport, IDirect3DRM *d3drm)
{
static const char classname[] = "Viewport";
struct d3drm_viewport *object;
TRACE("viewport %p, d3drm %p.\n", viewport, d3drm);
......@@ -1023,7 +1020,7 @@ HRESULT d3drm_viewport_create(struct d3drm_viewport **viewport, IDirect3DRM *d3d
object->IDirect3DRMViewport_iface.lpVtbl = &d3drm_viewport1_vtbl;
object->IDirect3DRMViewport2_iface.lpVtbl = &d3drm_viewport2_vtbl;
object->d3drm = d3drm;
d3drm_object_init(&object->obj);
d3drm_object_init(&object->obj, classname);
*viewport = object;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment