VirtualBox

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

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

crOpenGL: scaling bugfixes; rename stretch -> scale

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