Changeset 18721 in vbox for trunk/src/VBox/HostServices
- Timestamp:
- Apr 5, 2009 5:10:16 PM (16 years ago)
- Location:
- trunk/src/VBox/HostServices/SharedOpenGL/render
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu.h
r18637 r18721 27 27 28 28 #define MAX_VISUALS 32 29 30 #ifdef RT_OS_DARWIN 31 enum 32 { 33 /* Event classes */ 34 kEventClassVBox = 'vbox', 35 /* Event kinds */ 36 kEventVBoxShowWindow = 'swin', 37 kEventVBoxHideWindow = 'hwin', 38 kEventVBoxMoveWindow = 'mwin', 39 kEventVBoxResizeWindow = 'rwin', 40 kEventVBoxDisposeWindow = 'dwin', 41 kEventVBoxUpdateDock = 'udck', 42 kEventVBoxUpdateContext = 'uctx', 43 kEventVBoxBoundsChanged = 'bchg' 44 }; 45 pascal OSStatus windowEvtHndlr(EventHandlerCallRef myHandler, EventRef event, void* userData); 46 #endif /* RT_OS_DARWIN */ 29 47 30 48 /** … … 198 216 #endif 199 217 200 #ifdef DARWIN218 #ifdef RT_OS_DARWIN 201 219 RgnHandle hRootVisibleRegion; 202 #endif 220 RTSEMFASTMUTEX syncMutex; 221 EventHandlerUPP hParentEventHandler; 222 WindowGroupRef pParentGroup; 223 WindowGroupRef pMasterGroup; 224 GLint currentBufferName; 225 uint64_t uiDockUpdateTS; 226 #endif /* RT_OS_DARWIN */ 203 227 } RenderSPU; 204 228 -
trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu_agl.c
r18680 r18721 11 11 #include <iprt/time.h> 12 12 #include <iprt/assert.h> 13 #include <iprt/semaphore.h> 13 14 14 15 #include <stdio.h> … … 19 20 #include "cr_mem.h" 20 21 #include "renderspu.h" 21 22 /* Some necessary global defines */23 WindowGroupRef gParentGroup = NULL;24 WindowGroupRef gMasterGroup = NULL;25 GLint gCurrentBufferName = 1;26 uint64_t gDockUpdateTS = 0;27 static EventHandlerUPP gParentEventHandler = NULL;28 29 enum30 {31 /* Event classes */32 kEventClassVBox = 'vbox',33 /* Event kinds */34 kEventVBoxShowWindow = 'swin',35 kEventVBoxHideWindow = 'hwin',36 kEventVBoxMoveWindow = 'mwin',37 kEventVBoxResizeWindow = 'rwin',38 kEventVBoxDisposeWindow = 'dwin',39 kEventVBoxUpdateDock = 'udck',40 kEventVBoxUpdateContext = 'uctx',41 kEventVBoxBoundsChanged = 'bchg'42 };43 22 44 23 #ifdef __LP64__ /** @todo port to 64-bit darwin. */ … … 104 83 context->context) 105 84 { 106 OSStatus result = render_spu.ws.aglSetCurrentContext(context->context); 107 CHECK_AGL_RC (result, "Render SPU (renderspuWindowAttachContext): SetCurrentContext Failed"); 108 result = render_spu.ws.aglUpdateContext(context->context); 109 CHECK_AGL_RC (result, "Render SPU (renderspuWindowAttachContext): UpdateContext Failed"); 110 /* Update the clipping region */ 111 renderspu_SystemWindowApplyVisibleRegion(pWin); 85 RTSemFastMutexRequest(render_spu.syncMutex); 86 GLboolean result = render_spu.ws.aglSetCurrentContext(context->context); 87 CHECK_AGL_RC (result, "Render SPU (crClipRootHelper): SetCurrentContext Failed"); 88 if (result) 89 { 90 result = render_spu.ws.aglUpdateContext(context->context); 91 CHECK_AGL_RC (result, "Render SPU (crClipRootHelper): UpdateContext Failed"); 92 /* Update the clipping region */ 93 renderspu_SystemWindowApplyVisibleRegion(pWin); 94 } 95 RTSemFastMutexRelease(render_spu.syncMutex); 112 96 /* Make sure that the position is updated relative to the Qt main 113 97 * view */ … … 118 102 119 103 /* Window event handler */ 120 staticpascal OSStatus104 pascal OSStatus 121 105 windowEvtHndlr(EventHandlerCallRef myHandler, EventRef event, void* userData) 122 106 { 123 107 WindowRef window = NULL; 124 OSStatus result = eventNotHandledErr;108 OSStatus eventResult = eventNotHandledErr; 125 109 UInt32 class = GetEventClass (event); 126 110 UInt32 kind = GetEventKind (event); 127 111 112 /* Fetch the sender of the event */ 128 113 GetEventParameter(event, kEventParamDirectObject, typeWindowRef, 129 114 NULL, sizeof(WindowRef), NULL, &window); … … 136 121 case kEventVBoxUpdateContext: 137 122 { 138 #ifndef __LP64__ /** @todo port to 64-bit darwin! Need to c ehck if this event is generated or not (it probably isn't). */123 #ifndef __LP64__ /** @todo port to 64-bit darwin! Need to check if this event is generated or not (it probably isn't). */ 139 124 WindowInfo *wi1; 140 125 GetEventParameter(event, kEventParamUserData, typeVoidPtr, 141 126 NULL, sizeof(wi1), NULL, &wi1); 142 127 ContextInfo *context = renderspuGetWindowContext(wi1); 143 GLboolean result1 = true;144 128 if (context && 145 129 context->context) 146 130 { 147 DEBUG_MSG_POETZSCH (("kEventVBoxUpdateContext %x %x\n", window, context->context)); 148 result1 = render_spu.ws.aglSetCurrentContext(context->context); 149 result1 = render_spu.ws.aglUpdateContext(context->context); 150 CHECK_AGL_RC (result, "Render SPU (windowEvtHndlr): UpdateContext Failed"); 151 //glFlush(); 131 AGLContext tmpContext = render_spu.ws.aglGetCurrentContext(); 132 DEBUG_MSG_POETZSCH (("kEventVBoxUpdateContext %x %x\n", wi1, context->context)); 133 RTSemFastMutexRequest(render_spu.syncMutex); 134 GLboolean result = render_spu.ws.aglSetCurrentContext(context->context); 135 if (result) 136 { 137 result = render_spu.ws.aglUpdateContext(context->context); 138 CHECK_AGL_RC (result, "Render SPU (windowEvtHndlr): UpdateContext Failed"); 139 renderspu_SystemWindowApplyVisibleRegion(wi1); 140 /* Reapply the last active context */ 141 if (tmpContext) 142 { 143 result = render_spu.ws.aglSetCurrentContext(tmpContext); 144 CHECK_AGL_RC (result, "Render SPU (windowEvtHndlr): SetCurrentContext Failed"); 145 if (result) 146 { 147 result = render_spu.ws.aglUpdateContext(tmpContext); 148 CHECK_AGL_RC (result, "Render SPU (windowEvtHndlr): UpdateContext Failed"); 149 } 150 } 151 } 152 RTSemFastMutexRelease(render_spu.syncMutex); 152 153 } 153 result = noErr;154 eventResult = noErr; 154 155 #endif 155 156 break; … … 157 158 case kEventVBoxBoundsChanged: 158 159 { 159 #ifndef __LP64__ /** @todo port to 64-bit darwin! Need to c ehck if this event is generated or not (it probably isn't). */160 #ifndef __LP64__ /** @todo port to 64-bit darwin! Need to check if this event is generated or not (it probably isn't). */ 160 161 HIPoint p; 161 162 GetEventParameter(event, kEventParamOrigin, typeHIPoint, … … 170 171 r.size.width, 171 172 r.size.height }; 172 renderspu_SystemSetRootVisibleRegion(1, &l);173 173 /* Update the root window clip region */ 174 renderspu_SystemSetRootVisibleRegion(1, l); 174 175 /* Temporary save the current active context */ 175 176 AGLContext tmpContext = render_spu.ws.aglGetCurrentContext(); … … 178 179 if (tmpContext) 179 180 { 180 OSStatus result = render_spu.ws.aglSetCurrentContext(tmpContext); 181 RTSemFastMutexRequest(render_spu.syncMutex); 182 GLboolean result = render_spu.ws.aglSetCurrentContext(tmpContext); 181 183 CHECK_AGL_RC (result, "Render SPU (windowEvtHndlr): SetCurrentContext Failed"); 182 result = render_spu.ws.aglUpdateContext(tmpContext); 183 CHECK_AGL_RC (result, "Render SPU (windowEvtHndlr): UpdateContext Failed"); 184 if (result) 185 { 186 result = render_spu.ws.aglUpdateContext(tmpContext); 187 CHECK_AGL_RC (result, "Render SPU (windowEvtHndlr): UpdateContext Failed"); 188 } 189 RTSemFastMutexRelease(render_spu.syncMutex); 184 190 } 191 eventResult = noErr; 185 192 #endif 186 193 break; … … 192 199 }; 193 200 194 return result;201 return eventResult; 195 202 } 196 203 … … 360 367 #endif 361 368 /* New global buffer name */ 362 wi->bufferName = gCurrentBufferName++;369 wi->bufferName = render_spu.currentBufferName++; 363 370 /* Set the new buffer name to the dummy context. This enable the 364 371 * sharing of the same hardware buffer afterwards. */ … … 379 386 newDrawable = (AGLDrawable) GetWindowPort(window); 380 387 #endif 388 RTSemFastMutexRequest(render_spu.syncMutex); 381 389 /* Only switch the context if the drawable has changed */ 382 390 if (oldDrawable != newDrawable) … … 396 404 #endif 397 405 CHECK_AGL_RC (result, "Render SPU (renderspuWindowAttachContext): SetDrawable Failed"); 398 renderspuSetWindowContext( window, context);406 renderspuSetWindowContext(window, context); 399 407 } 400 408 result = render_spu.ws.aglSetCurrentContext(context->context); … … 402 410 result = render_spu.ws.aglUpdateContext(context->context); 403 411 CHECK_AGL_RC (result, "Render SPU (renderspuWindowAttachContext): UpdateContext Failed"); 412 RTSemFastMutexRelease(render_spu.syncMutex); 404 413 405 414 return result; … … 448 457 window->hVisibleRegion = 0; 449 458 } 459 } 460 461 void 462 renderspu_SystemWindowPosition(WindowInfo *window, 463 GLint x, GLint y) 464 { 465 CRASSERT(window); 466 CRASSERT(window->window); 467 468 OSStatus status = noErr; 469 /* Send a event to the main thread, cause some function of Carbon aren't 470 * thread safe */ 471 EventRef evt; 472 status = CreateEvent(NULL, kEventClassVBox, kEventVBoxMoveWindow, 0, kEventAttributeNone, &evt); 473 CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU (renderspu_SystemWindowPosition): CreateEvent Failed"); 474 status = SetEventParameter(evt, kEventParamWindowRef, typeWindowRef, sizeof(window->window), &window->window); 475 CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU (renderspu_SystemWindowPosition): SetEventParameter Failed"); 476 HIPoint p = CGPointMake (x, y); 477 status = SetEventParameter(evt, kEventParamOrigin, typeHIPoint, sizeof (p), &p); 478 CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU (renderspu_SystemWindowPosition): SetEventParameter Failed"); 479 status = SetEventParameter(evt, kEventParamUserData, typeVoidPtr, sizeof (window), &window); 480 CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU (renderspu_SystemWindowPosition): SetEventParameter Failed"); 481 status = PostEventToQueue(GetMainEventQueue(), evt, kEventPriorityStandard); 482 CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU (renderspu_SystemWindowPosition): PostEventToQueue Failed"); 483 484 /* save the new pos */ 485 window->x = x; 486 window->y = y; 450 487 } 451 488 … … 517 554 } 518 555 519 void520 renderspu_SystemWindowPosition(WindowInfo *window,521 GLint x, GLint y)522 {523 CRASSERT(window);524 CRASSERT(window->window);525 526 OSStatus status = noErr;527 /* Send a event to the main thread, cause some function of Carbon aren't528 * thread safe */529 EventRef evt;530 status = CreateEvent(NULL, kEventClassVBox, kEventVBoxMoveWindow, 0, kEventAttributeNone, &evt);531 CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU (renderspu_SystemWindowPosition): CreateEvent Failed");532 status = SetEventParameter(evt, kEventParamWindowRef, typeWindowRef, sizeof(window->window), &window->window);533 CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU (renderspu_SystemWindowPosition): SetEventParameter Failed");534 HIPoint p = CGPointMake (x, y);535 status = SetEventParameter(evt, kEventParamOrigin, typeHIPoint, sizeof (p), &p);536 CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU (renderspu_SystemWindowPosition): SetEventParameter Failed");537 status = SetEventParameter(evt, kEventParamUserData, typeVoidPtr, sizeof (window), &window);538 CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU (renderspu_SystemWindowPosition): SetEventParameter Failed");539 status = PostEventToQueue(GetMainEventQueue(), evt, kEventPriorityStandard);540 CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU (renderspu_SystemWindowPosition): PostEventToQueue Failed");541 542 /* save the new pos */543 window->x = x;544 window->y = y;545 }546 547 556 /* Either show or hide the render SPU's window. */ 548 557 void … … 583 592 CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU (renderspu_SystemShowWindow): PostEventToQueue Failed"); 584 593 } 585 594 /* Save the new value */ 586 595 window->visible = showIt; 587 596 } … … 631 640 } 632 641 } 642 /* Reapply the visible regions */ 643 renderspu_SystemWindowApplyVisibleRegion(window); 633 644 } 634 645 else … … 647 658 crError("Render SPU (renderspu_SystemSwapBuffers): SwapBuffers got a null context from the window"); 648 659 660 RTSemFastMutexRequest(render_spu.syncMutex); 649 661 // DEBUG_MSG_POETZSCH (("Swapped %d context %x visible: %d\n", window->id, context->context, IsWindowVisible (window->window))); 650 662 if (context->visual && … … 653 665 else 654 666 glFlush(); 667 RTSemFastMutexRelease(render_spu.syncMutex); 655 668 656 669 /* This method seems called very often. To prevent the dock using all free 657 670 * resources we update the dock only two times per second. */ 658 671 uint64_t curTS = RTTimeMilliTS(); 659 if ((curTS - gDockUpdateTS) > 500)672 if ((curTS - render_spu.uiDockUpdateTS) > 500) 660 673 { 661 674 OSStatus status = noErr; … … 668 681 CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU (renderspu_SystemSwapBuffers): PostEventToQueue Failed"); 669 682 670 gDockUpdateTS = curTS;683 render_spu.uiDockUpdateTS = curTS; 671 684 } 672 685 } … … 677 690 CRASSERT(window->window); 678 691 679 DEBUG_MSG_POETZSCH (("Visible region \n")); 680 692 /* Remember any additional clipping stuff e.g. seamless regions */ 681 693 if (window->hVisibleRegion) 682 694 { … … 697 709 pRects[4*i] , pRects[4*i+1], 698 710 pRects[4*i+2], pRects[4*i+3]); 699 DEBUG_MSG_POETZSCH (("visible rect %d %d %d %d\n", pRects[4*i] , pRects[4*i+1],700 pRects[4*i+2], pRects[4*i+3]));711 //DEBUG_MSG_POETZSCH (("visible rect %d %d %d %d\n", pRects[4*i] , pRects[4*i+1], 712 // pRects[4*i+2], pRects[4*i+3])); 701 713 UnionRgn (rgn, tmpRgn, rgn); 702 714 } … … 710 722 void renderspu_SystemSetRootVisibleRegion(GLint cRects, GLint *pRects) 711 723 { 724 /* Remember the visible region of the root window if there is one */ 712 725 if (render_spu.hRootVisibleRegion) 713 726 { … … 740 753 GLboolean result = true; 741 754 755 DEBUG_MSG_POETZSCH (("ApplyVisibleRegion %x\n", window)); 756 742 757 if (!c || !c->context) return; 743 758 744 759 rgn = NewRgn(); 745 SetEmptyRgn 760 SetEmptyRgn(rgn); 746 761 747 762 if (render_spu.hRootVisibleRegion) 748 763 { 749 CopyRgn(render_spu.hRootVisibleRegion, rgn); 750 } 751 else /*@todo create tmp region rect with size of underlying framebuffer */ 752 { 753 /* SetRectRgn(0,0,fb->width,fb->height); */ 754 SetRectRgn(rgn,0,0,4000,4000); 755 } 756 764 /* The render_spu.hRootVisibleRegion has coordinates from the root 765 * window. We intersect it with the rect of the OpenGL window we 766 * currently process. */ 767 SetRectRgn(rgn, 768 window->x, window->y, 769 window->x + window->width, 770 window->y + window->height); 771 SectRgn(render_spu.hRootVisibleRegion, rgn, rgn); 772 /* Because the clipping is done in the coodinate space of the OpenGL 773 * window we have to remove the x/y position from the newly created 774 * region. */ 775 OffsetRgn (rgn, -window->x, -window->y); 776 } 777 else 778 { 779 /* If there is not root clipping region is available, create a base 780 * region with the size of the target window. This covers all 781 * needed/possible space. */ 782 SetRectRgn(rgn, 0, 0, window->width, window->height); 783 } 784 785 /* Now intersect the window clipping region with a additional region e.g. 786 * for the seamless mode. */ 757 787 if (window->hVisibleRegion) 758 {759 788 SectRgn(rgn, window->hVisibleRegion, rgn); 760 }761 762 /* If we'd need to set clip region in host screen coordinates, than shift it*/763 /* OffsetRgn(rgn, fb->hostleft, fb->hosttop); */764 789 765 790 /* Set the clip region to the context */ … … 813 838 CFRelease(title_string); 814 839 815 /* We need grouping so create a master group for this & all following816 * windows & one group for the parent. */817 if(!gMasterGroup || !gParentGroup)818 {819 status = CreateWindowGroup(kWindowGroupAttrMoveTogether | kWindowGroupAttrLayerTogether | kWindowGroupAttrSharedActivation | kWindowGroupAttrHideOnCollapse | kWindowGroupAttrFixedLevel, &gMasterGroup);820 CHECK_CARBON_RC_RETURN (status, "Render SPU (renderspu_SystemVBoxCreateWindow): CreateWindowGroup Failed", GL_FALSE);821 status = CreateWindowGroup(kWindowGroupAttrMoveTogether | kWindowGroupAttrLayerTogether | kWindowGroupAttrSharedActivation | kWindowGroupAttrHideOnCollapse | kWindowGroupAttrFixedLevel, &gParentGroup);822 CHECK_CARBON_RC_RETURN (status, "Render SPU (renderspu_SystemVBoxCreateWindow): CreateWindowGroup Failed", GL_FALSE);823 /* Make the correct z-layering */824 SendWindowGroupBehind (gParentGroup, gMasterGroup);825 /* and set the gParentGroup as parent for gMasterGroup. */826 #ifdef __LP64__ /** @todo port to 64-bit darwin. */827 #else828 SetWindowGroupParent (gMasterGroup, gParentGroup);829 #endif830 }831 832 840 /* The parent has to be in its own group */ 833 841 WindowRef parent = NULL; … … 835 843 { 836 844 parent = HIViewGetWindow ((HIViewRef)render_spu_parent_window_id); 837 SetWindowGroup (parent, gParentGroup); 838 839 /* We need to process events from our main window */ 840 if(!gParentEventHandler) 841 { 842 /* Install the event handlers */ 843 EventTypeSpec eventList[] = 844 { 845 {kEventClassVBox, kEventVBoxUpdateContext}, /* Update the context after show/size/move events */ 846 {kEventClassVBox, kEventVBoxBoundsChanged} /* Clip/Pos the OpenGL windows when the main window is changed in pos/size */ 847 }; 848 849 gParentEventHandler = NewEventHandlerUPP(windowEvtHndlr); 850 InstallApplicationEventHandler (gParentEventHandler, 851 GetEventTypeCount(eventList), eventList, 852 NULL, NULL); 853 } 854 } 845 SetWindowGroup (parent, render_spu.pParentGroup); 846 847 } 848 855 849 /* Add the new window to the master group */ 856 SetWindowGroup(window->window, gMasterGroup);850 SetWindowGroup(window->window, render_spu.pMasterGroup); 857 851 858 852 /* This will be initialized on the first attempt to attach the global … … 860 854 window->bufferName = -1; 861 855 window->dummyContext = NULL; 856 window->hVisibleRegion = 0; 862 857 863 858 if(showIt) -
trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu_init.c
r18637 r18721 12 12 #include "renderspu.h" 13 13 #include <stdio.h> 14 15 #ifdef RT_OS_DARWIN 16 # include <iprt/semaphore.h> 17 #endif /* RT_OS_DARWIN */ 14 18 15 19 static SPUNamedFunctionTable _cr_render_table[1000]; … … 210 214 211 215 #ifdef DARWIN 216 # ifndef __LP64__ /** @todo port to 64-bit darwin. */ 212 217 render_spu.hRootVisibleRegion = 0; 213 #endif 218 render_spu.currentBufferName = 1; 219 render_spu.uiDockUpdateTS = 0; 220 /* Create a mutex for syncronizing events from the main Qt thread & this 221 thread */ 222 RTSemFastMutexCreate(&render_spu.syncMutex); 223 /* Create our window groups */ 224 CreateWindowGroup(kWindowGroupAttrMoveTogether | kWindowGroupAttrLayerTogether | kWindowGroupAttrSharedActivation | kWindowGroupAttrHideOnCollapse | kWindowGroupAttrFixedLevel, &render_spu.pMasterGroup); 225 CreateWindowGroup(kWindowGroupAttrMoveTogether | kWindowGroupAttrLayerTogether | kWindowGroupAttrSharedActivation | kWindowGroupAttrHideOnCollapse | kWindowGroupAttrFixedLevel, &render_spu.pParentGroup); 226 /* Make the correct z-layering */ 227 SendWindowGroupBehind (render_spu.pParentGroup, render_spu.pMasterGroup); 228 /* and set the gParentGroup as parent for gMasterGroup. */ 229 SetWindowGroupParent (render_spu.pMasterGroup, render_spu.pParentGroup); 230 /* Install the event handlers */ 231 EventTypeSpec eventList[] = 232 { 233 {kEventClassVBox, kEventVBoxUpdateContext}, /* Update the context after show/size/move events */ 234 {kEventClassVBox, kEventVBoxBoundsChanged} /* Clip/Pos the OpenGL windows when the main window is changed in pos/size */ 235 }; 236 /* We need to process events from our main window */ 237 render_spu.hParentEventHandler = NewEventHandlerUPP(windowEvtHndlr); 238 InstallApplicationEventHandler (render_spu.hParentEventHandler, 239 GetEventTypeCount(eventList), eventList, 240 NULL, NULL); 241 # endif /* !__LP64__ */ 242 #endif /* DARWIN */ 214 243 215 244 /* … … 331 360 332 361 #ifdef RT_OS_DARWIN 362 DisposeEventHandlerUPP(render_spu.hParentEventHandler); 363 ReleaseWindowGroup(render_spu.pMasterGroup); 364 ReleaseWindowGroup(render_spu.pParentGroup); 333 365 if (render_spu.hRootVisibleRegion) 334 366 { … … 336 368 render_spu.hRootVisibleRegion = 0; 337 369 } 338 #endif 370 render_spu.currentBufferName = 1; 371 render_spu.uiDockUpdateTS = 0; 372 RTSemFastMutexDestroy(render_spu.syncMutex); 373 #endif /* RT_OS_DARWIN */ 339 374 340 375 #ifdef RT_OS_WINDOWS
Note:
See TracChangeset
for help on using the changeset viewer.