source: trunk/src/ddraw/OS2DDRAW.CPP@ 46

Last change on this file since 46 was 46, checked in by sandervl, 26 years ago

* empty log message *

File size: 15.8 KB
Line 
1/*
2 * DirectDraw main class
3 *
4 * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
5 *
6 * Project Odin Software License can be found in LICENSE.TXT
7 *
8 */
9/*@Const************************************************************************
10* Defined Constants *
11*******************************************************************************/
12#define WIN32SDK_NOPOSTWRAPPER
13
14/*@Header***********************************************************************
15* Header Files *
16*******************************************************************************/
17#include <os2win.h>
18#include <dive.h>
19
20#include <memory.h>
21#include <builtin.h>
22
23#include "no.h"
24#include <w_windows.h>
25#include <ddraw.h>
26#include <d3d.h>
27#include <Win32SDKPostWrapper.h>
28
29#include <fourcc.h>
30
31#include "os2ddraw.h"
32#include "os2clipper.h"
33#include "os2palette.h"
34#include "os2surface.h"
35#include "misc.h"
36#include "os2util.h"
37
38
39/* KSO Apr 19 1999: Set correct interface. *
40 * (INTERFACE is used in the THIS and THIS_ macros) */
41#undef INTERFACE
42#define INTERFACE IDirectDraw2
43
44
45
46DIVE_CAPS dcaps = {0};
47FOURCC fccFormats[100] = {0}; /* Color format code */
48
49
50//******************************************************************************
51//******************************************************************************
52OS2IDirectDraw::OS2IDirectDraw(GUID *lpGUID) :
53 Referenced(0), lastError(DD_OK),
54 pFrameBuffer(NULL), hwndClient(0), screenwidth(640),
55 screenheight(480), screenbpp(8), fFullScreen(TRUE)
56{
57 if(lpGUID && *lpGUID == IID_IDirect3D) {
58 lpVtbl = (IDirectDraw2Vtbl *)&Vtbl3D;
59 Vtbl3D.AddRef = D3DAddRef;
60 Vtbl3D.Release = D3DRelease;
61 Vtbl3D.QueryInterface = D3DQueryInterface;
62 Vtbl3D.Initialize = D3DInitialize;
63 Vtbl3D.EnumDevices = D3DEnumDevices;
64 Vtbl3D.CreateLight = D3DCreateLight;
65 Vtbl3D.CreateMaterial = D3DCreateMaterial;
66 Vtbl3D.CreateViewport = D3DCreateViewport;
67 Vtbl3D.FindDevice = D3DFindDevice;
68 }
69 else {
70 lpVtbl = &Vtbl;
71 Vtbl.AddRef = DrawAddRef;
72 Vtbl.Release = DrawRelease;
73 Vtbl.QueryInterface = DrawQueryInterface;
74 Vtbl.Compact = DrawCompact;
75 Vtbl.CreateClipper = DrawCreateClipper;
76 Vtbl.W32_CreatePalette = DrawCreatePalette; //KSO Apr 19 1999: Sideeffect of the wrapping...
77 Vtbl.CreateSurface = DrawCreateSurface;
78 Vtbl.DuplicateSurface = DrawDuplicateSurface;
79 Vtbl.EnumDisplayModes = DrawEnumDisplayModes;
80 Vtbl.EnumSurfaces = DrawEnumSurfaces;
81 Vtbl.FlipToGDISurface = DrawFlipToGDISurface;
82 Vtbl.GetCaps = DrawGetCaps;
83 Vtbl.GetDisplayMode = DrawGetDisplayMode;
84 Vtbl.GetFourCCCodes = DrawGetFourCCCodes;
85 Vtbl.GetGDISurface = DrawGetGDISurface;
86 Vtbl.GetMonitorFrequency = DrawGetMonitorFrequency;
87 Vtbl.GetScanLine = DrawGetScanLine;
88 Vtbl.GetVerticalBlankStatus = DrawGetVerticalBlankStatus;
89 Vtbl.Initialize = DrawInitialize;
90 Vtbl.RestoreDisplayMode = DrawRestoreDisplayMode;
91 Vtbl.SetCooperativeLevel = DrawSetCooperativeLevel;
92
93 if(lpGUID && *lpGUID == IID_IDirectDraw2)
94 *(ULONG *)&Vtbl.SetDisplayMode = (ULONG)DrawSetDisplayMode2;
95 else *(ULONG *)&Vtbl.SetDisplayMode = (ULONG)DrawSetDisplayMode;
96
97 Vtbl.WaitForVerticalBlank = DrawWaitForVerticalBlank;
98 Vtbl.GetAvailableVidMem = DrawGetAvailableVidMem;
99 }
100
101 ULONG rc = DiveOpen(&hDive, FALSE, &pFrameBuffer);
102 if(rc) {
103 dprintf(("ERROR: DiveOpen returned %d\n", rc));
104 lastError = DDERR_GENERIC;
105 hDive = NULL;
106 }
107 dcaps.pFormatData = fccFormats;
108 dcaps.ulFormatLength = sizeof(fccFormats);
109 dcaps.ulStructLen = sizeof(dcaps);
110 DiveQueryCaps(&dcaps, DIVE_BUFFER_SCREEN);
111}
112//******************************************************************************
113//******************************************************************************
114OS2IDirectDraw::~OS2IDirectDraw()
115{
116 dprintf(("OS2IDirectDraw::~OS2IDirectDraw()\n"));
117 if(hDive) DiveClose(hDive);
118}
119//******************************************************************************
120//******************************************************************************
121HRESULT __stdcall DrawQueryInterface(THIS, REFIID riid, LPVOID FAR * ppvObj)
122{
123#ifdef DEBUG
124 WriteLog("OS2IDirectDraw::QueryInterface\n");
125#endif
126 *ppvObj = NULL;
127
128 if(!IsEqualGUID(riid, CLSID_DirectDraw) &&
129 !IsEqualGUID(riid, IID_IDirectDraw) &&
130 !IsEqualGUID(riid, IID_IDirectDraw2))
131//&& !IsEqualGUID(riid, IID_IUnknown))
132 return E_NOINTERFACE;
133
134 *ppvObj = This;
135
136 DrawAddRef(This);
137 return(DD_OK);
138}
139//******************************************************************************
140//******************************************************************************
141ULONG __stdcall DrawAddRef(THIS)
142{
143 OS2IDirectDraw *me = (OS2IDirectDraw *)This;
144
145#ifdef DEBUG
146 WriteLog("OS2IDirectDraw::AddRef %d\n", me->Referenced+1);
147#endif
148 return ++me->Referenced;
149}
150//******************************************************************************
151//******************************************************************************
152ULONG __stdcall DrawRelease(THIS)
153{
154 OS2IDirectDraw *me = (OS2IDirectDraw *)This;
155
156#ifdef DEBUG
157 WriteLog("OS2IDirectDraw::Release %d\n", me->Referenced-1);
158 WriteLog("OS2IDirectDraw::%X \n", me);
159#endif
160 if(me->Referenced) {
161 me->Referenced--;
162 if(me->Referenced == 0) {
163 delete me;
164 return(0);
165 }
166 else return me->Referenced;
167 }
168 else return(0);
169}
170//******************************************************************************
171//******************************************************************************
172HRESULT __stdcall DrawCompact(THIS)
173{
174#ifdef DEBUG
175 WriteLog("Compact\n");
176#endif
177 return(DD_OK);
178}
179//******************************************************************************
180//******************************************************************************
181HRESULT __stdcall DrawCreateClipper(THIS, DWORD, LPDIRECTDRAWCLIPPER FAR *lplpDD, IUnknown FAR * )
182{
183 OS2IDirectDraw *me = (OS2IDirectDraw *)This;
184 OS2IDirectDrawClipper *newclip = new OS2IDirectDrawClipper(me);
185 HRESULT rc;
186
187#ifdef DEBUG
188 WriteLog("CreateClipper\n");
189#endif
190 if(newclip == NULL) return(DDERR_OUTOFMEMORY);
191
192 newclip->Vtbl.AddRef((IDirectDrawClipper *)newclip);
193 rc = newclip->GetLastError();
194 if(rc != DD_OK) {
195 *lplpDD = NULL;
196 delete newclip;
197 }
198 else *lplpDD = (IDirectDrawClipper *)newclip;
199
200 return(rc);
201}
202//******************************************************************************
203//******************************************************************************
204HRESULT __stdcall DrawCreatePalette(THIS, DWORD dwFlags,
205 W32_LPPALETTEENTRY lpColorTable,
206 LPDIRECTDRAWPALETTE FAR *lplpDD,
207 IUnknown FAR *pUnkOuter)
208{
209 OS2IDirectDraw *me = (OS2IDirectDraw *)This;
210 OS2IDirectDrawPalette *newpal;
211 HRESULT rc;
212 int palsize = 0;
213
214 if(dwFlags & (DDPCAPS_2BIT | DDPCAPS_4BIT) && !(dwFlags & DDPCAPS_8BITENTRIES)) {
215 //only support 8 bits color palettes...
216 return DDERR_INVALIDPARAMS;
217 }
218 if(dwFlags & DDPCAPS_2BIT) palsize = 4;
219 if(dwFlags & DDPCAPS_4BIT) palsize = 16;
220 if(dwFlags & DDPCAPS_8BIT) palsize = 256;
221 if(dwFlags & DDPCAPS_ALLOW256) palsize = 256;
222 if(palsize == 0) return DDERR_INVALIDPARAMS;
223
224 dprintf(("CreatePalette with %d colors\n", palsize));
225
226 newpal = new OS2IDirectDrawPalette(me, palsize, lpColorTable);
227 if(newpal == NULL) return(DDERR_OUTOFMEMORY);
228
229 newpal->Vtbl.AddRef((IDirectDrawPalette *)newpal);
230 rc = newpal->GetLastError();
231 if(rc != DD_OK) {
232 *lplpDD = NULL;
233 delete newpal;
234 }
235 else *lplpDD = (IDirectDrawPalette *)newpal;
236
237 return(rc);
238}
239//******************************************************************************
240//******************************************************************************
241HRESULT __stdcall DrawCreateSurface(THIS, LPDDSURFACEDESC lpDDSurfaceDesc,
242 LPDIRECTDRAWSURFACE FAR *lplpDD,
243 IUnknown FAR *pUnkOuter)
244{
245 OS2IDirectDraw *me = (OS2IDirectDraw *)This;
246 OS2IDirectDrawSurface *newsurf;
247 HRESULT rc;
248
249#ifdef DEBUG
250 WriteLog("CreateSurface\n");
251 WriteLog(" dwSize %d\n", lpDDSurfaceDesc->dwSize);
252 WriteLog(" dwFlags %X\n", lpDDSurfaceDesc->dwFlags);
253 WriteLog(" dwHeight %d\n", lpDDSurfaceDesc->dwHeight);
254 WriteLog(" dwWidth %d\n", lpDDSurfaceDesc->dwWidth);
255 WriteLog(" lPitch %d\n", lpDDSurfaceDesc->lPitch);
256 WriteLog(" lpSurface %d\n", lpDDSurfaceDesc->lpSurface);
257 WriteLog(" dwBackBufferCount %d\n", lpDDSurfaceDesc->dwBackBufferCount);
258 WriteLog(" dwMipMapCount %d\n", lpDDSurfaceDesc->dwMipMapCount);
259 WriteLog(" dwAlphaBitDepth %d\n", lpDDSurfaceDesc->dwAlphaBitDepth);
260 WriteLog(" ddsCaps.dwCaps %X\n", lpDDSurfaceDesc->ddsCaps.dwCaps);
261#endif
262
263 newsurf = new OS2IDirectDrawSurface(me, lpDDSurfaceDesc);
264 if(newsurf == NULL) return(DDERR_OUTOFMEMORY);
265
266 newsurf->Vtbl.AddRef((IDirectDrawSurface2 *)newsurf);
267 rc = newsurf->GetLastError();
268 if(rc != DD_OK) {
269 *lplpDD = NULL;
270 delete newsurf;
271 }
272 else *lplpDD = (IDirectDrawSurface *)newsurf;
273
274 return(rc);
275}
276//******************************************************************************
277//******************************************************************************
278HRESULT __stdcall DrawDuplicateSurface(THIS, LPDIRECTDRAWSURFACE, LPDIRECTDRAWSURFACE FAR * )
279{
280#ifdef DEBUG
281 WriteLog("DuplicateSurface\n");
282#endif
283 return(DD_OK);
284}
285//******************************************************************************
286//******************************************************************************
287HRESULT __stdcall DrawEnumDisplayModes(THIS, DWORD, LPDDSURFACEDESC, LPVOID, LPDDENUMMODESCALLBACK )
288{
289#ifdef DEBUG
290 WriteLog("EnumDisplayModes\n");
291#endif
292 return(DD_OK);
293}
294//******************************************************************************
295//******************************************************************************
296HRESULT __stdcall DrawEnumSurfaces(THIS, DWORD, LPDDSURFACEDESC, LPVOID,LPDDENUMSURFACESCALLBACK )
297{
298#ifdef DEBUG
299 WriteLog("EnumSurfaces\n");
300#endif
301 return(DD_OK);
302}
303//******************************************************************************
304//******************************************************************************
305HRESULT __stdcall DrawFlipToGDISurface(THIS)
306{
307#ifdef DEBUG
308 WriteLog("FlipToGDISurface\n");
309#endif
310 return(DD_OK);
311}
312//******************************************************************************
313//******************************************************************************
314HRESULT __stdcall DrawGetCaps(THIS, LPDDCAPS, LPDDCAPS)
315{
316#ifdef DEBUG
317 WriteLog("GetCaps\n");
318#endif
319 return(DD_OK);
320}
321//******************************************************************************
322//******************************************************************************
323HRESULT __stdcall DrawGetDisplayMode(THIS, LPDDSURFACEDESC)
324{
325#ifdef DEBUG
326 WriteLog("GetDisplayMode\n");
327#endif
328 return(DD_OK);
329}
330//******************************************************************************
331//******************************************************************************
332HRESULT __stdcall DrawGetFourCCCodes(THIS, LPDWORD, LPDWORD)
333{
334#ifdef DEBUG
335 WriteLog("GetFourCCCodes\n");
336#endif
337 return(DD_OK);
338}
339//******************************************************************************
340//******************************************************************************
341HRESULT __stdcall DrawGetGDISurface(THIS, LPDIRECTDRAWSURFACE FAR *)
342{
343#ifdef DEBUG
344 WriteLog("GetGDISurface\n");
345#endif
346 return(DD_OK);
347}
348//******************************************************************************
349//******************************************************************************
350HRESULT __stdcall DrawGetMonitorFrequency(THIS, LPDWORD)
351{
352#ifdef DEBUG
353 WriteLog("GetMonitorFrequency\n");
354#endif
355 return(DD_OK);
356}
357//******************************************************************************
358//******************************************************************************
359HRESULT __stdcall DrawGetScanLine(THIS, LPDWORD)
360{
361#ifdef DEBUG
362 WriteLog("GetScanLine\n");
363#endif
364 return(DD_OK);
365}
366//******************************************************************************
367//******************************************************************************
368HRESULT __stdcall DrawGetVerticalBlankStatus(THIS, LPBOOL)
369{
370#ifdef DEBUG
371 WriteLog("GetVerticalBlankStatus\n");
372#endif
373 return(DD_OK);
374}
375//******************************************************************************
376//******************************************************************************
377HRESULT __stdcall DrawInitialize(THIS, GUID FAR *)
378{
379#ifdef DEBUG
380 WriteLog("Initialize\n");
381#endif
382 return(DD_OK);
383}
384//******************************************************************************
385//******************************************************************************
386HRESULT __stdcall DrawRestoreDisplayMode(THIS)
387{
388#ifdef DEBUG
389 WriteLog("RestoreDisplayMod\n");
390#endif
391 return(DD_OK);
392}
393//******************************************************************************
394//******************************************************************************
395HRESULT __stdcall DrawSetCooperativeLevel(THIS, W32_HWND hwndClient, DWORD dwFlags)
396{
397 OS2IDirectDraw *me = (OS2IDirectDraw *)This;
398
399 dprintf(("SetCooperativeLevel: hwnd %X, Flags %X\n", hwndClient, dwFlags));
400 if(dwFlags & DDSCL_FULLSCREEN) {
401 me->fFullScreen = TRUE;
402 }
403 else me->fFullScreen = FALSE;
404
405 me->hwndClient = hwndClient;
406 OS2MaximizeWindow((HWND)hwndClient);
407 return(DD_OK);
408}
409//******************************************************************************
410//Backwards compatibility, what's that??
411//******************************************************************************
412HRESULT __stdcall DrawSetDisplayMode2(THIS, DWORD dwWidth, DWORD dwHeight,
413 DWORD dwBPP, DWORD dwRefreshRate,
414 DWORD dwFlags)
415{
416 OS2IDirectDraw *me = (OS2IDirectDraw *)This;
417
418 dprintf(("SetDisplayMode2 to %dx%d with %d bits colors\n", dwWidth, dwHeight, dwBPP));
419 me->screenwidth = dwWidth;
420 me->screenheight = dwHeight;
421 me->screenbpp = dwBPP;
422 return(DD_OK);
423}
424//******************************************************************************
425//******************************************************************************
426HRESULT __stdcall DrawSetDisplayMode(THIS, DWORD dwWidth, DWORD dwHeight,
427 DWORD dwBPP)
428{
429 OS2IDirectDraw *me = (OS2IDirectDraw *)This;
430
431// _interrupt(3);
432 dprintf(("SetDisplayMode to %dx%d with %d bits colors\n", dwWidth, dwHeight, dwBPP));
433 me->screenwidth = dwWidth;
434 me->screenheight = dwHeight;
435 me->screenbpp = dwBPP;
436 return(DD_OK);
437}
438//******************************************************************************
439//******************************************************************************
440HRESULT __stdcall DrawWaitForVerticalBlank(THIS, DWORD, W32_HANDLE)
441{
442 dprintf(("WaitForVerticalBlank\n"));
443 return(DD_OK);
444}
445//******************************************************************************
446/*** Added in the v2 interface ***/
447//******************************************************************************
448HRESULT __stdcall DrawGetAvailableVidMem(THIS, LPDDSCAPS, LPDWORD, LPDWORD)
449{
450 dprintf(("GetAvailableVidMem\n"));
451 return(DD_OK);
452}
453//******************************************************************************
454//******************************************************************************
Note: See TracBrowser for help on using the repository browser.