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