VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Video/common/VBoxVideoTools.h@ 56378

Last change on this file since 56378 was 45132, checked in by vboxsync, 12 years ago

crOpenGL: seamles mode support impl; bugfizes & cleanup

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.8 KB
Line 
1/* $Id: VBoxVideoTools.h 45132 2013-03-21 16:11:28Z vboxsync $ */
2
3/** @file
4 * VBox Video tooling
5 */
6
7/*
8 * Copyright (C) 2012 Oracle Corporation
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 */
18#ifndef ___VBoxVideoTools_h__
19#define ___VBoxVideoTools_h__
20
21#include <iprt/cdefs.h>
22#include <iprt/assert.h>
23
24typedef struct VBOXVTLIST_ENTRY
25{
26 struct VBOXVTLIST_ENTRY *pNext;
27} VBOXVTLIST_ENTRY, *PVBOXVTLIST_ENTRY;
28
29typedef struct VBOXVTLIST
30{
31 PVBOXVTLIST_ENTRY pFirst;
32 PVBOXVTLIST_ENTRY pLast;
33} VBOXVTLIST, *PVBOXVTLIST;
34
35DECLINLINE(bool) vboxVtListIsEmpty(PVBOXVTLIST pList)
36{
37 return !pList->pFirst;
38}
39
40DECLINLINE(void) vboxVtListInit(PVBOXVTLIST pList)
41{
42 pList->pFirst = pList->pLast = NULL;
43}
44
45DECLINLINE(void) vboxVtListPut(PVBOXVTLIST pList, PVBOXVTLIST_ENTRY pFirst, PVBOXVTLIST_ENTRY pLast)
46{
47 Assert(pFirst);
48 Assert(pLast);
49 pLast->pNext = NULL;
50 if (pList->pLast)
51 {
52 Assert(pList->pFirst);
53 pList->pLast->pNext = pFirst;
54 pList->pLast = pLast;
55 }
56 else
57 {
58 Assert(!pList->pFirst);
59 pList->pFirst = pFirst;
60 pList->pLast = pLast;
61 }
62}
63
64#define vboxVtListPutTail vboxVtListPut
65
66DECLINLINE(void) vboxVtListPutHead(PVBOXVTLIST pList, PVBOXVTLIST_ENTRY pFirst, PVBOXVTLIST_ENTRY pLast)
67{
68 Assert(pFirst);
69 Assert(pLast);
70 pLast->pNext = pList->pFirst;
71 if (!pList->pLast)
72 {
73 Assert(!pList->pFirst);
74 pList->pLast = pLast;
75 }
76 else
77 {
78 Assert(pList->pFirst);
79 }
80 pList->pFirst = pFirst;
81}
82
83DECLINLINE(void) vboxVtListPutEntryHead(PVBOXVTLIST pList, PVBOXVTLIST_ENTRY pEntry)
84{
85 vboxVtListPutHead(pList, pEntry, pEntry);
86}
87
88DECLINLINE(void) vboxVtListPutEntryTail(PVBOXVTLIST pList, PVBOXVTLIST_ENTRY pEntry)
89{
90 vboxVtListPutTail(pList, pEntry, pEntry);
91}
92
93DECLINLINE(void) vboxVtListCat(PVBOXVTLIST pList1, PVBOXVTLIST pList2)
94{
95 vboxVtListPut(pList1, pList2->pFirst, pList2->pLast);
96 pList2->pFirst = pList2->pLast = NULL;
97}
98
99DECLINLINE(void) vboxVtListDetach(PVBOXVTLIST pList, PVBOXVTLIST_ENTRY *ppFirst, PVBOXVTLIST_ENTRY *ppLast)
100{
101 *ppFirst = pList->pFirst;
102 if (ppLast)
103 *ppLast = pList->pLast;
104 pList->pFirst = NULL;
105 pList->pLast = NULL;
106}
107
108DECLINLINE(void) vboxVtListDetach2List(PVBOXVTLIST pList, PVBOXVTLIST pDstList)
109{
110 vboxVtListDetach(pList, &pDstList->pFirst, &pDstList->pLast);
111}
112
113DECLINLINE(void) vboxVtListDetachEntries(PVBOXVTLIST pList, PVBOXVTLIST_ENTRY pBeforeDetach, PVBOXVTLIST_ENTRY pLast2Detach)
114{
115 if (pBeforeDetach)
116 {
117 pBeforeDetach->pNext = pLast2Detach->pNext;
118 if (!pBeforeDetach->pNext)
119 pList->pLast = pBeforeDetach;
120 }
121 else
122 {
123 pList->pFirst = pLast2Detach->pNext;
124 if (!pList->pFirst)
125 pList->pLast = NULL;
126 }
127 pLast2Detach->pNext = NULL;
128}
129
130DECLINLINE(void) vboxWddmRectUnite(RECT *pR, const RECT *pR2Unite)
131{
132 pR->left = RT_MIN(pR->left, pR2Unite->left);
133 pR->top = RT_MIN(pR->top, pR2Unite->top);
134 pR->right = RT_MAX(pR->right, pR2Unite->right);
135 pR->bottom = RT_MAX(pR->bottom, pR2Unite->bottom);
136}
137
138DECLINLINE(bool) vboxWddmRectIntersection(const RECT *a, const RECT *b, RECT *rect)
139{
140 Assert(a);
141 Assert(b);
142 Assert(rect);
143 rect->left = RT_MAX(a->left, b->left);
144 rect->right = RT_MIN(a->right, b->right);
145 rect->top = RT_MAX(a->top, b->top);
146 rect->bottom = RT_MIN(a->bottom, b->bottom);
147 return (rect->right>rect->left) && (rect->bottom>rect->top);
148}
149
150DECLINLINE(bool) vboxWddmRectIsEqual(const RECT *pRect1, const RECT *pRect2)
151{
152 Assert(pRect1);
153 Assert(pRect2);
154 if (pRect1->left != pRect2->left)
155 return false;
156 if (pRect1->top != pRect2->top)
157 return false;
158 if (pRect1->right != pRect2->right)
159 return false;
160 if (pRect1->bottom != pRect2->bottom)
161 return false;
162 return true;
163}
164
165DECLINLINE(bool) vboxWddmRectIsCoveres(const RECT *pRect, const RECT *pCovered)
166{
167 Assert(pRect);
168 Assert(pCovered);
169 if (pRect->left > pCovered->left)
170 return false;
171 if (pRect->top > pCovered->top)
172 return false;
173 if (pRect->right < pCovered->right)
174 return false;
175 if (pRect->bottom < pCovered->bottom)
176 return false;
177 return true;
178}
179
180DECLINLINE(bool) vboxWddmRectIsEmpty(const RECT * pRect)
181{
182 return pRect->left == pRect->right-1 && pRect->top == pRect->bottom-1;
183}
184
185DECLINLINE(bool) vboxWddmRectIsIntersect(const RECT * pRect1, const RECT * pRect2)
186{
187 return !((pRect1->left < pRect2->left && pRect1->right <= pRect2->left)
188 || (pRect2->left < pRect1->left && pRect2->right <= pRect1->left)
189 || (pRect1->top < pRect2->top && pRect1->bottom <= pRect2->top)
190 || (pRect2->top < pRect1->top && pRect2->bottom <= pRect1->top));
191}
192
193DECLINLINE(void) vboxWddmRectUnited(RECT * pDst, const RECT * pRect1, const RECT * pRect2)
194{
195 pDst->left = RT_MIN(pRect1->left, pRect2->left);
196 pDst->top = RT_MIN(pRect1->top, pRect2->top);
197 pDst->right = RT_MAX(pRect1->right, pRect2->right);
198 pDst->bottom = RT_MAX(pRect1->bottom, pRect2->bottom);
199}
200
201DECLINLINE(void) vboxWddmRectTranslate(RECT * pRect, int x, int y)
202{
203 pRect->left += x;
204 pRect->top += y;
205 pRect->right += x;
206 pRect->bottom += y;
207}
208
209DECLINLINE(void) vboxWddmRectMove(RECT * pRect, int x, int y)
210{
211 LONG w = pRect->right - pRect->left;
212 LONG h = pRect->bottom - pRect->top;
213 pRect->left = x;
214 pRect->top = y;
215 pRect->right = w + x;
216 pRect->bottom = h + y;
217}
218
219DECLINLINE(void) vboxWddmRectTranslated(RECT *pDst, const RECT * pRect, int x, int y)
220{
221 *pDst = *pRect;
222 vboxWddmRectTranslate(pDst, x, y);
223}
224
225DECLINLINE(void) vboxWddmRectMoved(RECT *pDst, const RECT * pRect, int x, int y)
226{
227 *pDst = *pRect;
228 vboxWddmRectMove(pDst, x, y);
229}
230
231typedef struct VBOXPOINT3D
232{
233 UINT x;
234 UINT y;
235 UINT z;
236} VBOXPOINT3D, *PVBOXPOINT3D;
237
238typedef struct VBOXBOX3D
239{
240 UINT Left;
241 UINT Top;
242 UINT Right;
243 UINT Bottom;
244 UINT Front;
245 UINT Back;
246} VBOXBOX3D, *PVBOXBOX3D;
247
248DECLINLINE(void) vboxWddmBoxTranslate(VBOXBOX3D * pBox, int x, int y, int z)
249{
250 pBox->Left += x;
251 pBox->Top += y;
252 pBox->Right += x;
253 pBox->Bottom += y;
254 pBox->Front += z;
255 pBox->Back += z;
256}
257
258DECLINLINE(void) vboxWddmBoxMove(VBOXBOX3D * pBox, int x, int y, int z)
259{
260 LONG w = pBox->Right - pBox->Left;
261 LONG h = pBox->Bottom - pBox->Top;
262 LONG d = pBox->Back - pBox->Front;
263 pBox->Left = x;
264 pBox->Top = y;
265 pBox->Right = w + x;
266 pBox->Bottom = h + y;
267 pBox->Front = z;
268 pBox->Back = d + z;
269}
270
271#define VBOXWDDM_BOXDIV_U(_v, _d, _nz) do { \
272 UINT tmp = (_v) / (_d); \
273 if (!tmp && (_v) && (_nz)) \
274 (_v) = 1; \
275 else \
276 (_v) = tmp; \
277 } while (0)
278
279DECLINLINE(void) vboxWddmBoxDivide(VBOXBOX3D * pBox, int div, bool fDontReachZero)
280{
281 VBOXWDDM_BOXDIV_U(pBox->Left, div, fDontReachZero);
282 VBOXWDDM_BOXDIV_U(pBox->Top, div, fDontReachZero);
283 VBOXWDDM_BOXDIV_U(pBox->Right, div, fDontReachZero);
284 VBOXWDDM_BOXDIV_U(pBox->Bottom, div, fDontReachZero);
285 VBOXWDDM_BOXDIV_U(pBox->Front, div, fDontReachZero);
286 VBOXWDDM_BOXDIV_U(pBox->Back, div, fDontReachZero);
287}
288
289DECLINLINE(void) vboxWddmPoint3DDivide(VBOXPOINT3D * pPoint, int div, bool fDontReachZero)
290{
291 VBOXWDDM_BOXDIV_U(pPoint->x, div, fDontReachZero);
292 VBOXWDDM_BOXDIV_U(pPoint->y, div, fDontReachZero);
293 VBOXWDDM_BOXDIV_U(pPoint->y, div, fDontReachZero);
294}
295
296DECLINLINE(void) vboxWddmBoxTranslated(VBOXBOX3D * pDst, const VBOXBOX3D * pBox, int x, int y, int z)
297{
298 *pDst = *pBox;
299 vboxWddmBoxTranslate(pDst, x, y, z);
300}
301
302DECLINLINE(void) vboxWddmBoxMoved(VBOXBOX3D * pDst, const VBOXBOX3D * pBox, int x, int y, int z)
303{
304 *pDst = *pBox;
305 vboxWddmBoxMove(pDst, x, y, z);
306}
307
308DECLINLINE(void) vboxWddmBoxDivided(VBOXBOX3D * pDst, const VBOXBOX3D * pBox, int div, bool fDontReachZero)
309{
310 *pDst = *pBox;
311 vboxWddmBoxDivide(pDst, div, fDontReachZero);
312}
313
314DECLINLINE(void) vboxWddmPoint3DDivided(VBOXPOINT3D * pDst, const VBOXPOINT3D * pPoint, int div, bool fDontReachZero)
315{
316 *pDst = *pPoint;
317 vboxWddmPoint3DDivide(pDst, div, fDontReachZero);
318}
319
320/* the dirty rect info is valid */
321#define VBOXWDDM_DIRTYREGION_F_VALID 0x00000001
322#define VBOXWDDM_DIRTYREGION_F_RECT_VALID 0x00000002
323
324typedef struct VBOXWDDM_DIRTYREGION
325{
326 uint32_t fFlags; /* <-- see VBOXWDDM_DIRTYREGION_F_xxx flags above */
327 RECT Rect;
328} VBOXWDDM_DIRTYREGION, *PVBOXWDDM_DIRTYREGION;
329
330DECLINLINE(void) vboxWddmDirtyRegionAddRect(PVBOXWDDM_DIRTYREGION pInfo, const RECT *pRect)
331{
332 if (!(pInfo->fFlags & VBOXWDDM_DIRTYREGION_F_VALID))
333 {
334 pInfo->fFlags = VBOXWDDM_DIRTYREGION_F_VALID;
335 if (pRect)
336 {
337 pInfo->fFlags |= VBOXWDDM_DIRTYREGION_F_RECT_VALID;
338 pInfo->Rect = *pRect;
339 }
340 }
341 else if (!!(pInfo->fFlags & VBOXWDDM_DIRTYREGION_F_RECT_VALID))
342 {
343 if (pRect)
344 vboxWddmRectUnite(&pInfo->Rect, pRect);
345 else
346 pInfo->fFlags &= ~VBOXWDDM_DIRTYREGION_F_RECT_VALID;
347 }
348}
349
350DECLINLINE(void) vboxWddmDirtyRegionUnite(PVBOXWDDM_DIRTYREGION pInfo, const VBOXWDDM_DIRTYREGION *pInfo2)
351{
352 if (pInfo2->fFlags & VBOXWDDM_DIRTYREGION_F_VALID)
353 {
354 if (pInfo2->fFlags & VBOXWDDM_DIRTYREGION_F_RECT_VALID)
355 vboxWddmDirtyRegionAddRect(pInfo, &pInfo2->Rect);
356 else
357 vboxWddmDirtyRegionAddRect(pInfo, NULL);
358 }
359}
360
361DECLINLINE(void) vboxWddmDirtyRegionClear(PVBOXWDDM_DIRTYREGION pInfo)
362{
363 pInfo->fFlags = 0;
364}
365
366#endif /* #ifndef ___VBoxVideoTools_h__ */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette