source: trunk/src/ddraw/OS2CLIPPER.CPP@ 7897

Last change on this file since 7897 was 7897, checked in by sandervl, 24 years ago

minor updates

File size: 11.1 KB
Line 
1/* $Id: OS2CLIPPER.CPP,v 1.17 2002-02-13 15:23:10 sandervl Exp $ */
2
3/*
4 * DX clipper class routines
5 *
6 * Copyright 1998-2001 Sander van Leeuwen
7 * Copyright 1999 Markus Montkowski
8 *
9 * Project Odin Software License can be found in LICENSE.TXT
10 *
11 * TODO: This is NOT THREAD SAFE!!!
12 *
13 */
14
15#include <odin.h>
16#include <memory.h>
17
18#define INITGUID
19#include "os2ddraw.h"
20#include "os2clipper.h"
21#define _OS2WIN_H
22#define FAR
23#include <misc.h>
24#include <winerror.h>
25#include <winuser.h>
26#include <winuser32.h>
27#include "oslibgpi.h"
28
29//******************************************************************************
30//******************************************************************************
31OS2IDirectDrawClipper::OS2IDirectDrawClipper(void) :
32 Referenced(0), lastError(DD_OK), fDrawingAllowed(TRUE),
33 clipWindow(0), lpRgnData(NULL), fClipListChanged(FALSE),
34 fClipListChangedInt(FALSE)
35{
36 // this constructor creates an unassociated instance of the ddraw clipper,
37 // no ddraw object is associated
38
39 lpVtbl = &Vtbl;
40 Vtbl.AddRef = ClipAddRef;
41 Vtbl.Release = ClipRelease;
42 Vtbl.QueryInterface = ClipQueryInterface;
43 Vtbl.GetClipList = ClipGetClipList;
44 Vtbl.GetHWnd = ClipGetHWnd;
45 Vtbl.Initialize = ClipInitialize;
46 Vtbl.IsClipListChanged = ClipIsClipListChanged;
47 Vtbl.SetClipList = ClipSetClipList;
48 Vtbl.SetHWnd = ClipSetHWnd;
49
50 lpDraw = NULL;
51 // lpDraw->Vtbl.AddRef(lpDraw);
52 // hDive = lpDirectDraw->GetDiveInstance();
53
54}
55
56//******************************************************************************
57//******************************************************************************
58OS2IDirectDrawClipper::OS2IDirectDrawClipper(OS2IDirectDraw *lpDirectDraw) :
59 Referenced(0), lastError(DD_OK), fDrawingAllowed(TRUE),
60 clipWindow(0), lpRgnData(NULL), fClipListChanged(FALSE),
61 fClipListChangedInt(FALSE)
62{
63 lpVtbl = &Vtbl;
64 Vtbl.AddRef = ClipAddRef;
65 Vtbl.Release = ClipRelease;
66 Vtbl.QueryInterface = ClipQueryInterface;
67 Vtbl.GetClipList = ClipGetClipList;
68 Vtbl.GetHWnd = ClipGetHWnd;
69 Vtbl.Initialize = ClipInitialize;
70 Vtbl.IsClipListChanged = ClipIsClipListChanged;
71 Vtbl.SetClipList = ClipSetClipList;
72 Vtbl.SetHWnd = ClipSetHWnd;
73
74 lpDraw = lpDirectDraw;
75 lpDraw->Vtbl.AddRef(lpDraw);
76 hDive = lpDirectDraw->GetDiveInstance();
77}
78//******************************************************************************
79//******************************************************************************
80OS2IDirectDrawClipper::~OS2IDirectDrawClipper()
81{
82 if(lpRgnData) free(lpRgnData);
83 if(clipWindow) {
84 WinSetVisibleRgnNotifyProc(clipWindow, NULL, 0);
85 }
86 lpDraw->Vtbl.Release(lpDraw);
87}
88//******************************************************************************
89//******************************************************************************
90HRESULT WIN32API ClipQueryInterface(THIS This, REFIID riid, LPVOID FAR * ppvObj)
91{
92 dprintf(("DDRAW: ClipQueryInterface\n"));
93
94 *ppvObj = NULL;
95
96 if(!IsEqualGUID(riid, IID_IDirectDrawClipper) &&
97 !IsEqualGUID(riid, CLSID_DirectDrawClipper))
98//&& !IsEqualGUID(riid, IID_IUnknown))
99 return E_NOINTERFACE;
100
101 *ppvObj = This;
102
103 ClipAddRef(This);
104 return(DD_OK);
105}
106//******************************************************************************
107//******************************************************************************
108ULONG WIN32API ClipAddRef(THIS This)
109{
110 OS2IDirectDrawClipper *me = (OS2IDirectDrawClipper *)This;
111
112 dprintf(("DDRAW: OS2IDirectDrawClipper::AddRef %d\n", me->Referenced+1));
113
114 return ++me->Referenced;
115}
116//******************************************************************************
117//******************************************************************************
118ULONG WIN32API ClipRelease(THIS This)
119{
120 OS2IDirectDrawClipper *me = (OS2IDirectDrawClipper *)This;
121
122 dprintf(("DDRAW: OS2IDirectDrawClipper::Release %d", me->Referenced-1));
123
124 if(me->Referenced)
125 {
126 me->Referenced--;
127 if(me->Referenced == 0)
128 {
129 delete( me);
130 return(0);
131 }
132 else
133 return me->Referenced;
134 }
135 else
136 return(0);
137}
138//******************************************************************************
139//******************************************************************************
140HRESULT WIN32API ClipGetClipList(THIS This, LPRECT lpRect, LPRGNDATA lpClipList,
141 LPDWORD lpdwSize)
142{
143 OS2IDirectDrawClipper *me = (OS2IDirectDrawClipper *)This;
144 HRESULT rc = DD_OK;
145
146 dprintf(("DDRAW: ClipGetClipList %x %x %x %x", This, lpRect, lpClipList, lpdwSize));
147
148 if(!lpdwSize) {
149 return DDERR_INVALIDPARAMS;
150 }
151 if(lpRect) {
152 dprintf(("WARNING: clipping the cliplist is not yet implemented"));
153 }
154 if(me->clipWindow)
155 {
156 RECT *rect = (RECT *)&lpClipList->Buffer;
157 DWORD regiondatasize;
158
159 if(me->lpRgnData == NULL) {
160 DebugInt3();
161 return DDERR_NOCLIPLIST;
162 }
163 //TODO: This is NOT THREAD SAFE!!!
164 regiondatasize = me->lpRgnData->rdh.dwSize + me->lpRgnData->rdh.nCount*sizeof(RECT);
165 if(lpClipList == NULL) {
166 *lpdwSize = regiondatasize;
167 return DD_OK;
168 }
169
170 if(*lpdwSize < regiondatasize) {
171 *lpdwSize = regiondatasize;
172 return DDERR_REGIONTOOSMALL;
173 }
174 memcpy(lpClipList, me->lpRgnData, regiondatasize);
175 dprintf(("Boundary rectangle (%d,%d)(%d,%d)", lpClipList->rdh.rcBound.left, lpClipList->rdh.rcBound.top, lpClipList->rdh.rcBound.right, lpClipList->rdh.rcBound.bottom));
176 }
177 else { //todo!!
178 dprintf(("ClipGetClipList not complete if not associated with window!"));
179 rc = DDERR_NOCLIPLIST;
180 }
181 return rc;
182}
183//******************************************************************************
184//******************************************************************************
185HRESULT WIN32API ClipGetHWnd(THIS This, HWND FAR *pHwnd)
186{
187 OS2IDirectDrawClipper *me = (OS2IDirectDrawClipper *)This;
188
189 dprintf(("DDRAW: ClipGetHWnd %x %x", This, me->clipWindow));
190
191 *pHwnd = me->clipWindow;
192 return(DD_OK);
193}
194//******************************************************************************
195//******************************************************************************
196HRESULT WIN32API ClipInitialize(THIS This, LPDIRECTDRAW lpDD, DWORD dwFlags)
197{
198 OS2IDirectDrawClipper *me = (OS2IDirectDrawClipper *)This;
199
200 dprintf(("DDRAW: ClipInitialize %x %x %x", This, lpDD, dwFlags));
201
202 // check parameters
203 if (dwFlags != 0)
204 return DDERR_INVALIDPARAMS;
205
206 // check if already initialized
207 if (me->hDive != NULL)
208 return(DDERR_ALREADYINITIALIZED); // Init is done during creation see M$ Doc
209
210 // initialize this instance (created with DirectDrawCreateClipper)
211
212 if (lpDD != NULL)
213 {
214 OS2IDirectDraw *os2DD = (OS2IDirectDraw *)lpDD;
215 me->lpDraw = os2DD;
216 me->lpDraw->Vtbl.AddRef(me->lpDraw);
217 me->hDive = me->lpDraw->GetDiveInstance();
218 }
219 else
220 {
221 // we're supposed to create an independent DirectDrawClipper object
222 // now.
223 if (me->lpDraw != NULL)
224 {
225 // we're not handling this any other currently
226 return(DDERR_ALREADYINITIALIZED);
227 }
228 // else
229 // we've been independent and remain so ...
230 }
231
232 return(DD_OK);
233}
234//******************************************************************************
235//******************************************************************************
236HRESULT WIN32API ClipIsClipListChanged(THIS This, BOOL *lpbChanged)
237{
238 OS2IDirectDrawClipper *me = (OS2IDirectDrawClipper *)This;
239
240 dprintf(("DDRAW: ClipIsClipListChanged %x %x", This, lpbChanged));
241
242 if(lpbChanged == NULL) {
243 return DDERR_INVALIDPARAMS;
244 }
245 *lpbChanged = me->fClipListChanged;
246 me->fClipListChanged = FALSE;
247 return(DD_OK);
248}
249//******************************************************************************
250//******************************************************************************
251HRESULT WIN32API ClipSetClipList(THIS This, LPRGNDATA lpClipList, DWORD dwFlags)
252{
253 OS2IDirectDrawClipper *me = (OS2IDirectDrawClipper *)This;
254
255 dprintf(("DDRAW: ClipSetClipList %x %x %x", This, lpClipList, dwFlags));
256
257 if(me->clipWindow) {
258 return DDERR_CLIPPERISUSINGHWND;
259 }
260 if(lpClipList == NULL) {
261 //TODO: should protect this with a critical section
262 if(me->lpRgnData) {
263 free(me->lpRgnData);
264 me->lpRgnData = NULL;
265 }
266 return DD_OK;
267 }
268 //TODO: return error if a clip list is already active??
269 if(me->lpRgnData) {
270 free(me->lpRgnData);
271 me->lpRgnData = NULL;
272 }
273 me->lpRgnData = (LPRGNDATA)malloc(lpClipList->rdh.dwSize + lpClipList->rdh.nCount*sizeof(RECT));
274 memcpy(me->lpRgnData, lpClipList, lpClipList->rdh.dwSize + lpClipList->rdh.nCount*sizeof(RECT));
275 return DD_OK;
276}
277//******************************************************************************
278//******************************************************************************
279BOOL WIN32API ClipVisRgnCallback(HWND hwnd, BOOL fDrawingAllowed, DWORD dwUserData)
280{
281 OS2IDirectDrawClipper *me = (OS2IDirectDrawClipper *)dwUserData;
282 LPRGNDATA lpClipList, lpRgnOld;
283
284 dprintf(("DDRAW: ClipVisRgnCallback %x %x %x", me, hwnd, fDrawingAllowed));
285 if(me && me->clipWindow == hwnd) {
286 me->fClipListChanged = TRUE;
287 me->fClipListChangedInt = TRUE; //internal flag
288 lpRgnOld = me->lpRgnData;
289 if(fDrawingAllowed == FALSE) {
290 me->fDrawingAllowed = FALSE;
291 lpClipList = (LPRGNDATA)malloc(sizeof(RGNDATA));
292 lpClipList->rdh.dwSize = sizeof(lpClipList->rdh);
293 lpClipList->rdh.iType = RDH_RECTANGLES; // one and only possible value
294 lpClipList->rdh.nCount = 0;
295 lpClipList->rdh.nRgnSize = 0;
296 me->lpRgnData = lpClipList;
297 }
298 else {
299 me->fDrawingAllowed = TRUE;
300 me->lpRgnData = OSLibQueryVisibleRegion(hwnd, (me->lpDraw) ? me->lpDraw->GetScreenHeight() : 0);
301 }
302 free(lpRgnOld);
303 }
304 return TRUE;
305}
306//******************************************************************************
307//DWORD param not used in DirectX 3
308//******************************************************************************
309HRESULT WIN32API ClipSetHWnd(THIS This, DWORD reserved, HWND hwnd)
310{
311 OS2IDirectDrawClipper *me = (OS2IDirectDrawClipper *)This;
312
313 dprintf(("DDRAW: ClipSetHWnd %x %x %x", This, reserved, hwnd));
314
315 if(!IsWindow(hwnd)) {
316 dprintf(("WARNING: ClipSetHWnd invalid window handle"));
317 return DDERR_INVALIDPARAMS;
318 }
319 if(me->clipWindow) {
320 //TODO: Is this really allowed??
321 WinSetVisibleRgnNotifyProc(me->clipWindow, NULL, 0);
322 }
323 me->clipWindow = hwnd;
324 WinSetVisibleRgnNotifyProc(hwnd, ClipVisRgnCallback, (DWORD)me);
325
326 me->lpRgnData = OSLibQueryVisibleRegion(hwnd, (me->lpDraw) ? me->lpDraw->GetScreenHeight() : 0);
327 me->fClipListChanged = TRUE;
328 me->fClipListChangedInt = TRUE; //internal flag
329
330 return(DD_OK);
331}
332//******************************************************************************
333//******************************************************************************
Note: See TracBrowser for help on using the repository browser.