VirtualBox

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

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

crOpenGL: presentation infrastructure rework (still work in progress)

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

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