wined3d: Get rid of some pointers in WINED3DADAPTER_IDENTIFIER.

This also avoids some unchecked strcpy() calls.
This commit is contained in:
Henri Verbeet 2009-07-07 11:08:03 +02:00 committed by Alexandre Julliard
parent 32fd8f2130
commit 699f68cdee
4 changed files with 96 additions and 60 deletions

View File

@ -103,30 +103,34 @@ static UINT WINAPI IDirect3D8Impl_GetAdapterCount (LPDIRECT3D8 iface) {
return hr; return hr;
} }
static HRESULT WINAPI IDirect3D8Impl_GetAdapterIdentifier (LPDIRECT3D8 iface, static HRESULT WINAPI IDirect3D8Impl_GetAdapterIdentifier(LPDIRECT3D8 iface,
UINT Adapter, DWORD Flags, D3DADAPTER_IDENTIFIER8* pIdentifier) { UINT Adapter, DWORD Flags, D3DADAPTER_IDENTIFIER8 *pIdentifier)
{
IDirect3D8Impl *This = (IDirect3D8Impl *)iface; IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
WINED3DADAPTER_IDENTIFIER adapter_id; WINED3DADAPTER_IDENTIFIER adapter_id;
HRESULT hr; HRESULT hr;
TRACE("(%p)->(%d,%08x, %p\n", This, Adapter, Flags, pIdentifier); TRACE("(%p)->(%d,%08x, %p\n", This, Adapter, Flags, pIdentifier);
EnterCriticalSection(&d3d8_cs);
/* dx8 and dx9 have different structures to be filled in, with incompatible
layouts so pass in pointers to the places to be filled via an internal
structure */
adapter_id.Driver = pIdentifier->Driver;
adapter_id.Description = pIdentifier->Description;
adapter_id.DeviceName = NULL; /* d3d9 only */
adapter_id.DriverVersion = &pIdentifier->DriverVersion;
adapter_id.VendorId = &pIdentifier->VendorId;
adapter_id.DeviceId = &pIdentifier->DeviceId;
adapter_id.SubSysId = &pIdentifier->SubSysId;
adapter_id.Revision = &pIdentifier->Revision;
adapter_id.DeviceIdentifier = &pIdentifier->DeviceIdentifier;
adapter_id.WHQLLevel = &pIdentifier->WHQLLevel;
adapter_id.driver = pIdentifier->Driver;
adapter_id.driver_size = sizeof(pIdentifier->Driver);
adapter_id.description = pIdentifier->Description;
adapter_id.description_size = sizeof(pIdentifier->Description);
adapter_id.device_name = NULL; /* d3d9 only */
adapter_id.device_name_size = 0; /* d3d9 only */
EnterCriticalSection(&d3d8_cs);
hr = IWineD3D_GetAdapterIdentifier(This->WineD3D, Adapter, Flags, &adapter_id); hr = IWineD3D_GetAdapterIdentifier(This->WineD3D, Adapter, Flags, &adapter_id);
LeaveCriticalSection(&d3d8_cs); LeaveCriticalSection(&d3d8_cs);
pIdentifier->DriverVersion = adapter_id.driver_version;
pIdentifier->VendorId = adapter_id.vendor_id;
pIdentifier->DeviceId = adapter_id.device_id;
pIdentifier->SubSysId = adapter_id.subsystem_id;
pIdentifier->Revision = adapter_id.revision;
memcpy(&pIdentifier->DeviceIdentifier, &adapter_id.device_identifier, sizeof(pIdentifier->DeviceIdentifier));
pIdentifier->WHQLLevel = adapter_id.whql_level;
return hr; return hr;
} }

View File

