VirtualBox

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

最後變更 在這個檔案從53586是 53586,由 vboxsync 提交於 10 年 前

Some style cleanups (no actual changes).

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

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