VirtualBox

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

Last change on this file since 82968 was 82968, checked in by vboxsync, 5 years ago

Copyright year updates by scm.

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