@ -106,23 +106,25 @@ static HRESULT WINAPI IDirect3D9Impl_GetAdapterIdentifier(LPDIRECT3D9EX iface, U
WINED3DADAPTER_IDENTIFIER adapter_id; WINED3DADAPTER_IDENTIFIER adapter_id;
HRESULT hr; HRESULT hr;
/* dx8 and dx9 have different structures to be filled in, with incompatible adapter_id.driver = pIdentifier->Driver;
layouts so pass in pointers to the places to be filled via an internal adapter_id.driver_size = sizeof(pIdentifier->Driver);
structure */ adapter_id.description = pIdentifier->Description;
adapter_id.Driver = pIdentifier->Driver; adapter_id.description_size = sizeof(pIdentifier->Description);
adapter_id.Description = pIdentifier->Description; adapter_id.device_name = pIdentifier->DeviceName;
adapter_id.DeviceName = pIdentifier->DeviceName; adapter_id.device_name_size = sizeof(pIdentifier->DeviceName);
adapter_id.DriverVersion = &pIdentifier->DriverVersion;
adapter_id.VendorId = &pIdentifier->VendorId;
adapter_id.DeviceId = &pIdentifier->DeviceId;
adapter_id.SubSysId = &pIdentifier->SubSysId;
adapter_id.Revision = &pIdentifier->Revision;
adapter_id.DeviceIdentifier = &pIdentifier->DeviceIdentifier;
adapter_id.WHQLLevel = &pIdentifier->WHQLLevel;
EnterCriticalSection(&d3d9_cs); EnterCriticalSection(&d3d9_cs);
hr = IWineD3D_GetAdapterIdentifier(This->WineD3D, Adapter, Flags, &adapter_id); hr = IWineD3D_GetAdapterIdentifier(This->WineD3D, Adapter, Flags, &adapter_id);
LeaveCriticalSection(&d3d9_cs); LeaveCriticalSection(&d3d9_cs);
pIdentifier->DriverVersion = adapter_id.driver_version;
pIdentifier->VendorId = adapter_id.vendor_id;
pIdentifier->DeviceId = adapter_id.device_id;
pIdentifier->SubSysId = adapter_id.subsystem_id;
pIdentifier->Revision = adapter_id.revision;
memcpy(&pIdentifier->DeviceIdentifier, &adapter_id.device_identifier, sizeof(pIdentifier->DeviceIdentifier));
pIdentifier->WHQLLevel = adapter_id.whql_level;
return hr; return hr;
} }

View File

