Changeset 44740 in vbox
- Timestamp:
- Feb 18, 2013 5:02:47 PM (12 years ago)
- Location:
- trunk/src/VBox
- Files:
-
- 2 added
- 1 deleted
- 25 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/crOpenGL/pack/packspu_misc.c
r42591 r44740 713 713 } 714 714 #endif /*CHROMIUM_THREADSAFE*/ 715 716 void PACKSPU_APIENTRY packspu_VBoxPresentComposition(GLint win, struct VBOXVR_SCR_COMPOSITOR * pCompositor, struct VBOXVR_SCR_COMPOSITOR_ENTRY *pChangedEntry) 717 { 718 } -
trunk/src/VBox/Additions/common/crOpenGL/pack/packspu_special
r44125 r44740 113 113 VBoxConDestroy 114 114 VBoxConFlush 115 VBoxPresentComposition 115 116 ChromiumParameteriCR 116 117 CompressedTexImage1DARB -
trunk/src/VBox/GuestHost/OpenGL/Makefile.kmk
r44528 r44740 78 78 util/warp.c \ 79 79 util/vreg.cpp \ 80 util/blitter.cpp \ 80 81 util/vboxhgcm.c \ 81 82 $(VBOX_PATH_CROGL_GENFILES)/debug_opcodes.c -
trunk/src/VBox/GuestHost/OpenGL/glapi_parser/APIspec.txt
r44326 r44740 8372 8372 chromium extpack 8373 8373 8374 name TexPresent8374 name VBoxTexPresent 8375 8375 return void 8376 8376 param texture GLuint … … 8582 8582 category VBox 8583 8583 chromium nopack 8584 8585 name VBoxPresentComposition 8586 return void 8587 param win GLint 8588 param pCompositor struct VBOXVR_SCR_COMPOSITOR * 8589 param pChangedEntry struct VBOXVR_SCR_COMPOSITOR_ENTRY * 8590 category VBox 8591 chromium nopack 8592 8584 8593 8585 8594 # OpenGL 1.5 -
trunk/src/VBox/GuestHost/OpenGL/include/chromium.h
r43888 r44740 80 80 /* to shut up gcc warning for struct VBOXUHGSMI * parameters */ 81 81 struct VBOXUHGSMI; 82 struct VBOXVR_SCR_COMPOSITOR; 83 struct VBOXVR_SCR_COMPOSITOR_ENTRY; 82 84 83 85 #if defined(IN_GUEST) && (WINDOWS) && defined(VBOX_WITH_WDDM) … … 768 770 extern void APIENTRY crWindowVisibleRegion( GLint window, GLint cRects, void *pRects ); 769 771 extern void APIENTRY crWindowShow( GLint window, GLint flag ); 770 extern void APIENTRY cr TexPresent(GLuint texture, GLuint cfg, GLint xPos, GLint yPos, GLint cRects, GLint *pRects);772 extern void APIENTRY crVBoxTexPresent(GLuint texture, GLuint cfg, GLint xPos, GLint yPos, GLint cRects, GLint *pRects); 771 773 772 774 typedef int (CR_APIENTRY *CR_PROC)(); -
trunk/src/VBox/GuestHost/OpenGL/include/cr_server.h
r44290 r44740 13 13 #include "cr_protocol.h" 14 14 #include "cr_glstate.h" 15 #include "cr_vreg.h" 15 16 #include "spu_dispatch_table.h" 16 17 … … 123 124 GLuint fboWidth, fboHeight; 124 125 GLuint idPBO; 126 127 VBOXVR_SCR_COMPOSITOR_ENTRY CEntry; 128 VBOXVR_SCR_COMPOSITOR Compositor; 125 129 126 130 /* bitfield representing contexts the mural has been ever current with … … 195 199 196 200 197 /* BLITTER */198 typedef struct CR_BLITTER_BUFFER199 {200 GLuint cbBuffer;201 GLvoid * pvBuffer;202 } CR_BLITTER_BUFFER, *PCR_BLITTER_BUFFER;203 204 typedef struct CR_BLITTER_TEXTURE205 {206 GLint width;207 GLint height;208 GLenum target;209 GLuint hwid;210 } CR_BLITTER_TEXTURE, *PCR_BLITTER_TEXTURE;211 212 typedef union CR_BLITTER_FLAGS213 {214 struct215 {216 uint32_t Initialized : 1;217 uint32_t SupportsFBO : 1;218 uint32_t SupportsFBOBlit : 1;219 uint32_t Reserved : 29;220 };221 uint32_t Value;222 } CR_BLITTER_FLAGS, *PCR_BLITTER_FLAGS;223 224 struct CR_BLITTER;225 226 typedef DECLCALLBACK(int) FNCRBLT_BLITTER(struct CR_BLITTER *pBlitter, CR_BLITTER_TEXTURE *pSrc, const RTRECT *paSrcRect, const PRTRECTSIZE pDstSize, const RTRECT *paDstRect, uint32_t cRects, uint32_t fFlags);227 typedef FNCRBLT_BLITTER *PFNCRBLT_BLITTER;228 229 #define CRBLT_F_LINEAR 0x00000001230 231 typedef struct CR_BLITTER232 {233 GLuint idFBO;234 CR_BLITTER_FLAGS Flags;235 PFNCRBLT_BLITTER pfnBlt;236 CR_BLITTER_BUFFER Verticies;237 CR_BLITTER_BUFFER Indicies;238 RTRECTSIZE CurrentSetSize;239 CRMuralInfo *pCurrentMural;240 CRContextInfo CtxInfo;241 CRContextInfo *pRestoreCtxInfo;242 CRMuralInfo *pRestoreMural;243 } CR_BLITTER, *PCR_BLITTER;244 245 int CrBltInit(PCR_BLITTER pBlitter, CRMuralInfo *pCurrentMural);246 void CrBltTerm(PCR_BLITTER pBlitter);247 248 DECLINLINE(GLboolean) CrBltSupportsTexTex(PCR_BLITTER pBlitter)249 {250 return pBlitter->Flags.SupportsFBO;251 }252 253 DECLINLINE(GLboolean) CrBltIsEntered(PCR_BLITTER pBlitter)254 {255 return !!pBlitter->pRestoreCtxInfo;256 }257 258 void CrBltMuralSetCurrent(PCR_BLITTER pBlitter, CRMuralInfo *pMural);259 260 void CrBltLeave(PCR_BLITTER pBlitter);261 int CrBltEnter(PCR_BLITTER pBlitter, CRContextInfo *pRestoreCtxInfo, CRMuralInfo *pRestoreMural);262 void CrBltBlitTexMural(PCR_BLITTER pBlitter, CR_BLITTER_TEXTURE *pSrc, const RTRECT *paSrcRects, const RTRECT *paDstRects, uint32_t cRects, uint32_t fFlags);263 void CrBltBlitTexTex(PCR_BLITTER pBlitter, CR_BLITTER_TEXTURE *pSrc, const RTRECT *pSrcRect, CR_BLITTER_TEXTURE *pDst, const RTRECT *pDstRect, uint32_t cRects, uint32_t fFlags);264 void CrBltPresent(PCR_BLITTER pBlitter);265 /* */266 267 /* PRESENTER */268 struct CR_PRESENTER;269 struct CR_PRESENTER_ENTRY;270 271 typedef DECLCALLBACK(int) FNCRDISPLAY_REGIONS_CHANGED(struct CR_PRESENTER *pPresenter);272 typedef FNCRDISPLAY_REGIONS_CHANGED *PFNCRDISPLAY_REGIONS_CHANGED;273 274 typedef DECLCALLBACK(int) FNCRDISPLAY_DRAW_ENTRY(struct CR_PRESENTER *pPresenter, struct CR_PRESENTER_ENTRY *pEntry, PCR_BLITTER pBlitter, bool *pfAllEntriesDrawn);275 typedef FNCRDISPLAY_DRAW_ENTRY *PFNCRDISPLAY_DRAW_ENTRY;276 277 typedef DECLCALLBACK(int) FNCRDISPLAY_DRAW_TEXTURE(struct CR_PRESENTER *pPresenter, PCR_BLITTER pBlitter,278 CR_BLITTER_TEXTURE *pTexture, const RTRECT *paSrcRects, const RTRECT *paDstRects, uint32_t cRects);279 typedef FNCRDISPLAY_DRAW_TEXTURE *PFNCRDISPLAY_DRAW_TEXTURE;280 281 typedef struct CR_PRESENTER_ENTRY282 {283 VBOXVR_COMPOSITOR_ENTRY Ce;284 CR_BLITTER_TEXTURE Texture;285 RTPOINT Pos;286 uint32_t cRects;287 PRTRECT paSrcRects;288 PRTRECT paDstRects;289 } CR_PRESENTER_ENTRY, *PCR_PRESENTER_ENTRY;290 291 typedef struct CR_PRESENTER292 {293 VBOXVR_COMPOSITOR Compositor;294 float StretchX;295 float StretchY;296 PFNCRDISPLAY_REGIONS_CHANGED pfnRegionsChanged;297 PFNCRDISPLAY_DRAW_ENTRY pfnDrawEntry;298 PFNCRDISPLAY_DRAW_TEXTURE pfnDrawTexture;299 uint32_t cRects;300 uint32_t cRectsBuffer;301 PRTRECT paSrcRects;302 PRTRECT paDstRects;303 } CR_PRESENTER, *PCR_PRESENTER;304 305 306 DECLCALLBACK(int) CrPtCbDrawEntrySingle(struct CR_PRESENTER *pPresenter, struct CR_PRESENTER_ENTRY *pEntry, PCR_BLITTER pBlitter, bool *pfAllEntriesDrawn);307 DECLCALLBACK(int) CrPtCbDrawEntryAll(struct CR_PRESENTER *pPresenter, struct CR_PRESENTER_ENTRY *pEntry, PCR_BLITTER pBlitter, bool *pfAllEntriesDrawn);308 309 DECLINLINE(void) CrPtEntryInit(PCR_PRESENTER_ENTRY pEntry, PCR_BLITTER_TEXTURE pTextureData)310 {311 VBoxVrCompositorEntryInit(&pEntry->Ce);312 pEntry->Texture = *pTextureData;313 memset(&pEntry->Pos, 0, sizeof (CR_PRESENTER_ENTRY) - RT_OFFSETOF(CR_PRESENTER_ENTRY, Pos));314 }315 DECLINLINE(bool) CrPtEntryIsUsed(const PCR_PRESENTER_ENTRY pEntry)316 {317 return VBoxVrCompositorEntryIsInList(&pEntry->Ce);318 }319 int CrPtPresent(PCR_PRESENTER pPresenter, PCR_BLITTER pBlitter);320 int CrPtPresentEntry(PCR_PRESENTER pPresenter, PCR_PRESENTER_ENTRY pEntry, PCR_BLITTER pBlitter);321 int CrPtEntryRegionsAdd(PCR_PRESENTER pPresenter, PCR_PRESENTER_ENTRY pEntry, const RTPOINT *pPos, uint32_t cRegions, const RTRECT *paRegions);322 int CrPtEntryRegionsSet(PCR_PRESENTER pPresenter, PCR_PRESENTER_ENTRY pEntry, const RTPOINT *pPos, uint32_t cRegions, const RTRECT *paRegions);323 int CrPtEntryRemove(PCR_PRESENTER pPresenter, PCR_PRESENTER_ENTRY pEntry);324 int CrPtInit(PCR_PRESENTER pPresenter, PFNCRDISPLAY_REGIONS_CHANGED pfnRegionsChanged, PFNCRDISPLAY_DRAW_ENTRY pfnDrawEntry, PFNCRDISPLAY_DRAW_TEXTURE pfnDrawTexture);325 void CrPtTerm(PCR_PRESENTER pPresenter);326 void CrPtSetStretching(PCR_PRESENTER pPresenter, float StretchX, float StretchY);327 /* regions are valid until the next CrPt call */328 int CrPtGetRegions(PCR_PRESENTER pPresenter, uint32_t *pcRegions, const RTRECT **ppaRegions);329 /* */330 331 201 /* DISPLAY */ 332 202 333 203 typedef struct CR_DISPLAY_ENTRY 334 204 { 335 CR_PRESENTER_ENTRY Pe;205 VBOXVR_SCR_COMPOSITOR_ENTRY CEntry; 336 206 } CR_DISPLAY_ENTRY, *PCR_DISPLAY_ENTRY; 337 207 338 208 typedef struct CR_DISPLAY 339 209 { 340 CR_PRESENTER Presenter;210 VBOXVR_SCR_COMPOSITOR Compositor; 341 211 CRMuralInfo Mural; 342 PCR_BLITTER pBlitter;343 212 } CR_DISPLAY, *PCR_DISPLAY; 344 213 345 214 int CrDpInit(PCR_DISPLAY pDisplay); 346 215 void CrDpTerm(PCR_DISPLAY pDisplay); 347 DECLINLINE(void) CrDpBlitterSet(PCR_DISPLAY pDisplay, PCR_BLITTER pBlitter)348 {349 pDisplay->pBlitter = pBlitter;350 }351 int CrDpBlitterTestWithMural(PCR_BLITTER pBlitter, CRMuralInfo *pMural);352 int CrDpBlitterTest(PCR_DISPLAY pDisplay, PCR_BLITTER pBlitter);353 216 void CrDpResize(PCR_DISPLAY pDisplay, uint32_t width, uint32_t height, 354 217 uint32_t stretchedWidth, uint32_t stretchedHeight); 355 void CrDpEntryInit(PCR_DISPLAY_ENTRY pEntry, PCR_BLITTER_TEXTURE pTextureData);218 void CrDpEntryInit(PCR_DISPLAY_ENTRY pEntry, const PVBOXVR_TEXTURE pTextureData); 356 219 void CrDpEntryCleanup(PCR_DISPLAY pDisplay, PCR_DISPLAY_ENTRY pEntry); 357 220 int CrDpEntryRegionsSet(PCR_DISPLAY pDisplay, PCR_DISPLAY_ENTRY pEntry, const RTPOINT *pPos, uint32_t cRegions, const RTRECT *paRegions); … … 360 223 DECLINLINE(bool) CrDpEntryIsUsed(PCR_DISPLAY_ENTRY pEntry) 361 224 { 362 return Cr PtEntryIsUsed(&pEntry->Pe);225 return CrVrScrCompositorEntryIsInList(&pEntry->CEntry); 363 226 } 364 227 … … 383 246 384 247 void CrHlpFreeTexImage(CRContext *pCurCtx, GLuint idPBO, void *pvData); 385 void* CrHlpGetTexImage(CRContext *pCurCtx, P CR_BLITTER_TEXTURE pTexture, GLuint idPBO);248 void* CrHlpGetTexImage(CRContext *pCurCtx, PVBOXVR_TEXTURE pTexture, GLuint idPBO); 386 249 387 250 /* */ … … 503 366 /* @todo: should we use just one blitter? 504 367 * we use two currently because the drawable attribs can differ*/ 505 int8_t fPresentBlitterInited;506 int8_t fFBOModeBlitterInited;507 368 CR_DISPLAY_ENTRY_MAP PresentTexturepMap; 508 CR_BLITTER PresentBlitter;509 CR_BLITTER FBOModeBlitter;510 369 uint32_t DisplaysInitMap[(CR_MAX_GUEST_MONITORS + 31)/32]; 511 370 CR_DISPLAY aDispplays[CR_MAX_GUEST_MONITORS]; -
trunk/src/VBox/GuestHost/OpenGL/include/cr_vreg.h
r43888 r44740 116 116 VBOXVREGDECL(void) VBoxVrTerm(); 117 117 118 typedef struct VBOXVR_LIST_ITERATOR 119 { 120 PVBOXVR_LIST pList; 121 PRTLISTNODE pNextEntry; 122 } VBOXVR_LIST_ITERATOR, *PVBOXVR_LIST_ITERATOR; 123 124 DECLINLINE(void) VBoxVrListIterInit(PVBOXVR_LIST pList, PVBOXVR_LIST_ITERATOR pIter) 125 { 126 pIter->pList = pList; 127 pIter->pNextEntry = pList->ListHead.pNext; 128 } 129 130 typedef struct VBOXVR_REG 131 { 132 RTLISTNODE ListEntry; 133 RTRECT Rect; 134 } VBOXVR_REG, *PVBOXVR_REG; 135 136 #define PVBOXVR_REG_FROM_ENTRY(_pEntry) ((PVBOXVR_REG)(((uint8_t*)(_pEntry)) - RT_OFFSETOF(VBOXVR_REG, ListEntry))) 137 138 DECLINLINE(const PRTRECT) VBoxVrListIterNext(PVBOXVR_LIST_ITERATOR pIter) 139 { 140 PRTLISTNODE pNextEntry = pIter->pNextEntry; 141 if (pNextEntry != &pIter->pList->ListHead) 142 { 143 const PRTRECT pRect = &(PVBOXVR_REG_FROM_ENTRY(pNextEntry)->Rect); 144 pIter->pNextEntry = pNextEntry->pNext; 145 return pRect; 146 } 147 return NULL; 148 } 149 118 150 typedef struct VBOXVR_COMPOSITOR_ENTRY 119 151 { … … 146 178 #define VBOXVR_COMPOSITOR_CF_ENTRIES_REGIONS_CHANGED 0x00000001 147 179 #define VBOXVR_COMPOSITOR_CF_COMPOSITED_REGIONS_CHANGED 0x00000002 180 #define VBOXVR_COMPOSITOR_CF_ENTRY_ADDED 0x00000004 181 148 182 149 183 VBOXVREGDECL(bool) VBoxVrCompositorEntryRemove(PVBOXVR_COMPOSITOR pCompositor, PVBOXVR_COMPOSITOR_ENTRY pEntry); … … 154 188 VBOXVREGDECL(void) VBoxVrCompositorVisit(PVBOXVR_COMPOSITOR pCompositor, PFNVBOXVRCOMPOSITOR_VISITOR pfnVisitor, void *pvVisitor); 155 189 190 typedef struct VBOXVR_COMPOSITOR_ITERATOR 191 { 192 PVBOXVR_COMPOSITOR pCompositor; 193 PRTLISTNODE pNextEntry; 194 } VBOXVR_COMPOSITOR_ITERATOR ,*PVBOXVR_COMPOSITOR_ITERATOR; 195 196 DECLINLINE(void) VBoxVrCompositorIterInit(PVBOXVR_COMPOSITOR pCompositor, PVBOXVR_COMPOSITOR_ITERATOR pIter) 197 { 198 pIter->pCompositor = pCompositor; 199 pIter->pNextEntry = pCompositor->List.pNext; 200 } 201 202 #define VBOXVR_COMPOSITOR_ENTRY_FROM_NODE(_p) ((PVBOXVR_COMPOSITOR_ENTRY)(((uint8_t*)(_p)) - RT_OFFSETOF(VBOXVR_COMPOSITOR_ENTRY, Node))) 203 204 DECLINLINE(PVBOXVR_COMPOSITOR_ENTRY) VBoxVrCompositorIterNext(PVBOXVR_COMPOSITOR_ITERATOR pIter) 205 { 206 PRTLISTNODE pNextEntry = pIter->pNextEntry; 207 if (pNextEntry != &pIter->pCompositor->List) 208 { 209 PVBOXVR_COMPOSITOR_ENTRY pEntry = VBOXVR_COMPOSITOR_ENTRY_FROM_NODE(pNextEntry); 210 pIter->pNextEntry = pNextEntry->pNext; 211 return pEntry; 212 } 213 return NULL; 214 } 215 216 /* Compositor with Stretching & Cached Rectangles info */ 217 218 typedef struct VBOXVR_TEXTURE 219 { 220 int32_t width; 221 int32_t height; 222 uint32_t target; 223 uint32_t hwid; 224 } VBOXVR_TEXTURE, *PVBOXVR_TEXTURE; 225 226 typedef struct VBOXVR_SCR_COMPOSITOR_ENTRY 227 { 228 VBOXVR_COMPOSITOR_ENTRY Ce; 229 VBOXVR_TEXTURE Tex; 230 RTPOINT Pos; 231 uint32_t fChanged; 232 uint32_t cRects; 233 PRTRECT paSrcRects; 234 PRTRECT paDstRects; 235 } VBOXVR_SCR_COMPOSITOR_ENTRY, *PVBOXVR_SCR_COMPOSITOR_ENTRY; 236 237 typedef struct VBOXVR_SCR_COMPOSITOR 238 { 239 VBOXVR_COMPOSITOR Compositor; 240 float StretchX; 241 float StretchY; 242 uint32_t cRects; 243 uint32_t cRectsBuffer; 244 PRTRECT paSrcRects; 245 PRTRECT paDstRects; 246 } VBOXVR_SCR_COMPOSITOR, *PVBOXVR_SCR_COMPOSITOR; 247 248 typedef DECLCALLBACK(bool) FNVBOXVRSCRCOMPOSITOR_VISITOR(PVBOXVR_SCR_COMPOSITOR pCompositor, PVBOXVR_SCR_COMPOSITOR_ENTRY pEntry, void *pvVisitor); 249 typedef FNVBOXVRSCRCOMPOSITOR_VISITOR *PFNVBOXVRSCRCOMPOSITOR_VISITOR; 250 251 252 DECLINLINE(void) CrVrScrCompositorEntryInit(PVBOXVR_SCR_COMPOSITOR_ENTRY pEntry, const PVBOXVR_TEXTURE pTex) 253 { 254 VBoxVrCompositorEntryInit(&pEntry->Ce); 255 pEntry->Tex = *pTex; 256 memset(&pEntry->Pos, 0, sizeof (VBOXVR_SCR_COMPOSITOR_ENTRY) - RT_OFFSETOF(VBOXVR_SCR_COMPOSITOR_ENTRY, Pos)); 257 } 258 259 DECLINLINE(bool) CrVrScrCompositorEntryIsUsed(const PVBOXVR_SCR_COMPOSITOR_ENTRY pEntry) 260 { 261 return VBoxVrCompositorEntryIsInList(&pEntry->Ce); 262 } 263 264 DECLINLINE(void) CrVrScrCompositorEntrySetChanged(PVBOXVR_SCR_COMPOSITOR_ENTRY pEntry, bool fChanged) 265 { 266 pEntry->fChanged = !!fChanged; 267 } 268 269 DECLINLINE(void) CrVrScrCompositorEntryTexNameUpdate(PVBOXVR_SCR_COMPOSITOR_ENTRY pEntry, uint32_t hwid) 270 { 271 pEntry->Tex.hwid = hwid; 272 CrVrScrCompositorEntrySetChanged(pEntry, true); 273 } 274 275 DECLINLINE(bool) CrVrScrCompositorEntryIsChanged(const PVBOXVR_SCR_COMPOSITOR_ENTRY pEntry) 276 { 277 return !!pEntry->fChanged; 278 } 279 280 VBOXVREGDECL(void) CrVrScrCompositorVisit(PVBOXVR_SCR_COMPOSITOR pCompositor, PFNVBOXVRSCRCOMPOSITOR_VISITOR pfnVisitor, void *pvVisitor); 281 VBOXVREGDECL(void) CrVrScrCompositorEntrySetAllChanged(PVBOXVR_SCR_COMPOSITOR pCompositor, bool fChanged); 282 DECLINLINE(bool) CrVrScrCompositorEntryIsInList(const PVBOXVR_SCR_COMPOSITOR_ENTRY pEntry) 283 { 284 return VBoxVrCompositorEntryIsInList(&pEntry->Ce); 285 } 286 VBOXVREGDECL(int) CrVrScrCompositorEntryRegionsAdd(PVBOXVR_SCR_COMPOSITOR pCompositor, PVBOXVR_SCR_COMPOSITOR_ENTRY pEntry, const RTPOINT *pPos, uint32_t cRegions, const RTRECT *paRegions); 287 VBOXVREGDECL(int) CrVrScrCompositorEntryRegionsSet(PVBOXVR_SCR_COMPOSITOR pCompositor, PVBOXVR_SCR_COMPOSITOR_ENTRY pEntry, const RTPOINT *pPos, uint32_t cRegions, const RTRECT *paRegions); 288 VBOXVREGDECL(int) CrVrScrCompositorEntryPosSet(PVBOXVR_SCR_COMPOSITOR pCompositor, PVBOXVR_SCR_COMPOSITOR_ENTRY pEntry, const RTPOINT *pPos); 289 290 /* regions are valid until the next CrVrScrCompositor call */ 291 VBOXVREGDECL(int) CrVrScrCompositorEntryRegionsGet(PVBOXVR_SCR_COMPOSITOR pCompositor, PVBOXVR_SCR_COMPOSITOR_ENTRY pEntry, uint32_t *pcRegions, const RTRECT **ppaSrcRegions, const RTRECT **ppaDstRegions); 292 VBOXVREGDECL(int) CrVrScrCompositorEntryRemove(PVBOXVR_SCR_COMPOSITOR pCompositor, PVBOXVR_SCR_COMPOSITOR_ENTRY pEntry); 293 VBOXVREGDECL(int) CrVrScrCompositorInit(PVBOXVR_SCR_COMPOSITOR pCompositor); 294 VBOXVREGDECL(void) CrVrScrCompositorTerm(PVBOXVR_SCR_COMPOSITOR pCompositor); 295 VBOXVREGDECL(void) CrVrScrCompositorSetStretching(PVBOXVR_SCR_COMPOSITOR pCompositor, float StretchX, float StretchY); 296 /* regions are valid until the next CrVrScrCompositor call */ 297 VBOXVREGDECL(int) CrVrScrCompositorRegionsGet(PVBOXVR_SCR_COMPOSITOR pCompositor, uint32_t *pcRegions, const RTRECT **ppaSrcRegions, const RTRECT **ppaDstRegions); 298 299 #define VBOXVR_SCR_COMPOSITOR_ENTRY_FROM_ENTRY(_p) ((PVBOXVR_SCR_COMPOSITOR_ENTRY)(((uint8_t*)(_p)) - RT_OFFSETOF(VBOXVR_SCR_COMPOSITOR_ENTRY, Ce))) 300 #define VBOXVR_SCR_COMPOSITOR_FROM_COMPOSITOR(_p) ((PVBOXVR_SCR_COMPOSITOR)(((uint8_t*)(_p)) - RT_OFFSETOF(VBOXVR_SCR_COMPOSITOR, Compositor))) 301 302 typedef struct VBOXVR_SCR_COMPOSITOR_ITERATOR 303 { 304 VBOXVR_COMPOSITOR_ITERATOR Base; 305 } VBOXVR_SCR_COMPOSITOR_ITERATOR ,*PVBOXVR_SCR_COMPOSITOR_ITERATOR; 306 307 DECLINLINE(void) CrVrScrCompositorIterInit(PVBOXVR_SCR_COMPOSITOR pCompositor, PVBOXVR_SCR_COMPOSITOR_ITERATOR pIter) 308 { 309 VBoxVrCompositorIterInit(&pCompositor->Compositor, &pIter->Base); 310 } 311 312 DECLINLINE(PVBOXVR_SCR_COMPOSITOR_ENTRY) CrVrScrCompositorIterNext(PVBOXVR_SCR_COMPOSITOR_ITERATOR pIter) 313 { 314 PVBOXVR_COMPOSITOR_ENTRY pCe = VBoxVrCompositorIterNext(&pIter->Base); 315 if (pCe) 316 { 317 return VBOXVR_SCR_COMPOSITOR_ENTRY_FROM_ENTRY(pCe); 318 } 319 return NULL; 320 } 321 156 322 RT_C_DECLS_END 157 323 -
trunk/src/VBox/GuestHost/OpenGL/util/vreg.cpp
r44596 r44740 20 20 #include <iprt/err.h> 21 21 #include <iprt/assert.h> 22 #include <iprt/asm.h> 22 23 23 24 #ifndef IN_RING0 … … 28 29 #endif 29 30 30 typedef struct VBOXVR_REG31 {32 RTLISTNODE ListEntry;33 RTRECT Rect;34 } VBOXVR_REG, *PVBOXVR_REG;35 36 #define PVBOXVR_REG_FROM_ENTRY(_pEntry) ((PVBOXVR_REG)(((uint8_t*)(_pEntry)) - RT_OFFSETOF(VBOXVR_REG, ListEntry)))37 38 31 #ifdef DEBUG_misha 39 32 //# define VBOXVDBG_VR_LAL_DISABLE … … 41 34 42 35 #ifndef VBOXVDBG_VR_LAL_DISABLE 36 static volatile int32_t g_cVBoxVrInits = 0; 43 37 static RTMEMCACHE g_VBoxVrLookasideList; 44 38 #endif … … 82 76 VBOXVREGDECL(int) VBoxVrInit() 83 77 { 78 int32_t cNewRefs = ASMAtomicIncS32(&g_cVBoxVrInits); 79 Assert(cNewRefs >= 1); 80 Assert(cNewRefs == 1); /* <- debugging */ 81 if (cNewRefs > 1) 82 return VINF_SUCCESS; 83 84 84 #ifndef VBOXVDBG_VR_LAL_DISABLE 85 85 int rc = RTMemCacheCreate(&g_VBoxVrLookasideList, sizeof (VBOXVR_REG), … … 103 103 VBOXVREGDECL(void) VBoxVrTerm() 104 104 { 105 int32_t cNewRefs = ASMAtomicDecS32(&g_cVBoxVrInits); 106 Assert(cNewRefs >= 0); 107 if (cNewRefs > 0) 108 return; 109 105 110 #ifndef VBOXVDBG_VR_LAL_DISABLE 106 111 RTMemCacheDestroy(g_VBoxVrLookasideList); … … 798 803 { 799 804 PVBOXVR_COMPOSITOR_ENTRY pEntry, pEntryNext; 800 RTListForEachSafe(&pCompositor->List, pEntry, pEntryNext, VBOXVR_COMPOSITOR_ENTRY, Node) ;805 RTListForEachSafe(&pCompositor->List, pEntry, pEntryNext, VBOXVR_COMPOSITOR_ENTRY, Node) 801 806 { 802 807 VBoxVrCompositorEntryRemove(pCompositor, pEntry); … … 935 940 else if (fEntryChanged) 936 941 fFlags = VBOXVR_COMPOSITOR_CF_ENTRIES_REGIONS_CHANGED | VBOXVR_COMPOSITOR_CF_COMPOSITED_REGIONS_CHANGED; 942 if (!fEntryInList) 943 fFlags |= VBOXVR_COMPOSITOR_CF_ENTRY_ADDED; 937 944 938 945 *pfChangeFlags = fFlags; … … 1073 1080 { 1074 1081 PVBOXVR_COMPOSITOR_ENTRY pEntry, pEntryNext; 1075 RTListForEachSafe(&pCompositor->List, pEntry, pEntryNext, VBOXVR_COMPOSITOR_ENTRY, Node) ;1082 RTListForEachSafe(&pCompositor->List, pEntry, pEntryNext, VBOXVR_COMPOSITOR_ENTRY, Node) 1076 1083 { 1077 1084 if (!pfnVisitor(pCompositor, pEntry, pvVisitor)) … … 1079 1086 } 1080 1087 } 1088 1089 1090 1091 #define VBOXVR_SCR_COMPOSITOR_RECTS_UNDEFINED UINT32_MAX 1092 1093 static int crVrScrCompositorRectsAssignBuffer(PVBOXVR_SCR_COMPOSITOR pCompositor, uint32_t cRects) 1094 { 1095 Assert(cRects); 1096 1097 if (pCompositor->cRectsBuffer >= cRects) 1098 { 1099 pCompositor->cRects = cRects; 1100 return VINF_SUCCESS; 1101 } 1102 1103 if (pCompositor->cRectsBuffer) 1104 { 1105 Assert(pCompositor->paSrcRects); 1106 RTMemFree(pCompositor->paSrcRects); 1107 Assert(pCompositor->paDstRects); 1108 RTMemFree(pCompositor->paDstRects); 1109 } 1110 1111 pCompositor->paSrcRects = (PRTRECT)RTMemAlloc(sizeof (*pCompositor->paSrcRects) * cRects); 1112 if (pCompositor->paSrcRects) 1113 { 1114 pCompositor->paDstRects = (PRTRECT)RTMemAlloc(sizeof (*pCompositor->paDstRects) * cRects); 1115 if (pCompositor->paDstRects) 1116 { 1117 pCompositor->cRects = cRects; 1118 pCompositor->cRectsBuffer = cRects; 1119 return VINF_SUCCESS; 1120 } 1121 else 1122 { 1123 crWarning("RTMemAlloc failed!"); 1124 RTMemFree(pCompositor->paSrcRects); 1125 pCompositor->paSrcRects = NULL; 1126 } 1127 } 1128 else 1129 { 1130 crWarning("RTMemAlloc failed!"); 1131 pCompositor->paDstRects = NULL; 1132 } 1133 1134 pCompositor->cRects = VBOXVR_SCR_COMPOSITOR_RECTS_UNDEFINED; 1135 pCompositor->cRectsBuffer = 0; 1136 1137 return VERR_NO_MEMORY; 1138 } 1139 1140 static void crVrScrCompositorRectsInvalidate(PVBOXVR_SCR_COMPOSITOR pCompositor) 1141 { 1142 pCompositor->cRects = VBOXVR_SCR_COMPOSITOR_RECTS_UNDEFINED; 1143 } 1144 1145 static DECLCALLBACK(bool) crVrScrCompositorRectsCounterCb(PVBOXVR_COMPOSITOR pCompositor, PVBOXVR_COMPOSITOR_ENTRY pEntry, void *pvVisitor) 1146 { 1147 uint32_t* pCounter = (uint32_t*)pvVisitor; 1148 Assert(VBoxVrListRectsCount(&pEntry->Vr)); 1149 *pCounter += VBoxVrListRectsCount(&pEntry->Vr); 1150 return true; 1151 } 1152 1153 typedef struct VBOXVR_SCR_COMPOSITOR_RECTS_ASSIGNER 1154 { 1155 PRTRECT paSrcRects; 1156 PRTRECT paDstRects; 1157 uint32_t cRects; 1158 } VBOXVR_SCR_COMPOSITOR_RECTS_ASSIGNER, *PVBOXVR_SCR_COMPOSITOR_RECTS_ASSIGNER; 1159 1160 static DECLCALLBACK(bool) crVrScrCompositorRectsAssignerCb(PVBOXVR_COMPOSITOR pCCompositor, PVBOXVR_COMPOSITOR_ENTRY pCEntry, void *pvVisitor) 1161 { 1162 PVBOXVR_SCR_COMPOSITOR_RECTS_ASSIGNER pData = (PVBOXVR_SCR_COMPOSITOR_RECTS_ASSIGNER)pvVisitor; 1163 PVBOXVR_SCR_COMPOSITOR pCompositor = VBOXVR_SCR_COMPOSITOR_FROM_COMPOSITOR(pCCompositor); 1164 PVBOXVR_SCR_COMPOSITOR_ENTRY pEntry = VBOXVR_SCR_COMPOSITOR_ENTRY_FROM_ENTRY(pCEntry); 1165 pEntry->paSrcRects = pData->paSrcRects; 1166 pEntry->paDstRects = pData->paDstRects; 1167 uint32_t cRects = VBoxVrListRectsCount(&pCEntry->Vr); 1168 Assert(cRects); 1169 Assert(cRects >= pData->cRects); 1170 int rc = VBoxVrListRectsGet(&pCEntry->Vr, cRects, pEntry->paDstRects); 1171 AssertRC(rc); 1172 if (pCompositor->StretchX >= 1. && pCompositor->StretchY >= 1. /* <- stretching can not zero some rects */ 1173 && !pEntry->Pos.x && !pEntry->Pos.y) 1174 { 1175 memcpy(pEntry->paSrcRects, pEntry->paDstRects, cRects * sizeof (*pEntry->paSrcRects)); 1176 } 1177 else 1178 { 1179 for (uint32_t i = 0; i < cRects; ++i) 1180 { 1181 pEntry->paSrcRects[i].xLeft = (int32_t)((pEntry->paDstRects[i].xLeft - pEntry->Pos.x) * pCompositor->StretchX); 1182 pEntry->paSrcRects[i].yTop = (int32_t)((pEntry->paDstRects[i].yTop - pEntry->Pos.y) * pCompositor->StretchY); 1183 pEntry->paSrcRects[i].xRight = (int32_t)((pEntry->paDstRects[i].xRight - pEntry->Pos.x) * pCompositor->StretchX); 1184 pEntry->paSrcRects[i].yBottom = (int32_t)((pEntry->paDstRects[i].yBottom - pEntry->Pos.y) * pCompositor->StretchY); 1185 } 1186 1187 bool canZeroX = (pCompositor->StretchX < 1); 1188 bool canZeroY = (pCompositor->StretchY < 1); 1189 if (canZeroX && canZeroY) 1190 { 1191 /* filter out zero rectangles*/ 1192 uint32_t iOrig, iNew; 1193 for (iOrig = 0, iNew = 0; iOrig < cRects; ++iOrig) 1194 { 1195 PRTRECT pOrigRect = &pEntry->paSrcRects[iOrig]; 1196 if (pOrigRect->xLeft == pOrigRect->xRight 1197 || pOrigRect->yTop == pOrigRect->yBottom) 1198 continue; 1199 1200 if (iNew != iOrig) 1201 { 1202 PRTRECT pNewRect = &pEntry->paSrcRects[iNew]; 1203 *pNewRect = *pOrigRect; 1204 } 1205 1206 ++iNew; 1207 } 1208 1209 Assert(iNew <= iOrig); 1210 1211 uint32_t cDiff = iOrig - iNew; 1212 1213 if (cDiff) 1214 { 1215 pCompositor->cRects -= cDiff; 1216 cRects -= cDiff; 1217 } 1218 } 1219 } 1220 1221 pEntry->cRects = cRects; 1222 pData->paDstRects += cRects; 1223 pData->paSrcRects += cRects; 1224 pData->cRects -= cRects; 1225 return true; 1226 } 1227 1228 static int crVrScrCompositorRectsCheckInit(PVBOXVR_SCR_COMPOSITOR pCompositor) 1229 { 1230 if (pCompositor->cRects != VBOXVR_SCR_COMPOSITOR_RECTS_UNDEFINED) 1231 return VINF_SUCCESS; 1232 1233 uint32_t cRects = 0; 1234 VBoxVrCompositorVisit(&pCompositor->Compositor, crVrScrCompositorRectsCounterCb, &cRects); 1235 1236 if (!cRects) 1237 { 1238 pCompositor->cRects = 0; 1239 return VINF_SUCCESS; 1240 } 1241 1242 int rc = crVrScrCompositorRectsAssignBuffer(pCompositor, cRects); 1243 if (!RT_SUCCESS(rc)) 1244 return rc; 1245 1246 VBOXVR_SCR_COMPOSITOR_RECTS_ASSIGNER AssignerData; 1247 AssignerData.paSrcRects = pCompositor->paSrcRects; 1248 AssignerData.paDstRects = pCompositor->paDstRects; 1249 AssignerData.cRects = pCompositor->cRects; 1250 VBoxVrCompositorVisit(&pCompositor->Compositor, crVrScrCompositorRectsAssignerCb, &AssignerData); 1251 Assert(!AssignerData.cRects); 1252 return VINF_SUCCESS; 1253 } 1254 1255 1256 static int crVrScrCompositorEntryRegionsAdd(PVBOXVR_SCR_COMPOSITOR pCompositor, PVBOXVR_SCR_COMPOSITOR_ENTRY pEntry, uint32_t cRegions, const RTRECT *paRegions, bool *pfChanged) 1257 { 1258 uint32_t fChangedFlags = 0; 1259 int rc = VBoxVrCompositorEntryRegionsAdd(&pCompositor->Compositor, &pEntry->Ce, cRegions, paRegions, &fChangedFlags); 1260 if (!RT_SUCCESS(rc)) 1261 { 1262 crWarning("VBoxVrCompositorEntryRegionsAdd failed, rc %d", rc); 1263 return rc; 1264 } 1265 1266 if (fChangedFlags & VBOXVR_COMPOSITOR_CF_COMPOSITED_REGIONS_CHANGED) 1267 { 1268 crVrScrCompositorRectsInvalidate(pCompositor); 1269 } 1270 1271 CrVrScrCompositorEntrySetChanged(pEntry, true); 1272 1273 if (pfChanged) 1274 *pfChanged = !!fChangedFlags; 1275 return VINF_SUCCESS; 1276 } 1277 1278 static int crVrScrCompositorEntryRegionsSet(PVBOXVR_SCR_COMPOSITOR pCompositor, PVBOXVR_SCR_COMPOSITOR_ENTRY pEntry, uint32_t cRegions, const RTRECT *paRegions, bool *pfChanged) 1279 { 1280 bool fChanged; 1281 int rc = VBoxVrCompositorEntryRegionsSet(&pCompositor->Compositor, &pEntry->Ce, cRegions, paRegions, &fChanged); 1282 if (!RT_SUCCESS(rc)) 1283 { 1284 crWarning("VBoxVrCompositorEntryRegionsSet failed, rc %d", rc); 1285 return rc; 1286 } 1287 1288 if (fChanged) 1289 { 1290 crVrScrCompositorRectsInvalidate(pCompositor); 1291 } 1292 1293 CrVrScrCompositorEntrySetChanged(pEntry, true); 1294 1295 if (pfChanged) 1296 *pfChanged = fChanged; 1297 return VINF_SUCCESS; 1298 } 1299 1300 static int crVrScrCompositorEntryPositionSet(PVBOXVR_SCR_COMPOSITOR pCompositor, PVBOXVR_SCR_COMPOSITOR_ENTRY pEntry, const RTPOINT *pPos, bool *pfChanged) 1301 { 1302 if (pEntry && (pEntry->Pos.x != pPos->x || pEntry->Pos.y != pPos->y)) 1303 { 1304 int rc = VBoxVrCompositorEntryRegionsTranslate(&pCompositor->Compositor, &pEntry->Ce, pPos->x - pEntry->Pos.x, pPos->y - pEntry->Pos.y, pfChanged); 1305 if (!RT_SUCCESS(rc)) 1306 { 1307 crWarning("VBoxVrCompositorEntryRegionsTranslate failed rc %d", rc); 1308 return rc; 1309 } 1310 1311 if (VBoxVrCompositorEntryIsInList(&pEntry->Ce)) 1312 { 1313 crVrScrCompositorRectsInvalidate(pCompositor); 1314 } 1315 1316 pEntry->Pos = *pPos; 1317 CrVrScrCompositorEntrySetChanged(pEntry, true); 1318 } 1319 return VINF_SUCCESS; 1320 } 1321 1322 VBOXVREGDECL(int) CrVrScrCompositorEntryRegionsAdd(PVBOXVR_SCR_COMPOSITOR pCompositor, PVBOXVR_SCR_COMPOSITOR_ENTRY pEntry, const RTPOINT *pPos, uint32_t cRegions, const RTRECT *paRegions) 1323 { 1324 int rc; 1325 if (pPos) 1326 { 1327 rc = crVrScrCompositorEntryPositionSet(pCompositor, pEntry, pPos, NULL); 1328 if (!RT_SUCCESS(rc)) 1329 { 1330 crWarning("RegionsAdd: crVrScrCompositorEntryPositionSet failed rc %d", rc); 1331 return rc; 1332 } 1333 } 1334 1335 rc = crVrScrCompositorEntryRegionsAdd(pCompositor, pEntry, cRegions, paRegions, NULL); 1336 if (!RT_SUCCESS(rc)) 1337 { 1338 crWarning("crVrScrCompositorEntryRegionsAdd failed, rc %d", rc); 1339 return rc; 1340 } 1341 1342 return VINF_SUCCESS; 1343 } 1344 1345 VBOXVREGDECL(int) CrVrScrCompositorEntryRegionsSet(PVBOXVR_SCR_COMPOSITOR pCompositor, PVBOXVR_SCR_COMPOSITOR_ENTRY pEntry, const RTPOINT *pPos, uint32_t cRegions, const RTRECT *paRegions) 1346 { 1347 int rc = CrVrScrCompositorEntryRemove(pCompositor, pEntry); 1348 if (!RT_SUCCESS(rc)) 1349 { 1350 crWarning("RegionsSet: CrVrScrCompositorEntryRemove failed rc %d", rc); 1351 return rc; 1352 } 1353 1354 if (pPos) 1355 { 1356 rc = crVrScrCompositorEntryPositionSet(pCompositor, pEntry, pPos, NULL); 1357 if (!RT_SUCCESS(rc)) 1358 { 1359 crWarning("RegionsSet: crVrScrCompositorEntryPositionSet failed rc %d", rc); 1360 return rc; 1361 } 1362 } 1363 1364 rc = crVrScrCompositorEntryRegionsSet(pCompositor, pEntry, cRegions, paRegions, NULL); 1365 if (!RT_SUCCESS(rc)) 1366 { 1367 crWarning("crVrScrCompositorEntryRegionsSet failed, rc %d", rc); 1368 return rc; 1369 } 1370 1371 return VINF_SUCCESS; 1372 } 1373 1374 VBOXVREGDECL(int) CrVrScrCompositorEntryPosSet(PVBOXVR_SCR_COMPOSITOR pCompositor, PVBOXVR_SCR_COMPOSITOR_ENTRY pEntry, const RTPOINT *pPos) 1375 { 1376 int rc = crVrScrCompositorEntryPositionSet(pCompositor, pEntry, pPos, NULL); 1377 if (!RT_SUCCESS(rc)) 1378 { 1379 crWarning("RegionsSet: crVrScrCompositorEntryPositionSet failed rc %d", rc); 1380 return rc; 1381 } 1382 return VINF_SUCCESS; 1383 } 1384 1385 /* regions are valid until the next CrVrScrCompositor call */ 1386 VBOXVREGDECL(int) CrVrScrCompositorEntryRegionsGet(PVBOXVR_SCR_COMPOSITOR pCompositor, PVBOXVR_SCR_COMPOSITOR_ENTRY pEntry, uint32_t *pcRegions, const RTRECT **ppaSrcRegions, const RTRECT **ppaDstRegions) 1387 { 1388 int rc = crVrScrCompositorRectsCheckInit(pCompositor); 1389 if (!RT_SUCCESS(rc)) 1390 { 1391 crWarning("crVrScrCompositorRectsCheckInit failed, rc %d", rc); 1392 return rc; 1393 } 1394 1395 Assert(pCompositor->cRects != VBOXVR_SCR_COMPOSITOR_RECTS_UNDEFINED); 1396 1397 *pcRegions = pEntry->cRects; 1398 if (ppaSrcRegions) 1399 *ppaSrcRegions = pEntry->paSrcRects; 1400 if (ppaDstRegions) 1401 *ppaDstRegions = pEntry->paDstRects; 1402 1403 return VINF_SUCCESS; 1404 } 1405 1406 VBOXVREGDECL(int) CrVrScrCompositorEntryRemove(PVBOXVR_SCR_COMPOSITOR pCompositor, PVBOXVR_SCR_COMPOSITOR_ENTRY pEntry) 1407 { 1408 if (!VBoxVrCompositorEntryRemove(&pCompositor->Compositor, &pEntry->Ce)) 1409 return VINF_SUCCESS; 1410 1411 crVrScrCompositorRectsInvalidate(pCompositor); 1412 return VINF_SUCCESS; 1413 } 1414 1415 VBOXVREGDECL(int) CrVrScrCompositorInit(PVBOXVR_SCR_COMPOSITOR pCompositor) 1416 { 1417 memset(pCompositor, 0, sizeof (*pCompositor)); 1418 VBoxVrCompositorInit(&pCompositor->Compositor, NULL); 1419 pCompositor->StretchX = 1.0; 1420 pCompositor->StretchY = 1.0; 1421 return VINF_SUCCESS; 1422 } 1423 1424 VBOXVREGDECL(void) CrVrScrCompositorTerm(PVBOXVR_SCR_COMPOSITOR pCompositor) 1425 { 1426 VBoxVrCompositorTerm(&pCompositor->Compositor); 1427 if (pCompositor->paDstRects) 1428 RTMemFree(pCompositor->paDstRects); 1429 if (pCompositor->paSrcRects) 1430 RTMemFree(pCompositor->paSrcRects); 1431 } 1432 1433 1434 static DECLCALLBACK(bool) crVrScrCompositorEntrySetAllChangedCb(PVBOXVR_COMPOSITOR pCompositor, PVBOXVR_COMPOSITOR_ENTRY pCEntry, void *pvVisitor) 1435 { 1436 PVBOXVR_SCR_COMPOSITOR_ENTRY pEntry = VBOXVR_SCR_COMPOSITOR_ENTRY_FROM_ENTRY(pCEntry); 1437 CrVrScrCompositorEntrySetChanged(pEntry, !!pvVisitor); 1438 return true; 1439 } 1440 1441 VBOXVREGDECL(void) CrVrScrCompositorEntrySetAllChanged(PVBOXVR_SCR_COMPOSITOR pCompositor, bool fChanged) 1442 { 1443 VBoxVrCompositorVisit(&pCompositor->Compositor, crVrScrCompositorEntrySetAllChangedCb, (void*)fChanged); 1444 } 1445 1446 VBOXVREGDECL(void) CrVrScrCompositorSetStretching(PVBOXVR_SCR_COMPOSITOR pCompositor, float StretchX, float StretchY) 1447 { 1448 pCompositor->StretchX = StretchX; 1449 pCompositor->StretchY = StretchY; 1450 crVrScrCompositorRectsInvalidate(pCompositor); 1451 CrVrScrCompositorEntrySetAllChanged(pCompositor, true); 1452 } 1453 1454 /* regions are valid until the next CrVrScrCompositor call */ 1455 VBOXVREGDECL(int) CrVrScrCompositorRegionsGet(PVBOXVR_SCR_COMPOSITOR pCompositor, uint32_t *pcRegions, const RTRECT **ppaSrcRegions, const RTRECT **ppaDstRegions) 1456 { 1457 int rc = crVrScrCompositorRectsCheckInit(pCompositor); 1458 if (!RT_SUCCESS(rc)) 1459 { 1460 crWarning("crVrScrCompositorRectsCheckInit failed, rc %d", rc); 1461 return rc; 1462 } 1463 1464 Assert(pCompositor->cRects != VBOXVR_SCR_COMPOSITOR_RECTS_UNDEFINED); 1465 1466 *pcRegions = pCompositor->cRects; 1467 if (ppaSrcRegions) 1468 *ppaSrcRegions = pCompositor->paSrcRects; 1469 if (ppaDstRegions) 1470 *ppaDstRegions = pCompositor->paDstRects; 1471 1472 return VINF_SUCCESS; 1473 } 1474 1475 typedef struct VBOXVR_SCR_COMPOSITOR_VISITOR_CB 1476 { 1477 PFNVBOXVRSCRCOMPOSITOR_VISITOR pfnVisitor; 1478 void *pvVisitor; 1479 } VBOXVR_SCR_COMPOSITOR_VISITOR_CB, *PVBOXVR_SCR_COMPOSITOR_VISITOR_CB; 1480 1481 static DECLCALLBACK(bool) crVrScrCompositorVisitCb(PVBOXVR_COMPOSITOR pCCompositor, PVBOXVR_COMPOSITOR_ENTRY pCEntry, void *pvVisitor) 1482 { 1483 PVBOXVR_SCR_COMPOSITOR_VISITOR_CB pData = (PVBOXVR_SCR_COMPOSITOR_VISITOR_CB)pvVisitor; 1484 PVBOXVR_SCR_COMPOSITOR pCompositor = VBOXVR_SCR_COMPOSITOR_FROM_COMPOSITOR(pCCompositor); 1485 PVBOXVR_SCR_COMPOSITOR_ENTRY pEntry = VBOXVR_SCR_COMPOSITOR_ENTRY_FROM_ENTRY(pCEntry); 1486 return pData->pfnVisitor(pCompositor, pEntry, pData->pvVisitor); 1487 } 1488 1489 VBOXVREGDECL(void) CrVrScrCompositorVisit(PVBOXVR_SCR_COMPOSITOR pCompositor, PFNVBOXVRSCRCOMPOSITOR_VISITOR pfnVisitor, void *pvVisitor) 1490 { 1491 VBOXVR_SCR_COMPOSITOR_VISITOR_CB Data; 1492 Data.pfnVisitor = pfnVisitor; 1493 Data.pvVisitor = pvVisitor; 1494 VBoxVrCompositorVisit(&pCompositor->Compositor, crVrScrCompositorVisitCb, &Data); 1495 } -
trunk/src/VBox/HostServices/SharedOpenGL/Makefile.kmk
r43888 r44740 134 134 crserverlib/server_muralfbo.c \ 135 135 crserverlib/server_texture.c \ 136 crserverlib/server_blitter.cpp \137 136 crserverlib/server_presenter.cpp \ 138 137 $(VBOX_PATH_CROGL_GENFILES)/server_dispatch.c \ -
trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server.h
r44390 r44740 145 145 #define CR_SERVER_FBO_FB_IDX(_mural) (((_mural)->iBbBuffer + 1) % ((_mural)->cBuffers)) 146 146 147 PCR_BLITTER crServerGetFBOPresentBlitter(CRMuralInfo*pMural);148 149 147 int32_t crVBoxServerInternalClientRead(CRClient *pClient, uint8_t *pBuffer, uint32_t *pcbBuffer); 150 148 -
trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_config.c
r44290 r44740 162 162 int rc = crServerSetOffscreenRenderingMode(redir); 163 163 if (!RT_SUCCESS(rc)) 164 164 crWarning("offscreen rendering unsupported, no offscreen rendering will be used.."); 165 165 } 166 166 else 167 167 crWarning("invalid redir option %c", redir); 168 168 } 169 #ifdef RT_OS_DARWIN 170 else 171 { 172 int rc = crServerSetOffscreenRenderingMode(CR_SERVER_REDIR_FBO_BLT); 173 if (!RT_SUCCESS(rc)) 174 crWarning("offscreen rendering unsupported, no offscreen rendering will be used.."); 175 176 } 177 #endif 169 178 cr_server.bOffscreenRenderingDefault = cr_server.bForceOffscreenRendering; 170 179 … … 300 309 crWarning("invalid redir option %c", redir); 301 310 } 311 #ifdef RT_OS_DARWIN 312 else 313 { 314 int rc = crServerSetOffscreenRenderingMode(CR_SERVER_REDIR_FBO_BLT); 315 if (!RT_SUCCESS(rc)) 316 crWarning("offscreen rendering unsupported, no offscreen rendering will be used.."); 317 318 } 319 #endif 302 320 cr_server.bOffscreenRenderingDefault = cr_server.bForceOffscreenRendering; 303 321 -
trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_main.c
r44392 r44740 13 13 #include "cr_mem.h" 14 14 #include "cr_hash.h" 15 #include "cr_vreg.h" 15 16 #include "cr_environment.h" 16 17 #include "cr_pixeldata.h" … … 198 199 199 200 crNetTearDown(); 201 202 VBoxVrTerm(); 200 203 } 201 204 … … 243 246 char *mothership = NULL; 244 247 CRMuralInfo *defaultMural; 248 int rc = VBoxVrInit(); 249 if (!RT_SUCCESS(rc)) 250 { 251 crWarning("VBoxVrInit failed, rc %d", rc); 252 return; 253 } 245 254 246 255 for (i = 1 ; i < argc ; i++) … … 349 358 { 350 359 CRMuralInfo *defaultMural; 360 361 int rc = VBoxVrInit(); 362 if (!RT_SUCCESS(rc)) 363 { 364 crWarning("VBoxVrInit failed, rc %d", rc); 365 return GL_FALSE; 366 } 351 367 352 368 #if DEBUG_FP_EXCEPTIONS … … 1007 1023 else 1008 1024 { 1009 CR_BLITTER_TEXTURE Tex;1025 VBOXVR_TEXTURE Tex; 1010 1026 void *pvData; 1011 1027 GLuint idPBO = cr_server.bUsePBOForReadback ? pMural->idPBO : 0; -
trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_muralfbo.c
r44529 r44740 20 20 #include "cr_string.h" 21 21 #include "cr_mem.h" 22 #include "cr_vreg.h" 22 23 #include "render/renderspu.h" 23 24 … … 315 316 CRASSERT(mural->aidFBOs[0]==0); 316 317 CRASSERT(mural->aidFBOs[1]==0); 318 CRASSERT(mural->width == mural->CEntry.Tex.width); 319 CRASSERT(mural->height == mural->CEntry.Tex.height); 317 320 318 321 pMuralContextInfo = cr_server.currentCtxInfo; … … 415 418 } 416 419 420 CRASSERT(mural->aidColorTexs[CR_SERVER_FBO_FB_IDX(mural)]); 421 CrVrScrCompositorEntryTexNameUpdate(&mural->CEntry, mural->aidColorTexs[CR_SERVER_FBO_FB_IDX(mural)]); 422 417 423 if (RestoreSpuWindow >= 0 && RestoreSpuContext >= 0) 418 424 { … … 512 518 GLuint idPBO; 513 519 CRContext *ctx = crStateGetCurrent(); 514 CR_BLITTER_TEXTURE Tex;520 VBOXVR_TEXTURE Tex; 515 521 516 522 CRASSERT(mural->fUseFBO); … … 524 530 if (!mural->width || !mural->height) 525 531 { 532 return; 533 } 534 535 if (!CrVrScrCompositorEntryIsInList(&mural->CEntry)) 536 return; 537 538 if (mural->fUseFBO == CR_SERVER_REDIR_FBO_BLT) 539 { 540 GLuint idDrawFBO, idReadFBO; 541 542 idDrawFBO = mural->aidFBOs[mural->iCurDrawBuffer]; 543 idReadFBO = mural->aidFBOs[mural->iCurReadBuffer]; 544 545 crStateSwitchPrepare(NULL, ctx, idDrawFBO, idReadFBO); 546 547 cr_server.head_spu->dispatch_table.VBoxPresentComposition(mural->spuWindow, &mural->Compositor, &mural->CEntry); 548 549 crStateSwitchPostprocess(ctx, NULL, idDrawFBO, idReadFBO); 550 526 551 return; 527 552 } … … 532 557 Tex.hwid = mural->aidColorTexs[CR_SERVER_FBO_FB_IDX(mural)]; 533 558 CRASSERT(Tex.hwid); 534 535 if (mural->fUseFBO == CR_SERVER_REDIR_FBO_BLT)536 {537 int rc;538 PCR_BLITTER pBlitter = crServerGetFBOPresentBlitter(mural);539 if (!pBlitter)540 {541 static int cPrintedWarnings = 0;542 if (++cPrintedWarnings <= 5)543 {544 crWarning("crServerGetFBOPresentBlitter returned no blitter %d", cPrintedWarnings);545 if (cPrintedWarnings == 5)546 crWarning("won't print the above crServerGetFBOPresentBlitter warning any more", cPrintedWarnings);547 }548 return;549 }550 551 CrBltMuralSetCurrent(pBlitter, mural);552 rc = CrBltEnter(pBlitter, cr_server.currentCtxInfo, cr_server.currentMural);553 if (RT_SUCCESS(rc))554 {555 RTRECT Rect;556 Rect.xLeft = 0;557 Rect.yTop = 0;558 Rect.xRight = Tex.width;559 Rect.yBottom = Tex.height;560 561 CrBltBlitTexMural(pBlitter, &Tex, &Rect, &Rect, 1, 0);562 CrBltPresent(pBlitter);563 564 CrBltLeave(pBlitter);565 }566 else567 {568 crWarning("CrBltEnter failed rc %d", rc);569 return;570 }571 return;572 }573 559 574 560 if (cr_server.bUsePBOForReadback && !mural->idPBO) … … 687 673 cr_server.head_spu->dispatch_table.BindFramebufferEXT(GL_READ_FRAMEBUFFER, mural->aidFBOs[mural->iCurReadBuffer]); 688 674 } 689 } 675 Assert(mural->aidColorTexs[CR_SERVER_FBO_FB_IDX(mural)]); 676 CrVrScrCompositorEntryTexNameUpdate(&mural->CEntry, mural->aidColorTexs[CR_SERVER_FBO_FB_IDX(mural)]); 677 } -
trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_presenter.cpp
r44529 r44740 32 32 #include <iprt/mem.h> 33 33 34 #define CR_DISPLAY_RECTS_UNDEFINED UINT32_MAX35 36 37 #define CR_PRESENTER_ENTRY_FROM_ENTRY(_p) ((PCR_PRESENTER_ENTRY)(((uint8_t*)(_p)) - RT_OFFSETOF(CR_PRESENTER_ENTRY, Ce)))38 #define CR_PRESENTER_FROM_COMPOSITOR(_p) ((PCR_PRESENTER)(((uint8_t*)(_p)) - RT_OFFSETOF(CR_PRESENTER, Compositor)))39 40 41 static int crPtRectsAssignBuffer(PCR_PRESENTER pPresenter, uint32_t cRects)42 {43 Assert(cRects);44 45 if (pPresenter->cRectsBuffer >= cRects)46 {47 pPresenter->cRects = cRects;48 return VINF_SUCCESS;49 }50 51 if (pPresenter->cRectsBuffer)52 {53 Assert(pPresenter->paSrcRects);54 RTMemFree(pPresenter->paSrcRects);55 Assert(pPresenter->paDstRects);56 RTMemFree(pPresenter->paDstRects);57 }58 59 pPresenter->paSrcRects = (PRTRECT)RTMemAlloc(sizeof (*pPresenter->paSrcRects) * cRects);60 if (pPresenter->paSrcRects)61 {62 pPresenter->paDstRects = (PRTRECT)RTMemAlloc(sizeof (*pPresenter->paDstRects) * cRects);63 if (pPresenter->paDstRects)64 {65 pPresenter->cRects = cRects;66 pPresenter->cRectsBuffer = cRects;67 return VINF_SUCCESS;68 }69 else70 {71 crWarning("RTMemAlloc failed!");72 RTMemFree(pPresenter->paSrcRects);73 pPresenter->paSrcRects = NULL;74 }75 }76 else77 {78 crWarning("RTMemAlloc failed!");79 pPresenter->paDstRects = NULL;80 }81 82 pPresenter->cRects = CR_DISPLAY_RECTS_UNDEFINED;83 pPresenter->cRectsBuffer = 0;84 85 return VERR_NO_MEMORY;86 }87 88 static void crPtRectsInvalidate(PCR_PRESENTER pPresenter)89 {90 pPresenter->cRects = CR_DISPLAY_RECTS_UNDEFINED;91 }92 93 static DECLCALLBACK(bool) crPtRectsCounterCb(PVBOXVR_COMPOSITOR pCompositor, PVBOXVR_COMPOSITOR_ENTRY pEntry, void *pvVisitor)94 {95 uint32_t* pCounter = (uint32_t*)pvVisitor;96 Assert(VBoxVrListRectsCount(&pEntry->Vr));97 *pCounter += VBoxVrListRectsCount(&pEntry->Vr);98 return true;99 }100 101 typedef struct CR_PRESENTOR_RECTS_ASSIGNER102 {103 PRTRECT paSrcRects;104 PRTRECT paDstRects;105 uint32_t cRects;106 } CR_PRESENTOR_RECTS_ASSIGNER, *PCR_PRESENTOR_RECTS_ASSIGNER;107 108 static DECLCALLBACK(bool) crPtRectsAssignerCb(PVBOXVR_COMPOSITOR pCompositor, PVBOXVR_COMPOSITOR_ENTRY pCEntry, void *pvVisitor)109 {110 PCR_PRESENTOR_RECTS_ASSIGNER pData = (PCR_PRESENTOR_RECTS_ASSIGNER)pvVisitor;111 PCR_PRESENTER pPresenter = CR_PRESENTER_FROM_COMPOSITOR(pCompositor);112 PCR_PRESENTER_ENTRY pEntry = CR_PRESENTER_ENTRY_FROM_ENTRY(pCEntry);113 pEntry->paSrcRects = pData->paSrcRects;114 pEntry->paDstRects = pData->paDstRects;115 uint32_t cRects = VBoxVrListRectsCount(&pCEntry->Vr);116 Assert(cRects);117 Assert(cRects >= pData->cRects);118 int rc = VBoxVrListRectsGet(&pCEntry->Vr, cRects, pEntry->paDstRects);119 AssertRC(rc);120 if (pPresenter->StretchX >= 1. && pPresenter->StretchY >= 1. /* <- stretching can not zero some rects */121 && !pEntry->Pos.x && !pEntry->Pos.y)122 {123 memcpy(pEntry->paSrcRects, pEntry->paDstRects, cRects * sizeof (*pEntry->paSrcRects));124 }125 else126 {127 for (uint32_t i = 0; i < cRects; ++i)128 {129 pEntry->paSrcRects[i].xLeft = (int32_t)((pEntry->paDstRects[i].xLeft - pEntry->Pos.x) * pPresenter->StretchX);130 pEntry->paSrcRects[i].yTop = (int32_t)((pEntry->paDstRects[i].yTop - pEntry->Pos.y) * pPresenter->StretchY);131 pEntry->paSrcRects[i].xRight = (int32_t)((pEntry->paDstRects[i].xRight - pEntry->Pos.x) * pPresenter->StretchX);132 pEntry->paSrcRects[i].yBottom = (int32_t)((pEntry->paDstRects[i].yBottom - pEntry->Pos.y) * pPresenter->StretchY);133 }134 135 bool canZeroX = (pPresenter->StretchX < 1);136 bool canZeroY = (pPresenter->StretchY < 1);137 if (canZeroX && canZeroY)138 {139 /* filter out zero rectangles*/140 uint32_t iOrig, iNew;141 for (iOrig = 0, iNew = 0; iOrig < cRects; ++iOrig)142 {143 PRTRECT pOrigRect = &pEntry->paSrcRects[iOrig];144 if (pOrigRect->xLeft == pOrigRect->xRight145 || pOrigRect->yTop == pOrigRect->yBottom)146 continue;147 148 if (iNew != iOrig)149 {150 PRTRECT pNewRect = &pEntry->paSrcRects[iNew];151 *pNewRect = *pOrigRect;152 }153 154 ++iNew;155 }156 157 Assert(iNew <= iOrig);158 159 uint32_t cDiff = iOrig - iNew;160 161 if (cDiff)162 {163 pPresenter->cRects -= cDiff;164 cRects -= cDiff;165 }166 }167 }168 169 pEntry->cRects = cRects;170 pData->paDstRects += cRects;171 pData->paSrcRects += cRects;172 pData->cRects -= cRects;173 return true;174 }175 176 static int crPtRectsCheckInit(PCR_PRESENTER pPresenter)177 {178 if (pPresenter->cRects != CR_DISPLAY_RECTS_UNDEFINED)179 return VINF_SUCCESS;180 181 uint32_t cRects = 0;182 VBoxVrCompositorVisit(&pPresenter->Compositor, crPtRectsCounterCb, &cRects);183 184 if (!cRects)185 {186 pPresenter->cRects = 0;187 return VINF_SUCCESS;188 }189 190 int rc = crPtRectsAssignBuffer(pPresenter, cRects);191 if (!RT_SUCCESS(rc))192 return rc;193 194 CR_PRESENTOR_RECTS_ASSIGNER AssignerData;195 AssignerData.paSrcRects = pPresenter->paSrcRects;196 AssignerData.paDstRects = pPresenter->paDstRects;197 AssignerData.cRects = pPresenter->cRects;198 VBoxVrCompositorVisit(&pPresenter->Compositor, crPtRectsAssignerCb, &AssignerData);199 Assert(!AssignerData.cRects);200 return VINF_SUCCESS;201 }202 203 DECLCALLBACK(int) CrPtCbDrawEntrySingle(struct CR_PRESENTER *pPresenter, struct CR_PRESENTER_ENTRY *pEntry, PCR_BLITTER pBlitter, bool *pfAllEntriesDrawn)204 {205 if (pfAllEntriesDrawn)206 *pfAllEntriesDrawn = false;207 208 int rc = crPtRectsCheckInit(pPresenter);209 if (!RT_SUCCESS(rc))210 {211 crWarning("crPtRectsCheckInit failed, rc %d", rc);212 return rc;213 }214 215 Assert(VBoxVrListRectsCount(&pEntry->Ce.Vr));216 217 if (!pEntry->cRects)218 return VINF_SUCCESS;219 220 rc = pPresenter->pfnDrawTexture(pPresenter, pBlitter, &pEntry->Texture, pEntry->paSrcRects, pEntry->paDstRects, pEntry->cRects);221 if (!RT_SUCCESS(rc))222 {223 crWarning("pfnDrawTexture failed, rc %d", rc);224 return rc;225 }226 227 return VINF_SUCCESS;228 }229 230 static DECLCALLBACK(bool) crPtDrawEntryAllCb(PVBOXVR_COMPOSITOR pCompositor, PVBOXVR_COMPOSITOR_ENTRY pCEntry, void *pvVisitor)231 {232 struct CR_PRESENTER *pPresenter = CR_PRESENTER_FROM_COMPOSITOR(pCompositor);233 struct CR_PRESENTER_ENTRY *pEntry = CR_PRESENTER_ENTRY_FROM_ENTRY(pCEntry);234 PCR_BLITTER pBlitter = (PCR_BLITTER)pvVisitor;235 bool fAllEntriesDrawn;236 int rc = CrPtCbDrawEntrySingle(pPresenter, pEntry, pBlitter, &fAllEntriesDrawn);237 if (!RT_SUCCESS(rc))238 {239 crWarning("CrPtCbDrawEntrySingle failed, rc %d", rc);240 }241 return !fAllEntriesDrawn;242 }243 244 DECLCALLBACK(int) CrPtCbDrawEntryAll(struct CR_PRESENTER *pPresenter, struct CR_PRESENTER_ENTRY *pEntry, PCR_BLITTER pBlitter, bool *pfAllEntriesDrawn)245 {246 int rc = crPtRectsCheckInit(pPresenter);247 if (!RT_SUCCESS(rc))248 {249 crWarning("crPtRectsCheckInit failed, rc %d", rc);250 return rc;251 }252 253 VBoxVrCompositorVisit(&pPresenter->Compositor, crPtDrawEntryAllCb, pBlitter);254 255 if (pfAllEntriesDrawn)256 *pfAllEntriesDrawn = true;257 258 return VINF_SUCCESS;259 }260 261 static int crPtEntryRegionsAdd(PCR_PRESENTER pPresenter, PCR_PRESENTER_ENTRY pEntry, uint32_t cRegions, const RTRECT *paRegions, bool *pfChanged)262 {263 uint32_t fChangedFlags = 0;264 int rc = VBoxVrCompositorEntryRegionsAdd(&pPresenter->Compositor, &pEntry->Ce, cRegions, paRegions, &fChangedFlags);265 if (!RT_SUCCESS(rc))266 {267 crWarning("VBoxVrCompositorEntryRegionsAdd failed, rc %d", rc);268 return rc;269 }270 271 if (fChangedFlags & VBOXVR_COMPOSITOR_CF_COMPOSITED_REGIONS_CHANGED)272 {273 crPtRectsInvalidate(pPresenter);274 rc = pPresenter->pfnRegionsChanged(pPresenter);275 if (!RT_SUCCESS(rc))276 {277 crWarning("pfnRegionsChanged failed, rc %d", rc);278 return rc;279 }280 }281 282 if (pfChanged)283 *pfChanged = !!fChangedFlags;284 return VINF_SUCCESS;285 }286 287 static int crPtEntryRegionsSet(PCR_PRESENTER pPresenter, PCR_PRESENTER_ENTRY pEntry, uint32_t cRegions, const RTRECT *paRegions, bool *pfChanged)288 {289 bool fChanged;290 int rc = VBoxVrCompositorEntryRegionsSet(&pPresenter->Compositor, &pEntry->Ce, cRegions, paRegions, &fChanged);291 if (!RT_SUCCESS(rc))292 {293 crWarning("VBoxVrCompositorEntryRegionsSet failed, rc %d", rc);294 return rc;295 }296 297 if (fChanged)298 {299 crPtRectsInvalidate(pPresenter);300 rc = pPresenter->pfnRegionsChanged(pPresenter);301 if (!RT_SUCCESS(rc))302 {303 crWarning("pfnRegionsChanged failed, rc %d", rc);304 return rc;305 }306 }307 308 if (pfChanged)309 *pfChanged = fChanged;310 return VINF_SUCCESS;311 }312 313 static void crPtEntryPositionSet(PCR_PRESENTER pPresenter, PCR_PRESENTER_ENTRY pEntry, const RTPOINT *pPos)314 {315 if (pEntry && (pEntry->Pos.x != pPos->x || pEntry->Pos.y != pPos->y))316 {317 if (VBoxVrCompositorEntryIsInList(&pEntry->Ce))318 {319 VBoxVrCompositorEntryRemove(&pPresenter->Compositor, &pEntry->Ce);320 crPtRectsInvalidate(pPresenter);321 }322 pEntry->Pos = *pPos;323 }324 }325 326 int CrPtPresentEntry(PCR_PRESENTER pPresenter, PCR_PRESENTER_ENTRY pEntry, PCR_BLITTER pBlitter)327 {328 int rc = CrBltEnter(pBlitter, cr_server.currentCtxInfo, cr_server.currentMural);329 if (!RT_SUCCESS(rc))330 {331 crWarning("CrBltEnter failed, rc %d", rc);332 return rc;333 }334 335 rc = pPresenter->pfnDrawEntry(pPresenter, pEntry, pBlitter, NULL);336 337 CrBltLeave(pBlitter);338 339 if (!RT_SUCCESS(rc))340 {341 crWarning("pfnDraw failed, rc %d", rc);342 return rc;343 }344 345 return VINF_SUCCESS;346 }347 348 static DECLCALLBACK(bool) crPtPresentCb(PVBOXVR_COMPOSITOR pCompositor, PVBOXVR_COMPOSITOR_ENTRY pCEntry, void *pvVisitor)349 {350 struct CR_PRESENTER *pPresenter = CR_PRESENTER_FROM_COMPOSITOR(pCompositor);351 struct CR_PRESENTER_ENTRY *pEntry = CR_PRESENTER_ENTRY_FROM_ENTRY(pCEntry);352 PCR_BLITTER pBlitter = (PCR_BLITTER)pvVisitor;353 bool fAllDrawn = false;354 int rc = pPresenter->pfnDrawEntry(pPresenter, pEntry, pBlitter, &fAllDrawn);355 if (!RT_SUCCESS(rc))356 {357 crWarning("pfnDrawEntry failed, rc %d", rc);358 }359 return !fAllDrawn;360 }361 362 int CrPtPresent(PCR_PRESENTER pPresenter, PCR_BLITTER pBlitter)363 {364 int rc = CrBltEnter(pBlitter, cr_server.currentCtxInfo, cr_server.currentMural);365 if (!RT_SUCCESS(rc))366 {367 crWarning("CrBltEnter failed, rc %d", rc);368 return rc;369 }370 371 VBoxVrCompositorVisit(&pPresenter->Compositor, crPtPresentCb, pBlitter);372 373 CrBltLeave(pBlitter);374 375 if (!RT_SUCCESS(rc))376 {377 crWarning("pfnDraw failed, rc %d", rc);378 return rc;379 }380 381 return VINF_SUCCESS;382 }383 384 int CrPtEntryRegionsAdd(PCR_PRESENTER pPresenter, PCR_PRESENTER_ENTRY pEntry, const RTPOINT *pPos, uint32_t cRegions, const RTRECT *paRegions)385 {386 crPtEntryPositionSet(pPresenter, pEntry, pPos);387 388 int rc = crPtEntryRegionsAdd(pPresenter, pEntry, cRegions, paRegions, NULL);389 if (!RT_SUCCESS(rc))390 {391 crWarning("crPtEntryRegionsAdd failed, rc %d", rc);392 return rc;393 }394 395 return VINF_SUCCESS;396 }397 398 int CrPtEntryRegionsSet(PCR_PRESENTER pPresenter, PCR_PRESENTER_ENTRY pEntry, const RTPOINT *pPos, uint32_t cRegions, const RTRECT *paRegions)399 {400 crPtEntryPositionSet(pPresenter, pEntry, pPos);401 402 int rc = crPtEntryRegionsSet(pPresenter, pEntry, cRegions, paRegions, NULL);403 if (!RT_SUCCESS(rc))404 {405 crWarning("crPtEntryRegionsAdd failed, rc %d", rc);406 return rc;407 }408 409 return VINF_SUCCESS;410 }411 412 int CrPtEntryRemove(PCR_PRESENTER pPresenter, PCR_PRESENTER_ENTRY pEntry)413 {414 if (!VBoxVrCompositorEntryRemove(&pPresenter->Compositor, &pEntry->Ce))415 return VINF_SUCCESS;416 417 crPtRectsInvalidate(pPresenter);418 int rc = pPresenter->pfnRegionsChanged(pPresenter);419 if (!RT_SUCCESS(rc))420 {421 crWarning("pfnRegionsChanged failed, rc %d", rc);422 return rc;423 }424 return VINF_SUCCESS;425 }426 427 int CrPtInit(PCR_PRESENTER pPresenter, PFNCRDISPLAY_REGIONS_CHANGED pfnRegionsChanged, PFNCRDISPLAY_DRAW_ENTRY pfnDrawEntry, PFNCRDISPLAY_DRAW_TEXTURE pfnDrawTexture)428 {429 memset(pPresenter, 0, sizeof (*pPresenter));430 VBoxVrCompositorInit(&pPresenter->Compositor, NULL);431 pPresenter->StretchX = 1.0;432 pPresenter->StretchY = 1.0;433 pPresenter->pfnRegionsChanged = pfnRegionsChanged;434 pPresenter->pfnDrawEntry = pfnDrawEntry;435 pPresenter->pfnDrawTexture = pfnDrawTexture;436 return VINF_SUCCESS;437 }438 439 void CrPtTerm(PCR_PRESENTER pPresenter)440 {441 VBoxVrCompositorTerm(&pPresenter->Compositor);442 if (pPresenter->paDstRects)443 RTMemFree(pPresenter->paDstRects);444 if (pPresenter->paSrcRects)445 RTMemFree(pPresenter->paSrcRects);446 }447 448 void CrPtSetStretching(PCR_PRESENTER pPresenter, float StretchX, float StretchY)449 {450 pPresenter->StretchX = StretchX;451 pPresenter->StretchY = StretchY;452 crPtRectsInvalidate(pPresenter);453 }454 455 int CrPtGetRegions(PCR_PRESENTER pPresenter, uint32_t *pcRegions, const RTRECT **ppaRegions)456 {457 int rc = crPtRectsCheckInit(pPresenter);458 if (!RT_SUCCESS(rc))459 {460 crWarning("crPtRectsCheckInit failed, rc %d", rc);461 return rc;462 }463 464 Assert(pPresenter->cRects != CR_DISPLAY_RECTS_UNDEFINED);465 466 *pcRegions = pPresenter->cRects;467 *ppaRegions = pPresenter->paDstRects;468 return VINF_SUCCESS;469 }470 34 471 35 /* DISPLAY */ 472 #define CR_DISPLAY_FROM_PRESENTER(_p) ((PCR_DISPLAY)(((uint8_t*)(_p)) - RT_OFFSETOF(CR_DISPLAY, Presenter))) 473 474 static DECLCALLBACK(int) crDpCbRegionsChanged(struct CR_PRESENTER *pPresenter) 475 { 476 uint32_t cRegions; 477 const RTRECT *paRegions; 478 int rc = CrPtGetRegions(pPresenter, &cRegions, &paRegions); 479 if (!RT_SUCCESS(rc)) 480 { 481 crWarning("CrPtGetRegions failed, rc %d", rc); 482 return rc; 483 } 484 485 PCR_DISPLAY pDisplay = CR_DISPLAY_FROM_PRESENTER(pPresenter); 486 487 cr_server.head_spu->dispatch_table.WindowVisibleRegion(pDisplay->Mural.spuWindow, cRegions, (GLint*)paRegions); 488 489 if (pDisplay->Mural.pvOutputRedirectInstance) 490 { 491 /* @todo the code assumes that RTRECT == four GLInts. */ 492 cr_server.outputRedirect.CRORVisibleRegion(pDisplay->Mural.pvOutputRedirectInstance, 493 cRegions, paRegions); 494 } 495 496 return VINF_SUCCESS; 497 } 498 499 static DECLCALLBACK(int) crDpCbDrawTextureWindow(struct CR_PRESENTER *pPresenter, PCR_BLITTER pBlitter, 500 CR_BLITTER_TEXTURE *pTexture, const RTRECT *paSrcRects, const RTRECT *paDstRects, uint32_t cRects) 501 { 502 Assert(CrBltIsEntered(pBlitter)); 503 CrBltBlitTexMural(pBlitter, pTexture, paSrcRects, paDstRects, cRects, 0); 504 return VINF_SUCCESS; 505 } 36 37 //static DECLCALLBACK(int) crDpCbRegionsChanged(struct CR_PRESENTER *pPresenter) 38 //{ 39 // uint32_t cRegions; 40 // const RTRECT *paRegions; 41 // int rc = CrPtGetRegions(pPresenter, &cRegions, &paRegions); 42 // if (!RT_SUCCESS(rc)) 43 // { 44 // crWarning("CrPtGetRegions failed, rc %d", rc); 45 // return rc; 46 // } 47 // 48 // PCR_DISPLAY pDisplay = CR_DISPLAY_FROM_PRESENTER(pPresenter); 49 // 50 // cr_server.head_spu->dispatch_table.WindowVisibleRegion(pDisplay->Mural.spuWindow, cRegions, (GLint*)paRegions); 51 // 52 // if (pDisplay->Mural.pvOutputRedirectInstance) 53 // { 54 // /* @todo the code assumes that RTRECT == four GLInts. */ 55 // cr_server.outputRedirect.CRORVisibleRegion(pDisplay->Mural.pvOutputRedirectInstance, 56 // cRegions, paRegions); 57 // } 58 // 59 // return VINF_SUCCESS; 60 //} 506 61 507 62 int CrDpInit(PCR_DISPLAY pDisplay) 508 63 { 509 const GLint visBits = CR_RGB_BIT | CR_DOUBLE_BIT; 510 int rc = CrPtInit(&pDisplay->Presenter, crDpCbRegionsChanged, CrPtCbDrawEntryAll, crDpCbDrawTextureWindow); 64 int rc = CrVrScrCompositorInit(&pDisplay->Compositor); 511 65 if (RT_SUCCESS(rc)) 512 66 { 67 const GLint visBits = CR_RGB_BIT | CR_DOUBLE_BIT; 513 68 if (crServerMuralInit(&pDisplay->Mural, "", visBits, -1) >= 0) 514 69 { … … 521 76 rc = VERR_GENERAL_FAILURE; 522 77 } 523 CrPtTerm(&pDisplay->Presenter); 78 CrVrScrCompositorTerm(&pDisplay->Compositor); 79 } 80 else 81 { 82 crWarning("CrVrScrCompositorInit failed, rc %d", rc); 524 83 } 525 84 CRASSERT(RT_FAILURE(rc)); … … 529 88 void CrDpTerm(PCR_DISPLAY pDisplay) 530 89 { 531 Cr PtTerm(&pDisplay->Presenter);90 CrVrScrCompositorTerm(&pDisplay->Compositor); 532 91 crServerMuralTerm(&pDisplay->Mural); 533 }534 535 int CrDpBlitterTestWithMural(PCR_BLITTER pBlitter, CRMuralInfo *pMural)536 {537 CrBltMuralSetCurrent(pBlitter, pMural);538 /* try to enter to make sure the blitter is initialized completely and to make sure we actually can do that */539 int rc = CrBltEnter(pBlitter, cr_server.currentCtxInfo, cr_server.currentMural);540 if (RT_SUCCESS(rc))541 {542 CrBltLeave(pBlitter);543 return VINF_SUCCESS;544 }545 else546 {547 crWarning("CrBltEnter failed, rc %d", rc);548 }549 return rc;550 }551 552 int CrDpBlitterTest(PCR_DISPLAY pDisplay, PCR_BLITTER pBlitter)553 {554 return CrDpBlitterTestWithMural(pBlitter, &pDisplay->Mural);555 92 } 556 93 … … 562 99 StretchY = ((float)stretchedHeight)/height; 563 100 crServerMuralSize(&pDisplay->Mural, stretchedWidth, stretchedHeight); 564 Cr PtSetStretching(&pDisplay->Presenter, StretchX, StretchY);101 CrVrScrCompositorSetStretching(&pDisplay->Compositor, StretchX, StretchY); 565 102 } 566 103 567 104 int CrDpEntryRegionsSet(PCR_DISPLAY pDisplay, PCR_DISPLAY_ENTRY pEntry, const RTPOINT *pPos, uint32_t cRegions, const RTRECT *paRegions) 568 105 { 569 return Cr PtEntryRegionsSet(&pDisplay->Presenter, &pEntry->Pe, pPos, cRegions, paRegions);106 return CrVrScrCompositorEntryRegionsSet(&pDisplay->Compositor, &pEntry->CEntry, pPos, cRegions, paRegions); 570 107 } 571 108 572 109 int CrDpEntryRegionsAdd(PCR_DISPLAY pDisplay, PCR_DISPLAY_ENTRY pEntry, const RTPOINT *pPos, uint32_t cRegions, const RTRECT *paRegions) 573 110 { 574 return Cr PtEntryRegionsAdd(&pDisplay->Presenter, &pEntry->Pe, pPos, cRegions, paRegions);111 return CrVrScrCompositorEntryRegionsAdd(&pDisplay->Compositor, &pEntry->CEntry, pPos, cRegions, paRegions); 575 112 } 576 113 577 114 int CrDpPresentEntry(PCR_DISPLAY pDisplay, PCR_DISPLAY_ENTRY pEntry) 578 115 { 579 return CrPtPresentEntry(&pDisplay->Presenter, &pEntry->Pe, pDisplay->pBlitter); 580 } 581 582 void CrDpEntryInit(PCR_DISPLAY_ENTRY pEntry, PCR_BLITTER_TEXTURE pTextureData) 583 { 584 CrPtEntryInit(&pEntry->Pe, pTextureData); 116 GLuint idDrawFBO = 0, idReadFBO = 0; 117 CRMuralInfo *pMural = cr_server.currentMural; 118 CRContext *pCtx = cr_server.currentCtxInfo ? cr_server.currentCtxInfo->pContext : cr_server.MainContextInfo.pContext; 119 120 if (pMural) 121 { 122 idDrawFBO = pMural->aidFBOs[pMural->iCurDrawBuffer]; 123 idReadFBO = pMural->aidFBOs[pMural->iCurReadBuffer]; 124 } 125 126 crStateSwitchPrepare(NULL, pCtx, idDrawFBO, idReadFBO); 127 128 cr_server.head_spu->dispatch_table.VBoxPresentComposition(pDisplay->Mural.spuWindow, &pDisplay->Compositor, &pEntry->CEntry); 129 130 crStateSwitchPostprocess(pCtx, NULL, idDrawFBO, idReadFBO); 131 132 return VINF_SUCCESS; 133 } 134 135 void CrDpEntryInit(PCR_DISPLAY_ENTRY pEntry, const PVBOXVR_TEXTURE pTextureData) 136 { 137 CrVrScrCompositorEntryInit(&pEntry->CEntry, pTextureData); 585 138 } 586 139 587 140 void CrDpEntryCleanup(PCR_DISPLAY pDisplay, PCR_DISPLAY_ENTRY pEntry) 588 141 { 589 Cr PtEntryRemove(&pDisplay->Presenter, &pEntry->Pe);142 CrVrScrCompositorEntryRemove(&pDisplay->Compositor, &pEntry->CEntry); 590 143 } 591 144 … … 632 185 } 633 186 634 CR_BLITTER_TEXTURE TextureData;187 VBOXVR_TEXTURE TextureData; 635 188 TextureData.width = pTobj->level[0]->width; 636 189 TextureData.height = pTobj->level[0]->height; … … 675 228 #define CR_PRESENT_GET_FLAGS(_cfg) ((_cfg) >> CR_PRESENT_FLAGS_OFFSET) 676 229 677 int crServerBlitterInit(PCR_BLITTER pBlitter, CRMuralInfo*pMural)678 {679 int rc = CrBltInit(pBlitter, pMural);680 if (RT_SUCCESS(rc))681 {682 rc = CrDpBlitterTestWithMural(pBlitter, pMural);683 if (RT_SUCCESS(rc))684 return VINF_SUCCESS;685 else686 crWarning("CrDpBlitterTestWithMural failed, rc %d", rc);687 CrBltTerm(pBlitter);688 }689 else690 crWarning("CrBltInit failed, rc %d", rc);691 return rc;692 }693 694 PCR_BLITTER crServerGetFBOPresentBlitter(CRMuralInfo*pMural)695 {696 if (cr_server.fFBOModeBlitterInited > 0)697 return &cr_server.FBOModeBlitter;698 if (!cr_server.fFBOModeBlitterInited)699 {700 int rc = crServerBlitterInit(&cr_server.FBOModeBlitter, pMural);701 if (RT_SUCCESS(rc))702 {703 cr_server.fFBOModeBlitterInited = 1;704 return &cr_server.FBOModeBlitter;705 }706 crWarning("crServerBlitterInit failed rc %d", rc);707 cr_server.fFBOModeBlitterInited = -1;708 }709 return NULL;710 }711 712 static int8_t crServerCheckInitDisplayBlitter()713 {714 if (cr_server.fPresentBlitterInited)715 return cr_server.fPresentBlitterInited;716 717 crDebug("Display Functionality is requested");718 Assert(!ASMBitTest(cr_server.DisplaysInitMap, 0));719 720 int rc = CrDemInit(&cr_server.PresentTexturepMap);721 if (RT_SUCCESS(rc))722 {723 rc = CrDpInit(&cr_server.aDispplays[0]);724 if (RT_SUCCESS(rc))725 {726 CRMuralInfo*pMural = CrDpGetMural(&cr_server.aDispplays[0]);727 rc = crServerBlitterInit(&cr_server.PresentBlitter, pMural);728 if (RT_SUCCESS(rc))729 {730 CrDpBlitterSet(&cr_server.aDispplays[0], &cr_server.PresentBlitter);731 CrDpResize(&cr_server.aDispplays[0],732 cr_server.screen[0].w, cr_server.screen[0].h,733 cr_server.screen[0].w, cr_server.screen[0].h);734 ASMBitSet(cr_server.DisplaysInitMap, 0);735 cr_server.fPresentBlitterInited = 1;736 return 1;737 }738 else739 {740 crWarning("crServerBlitterInit failed, rc %d", rc);741 }742 CrDpTerm(&cr_server.aDispplays[0]);743 }744 else745 {746 crWarning("CrDpInit failed, rc %d", rc);747 }748 CrDemTerm(&cr_server.PresentTexturepMap);749 }750 else751 {752 crWarning("CrDemInit failed, rc %d", rc);753 }754 755 cr_server.fPresentBlitterInited = -1;756 return -1;757 }758 759 static bool crServerDisplayIsSupported()760 {761 return crServerCheckInitDisplayBlitter() > 0;762 }763 764 230 PCR_DISPLAY crServerDisplayGetInitialized(uint32_t idScreen) 765 231 { … … 780 246 return &cr_server.aDispplays[idScreen]; 781 247 782 if (crServerCheckInitDisplayBlitter() > 0) 783 { 784 /* the display (screen id == 0) can be initialized while doing crServerCheckInitDisplayBlitter, 785 * so re-check the bit map */ 786 if (ASMBitTest(cr_server.DisplaysInitMap, idScreen)) 787 return &cr_server.aDispplays[idScreen]; 788 789 int rc = CrDpInit(&cr_server.aDispplays[idScreen]); 790 if (RT_SUCCESS(rc)) 791 { 792 CrDpBlitterSet(&cr_server.aDispplays[idScreen], &cr_server.PresentBlitter); 793 CrDpResize(&cr_server.aDispplays[idScreen], 794 cr_server.screen[idScreen].w, cr_server.screen[idScreen].h, 795 cr_server.screen[idScreen].w, cr_server.screen[idScreen].h); 796 ASMBitSet(cr_server.DisplaysInitMap, idScreen); 797 return &cr_server.aDispplays[idScreen]; 798 } 799 else 800 { 801 crWarning("CrDpInit failed for screen %d", idScreen); 802 } 803 } 804 else 805 { 806 crWarning("crServerCheckInitDisplayBlitter said \"UNSUPPORTED\""); 807 } 248 /* the display (screen id == 0) can be initialized while doing crServerCheckInitDisplayBlitter, 249 * so re-check the bit map */ 250 if (ASMBitTest(cr_server.DisplaysInitMap, idScreen)) 251 return &cr_server.aDispplays[idScreen]; 252 253 int rc = CrDpInit(&cr_server.aDispplays[idScreen]); 254 if (RT_SUCCESS(rc)) 255 { 256 CrDpResize(&cr_server.aDispplays[idScreen], 257 cr_server.screen[idScreen].w, cr_server.screen[idScreen].h, 258 cr_server.screen[idScreen].w, cr_server.screen[idScreen].h); 259 ASMBitSet(cr_server.DisplaysInitMap, idScreen); 260 return &cr_server.aDispplays[idScreen]; 261 } 262 else 263 { 264 crWarning("CrDpInit failed for screen %d", idScreen); 265 } 808 266 809 267 return NULL; … … 828 286 } 829 287 830 void* CrHlpGetTexImage(CRContext *pCurCtx, P CR_BLITTER_TEXTURE pTexture, GLuint idPBO)288 void* CrHlpGetTexImage(CRContext *pCurCtx, PVBOXVR_TEXTURE pTexture, GLuint idPBO) 831 289 { 832 290 void *pvData = NULL; … … 885 343 886 344 void SERVER_DISPATCH_APIENTRY 887 crServerDispatch TexPresent(GLuint texture, GLuint cfg, GLint xPos, GLint yPos, GLint cRects, GLint *pRects)345 crServerDispatchVBoxTexPresent(GLuint texture, GLuint cfg, GLint xPos, GLint yPos, GLint cRects, GLint *pRects) 888 346 { 889 347 uint32_t idScreen = CR_PRESENT_GET_SCREEN(cfg); -
trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_special
r44388 r44740 250 250 DrawBuffer 251 251 ReadBuffer 252 TexPresent252 VBoxTexPresent 253 253 GetError -
trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_window.c
r44389 r44740 22 22 GLint dims[2]; 23 23 GLint windowID = -1; 24 GLint spuWindow; 25 VBOXVR_TEXTURE Tex = {0}; 26 27 int rc = CrVrScrCompositorInit(&mural->Compositor); 28 if (!RT_SUCCESS(rc)) 29 { 30 crWarning("CrVrScrCompositorInit failed, rc %d", rc); 31 return -1; 32 } 33 24 34 /* 25 35 * Have first SPU make a new window. 26 36 */ 27 GLintspuWindow = cr_server.head_spu->dispatch_table.WindowCreate( dpyName, visBits );37 spuWindow = cr_server.head_spu->dispatch_table.WindowCreate( dpyName, visBits ); 28 38 if (spuWindow < 0) { 29 crServerReturnValue( &spuWindow, sizeof(spuWindow));39 CrVrScrCompositorTerm(&mural->Compositor); 30 40 return spuWindow; 31 41 } … … 33 43 /* get initial window size */ 34 44 cr_server.head_spu->dispatch_table.GetChromiumParametervCR(GL_WINDOW_SIZE_CR, spuWindow, GL_INT, 2, dims); 45 46 Tex.width = dims[0]; 47 Tex.height = dims[1]; 48 Tex.target = GL_TEXTURE_2D; 49 Tex.hwid = 0; 50 CrVrScrCompositorEntryInit(&mural->CEntry, &Tex); 35 51 36 52 defaultMural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, 0); … … 118 134 { 119 135 crWarning("crServerMuralInit failed!"); 136 crServerReturnValue( &windowID, sizeof(windowID) ); 120 137 crFree(mural); 121 138 return windowID; … … 290 307 } 291 308 309 CrVrScrCompositorTerm(&mural->Compositor); 310 292 311 crHashtableDelete(cr_server.muralTable, window, crFree); 293 312 } … … 295 314 void crServerMuralSize(CRMuralInfo *mural, GLint width, GLint height) 296 315 { 297 mural->width = width; 298 mural->height = height; 316 if (mural->width != width || mural->height != height) 317 { 318 VBOXVR_TEXTURE Tex; 319 Tex.width = width; 320 Tex.height = height; 321 Tex.target = GL_TEXTURE_2D; 322 Tex.hwid = 0; 323 CrVrScrCompositorEntryRemove(&mural->Compositor, &mural->CEntry); 324 CrVrScrCompositorEntryInit(&mural->CEntry, &Tex); 325 mural->width = width; 326 mural->height = height; 327 } 299 328 300 329 if (cr_server.curClient && cr_server.curClient->currentMural == mural) … … 342 371 { 343 372 CRMuralInfo *mural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, window); 373 RTPOINT Pos; 344 374 /* crDebug("CRServer: Window %d pos %d, %d", window, x, y);*/ 345 375 if (!mural) { … … 352 382 mural->gY = y; 353 383 384 Pos.x = x; 385 Pos.y = y; 386 387 CrVrScrCompositorEntryPosSet(&mural->Compositor, &mural->CEntry, &Pos); 388 354 389 crServerCheckMuralGeometry(mural); 355 390 } … … 392 427 cRects, (RTRECT *)pRects); 393 428 } 429 430 CrVrScrCompositorEntryRegionsSet(&mural->Compositor, &mural->CEntry, NULL, cRects, (const RTRECT *)pRects); 394 431 } 395 432 -
trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu.c
r44377 r44740 10 10 #include "cr_mem.h" 11 11 #include "cr_spu.h" 12 #include "cr_environment.h" 12 13 #include "renderspu.h" 13 14 #include "cr_extstring.h" … … 128 129 } 129 130 131 static ContextInfo * renderspuCreateContextInternal(const char *dpyName, GLint visBits, ContextInfo * sharedContext) 132 { 133 ContextInfo *context; 134 VisualInfo *visual; 135 136 if (!dpyName || crStrlen(render_spu.display_string)>0) 137 dpyName = render_spu.display_string; 138 139 visual = renderspuFindVisual(dpyName, visBits); 140 if (!visual) 141 return NULL; 142 143 context = (ContextInfo *) crCalloc(sizeof(ContextInfo)); 144 if (!context) 145 return NULL; 146 context->BltInfo.Base.id = render_spu.context_id; 147 context->shared = sharedContext; 148 if (!renderspu_SystemCreateContext(visual, context, sharedContext)) 149 return NULL; 150 151 crHashtableAdd(render_spu.contextTable, render_spu.context_id, context); 152 render_spu.context_id++; 153 154 context->BltInfo.Base.visualBits = visual->visAttribs; 155 /* 156 crDebug("Render SPU: CreateContext(%s, 0x%x) returning %d", 157 dpyName, visBits, context->BltInfo.Base.id); 158 */ 159 160 return context; 161 } 162 130 163 /* 131 164 * Context functions … … 136 169 { 137 170 ContextInfo *context, *sharedContext = NULL; 138 VisualInfo *visual; 139 140 if (shareCtx > 0) { 171 bool fHasShared; 172 173 if (shareCtx > 0) 174 fHasShared = true; 175 else if (shareCtx == -1) 176 { 177 shareCtx = 0; 178 fHasShared = true; 179 } 180 else 181 fHasShared = false; 182 183 if (fHasShared) { 141 184 sharedContext 142 185 = (ContextInfo *) crHashtableSearch(render_spu.contextTable, shareCtx); 143 } 144 145 if (!dpyName || crStrlen(render_spu.display_string)>0) 146 dpyName = render_spu.display_string; 147 148 visual = renderspuFindVisual(dpyName, visBits); 149 if (!visual) 150 return -1; 151 152 context = (ContextInfo *) crCalloc(sizeof(ContextInfo)); 153 if (!context) 154 return -1; 155 context->id = render_spu.context_id; 156 context->shared = sharedContext; 157 if (!renderspu_SystemCreateContext(visual, context, sharedContext)) 158 return -1; 159 160 crHashtableAdd(render_spu.contextTable, render_spu.context_id, context); 161 render_spu.context_id++; 162 163 /* 164 crDebug("Render SPU: CreateContext(%s, 0x%x) returning %d", 165 dpyName, visBits, context->id); 166 */ 167 168 return context->id; 169 } 170 186 CRASSERT(sharedContext); 187 } 188 189 context = renderspuCreateContextInternal(dpyName, visBits, sharedContext); 190 if (context) 191 return context->BltInfo.Base.id; 192 return -1; 193 } 171 194 172 195 static void RENDER_APIENTRY … … 306 329 307 330 crHashtableAdd(render_spu.windowTable, render_spu.window_id, window); 308 window-> id = render_spu.window_id;331 window->BltInfo.Base.id = render_spu.window_id; 309 332 render_spu.window_id++; 310 333 311 334 window->x = render_spu.defaultX; 312 335 window->y = render_spu.defaultY; 313 window-> width = render_spu.defaultWidth;314 window-> height = render_spu.defaultHeight;336 window->BltInfo.width = render_spu.defaultWidth; 337 window->BltInfo.height = render_spu.defaultHeight; 315 338 316 339 if (render_spu.force_hidden_wdn_create … … 318 341 showIt = 0; 319 342 else 320 showIt = window-> id > 0;343 showIt = window->BltInfo.Base.id > 0; 321 344 322 345 /* Set window->title, replacing %i with the window ID number */ … … 328 351 for (i = 0; render_spu.window_title[i] != '%'; i++) 329 352 window->title[i] = render_spu.window_title[i]; 330 k = sprintf(window->title + i, "%d", window-> id);353 k = sprintf(window->title + i, "%d", window->BltInfo.Base.id); 331 354 CRASSERT(k < 10); 332 355 i++; /* skip the 'i' after the '%' */ … … 341 364 342 365 /* 343 crDebug("Render SPU: Creating window (visBits=0x%x, id=%d)", visBits, window-> id);366 crDebug("Render SPU: Creating window (visBits=0x%x, id=%d)", visBits, window->BltInfo.Base.id); 344 367 */ 345 368 /* Have GLX/WGL/AGL create the window */ … … 353 376 CRASSERT(window->visual == visual); 354 377 355 return window->id; 378 window->BltInfo.Base.visualBits = visual->visAttribs; 379 380 return window->BltInfo.Base.id; 356 381 } 357 382 … … 364 389 if (pCtx->currentWindow==pWindow) 365 390 { 366 renderspuMakeCurrent(0, 0, pCtx-> id);391 renderspuMakeCurrent(0, 0, pCtx->BltInfo.Base.id); 367 392 pCtx->currentWindow=0; 368 393 } … … 396 421 if (pNewCtx!=pOldCtx) 397 422 { 398 renderspuMakeCurrent(pOldCtx&&pOldCtx->currentWindow ? pOldCtx->currentWindow-> id:0, 0,399 pOldCtx ? pOldCtx-> id:0);423 renderspuMakeCurrent(pOldCtx&&pOldCtx->currentWindow ? pOldCtx->currentWindow->BltInfo.Base.id:0, 0, 424 pOldCtx ? pOldCtx->BltInfo.Base.id:0); 400 425 } 401 426 } … … 415 440 if (window) { 416 441 renderspu_SystemWindowSize( window, w, h ); 442 window->BltInfo.width = w; 443 window->BltInfo.height = h; 417 444 } 418 445 else { … … 475 502 } 476 503 504 static void RENDER_APIENTRY 505 renderspuVBoxPresentComposition( GLint win, struct VBOXVR_SCR_COMPOSITOR * pCompositor, struct VBOXVR_SCR_COMPOSITOR_ENTRY *pChangedEntry ) 506 { 507 WindowInfo *window; 508 CRASSERT(win >= 0); 509 window = (WindowInfo *) crHashtableSearch(render_spu.windowTable, win); 510 if (window) { 511 renderspu_SystemVBoxPresentComposition(window, pCompositor, pChangedEntry); 512 } 513 else { 514 crDebug("Render SPU: Attempt to PresentComposition for invalid window (%d)", win); 515 } 516 } 517 518 void renderspuVBoxCompositorBlitStretched ( struct VBOXVR_SCR_COMPOSITOR * pCompositor, PCR_BLITTER pBlitter, GLfloat scaleX, GLfloat scaleY) 519 { 520 VBOXVR_SCR_COMPOSITOR_ITERATOR CIter; 521 PVBOXVR_SCR_COMPOSITOR_ENTRY pEntry; 522 CrVrScrCompositorIterInit(pCompositor, &CIter); 523 while ((pEntry = CrVrScrCompositorIterNext(&CIter)) != NULL) 524 { 525 uint32_t cRegions; 526 const RTRECT *paSrcRegions, *paDstRegions; 527 int rc = CrVrScrCompositorEntryRegionsGet(pCompositor, pEntry, &cRegions, &paSrcRegions, &paDstRegions); 528 if (RT_SUCCESS(rc)) 529 { 530 uint32_t i; 531 for (i = 0; i < pEntry->cRects; ++i) 532 { 533 RTRECT DstRect; 534 DstRect.xLeft = paDstRegions[i].xLeft * scaleX; 535 DstRect.yTop = paDstRegions[i].yTop * scaleY; 536 DstRect.xRight = paDstRegions[i].xRight * scaleX; 537 DstRect.yBottom = paDstRegions[i].yBottom * scaleY; 538 CrBltBlitTexMural(pBlitter, &pEntry->Tex, &paSrcRegions[i], &DstRect, 1, CRBLT_F_LINEAR); 539 } 540 } 541 else 542 { 543 crWarning("BlitStretched: CrVrScrCompositorEntryRegionsGet failed rc %d", rc); 544 } 545 } 546 } 547 548 void renderspuVBoxCompositorBlit ( struct VBOXVR_SCR_COMPOSITOR * pCompositor, PCR_BLITTER pBlitter) 549 { 550 VBOXVR_SCR_COMPOSITOR_ITERATOR CIter; 551 PVBOXVR_SCR_COMPOSITOR_ENTRY pEntry; 552 CrVrScrCompositorIterInit(pCompositor, &CIter); 553 while ((pEntry = CrVrScrCompositorIterNext(&CIter)) != NULL) 554 { 555 uint32_t cRegions; 556 const RTRECT *paSrcRegions, *paDstRegions; 557 int rc = CrVrScrCompositorEntryRegionsGet(pCompositor, pEntry, &cRegions, &paSrcRegions, &paDstRegions); 558 if (RT_SUCCESS(rc)) 559 { 560 CrBltBlitTexMural(pBlitter, &pEntry->Tex, paSrcRegions, paDstRegions, cRegions, CRBLT_F_LINEAR); 561 } 562 else 563 { 564 crWarning("Blit: CrVrScrCompositorEntryRegionsGet failed rc %d", rc); 565 } 566 } 567 } 568 569 PCR_BLITTER renderspuVBoxPresentBlitterGet( WindowInfo *window ) 570 { 571 PCR_BLITTER pBlitter = window->pBlitter; 572 if (!pBlitter) 573 { 574 if (render_spu.blitterTable) 575 { 576 pBlitter = (PCR_BLITTER)crHashtableSearch(render_spu.blitterTable, window->visual->visAttribs); 577 } 578 579 if (!pBlitter) 580 { 581 int rc; 582 CR_BLITTER_CONTEXT ctx; 583 pBlitter = (PCR_BLITTER)crCalloc(sizeof (*pBlitter)); 584 if (!pBlitter) 585 { 586 crWarning("failed to allocate blitter"); 587 return NULL; 588 } 589 590 /* @todo: this is the assumption that crserverlib uses context 1 as a default one 591 * need to do it in a more proper way */ 592 ctx.Base.id = 1; 593 ctx.Base.visualBits = window->visual->visAttribs; 594 rc = CrBltInit(pBlitter, &ctx, true, render_spu.blitterDispatch); 595 if (!RT_SUCCESS(rc)) 596 { 597 crWarning("CrBltInit failed, rc %d", rc); 598 crFree(pBlitter); 599 return NULL; 600 } 601 } 602 603 Assert(pBlitter); 604 window->pBlitter = pBlitter; 605 } 606 607 CrBltMuralSetCurrent(pBlitter, &window->BltInfo); 608 return pBlitter; 609 } 610 611 int renderspuVBoxPresentBlitterEnter( PCR_BLITTER pBlitter ) 612 { 613 int rc; 614 GET_CONTEXT(pCtx); 615 616 if (!pCtx) 617 { 618 crWarning("renderspuVBoxPresentBlitterEnter: no current context!"); 619 return VERR_INVALID_STATE; 620 } 621 622 if (!pCtx->currentWindow) 623 { 624 crWarning("renderspuVBoxPresentBlitterEnter: no current window!"); 625 return VERR_INVALID_STATE; 626 } 627 628 rc = CrBltEnter(pBlitter, &pCtx->BltInfo, &pCtx->currentWindow->BltInfo); 629 if (!RT_SUCCESS(rc)) 630 { 631 crWarning("CrBltEnter failed, rc %d", rc); 632 return rc; 633 } 634 return VINF_SUCCESS; 635 } 636 637 PCR_BLITTER renderspuVBoxPresentBlitterGetAndEnter( WindowInfo *window ) 638 { 639 PCR_BLITTER pBlitter = renderspuVBoxPresentBlitterGet(window); 640 if (pBlitter) 641 { 642 int rc = renderspuVBoxPresentBlitterEnter(pBlitter); 643 if (RT_SUCCESS(rc)) 644 { 645 return pBlitter; 646 } 647 } 648 return NULL; 649 } 650 651 void renderspuVBoxPresentCompositionGeneric( WindowInfo *window, struct VBOXVR_SCR_COMPOSITOR * pCompositor, struct VBOXVR_SCR_COMPOSITOR_ENTRY *pChangedEntry ) 652 { 653 PCR_BLITTER pBlitter = renderspuVBoxPresentBlitterGetAndEnter(window); 654 if (!pBlitter) 655 return; 656 657 renderspuVBoxCompositorBlit(pCompositor, pBlitter); 658 659 CrBltPresent(pBlitter); 660 661 CrBltLeave(pBlitter); 662 } 477 663 478 664 /* … … 1083 1269 } 1084 1270 1085 #if defined(DARWIN)1086 # ifdef VBOX_WITH_COCOA_QT1087 void renderspuFlush()1088 {1089 renderspu_SystemFlush();1090 }1091 1092 void renderspuFinish()1093 {1094 renderspu_SystemFinish();1095 }1096 1097 void renderspuBindFramebufferEXT(GLenum target, GLuint framebuffer)1098 {1099 renderspu_SystemBindFramebufferEXT(target, framebuffer);1100 }1101 1102 void renderspuCopyPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum type)1103 {1104 renderspu_SystemCopyPixels(x, y, width, height, type);1105 }1106 1107 void renderspuGetIntegerv(GLenum pname, GLint * params)1108 {1109 renderspu_SystemGetIntegerv(pname, params);1110 }1111 1112 void renderspuDrawBuffer(GLenum mode)1113 {1114 renderspu_SystemDrawBuffer(mode);1115 }1116 1117 void renderspuReadBuffer(GLenum mode)1118 {1119 renderspu_SystemReadBuffer(mode);1120 }1121 # endif1122 #endif1123 1124 1271 #define FILLIN( NAME, FUNC ) \ 1125 1272 table[i].name = crStrdup(NAME); \ … … 1158 1305 FILLIN( "GetChromiumParametervCR", renderspuGetChromiumParametervCR ); 1159 1306 FILLIN( "GetString", renderspuGetString ); 1160 #if defined(DARWIN) 1161 # ifdef VBOX_WITH_COCOA_QT 1162 FILLIN( "Flush", renderspuFlush ); 1163 FILLIN( "Finish", renderspuFinish ); 1164 FILLIN( "BindFramebufferEXT", renderspuBindFramebufferEXT ); 1165 FILLIN( "CopyPixels", renderspuCopyPixels ); 1166 FILLIN( "GetIntegerv", renderspuGetIntegerv ); 1167 FILLIN( "ReadBuffer", renderspuReadBuffer ); 1168 FILLIN( "DrawBuffer", renderspuDrawBuffer ); 1169 # endif 1170 #endif 1307 FILLIN( "VBoxPresentComposition", renderspuVBoxPresentComposition ); 1308 1171 1309 return i; 1172 1310 } -
trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu.h
r43748 r44740 28 28 #include "cr_hash.h" 29 29 #include "cr_server.h" 30 #include "cr_blitter.h" 30 31 31 32 #include <iprt/cdefs.h> … … 79 80 typedef struct { 80 81 int x, y; 81 int width, height; 82 int id; /**< integer window ID */ 82 // int width, height; 83 // int id; /**< integer window ID */ 84 CR_BLITTER_WINDOW BltInfo; 85 83 86 VisualInfo *visual; 84 87 GLboolean mapPending; … … 86 89 GLboolean everCurrent; /**< has this window ever been bound? */ 87 90 char *title; 91 92 PCR_BLITTER pBlitter; 88 93 #if defined(WINDOWS) 89 94 HDC nativeWindow; /**< for render_to_app_window */ … … 125 130 */ 126 131 typedef struct _ContextInfo { 127 int id; /**< integer context ID */ 132 // int id; /**< integer context ID */ 133 CR_BLITTER_CONTEXT BltInfo; 128 134 VisualInfo *visual; 129 135 GLboolean everCurrent; … … 218 224 CRConnection **swap_conns; 219 225 226 SPUDispatchTable *blitterDispatch; 227 CRHashTable *blitterTable; 228 220 229 #ifdef USE_OSMESA 221 230 /** Off screen rendering hooks. */ … … 293 302 294 303 #define GET_CONTEXT(T) ContextInfo *T = GET_CONTEXT_VAL() 304 305 295 306 296 307 extern void renderspuSetVBoxConfiguration( RenderSPU *spu ); … … 311 322 #ifdef RT_OS_DARWIN 312 323 extern void renderspu_SystemSetRootVisibleRegion(GLint cRects, GLint *pRects); 313 # ifdef VBOX_WITH_COCOA_QT314 extern void renderspu_SystemFlush();315 extern void renderspu_SystemFinish();316 extern void renderspu_SystemBindFramebufferEXT(GLenum target, GLuint framebuffer);317 extern void renderspu_SystemCopyPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum type);318 extern void renderspu_SystemGetIntegerv(GLenum pname, GLint *params);319 extern void renderspu_SystemReadBuffer(GLenum mode);320 extern void renderspu_SystemDrawBuffer(GLenum mode);321 # endif322 324 #endif 323 325 extern void renderspu_SystemShowWindow( WindowInfo *window, GLboolean showIt ); … … 325 327 extern void renderspu_SystemSwapBuffers( WindowInfo *window, GLint flags ); 326 328 extern void renderspu_SystemReparentWindow(WindowInfo *window); 329 extern void renderspu_SystemVBoxPresentComposition( WindowInfo *window, struct VBOXVR_SCR_COMPOSITOR * pCompositor, struct VBOXVR_SCR_COMPOSITOR_ENTRY *pChangedEntry ); 327 330 extern void renderspu_GCWindow(void); 328 331 extern int renderspuCreateFunctions( SPUNamedFunctionTable table[] ); 332 extern void renderspuVBoxPresentCompositionGeneric( WindowInfo *window, struct VBOXVR_SCR_COMPOSITOR * pCompositor, struct VBOXVR_SCR_COMPOSITOR_ENTRY *pChangedEntry ); 333 extern PCR_BLITTER renderspuVBoxPresentBlitterGet( WindowInfo *window ); 334 extern int renderspuVBoxPresentBlitterEnter( PCR_BLITTER pBlitter ); 335 extern PCR_BLITTER renderspuVBoxPresentBlitterGetAndEnter( WindowInfo *window ); 336 extern void renderspuVBoxCompositorBlit ( struct VBOXVR_SCR_COMPOSITOR * pCompositor, PCR_BLITTER pBlitter); 337 extern void renderspuVBoxCompositorBlitStretched ( struct VBOXVR_SCR_COMPOSITOR * pCompositor, PCR_BLITTER pBlitter, GLfloat scaleX, GLfloat scaleY); 329 338 330 339 extern GLint RENDER_APIENTRY renderspuWindowCreate( const char *dpyName, GLint visBits ); -
trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu_agl.c
r33540 r44740 341 341 return render_spu.ws.aglSetCurrentContext( NULL ); 342 342 343 /* DEBUG_MSG_POETZSCH (("WindowAttachContext %d\n", wi-> id));*/343 /* DEBUG_MSG_POETZSCH (("WindowAttachContext %d\n", wi->BltInfo.Base.id));*/ 344 344 345 345 /* Flush old context first */ … … 350 350 if (wi->bufferName == -1) 351 351 { 352 DEBUG_MSG_POETZSCH (("WindowAttachContext: create context %d\n", wi-> id));352 DEBUG_MSG_POETZSCH (("WindowAttachContext: create context %d\n", wi->BltInfo.Base.id)); 353 353 /* Use the same visual bits as those in the context structure */ 354 354 AGLPixelFormat pix; … … 520 520 CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU (renderspu_SystemWindowSize): SendEventToEventTarget Failed"); 521 521 522 DEBUG_MSG_POETZSCH (("Size %d visible %d\n", window-> id, IsWindowVisible (window->window)));522 DEBUG_MSG_POETZSCH (("Size %d visible %d\n", window->BltInfo.Base.id, IsWindowVisible (window->window))); 523 523 /* save the new size */ 524 window-> width = w;525 window-> height = h;524 window->BltInfo.width = w; 525 window->BltInfo.height = h; 526 526 } 527 527 … … 607 607 } 608 608 609 void renderspu_SystemVBoxPresentComposition( WindowInfo *window, struct VBOXVR_SCR_COMPOSITOR * pCompositor, struct VBOXVR_SCR_COMPOSITOR_ENTRY *pChangedEntry ) 610 { 611 renderspuVBoxPresentCompositionGeneric(window, pCompositor, pChangedEntry); 612 } 613 609 614 void 610 615 renderspu_SystemMakeCurrent(WindowInfo *window, GLint nativeWindow, … … 612 617 { 613 618 Boolean result; 614 /* DEBUG_MSG_POETZSCH (("makecurrent %d: \n", window-> id));*/619 /* DEBUG_MSG_POETZSCH (("makecurrent %d: \n", window->BltInfo.Base.id));*/ 615 620 616 621 CRASSERT(render_spu.ws.aglSetCurrentContext); … … 670 675 671 676 RTSemFastMutexRequest(render_spu.syncMutex); 672 // DEBUG_MSG_POETZSCH (("Swapped %d context %x visible: %d\n", window-> id, context->context, IsWindowVisible (window->window)));677 // DEBUG_MSG_POETZSCH (("Swapped %d context %x visible: %d\n", window->BltInfo.Base.id, context->context, IsWindowVisible (window->window))); 673 678 if (context->visual && 674 679 context->visual->visAttribs & CR_DOUBLE_BIT) … … 778 783 SetRectRgn(rgn, 779 784 window->x, window->y, 780 window->x + window-> width,781 window->y + window-> height);785 window->x + window->BltInfo.width, 786 window->y + window->BltInfo.height); 782 787 SectRgn(render_spu.hRootVisibleRegion, rgn, rgn); 783 788 /* Because the clipping is done in the coordinate space of the OpenGL … … 791 796 * region with the size of the target window. This covers all 792 797 * needed/possible space. */ 793 SetRectRgn(rgn, 0, 0, window-> width, window->height);798 SetRectRgn(rgn, 0, 0, window->BltInfo.width, window->BltInfo.height); 794 799 } 795 800 … … 839 844 windowRect.left = window->x; 840 845 windowRect.top = window->y; 841 windowRect.right = window->x + window-> width;842 windowRect.bottom = window->y + window-> height;846 windowRect.right = window->x + window->BltInfo.width; 847 windowRect.bottom = window->y + window->BltInfo.height; 843 848 844 849 status = CreateNewWindow(winClass, winAttr, &windowRect, &window->window); … … 849 854 title_string = CFStringCreateWithCStringNoCopy(NULL, window->title, 850 855 kCFStringEncodingMacRoman, NULL); 851 SetWindowTitleWithCFString(window-> window, title_string);856 SetWindowTitleWithCFString(window->BltInfo.window, title_string); 852 857 CFRelease(title_string); 853 858 … … 874 879 875 880 crDebug("Render SPU (renderspu_SystemVBoxCreateWindow): actual window (x, y, width, height): %d, %d, %d, %d", 876 window->x, window->y, window-> width, window->height);881 window->x, window->y, window->BltInfo.width, window->BltInfo.height); 877 882 878 883 return GL_TRUE; -
trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu_cocoa.c
r44529 r44740 152 152 } 153 153 154 void renderspu_SystemVBoxPresentComposition( WindowInfo *window, struct VBOXVR_SCR_COMPOSITOR * pCompositor, struct VBOXVR_SCR_COMPOSITOR_ENTRY *pChangedEntry ) 155 { 156 cocoaViewPresentComposition(window->window, pCompositor, pChangedEntry); 157 } 158 154 159 void renderspu_SystemMakeCurrent(WindowInfo *pWinInfo, GLint nativeWindow, ContextInfo *pCtxInfo) 155 160 { … … 184 189 { 185 190 } 186 187 void renderspu_SystemFlush()188 {189 cocoaFlush();190 }191 192 void renderspu_SystemFinish()193 {194 cocoaFinish();195 }196 197 void renderspu_SystemBindFramebufferEXT(GLenum target, GLuint framebuffer)198 {199 cocoaBindFramebufferEXT(target, framebuffer);200 }201 202 void renderspu_SystemCopyPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum type)203 {204 cocoaCopyPixels(x, y, width, height, type);205 }206 207 void renderspu_SystemGetIntegerv(GLenum pname, GLint * params)208 {209 cocoaGetIntegerv(pname, params);210 }211 212 void renderspu_SystemReadBuffer(GLenum mode)213 {214 cocoaReadBuffer(mode);215 }216 217 void renderspu_SystemDrawBuffer(GLenum mode)218 {219 cocoaDrawBuffer(mode);220 }221 -
trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu_cocoa_helper.h
r44528 r44740 22 22 #include <VBox/VBoxCocoa.h> 23 23 #include <OpenGL/OpenGL.h> 24 #include <cr_vreg.h> 24 25 25 26 RT_C_DECLS_BEGIN … … 44 45 void cocoaViewMakeCurrentContext(NativeNSViewRef pView, NativeNSOpenGLContextRef pCtx); 45 46 void cocoaViewSetVisibleRegion(NativeNSViewRef pView, GLint cRects, GLint* paRects); 46 47 /* OpenGL wrapper */ 48 void cocoaFlush(void); 49 void cocoaFinish(void); 50 void cocoaBindFramebufferEXT(GLenum target, GLuint framebuffer); 51 void cocoaCopyPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum type); 52 void cocoaGetIntegerv(GLenum pname, GLint *params); 53 void cocoaReadBuffer(GLenum mode); 54 void cocoaDrawBuffer(GLenum mode); 47 void cocoaViewPresentComposition(NativeNSViewRef pView, struct VBOXVR_SCR_COMPOSITOR * pCompositor, struct VBOXVR_SCR_COMPOSITOR_ENTRY *pChangedEntry); 55 48 56 49 RT_C_DECLS_END -
trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu_cocoa_helper.m
r44528 r44740 26 26 #include <iprt/mem.h> 27 27 #include <iprt/time.h> 28 29 #include <cr_vreg.h> 28 30 29 31 /** @page pg_opengl_cocoa OpenGL - Cocoa Window System Helper … … 159 161 } \ 160 162 while(0); 163 164 static NSOpenGLContext *g_pVBoxCurrentContext = NULL; 165 #ifdef DEBUG 166 static NSView *g_pVBoxCurrentView = NULL; 167 #endif 168 169 static NSOpenGLContext * vboxCtxGetCurrent() 170 { 171 #ifdef DEBUG 172 if (g_pVBoxCurrentContext) 173 { 174 Assert(g_pVBoxCurrentView == [g_pVBoxCurrentContext view]); 175 } 176 #endif 177 return g_pVBoxCurrentContext; 178 } 179 180 static void vboxCtxSetCurrent(NSOpenGLContext * pCtx) 181 { 182 g_pVBoxCurrentContext = pCtx; 183 if (pCtx) 184 { 185 #ifdef DEBUG 186 g_pVBoxCurrentView = [g_pVBoxCurrentContext view]; 187 #endif 188 [pCtx makeCurrentContext]; 189 } 190 else 191 { 192 #ifdef DEBUG 193 g_pVBoxCurrentView = NULL; 194 #endif 195 [NSOpenGLContext clearCurrentContext]; 196 } 197 } 161 198 162 199 /** Custom OpenGL context class. … … 194 231 RTTHREAD mThread; 195 232 196 #ifdef FBO197 233 GLuint m_FBOId; 198 /* FBO handling */199 GLuint m_FBOTexBackId;200 GLuint m_FBOTexFrontId;201 GLuint m_FBOAttBackId;202 GLuint m_FBOAttFrontId;203 GLuint m_FBODepthStencilPackedId;204 NSSize m_FBOTexSize;205 206 bool m_fFrontDrawing;207 #endif208 234 209 235 /** The corresponding dock tile view of this OpenGL view & all helper … … 211 237 DockOverlayView *m_DockTileView; 212 238 213 GLuint m_FBOThumbId;214 GLuint m_FBOThumbTexId;215 239 GLfloat m_FBOThumbScaleX; 216 240 GLfloat m_FBOThumbScaleY; … … 227 251 /** This is necessary for clipping on the root window */ 228 252 NSPoint m_RootShift; 253 254 PVBOXVR_SCR_COMPOSITOR m_pCompositor; 255 bool m_fNeedViewportUpdate; 256 bool m_fNeedCtxUpdate; 229 257 } 230 258 - (id)initWithFrame:(NSRect)frame thread:(RTTHREAD)aThread parentView:(NSView*)pParentView; … … 241 269 - (void)setSize:(NSSize)size; 242 270 - (NSSize)size; 243 - (void)updateViewport ;271 - (void)updateViewportCS; 244 272 - (void)reshape; 245 273 246 - (void)createFBO; 247 - (void)deleteFBO; 248 249 - (bool)isCurrentFBO; 250 - (void)updateFBO; 274 - (void)createDockTile; 275 - (void)deleteDockTile; 276 251 277 - (void)makeCurrentFBO; 252 278 - (void)swapFBO; 253 - (void)flushFBO;254 - (void)stateInfo:(GLenum)pname withParams:(GLint*)params;255 - (void)finishFBO;256 - (void)bindFBO:(GLenum)target withFrameBuffer:(GLuint)framebuffer;257 279 - (void)tryDraw; 258 - (void)renderFBOToView; 259 - (void)renderFBOToDockTile; 280 - (void)vboxPresent; 281 - (void)vboxPresentCS; 282 - (void)vboxPresentToDockTileCS; 283 - (void)vboxPresentToViewCS; 284 - (void)presentComposition:(PVBOXVR_SCR_COMPOSITOR)pCompositor withChangedEntry:(PVBOXVR_SCR_COMPOSITOR_ENTRY)pChangedEntry; 285 - (void)performSelectorMakingCurrent:(NSOpenGLContext*)pCtx idSel:(SEL)selector; 260 286 261 287 - (void)clearVisibleRegions; … … 466 492 DEBUG_MSG(("OCTX(%p): setView: new view: %p\n", (void*)self, (void*)view)); 467 493 468 #if def FBO494 #if 1 /* def FBO */ 469 495 m_pView = view;; 470 496 #else … … 475 501 -(NSView*)view 476 502 { 477 #if def FBO503 #if 1 /* def FBO */ 478 504 return m_pView; 479 505 #else … … 646 672 m_pSharedGLCtx = nil; 647 673 mThread = aThread; 648 #ifdef FBO649 674 m_FBOId = 0; 650 m_FBOTexBackId = 0;651 m_FBOTexFrontId = 0;652 m_FBOAttBackId = GL_COLOR_ATTACHMENT0_EXT;653 m_FBOAttFrontId = GL_COLOR_ATTACHMENT1_EXT;654 m_FBODepthStencilPackedId = 0;655 m_FBOTexSize = NSZeroSize;656 #endif657 m_FBOThumbId = 0;658 m_FBOThumbTexId = 0;659 675 m_cClipRects = 0; 660 676 m_paClipRects = NULL; … … 662 678 m_Size = NSMakeSize(1, 1); 663 679 m_RootShift = NSZeroPoint; 664 680 m_pCompositor = NULL; 681 m_fNeedViewportUpdate = true; 682 m_fNeedCtxUpdate = true; 683 665 684 self = [super initWithFrame:frame]; 666 685 … … 672 691 - (void)cleanupData 673 692 { 674 [self delete FBO];675 693 [self deleteDockTile]; 694 676 695 if (m_pGLCtx) 677 696 { … … 768 787 m_Size = size; 769 788 770 #ifdef FBO771 if (m_FBOId)772 789 { 773 790 DEBUG_MSG(("OVIW(%p): setSize: new size: %dx%d\n", (void*)self, (int)size.width, (int)size.height)); 774 791 [self reshape]; 775 [self updateFBO];792 [self createDockTile]; 776 793 /* have to rebind GL_TEXTURE_RECTANGLE_ARB as m_FBOTexId could be changed in updateFBO call */ 777 [self updateViewport]; 778 } 779 else 780 #endif 781 { 782 DEBUG_MSG(("OVIW(%p): setSize (no FBO): new size: %dx%d\n", (void*)self, (int)size.width, (int)size.height)); 783 [self reshape]; 784 [self updateFBO]; 794 m_fNeedViewportUpdate = true; 795 m_fNeedCtxUpdate = true; 785 796 } 786 797 } … … 791 802 } 792 803 793 - (void)updateViewport 804 - (void)updateViewportCS 794 805 { 795 806 NSRect r; … … 797 808 DEBUG_MSG(("OVIW(%p): updateViewport\n", (void*)self)); 798 809 799 #ifdef FBO800 if (m_pSharedGLCtx)801 810 { 802 811 /* Update the viewport for our OpenGL view */ 803 DEBUG_MSG(("OVIW(%p): makeCurrent (shared) %p\n", (void*)self, (void*)m_pSharedGLCtx));804 [m_pSharedGLCtx makeCurrentContext];805 812 [m_pSharedGLCtx update]; 806 813 … … 821 828 /* Clear background to transparent */ 822 829 glClearColor(0.0f, 0.0f, 0.0f, 0.0f); 823 824 DEBUG_MSG(("OVIW(%p): makeCurrent (non shared) %p\n", (void*)self, (void*)m_pGLCtx)); 825 [m_pGLCtx makeCurrentContext]; 826 } 827 #endif 830 } 828 831 } 829 832 … … 889 892 890 893 /* Make sure the context is updated according */ 891 [self updateViewport]; 892 } 893 894 - (void)createFBO 895 { 896 GLint oldTexId = 0; 897 GLint oldFBId = 0; 898 NSView *pDockScreen = nil; 899 GLint maxTexSize = 0; 900 GLfloat imageAspectRatio = 0; 901 GLint filter = GL_NEAREST; 902 903 [self deleteFBO]; 904 905 #ifdef FBO 906 DEBUG_MSG(("OVIW(%p): createFBO\n", (void*)self)); 907 908 glGetIntegerv(GL_TEXTURE_BINDING_RECTANGLE_ARB, &oldTexId); 909 glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &oldFBId); 910 911 /* If not previously setup generate IDs for FBO and its associated texture. */ 912 if (!m_FBOId) 913 { 914 /* Make sure the framebuffer extension is supported */ 915 const GLubyte* strExt; 916 GLboolean isFBO; 917 /* Get the extension name string. It is a space-delimited list of the 918 * OpenGL extensions that are supported by the current renderer. */ 919 strExt = glGetString(GL_EXTENSIONS); 920 isFBO = gluCheckExtension((const GLubyte*)"GL_EXT_framebuffer_object", strExt); 921 if (!isFBO) 922 { 923 DEBUG_MSG(("Your system does not support the GL_EXT_framebuffer_object extension\n")); 924 } 925 isFBO = gluCheckExtension((const GLubyte*)"GL_EXT_framebuffer_blit", strExt); 926 if (!isFBO) 927 { 928 DEBUG_MSG(("Your system does not support the GL_EXT_framebuffer_blit extension\n")); 929 } 930 931 /* Create FBO object */ 932 glGenFramebuffersEXT(1, &m_FBOId); 933 /* & the texture as well the depth/stencil render buffer */ 934 glGenTextures(1, &m_FBOTexBackId); 935 glGenTextures(1, &m_FBOTexFrontId); 936 DEBUG_MSG(("OVIW(%p): gen numbers: FBOId=%d FBOTexBackId=%d FBOTexFrontId=%d\n", (void*)self, m_FBOId, m_FBOTexBackId, m_FBOTexFrontId)); 937 938 glGenRenderbuffersEXT(1, &m_FBODepthStencilPackedId); 939 } 940 941 m_FBOTexSize = m_Size; 942 /* Bind to FBO */ 943 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_FBOId); 944 945 /* 946 glEnable(GL_TEXTURE_RECTANGLE_ARB); 947 */ 948 949 imageAspectRatio = m_FBOTexSize.width / m_FBOTexSize.height; 950 951 /* Sanity check against maximum OpenGL texture size. If bigger adjust to 952 * maximum possible size while maintain the aspect ratio. */ 953 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTexSize); 954 if (m_FBOTexSize.width > maxTexSize || m_FBOTexSize.height > maxTexSize) 955 { 956 filter = GL_LINEAR; 957 if (imageAspectRatio > 1) 958 { 959 m_FBOTexSize.width = maxTexSize; 960 m_FBOTexSize.height = maxTexSize / imageAspectRatio; 961 } 962 else 963 { 964 m_FBOTexSize.width = maxTexSize * imageAspectRatio; 965 m_FBOTexSize.height = maxTexSize; 966 } 967 } 968 969 DEBUG_MSG(("OVIW(%p): tex size is: %dx%d\n", (void*)self, (int)m_FBOTexSize.width, (int)m_FBOTexSize.height)); 970 971 /* Initialize FBO Textures */ 972 /* The GPUs like the GL_BGRA / GL_UNSIGNED_INT_8_8_8_8_REV combination 973 * others are also valid, but might incur a costly software translation. */ 974 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, m_FBOTexBackId); 975 glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGB, m_FBOTexSize.width, m_FBOTexSize.height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL); 976 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, m_FBOTexFrontId); 977 glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGB, m_FBOTexSize.width, m_FBOTexSize.height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL); 978 979 /* Now attach the textures to the FBO as its color destinations */ 980 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, m_FBOAttBackId, GL_TEXTURE_RECTANGLE_ARB, m_FBOTexBackId, 0); 981 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, m_FBOAttFrontId, GL_TEXTURE_RECTANGLE_ARB, m_FBOTexFrontId, 0); 982 983 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, m_FBODepthStencilPackedId); 984 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, m_FBOTexSize.width, m_FBOTexSize.height); 985 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_FBODepthStencilPackedId); 986 987 /* Bind the FBOs for reading and drawing. */ 988 glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, m_FBOId); 989 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, m_FBOId); 990 991 /* Explicitly clear the textures otherwise they would contain old memory stuff. */ 992 glDrawBuffer(m_FBOAttBackId); 993 glClear(GL_COLOR_BUFFER_BIT); 994 glDrawBuffer(m_FBOAttFrontId); 995 glClear(GL_COLOR_BUFFER_BIT); 996 997 /* Now initially reading/drawing to the back buffer. */ 998 glReadBuffer(m_FBOAttBackId); 999 glDrawBuffer(m_FBOAttBackId); 1000 1001 /* Make sure the FBO was created successfully. */ 1002 if (GL_FRAMEBUFFER_COMPLETE_EXT != glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT)) 1003 DEBUG_MSG(("OVIW(%p): Framebuffer Object creation or update failed!\n", (void*)self)); 1004 1005 // glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0); 1006 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, oldTexId); 1007 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, (GLuint)oldFBId ? (GLuint)oldFBId : m_FBOId); 1008 1009 /* Is there a dock tile preview enabled in the GUI? If so setup a 894 /* [self updateViewport]; */ 895 if (m_pSharedGLCtx) 896 { 897 [self performSelectorMakingCurrent:m_pSharedGLCtx idSel:@selector(updateViewportCS)]; 898 } 899 } 900 901 - (void)createDockTile 902 { 903 NSView *pDockScreen = nil; 904 [self deleteDockTile]; 905 906 /* Is there a dock tile preview enabled in the GUI? If so setup a 1010 907 * additional thumbnail view for the dock tile. */ 1011 pDockScreen = [self dockTileScreen]; 1012 if (pDockScreen) 1013 { 1014 if (!m_FBOThumbId) 1015 { 1016 glGenFramebuffersEXT(1, &m_FBOThumbId); 1017 glGenTextures(1, &m_FBOThumbTexId); 1018 } 1019 1020 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_FBOThumbId); 1021 /* Initialize FBO Texture */ 1022 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, m_FBOThumbTexId); 1023 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 1024 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 1025 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP); 1026 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP); 1027 1028 /* The GPUs like the GL_BGRA / GL_UNSIGNED_INT_8_8_8_8_REV combination 1029 * others are also valid, but might incur a costly software translation. */ 1030 glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGB, m_FBOTexSize.width * m_FBOThumbScaleX, m_FBOTexSize.height * m_FBOThumbScaleY, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL); 1031 1032 /* Now attach texture to the FBO as its color destination */ 1033 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_RECTANGLE_ARB, m_FBOThumbTexId, 0); 1034 1035 /* Make sure the FBO was created successfully. */ 1036 if (GL_FRAMEBUFFER_COMPLETE_EXT != glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT)) 1037 DEBUG_MSG(("OVIW(%p): Framebuffer \"Thumb\" Object creation or update failed!\n", (void*)self)); 1038 1039 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, oldTexId); 1040 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, (GLuint)oldFBId ? (GLuint)oldFBId : m_FBOId); 1041 908 pDockScreen = [self dockTileScreen]; 909 if (pDockScreen) 910 { 1042 911 m_DockTileView = [[DockOverlayView alloc] init]; 1043 912 [self reshapeDockTile]; 1044 913 [pDockScreen addSubview:m_DockTileView]; 1045 914 } 1046 1047 /* Initialize with one big visual region over the full size */ 1048 [self clearVisibleRegions]; 1049 m_cClipRects = 1; 1050 m_paClipRects = (GLint*)RTMemAlloc(sizeof(GLint) * 4); 1051 m_paClipRects[0] = 0; 1052 m_paClipRects[1] = 0; 1053 m_paClipRects[2] = m_FBOTexSize.width; 1054 m_paClipRects[3] = m_FBOTexSize.height; 1055 #endif 1056 } 1057 1058 - (void)deleteFBO 1059 { 1060 DEBUG_MSG(("OVIW(%p): deleteFBO\n", (void*)self)); 1061 1062 if (m_pSharedGLCtx) 1063 { 1064 DEBUG_MSG(("OVIW(%p): makeCurrent (shared) %p\n", (void*)self, (void*)m_pSharedGLCtx)); 1065 [m_pSharedGLCtx makeCurrentContext]; 1066 [m_pSharedGLCtx update]; 1067 1068 glEnable(GL_TEXTURE_RECTANGLE_ARB); 1069 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0); 1070 } 1071 1072 if (m_pGLCtx) 1073 { 1074 DEBUG_MSG(("OVIW(%p): makeCurrent (non shared) %p\n", (void*)self, (void*)m_pGLCtx)); 1075 [m_pGLCtx makeCurrentContext]; 1076 1077 #ifdef FBO 1078 if (m_FBODepthStencilPackedId > 0) 1079 { 1080 glDeleteRenderbuffersEXT(1, &m_FBODepthStencilPackedId); 1081 m_FBODepthStencilPackedId = 0; 1082 } 1083 if (m_FBOTexBackId > 0) 1084 { 1085 glDeleteTextures(1, &m_FBOTexBackId); 1086 m_FBOTexBackId = 0; 1087 } 1088 if (m_FBOTexFrontId > 0) 1089 { 1090 glDeleteTextures(1, &m_FBOTexFrontId); 1091 m_FBOTexFrontId = 0; 1092 } 1093 if (m_FBOId > 0) 1094 { 1095 if ([self isCurrentFBO]) 1096 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 1097 1098 glDeleteFramebuffersEXT(1, &m_FBOId); 1099 m_FBOId = 0; 1100 } 1101 #endif 1102 } 1103 1104 if (m_DockTileView != nil) 915 } 916 917 - (void)deleteDockTile 918 { 919 if (m_DockTileView != nil) 1105 920 { 1106 921 [m_DockTileView removeFromSuperview]; … … 1110 925 } 1111 926 1112 - (void)updateFBO1113 {1114 DEBUG_MSG(("OVIW(%p): updateFBO\n", (void*)self));1115 1116 [self makeCurrentFBO];1117 1118 if (m_pGLCtx)1119 {1120 #ifdef FBO1121 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);1122 [self createFBO];1123 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_FBOId);1124 #endif1125 [m_pGLCtx update];1126 }1127 }1128 1129 927 - (void)makeCurrentFBO 1130 928 { 1131 929 DEBUG_MSG(("OVIW(%p): makeCurrentFBO\n", (void*)self)); 1132 930 1133 #ifdef FBO1134 DEBUG_MSG(("OVIW(%p): FBOId=%d CTX=%p\n", (void*)self, m_FBOId, (void*)m_pGLCtx));1135 if([NSOpenGLContext currentContext] != 0)1136 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_FBOId);1137 #endif1138 931 if (m_pGLCtx) 1139 932 { … … 1150 943 */ 1151 944 { 1152 [m_pGLCtx makeCurrentContext];945 vboxCtxSetCurrent(m_pGLCtx); 1153 946 CHECK_GL_ERROR(); 1154 /* 1155 [m_pGLCtx update]; 1156 */ 947 if (m_fNeedCtxUpdate == true) 948 { 949 [m_pGLCtx update]; 950 m_fNeedCtxUpdate = false; 951 } 1157 952 } 1158 } 1159 #ifdef FBO 1160 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_FBOId); 1161 #endif 1162 } 1163 1164 - (bool)isCurrentFBO 1165 { 1166 #ifdef FBO 1167 GLint curFBOId = 0; 1168 1169 glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &curFBOId); 1170 DEBUG_MSG_1(("OVIW(%p): isCurrentFBO: curFBOId=%d FBOId=%d\n", (void*)self, curFBOId, m_FBOId)); 1171 return (GLuint)curFBOId == m_FBOId; 1172 #else 1173 return false; 1174 #endif 953 954 if (!m_FBOId) 955 { 956 glGenFramebuffersEXT(1, &m_FBOId); 957 Assert(m_FBOId); 958 } 959 960 } 1175 961 } 1176 962 … … 1179 965 if ([self lockFocusIfCanDraw]) 1180 966 { 1181 [self renderFBOToView];967 [self vboxPresent]; 1182 968 [self unlockFocus]; 1183 969 } … … 1186 972 - (void)swapFBO 1187 973 { 1188 GLint sw = 0;1189 GLint readFBOId = 0;1190 GLint drawFBOId = 0;1191 GLint readId = 0;1192 GLint drawId = 0;1193 1194 DEBUG_MSG(("OVIW(%p): swapFBO\n", (void*)self));1195 1196 #ifdef FBO1197 /* Don't use flush buffers cause we are using FBOs here! */1198 1199 /* Before we swap make sure everything is done (This is really1200 * important. Don't remove.) */1201 glFlush();1202 1203 /* Fetch the current used read and draw buffers. */1204 glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &readFBOId);1205 glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &drawFBOId);1206 glGetIntegerv(GL_READ_BUFFER, &readId);1207 glGetIntegerv(GL_DRAW_BUFFER, &drawId);1208 1209 /* Do the swapping of our internal ids */1210 sw = m_FBOTexFrontId;1211 m_FBOTexFrontId = m_FBOTexBackId;1212 m_FBOTexBackId = sw;1213 sw = m_FBOAttFrontId;1214 m_FBOAttFrontId = m_FBOAttBackId;1215 m_FBOAttBackId = sw;1216 1217 DEBUG_MSG_1(("read FBO: %d draw FBO: %d readId: %d drawId: %d\n", readFBOId, drawFBOId, readId, drawId));1218 /* We also have to swap the real ids on the current context. */1219 if ((GLuint)readFBOId == m_FBOId)1220 {1221 if ((GLuint)readId == m_FBOAttFrontId)1222 glReadBuffer(m_FBOAttBackId);1223 if ((GLuint)readId == m_FBOAttBackId)1224 glReadBuffer(m_FBOAttFrontId);1225 }1226 if ((GLuint)drawFBOId == m_FBOId)1227 {1228 if ((GLuint)drawId == m_FBOAttFrontId)1229 glDrawBuffer(m_FBOAttBackId);1230 if ((GLuint)drawId == m_FBOAttBackId)1231 glDrawBuffer(m_FBOAttFrontId);1232 }1233 1234 if (m_cClipRects)1235 [self tryDraw];1236 #else1237 974 [m_pGLCtx flushBuffer]; 1238 #endif 1239 } 1240 1241 - (void)flushFBO 1242 { 1243 GLint drawId = 0; 1244 GLint FBOId = 0; 1245 1246 DEBUG_MSG(("OVIW(%p): flushFBO\n", (void*)self)); 1247 1248 glFlush(); 1249 #ifdef FBO 1250 /* If at any time OpenGl operations where done in the front buffer, we need 1251 * to reflect this in the FBO as well. This is something which on real 1252 * hardware happens and unfortunately some applications rely on it (grrr ... Compiz). */ 1253 if ( m_fFrontDrawing 1254 && [self isCurrentFBO]) 1255 { 1256 /* Only reset if we aren't currently front. */ 1257 glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &FBOId); 1258 glGetIntegerv(GL_DRAW_BUFFER, &drawId); 1259 if (!( (GLuint)FBOId == m_FBOId 1260 && (GLuint)drawId == m_FBOAttFrontId)) 1261 m_fFrontDrawing = false; 1262 if (m_cClipRects) 1263 [self tryDraw]; 1264 } 1265 #endif 1266 } 1267 1268 - (void)finishFBO 1269 { 1270 DEBUG_MSG(("OVIW(%p): finishFBO\n", (void*)self)); 1271 1272 glFinish(); 1273 #ifdef FBO 1274 if (m_cClipRects && [self isCurrentFBO]) 1275 [self tryDraw]; 1276 #endif 1277 } 1278 1279 - (void)stateInfo:(GLenum)pname withParams:(GLint*)params 1280 { 1281 GLint test; 1282 // DEBUG_MSG_1(("StateInfo requested: %d\n", pname)); 1283 1284 glGetIntegerv(pname, params); 1285 #ifdef FBO 1286 switch(pname) 1287 { 1288 case GL_FRAMEBUFFER_BINDING_EXT: 1289 case GL_READ_FRAMEBUFFER_BINDING: 1290 case GL_READ_FRAMEBUFFER_EXT: 1291 case GL_DRAW_FRAMEBUFFER_EXT: 1292 { 1293 if ((GLuint)*params == m_FBOId) 1294 *params = 0; 1295 break; 1296 } 1297 case GL_READ_BUFFER: 1298 { 1299 glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &test); 1300 if ((GLuint)test == m_FBOId) 975 } 976 977 - (void)vboxPresent 978 { 979 GLint opaque = 0; 980 981 DEBUG_MSG(("OVIW(%p): renderFBOToView\n", (void*)self)); 982 983 if (!m_pCompositor) 984 return; 985 986 #ifdef DEBUG 1301 987 { 1302 if ((GLuint)*params == m_FBOAttFrontId) 1303 *params = GL_FRONT; 1304 else 1305 if ((GLuint)*params == m_FBOAttBackId) 1306 *params = GL_BACK; 988 NSOpenGLContext *pTstOldCtx = [NSOpenGLContext currentContext]; 989 NSView *pTstOldView = (pTstOldCtx ? [pTstOldCtx view] : nil); 990 Assert(pTstOldCtx == m_pGLCtx); 991 Assert(pTstOldView == self); 1307 992 } 1308 break; 1309 } 1310 case GL_DRAW_BUFFER: 1311 { 1312 glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &test); 1313 if ((GLuint)test == m_FBOId) 1314 { 1315 if ((GLuint)*params == m_FBOAttFrontId) 1316 *params = GL_FRONT; 1317 else 1318 if ((GLuint)*params == m_FBOAttBackId) 1319 *params = GL_BACK; 1320 } 1321 break; 1322 } 1323 } 1324 #endif 1325 } 1326 1327 - (void)readBuffer:(GLenum)mode 1328 { 1329 #ifdef FBO 1330 /* 1331 if ([self isCurrentFBO]) 1332 */ 1333 { 1334 if (mode == GL_FRONT) 1335 { 1336 glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, m_FBOId); 1337 glReadBuffer(m_FBOAttFrontId); 1338 } 1339 else if (mode == GL_BACK) 1340 { 1341 glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, m_FBOId); 1342 glReadBuffer(m_FBOAttBackId); 1343 } 1344 else 1345 glReadBuffer(mode); 1346 } 1347 #else 1348 glReadBuffer(mode); 1349 #endif 1350 } 1351 1352 - (void)drawBuffer:(GLenum)mode 1353 { 1354 #ifdef FBO 1355 /* 1356 if ([self isCurrentFBO]) 1357 */ 1358 { 1359 if (mode == GL_FRONT) 1360 { 1361 DEBUG_MSG(("OVIW(%p): front\n", (void*)self)); 1362 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, m_FBOId); 1363 glDrawBuffer(m_FBOAttFrontId); 1364 m_fFrontDrawing = true; 1365 } 1366 else if (mode == GL_BACK) 1367 { 1368 DEBUG_MSG(("OVIW(%p): back\n", (void*)self)); 1369 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, m_FBOId); 1370 glDrawBuffer(m_FBOAttBackId); 1371 } 1372 else 1373 { 1374 DEBUG_MSG(("OVIW(%p): other: %d\n", (void*)self, mode)); 1375 glDrawBuffer(mode); 1376 } 1377 } 1378 #else 1379 glDrawBuffer(mode); 1380 #endif 1381 } 1382 1383 - (void)bindFBO:(GLenum)target withFrameBuffer:(GLuint)framebuffer 1384 { 1385 #ifdef FBO 1386 if (framebuffer != 0) 1387 glBindFramebufferEXT(target, framebuffer); 1388 else 1389 glBindFramebufferEXT(target, m_FBOId); 1390 #else 1391 glBindFramebufferEXT(target, framebuffer); 1392 #endif 1393 } 1394 1395 - (void)renderFBOToView 1396 { 1397 GLint opaque = 0; 1398 GLint i = 0; 1399 GLint oldReadFBOId = 0; 1400 GLint oldDrawFBOId = 0; 1401 GLint oldReadId = 0; 1402 GLint oldDrawId = 0; 1403 1404 DEBUG_MSG(("OVIW(%p): renderFBOToView\n", (void*)self)); 1405 1406 #ifdef FBO 1407 1408 /* Fetch the current used read and draw buffers. */ 1409 glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING_EXT, &oldReadFBOId); 1410 glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING_EXT, &oldDrawFBOId); 1411 glGetIntegerv(GL_READ_BUFFER, &oldReadId); 1412 glGetIntegerv(GL_DRAW_BUFFER, &oldDrawId); 993 #endif 1413 994 1414 995 if (!m_pSharedGLCtx) … … 1421 1002 /* Set this view as the drawable for the new context */ 1422 1003 [m_pSharedGLCtx setView: self]; 1423 [self updateViewport]; 1424 } 1425 1426 if (m_pSharedGLCtx) 1427 { 1004 m_fNeedViewportUpdate = true; 1005 } 1006 1007 #ifdef DEBUG 1008 { 1009 NSOpenGLContext *pTstOldCtx = [NSOpenGLContext currentContext]; 1010 NSView *pTstOldView = (pTstOldCtx ? [pTstOldCtx view] : nil); 1011 Assert(pTstOldCtx == m_pGLCtx); 1012 Assert(pTstOldView == self); 1013 } 1014 #endif 1015 1016 [self performSelectorMakingCurrent:m_pSharedGLCtx idSel:@selector(vboxPresentCS)]; 1017 } 1018 1019 - (void)vboxPresentCS 1020 { 1428 1021 NSRect r = [self frame]; 1429 1022 DEBUG_MSG(("OVIW(%p): rF2V frame: [%i, %i, %i, %i]\n", (void*)self, (int)r.origin.x, (int)r.origin.y, (int)r.size.width, (int)r.size.height)); 1430 1023 1431 if (m_FBOTexFrontId > 0)1432 1024 { 1433 1025 if ([m_pSharedGLCtx view] != self) … … 1435 1027 DEBUG_MSG(("OVIW(%p): not current view of shared ctx! Switching ...\n", (void*)self)); 1436 1028 [m_pSharedGLCtx setView: self]; 1437 [self updateViewport];1029 m_fNeedViewportUpdate = true; 1438 1030 } 1439 1440 [m_pSharedGLCtx makeCurrentContext]; 1441 1031 1032 if (m_fNeedViewportUpdate) 1033 { 1034 [self updateViewportCS]; 1035 m_fNeedViewportUpdate = false; 1036 } 1037 1038 /* Render FBO content to the dock tile when necessary. */ 1039 [self vboxPresentToDockTileCS]; 1040 1041 [self vboxPresentToViewCS]; 1042 } 1043 } 1044 1045 - (void)vboxPresentToViewCS 1046 { 1047 #if 1 /* Set to 0 to see the docktile instead of the real output */ 1048 VBOXVR_SCR_COMPOSITOR_ITERATOR CIter; 1049 PVBOXVR_SCR_COMPOSITOR_ENTRY pEntry; 1050 1051 CrVrScrCompositorIterInit(m_pCompositor, &CIter); 1052 1053 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0); 1054 glDrawBuffer(GL_BACK); 1055 1056 /* Clear background to transparent */ 1057 glClear(GL_COLOR_BUFFER_BIT); 1058 1059 while ((pEntry = CrVrScrCompositorIterNext(&CIter)) != NULL) 1060 { 1061 uint32_t cRegions; 1062 const RTRECT *paSrcRegions, *paDstRegions; 1063 int rc = CrVrScrCompositorEntryRegionsGet(m_pCompositor, pEntry, &cRegions, &paSrcRegions, &paDstRegions); 1064 if (RT_SUCCESS(rc)) 1065 { 1066 uint32_t i; 1067 1442 1068 glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, m_FBOId); 1443 glReadBuffer(m_FBOAttFrontId); 1444 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0); 1445 glDrawBuffer(GL_BACK); 1446 1447 /* Render FBO content to the dock tile when necessary. */ 1448 [self renderFBOToDockTile]; 1449 1450 #if 1 /* Set to 0 to see the docktile instead of the real output */ 1451 /* Clear background to transparent */ 1452 glClear(GL_COLOR_BUFFER_BIT); 1453 1454 /* Blit the content of the FBO to the screen. */ 1455 for (i = 0; i < m_cClipRects; ++i) 1069 glFramebufferTexture2DEXT(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, pEntry->Tex.target, pEntry->Tex.hwid, 0); 1070 glReadBuffer(GL_COLOR_ATTACHMENT0); 1071 1072 for (i = 0; i < pEntry->cRects; ++i) 1456 1073 { 1457 GLint x1 = m_paClipRects[4*i]; 1458 GLint y1 = r.size.height - m_paClipRects[4*i+1]; 1459 GLint x2 = m_paClipRects[4*i+2]; 1460 GLint y2 = r.size.height - m_paClipRects[4*i+3]; 1461 glBlitFramebufferEXT(x1, y1 + m_RootShift.y, x2, y2 + m_RootShift.y, 1462 x1 - m_RootShift.x, y1, x2 - m_RootShift.x, y2, 1463 GL_COLOR_BUFFER_BIT, GL_NEAREST); 1074 const RTRECT * pSrcRect = &paSrcRegions[i]; 1075 const RTRECT * pDstRect = &paDstRegions[i]; 1076 1077 glBlitFramebufferEXT(pSrcRect->xLeft, pSrcRect->yTop, pSrcRect->xRight, pSrcRect->yBottom, 1078 pDstRect->xLeft, pDstRect->yTop, pDstRect->xRight, pDstRect->yBottom, 1079 GL_COLOR_BUFFER_BIT, GL_LINEAR); 1464 1080 } 1081 } 1082 else 1083 { 1084 Assert(0); 1085 DEBUG_MSG_1(("BlitStretched: CrVrScrCompositorEntryRegionsGet failed rc %d\n", rc)); 1086 } 1087 } 1465 1088 #endif 1466 1089 /* … … 1469 1092 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 1470 1093 [m_pSharedGLCtx flushBuffer]; 1471 1472 [m_pGLCtx makeCurrentContext]; 1473 /* Reset to previous buffer bindings. */ 1474 glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, oldReadFBOId); 1475 glReadBuffer(oldReadId); 1476 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, oldDrawFBOId); 1477 glDrawBuffer(oldDrawId); 1094 } 1095 1096 - (void)performSelectorMakingCurrent:(NSOpenGLContext*)pCtx idSel:(SEL)selector 1097 { 1098 NSOpenGLContext *pOldCtx = vboxCtxGetCurrent(); 1099 NSView *pOldView = (pOldCtx ? [pOldCtx view] : nil); 1100 NSView *pView = [pCtx view]; 1101 bool fNeedCtxSwitch = (pOldCtx != pCtx || pOldView != pView); 1102 Assert(pCtx); 1103 Assert(pOldCtx == m_pGLCtx); 1104 Assert(pOldView == self); 1105 Assert(fNeedCtxSwitch); 1106 if (fNeedCtxSwitch) 1107 { 1108 if(pOldCtx != nil) 1109 glFlush(); 1110 1111 vboxCtxSetCurrent(pCtx); 1112 } 1113 1114 [self performSelector:selector]; 1115 1116 if (fNeedCtxSwitch) 1117 { 1118 glFlush(); 1119 if (pOldCtx != nil) 1120 { 1121 if ([pOldCtx view] != pOldView) 1122 { 1123 [pOldCtx setView: pOldView]; 1124 } 1125 1126 vboxCtxSetCurrent(pOldCtx); 1127 1128 #ifdef DEBUG 1129 { 1130 NSOpenGLContext *pTstOldCtx = [NSOpenGLContext currentContext]; 1131 NSView *pTstOldView = (pTstOldCtx ? [pTstOldCtx view] : nil); 1132 Assert(pTstOldCtx == pOldCtx); 1133 Assert(pTstOldView == pOldView); 1134 } 1135 #endif 1478 1136 } 1479 } 1480 #else 1481 [m_pGLCtx flushBuffer]; 1482 #endif 1483 } 1484 1485 - (void)renderFBOToDockTile 1137 else 1138 { 1139 [NSOpenGLContext clearCurrentContext]; 1140 } 1141 } 1142 } 1143 1144 - (void)presentComposition:(PVBOXVR_SCR_COMPOSITOR)pCompositor withChangedEntry:(PVBOXVR_SCR_COMPOSITOR_ENTRY)pChangedEntry 1145 { 1146 m_pCompositor = pCompositor; 1147 1148 [self tryDraw]; 1149 } 1150 1151 - (void)vboxPresentToDockTileCS 1486 1152 { 1487 1153 NSRect r = [self frame]; … … 1490 1156 NSDockTile *pDT = nil; 1491 1157 1492 #ifdef FBO 1493 if ( m_FBOThumbId 1494 && m_FBOThumbTexId 1495 && [m_DockTileView thumbBitmap] != nil) 1158 if ([m_DockTileView thumbBitmap] != nil) 1496 1159 { 1497 1160 /* Only update after at least 200 ms, cause glReadPixels is 1498 1161 * heavy performance wise. */ 1499 1162 uint64_t uiNewTime = RTTimeMilliTS(); 1163 VBOXVR_SCR_COMPOSITOR_ITERATOR CIter; 1164 PVBOXVR_SCR_COMPOSITOR_ENTRY pEntry; 1165 1500 1166 if (uiNewTime - m_uiDockUpdateTime > 200) 1501 1167 { … … 1517 1183 GL_UNSIGNED_INT_8_8_8_8_REV, pixels); 1518 1184 #endif 1185 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0); 1186 glDrawBuffer(GL_BACK); 1187 1519 1188 /* Clear background to transparent */ 1520 1189 glClear(GL_COLOR_BUFFER_BIT); 1521 1190 1522 1191 rr = [m_DockTileView frame]; 1523 1524 for (i = 0; i < m_cClipRects; ++i) 1192 1193 CrVrScrCompositorIterInit(m_pCompositor, &CIter); 1194 while ((pEntry = CrVrScrCompositorIterNext(&CIter)) != NULL) 1525 1195 { 1526 GLint x1 = m_paClipRects[4*i]; 1527 GLint y1 = r.size.height - m_paClipRects[4*i+1]; 1528 GLint x2 = m_paClipRects[4*i+2]; 1529 GLint y2 = r.size.height - m_paClipRects[4*i+3]; 1530 1531 glBlitFramebufferEXT(x1, y1 + m_RootShift.y, x2, y2 + m_RootShift.y, 1532 x1 * m_FBOThumbScaleX, y1 * m_FBOThumbScaleY, x2 * m_FBOThumbScaleX, y2 * m_FBOThumbScaleY, 1533 GL_COLOR_BUFFER_BIT, GL_LINEAR); 1196 uint32_t cRegions; 1197 const RTRECT *paSrcRegions, *paDstRegions; 1198 int rc = CrVrScrCompositorEntryRegionsGet(m_pCompositor, pEntry, &cRegions, &paSrcRegions, &paDstRegions); 1199 if (RT_SUCCESS(rc)) 1200 { 1201 uint32_t i; 1202 1203 glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, m_FBOId); 1204 glFramebufferTexture2DEXT(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, pEntry->Tex.target, pEntry->Tex.hwid, 0); 1205 glReadBuffer(GL_COLOR_ATTACHMENT0); 1206 1207 for (i = 0; i < pEntry->cRects; ++i) 1208 { 1209 const RTRECT * pSrcRect = &paSrcRegions[i]; 1210 const RTRECT * pDstRect = &paDstRegions[i]; 1211 1212 glBlitFramebufferEXT(pSrcRect->xLeft, pSrcRect->yTop, pSrcRect->xRight, pSrcRect->yBottom, 1213 pDstRect->xLeft * m_FBOThumbScaleX, pDstRect->yTop * m_FBOThumbScaleY, pDstRect->xRight * m_FBOThumbScaleX, pDstRect->yBottom * m_FBOThumbScaleY, 1214 GL_COLOR_BUFFER_BIT, GL_LINEAR); 1215 } 1216 } 1217 else 1218 { 1219 Assert(0); 1220 DEBUG_MSG_1(("BlitStretched: CrVrScrCompositorEntryRegionsGet failed rc %d\n", rc)); 1221 } 1534 1222 } 1223 1535 1224 glFinish(); 1536 1225 … … 1547 1236 [m_DockTileView unlock]; 1548 1237 1549 glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, m_FBOId);1550 glReadBuffer(m_FBOAttFrontId);1551 1552 1238 pDT = [[NSApplication sharedApplication] dockTile]; 1553 1239 1554 1240 /* Send a display message to the dock tile in the main thread */ 1555 1241 [[[NSApplication sharedApplication] dockTile] performSelectorOnMainThread:@selector(display) withObject:nil waitUntilDone:NO]; 1556 1557 1242 } 1558 1243 } 1559 #endif1560 1244 } 1561 1245 … … 1590 1274 memcpy(m_paClipRects, paRects, sizeof(GLint) * 4 * cRects); 1591 1275 } 1276 #if 0 1277 /* todo: handle pending m_fNeedCtxUpdate */ 1592 1278 else if (cOldRects) 1593 1279 [self tryDraw]; 1280 #endif 1594 1281 } 1595 1282 … … 1779 1466 { 1780 1467 [[pParentView window] addChildWindow:[pOView overlayWin] ordered:NSWindowAbove]; 1781 [pOView create FBO];1468 [pOView createDockTile]; 1782 1469 } 1783 1470 } … … 1887 1574 } 1888 1575 1576 void cocoaViewPresentComposition(NativeNSViewRef pView, struct VBOXVR_SCR_COMPOSITOR * pCompositor, struct VBOXVR_SCR_COMPOSITOR_ENTRY *pChangedEntry) 1577 { 1578 NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init]; 1579 1580 [(OverlayView*)pView presentComposition:pCompositor withChangedEntry:pChangedEntry]; 1581 1582 [pPool release]; 1583 } 1584 1889 1585 void cocoaViewMakeCurrentContext(NativeNSViewRef pView, NativeNSOpenGLContextRef pCtx) 1890 1586 { … … 1907 1603 [pPool release]; 1908 1604 } 1909 1910 /********************************************************************************1911 *1912 * Additional OpenGL wrapper1913 *1914 ********************************************************************************/1915 static void performSelectorOnView(SEL selector)1916 {1917 NSOpenGLContext *pCtx = [NSOpenGLContext currentContext];1918 1919 if (pCtx)1920 {1921 NSView *pView = [pCtx view];1922 if (pView)1923 {1924 if ([pView respondsToSelector:selector])1925 [pView performSelector:selector];1926 }1927 }1928 }1929 1930 static void performSelectorOnViewOneArg(SEL selector, id arg1)1931 {1932 NSOpenGLContext *pCtx = [NSOpenGLContext currentContext];1933 1934 if (pCtx)1935 {1936 NSView *pView = [pCtx view];1937 if (pView)1938 {1939 if ([pView respondsToSelector:selector])1940 [pView performSelector:selector withObject:arg1];1941 }1942 }1943 }1944 1945 static void performSelectorOnViewTwoArgs(SEL selector, id arg1, id arg2)1946 {1947 NSOpenGLContext *pCtx = [NSOpenGLContext currentContext];1948 1949 if (pCtx)1950 {1951 NSView *pView = [pCtx view];1952 if (pView)1953 {1954 if ([pView respondsToSelector:selector])1955 [pView performSelector:selector withObject:arg1 withObject:arg2];1956 }1957 }1958 }1959 1960 void cocoaFlush(void)1961 {1962 NSOpenGLContext *pCtx = nil;1963 1964 NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];1965 1966 DEBUG_MSG_1(("glFlush called\n"));1967 1968 performSelectorOnView(@selector(flushFBO));1969 1970 [pPool release];1971 }1972 1973 void cocoaFinish(void)1974 {1975 NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];1976 1977 DEBUG_MSG_1(("glFinish called\n"));1978 1979 performSelectorOnView(@selector(finishFBO));1980 1981 [pPool release];1982 }1983 1984 void cocoaBindFramebufferEXT(GLenum target, GLuint framebuffer)1985 {1986 NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];1987 1988 DEBUG_MSG_1(("glBindFramebufferEXT called target: %d fb: %d\n", target, framebuffer));1989 1990 performSelectorOnViewTwoArgs(@selector(bindFBO:withFrameBuffer:), (id)target, (id)framebuffer);1991 1992 [pPool release];1993 }1994 1995 void cocoaCopyPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum type)1996 {1997 NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];1998 GLbitfield mask = GL_COLOR_BUFFER_BIT;1999 2000 DEBUG_MSG_1(("glCopyPixels called: %d,%d-%dx%d type: %d\n", x, y, width, height, type));2001 2002 #ifdef FBO2003 if (type == GL_DEPTH)2004 mask = GL_DEPTH_BUFFER_BIT;2005 else if (type == GL_STENCIL)2006 mask = GL_STENCIL_BUFFER_BIT;2007 glBlitFramebufferEXT(x, y, x + width, y + height, x, y, x + width, y + height, mask, GL_NEAREST);2008 #else2009 glCopyPixels(x, y, width, height, type);2010 #endif2011 2012 [pPool release];2013 }2014 2015 void cocoaGetIntegerv(GLenum pname, GLint *params)2016 {2017 NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];2018 2019 // DEBUG_MSG_1(("getIntergerv called: %d\n", pname));2020 2021 performSelectorOnViewTwoArgs(@selector(stateInfo:withParams:), (id)pname, (id)params);2022 2023 [pPool release];2024 }2025 2026 void cocoaReadBuffer(GLenum mode)2027 {2028 NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];2029 2030 DEBUG_MSG_1(("glReadBuffer called: %d\n", mode));2031 2032 performSelectorOnViewOneArg(@selector(readBuffer:), (id)mode);2033 2034 [pPool release];2035 }2036 2037 void cocoaDrawBuffer(GLenum mode)2038 {2039 NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];2040 2041 DEBUG_MSG_1(("glDrawBuffer called: %d\n", mode));2042 2043 performSelectorOnViewOneArg(@selector(drawBuffer:), (id)mode);2044 2045 [pPool release];2046 }2047 -
trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu_glx.c
r44714 r44740 641 641 window->x = 0; 642 642 window->y = 0; 643 window-> width = xwa.width;644 window-> height = xwa.height;643 window->BltInfo.width = xwa.width; 644 window->BltInfo.height = xwa.height; 645 645 } 646 646 647 647 /* i've changed default window size to be 0,0 but X doesn't like it */ 648 /*CRASSERT(window-> width >= 1);649 CRASSERT(window-> height >= 1);*/650 if (window-> width < 1) window->width = 1;651 if (window-> height < 1) window->height = 1;648 /*CRASSERT(window->BltInfo.width >= 1); 649 CRASSERT(window->BltInfo.height >= 1);*/ 650 if (window->BltInfo.width < 1) window->BltInfo.width = 1; 651 if (window->BltInfo.height < 1) window->BltInfo.height = 1; 652 652 653 653 /* … … 708 708 window->window = XCreateWindow(dpy, render_spu_parent_window_id, 709 709 window->x, window->y, 710 window-> width, window->height,710 window->BltInfo.width, window->BltInfo.height, 711 711 0, visual->visual->depth, InputOutput, 712 712 visual->visual->visual, flags, &swa); … … 721 721 window->window = XCreateWindow(dpy, RootWindow(dpy, visual->visual->screen), 722 722 window->x, window->y, 723 window-> width, window->height,723 window->BltInfo.width, window->BltInfo.height, 724 724 0, visual->visual->depth, InputOutput, 725 725 visual->visual->visual, flags, &swa); … … 791 791 hints.x = window->x; 792 792 hints.y = window->y; 793 hints.width = window-> width;794 hints.height = window-> height;793 hints.width = window->BltInfo.width; 794 hints.height = window->BltInfo.height; 795 795 hints.min_width = hints.width; 796 796 hints.min_height = hints.height; … … 836 836 * which form a mural are in the same swap group. 837 837 */ 838 GLuint group = 0; /*render_spu.nvSwapGroup + window-> id;*/838 GLuint group = 0; /*render_spu.nvSwapGroup + window->BltInfo.Base.id;*/ 839 839 GLuint barrier = 0; 840 840 JoinSwapGroup(dpy, visual->visual->screen, window->window, group, barrier); … … 845 845 */ 846 846 crDebug( "Render SPU: actual window x, y, width, height: %d, %d, %d, %d", 847 window->x, window->y, window-> width, window->height );847 window->x, window->y, window->BltInfo.width, window->BltInfo.height ); 848 848 849 849 XSync(dpy, 0); … … 861 861 window->nativeWindow = 0; 862 862 863 CRASSERT(window-> width > 0);864 CRASSERT(window-> height > 0);863 CRASSERT(window->BltInfo.width > 0); 864 CRASSERT(window->BltInfo.height > 0); 865 865 866 866 #ifdef GLX_VERSION_1_3 … … 868 868 int attribs[100], i = 0, w, h; 869 869 CRASSERT(visual->fbconfig); 870 w = window-> width;871 h = window-> height;870 w = window->BltInfo.width; 871 h = window->BltInfo.height; 872 872 attribs[i++] = GLX_PRESERVED_CONTENTS; 873 873 attribs[i++] = True; … … 897 897 { 898 898 if (visual->visAttribs & CR_PBUFFER_BIT) { 899 window-> width = render_spu.defaultWidth;900 window-> height = render_spu.defaultHeight;899 window->BltInfo.width = render_spu.defaultWidth; 900 window->BltInfo.height = render_spu.defaultHeight; 901 901 return createPBuffer(visual, window); 902 902 } … … 1001 1001 crDebug("Render SPU: Created %s context (%d) on display %s for visAttribs 0x%x", 1002 1002 is_direct ? "DIRECT" : "INDIRECT", 1003 context-> id,1003 context->BltInfo.Base.id, 1004 1004 DisplayString(visual->dpy), 1005 1005 visual->visAttribs); … … 1153 1153 check_buffer_size( WindowInfo *window ) 1154 1154 { 1155 if (window-> width != window->in_buffer_width1156 || window-> height != window->in_buffer_height1155 if (window->BltInfo.width != window->in_buffer_width 1156 || window->BltInfo.height != window->in_buffer_height 1157 1157 || ! window->buffer) { 1158 1158 crFree(window->buffer); 1159 1159 1160 window->buffer = crCalloc(window-> width * window->height1160 window->buffer = crCalloc(window->BltInfo.width * window->BltInfo.height 1161 1161 * 4 * sizeof (GLubyte)); 1162 1162 1163 window->in_buffer_width = window-> width;1164 window->in_buffer_height = window-> height;1165 1166 crDebug("Render SPU: dimensions changed to %d x %d", window-> width, window->height);1163 window->in_buffer_width = window->BltInfo.width; 1164 window->in_buffer_height = window->BltInfo.height; 1165 1166 crDebug("Render SPU: dimensions changed to %d x %d", window->BltInfo.width, window->BltInfo.height); 1167 1167 } 1168 1168 } … … 1186 1186 render_spu.OSMesaMakeCurrent( (OSMesaContext) context->context, 1187 1187 window->buffer, GL_UNSIGNED_BYTE, 1188 window-> width, window->height);1188 window->BltInfo.width, window->BltInfo.height); 1189 1189 return; 1190 1190 } … … 1194 1194 if (window->visual != context->visual) { 1195 1195 crDebug("Render SPU: MakeCurrent visual mismatch (win(%d) bits:0x%x != ctx(%d) bits:0x%x); remaking window.", 1196 window-> id, window->visual->visAttribs,1197 context-> id, context->visual->visAttribs);1196 window->BltInfo.Base.id, window->visual->visAttribs, 1197 context->BltInfo.Base.id, context->visual->visAttribs); 1198 1198 /* 1199 1199 * XXX have to revisit this issue!!! … … 1274 1274 crWarning("Render SPU: Can't bind context %d to CRUT/native window " 1275 1275 "0x%x because of different X visuals (0x%x != 0x%x)!", 1276 context-> id, (int) nativeWindow,1276 context->BltInfo.Base.id, (int) nativeWindow, 1277 1277 vid, (int) context->visual->visual->visualid); 1278 1278 crWarning("Render SPU: Trying to recreate GLX context to match."); … … 1328 1328 window->visual->dpy, 1329 1329 (int) window->window, (void *) context->context, 1330 window-> id, context->id );1330 window->BltInfo.Base.id, context->BltInfo.Base.id ); 1331 1331 } 1332 1332 /*CRASSERT(b);*/ … … 1361 1361 #ifdef USE_OSMESA 1362 1362 if (render_spu.use_osmesa) { 1363 window-> width = w;1364 window-> height = h;1363 window->BltInfo.width = w; 1364 window->BltInfo.height = h; 1365 1365 check_buffer_size(window); 1366 1366 return; … … 1395 1395 } 1396 1396 1397 if (window-> width != w || window->height != h) {1397 if (window->BltInfo.width != w || window->BltInfo.height != h) { 1398 1398 /* Only resize if the new dimensions really are different */ 1399 1399 #ifdef CHROMIUM_THREADSAFE … … 1404 1404 /* Can't resize pbuffers, so destroy it and make a new one */ 1405 1405 render_spu.ws.glXDestroyPbuffer(window->visual->dpy, window->window); 1406 window-> width = w;1407 window-> height = h;1406 window->BltInfo.width = w; 1407 window->BltInfo.height = h; 1408 1408 crDebug("Render SPU: Creating new %d x %d PBuffer (id=%d)", 1409 w, h, window-> id);1409 w, h, window->BltInfo.Base.id); 1410 1410 if (!createPBuffer(window->visual, window)) { 1411 1411 crWarning("Render SPU: Unable to create PBuffer (out of VRAM?)!"); … … 1447 1447 1448 1448 /* finally, save the new size */ 1449 window-> width = w;1450 window-> height = h;1449 window->BltInfo.width = w; 1450 window->BltInfo.height = h; 1451 1451 } 1452 1452 … … 1458 1458 #ifdef USE_OSMESA 1459 1459 if (render_spu.use_osmesa) { 1460 *w = window-> width;1461 *h = window-> height;1460 *w = window->BltInfo.width; 1461 *h = window->BltInfo.height; 1462 1462 return; 1463 1463 } … … 1471 1471 *x = 0; 1472 1472 *y = 0; 1473 *w = window-> width;1474 *h = window-> height;1473 *w = window->BltInfo.width; 1474 *h = window->BltInfo.height; 1475 1475 } 1476 1476 else … … 1622 1622 } 1623 1623 1624 void renderspu_SystemVBoxPresentComposition( WindowInfo *window, struct VBOXVR_SCR_COMPOSITOR * pCompositor, struct VBOXVR_SCR_COMPOSITOR_ENTRY *pChangedEntry ) 1625 { 1626 renderspuVBoxPresentCompositionGeneric(window, pCompositor, pChangedEntry); 1627 } 1624 1628 1625 1629 static void … … 1633 1637 gc = XCreateGC(w->visual->dpy, w->nativeWindow, GCFunction, &gcValues); 1634 1638 } 1635 XDrawLine(w->visual->dpy, w->nativeWindow, gc, 0, 0, w-> width, w->height);1639 XDrawLine(w->visual->dpy, w->nativeWindow, gc, 0, 0, w->BltInfo.width, w->BltInfo.height); 1636 1640 } 1637 1641 -
trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu_init.c
r40318 r44740 10 10 #include "cr_string.h" 11 11 #include "cr_url.h" 12 #include "cr_environment.h" 12 13 #include "renderspu.h" 13 14 #include <stdio.h> … … 139 140 GLint defaultWin, defaultCtx; 140 141 WindowInfo *windowInfo; 142 const char * pcpwSetting; 141 143 142 144 (void) child; … … 200 202 render_spu.contextTable = crAllocHashtable(); 201 203 render_spu.windowTable = crAllocHashtable(); 204 205 pcpwSetting = crGetenv("CR_RENDER_ENABLE_PRESENT_CONTEXT_PER_WINDOW"); 206 if (pcpwSetting) 207 { 208 if (pcpwSetting[0] == '0') 209 pcpwSetting = NULL; 210 } 211 else 212 { 213 /* default is enable for OSX */ 214 #if defined(DARWIN) && defined(VBOX_WITH_COCOA_QT) 215 pcpwSetting = (char*)1; 216 #endif 217 218 } 219 220 if (pcpwSetting) 221 { 222 render_spu.blitterTable = crAllocHashtable(); 223 CRASSERT(render_spu.blitterTable); 224 } 225 else 226 render_spu.blitterTable = NULL; 202 227 203 228 CRASSERT(render_spu.default_visual & CR_RGB_BIT); … … 353 378 } 354 379 355 356 380 static void renderSPUSelfDispatch(SPUDispatchTable *self) 357 381 { 358 382 crSPUInitDispatchTable( &(render_spu.self) ); 359 383 crSPUCopyDispatchTable( &(render_spu.self), self ); 384 385 render_spu.blitterDispatch = &(render_spu.self); 360 386 361 387 render_spu.server = (CRServer *)(self->server); … … 387 413 renderspu_SystemDestroyWindow(window); 388 414 crFree(window); 415 } 416 417 static void DeleteBlitterCallback( void *data ) 418 { 419 PCR_BLITTER pBlitter = (PCR_BLITTER) data; 420 CrBltTerm(pBlitter); 421 crFree(pBlitter); 389 422 } 390 423 … … 397 430 crFreeHashtable(render_spu.barrierHash, crFree); 398 431 render_spu.barrierHash = NULL; 432 433 if (render_spu.blitterTable) 434 crFreeHashtable(render_spu.blitterTable, DeleteBlitterCallback); 399 435 400 436 #ifdef RT_OS_DARWIN -
trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu_wgl.c
r44290 r44740 783 783 int smCyCaption = GetSystemMetrics( SM_CYCAPTION ); 784 784 785 window-> width = GetSystemMetrics( SM_CXSCREEN ) ;786 window-> height = GetSystemMetrics( SM_CYSCREEN ) ;787 788 crDebug( "Render SPU: Window Dims: %d, %d", window-> width, window->height );785 window->BltInfo.width = GetSystemMetrics( SM_CXSCREEN ) ; 786 window->BltInfo.height = GetSystemMetrics( SM_CYSCREEN ) ; 787 788 crDebug( "Render SPU: Window Dims: %d, %d", window->BltInfo.width, window->BltInfo.height ); 789 789 790 790 window->x = render_spu->defaultX - smCxFixedFrame - 1; 791 791 window->y = render_spu->defaultY - smCyFixedFrame - smCyCaption; 792 792 793 window_plus_caption_width = window-> width + 2 * smCxFixedFrame;794 window_plus_caption_height = window-> height + 2 * smCyFixedFrame + smCyCaption;793 window_plus_caption_width = window->BltInfo.width + 2 * smCxFixedFrame; 794 window_plus_caption_height = window->BltInfo.height + 2 * smCyFixedFrame + smCyCaption; 795 795 796 796 #else … … 798 798 * with these parameters. */ 799 799 800 window-> width = GetSystemMetrics( SM_CXSCREEN ) ;801 window-> height = GetSystemMetrics( SM_CYSCREEN ) ;800 window->BltInfo.width = GetSystemMetrics( SM_CXSCREEN ) ; 801 window->BltInfo.height = GetSystemMetrics( SM_CYSCREEN ) ; 802 802 window->x = 0; 803 803 window->y = 0; 804 window_plus_caption_width = window-> width;805 window_plus_caption_height = window-> height;804 window_plus_caption_width = window->BltInfo.width; 805 window_plus_caption_height = window->BltInfo.height; 806 806 807 807 #endif … … 820 820 crDebug( "Render SPU: Got the Caption " ); 821 821 822 window_plus_caption_width = window-> width + 2 * smCxFixedFrame;823 window_plus_caption_height = window-> height + 2 * smCyFixedFrame + smCyCaption;822 window_plus_caption_width = window->BltInfo.width + 2 * smCxFixedFrame; 823 window_plus_caption_height = window->BltInfo.height + 2 * smCyFixedFrame + smCyCaption; 824 824 825 825 window->x = render_spu.defaultX - smCxFixedFrame; … … 846 846 { 847 847 renderspu_SystemShowWindow( window, 0 ); 848 if (window-> height <= 0 || window->width <= 0)848 if (window->BltInfo.height <= 0 || window->BltInfo.width <= 0) 849 849 { 850 850 renderspu_SystemWindowSize(window, 851 window-> width > 0 ? window->width : 4,852 window-> height > 0 ? window->height : 4);851 window->BltInfo.width > 0 ? window->BltInfo.width : 4, 852 window->BltInfo.height > 0 ? window->BltInfo.height : 4); 853 853 } 854 854 } … … 999 999 int smCyCaption = GetSystemMetrics( SM_CYCAPTION ); 1000 1000 1001 window-> width = GetSystemMetrics( SM_CXSCREEN ) ;1002 window-> height = GetSystemMetrics( SM_CYSCREEN ) ;1003 1004 crDebug( "Render SPU: Window Dims: %d, %d", window-> width, window->height );1001 window->BltInfo.width = GetSystemMetrics( SM_CXSCREEN ) ; 1002 window->BltInfo.height = GetSystemMetrics( SM_CYSCREEN ) ; 1003 1004 crDebug( "Render SPU: Window Dims: %d, %d", window->BltInfo.width, window->BltInfo.height ); 1005 1005 1006 1006 window->x = render_spu->defaultX - smCxFixedFrame - 1; 1007 1007 window->y = render_spu->defaultY - smCyFixedFrame - smCyCaption; 1008 1008 1009 window_plus_caption_width = window-> width + 2 * smCxFixedFrame;1010 window_plus_caption_height = window-> height + 2 * smCyFixedFrame + smCyCaption;1009 window_plus_caption_width = window->BltInfo.width + 2 * smCxFixedFrame; 1010 window_plus_caption_height = window->BltInfo.height + 2 * smCyFixedFrame + smCyCaption; 1011 1011 1012 1012 #else … … 1014 1014 * with these parameters. */ 1015 1015 1016 window-> width = GetSystemMetrics( SM_CXSCREEN ) ;1017 window-> height = GetSystemMetrics( SM_CYSCREEN ) ;1016 window->BltInfo.width = GetSystemMetrics( SM_CXSCREEN ) ; 1017 window->BltInfo.height = GetSystemMetrics( SM_CYSCREEN ) ; 1018 1018 window->x = 0; 1019 1019 window->y = 0; 1020 window_plus_caption_width = window-> width;1021 window_plus_caption_height = window-> height;1020 window_plus_caption_width = window->BltInfo.width; 1021 window_plus_caption_height = window->BltInfo.height; 1022 1022 1023 1023 #endif … … 1035 1035 crDebug( "Render SPU: Got the Caption " ); 1036 1036 1037 window_plus_caption_width = window-> width + 2 * smCxFixedFrame;1038 window_plus_caption_height = window-> height + 2 * smCyFixedFrame + smCyCaption;1037 window_plus_caption_width = window->BltInfo.width + 2 * smCxFixedFrame; 1038 window_plus_caption_height = window->BltInfo.height + 2 * smCyFixedFrame + smCyCaption; 1039 1039 1040 1040 window->x = render_spu.defaultX; … … 1047 1047 window_style, 1048 1048 window->x, window->y, 1049 window-> width,1050 window-> height,1049 window->BltInfo.width, 1050 window->BltInfo.height, 1051 1051 (void*) render_spu_parent_window_id, NULL, hinstance, &render_spu );*/ 1052 1052 { … … 1061 1061 cs.x = window->x; 1062 1062 cs.y = window->y; 1063 cs.cx = window-> width;1064 cs.cy = window-> height;1063 cs.cx = window->BltInfo.width; 1064 cs.cy = window->BltInfo.height; 1065 1065 cs.hwndParent = (void*) render_spu_parent_window_id; 1066 1066 cs.hMenu = NULL; … … 1111 1111 { 1112 1112 renderspu_SystemShowWindow( window, 0 ); 1113 if (window-> height <= 0 || window->width <= 0)1113 if (window->BltInfo.height <= 0 || window->BltInfo.width <= 0) 1114 1114 { 1115 1115 renderspu_SystemWindowSize(window, 1116 window-> width > 0 ? window->width : 4,1117 window-> height > 0 ? window->height : 4);1116 window->BltInfo.width > 0 ? window->BltInfo.width : 4, 1117 window->BltInfo.height > 0 ? window->BltInfo.height : 4); 1118 1118 } 1119 1119 } … … 1128 1128 /* Intel drivers require a window to be visible for proper 3D rendering, 1129 1129 * so set it visible and handle the visibility with visible regions (see below) */ 1130 if (window-> id)1130 if (window->BltInfo.Base.id) 1131 1131 { 1132 1132 ShowWindow( window->hWnd, SW_SHOWNORMAL ); … … 1141 1141 1142 1142 SetWindowPos( window->hWnd, HWND_TOP, window->x, window->y, 1143 window-> width, window->height,1143 window->BltInfo.width, window->BltInfo.height, 1144 1144 ( render_spu.fullscreen ? 1145 1145 (SWP_SHOWWINDOW | SWP_NOSENDCHANGING | SWP_NOREDRAW | SWP_NOACTIVATE ) : SWP_NOACTIVATE 1146 1146 ) ); 1147 1147 crDebug("Render SPU: SetWindowPos (%x, %d, %d, %d, %d)", window->hWnd, 1148 window->x, window->y, window-> width, window->height);1148 window->x, window->y, window->BltInfo.width, window->BltInfo.height); 1149 1149 1150 1150 if ( render_spu.fullscreen ) … … 1183 1183 } 1184 1184 1185 void renderspu_SystemVBoxPresentComposition( WindowInfo *window, struct VBOXVR_SCR_COMPOSITOR * pCompositor, struct VBOXVR_SCR_COMPOSITOR_ENTRY *pChangedEntry ) 1186 { 1187 renderspuVBoxPresentCompositionGeneric(window, pCompositor, pChangedEntry); 1188 } 1189 1185 1190 GLboolean renderspu_SystemCreateContext( VisualInfo *visual, ContextInfo *context, ContextInfo *sharedContext ) 1186 1191 { … … 1222 1227 return GL_TRUE; 1223 1228 1224 CRASSERT(sharedContext-> id);1229 CRASSERT(sharedContext->BltInfo.Base.id); 1225 1230 1226 1231 if (sharedContext->shared) … … 1340 1345 1341 1346 /*Requery ext function pointers, we skip dummy ctx as it should never be used with ext functions*/ 1342 if (0 && context-> id)1347 if (0 && context->BltInfo.Base.id) 1343 1348 { 1344 1349 int numFuncs, i; … … 1399 1404 } 1400 1405 /* save the new size */ 1401 window-> width = w;1402 window-> height = h;1406 window->BltInfo.width = w; 1407 window->BltInfo.height = h; 1403 1408 } 1404 1409 … … 1442 1447 1443 1448 if (!SetWindowPos( window->hWnd, HWND_TOP, 1444 x, y, window-> width, window->height, winprop )) {1445 crWarning("!!!FAILED!!! Render SPU: SetWindowPos (%x, %d, %d, %d, %d)", window->hWnd, x, y, window-> width, window->height);1449 x, y, window->BltInfo.width, window->BltInfo.height, winprop )) { 1450 crWarning("!!!FAILED!!! Render SPU: SetWindowPos (%x, %d, %d, %d, %d)", window->hWnd, x, y, window->BltInfo.width, window->BltInfo.height); 1446 1451 } else { 1447 1452 crDebug("Render SPU: SetWindowPos (%x, %d, %d, %d, %d)", window->hWnd, 1448 x, y, window-> width, window->height);1453 x, y, window->BltInfo.width, window->BltInfo.height); 1449 1454 } 1450 1455 /* save the new position */ … … 1517 1522 LONG ws; 1518 1523 1519 hRgn1 = CreateRectRgn(0, 0, w-> width, w->height);1524 hRgn1 = CreateRectRgn(0, 0, w->BltInfo.width, w->BltInfo.height); 1520 1525 hRgn2 = CreateRectRgn(50, 50, 100, 100); 1521 1526 hRgn3 = CreateRectRgn(0, 0, 0, 0);
Note:
See TracChangeset
for help on using the changeset viewer.