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