Changeset 44784 in vbox for trunk/src/VBox/HostServices/SharedOpenGL
- Timestamp:
- Feb 21, 2013 2:56:31 PM (12 years ago)
- Location:
- trunk/src/VBox/HostServices/SharedOpenGL/render
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu.h
r44766 r44784 79 79 * Window info 80 80 */ 81 typedef struct {81 typedef struct WindowInfo { 82 82 int x, y; 83 83 // int width, height; -
trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu_cocoa.c
r44766 r44784 83 83 #endif /* __LP64__ */ 84 84 85 cocoaViewCreate(&pWinInfo->window, p ParentWin, pVisInfo->visAttribs);85 cocoaViewCreate(&pWinInfo->window, pWinInfo, pParentWin, pVisInfo->visAttribs); 86 86 87 87 if (fShowIt) -
trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu_cocoa_helper.h
r44740 r44784 26 26 RT_C_DECLS_BEGIN 27 27 28 struct WindowInfo; 29 28 30 ADD_COCOA_NATIVE_REF(NSView); 29 31 ADD_COCOA_NATIVE_REF(NSOpenGLContext); … … 34 36 35 37 /* View management */ 36 void cocoaViewCreate(NativeNSViewRef *ppView, NativeNSViewRef pParentView, GLbitfield fVisParams);38 void cocoaViewCreate(NativeNSViewRef *ppView, struct WindowInfo *pWinInfo, NativeNSViewRef pParentView, GLbitfield fVisParams); 37 39 void cocoaViewReparent(NativeNSViewRef pView, NativeNSViewRef pParentView); 38 40 void cocoaViewDestroy(NativeNSViewRef pView); -
trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu_cocoa_helper.m
r44766 r44784 28 28 29 29 #include <cr_vreg.h> 30 31 #include "renderspu.h" 30 32 31 33 /** @page pg_opengl_cocoa OpenGL - Cocoa Window System Helper … … 161 163 } \ 162 164 while(0); 163 164 static NSOpenGLContext *g_pVBoxCurrentContext = NULL; 165 #ifdef DEBUG 166 static NSView *g_pVBoxCurrentView = NULL; 167 #endif 165 168 166 169 167 static NSOpenGLContext * vboxCtxGetCurrent() 170 168 { 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) 169 GET_CONTEXT(pCtxInfo); 170 if (pCtxInfo) 184 171 { 185 172 #ifdef DEBUG 186 g_pVBoxCurrentView = [g_pVBoxCurrentContext view]; 173 NSOpenGLContext *pDbgCur = [NSOpenGLContext currentContext]; 174 Assert(pCtxInfo->context == pDbgCur); 175 if (pDbgCur) 176 { 177 NSView *pDbgView = [pDbgCur view]; 178 Assert(pCtxInfo->currentWindow->window == pDbgView); 179 } 187 180 #endif 188 [pCtx makeCurrentContext];181 return pCtxInfo->context; 189 182 } 190 else 183 184 #ifdef DEBUG 191 185 { 192 #ifdef DEBUG 193 g_pVBoxCurrentView = NULL; 186 NSOpenGLContext *pDbgCur = [NSOpenGLContext currentContext]; 187 Assert(!pDbgCur); 188 } 194 189 #endif 195 [NSOpenGLContext clearCurrentContext]; 196 } 190 return nil; 197 191 } 198 192 … … 252 246 NSPoint m_RootShift; 253 247 254 PVBOXVR_SCR_COMPOSITOR m_pCompositor; 248 WindowInfo *m_pWinInfo; 249 PVBOXVR_SCR_COMPOSITOR m_pCompositor; 255 250 bool m_fNeedViewportUpdate; 256 251 bool m_fNeedCtxUpdate; 257 252 } 258 - (id)initWithFrame:(NSRect)frame thread:(RTTHREAD)aThread parentView:(NSView*)pParentView ;253 - (id)initWithFrame:(NSRect)frame thread:(RTTHREAD)aThread parentView:(NSView*)pParentView winInfo:(WindowInfo*)pWinInfo; 259 254 - (void)setGLCtx:(NSOpenGLContext*)pCtx; 260 255 - (NSOpenGLContext*)glCtx; … … 277 272 - (void)makeCurrentFBO; 278 273 - (void)swapFBO; 279 - (void)tryDraw; 274 - (void)vboxTryDraw; 275 - (void)vboxTryDrawUI; 280 276 - (void)vboxPresent; 281 277 - (void)vboxPresentCS; … … 665 661 @implementation OverlayView 666 662 667 - (id)initWithFrame:(NSRect)frame thread:(RTTHREAD)aThread parentView:(NSView*)pParentView 663 - (id)initWithFrame:(NSRect)frame thread:(RTTHREAD)aThread parentView:(NSView*)pParentView winInfo:(WindowInfo*)pWinInfo 668 664 { 669 665 m_pParentView = pParentView; … … 678 674 m_Size = NSMakeSize(1, 1); 679 675 m_RootShift = NSZeroPoint; 680 m_pCompositor = NULL; 676 m_pWinInfo = pWinInfo; 677 m_pCompositor = nil; 681 678 m_fNeedViewportUpdate = true; 682 679 m_fNeedCtxUpdate = true; … … 724 721 - (void)drawRect:(NSRect)aRect 725 722 { 726 /* Do nothing */723 [self vboxTryDrawUI]; 727 724 } 728 725 … … 776 773 777 774 [self reshape]; 775 776 [self vboxTryDraw]; 778 777 } 779 778 … … 943 942 */ 944 943 { 945 vboxCtxSetCurrent(m_pGLCtx);944 [m_pGLCtx makeCurrentContext]; 946 945 CHECK_GL_ERROR(); 947 946 if (m_fNeedCtxUpdate == true) … … 961 960 } 962 961 963 - (void)tryDraw 964 { 962 - (void)vboxTryDraw 963 { 964 GLint opaque = 0; 965 965 if ([self lockFocusIfCanDraw]) 966 966 { 967 [self vboxPresent]; 967 bool fCompositorAquired = false; 968 if (!m_pSharedGLCtx) 969 { 970 m_pCompositor = renderspuVBoxCompositorAcquire(m_pWinInfo); 971 if (m_pCompositor) 972 { 973 fCompositorAquired = true; 974 /* Create a shared context out of the main context. Use the same pixel format. */ 975 m_pSharedGLCtx = [[NSOpenGLContext alloc] initWithFormat:[(OverlayOpenGLContext*)m_pGLCtx openGLPixelFormat] shareContext:m_pGLCtx]; 976 977 /* Set the new context as non opaque */ 978 [m_pSharedGLCtx setValues:&opaque forParameter:NSOpenGLCPSurfaceOpacity]; 979 /* Set this view as the drawable for the new context */ 980 [m_pSharedGLCtx setView: self]; 981 m_fNeedViewportUpdate = true; 982 } 983 } 984 985 if (m_pSharedGLCtx) 986 { 987 if (!fCompositorAquired) 988 { 989 /* we do not want to be blocked with the GUI thread here, so only draw her eif we are really able to do that w/o bllocking */ 990 int rc = renderspuVBoxCompositorTryAcquire(m_pWinInfo, &m_pCompositor); 991 if (RT_SUCCESS(rc)) 992 { 993 fCompositorAquired = true; 994 } 995 else if (rc != VERR_SEM_BUSY) 996 { 997 glFlush(); 998 /* issue to the gui thread */ 999 [self setNeedsDisplay:YES]; 1000 } 1001 else 1002 { 1003 /* this is somewhat we do not expect */ 1004 DEBUG_MSG(("renderspuVBoxCompositorTryAcquire failed rc %d", rc)); 1005 } 1006 } 1007 1008 if (fCompositorAquired) 1009 { 1010 Assert(m_pCompositor); 1011 [self vboxPresent]; 1012 renderspuVBoxCompositorRelease(m_pWinInfo); 1013 } 1014 } 1015 else 1016 { 1017 AssertRelease(!fCompositorAquired); 1018 } 968 1019 [self unlockFocus]; 969 1020 } 970 1021 } 971 1022 1023 - (void)vboxTryDrawUI 1024 { 1025 if ([self lockFocusIfCanDraw]) 1026 { 1027 if (m_pSharedGLCtx) 1028 { 1029 m_pCompositor = renderspuVBoxCompositorAcquire(m_pWinInfo); 1030 if (m_pCompositor) 1031 { 1032 [self vboxPresent]; 1033 renderspuVBoxCompositorRelease(m_pWinInfo); 1034 } 1035 } 1036 [self unlockFocus]; 1037 } 1038 } 1039 972 1040 - (void)swapFBO 973 1041 { … … 977 1045 - (void)vboxPresent 978 1046 { 979 GLint opaque = 0;980 981 1047 DEBUG_MSG(("OVIW(%p): renderFBOToView\n", (void*)self)); 982 1048 983 if (!m_pCompositor) 984 return; 985 986 #ifdef DEBUG 987 { 988 NSOpenGLContext *pTstOldCtx = [NSOpenGLContext currentContext]; 989 NSView *pTstOldView = (pTstOldCtx ? [pTstOldCtx view] : nil); 990 Assert(pTstOldCtx == m_pGLCtx); 991 Assert(pTstOldView == self); 992 } 993 #endif 994 995 if (!m_pSharedGLCtx) 996 { 997 /* Create a shared context out of the main context. Use the same pixel format. */ 998 m_pSharedGLCtx = [[NSOpenGLContext alloc] initWithFormat:[(OverlayOpenGLContext*)m_pGLCtx openGLPixelFormat] shareContext:m_pGLCtx]; 999 1000 /* Set the new context as non opaque */ 1001 [m_pSharedGLCtx setValues:&opaque forParameter:NSOpenGLCPSurfaceOpacity]; 1002 /* Set this view as the drawable for the new context */ 1003 [m_pSharedGLCtx setView: self]; 1004 m_fNeedViewportUpdate = true; 1005 } 1049 Assert(m_pCompositor); 1006 1050 1007 #if def DEBUG1051 #if 0 //def DEBUG 1008 1052 { 1009 1053 NSOpenGLContext *pTstOldCtx = [NSOpenGLContext currentContext]; … … 1103 1147 bool fNeedCtxSwitch = (pOldCtx != pCtx || pOldView != pView); 1104 1148 Assert(pCtx); 1105 Assert(pOldCtx == m_pGLCtx);1106 Assert(pOldView == self);1107 Assert(fNeedCtxSwitch);1149 // Assert(pOldCtx == m_pGLCtx); 1150 // Assert(pOldView == self); 1151 // Assert(fNeedCtxSwitch); 1108 1152 if (fNeedCtxSwitch) 1109 1153 { … … 1111 1155 glFlush(); 1112 1156 1113 vboxCtxSetCurrent(pCtx);1157 [pCtx makeCurrentContext]; 1114 1158 } 1115 1159 … … 1126 1170 } 1127 1171 1128 vboxCtxSetCurrent(pOldCtx);1172 [pOldCtx makeCurrentContext]; 1129 1173 1130 1174 #ifdef DEBUG … … 1146 1190 - (void)presentComposition:(PVBOXVR_SCR_COMPOSITOR)pCompositor withChangedEntry:(PVBOXVR_SCR_COMPOSITOR_ENTRY)pChangedEntry 1147 1191 { 1148 m_pCompositor = pCompositor; 1149 1150 [self tryDraw]; 1192 [self vboxTryDraw]; 1151 1193 } 1152 1194 … … 1278 1320 memcpy(m_paClipRects, paRects, sizeof(GLint) * 4 * cRects); 1279 1321 } 1280 #if 0 1281 /* todo: handle pending m_fNeedCtxUpdate */ 1282 else if (cOldRects) 1283 [self tryDraw]; 1284 #endif 1322 1323 [self vboxTryDraw]; 1285 1324 } 1286 1325 … … 1431 1470 * 1432 1471 ********************************************************************************/ 1433 void cocoaViewCreate(NativeNSViewRef *ppView, NativeNSViewRef pParentView, GLbitfield fVisParams)1472 void cocoaViewCreate(NativeNSViewRef *ppView, WindowInfo *pWinInfo, NativeNSViewRef pParentView, GLbitfield fVisParams) 1434 1473 { 1435 1474 NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init]; 1436 1475 1437 1476 /* Create our worker view */ 1438 OverlayView* pView = [[OverlayView alloc] initWithFrame:NSZeroRect thread:RTThreadSelf() parentView:pParentView ];1477 OverlayView* pView = [[OverlayView alloc] initWithFrame:NSZeroRect thread:RTThreadSelf() parentView:pParentView winInfo:pWinInfo]; 1439 1478 1440 1479 if (pView) … … 1600 1639 else 1601 1640 { 1602 vboxCtxSetCurrent(NULL);1641 [NSOpenGLContext clearCurrentContext]; 1603 1642 } 1604 1643
Note:
See TracChangeset
for help on using the changeset viewer.