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