@ -2224,6 +2224,7 @@ static HRESULT WINAPI IWineD3DImpl_GetAdapterDisplayMode(IWineD3D *iface, UINT A
static HRESULT WINAPI IWineD3DImpl_GetAdapterIdentifier(IWineD3D *iface, UINT Adapter, DWORD Flags, static HRESULT WINAPI IWineD3DImpl_GetAdapterIdentifier(IWineD3D *iface, UINT Adapter, DWORD Flags,
WINED3DADAPTER_IDENTIFIER* pIdentifier) { WINED3DADAPTER_IDENTIFIER* pIdentifier) {
IWineD3DImpl *This = (IWineD3DImpl *)iface; IWineD3DImpl *This = (IWineD3DImpl *)iface;
size_t len;
TRACE_(d3d_caps)("(%p}->(Adapter: %d, Flags: %x, pId=%p)\n", This, Adapter, Flags, pIdentifier); TRACE_(d3d_caps)("(%p}->(Adapter: %d, Flags: %x, pId=%p)\n", This, Adapter, Flags, pIdentifier);
@ -2233,39 +2234,65 @@ static HRESULT WINAPI IWineD3DImpl_GetAdapterIdentifier(IWineD3D *iface, UINT Ad
/* Return the information requested */ /* Return the information requested */
TRACE_(d3d_caps)("device/Vendor Name and Version detection using FillGLCaps\n"); TRACE_(d3d_caps)("device/Vendor Name and Version detection using FillGLCaps\n");
strcpy(pIdentifier->Driver, This->adapters[Adapter].driver);
if(This->adapters[Adapter].gl_info.driver_description)
strcpy(pIdentifier->Description, This->adapters[Adapter].gl_info.driver_description);
else /* Copy default description "Direct3D HAL" */
strcpy(pIdentifier->Description, This->adapters[Adapter].description);
/* Note dx8 doesn't supply a DeviceName */ if (pIdentifier->driver_size)
if (NULL != pIdentifier->DeviceName) strcpy(pIdentifier->DeviceName, "\\\\.\\DISPLAY1"); /* FIXME: May depend on desktop? */ {
pIdentifier->DriverVersion->u.HighPart = This->adapters[Adapter].gl_info.driver_version_hipart; len = min(strlen(This->adapters[Adapter].driver), pIdentifier->driver_size - 1);
pIdentifier->DriverVersion->u.LowPart = This->adapters[Adapter].gl_info.driver_version; memcpy(pIdentifier->driver, This->adapters[Adapter].driver, len);
*(pIdentifier->VendorId) = This->adapters[Adapter].gl_info.gl_vendor; pIdentifier->driver[len] = '\0';
*(pIdentifier->DeviceId) = This->adapters[Adapter].gl_info.gl_card; }
*(pIdentifier->SubSysId) = 0;
*(pIdentifier->Revision) = 0; if (pIdentifier->description_size)
*pIdentifier->DeviceIdentifier = IID_D3DDEVICE_D3DUID; {
const char *description;
if (This->adapters[Adapter].gl_info.driver_description)
description = This->adapters[Adapter].gl_info.driver_description;
else
description = This->adapters[Adapter].description;
len = min(strlen(description), pIdentifier->description_size - 1);
memcpy(pIdentifier->description, description, len);
pIdentifier->description[len] = '\0';
}
/* Note that d3d8 doesn't supply a device name. */
if (pIdentifier->device_name_size)
{
static const char *device_name = "\\\\.\\DISPLAY1"; /* FIXME: May depend on desktop? */
len = strlen(device_name);
if (len >= pIdentifier->device_name_size)
{
ERR("Device name size too small.\n");
return WINED3DERR_INVALIDCALL;
}
memcpy(pIdentifier->device_name, device_name, len);
pIdentifier->device_name[len] = '\0';
}
pIdentifier->driver_version.u.HighPart = This->adapters[Adapter].gl_info.driver_version_hipart;
pIdentifier->driver_version.u.LowPart = This->adapters[Adapter].gl_info.driver_version;
pIdentifier->vendor_id = This->adapters[Adapter].gl_info.gl_vendor;
pIdentifier->device_id = This->adapters[Adapter].gl_info.gl_card;
pIdentifier->subsystem_id = 0;
pIdentifier->revision = 0;
memcpy(&pIdentifier->device_identifier, &IID_D3DDEVICE_D3DUID, sizeof(pIdentifier->device_identifier));
if(wined3d_settings.pci_device_id != PCI_DEVICE_NONE) if(wined3d_settings.pci_device_id != PCI_DEVICE_NONE)
{ {
TRACE_(d3d_caps)("Overriding pci device id with: %x\n", wined3d_settings.pci_device_id); TRACE_(d3d_caps)("Overriding pci device id with: %x\n", wined3d_settings.pci_device_id);
*(pIdentifier->DeviceId) = wined3d_settings.pci_device_id; pIdentifier->device_id = wined3d_settings.pci_device_id;
} }
if(wined3d_settings.pci_vendor_id != PCI_VENDOR_NONE) if(wined3d_settings.pci_vendor_id != PCI_VENDOR_NONE)
{ {
TRACE_(d3d_caps)("Overriding pci vendor id with: %x\n", wined3d_settings.pci_vendor_id); TRACE_(d3d_caps)("Overriding pci vendor id with: %x\n", wined3d_settings.pci_vendor_id);
*(pIdentifier->VendorId) = wined3d_settings.pci_vendor_id; pIdentifier->vendor_id = wined3d_settings.pci_vendor_id;
} }
if (Flags & WINED3DENUM_NO_WHQL_LEVEL) { pIdentifier->whql_level = (Flags & WINED3DENUM_NO_WHQL_LEVEL) ? 0 : 1;
*(pIdentifier->WHQLLevel) = 0;
} else {
*(pIdentifier->WHQLLevel) = 1;
}
return WINED3D_OK; return WINED3D_OK;
} }

View File

@ -1691,16 +1691,19 @@ typedef struct _WINED3DTRIPATCH_INFO
typedef struct _WINED3DADAPTER_IDENTIFIER typedef struct _WINED3DADAPTER_IDENTIFIER
{ {
char *Driver; char *driver;
char *Description; UINT driver_size;
char *DeviceName; char *description;
LARGE_INTEGER *DriverVersion; UINT description_size;
DWORD *VendorId; char *device_name;
DWORD *DeviceId; UINT device_name_size;
DWORD *SubSysId; LARGE_INTEGER driver_version;
DWORD *Revision; DWORD vendor_id;
GUID *DeviceIdentifier; DWORD device_id;
DWORD *WHQLLevel; DWORD subsystem_id;
DWORD revision;
GUID device_identifier;
DWORD whql_level;
} WINED3DADAPTER_IDENTIFIER; } WINED3DADAPTER_IDENTIFIER;
typedef struct _WINED3DPRESENT_PARAMETERS typedef struct _WINED3DPRESENT_PARAMETERS