VirtualBox

source: vbox/trunk/src/VBox/GuestHost/OpenGL/include/cr_vreg.h@ 53426

Last change on this file since 53426 was 50944, checked in by vboxsync, 11 years ago

wddm/crOpenGL: new command submission fixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.2 KB
Line 
1/* $Id: cr_vreg.h 50944 2014-04-01 13:53:32Z vboxsync $ */
2
3/** @file
4 * Visible Regions processing API
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 ___cr_vreg_h_
19#define ___cr_vreg_h_
20
21#include <iprt/list.h>
22#include <iprt/types.h>
23#include <iprt/mem.h>
24#include <iprt/string.h>
25#include <iprt/assert.h>
26#include <iprt/critsect.h>
27#include <iprt/asm.h>
28
29#ifndef IN_RING0
30# define VBOXVREGDECL(_type) DECLEXPORT(_type)
31#else
32# define VBOXVREGDECL(_type) RTDECL(_type)
33#endif
34
35
36
37RT_C_DECLS_BEGIN
38
39typedef struct VBOXVR_LIST
40{
41 RTLISTNODE ListHead;
42 uint32_t cEntries;
43} VBOXVR_LIST, *PVBOXVR_LIST;
44
45DECLINLINE(int) VBoxRectCmp(const RTRECT * pRect1, const RTRECT * pRect2)
46{
47 return memcmp(pRect1, pRect2, sizeof (*pRect1));
48}
49
50#ifndef IN_RING0
51#define CR_FLOAT_RCAST(_t, _v) ((_t)((float)(_v) + 0.5))
52
53DECLINLINE(void) VBoxRectScale(PRTRECT pRect, float xScale, float yScale)
54{
55 pRect->xLeft = CR_FLOAT_RCAST(int32_t, pRect->xLeft * xScale);
56 pRect->yTop = CR_FLOAT_RCAST(int32_t, pRect->yTop * yScale);
57 pRect->xRight = CR_FLOAT_RCAST(int32_t, pRect->xRight * xScale);
58 pRect->yBottom = CR_FLOAT_RCAST(int32_t, pRect->yBottom * yScale);
59}
60
61DECLINLINE(void) VBoxRectScaled(const RTRECT *pRect, float xScale, float yScale, PRTRECT pResult)
62{
63 *pResult = *pRect;
64 VBoxRectScale(pResult, xScale, yScale);
65}
66
67DECLINLINE(void) VBoxRectUnscale(PRTRECT pRect, float xScale, float yScale)
68{
69 pRect->xLeft = CR_FLOAT_RCAST(int32_t, pRect->xLeft / xScale);
70 pRect->yTop = CR_FLOAT_RCAST(int32_t, pRect->yTop / yScale);
71 pRect->xRight = CR_FLOAT_RCAST(int32_t, pRect->xRight / xScale);
72 pRect->yBottom = CR_FLOAT_RCAST(int32_t, pRect->yBottom / yScale);
73}
74
75DECLINLINE(void) VBoxRectUnscaled(const RTRECT *pRect, float xScale, float yScale, PRTRECT pResult)
76{
77 *pResult = *pRect;
78 VBoxRectUnscale(pResult, xScale, yScale);
79}
80#endif
81
82DECLINLINE(void) VBoxRectIntersect(PRTRECT pRect1, const RTRECT * pRect2)
83{
84 Assert(pRect1);
85 Assert(pRect2);
86 pRect1->xLeft = RT_MAX(pRect1->xLeft, pRect2->xLeft);
87 pRect1->yTop = RT_MAX(pRect1->yTop, pRect2->yTop);
88 pRect1->xRight = RT_MIN(pRect1->xRight, pRect2->xRight);
89 pRect1->yBottom = RT_MIN(pRect1->yBottom, pRect2->yBottom);
90 /* ensure the rect is valid */
91 pRect1->xRight = RT_MAX(pRect1->xRight, pRect1->xLeft);
92 pRect1->yBottom = RT_MAX(pRect1->yBottom, pRect1->yTop);
93}
94
95DECLINLINE(void) VBoxRectIntersected(const RTRECT *pRect1, const RTRECT * pRect2, RTRECT *pResult)
96{
97 *pResult = *pRect1;
98 VBoxRectIntersect(pResult, pRect2);
99}
100
101
102DECLINLINE(void) VBoxRectTranslate(RTRECT * pRect, int32_t x, int32_t y)
103{
104 pRect->xLeft += x;
105 pRect->yTop += y;
106 pRect->xRight += x;
107 pRect->yBottom += y;
108}
109
110DECLINLINE(void) VBoxRectTranslated(const RTRECT * pRect, int32_t x, int32_t y, RTRECT *pResult)
111{
112 *pResult = *pRect;
113 VBoxRectTranslate(pResult, x, y);
114}
115
116DECLINLINE(void) VBoxRectInvertY(RTRECT * pRect)
117{
118 int32_t y = pRect->yTop;
119 pRect->yTop = pRect->yBottom;
120 pRect->yBottom = y;
121}
122
123DECLINLINE(void) VBoxRectInvertedY(const RTRECT * pRect, RTRECT * pResult)
124{
125 *pResult = *pRect;
126 VBoxRectInvertY(pResult);
127}
128
129DECLINLINE(void) VBoxRectMove(RTRECT * pRect, int32_t x, int32_t y)
130{
131 int32_t w = pRect->xRight - pRect->xLeft;
132 int32_t h = pRect->yBottom - pRect->yTop;
133 pRect->xLeft = x;
134 pRect->yTop = y;
135 pRect->xRight = w + x;
136 pRect->yBottom = h + y;
137}
138
139DECLINLINE(void) VBoxRectMoved(const RTRECT * pRect, int32_t x, int32_t y, RTRECT *pResult)
140{
141 *pResult = *pRect;
142 VBoxRectMove(pResult, x, y);
143}
144
145DECLINLINE(bool) VBoxRectCovers(const RTRECT *pRect, const RTRECT *pCovered)
146{
147 Assert(pRect);
148 Assert(pCovered);
149 if (pRect->xLeft > pCovered->xLeft)
150 return false;
151 if (pRect->yTop > pCovered->yTop)
152 return false;
153 if (pRect->xRight < pCovered->xRight)
154 return false;
155 if (pRect->yBottom < pCovered->yBottom)
156 return false;
157 return true;
158}
159
160DECLINLINE(bool) VBoxRectIsZero(const RTRECT *pRect)
161{
162 return pRect->xLeft == pRect->xRight || pRect->yTop == pRect->yBottom;
163}
164
165DECLINLINE(bool) VBoxRectIsIntersect(const RTRECT * pRect1, const RTRECT * pRect2)
166{
167 return !((pRect1->xLeft < pRect2->xLeft && pRect1->xRight <= pRect2->xLeft)
168 || (pRect2->xLeft < pRect1->xLeft && pRect2->xRight <= pRect1->xLeft)
169 || (pRect1->yTop < pRect2->yTop && pRect1->yBottom <= pRect2->yTop)
170 || (pRect2->yTop < pRect1->yTop && pRect2->yBottom <= pRect1->yTop));
171}
172
173DECLINLINE(uint32_t) VBoxVrListRectsCount(const VBOXVR_LIST *pList)
174{
175 return pList->cEntries;
176}
177
178DECLINLINE(bool) VBoxVrListIsEmpty(const VBOXVR_LIST *pList)
179{
180 return !VBoxVrListRectsCount(pList);
181}
182
183DECLINLINE(void) VBoxVrListInit(PVBOXVR_LIST pList)
184{
185 RTListInit(&pList->ListHead);
186 pList->cEntries = 0;
187}
188
189VBOXVREGDECL(void) VBoxVrListClear(PVBOXVR_LIST pList);
190
191/* moves list data to pDstList and empties the pList */
192VBOXVREGDECL(void) VBoxVrListMoveTo(PVBOXVR_LIST pList, PVBOXVR_LIST pDstList);
193
194VBOXVREGDECL(void) VBoxVrListTranslate(PVBOXVR_LIST pList, int32_t x, int32_t y);
195
196VBOXVREGDECL(int) VBoxVrListCmp(const VBOXVR_LIST *pList1, const VBOXVR_LIST *pList2);
197
198VBOXVREGDECL(int) VBoxVrListRectsSet(PVBOXVR_LIST pList, uint32_t cRects, const RTRECT * aRects, bool *pfChanged);
199VBOXVREGDECL(int) VBoxVrListRectsAdd(PVBOXVR_LIST pList, uint32_t cRects, const RTRECT * aRects, bool *pfChanged);
200VBOXVREGDECL(int) VBoxVrListRectsSubst(PVBOXVR_LIST pList, uint32_t cRects, const RTRECT * aRects, bool *pfChanged);
201VBOXVREGDECL(int) VBoxVrListRectsGet(PVBOXVR_LIST pList, uint32_t cRects, RTRECT * aRects);
202
203VBOXVREGDECL(int) VBoxVrListClone(const VBOXVR_LIST *pList, VBOXVR_LIST *pDstList);
204
205/* NOTE: with the current implementation the VBoxVrListIntersect is faster than VBoxVrListRectsIntersect,
206 * i.e. VBoxVrListRectsIntersect is actually a convenience function that create a temporary list and calls VBoxVrListIntersect internally */
207VBOXVREGDECL(int) VBoxVrListRectsIntersect(PVBOXVR_LIST pList, uint32_t cRects, const RTRECT * aRects, bool *pfChanged);
208VBOXVREGDECL(int) VBoxVrListIntersect(PVBOXVR_LIST pList, const VBOXVR_LIST *pList2, bool *pfChanged);
209
210VBOXVREGDECL(int) VBoxVrInit(void);
211VBOXVREGDECL(void) VBoxVrTerm(void);
212
213typedef struct VBOXVR_LIST_ITERATOR
214{
215 PVBOXVR_LIST pList;
216 PRTLISTNODE pNextEntry;
217} VBOXVR_LIST_ITERATOR, *PVBOXVR_LIST_ITERATOR;
218
219DECLINLINE(void) VBoxVrListIterInit(PVBOXVR_LIST pList, PVBOXVR_LIST_ITERATOR pIter)
220{
221 pIter->pList = pList;
222 pIter->pNextEntry = pList->ListHead.pNext;
223}
224
225typedef struct VBOXVR_REG
226{
227 RTLISTNODE ListEntry;
228 RTRECT Rect;
229} VBOXVR_REG, *PVBOXVR_REG;
230
231#define PVBOXVR_REG_FROM_ENTRY(_pEntry) ((PVBOXVR_REG)(((uint8_t*)(_pEntry)) - RT_OFFSETOF(VBOXVR_REG, ListEntry)))
232
233DECLINLINE(PCRTRECT) VBoxVrListIterNext(PVBOXVR_LIST_ITERATOR pIter)
234{
235 PRTLISTNODE pNextEntry = pIter->pNextEntry;
236 if (pNextEntry != &pIter->pList->ListHead)
237 {
238 PCRTRECT pRect = &(PVBOXVR_REG_FROM_ENTRY(pNextEntry)->Rect);
239 pIter->pNextEntry = pNextEntry->pNext;
240 return pRect;
241 }
242 return NULL;
243}
244
245typedef struct VBOXVR_COMPOSITOR_ENTRY
246{
247 RTLISTNODE Node;
248 VBOXVR_LIST Vr;
249 uint32_t cRefs;
250} VBOXVR_COMPOSITOR_ENTRY, *PVBOXVR_COMPOSITOR_ENTRY;
251
252struct VBOXVR_COMPOSITOR;
253
254typedef DECLCALLBACK(void) FNVBOXVRCOMPOSITOR_ENTRY_RELEASED(const struct VBOXVR_COMPOSITOR *pCompositor, PVBOXVR_COMPOSITOR_ENTRY pEntry, PVBOXVR_COMPOSITOR_ENTRY pReplacingEntry);
255typedef FNVBOXVRCOMPOSITOR_ENTRY_RELEASED *PFNVBOXVRCOMPOSITOR_ENTRY_RELEASED;
256
257typedef struct VBOXVR_COMPOSITOR
258{
259 RTLISTNODE List;
260 PFNVBOXVRCOMPOSITOR_ENTRY_RELEASED pfnEntryReleased;
261} VBOXVR_COMPOSITOR, *PVBOXVR_COMPOSITOR;
262
263typedef DECLCALLBACK(bool) FNVBOXVRCOMPOSITOR_VISITOR(PVBOXVR_COMPOSITOR pCompositor, PVBOXVR_COMPOSITOR_ENTRY pEntry, void *pvVisitor);
264typedef FNVBOXVRCOMPOSITOR_VISITOR *PFNVBOXVRCOMPOSITOR_VISITOR;
265
266VBOXVREGDECL(void) VBoxVrCompositorInit(PVBOXVR_COMPOSITOR pCompositor, PFNVBOXVRCOMPOSITOR_ENTRY_RELEASED pfnEntryReleased);
267VBOXVREGDECL(void) VBoxVrCompositorClear(PVBOXVR_COMPOSITOR pCompositor);
268VBOXVREGDECL(void) VBoxVrCompositorRegionsClear(PVBOXVR_COMPOSITOR pCompositor, bool *pfChanged);
269VBOXVREGDECL(void) VBoxVrCompositorEntryInit(PVBOXVR_COMPOSITOR_ENTRY pEntry);
270DECLINLINE(bool) VBoxVrCompositorEntryIsInList(const VBOXVR_COMPOSITOR_ENTRY *pEntry)
271{
272 return !VBoxVrListIsEmpty(&pEntry->Vr);
273}
274
275#define CRBLT_F_LINEAR 0x00000001
276#define CRBLT_F_INVERT_SRC_YCOORDS 0x00000002
277#define CRBLT_F_INVERT_DST_YCOORDS 0x00000004
278#define CRBLT_F_INVERT_YCOORDS (CRBLT_F_INVERT_SRC_YCOORDS | CRBLT_F_INVERT_DST_YCOORDS)
279/* the blit operation with discard the source alpha channel values and set the destination alpha values to 1.0 */
280#define CRBLT_F_NOALPHA 0x00000010
281
282#define CRBLT_FTYPE_XOR CRBLT_F_INVERT_YCOORDS
283#define CRBLT_FTYPE_OR (CRBLT_F_LINEAR | CRBLT_F_NOALPHA)
284#define CRBLT_FOP_COMBINE(_f1, _f2) ((((_f1) ^ (_f2)) & CRBLT_FTYPE_XOR) | (((_f1) | (_f2)) & CRBLT_FTYPE_OR))
285
286#define CRBLT_FLAGS_FROM_FILTER(_f) ( ((_f) & GL_LINEAR) ? CRBLT_F_LINEAR : 0)
287#define CRBLT_FILTER_FROM_FLAGS(_f) (((_f) & CRBLT_F_LINEAR) ? GL_LINEAR : GL_NEAREST)
288
289/* compositor regions changed */
290#define VBOXVR_COMPOSITOR_CF_REGIONS_CHANGED 0x00000001
291/* other entries changed along while doing current entry modification
292 * always comes with VBOXVR_COMPOSITOR_CF_ENTRY_REGIONS_CHANGED */
293#define VBOXVR_COMPOSITOR_CF_OTHER_ENTRIES_REGIONS_CHANGED 0x00000002
294/* only current entry regions changed
295 * can come wither with VBOXVR_COMPOSITOR_CF_REGIONS_CHANGED or with VBOXVR_COMPOSITOR_CF_ENTRY_REPLACED */
296#define VBOXVR_COMPOSITOR_CF_ENTRY_REGIONS_CHANGED 0x00000004
297/* the given entry has replaced some other entry, while overal regions did NOT change.
298 * always comes with VBOXVR_COMPOSITOR_CF_ENTRY_REGIONS_CHANGED */
299#define VBOXVR_COMPOSITOR_CF_ENTRY_REPLACED 0x00000008
300
301
302VBOXVREGDECL(bool) VBoxVrCompositorEntryRemove(PVBOXVR_COMPOSITOR pCompositor, PVBOXVR_COMPOSITOR_ENTRY pEntry);
303VBOXVREGDECL(bool) VBoxVrCompositorEntryReplace(PVBOXVR_COMPOSITOR pCompositor, PVBOXVR_COMPOSITOR_ENTRY pEntry, PVBOXVR_COMPOSITOR_ENTRY pNewEntry);
304VBOXVREGDECL(int) VBoxVrCompositorEntryRegionsAdd(PVBOXVR_COMPOSITOR pCompositor, PVBOXVR_COMPOSITOR_ENTRY pEntry, uint32_t cRegions, const RTRECT *paRegions, PVBOXVR_COMPOSITOR_ENTRY *ppReplacedEntry, uint32_t *pfChangeFlags);
305VBOXVREGDECL(int) VBoxVrCompositorEntryRegionsSubst(PVBOXVR_COMPOSITOR pCompositor, PVBOXVR_COMPOSITOR_ENTRY pEntry, uint32_t cRegions, const RTRECT *paRegions, bool *pfChanged);
306VBOXVREGDECL(int) VBoxVrCompositorEntryRegionsSet(PVBOXVR_COMPOSITOR pCompositor, PVBOXVR_COMPOSITOR_ENTRY pEntry, uint32_t cRegions, const RTRECT *paRegions, bool *pfChanged);
307VBOXVREGDECL(int) VBoxVrCompositorEntryRegionsIntersect(PVBOXVR_COMPOSITOR pCompositor, PVBOXVR_COMPOSITOR_ENTRY pEntry, uint32_t cRegions, const RTRECT *paRegions, bool *pfChanged);
308VBOXVREGDECL(int) VBoxVrCompositorEntryListIntersect(PVBOXVR_COMPOSITOR pCompositor, PVBOXVR_COMPOSITOR_ENTRY pEntry, const VBOXVR_LIST *pList2, bool *pfChanged);
309VBOXVREGDECL(int) VBoxVrCompositorEntryRegionsIntersectAll(PVBOXVR_COMPOSITOR pCompositor, uint32_t cRegions, const RTRECT *paRegions, bool *pfChanged);
310VBOXVREGDECL(int) VBoxVrCompositorEntryListIntersectAll(PVBOXVR_COMPOSITOR pCompositor, const VBOXVR_LIST *pList2, bool *pfChanged);
311VBOXVREGDECL(int) VBoxVrCompositorEntryRegionsTranslate(PVBOXVR_COMPOSITOR pCompositor, PVBOXVR_COMPOSITOR_ENTRY pEntry, int32_t x, int32_t y, bool *pfChanged);
312VBOXVREGDECL(void) VBoxVrCompositorVisit(PVBOXVR_COMPOSITOR pCompositor, PFNVBOXVRCOMPOSITOR_VISITOR pfnVisitor, void *pvVisitor);
313
314DECLINLINE(bool) VBoxVrCompositorIsEmpty(const VBOXVR_COMPOSITOR *pCompositor)
315{
316 return RTListIsEmpty(&pCompositor->List);
317}
318
319typedef struct VBOXVR_COMPOSITOR_ITERATOR
320{
321 PVBOXVR_COMPOSITOR pCompositor;
322 PRTLISTNODE pNextEntry;
323} VBOXVR_COMPOSITOR_ITERATOR ,*PVBOXVR_COMPOSITOR_ITERATOR;
324
325typedef struct VBOXVR_COMPOSITOR_CONST_ITERATOR
326{
327 const VBOXVR_COMPOSITOR *pCompositor;
328 const RTLISTNODE *pNextEntry;
329} VBOXVR_COMPOSITOR_CONST_ITERATOR ,*PVBOXVR_COMPOSITOR_CONST_ITERATOR;
330
331DECLINLINE(void) VBoxVrCompositorIterInit(PVBOXVR_COMPOSITOR pCompositor, PVBOXVR_COMPOSITOR_ITERATOR pIter)
332{
333 pIter->pCompositor = pCompositor;
334 pIter->pNextEntry = pCompositor->List.pNext;
335}
336
337DECLINLINE(void) VBoxVrCompositorConstIterInit(const VBOXVR_COMPOSITOR *pCompositor, PVBOXVR_COMPOSITOR_CONST_ITERATOR pIter)
338{
339 pIter->pCompositor = pCompositor;
340 pIter->pNextEntry = pCompositor->List.pNext;
341}
342
343#define VBOXVR_COMPOSITOR_ENTRY_FROM_NODE(_p) ((PVBOXVR_COMPOSITOR_ENTRY)(((uint8_t*)(_p)) - RT_OFFSETOF(VBOXVR_COMPOSITOR_ENTRY, Node)))
344#define VBOXVR_COMPOSITOR_CONST_ENTRY_FROM_NODE(_p) ((const VBOXVR_COMPOSITOR_ENTRY*)(((uint8_t*)(_p)) - RT_OFFSETOF(VBOXVR_COMPOSITOR_ENTRY, Node)))
345
346DECLINLINE(PVBOXVR_COMPOSITOR_ENTRY) VBoxVrCompositorIterNext(PVBOXVR_COMPOSITOR_ITERATOR pIter)
347{
348 PRTLISTNODE pNextEntry = pIter->pNextEntry;
349 if (pNextEntry != &pIter->pCompositor->List)
350 {
351 PVBOXVR_COMPOSITOR_ENTRY pEntry = VBOXVR_COMPOSITOR_ENTRY_FROM_NODE(pNextEntry);
352 pIter->pNextEntry = pNextEntry->pNext;
353 return pEntry;
354 }
355 return NULL;
356}
357
358DECLINLINE(const VBOXVR_COMPOSITOR_ENTRY*) VBoxVrCompositorConstIterNext(PVBOXVR_COMPOSITOR_CONST_ITERATOR pIter)
359{
360 const RTLISTNODE *pNextEntry = pIter->pNextEntry;
361 if (pNextEntry != &pIter->pCompositor->List)
362 {
363 const VBOXVR_COMPOSITOR_ENTRY *pEntry = VBOXVR_COMPOSITOR_CONST_ENTRY_FROM_NODE(pNextEntry);
364 pIter->pNextEntry = pNextEntry->pNext;
365 return pEntry;
366 }
367 return NULL;
368}
369
370typedef struct VBOXVR_TEXTURE
371{
372 int32_t width;
373 int32_t height;
374 uint32_t target;
375 uint32_t hwid;
376} VBOXVR_TEXTURE, *PVBOXVR_TEXTURE;
377
378RT_C_DECLS_END
379
380#endif /* #ifndef ___cr_vreg_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