| 1 | /* $Id: ddraw.CPP,v 1.16 2001-03-09 22:48:47 mike Exp $ */ | 
|---|
| 2 |  | 
|---|
| 3 | /* | 
|---|
| 4 | * DXDraw DLL implementaion | 
|---|
| 5 | * | 
|---|
| 6 | * Copyright 1998 Sander va Leeuwen | 
|---|
| 7 | * Copyright 1999 Markus Montkowski | 
|---|
| 8 | * | 
|---|
| 9 | * WARNING: DirectDrawCreate defaults to ddraw v4 if lpGUID == NULL!! | 
|---|
| 10 | * | 
|---|
| 11 | * | 
|---|
| 12 | * Project Odin Software License can be found in LICENSE.TXT | 
|---|
| 13 | * | 
|---|
| 14 | */ | 
|---|
| 15 |  | 
|---|
| 16 | #include <memory.h> | 
|---|
| 17 | #include <stdio.h> | 
|---|
| 18 |  | 
|---|
| 19 | #define INITGUID | 
|---|
| 20 | #define ICOM_CINTERFACE 1 | 
|---|
| 21 | #define CINTERFACE | 
|---|
| 22 |  | 
|---|
| 23 | #include "os2ddraw.h" | 
|---|
| 24 | #include "winerror.h" | 
|---|
| 25 | // define the following as we include winnt.h | 
|---|
| 26 | #define _OS2WIN_H | 
|---|
| 27 | #define FAR | 
|---|
| 28 |  | 
|---|
| 29 | #include <misc.h> | 
|---|
| 30 |  | 
|---|
| 31 | extern "C" { | 
|---|
| 32 |  | 
|---|
| 33 | //****************************************************************************** | 
|---|
| 34 | //****************************************************************************** | 
|---|
| 35 | HRESULT WIN32API OS2DirectDrawCreate( GUID FAR *lpGUID, | 
|---|
| 36 | LPDIRECTDRAW FAR *lplpDD, | 
|---|
| 37 | IUnknown FAR *pUnkOuter) | 
|---|
| 38 | { | 
|---|
| 39 | OS2IDirectDraw *newdraw; | 
|---|
| 40 | HRESULT         rc; | 
|---|
| 41 |  | 
|---|
| 42 | dprintf(("DDRAW: DirectDrawCreate %X %X %X\n", lpGUID, lplpDD, pUnkOuter)); | 
|---|
| 43 |  | 
|---|
| 44 | newdraw = new OS2IDirectDraw(lpGUID); | 
|---|
| 45 |  | 
|---|
| 46 | if(newdraw == NULL) | 
|---|
| 47 | { | 
|---|
| 48 | rc = DDERR_NODIRECTDRAWHW; | 
|---|
| 49 | } | 
|---|
| 50 | else | 
|---|
| 51 | { | 
|---|
| 52 | newdraw->Vtbl.AddRef((IDirectDraw2 *)newdraw); | 
|---|
| 53 |  | 
|---|
| 54 | rc = newdraw->GetLastError(); | 
|---|
| 55 | if(rc != DD_OK) | 
|---|
| 56 | { | 
|---|
| 57 | *lplpDD = NULL; | 
|---|
| 58 |  | 
|---|
| 59 | delete newdraw; | 
|---|
| 60 | } | 
|---|
| 61 | else *lplpDD = (LPDIRECTDRAW)newdraw; | 
|---|
| 62 | } | 
|---|
| 63 | return(rc); | 
|---|
| 64 | } | 
|---|
| 65 | //****************************************************************************** | 
|---|
| 66 | //****************************************************************************** | 
|---|
| 67 | HRESULT WIN32API DirectDrawCreateEx(LPGUID lpGUID, LPVOID* lplpDD, REFIID iid, LPUNKNOWN pUnkOuter) | 
|---|
| 68 | { | 
|---|
| 69 | dprintf(("DirectDrawCreateEx: %x %x %x %x", lpGUID, lplpDD, iid, pUnkOuter)); | 
|---|
| 70 | /* I don't know about what functionality is unique to Ex */ | 
|---|
| 71 | return OS2DirectDrawCreate(lpGUID,(LPDIRECTDRAW*)lplpDD,pUnkOuter); | 
|---|
| 72 | } | 
|---|
| 73 |  | 
|---|
| 74 | //****************************************************************************** | 
|---|
| 75 | //typedef BOOL (FAR PASCAL * LPDDENUMCALLBACKA)(GUID FAR *, LPSTR, LPSTR, LPVOID); | 
|---|
| 76 | //****************************************************************************** | 
|---|
| 77 | HRESULT WIN32API OS2DirectDrawEnumerateA(LPDDENUMCALLBACKA lpCallback, | 
|---|
| 78 | LPVOID lpContext) | 
|---|
| 79 | { | 
|---|
| 80 | dprintf(("DDRAW: DirectDrawEnumerateA\n Callback for DIVE\n")); | 
|---|
| 81 | //call it twice for the DirectDraw & Direct3D classes | 
|---|
| 82 | if(lpCallback(NULL, "DIVE DirectDraw for OS/2", | 
|---|
| 83 | "DirectDraw/2 v0.2", lpContext) == DDENUMRET_CANCEL) | 
|---|
| 84 | { | 
|---|
| 85 | dprintf(("DDRAW: Cancel Callback\n")); | 
|---|
| 86 | return(DD_OK); | 
|---|
| 87 | } | 
|---|
| 88 | //SvL: Crashes dxview.exe; expects a different vtbl when creating | 
|---|
| 89 | //     an IID_IDirect3D object | 
|---|
| 90 | #if 1 | 
|---|
| 91 | else //now for Direct3D | 
|---|
| 92 | { | 
|---|
| 93 | dprintf(("DDRAW: Callback for 3Dfx Voodoo")); | 
|---|
| 94 | if(lpCallback((GUID *)&IID_IDirect3D, "3Dfx Voodoo Direct3D/2", | 
|---|
| 95 | "Direct3D/2 v0.2", lpContext) == DDENUMRET_CANCEL) | 
|---|
| 96 | { | 
|---|
| 97 | dprintf(("DDRAW: Cancel Callback\n")); | 
|---|
| 98 | return(DD_OK); | 
|---|
| 99 | } | 
|---|
| 100 | } | 
|---|
| 101 | #endif | 
|---|
| 102 | dprintf(("DDRAW: Done Enumeration\n\n")); | 
|---|
| 103 |  | 
|---|
| 104 | return(DD_OK); | 
|---|
| 105 | } | 
|---|
| 106 |  | 
|---|
| 107 | //****************************************************************************** | 
|---|
| 108 | typedef struct | 
|---|
| 109 | { | 
|---|
| 110 | LPDDENUMCALLBACKEXA lpCallbackEx; | 
|---|
| 111 | LPVOID lpContext; | 
|---|
| 112 | } ENUMDATA, *PENUMDATA; | 
|---|
| 113 |  | 
|---|
| 114 | BOOL FAR PASCAL SimpleEnum ( GUID FAR *lpGUID, | 
|---|
| 115 | LPSTR  lpDriverDescription, | 
|---|
| 116 | LPSTR  lpDriverName, | 
|---|
| 117 | LPVOID lpContext) | 
|---|
| 118 | { | 
|---|
| 119 | BOOL rc; | 
|---|
| 120 | PENUMDATA pData; | 
|---|
| 121 |  | 
|---|
| 122 | dprintf(("DDRAW: SimpleEnum\n")); | 
|---|
| 123 |  | 
|---|
| 124 | pData = (PENUMDATA)lpContext; | 
|---|
| 125 | rc = pData->lpCallbackEx( lpGUID, | 
|---|
| 126 | lpDriverDescription, | 
|---|
| 127 | lpDriverName, | 
|---|
| 128 | pData->lpContext, | 
|---|
| 129 | NULL); | 
|---|
| 130 |  | 
|---|
| 131 | dprintf(("DDRAW: Callback returned\n")); | 
|---|
| 132 | return rc; | 
|---|
| 133 | } | 
|---|
| 134 |  | 
|---|
| 135 | //****************************************************************************** | 
|---|
| 136 | HRESULT WIN32API OS2DirectDrawEnumerateExA( LPDDENUMCALLBACKEXA lpCallbackEx, | 
|---|
| 137 | LPVOID lpContext, | 
|---|
| 138 | DWORD dwFlags) | 
|---|
| 139 | { | 
|---|
| 140 | ENUMDATA data; | 
|---|
| 141 |  | 
|---|
| 142 | dprintf(("DDRAW: DirectDrawEnumerateExA\n")); | 
|---|
| 143 |  | 
|---|
| 144 | data.lpCallbackEx = lpCallbackEx; | 
|---|
| 145 | data.lpContext    = lpContext; | 
|---|
| 146 |  | 
|---|
| 147 | OS2DirectDrawEnumerateA( SimpleEnum, | 
|---|
| 148 | &data); | 
|---|
| 149 | return (DD_OK); | 
|---|
| 150 | } | 
|---|
| 151 | //****************************************************************************** | 
|---|
| 152 | //****************************************************************************** | 
|---|
| 153 | DWORD WIN32API DDHAL32_VidMemFree(DWORD address) | 
|---|
| 154 | { | 
|---|
| 155 | dprintf(("DDRAW: DDHAL32_VidMemFree, not supported\n")); | 
|---|
| 156 | return(0); | 
|---|
| 157 | } | 
|---|
| 158 | //****************************************************************************** | 
|---|
| 159 | //****************************************************************************** | 
|---|
| 160 | DWORD WIN32API DDHAL32_VidMemAlloc(DWORD size) | 
|---|
| 161 | { | 
|---|
| 162 | dprintf(("DDRAW: DDHAL32_VidMemAlloc, not supported\n")); | 
|---|
| 163 | return(0); | 
|---|
| 164 | } | 
|---|
| 165 | //****************************************************************************** | 
|---|
| 166 |  | 
|---|
| 167 | /******************************************************************************* | 
|---|
| 168 | * DirectDraw ClassFactory | 
|---|
| 169 | * | 
|---|
| 170 | */ | 
|---|
| 171 |  | 
|---|
| 172 | typedef struct | 
|---|
| 173 | { | 
|---|
| 174 | /* IUnknown fields */ | 
|---|
| 175 | ICOM_VTABLE(IClassFactory) *lpvtbl; | 
|---|
| 176 | DWORD                       ref; | 
|---|
| 177 | } IClassFactoryImpl; | 
|---|
| 178 |  | 
|---|
| 179 | static HRESULT WINAPI | 
|---|
| 180 | DDCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) | 
|---|
| 181 | { | 
|---|
| 182 | ICOM_THIS(IClassFactoryImpl,iface); | 
|---|
| 183 | char buf[80]; | 
|---|
| 184 |  | 
|---|
| 185 | if (HIWORD(riid)) | 
|---|
| 186 | WINE_StringFromCLSID(riid,buf); | 
|---|
| 187 | else | 
|---|
| 188 | sprintf(buf,"<guid-0x%04x>",LOWORD(riid)); | 
|---|
| 189 | dprintf(("DDRAW:(%p)->(%s,%p),stub!\n",This,buf,ppobj)); | 
|---|
| 190 | return E_NOINTERFACE; | 
|---|
| 191 | } | 
|---|
| 192 |  | 
|---|
| 193 | static ULONG WINAPI | 
|---|
| 194 | DDCF_AddRef(LPCLASSFACTORY iface) | 
|---|
| 195 | { | 
|---|
| 196 | ICOM_THIS(IClassFactoryImpl,iface); | 
|---|
| 197 | return ++(This->ref); | 
|---|
| 198 | } | 
|---|
| 199 |  | 
|---|
| 200 | static ULONG WINAPI DDCF_Release(LPCLASSFACTORY iface) | 
|---|
| 201 | { | 
|---|
| 202 | ICOM_THIS(IClassFactoryImpl,iface); | 
|---|
| 203 | /* static class, won't be  freed */ | 
|---|
| 204 | return --(This->ref); | 
|---|
| 205 | } | 
|---|
| 206 |  | 
|---|
| 207 | static HRESULT WINAPI DDCF_CreateInstance( LPCLASSFACTORY iface, | 
|---|
| 208 | LPUNKNOWN pOuter, | 
|---|
| 209 | REFIID riid, | 
|---|
| 210 | LPVOID *ppobj) | 
|---|
| 211 | { | 
|---|
| 212 | ICOM_THIS(IClassFactoryImpl,iface); | 
|---|
| 213 | LPGUID lpGUID; | 
|---|
| 214 | lpGUID = (LPGUID) riid; | 
|---|
| 215 |  | 
|---|
| 216 | dprintf(("DDRAW:DDCF_CreateInstance\n")); | 
|---|
| 217 | if( lpGUID && | 
|---|
| 218 | ( (*lpGUID == IID_IDirectDraw ) || | 
|---|
| 219 | (*lpGUID == IID_IDirectDraw2) || | 
|---|
| 220 | (*lpGUID == IID_IDirectDraw4)) | 
|---|
| 221 | ) | 
|---|
| 222 | { | 
|---|
| 223 | /* FIXME: reuse already created DirectDraw if present? */ | 
|---|
| 224 | return OS2DirectDrawCreate(lpGUID,(LPDIRECTDRAW*)ppobj,pOuter); | 
|---|
| 225 | } | 
|---|
| 226 | return E_NOINTERFACE; | 
|---|
| 227 | } | 
|---|
| 228 |  | 
|---|
| 229 | static HRESULT WINAPI DDCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) | 
|---|
| 230 | { | 
|---|
| 231 | ICOM_THIS(IClassFactoryImpl,iface); | 
|---|
| 232 | dprintf(("DDRAW:(%p)->(%d),stub!\n",This,dolock)); | 
|---|
| 233 | return S_OK; | 
|---|
| 234 | } | 
|---|
| 235 |  | 
|---|
| 236 | static ICOM_VTABLE(IClassFactory) DDCF_Vtbl = | 
|---|
| 237 | { | 
|---|
| 238 | DDCF_QueryInterface, | 
|---|
| 239 | DDCF_AddRef, | 
|---|
| 240 | DDCF_Release, | 
|---|
| 241 | DDCF_CreateInstance, | 
|---|
| 242 | DDCF_LockServer | 
|---|
| 243 | }; | 
|---|
| 244 |  | 
|---|
| 245 | static IClassFactoryImpl DDRAW_CF = {&DDCF_Vtbl, 1 }; | 
|---|
| 246 |  | 
|---|
| 247 |  | 
|---|
| 248 | HRESULT WINAPI DllGetClassObject( REFCLSID rclsid, | 
|---|
| 249 | REFIID riid, | 
|---|
| 250 | LPVOID *ppv) | 
|---|
| 251 | { | 
|---|
| 252 | char buf[80],xbuf[80]; | 
|---|
| 253 |  | 
|---|
| 254 | if (HIWORD(rclsid)) | 
|---|
| 255 | WINE_StringFromCLSID(rclsid,xbuf); | 
|---|
| 256 | else | 
|---|
| 257 | sprintf(xbuf,"<guid-0x%04x>",LOWORD(rclsid)); | 
|---|
| 258 | if (HIWORD(riid)) | 
|---|
| 259 | WINE_StringFromCLSID(riid,buf); | 
|---|
| 260 | else | 
|---|
| 261 | sprintf(buf,"<guid-0x%04x>",LOWORD(riid)); | 
|---|
| 262 | WINE_StringFromCLSID(riid,xbuf); | 
|---|
| 263 |  | 
|---|
| 264 | dprintf(("DDRAW:(%p,%p,%p)\n", xbuf, buf, ppv)); | 
|---|
| 265 | if (!memcmp(riid,&IID_IClassFactory,sizeof(IID_IClassFactory))) | 
|---|
| 266 | { | 
|---|
| 267 | *ppv = (LPVOID)&DDRAW_CF; | 
|---|
| 268 | DDRAW_CF.lpvtbl->AddRef((IClassFactory*)&DDRAW_CF); | 
|---|
| 269 | return S_OK; | 
|---|
| 270 | } | 
|---|
| 271 | dprintf(("DDRAW: (%p,%p,%p): no interface found.\n", xbuf, buf, ppv)); | 
|---|
| 272 | return E_NOINTERFACE; | 
|---|
| 273 | } | 
|---|
| 274 |  | 
|---|
| 275 |  | 
|---|
| 276 | /******************************************************************************* | 
|---|
| 277 | * DllCanUnloadNow [DDRAW.12]  Determines whether the DLL is in use. | 
|---|
| 278 | * | 
|---|
| 279 | * RETURNS | 
|---|
| 280 | *    Success: S_OK | 
|---|
| 281 | *    Failure: S_FALSE | 
|---|
| 282 | */ | 
|---|
| 283 | HRESULT WINAPI DllCanUnloadNow(void) | 
|---|
| 284 | { | 
|---|
| 285 | dprintf(("DllCanUnloadNow(void) stub\n")); | 
|---|
| 286 | return S_FALSE; | 
|---|
| 287 | }//****************************************************************************** | 
|---|
| 288 | } | 
|---|