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