source: trunk/src/ddraw/clipper.cpp

Last change on this file was 21494, checked in by dmik, 15 years ago

Fixed broken build after r21492 by sorting out a huuuuge wagon of duplicates, wrong include order and other dirty mess.

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