Changeset 53556 in vbox for trunk/src/VBox
- Timestamp:
- Dec 17, 2014 12:21:43 AM (10 years ago)
- Location:
- trunk/src/VBox/HostServices/SharedOpenGL/render
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu_cocoa_helper.h
r51442 r53556 5 5 6 6 /* 7 * Copyright (C) 2009-201 2Oracle Corporation7 * Copyright (C) 2009-2014 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 33 33 ADD_COCOA_NATIVE_REF(NSOpenGLContext); 34 34 35 /* OpenGL context management */ 35 /** @name OpenGL context management 36 * @{ */ 36 37 void cocoaGLCtxCreate(NativeNSOpenGLContextRef *ppCtx, GLbitfield fVisParams, NativeNSOpenGLContextRef pSharedCtx); 37 38 void cocoaGLCtxDestroy(NativeNSOpenGLContextRef pCtx); 39 /** @} */ 38 40 39 /* View management */ 41 /** @name View management 42 * @{ */ 40 43 void cocoaViewCreate(NativeNSViewRef *ppView, struct WindowInfo *pWinInfo, NativeNSViewRef pParentView, GLbitfield fVisParams); 41 44 void cocoaViewReparent(NativeNSViewRef pView, NativeNSViewRef pParentView); … … 44 47 void cocoaViewShow(NativeNSViewRef pView, GLboolean fShowIt); 45 48 void cocoaViewSetPosition(NativeNSViewRef pView, NativeNSViewRef pParentView, int x, int y); 46 void cocoaViewSetSize(NativeNSViewRef pView, int w, int h); 47 void cocoaViewGetGeometry(NativeNSViewRef pView, int *pX, int *pY, int *pW, int *pH); 48 49 void cocoaViewSetSize(NativeNSViewRef pView, int cx, int cy); 50 void cocoaViewGetGeometry(NativeNSViewRef pView, int *px, int *py, int *pcx, int *pcy); 49 51 void cocoaViewMakeCurrentContext(NativeNSViewRef pView, NativeNSOpenGLContextRef pCtx); 50 void cocoaViewSetVisibleRegion(NativeNSViewRef pView, GLint cRects, const GLint *paRects);52 void cocoaViewSetVisibleRegion(NativeNSViewRef pView, GLint cRects, const GLint *paRects); 51 53 GLboolean cocoaViewNeedsEmptyPresent(NativeNSViewRef pView); 52 54 void cocoaViewPresentComposition(NativeNSViewRef pView, const struct VBOXVR_SCR_COMPOSITOR_ENTRY *pChangedEntry); 55 /** @} */ 53 56 54 57 RT_C_DECLS_END -
trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu_cocoa_helper.m
r52625 r53556 15 15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. 16 16 */ 17 18 #include "renderspu_cocoa_helper.h"19 20 #import <Cocoa/Cocoa.h>21 #undef PVM22 23 #include "chromium.h" /* For the visual bits of chromium */24 25 #include <iprt/thread.h>26 #include <iprt/string.h>27 #include <iprt/mem.h>28 #include <iprt/time.h>29 #include <iprt/assert.h>30 #include <VBox/VBoxOGLTest.h>31 32 #include <cr_vreg.h>33 #include <cr_error.h>34 #include <cr_blitter.h>35 #ifdef VBOX_WITH_CRDUMPER_THUMBNAIL36 # include <cr_pixeldata.h>37 #endif38 39 40 #include "renderspu.h"41 17 42 18 /** @page pg_opengl_cocoa OpenGL - Cocoa Window System Helper … … 85 61 */ 86 62 63 /******************************************************************************* 64 * Header Files * 65 *******************************************************************************/ 66 #include "renderspu_cocoa_helper.h" 67 68 #import <Cocoa/Cocoa.h> 69 #undef PVM /* sys/param.h (included via Cocoa.h) pollutes the namespace with this define. */ 70 71 #include "chromium.h" /* For the visual bits of chromium */ 72 73 #include <iprt/thread.h> 74 #include <iprt/string.h> 75 #include <iprt/mem.h> 76 #include <iprt/time.h> 77 #include <iprt/assert.h> 78 #include <VBox/VBoxOGLTest.h> 79 80 #include <cr_vreg.h> 81 #include <cr_error.h> 82 #include <cr_blitter.h> 83 #ifdef VBOX_WITH_CRDUMPER_THUMBNAIL 84 # include <cr_pixeldata.h> 85 #endif 86 87 88 #include "renderspu.h" 89 90 91 /******************************************************************************* 92 * Defined Constants And Macros * 93 *******************************************************************************/ 87 94 /* Debug macros */ 88 #define FBO 1 /* Disable this to see how the output is without the FBO in the middle of the processing chain. */ 89 #if 0 90 # define CR_RENDER_FORCE_PRESENT_MAIN_THREAD /* force present schedule to main thread */ 91 # define SHOW_WINDOW_BACKGROUND 1 /* Define this to see the window background even if the window is clipped */ 92 # define DEBUG_VERBOSE /* Define this to get some debug info about the messages flow. */ 95 /** @def FBO 96 * Disable this to see how the output is without the FBO in the middle of the processing chain. */ 97 #define FBO 1 98 /** @def CR_RENDER_FORCE_PRESENT_MAIN_THREAD 99 * Force present schedule to main thread. */ 100 /** @def SHOW_WINDOW_BACKGROUND 101 * Define this to see the window background even if the window is clipped. */ 102 /** @def DEBUG_VERBOSE 103 * Define this to get some debug info about the messages flow. */ 104 #if 0 || defined(DOXYGEN_RUNNING) 105 # define CR_RENDER_FORCE_PRESENT_MAIN_THREAD 106 # define SHOW_WINDOW_BACKGROUND 1 107 # define DEBUG_VERBOSE 93 108 #endif 94 109 … … 97 112 # define DEBUG_INFO(text) do { \ 98 113 crWarning text ; \ 99 Assert (0); \114 AssertFailed(); \ 100 115 } while (0) 101 102 # define DEBUG_MSG(text) \103 printf text104 116 105 117 # define DEBUG_WARN(text) do { \ 106 118 crWarning text ; \ 107 Assert (0); \119 AssertFailed(); \ 108 120 } while (0) 109 121 110 # define DEBUG_MSG _1(text) \111 DEBUG_MSG(text)122 # define DEBUG_MSG(text) do { printf text; } while (0) 123 # define DEBUG_MSG_1(text) do { printf text; } while (0) 112 124 113 125 #else … … 117 129 } while (0) 118 130 119 # define DEBUG_MSG(text) \120 do {} while (0)121 122 131 # define DEBUG_WARN(text) do { \ 123 132 crWarning text ; \ 124 133 } while (0) 125 134 126 # define DEBUG_MSG _1(text) \127 135 # define DEBUG_MSG(text) do {} while (0) 136 # define DEBUG_MSG_1(text) do {} while (0) 128 137 129 138 #endif 130 139 131 140 132 #define DEBUG_FUNC_ENTER() do { \ 133 DEBUG_MSG(("==>%s\n", __PRETTY_FUNCTION__)); \ 134 } while (0) 135 136 #define DEBUG_FUNC_LEAVE() do { \ 137 DEBUG_MSG(("<==%s\n", __PRETTY_FUNCTION__)); \ 138 } while (0) 139 140 141 #ifdef DEBUG_poetzsch 142 # define CHECK_GL_ERROR()\ 143 do \ 144 { \ 145 checkGLError(__FILE__, __LINE__); \ 146 }while (0); 147 148 static void checkGLError(char *file, int line) 149 { 150 GLenum g = glGetError(); 151 if (g != GL_NO_ERROR) 152 { 153 char *errStr; 154 switch (g) 155 { 156 case GL_INVALID_ENUM: errStr = RTStrDup("GL_INVALID_ENUM"); break; 157 case GL_INVALID_VALUE: errStr = RTStrDup("GL_INVALID_VALUE"); break; 158 case GL_INVALID_OPERATION: errStr = RTStrDup("GL_INVALID_OPERATION"); break; 159 case GL_STACK_OVERFLOW: errStr = RTStrDup("GL_STACK_OVERFLOW"); break; 160 case GL_STACK_UNDERFLOW: errStr = RTStrDup("GL_STACK_UNDERFLOW"); break; 161 case GL_OUT_OF_MEMORY: errStr = RTStrDup("GL_OUT_OF_MEMORY"); break; 162 case GL_TABLE_TOO_LARGE: errStr = RTStrDup("GL_TABLE_TOO_LARGE"); break; 163 default: errStr = RTStrDup("UNKNOWN"); break; 164 } 165 DEBUG_MSG(("%s:%d: glError %d (%s)\n", file, line, g, errStr)); 166 RTMemFree(errStr); 167 } 168 } 169 #else 170 # define CHECK_GL_ERROR()\ 171 do {} while (0) 172 #endif 173 174 #define GL_SAVE_STATE \ 175 do \ 176 { \ 141 #define DEBUG_FUNC_ENTER() DEBUG_MSG(("==>%s\n", __PRETTY_FUNCTION__)) 142 #define DEBUG_FUNC_LEAVE() DEBUG_MSG(("<==%s\n", __PRETTY_FUNCTION__)) 143 144 #define DEBUG_GL_SAVE_STATE() \ 145 do { \ 177 146 glPushAttrib(GL_ALL_ATTRIB_BITS); \ 178 147 glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS); \ … … 185 154 glMatrixMode(GL_MODELVIEW); \ 186 155 glPushMatrix(); \ 187 } \ 188 while(0); 189 190 #define GL_RESTORE_STATE \ 191 do \ 192 { \ 156 } while (0) 157 158 #define DEBUG_GL_RESTORE_STATE() \ 159 do { \ 193 160 glMatrixMode(GL_MODELVIEW); \ 194 161 glPopMatrix(); \ … … 201 168 glPopClientAttrib(); \ 202 169 glPopAttrib(); \ 203 } \ 204 while(0); 205 206 static NSOpenGLContext * vboxCtxGetCurrent() 170 } while (0) 171 172 #ifdef DEBUG_poetzsch 173 # define DEBUG_CHECK_GL_ERROR() do { checkGLError(__FILE__, __LINE__); } while (0); 174 static void checkGLError(char *pszFile, int iLine) 175 { 176 GLenum uGlErr = glGetError(); 177 if (uGlErr != GL_NO_ERROR) 178 { 179 const char *errStr; 180 switch (uGlErr) 181 { 182 case GL_INVALID_ENUM: errStr = "GL_INVALID_ENUM"; break; 183 case GL_INVALID_VALUE: errStr = "GL_INVALID_VALUE"; break; 184 case GL_INVALID_OPERATION: errStr = "GL_INVALID_OPERATION"; break; 185 case GL_STACK_OVERFLOW: errStr = "GL_STACK_OVERFLOW"; break; 186 case GL_STACK_UNDERFLOW: errStr = "GL_STACK_UNDERFLOW"; break; 187 case GL_OUT_OF_MEMORY: errStr = "GL_OUT_OF_MEMORY"; break; 188 case GL_TABLE_TOO_LARGE: errStr = "GL_TABLE_TOO_LARGE"; break; 189 default: errStr = "UNKNOWN"; break; 190 } 191 DEBUG_MSG(("%s:%d: glError %d (%s)\n", pszFile, iLine, uGlErr, errStr)); 192 } 193 } 194 #else 195 # define DEBUG_CHECK_GL_ERROR() do {} while (0) 196 #endif 197 198 199 200 static NSOpenGLContext *vboxCtxGetCurrent(void) 207 201 { 208 202 GET_CONTEXT(pCtxInfo); … … 216 210 } 217 211 218 static bool vboxCtxSyncCurrentInfo( )212 static bool vboxCtxSyncCurrentInfo(void) 219 213 { 220 214 GET_CONTEXT(pCtxInfo); … … 226 220 WindowInfo *pWinInfo = pCtxInfo->currentWindow; 227 221 Assert(pWinInfo); 228 if ( pCtxInfo->context != pCtx229 || pWinInfo->window != pView)222 if ( pCtxInfo->context != pCtx 223 || pWinInfo->window != pView) 230 224 { 231 225 renderspu_SystemMakeCurrent(pWinInfo, 0, pCtxInfo); … … 233 227 } 234 228 } 235 else 236 { 237 if (pCtx) 238 { 239 [NSOpenGLContext clearCurrentContext]; 240 fAdjusted = true; 241 } 229 else if (pCtx) 230 { 231 [NSOpenGLContext clearCurrentContext]; 232 fAdjusted = true; 242 233 } 243 234 … … 245 236 } 246 237 238 239 /** 240 * State carrying structure for use with vboxCtxEnter and vboxCtxLeave 241 */ 247 242 typedef struct VBOX_CR_RENDER_CTX_INFO 248 243 { 249 bool fIsValid; 250 NSOpenGLContext *pCtx; 251 NSView *pView; 252 } VBOX_CR_RENDER_CTX_INFO, *PVBOX_CR_RENDER_CTX_INFO; 253 254 static void vboxCtxEnter(NSOpenGLContext*pCtx, PVBOX_CR_RENDER_CTX_INFO pCtxInfo) 255 { 256 NSOpenGLContext *pOldCtx = vboxCtxGetCurrent(); 257 NSView *pOldView = (pOldCtx ? [pOldCtx view] : nil); 258 NSView *pView = [pCtx view]; 259 bool fNeedCtxSwitch = (pOldCtx != pCtx || pOldView != pView); 260 Assert(pCtx); 261 // Assert(pOldCtx == m_pGLCtx); 262 // Assert(pOldView == self); 263 // Assert(fNeedCtxSwitch); 264 if (fNeedCtxSwitch) 265 { 266 if(pOldCtx != nil) 244 bool fIsValid; 245 NSOpenGLContext *pCtx; 246 NSView *pView; 247 } VBOX_CR_RENDER_CTX_INFO; 248 /** Pointer to render context info for use with vboxCtxEnter/Leave. */ 249 typedef VBOX_CR_RENDER_CTX_INFO *PVBOX_CR_RENDER_CTX_INFO; 250 251 static void vboxCtxEnter(NSOpenGLContext *pNewCtx, PVBOX_CR_RENDER_CTX_INFO pCtxInfo) 252 { 253 NSOpenGLContext *pOldCtx = vboxCtxGetCurrent(); 254 NSView *pOldView = pOldCtx ? [pOldCtx view] : nil; 255 NSView *pNewView = [pNewCtx view]; 256 257 Assert(pNewCtx); 258 259 if ( pOldCtx != pNewCtx 260 || pOldView != pNewView) 261 { 262 if (pOldCtx != nil) 267 263 glFlush(); 268 264 269 [p Ctx makeCurrentContext];265 [pNewCtx makeCurrentContext]; 270 266 271 267 pCtxInfo->fIsValid = true; 272 pCtxInfo->pCtx = pOldCtx; 273 pCtxInfo->pView = pView; 268 pCtxInfo->pCtx = pOldCtx; 269 /** @todo r=bird: Why do we save the NEW VIEW here? vboxCtxLeave calls it 'pOldView'. Bug? */ 270 pCtxInfo->pView = pNewView; 274 271 } 275 272 else 276 273 { 274 /* No context switch necessary. */ 277 275 pCtxInfo->fIsValid = false; 278 276 } … … 283 281 if (pCtxInfo->fIsValid) 284 282 { 285 NSOpenGLContext *pOldCtx = pCtxInfo->pCtx;286 NSView *pOldView = pCtxInfo->pView;283 NSOpenGLContext *pOldCtx = pCtxInfo->pCtx; 284 NSView *pOldView = pCtxInfo->pView; 287 285 288 286 glFlush(); 289 287 if (pOldCtx != nil) 290 288 { 291 if ([pOldCtx view] != pOldView) 289 /* vboxCtxEnter saves the new view, not the old. So, what we actually 290 do here is switching the view of the old context to that of the new 291 one (wrt vboxCtxEnter) before making it current. */ 292 /** @todo r=bird: Figure out what we really want to do here, and either rename 293 * pOldView or fix the code. */ 294 if ([pOldCtx view] != pOldView) 292 295 { 293 296 [pOldCtx setView: pOldView]; … … 296 299 [pOldCtx makeCurrentContext]; 297 300 298 #ifdef DEBUG301 #ifdef VBOX_STRICT 299 302 { 300 NSOpenGLContext *pTstOldCtx = [NSOpenGLContext currentContext];301 NSView *pTstOldView = (pTstOldCtx ? [pTstOldCtx view] : nil);303 NSOpenGLContext *pTstOldCtx = [NSOpenGLContext currentContext]; 304 NSView *pTstOldView = pTstOldCtx ? [pTstOldCtx view] : nil; 302 305 Assert(pTstOldCtx == pOldCtx); 303 306 Assert(pTstOldView == pOldView); … … 312 315 } 313 316 314 /** Custom OpenGL context class. 317 318 /** 319 * Custom OpenGL context class. 315 320 * 316 * This implementation doesn't allow to set a view to the 317 * context, but save the view for later use. Also it saves a copy of the 318 * pixel format used to create that context for later use. */ 321 * This implementation doesn't allow to set a view to the context, but save the 322 * view for later use. Also it saves a copy of the pixel format used to create 323 * that context for later use. 324 */ 319 325 @interface OverlayOpenGLContext: NSOpenGLContext 320 326 { … … 323 329 NSView *m_pView; 324 330 } 325 - (NSOpenGLPixelFormat *)openGLPixelFormat;331 - (NSOpenGLPixelFormat *)openGLPixelFormat; 326 332 @end 327 333 334 /** 335 * Abstrack task class. 336 */ 328 337 @interface VBoxTask : NSObject 329 338 { … … 332 341 @end 333 342 343 @implementation VBoxTask 344 /** Run method that the child classes must reimplement. 345 * This will abort the process. */ 346 - (void)run 347 { 348 AssertReleaseFailed(); 349 } 350 @end 351 352 353 /** 354 * Generic task class for executing a given method select. 355 */ 334 356 @interface VBoxTaskPerformSelector : VBoxTask 335 357 { 336 358 @private 337 id m_Object;359 id m_Object; 338 360 SEL m_Selector; 339 id m_Arg;361 id m_Arg; 340 362 } 341 363 - (id)initWithObject:(id)aObject selector:(SEL)aSelector arg:(id)aArg; … … 344 366 @end 345 367 346 #if 0347 typedef DECLCALLBACKPTR(void, PFNVBOXTASKCALLBACK)(void *pvCb);348 349 @interface VBoxTaskCallback: VBoxTask350 {351 @private352 PFNVBOXTASKCALLBACK m_pfnCb;353 void *m_pvCb;354 }355 - (id)initWithCb:(PFNVBOXTASKCALLBACK)pfnCb arg:(void*)pvCb;356 - (void)run;357 @end358 #endif359 360 @interface VBoxTaskComposite: VBoxTask361 {362 @private363 NSUInteger m_CurIndex;364 RTCRITSECT m_Lock;365 NSMutableArray *m_pArray;366 }367 - (id)init;368 - (void)add:(VBoxTask*)pTask;369 - (void)run;370 - (void)dealloc;371 @end372 373 @implementation VBoxTask374 @end375 376 368 @implementation VBoxTaskPerformSelector 369 370 /** 371 * Initializes a VBoxTaskPerformSelector. 372 * 373 * @param aObject The object (reference not consumed). 374 * @param aSelector The method selector. 375 * @param aArg The method argument (reference not consumed). 376 */ 377 377 - (id)initWithObject:(id)aObject selector:(SEL)aSelector arg:(id)aArg 378 378 { 379 379 self = [super init]; 380 381 380 if (self) 382 381 { … … 407 406 @end 408 407 408 409 #if 0 410 /** Callback function pointer type for VBoxTaskCallback. */ 411 typedef DECLCALLBACKPTR(void, PFNVBOXTASKCALLBACK)(void *pvUser); 412 413 /** 414 * Generic task class for executing a given C callback with a single parameter. 415 */ 416 @interface VBoxTaskCallback: VBoxTask 417 { 418 @private 419 PFNVBOXTASKCALLBACK m_pfnCallback; 420 void *m_pvUser; 421 } 422 - (id)initWithCb:(PFNVBOXTASKCALLBACK)pfnCb arg:(void *)pvUser; 423 - (void)run; 424 @end 425 #endif 426 427 428 /** 429 * 430 */ 431 @interface VBoxTaskComposite : VBoxTask 432 { 433 @private 434 NSUInteger m_CurIndex; 435 RTCRITSECT m_Lock; 436 NSMutableArray *m_pArray; 437 } 438 - (id)init; 439 - (void)add:(VBoxTask *)pTask; 440 - (void)run; 441 - (void)dealloc; 442 @end 443 409 444 @implementation VBoxTaskComposite 410 445 - (id)init … … 429 464 } 430 465 431 - (void)add:(VBoxTask*)pTask 466 /** 467 * Adds a task to the composite task object. 468 * 469 * @param pTask Task to add. Reference is NOT consumed. 470 */ 471 - (void)add:(VBoxTask *)pTask 432 472 { 433 473 [pTask retain]; … … 447 487 - (void)run 448 488 { 449 for(;;) 450 { 489 for (;;) 490 { 491 /* 492 * Dequeue a task. 493 */ 451 494 int rc = RTCritSectEnter(&m_Lock); 452 495 if (RT_FAILURE(rc)) … … 466 509 } 467 510 468 VBoxTask * pTask = (VBoxTask*)[m_pArray objectAtIndex:m_CurIndex];511 VBoxTask *pTask = (VBoxTask *)[m_pArray objectAtIndex:m_CurIndex]; 469 512 Assert(pTask != nil); 470 513 471 514 ++m_CurIndex; 472 515 516 /* 517 * Remove the first 1025 empty entires. 518 */ 473 519 if (m_CurIndex > 1024) 474 520 { … … 481 527 RTCritSectLeave(&m_Lock); 482 528 529 /* 530 * Run the task and release it. 531 */ 483 532 [pTask run]; 484 533 [pTask release]; … … 489 538 { 490 539 NSUInteger count = [m_pArray count]; 491 for (;m_CurIndex < count; ++m_CurIndex)492 { 493 VBoxTask *pTask = (VBoxTask*)[m_pArray objectAtIndex:m_CurIndex];540 for (;m_CurIndex < count; ++m_CurIndex) 541 { 542 VBoxTask *pTask = (VBoxTask*)[m_pArray objectAtIndex:m_CurIndex]; 494 543 DEBUG_WARN(("dealloc with non-empty tasks! %p\n", pTask)); 495 544 [pTask release]; … … 503 552 @end 504 553 554 555 /** 556 * 557 * 558 */ 505 559 @interface VBoxMainThreadTaskRunner : NSObject 506 560 { … … 509 563 } 510 564 - (id)init; 511 - (void)add:(VBoxTask *)pTask;565 - (void)add:(VBoxTask *)pTask; 512 566 - (void)addObj:(id)aObject selector:(SEL)aSelector arg:(id)aArg; 513 567 - (void)runTasks; 514 568 - (bool)runTasksSyncIfPossible; 515 569 - (void)dealloc; 516 + (VBoxMainThreadTaskRunner *) globalInstance;570 + (VBoxMainThreadTaskRunner *) globalInstance; 517 571 @end 518 572 … … 529 583 } 530 584 531 + (VBoxMainThreadTaskRunner *) globalInstance532 { 533 static dispatch_once_t dispatchOnce;534 static VBoxMainThreadTaskRunner * pRunner = nil;535 dispatch_once(& dispatchOnce, ^{536 pRunner = [[VBoxMainThreadTaskRunner alloc] init];585 + (VBoxMainThreadTaskRunner *) globalInstance 586 { 587 static dispatch_once_t s_DispatchOnce; 588 static VBoxMainThreadTaskRunner *s_pRunner = nil; 589 dispatch_once(&s_DispatchOnce, ^{ 590 s_pRunner = [[VBoxMainThreadTaskRunner alloc] init]; 537 591 }); 538 return pRunner; 539 } 540 541 typedef struct CR_RCD_RUN 542 { 543 VBoxMainThreadTaskRunner *pRunner; 544 } CR_RCD_RUN; 545 546 static DECLCALLBACK(void) vboxRcdRun(void *pvCb) 547 { 548 DEBUG_FUNC_ENTER(); 549 CR_RCD_RUN * pRun = (CR_RCD_RUN*)pvCb; 550 [pRun->pRunner runTasks]; 551 DEBUG_FUNC_LEAVE(); 552 } 553 554 - (void)add:(VBoxTask*)pTask 592 return s_pRunner; 593 } 594 595 - (void)add:(VBoxTask *)pTask 555 596 { 556 597 DEBUG_FUNC_ENTER(); 557 598 [m_pTasks add:pTask]; 599 /** @todo r=bird: Unbalanced [self retain]. */ 558 600 [self retain]; 559 601 … … 567 609 } 568 610 611 /** 612 * Adds a task calling an object method (selector). 613 * 614 * @param aObject The object (reference not consumed).. 615 * @param aSelector The method selector. 616 * @param aArg The method argument (reference not consumed). 617 */ 569 618 - (void)addObj:(id)aObject selector:(SEL)aSelector arg:(id)aArg 570 619 { … … 574 623 } 575 624 625 626 /** 627 * Internal method for running the pending tasks. 628 */ 576 629 - (void)runTasks 577 630 { 578 BOOL fIsMain = [NSThread isMainThread]; 579 Assert(fIsMain); 580 if (fIsMain) 631 if ([NSThread isMainThread]) 581 632 { 582 633 [m_pTasks run]; 634 /** @todo r=bird: This release and the retain in the add method aren't 635 * necessarily balanced if there are more than one call to add(). 636 * 637 * This could probably end up deleting the singleton prematurely and leave 638 * globalInstance() returning pointers to a stale object in freed memory, 639 * quite possibly causing crashes or/and heap corruption. */ 583 640 [self release]; 584 641 } … … 586 643 { 587 644 DEBUG_WARN(("run tasks called not on main thread!\n")); 645 #ifndef DEBUG_VERBOSE 646 AssertFailed(); 647 #endif 588 648 [self performSelectorOnMainThread:@selector(runTasks) withObject:nil waitUntilDone:YES]; 589 649 } 590 650 } 591 651 652 /** 653 * Callback for calling runTasks via renderspuCalloutClient. 654 * @param pvUser The VBoxMainThreadTaskRunner singleton. 655 */ 656 static DECLCALLBACK(void) VBoxMainThreadTaskRunner_RcdRunCallback(void *pvUser) 657 { 658 DEBUG_FUNC_ENTER(); 659 VBoxMainThreadTaskRunner *pRunner = (VBoxMainThreadTaskRunner *)pvUser; 660 Assert(pRunner == [VBoxMainThreadTaskRunner globalInstance]); 661 [pRunner runTasks]; 662 DEBUG_FUNC_LEAVE(); 663 } 664 665 /** 666 * Runs pending tasks synchronously, if possible in the current context. 667 * 668 * @returns true if executed tasks, false if not possible. 669 */ 592 670 - (bool)runTasksSyncIfPossible 593 671 { 672 /* 673 * Call on main thread (?) via renderspuCalloutClient (whatever that is). 674 */ 594 675 if (renderspuCalloutAvailable()) 595 676 { 596 CR_RCD_RUN Run;597 Run.pRunner = self;598 677 Assert(![NSThread isMainThread]); 599 renderspuCalloutClient( vboxRcdRun, &Run);678 renderspuCalloutClient(VBoxMainThreadTaskRunner_RcdRunCallback, self); 600 679 return true; 601 680 } 602 681 682 /* 683 * Run directly if on main thread. 684 */ 603 685 if ([NSThread isMainThread]) 604 686 { … … 607 689 } 608 690 691 /* Not possible. */ 609 692 return false; 610 693 } … … 612 695 - (void)dealloc 613 696 { 697 /** @todo r=bird: WTF is the point of the deallocator. The object is a singelton 698 * stored in an inaccessible static variable! */ 614 699 [m_pTasks release]; 700 m_pTasks = nil; 701 615 702 [super dealloc]; 616 703 } … … 620 707 @class DockOverlayView; 621 708 622 /** The custom view class. 623 * This is the main class of the cocoa OpenGL implementation. It 624 * manages an frame buffer object for the rendering of the guest 625 * applications. The guest applications render in this frame buffer which 626 * is bind to an OpenGL texture. To display the guest content, an secondary 627 * shared OpenGL context of the main OpenGL context is created. The secondary 628 * context is marked as non opaque & the texture is displayed on an object 629 * which is composed out of the several visible region rectangles. */ 630 @interface OverlayView: NSView 709 /** 710 * The custom view class. 711 * 712 * This is the main class of the cocoa OpenGL implementation. It manages a 713 * frame buffer object for the rendering of the guest applications. The guest 714 * applications render in this frame buffer which is bound to an OpenGL texture. 715 * To display the guest content, a secondary shared OpenGL context of the main 716 * OpenGL context is created. The secondary context is marked as non-opaque and 717 * the texture is displayed on an object which is composed out of the several 718 * visible region rectangles. 719 */ 720 @interface OverlayView : NSView 631 721 { 632 722 @private 633 NSView *m_pParentView;634 NSWindow *m_pOverlayWin;635 636 NSOpenGLContext *m_pGLCtx;637 NSOpenGLContext *m_pSharedGLCtx;638 RTTHREAD mThread;639 640 GLuint m_FBOId;723 NSView *m_pParentView; 724 NSWindow *m_pOverlayWin; 725 726 NSOpenGLContext *m_pGLCtx; 727 NSOpenGLContext *m_pSharedGLCtx; 728 RTTHREAD m_Thread; 729 730 GLuint m_FBOId; 641 731 642 732 /** The corresponding dock tile view of this OpenGL view & all helper 643 733 * members. */ 644 DockOverlayView *m_DockTileView; 645 646 GLfloat m_FBOThumbScaleX; 647 GLfloat m_FBOThumbScaleY; 648 uint64_t m_uiDockUpdateTime; 649 650 /* For clipping */ 651 GLint m_cClipRects; 652 GLint *m_paClipRects; 653 654 /* Position/Size tracking */ 655 NSPoint m_Pos; 656 NSSize m_Size; 734 DockOverlayView *m_DockTileView; 735 736 GLfloat m_FBOThumbScaleX; 737 GLfloat m_FBOThumbScaleY; 738 uint64_t m_msDockUpdateTS; 739 740 /** @name For clipping 741 * @{ */ 742 GLint m_cClipRects; 743 GLint *m_paClipRects; 744 /** @} */ 745 746 /** @name Position/Size tracking 747 * @{ */ 748 NSPoint m_Pos; 749 NSSize m_Size; 750 /** @} */ 657 751 658 752 /** This is necessary for clipping on the root window */ 659 NSRect m_RootRect;660 float m_yInvRootOffset;661 662 CR_BLITTER *m_pBlitter;663 WindowInfo *m_pWinInfo;664 bool m_fNeedViewportUpdate;665 bool m_fNeedCtxUpdate;666 bool m_fDataVisible;667 bool m_fCleanupNeeded;668 bool m_fEverSized;669 } 670 - (id)initWithFrame:(NSRect)frame thread:(RTTHREAD)aThread parentView:(NSView *)pParentView winInfo:(WindowInfo*)pWinInfo;753 NSRect m_RootRect; 754 float m_yInvRootOffset; 755 756 CR_BLITTER *m_pBlitter; 757 WindowInfo *m_pWinInfo; 758 bool m_fNeedViewportUpdate; 759 bool m_fNeedCtxUpdate; 760 bool m_fDataVisible; 761 bool m_fCleanupNeeded; 762 bool m_fEverSized; 763 } 764 - (id)initWithFrame:(NSRect)frame thread:(RTTHREAD)aThread parentView:(NSView *)pParentView winInfo:(WindowInfo *)pWinInfo; 671 765 - (void)setGLCtx:(NSOpenGLContext*)pCtx; 672 - (NSOpenGLContext *)glCtx;673 674 - (void)setParentView: (NSView *)view;675 - (NSView *)parentView;676 - (void)setOverlayWin: (NSWindow *)win;677 - (NSWindow *)overlayWin;766 - (NSOpenGLContext *)glCtx; 767 768 - (void)setParentView: (NSView *)view; 769 - (NSView *)parentView; 770 - (void)setOverlayWin: (NSWindow *)win; 771 - (NSWindow *)overlayWin; 678 772 679 773 - (void)vboxSetPos:(NSPoint)pos; 680 774 - (void)vboxSetPosUI:(NSPoint)pos; 681 - (void)vboxSetPosUIObj:(NSValue *)pPos;775 - (void)vboxSetPosUIObj:(NSValue *)pPos; 682 776 - (NSPoint)pos; 683 777 - (bool)isEverSized; 684 778 - (void)vboxDestroy; 685 779 - (void)vboxSetSizeUI:(NSSize)size; 686 - (void)vboxSetSizeUIObj:(NSValue *)pSize;780 - (void)vboxSetSizeUIObj:(NSValue *)pSize; 687 781 - (void)vboxSetSize:(NSSize)size; 688 782 - (NSSize)size; … … 698 792 - (void)swapFBO; 699 793 - (void)vboxSetVisible:(GLboolean)fVisible; 700 - (void)vboxSetVisibleUIObj:(NSNumber *)pVisible;794 - (void)vboxSetVisibleUIObj:(NSNumber *)pVisible; 701 795 - (void)vboxSetVisibleUI:(GLboolean)fVisible; 702 796 - (void)vboxTryDraw; 703 797 - (void)vboxTryDrawUI; 704 - (void)vboxReparent:(NSView *)pParentView;705 - (void)vboxReparentUI:(NSView *)pParentView;706 - (void)vboxPresent:(const VBOXVR_SCR_COMPOSITOR *)pCompositor;707 - (void)vboxPresentCS:(const VBOXVR_SCR_COMPOSITOR *)pCompositor;708 - (void)vboxPresentToDockTileCS:(const VBOXVR_SCR_COMPOSITOR *)pCompositor;709 - (void)vboxPresentToViewCS:(const VBOXVR_SCR_COMPOSITOR *)pCompositor;710 - (void)presentComposition:(const VBOXVR_SCR_COMPOSITOR_ENTRY *)pChangedEntry;798 - (void)vboxReparent:(NSView *)pParentView; 799 - (void)vboxReparentUI:(NSView *)pParentView; 800 - (void)vboxPresent:(const VBOXVR_SCR_COMPOSITOR *)pCompositor; 801 - (void)vboxPresentCS:(const VBOXVR_SCR_COMPOSITOR *)pCompositor; 802 - (void)vboxPresentToDockTileCS:(const VBOXVR_SCR_COMPOSITOR *)pCompositor; 803 - (void)vboxPresentToViewCS:(const VBOXVR_SCR_COMPOSITOR *)pCompositor; 804 - (void)presentComposition:(const VBOXVR_SCR_COMPOSITOR_ENTRY *)pChangedEntry; 711 805 - (void)vboxBlitterSyncWindow; 712 806 713 807 - (void)clearVisibleRegions; 714 - (void)setVisibleRegions:(GLint)cRects paRects:(const GLint *)paRects;808 - (void)setVisibleRegions:(GLint)cRects paRects:(const GLint *)paRects; 715 809 - (GLboolean)vboxNeedsEmptyPresent; 716 810 717 - (NSView *)dockTileScreen;811 - (NSView *)dockTileScreen; 718 812 - (void)reshapeDockTile; 719 813 - (void)cleanupData; 720 814 @end 721 815 722 /** Helper view. 816 /** 817 * Helper view. 723 818 * 724 819 * This view is added as a sub view of the parent view to track … … 726 821 * (which happens on fullscreen/seamless entry/exit) the overlay 727 822 * window is informed & can add them self as a child window 728 * again. */ 823 * again. 824 */ 729 825 @class OverlayWindow; 730 826 @interface OverlayHelperView: NSView … … 733 829 OverlayWindow *m_pOverlayWindow; 734 830 } 735 -(id)initWithOverlayWindow:(OverlayWindow *)pOverlayWindow;831 -(id)initWithOverlayWindow:(OverlayWindow *)pOverlayWindow; 736 832 @end 737 833 738 /** Custom window class. 834 /** 835 * Custom window class. 739 836 * 740 837 * This is the overlay window which contains our custom NSView. 741 838 * Its a direct child of the Qt Main window. It marks its background 742 839 * transparent & non opaque to make clipping possible. It also disable mouse 743 * events and handle frame change events of the parent view. */ 744 @interface OverlayWindow: NSWindow 840 * events and handle frame change events of the parent view. 841 */ 842 @interface OverlayWindow : NSWindow 745 843 { 746 844 @private 747 NSView *m_pParentView;748 OverlayView *m_pOverlayView;749 OverlayHelperView *m_pOverlayHelperView;750 NSThread *m_Thread;751 } 752 - (id)initWithParentView:(NSView *)pParentView overlayView:(OverlayView*)pOverlayView;845 NSView *m_pParentView; 846 OverlayView *m_pOverlayView; 847 OverlayHelperView *m_pOverlayHelperView; 848 NSThread *m_Thread; 849 } 850 - (id)initWithParentView:(NSView *)pParentView overlayView:(OverlayView *)pOverlayView; 753 851 - (void)parentWindowFrameChanged:(NSNotification *)note; 754 - (void)parentWindowChanged:(NSWindow *)pWindow;852 - (void)parentWindowChanged:(NSWindow *)pWindow; 755 853 @end 756 854 855 856 /** 857 * Dock overlay view class. 858 */ 757 859 @interface DockOverlayView: NSView 758 860 { 759 NSBitmapImageRep *m_ThumbBitmap;760 NSImage *m_ThumbImage;761 NSLock *m_Lock;861 NSBitmapImageRep *m_ThumbBitmap; 862 NSImage *m_ThumbImage; 863 NSLock *m_Lock; 762 864 } 763 865 - (void)dealloc; … … 767 869 - (void)setFrame:(NSRect)frame; 768 870 - (void)drawRect:(NSRect)aRect; 769 - (NSBitmapImageRep *)thumbBitmap;770 - (NSImage *)thumbImage;871 - (NSBitmapImageRep *)thumbBitmap; 872 - (NSImage *)thumbImage; 771 873 @end 772 874 … … 776 878 DEBUG_FUNC_ENTER(); 777 879 self = [super init]; 778 779 880 if (self) 780 881 { 781 /* We need a lock cause the thumb image could be accessed from the main 882 /* 883 * We need a lock cause the thumb image could be accessed from the main 782 884 * thread when someone is calling display on the dock tile & from the 783 * OpenGL thread when the thumbnail is updated. */ 885 * OpenGL thread when the thumbnail is updated. 886 */ 784 887 m_Lock = [[NSLock alloc] init]; 785 888 } … … 811 914 m_ThumbImage = nil; 812 915 } 916 813 917 if (m_ThumbBitmap != nil) 814 918 { … … 856 960 bitmapFormat:NSAlphaFirstBitmapFormat 857 961 bytesPerRow:frame.size.width * 4 858 bitsPerPixel:8 * 4]; 962 bitsPerPixel:8 * 4 963 ]; 859 964 m_ThumbImage = [[NSImage alloc] initWithSize:[m_ThumbBitmap size]]; 860 965 [m_ThumbImage addRepresentation:m_ThumbBitmap]; 861 966 } 967 862 968 [self unlock]; 863 969 DEBUG_FUNC_LEAVE(); … … 873 979 - (void)drawRect:(NSRect)aRect 874 980 { 875 DEBUG_FUNC_ENTER();876 981 NSRect frame; 877 982 DEBUG_FUNC_ENTER(); 878 983 [self lock]; 984 879 985 #ifdef SHOW_WINDOW_BACKGROUND 880 986 [[NSColor colorWithCalibratedRed:1.0 green:0.0 blue:0.0 alpha:0.7] set]; … … 884 990 if (m_ThumbImage != nil) 885 991 [m_ThumbImage drawAtPoint:NSMakePoint(0, 0) fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0]; 992 886 993 [self unlock]; 887 994 DEBUG_FUNC_LEAVE(); 888 995 } 889 996 890 - (NSBitmapImageRep *)thumbBitmap997 - (NSBitmapImageRep *)thumbBitmap 891 998 { 892 999 DEBUG_FUNC_ENTER(); … … 895 1002 } 896 1003 897 - (NSImage*)thumbImage 898 { 899 DEBUG_FUNC_ENTER(); 900 DEBUG_FUNC_LEAVE(); 901 1004 - (NSImage *)thumbImage 1005 { 1006 DEBUG_FUNC_ENTER(); 1007 DEBUG_FUNC_LEAVE(); 902 1008 return m_ThumbImage; 903 1009 } 904 1010 @end 1011 905 1012 906 1013 /******************************************************************************** … … 911 1018 @implementation OverlayOpenGLContext 912 1019 913 -(id)initWithFormat:(NSOpenGLPixelFormat *)format shareContext:(NSOpenGLContext*)share1020 -(id)initWithFormat:(NSOpenGLPixelFormat *)format shareContext:(NSOpenGLContext *)share 914 1021 { 915 1022 DEBUG_FUNC_ENTER(); … … 922 1029 m_pPixelFormat = format; 923 1030 924 DEBUG_MSG(("OCTX(%p): init OverlayOpenGLContext\n", (void*)self)); 925 926 DEBUG_FUNC_LEAVE(); 927 1031 DEBUG_MSG(("OCTX(%p): init OverlayOpenGLContext\n", (void *)self)); 1032 DEBUG_FUNC_LEAVE(); 928 1033 return self; 929 1034 } … … 932 1037 { 933 1038 DEBUG_FUNC_ENTER(); 934 935 DEBUG_MSG(("OCTX(%p): dealloc OverlayOpenGLContext\n", (void*)self)); 1039 DEBUG_MSG(("OCTX(%p): dealloc OverlayOpenGLContext\n", (void *)self)); 936 1040 937 1041 [m_pPixelFormat release]; … … 950 1054 951 1055 DEBUG_FUNC_LEAVE(); 952 953 1056 return val == GL_TRUE ? YES : NO; 954 1057 } 955 1058 956 -(void)setView:(NSView*)view 957 { 958 DEBUG_FUNC_ENTER(); 959 960 DEBUG_MSG(("OCTX(%p): setView: new view: %p\n", (void*)self, (void*)view)); 1059 -(void)setView:(NSView *)view 1060 { 1061 DEBUG_FUNC_ENTER(); 1062 DEBUG_MSG(("OCTX(%p): setView: new view: %p\n", (void *)self, (void *)view)); 961 1063 962 1064 #if 1 /* def FBO */ … … 969 1071 } 970 1072 971 -(NSView*)view 972 { 973 DEBUG_FUNC_ENTER(); 974 DEBUG_FUNC_LEAVE(); 975 1073 -(NSView *)view 1074 { 1075 DEBUG_FUNC_ENTER(); 1076 DEBUG_FUNC_LEAVE(); 976 1077 #if 1 /* def FBO */ 977 1078 return m_pView; … … 984 1085 { 985 1086 DEBUG_FUNC_ENTER(); 986 987 DEBUG_MSG(("OCTX(%p): clearDrawable\n", (void*)self)); 1087 DEBUG_MSG(("OCTX(%p): clearDrawable\n", (void *)self)); 988 1088 989 1089 m_pView = NULL;; … … 993 1093 } 994 1094 995 -(NSOpenGLPixelFormat *)openGLPixelFormat1095 -(NSOpenGLPixelFormat *)openGLPixelFormat 996 1096 { 997 1097 DEBUG_FUNC_ENTER(); … … 1001 1101 } 1002 1102 1003 @end 1103 @end /* @implementation OverlayOpenGLContext */ 1104 1004 1105 1005 1106 /******************************************************************************** … … 1010 1111 @implementation OverlayHelperView 1011 1112 1012 -(id)initWithOverlayWindow:(OverlayWindow *)pOverlayWindow1113 -(id)initWithOverlayWindow:(OverlayWindow *)pOverlayWindow 1013 1114 { 1014 1115 DEBUG_FUNC_ENTER(); … … 1018 1119 m_pOverlayWindow = pOverlayWindow; 1019 1120 1020 DEBUG_MSG(("OHVW(%p): init OverlayHelperView\n", (void*)self)); 1021 1022 DEBUG_FUNC_LEAVE(); 1023 1121 DEBUG_MSG(("OHVW(%p): init OverlayHelperView\n", (void *)self)); 1122 DEBUG_FUNC_LEAVE(); 1024 1123 return self; 1025 1124 } … … 1028 1127 { 1029 1128 DEBUG_FUNC_ENTER(); 1030 1031 DEBUG_MSG(("OHVW(%p): viewDidMoveToWindow: new win: %p\n", (void*)self, (void*)[self window])); 1129 DEBUG_MSG(("OHVW(%p): viewDidMoveToWindow: new win: %p\n", (void *)self, (void *)[self window])); 1032 1130 1033 1131 [m_pOverlayWindow parentWindowChanged:[self window]]; … … 1037 1135 1038 1136 @end 1137 1039 1138 1040 1139 /******************************************************************************** … … 1045 1144 @implementation OverlayWindow 1046 1145 1047 - (id)initWithParentView:(NSView*)pParentView overlayView:(OverlayView*)pOverlayView 1048 { 1049 DEBUG_FUNC_ENTER(); 1050 1146 - (id)initWithParentView:(NSView *)pParentView overlayView:(OverlayView *)pOverlayView 1147 { 1148 DEBUG_FUNC_ENTER(); 1051 1149 NSWindow *pParentWin = nil; 1052 1150 1053 if((self = [super initWithContentRect:NSZeroRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO])) 1151 self = [super initWithContentRect:NSZeroRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]; 1152 if (self) 1054 1153 { 1055 1154 m_pParentView = pParentView; … … 1060 1159 1061 1160 m_pOverlayHelperView = [[OverlayHelperView alloc] initWithOverlayWindow:self]; 1161 1062 1162 /* Add the helper view as a child of the parent view to get notifications */ 1063 1163 [pParentView addSubview:m_pOverlayHelperView]; … … 1072 1172 [self setOpaque:NO]; 1073 1173 [self setAlphaValue:.999]; 1174 1074 1175 /* Disable mouse events for this window */ 1075 1176 [self setIgnoresMouseEvents:YES]; … … 1090 1191 [pParentWin addChildWindow:self ordered:NSWindowAbove]; 1091 1192 } 1092 DEBUG_MSG(("OWIN(%p): init OverlayWindow\n", (void*)self)); 1093 1094 DEBUG_FUNC_LEAVE(); 1095 1193 1194 DEBUG_MSG(("OWIN(%p): init OverlayWindow\n", (void *)self)); 1195 DEBUG_FUNC_LEAVE(); 1096 1196 return self; 1097 1197 } … … 1100 1200 { 1101 1201 DEBUG_FUNC_ENTER(); 1102 1103 DEBUG_MSG(("OWIN(%p): dealloc OverlayWindow\n", (void*)self)); 1202 DEBUG_MSG(("OWIN(%p): dealloc OverlayWindow\n", (void *)self)); 1104 1203 1105 1204 [[NSNotificationCenter defaultCenter] removeObserver:self]; … … 1113 1212 } 1114 1213 1115 - (void)parentWindowFrameChanged:(NSNotification*)pNote 1116 { 1117 DEBUG_FUNC_ENTER(); 1118 1119 DEBUG_MSG(("OWIN(%p): parentWindowFrameChanged\n", (void*)self)); 1120 1121 /* Reposition this window with the help of the OverlayView. Perform the 1122 * call in the OpenGL thread. */ 1214 - (void)parentWindowFrameChanged:(NSNotification *)pNote 1215 { 1216 DEBUG_FUNC_ENTER(); 1217 DEBUG_MSG(("OWIN(%p): parentWindowFrameChanged\n", (void *)self)); 1218 1219 /* 1220 * Reposition this window with the help of the OverlayView. Perform the 1221 * call in the OpenGL thread. 1222 */ 1123 1223 /* 1124 1224 [m_pOverlayView performSelector:@selector(vboxReshapePerform) onThread:m_Thread withObject:nil waitUntilDone:YES]; … … 1127 1227 if ([m_pOverlayView isEverSized]) 1128 1228 { 1129 if ([NSThread isMainThread])1229 if ([NSThread isMainThread]) 1130 1230 [m_pOverlayView vboxReshapePerform]; 1131 1231 else … … 1136 1236 } 1137 1237 1138 - (void)parentWindowChanged:(NSWindow*)pWindow 1139 { 1140 DEBUG_FUNC_ENTER(); 1141 1142 DEBUG_MSG(("OWIN(%p): parentWindowChanged\n", (void*)self)); 1238 - (void)parentWindowChanged:(NSWindow *)pWindow 1239 { 1240 DEBUG_FUNC_ENTER(); 1241 DEBUG_MSG(("OWIN(%p): parentWindowChanged\n", (void *)self)); 1143 1242 1144 1243 [[NSNotificationCenter defaultCenter] removeObserver:self]; 1145 1244 1146 if (pWindow != nil)1245 if (pWindow != nil) 1147 1246 { 1148 1247 /* Ask to get notifications when our parent window frame changes. */ … … 1152 1251 name:NSWindowDidResizeNotification 1153 1252 object:pWindow]; 1253 1154 1254 /* Add us self as child window */ 1155 1255 [pWindow addChildWindow:self ordered:NSWindowAbove]; 1156 /* Reshape the overlay view after a short waiting time to let the main 1157 * window resize itself properly. */ 1256 1257 /* 1258 * Reshape the overlay view after a short waiting time to let the main 1259 * window resize itself properly. 1260 */ 1158 1261 /* 1159 1262 [m_pOverlayView performSelector:@selector(vboxReshapePerform) withObject:nil afterDelay:0.2]; … … 1163 1266 if ([m_pOverlayView isEverSized]) 1164 1267 { 1165 if ([NSThread isMainThread])1268 if ([NSThread isMainThread]) 1166 1269 [m_pOverlayView vboxReshapePerform]; 1167 1270 else … … 1173 1276 } 1174 1277 1175 @end 1278 @end /* @implementation OverlayWindow */ 1279 1280 1176 1281 1177 1282 /******************************************************************************** … … 1182 1287 @implementation OverlayView 1183 1288 1184 - (id)initWithFrame:(NSRect)frame thread:(RTTHREAD)aThread parentView:(NSView *)pParentView winInfo:(WindowInfo*)pWinInfo1289 - (id)initWithFrame:(NSRect)frame thread:(RTTHREAD)aThread parentView:(NSView *)pParentView winInfo:(WindowInfo *)pWinInfo 1185 1290 { 1186 1291 DEBUG_FUNC_ENTER(); … … 1190 1295 m_pGLCtx = nil; 1191 1296 m_pSharedGLCtx = nil; 1192 m Thread= aThread;1297 m_Thread = aThread; 1193 1298 m_FBOId = 0; 1194 1299 m_cClipRects = 0; … … 1199 1304 m_yInvRootOffset = 0; 1200 1305 m_pBlitter = nil; 1201 m_pWinInfo 1306 m_pWinInfo = pWinInfo; 1202 1307 m_fNeedViewportUpdate = true; 1203 1308 m_fNeedCtxUpdate = true; … … 1208 1313 self = [super initWithFrame:frame]; 1209 1314 1210 DEBUG_MSG(("OVIW(%p): init OverlayView\n", (void*)self)); 1211 1212 DEBUG_FUNC_LEAVE(); 1213 1315 DEBUG_MSG(("OVIW(%p): init OverlayView\n", (void *)self)); 1316 DEBUG_FUNC_LEAVE(); 1214 1317 return self; 1215 1318 } … … 1220 1323 1221 1324 [self deleteDockTile]; 1222 1325 1223 1326 [self setGLCtx:nil]; 1224 1327 … … 1229 1332 1230 1333 [m_pSharedGLCtx release]; 1231 1232 1334 m_pSharedGLCtx = nil; 1233 1335 1234 1336 CrBltTerm(m_pBlitter); 1337 RTMemFree(m_pBlitter); 1338 m_pBlitter = nil; 1339 } 1340 1341 [self clearVisibleRegions]; 1342 1343 DEBUG_FUNC_LEAVE(); 1344 } 1345 1346 - (void)dealloc 1347 { 1348 DEBUG_FUNC_ENTER(); 1349 DEBUG_MSG(("OVIW(%p): dealloc OverlayView\n", (void *)self)); 1350 1351 [self cleanupData]; 1352 [super dealloc]; 1353 1354 DEBUG_FUNC_LEAVE(); 1355 } 1356 1357 - (void)drawRect:(NSRect)aRect 1358 { 1359 [self vboxTryDrawUI]; 1360 } 1361 1362 - (void)setGLCtx:(NSOpenGLContext *)pCtx 1363 { 1364 DEBUG_FUNC_ENTER(); 1365 DEBUG_MSG(("OVIW(%p): setGLCtx: new ctx: %p\n", (void *)self, (void *)pCtx)); 1366 1367 /* 1368 * Only do something if the context changes. 1369 */ 1370 if (m_pGLCtx != pCtx) 1371 { 1372 /* Ensure the context drawable is cleared to avoid holding a reference to inexistent view. */ 1373 if (m_pGLCtx) 1374 { 1375 [m_pGLCtx clearDrawable]; 1376 [m_pGLCtx release]; 1377 /*[m_pGLCtx performSelectorOnMainThread:@selector(release) withObject:nil waitUntilDone:NO];*/ 1378 } 1379 1380 m_pGLCtx = pCtx; 1381 if (pCtx) 1382 [pCtx retain]; 1383 } 1235 1384 1236 RTMemFree(m_pBlitter); 1237 1238 m_pBlitter = nil; 1239 } 1240 1241 [self clearVisibleRegions]; 1242 1243 DEBUG_FUNC_LEAVE(); 1244 } 1245 1246 - (void)dealloc 1247 { 1248 DEBUG_FUNC_ENTER(); 1249 1250 DEBUG_MSG(("OVIW(%p): dealloc OverlayView\n", (void*)self)); 1251 1252 [self cleanupData]; 1253 1254 [super dealloc]; 1255 1256 DEBUG_FUNC_LEAVE(); 1257 } 1258 1259 - (void)drawRect:(NSRect)aRect 1260 { 1261 [self vboxTryDrawUI]; 1262 } 1263 1264 - (void)setGLCtx:(NSOpenGLContext*)pCtx 1265 { 1266 DEBUG_FUNC_ENTER(); 1267 1268 DEBUG_MSG(("OVIW(%p): setGLCtx: new ctx: %p\n", (void*)self, (void*)pCtx)); 1269 if (m_pGLCtx == pCtx) 1270 { 1271 DEBUG_FUNC_LEAVE(); 1272 return; 1273 } 1274 1275 /* ensure the context drawable is cleared to avoid holding a reference to inexistent view */ 1276 if (m_pGLCtx) 1277 { 1278 [m_pGLCtx clearDrawable]; 1279 [m_pGLCtx release]; 1280 /*[m_pGLCtx performSelectorOnMainThread:@selector(release) withObject:nil waitUntilDone:NO];*/ 1281 } 1282 1283 m_pGLCtx = pCtx; 1284 if (pCtx) 1285 [pCtx retain]; 1286 1287 DEBUG_FUNC_LEAVE(); 1288 } 1289 1290 - (NSOpenGLContext*)glCtx 1291 { 1292 DEBUG_FUNC_ENTER(); 1293 DEBUG_FUNC_LEAVE(); 1294 1385 DEBUG_FUNC_LEAVE(); 1386 } 1387 1388 - (NSOpenGLContext *)glCtx 1389 { 1390 DEBUG_FUNC_ENTER(); 1391 DEBUG_FUNC_LEAVE(); 1295 1392 return m_pGLCtx; 1296 1393 } 1297 1394 1298 - (NSView*)parentView 1299 { 1300 DEBUG_FUNC_ENTER(); 1301 DEBUG_FUNC_LEAVE(); 1302 1395 - (NSView *)parentView 1396 { 1397 DEBUG_FUNC_ENTER(); 1398 DEBUG_FUNC_LEAVE(); 1303 1399 return m_pParentView; 1304 1400 } 1305 1401 1306 - (void)setParentView:(NSView*)pView 1307 { 1308 DEBUG_FUNC_ENTER(); 1309 1310 DEBUG_MSG(("OVIW(%p): setParentView: new view: %p\n", (void*)self, (void*)pView)); 1402 - (void)setParentView:(NSView *)pView 1403 { 1404 DEBUG_FUNC_ENTER(); 1405 DEBUG_MSG(("OVIW(%p): setParentView: new view: %p\n", (void *)self, (void *)pView)); 1311 1406 1312 1407 m_pParentView = pView; … … 1315 1410 } 1316 1411 1317 - (void)setOverlayWin:(NSWindow*)pWin 1318 { 1319 DEBUG_FUNC_ENTER(); 1320 1321 DEBUG_MSG(("OVIW(%p): setOverlayWin: new win: %p\n", (void*)self, (void*)pWin)); 1412 - (void)setOverlayWin:(NSWindow *)pWin 1413 { 1414 DEBUG_FUNC_ENTER(); 1415 DEBUG_MSG(("OVIW(%p): setOverlayWin: new win: %p\n", (void *)self, (void *)pWin)); 1322 1416 1323 1417 m_pOverlayWin = pWin; … … 1326 1420 } 1327 1421 1328 - (NSWindow*)overlayWin 1329 { 1330 DEBUG_FUNC_ENTER(); 1331 DEBUG_FUNC_LEAVE(); 1332 1422 - (NSWindow *)overlayWin 1423 { 1424 DEBUG_FUNC_ENTER(); 1425 DEBUG_FUNC_LEAVE(); 1333 1426 return m_pOverlayWin; 1334 1427 } … … 1346 1439 } 1347 1440 1348 - (void)vboxSetPosUIObj:(NSValue *)pPos1441 - (void)vboxSetPosUIObj:(NSValue *)pPos 1349 1442 { 1350 1443 DEBUG_FUNC_ENTER(); … … 1356 1449 } 1357 1450 1451 #if 0 /* unused */ 1358 1452 typedef struct CR_RCD_SETPOS 1359 1453 { … … 1366 1460 DEBUG_FUNC_ENTER(); 1367 1461 1368 CR_RCD_SETPOS * 1462 CR_RCD_SETPOS *pPos = (CR_RCD_SETPOS*)pvCb; 1369 1463 [pPos->pView vboxSetPosUI:pPos->pos]; 1370 1464 1371 1465 DEBUG_FUNC_LEAVE(); 1372 1466 } 1467 #endif 1373 1468 1374 1469 - (void)vboxSetPos:(NSPoint)pos … … 1376 1471 DEBUG_FUNC_ENTER(); 1377 1472 1378 DEBUG_MSG(("OVIW(%p): vboxSetPos: new pos: %d, %d\n", (void *)self, (int)pos.x, (int)pos.y));1473 DEBUG_MSG(("OVIW(%p): vboxSetPos: new pos: %d, %d\n", (void *)self, (int)pos.x, (int)pos.y)); 1379 1474 VBoxMainThreadTaskRunner *pRunner = [VBoxMainThreadTaskRunner globalInstance]; 1380 1475 NSValue *pPos = [NSValue valueWithPoint:pos]; … … 1401 1496 { 1402 1497 DEBUG_FUNC_ENTER(); 1403 BOOL fIsMain = [NSThread isMainThread];1404 NSWindow *pWin= nil;1498 BOOL fIsMain = [NSThread isMainThread]; 1499 NSWindow *pWin = nil; 1405 1500 1406 1501 Assert(fIsMain); 1407 1502 1408 /* Hide the view early */1503 /* Hide the view early. */ 1409 1504 [self setHidden: YES]; 1410 1505 … … 1421 1516 caused by main thread waiting xpcom thread, xpcom thread waiting to main hgcm thread, 1422 1517 and main hgcm thread waiting for us, this is why use waitUntilDone:NO, 1423 which should cause no harm */1518 which should cause no harm. */ 1424 1519 [pWin performSelectorOnMainThread:@selector(release) withObject:nil waitUntilDone:NO]; 1425 1520 } … … 1434 1529 caused by main thread waiting xpcom thread, xpcom thread waiting to main hgcm thread, 1435 1530 and main hgcm thread waiting for us, this is why use waitUntilDone:NO. 1436 We need to avoid concurrency though, so we cleanup some data right away via a cleanupData call */1531 We need to avoid concurrency though, so we cleanup some data right away via a cleanupData call. */ 1437 1532 [self performSelectorOnMainThread:@selector(release) withObject:nil waitUntilDone:NO]; 1438 1533 } … … 1443 1538 } 1444 1539 1445 - (void)vboxSetSizeUIObj:(NSValue *)pSize1540 - (void)vboxSetSizeUIObj:(NSValue *)pSize 1446 1541 { 1447 1542 DEBUG_FUNC_ENTER(); … … 1454 1549 { 1455 1550 DEBUG_FUNC_ENTER(); 1551 1456 1552 m_Size = size; 1457 1458 1553 m_fEverSized = true; 1459 1554 1460 DEBUG_MSG(("OVIW(%p): vboxSetSize: new size: %dx%d\n", (void *)self, (int)m_Size.width, (int)m_Size.height));1555 DEBUG_MSG(("OVIW(%p): vboxSetSize: new size: %dx%d\n", (void *)self, (int)m_Size.width, (int)m_Size.height)); 1461 1556 [self vboxReshapeOnResizePerform]; 1462 1557 1463 1558 /* ensure window contents is updated after that */ 1464 1559 [self vboxTryDrawUI]; 1465 DEBUG_FUNC_LEAVE(); 1466 } 1467 1560 1561 DEBUG_FUNC_LEAVE(); 1562 } 1563 1564 #if 0 /* unused */ 1468 1565 typedef struct CR_RCD_SETSIZE 1469 1566 { … … 1479 1576 DEBUG_FUNC_LEAVE(); 1480 1577 } 1578 #endif 1481 1579 1482 1580 - (void)vboxSetSize:(NSSize)size … … 1494 1592 { 1495 1593 DEBUG_FUNC_ENTER(); 1594 DEBUG_FUNC_LEAVE(); 1496 1595 return m_Size; 1497 DEBUG_FUNC_LEAVE();1498 1596 } 1499 1597 … … 1501 1599 { 1502 1600 DEBUG_FUNC_ENTER(); 1503 DEBUG_MSG(("OVIW(%p): updateViewport\n", (void *)self));1504 1505 /* Update the viewport for our OpenGL view */1601 DEBUG_MSG(("OVIW(%p): updateViewport\n", (void *)self)); 1602 1603 /* Update the viewport for our OpenGL view. */ 1506 1604 [m_pSharedGLCtx update]; 1507 1605 1508 1606 [self vboxBlitterSyncWindow]; 1509 1607 1510 /* Clear background to transparent */1608 /* Clear background to transparent. */ 1511 1609 glClearColor(0.0f, 0.0f, 0.0f, 0.0f); 1512 1610 DEBUG_FUNC_LEAVE(); … … 1516 1614 { 1517 1615 DEBUG_FUNC_ENTER(); 1616 1518 1617 [self vboxReshapePerform]; 1519 1520 1618 [self createDockTile]; 1619 1521 1620 /* have to rebind GL_TEXTURE_RECTANGLE_ARB as m_FBOTexId could be changed in updateFBO call */ 1522 1621 m_fNeedViewportUpdate = true; … … 1534 1633 } 1535 1634 #endif 1635 1536 1636 DEBUG_FUNC_LEAVE(); 1537 1637 } … … 1553 1653 NSRect newFrame = NSZeroRect; 1554 1654 1555 DEBUG_MSG(("OVIW(%p): vboxReshapePerform\n", (void *)self));1655 DEBUG_MSG(("OVIW(%p): vboxReshapePerform\n", (void *)self)); 1556 1656 1557 1657 parentFrame = [m_pParentView frame]; … … 1581 1681 1582 1682 DEBUG_MSG(("[%#p]: parentFrame pos[%f : %f] size[%f : %f]\n", 1583 (void*)self, 1584 parentFrame.origin.x, parentFrame.origin.y, 1585 parentFrame.size.width, parentFrame.size.height)); 1683 (void *)self, parentFrame.origin.x, parentFrame.origin.y, parentFrame.size.width, parentFrame.size.height)); 1586 1684 DEBUG_MSG(("[%#p]: childFrame pos[%f : %f] size[%f : %f]\n", 1587 (void*)self, 1588 childFrame.origin.x, childFrame.origin.y, 1589 childFrame.size.width, childFrame.size.height)); 1685 (void *)self, childFrame.origin.x, childFrame.origin.y, childFrame.size.width, childFrame.size.height)); 1590 1686 1591 1687 DEBUG_MSG(("[%#p]: newFrame pos[%f : %f] size[%f : %f]\n", 1592 (void*)self, 1593 newFrame.origin.x, newFrame.origin.y, 1594 newFrame.size.width, newFrame.size.height)); 1688 (void *)self, newFrame.origin.x, newFrame.origin.y, newFrame.size.width, newFrame.size.height)); 1595 1689 1596 1690 /* Later we have to correct the texture position in the case the window is … … 1602 1696 1603 1697 DEBUG_MSG(("[%#p]: m_RootRect pos[%f : %f] size[%f : %f]\n", 1604 (void*)self, 1605 m_RootRect.origin.x, m_RootRect.origin.y, 1606 m_RootRect.size.width, m_RootRect.size.height)); 1698 (void *)self, m_RootRect.origin.x, m_RootRect.origin.y, m_RootRect.size.width, m_RootRect.size.height)); 1607 1699 1608 1700 … … 1624 1716 [[self window] setFrame:newFrame display:YES]; 1625 1717 1626 /* Inform the dock tile view as well */1718 /* Inform the dock tile view as well. */ 1627 1719 [self reshapeDockTile]; 1628 1720 1629 /* Make sure the context is updated according */1721 /* Make sure the context is updated accordingly. */ 1630 1722 /* [self updateViewport]; */ 1631 1723 if (m_pSharedGLCtx) … … 1638 1730 vboxCtxLeave(&CtxInfo); 1639 1731 } 1732 1640 1733 DEBUG_FUNC_LEAVE(); 1641 1734 } … … 1644 1737 { 1645 1738 DEBUG_FUNC_ENTER(); 1646 NSView *pDockScreen = nil; 1647 [self deleteDockTile]; 1739 NSView *pDockScreen = nil; 1740 1741 [self deleteDockTile]; 1648 1742 1649 1743 /* Is there a dock tile preview enabled in the GUI? If so setup a 1650 1744 * additional thumbnail view for the dock tile. */ 1651 1652 1745 pDockScreen = [self dockTileScreen]; 1746 if (pDockScreen) 1653 1747 { 1654 1748 m_DockTileView = [[DockOverlayView alloc] init]; … … 1656 1750 [pDockScreen addSubview:m_DockTileView]; 1657 1751 } 1752 1658 1753 DEBUG_FUNC_LEAVE(); 1659 1754 } … … 1662 1757 { 1663 1758 DEBUG_FUNC_ENTER(); 1664 1759 if (m_DockTileView != nil) 1665 1760 { 1666 1761 [m_DockTileView removeFromSuperview]; … … 1673 1768 - (void)makeCurrentFBO 1674 1769 { 1675 DEBUG_MSG(("OVIW(%p): makeCurrentFBO\n", (void *)self));1770 DEBUG_MSG(("OVIW(%p): makeCurrentFBO\n", (void *)self)); 1676 1771 1677 1772 if (m_pGLCtx) … … 1680 1775 { 1681 1776 /* We change the active view, so flush first */ 1682 if ([NSOpenGLContext currentContext] != 0)1777 if ([NSOpenGLContext currentContext] != 0) 1683 1778 glFlush(); 1684 1779 [m_pGLCtx setView: self]; 1685 CHECK_GL_ERROR();1780 DEBUG_CHECK_GL_ERROR(); 1686 1781 } 1687 1782 /* … … 1690 1785 { 1691 1786 [m_pGLCtx makeCurrentContext]; 1692 CHECK_GL_ERROR();1787 DEBUG_CHECK_GL_ERROR(); 1693 1788 if (m_fNeedCtxUpdate == true) 1694 1789 { … … 1703 1798 Assert(m_FBOId); 1704 1799 } 1705 1706 1800 } 1707 1801 } … … 1710 1804 { 1711 1805 DEBUG_FUNC_ENTER(); 1806 GLint opaque = 0; 1807 NSOpenGLContext *pSharedGLCtx; 1808 NSOpenGLPixelFormat *pPixelFormat; 1809 1712 1810 if (m_pSharedGLCtx) 1713 1811 { … … 1718 1816 Assert(!m_pBlitter); 1719 1817 m_pBlitter = RTMemAlloc(sizeof (*m_pBlitter)); 1720 if ( !m_pBlitter)1818 if (RT_UNLIKELY(!m_pBlitter)) 1721 1819 { 1722 1820 DEBUG_WARN(("m_pBlitter allocation failed")); … … 1726 1824 1727 1825 int rc = CrBltInit(m_pBlitter, NULL, false, false, &render_spu.GlobalShaders, &render_spu.blitterDispatch); 1728 if (RT_SUCCESS(rc)) 1729 { 1730 DEBUG_MSG(("blitter created successfully for view 0x%p\n", (void*)self)); 1731 } 1732 else 1826 if (RT_FAILURE(rc)) 1733 1827 { 1734 1828 DEBUG_WARN(("CrBltInit failed, rc %d", rc)); … … 1738 1832 return false; 1739 1833 } 1740 1741 GLint opaque = 0; 1834 1835 DEBUG_MSG(("blitter created successfully for view 0x%p\n", (void *)self)); 1836 1742 1837 /* Create a shared context out of the main context. Use the same pixel format. */ 1743 NSOpenGLContext *pSharedGLCtx = [[NSOpenGLContext alloc] initWithFormat:[(OverlayOpenGLContext*)m_pGLCtx openGLPixelFormat] shareContext:m_pGLCtx]; 1838 pPixelFormat = [(OverlayOpenGLContext *)m_pGLCtx openGLPixelFormat]; 1839 pSharedGLCtx = [[NSOpenGLContext alloc] initWithFormat:pPixelFormat shareContext:m_pGLCtx]; 1744 1840 1745 1841 /* Set the new context as non opaque */ 1746 1842 [pSharedGLCtx setValues:&opaque forParameter:NSOpenGLCPSurfaceOpacity]; 1843 1747 1844 /* Set this view as the drawable for the new context */ 1748 [pSharedGLCtx setView: 1845 [pSharedGLCtx setView:self]; 1749 1846 m_fNeedViewportUpdate = true; 1750 1847 1751 1848 m_pSharedGLCtx = pSharedGLCtx; 1752 1849 … … 1759 1856 glFlush(); 1760 1857 1858 /* Issue to the gui thread. */ 1761 1859 DEBUG_MSG(("My[%p]: Draw\n", self)); 1762 /* issue to the gui thread */1763 1860 [self performSelectorOnMainThread:@selector(vboxTryDrawUI) withObject:nil waitUntilDone:NO]; 1764 1861 } 1765 1862 1863 #if 0 /* unused */ 1766 1864 typedef struct CR_RCD_SETVISIBLE 1767 1865 { … … 1778 1876 DEBUG_FUNC_LEAVE(); 1779 1877 } 1878 #endif 1780 1879 1781 1880 - (void)vboxSetVisible:(GLboolean)fVisible … … 1805 1904 } 1806 1905 1906 #if 0 /* unused */ 1807 1907 typedef struct CR_RCD_REPARENT 1808 1908 { … … 1818 1918 DEBUG_FUNC_LEAVE(); 1819 1919 } 1820 1821 - (void)vboxReparent:(NSView*)pParentView 1920 #endif 1921 1922 - (void)vboxReparent:(NSView *)pParentView 1822 1923 { 1823 1924 DEBUG_FUNC_ENTER(); … … 1829 1930 } 1830 1931 1831 - (void)vboxReparentUI:(NSView*)pParentView 1832 { 1833 DEBUG_FUNC_ENTER(); 1932 - (void)vboxReparentUI:(NSView *)pParentView 1933 { 1934 DEBUG_FUNC_ENTER(); 1935 1834 1936 /* Make sure the window is removed from any previous parent window. */ 1835 1937 if ([[self overlayWin] parentWindow] != nil) … … 1854 1956 - (void)vboxTryDrawUI 1855 1957 { 1958 const VBOXVR_SCR_COMPOSITOR *pCompositor; 1856 1959 DEBUG_MSG(("My[%p]: DrawUI\n", self)); 1857 const VBOXVR_SCR_COMPOSITOR *pCompositor;1858 1960 1859 1961 if ([self isHidden]) … … 1944 2046 { 1945 2047 VBOX_CR_RENDER_CTX_INFO CtxInfo; 1946 1947 DEBUG_MSG(("OVIW(%p): renderFBOToView\n", (void*)self)); 2048 DEBUG_MSG(("OVIW(%p): renderFBOToView\n", (void *)self)); 1948 2049 1949 2050 Assert(pCompositor); … … 1956 2057 } 1957 2058 1958 - (void)vboxPresentCS:(const VBOXVR_SCR_COMPOSITOR *)pCompositor1959 { 1960 {1961 if ([m_pSharedGLCtx view] != self)1962 {1963 DEBUG_MSG(("OVIW(%p): not current view of shared ctx! Switching ...\n", (void*)self));1964 [m_pSharedGLCtx setView: self];1965 m_fNeedViewportUpdate = true;1966 }1967 1968 if (m_fNeedViewportUpdate)1969 {1970 [self updateViewportCS];1971 m_fNeedViewportUpdate = false;1972 }1973 1974 m_fCleanupNeeded = false;1975 1976 /* Render FBO content to the dock tile when necessary. */1977 [self vboxPresentToDockTileCS:pCompositor]; 1978 2059 - (void)vboxPresentCS:(const VBOXVR_SCR_COMPOSITOR *)pCompositor 2060 { 2061 if ([m_pSharedGLCtx view] != self) 2062 { 2063 DEBUG_MSG(("OVIW(%p): not current view of shared ctx! Switching ...\n", (void *)self)); 2064 [m_pSharedGLCtx setView: self]; 2065 m_fNeedViewportUpdate = true; 2066 } 2067 2068 if (m_fNeedViewportUpdate) 2069 { 2070 [self updateViewportCS]; 2071 m_fNeedViewportUpdate = false; 2072 } 2073 2074 m_fCleanupNeeded = false; 2075 2076 /* Render FBO content to the dock tile when necessary. */ 2077 [self vboxPresentToDockTileCS:pCompositor]; 2078 2079 /* change to #if 0 to see thumbnail image */ 1979 2080 #if 1 1980 2081 [self vboxPresentToViewCS:pCompositor]; 1981 2082 #else 1982 1983 2083 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 2084 [m_pSharedGLCtx flushBuffer]; 1984 2085 #endif 1985 1986 }1987 2086 } 1988 2087 1989 2088 DECLINLINE(void) vboxNSRectToRect(const NSRect *pR, RTRECT *pRect) 1990 2089 { 1991 pRect->xLeft = (int)pR->origin.x;1992 pRect->yTop = (int)pR->origin.y;1993 pRect->xRight = (int)(pR->origin.x + pR->size.width);2090 pRect->xLeft = (int)pR->origin.x; 2091 pRect->yTop = (int)pR->origin.y; 2092 pRect->xRight = (int)(pR->origin.x + pR->size.width); 1994 2093 pRect->yBottom = (int)(pR->origin.y + pR->size.height); 1995 2094 } … … 1997 2096 DECLINLINE(void) vboxNSRectToRectUnstretched(const NSRect *pR, RTRECT *pRect, float xStretch, float yStretch) 1998 2097 { 1999 pRect->xLeft = (int)(pR->origin.x / xStretch);2000 pRect->yTop = (int)(pR->origin.y / yStretch);2001 pRect->xRight = (int)((pR->origin.x + pR->size.width) / xStretch);2098 pRect->xLeft = (int)(pR->origin.x / xStretch); 2099 pRect->yTop = (int)(pR->origin.y / yStretch); 2100 pRect->xRight = (int)((pR->origin.x + pR->size.width) / xStretch); 2002 2101 pRect->yBottom = (int)((pR->origin.y + pR->size.height) / yStretch); 2003 2102 } … … 2005 2104 DECLINLINE(void) vboxNSRectToRectStretched(const NSRect *pR, RTRECT *pRect, float xStretch, float yStretch) 2006 2105 { 2007 pRect->xLeft = (int)(pR->origin.x * xStretch);2008 pRect->yTop = (int)(pR->origin.y * yStretch);2009 pRect->xRight = (int)((pR->origin.x + pR->size.width) * xStretch);2106 pRect->xLeft = (int)(pR->origin.x * xStretch); 2107 pRect->yTop = (int)(pR->origin.y * yStretch); 2108 pRect->xRight = (int)((pR->origin.x + pR->size.width) * xStretch); 2010 2109 pRect->yBottom = (int)((pR->origin.y + pR->size.height) * yStretch); 2011 2110 } … … 2014 2113 { 2015 2114 NSRect r = [self frame]; 2016 float xStretch, yStretch; 2017 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)); 2115 float xStretch; 2116 float yStretch; 2117 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)); 2018 2118 2019 2119 #if 1 /* Set to 0 to see the docktile instead of the real output */ … … 2041 2141 if (RT_SUCCESS(rc)) 2042 2142 { 2043 uint32_t i; 2044 int rc = CrBltEnter(m_pBlitter); 2143 rc = CrBltEnter(m_pBlitter); 2045 2144 if (RT_SUCCESS(rc)) 2046 2145 { 2146 uint32_t i; 2047 2147 for (i = 0; i < cRegions; ++i) 2048 2148 { 2049 const RTRECT * pSrcRect = &paSrcRegions[i]; 2050 const RTRECT * pDstRect = &paDstRegions[i]; 2051 RTRECT DstRect, RestrictDstRect; 2052 RTRECT SrcRect, RestrictSrcRect; 2149 const CR_TEXDATA *pTexData; 2150 PCRTRECT pSrcRect = &paSrcRegions[i]; 2151 PCRTRECT pDstRect = &paDstRegions[i]; 2152 RTRECT DstRect, RestrictDstRect; 2153 RTRECT SrcRect, RestrictSrcRect; 2053 2154 2054 2155 vboxNSRectToRect(&m_RootRect, &RestrictDstRect); … … 2061 2162 2062 2163 vboxNSRectToRectUnstretched(&m_RootRect, &RestrictSrcRect, xStretch, yStretch); 2063 VBoxRectTranslate(&RestrictSrcRect, -CrVrScrCompositorEntryRectGet(pEntry)->xLeft, -CrVrScrCompositorEntryRectGet(pEntry)->yTop); 2164 VBoxRectTranslate(&RestrictSrcRect, 2165 -CrVrScrCompositorEntryRectGet(pEntry)->xLeft, 2166 -CrVrScrCompositorEntryRectGet(pEntry)->yTop); 2064 2167 VBoxRectIntersected(&RestrictSrcRect, pSrcRect, &SrcRect); 2065 2168 … … 2070 2173 pDstRect = &DstRect; 2071 2174 2072 const CR_TEXDATA *pTexData = CrVrScrCompositorEntryTexGet(pEntry);2175 pTexData = CrVrScrCompositorEntryTexGet(pEntry); 2073 2176 2074 2177 CrBltBlitTexMural(m_pBlitter, true, CrTdTexGet(pTexData), pSrcRect, pDstRect, 1, fFlags | CRBLT_F_NOALPHA); … … 2081 2184 { 2082 2185 DEBUG_WARN(("CrBltEnter failed rc %d", rc)); 2186 # ifndef DEBUG_VERBOSE 2187 AssertMsgFailed(("CrBltEnter failed rc %Rrc", rc)); 2188 # endif 2083 2189 } 2084 2190 } 2085 2191 else 2086 2192 { 2087 Assert (0);2193 AssertMsgFailed(("BlitStretched: CrVrScrCompositorEntryRegionsGet failed rc %Rrc\n", rc)); 2088 2194 DEBUG_MSG_1(("BlitStretched: CrVrScrCompositorEntryRegionsGet failed rc %d\n", rc)); 2089 2195 } 2090 2196 } 2091 2197 #endif 2092 /* 2093 glFinish(); 2094 */ 2095 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 2096 [m_pSharedGLCtx flushBuffer]; 2097 } 2098 2099 - (void)presentComposition:(const VBOXVR_SCR_COMPOSITOR_ENTRY*)pChangedEntry 2198 2199 /* 2200 glFinish(); 2201 */ 2202 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 2203 [m_pSharedGLCtx flushBuffer]; 2204 } 2205 2206 - (void)presentComposition:(const VBOXVR_SCR_COMPOSITOR_ENTRY *)pChangedEntry 2100 2207 { 2101 2208 [self vboxTryDraw]; … … 2104 2211 - (void)vboxBlitterSyncWindow 2105 2212 { 2106 CR_BLITTER_WINDOW WinInfo;2107 NSRect r;2213 CR_BLITTER_WINDOW WinInfo; 2214 NSRect r; 2108 2215 2109 2216 if (!m_pBlitter) 2110 2217 return; 2111 2218 2112 memset(&WinInfo, 0, sizeof (WinInfo));2219 RT_ZERO(WinInfo); 2113 2220 2114 2221 r = [self frame]; … … 2130 2237 - (void)vboxPresentToDockTileCS:(const VBOXVR_SCR_COMPOSITOR*)pCompositor 2131 2238 { 2132 NSRect r= [self frame];2133 NSRect rr= NSZeroRect;2134 GLint i= 0;2239 NSRect r = [self frame]; 2240 NSRect rr = NSZeroRect; 2241 GLint i = 0; 2135 2242 NSDockTile *pDT = nil; 2136 float xStretch, yStretch; 2243 float xStretch; 2244 float yStretch; 2137 2245 2138 2246 if ([m_DockTileView thumbBitmap] != nil) 2139 2247 { 2140 /* Only update after at least 200 ms, cause glReadPixels is 2141 * heavy performance wise. */ 2142 uint64_t uiNewTime = RTTimeMilliTS(); 2143 VBOXVR_SCR_COMPOSITOR_CONST_ITERATOR CIter; 2144 const VBOXVR_SCR_COMPOSITOR_ENTRY *pEntry; 2248 /* 2249 * Only update after at least 200 ms, cause glReadPixels is 2250 * heavy performance wise. 2251 */ 2252 uint64_t msTS = RTTimeSystemMilliTS(); 2253 VBOXVR_SCR_COMPOSITOR_CONST_ITERATOR CIter; 2254 const VBOXVR_SCR_COMPOSITOR_ENTRY *pEntry; 2145 2255 2146 if ( uiNewTime - m_uiDockUpdateTime> 200)2256 if (msTS - m_msDockUpdateTS > 200) 2147 2257 { 2148 m_ uiDockUpdateTime = uiNewTime;2258 m_msDockUpdateTS = msTS; 2149 2259 #if 0 2150 2260 /* todo: check this for optimization */ … … 2176 2286 while ((pEntry = CrVrScrCompositorConstIterNext(&CIter)) != NULL) 2177 2287 { 2178 uint32_t cRegions; 2179 const RTRECT *paSrcRegions, *paDstRegions; 2288 uint32_t cRegions; 2289 PCRTRECT paSrcRegions; 2290 PCRTRECT paDstRegions; 2180 2291 int rc = CrVrScrCompositorEntryRegionsGet(pCompositor, pEntry, &cRegions, &paSrcRegions, &paDstRegions, NULL); 2181 uint32_t fFlags = CrVrScrCompositorEntryFlagsCombinedGet(pCompositor, pEntry);2292 uint32_t fFlags = CrVrScrCompositorEntryFlagsCombinedGet(pCompositor, pEntry); 2182 2293 if (RT_SUCCESS(rc)) 2183 2294 { 2184 uint32_t i;2185 2295 int rc = CrBltEnter(m_pBlitter); 2186 2296 if (RT_SUCCESS(rc)) 2187 2297 { 2298 uint32_t i; 2188 2299 for (i = 0; i < cRegions; ++i) 2189 2300 { 2190 const RTRECT * pSrcRect = &paSrcRegions[i]; 2191 const RTRECT * pDstRect = &paDstRegions[i]; 2192 RTRECT SrcRect, DstRect, RestrictSrcRect, RestrictDstRect; 2301 const CR_TEXDATA *pTexData; 2302 PCRTRECT pSrcRect = &paSrcRegions[i]; 2303 PCRTRECT pDstRect = &paDstRegions[i]; 2304 RTRECT DstRect, RestrictDstRect; 2305 RTRECT SrcRect, RestrictSrcRect; 2193 2306 2194 2307 vboxNSRectToRect(&m_RootRect, &RestrictDstRect); … … 2203 2316 2204 2317 vboxNSRectToRectUnstretched(&m_RootRect, &RestrictSrcRect, xStretch, yStretch); 2205 VBoxRectTranslate(&RestrictSrcRect, -CrVrScrCompositorEntryRectGet(pEntry)->xLeft, -CrVrScrCompositorEntryRectGet(pEntry)->yTop); 2318 VBoxRectTranslate(&RestrictSrcRect, 2319 -CrVrScrCompositorEntryRectGet(pEntry)->xLeft, 2320 -CrVrScrCompositorEntryRectGet(pEntry)->yTop); 2206 2321 VBoxRectIntersected(&RestrictSrcRect, pSrcRect, &SrcRect); 2207 2322 … … 2212 2327 pDstRect = &DstRect; 2213 2328 2214 const CR_TEXDATA *pTexData = CrVrScrCompositorEntryTexGet(pEntry);2329 pTexData = CrVrScrCompositorEntryTexGet(pEntry); 2215 2330 2216 2331 CrBltBlitTexMural(m_pBlitter, true, CrTdTexGet(pTexData), pSrcRect, pDstRect, 1, fFlags); … … 2221 2336 { 2222 2337 DEBUG_WARN(("CrBltEnter failed rc %d", rc)); 2338 #ifndef DEBUG_VERBOSE 2339 AssertMsgFailed(("CrBltEnter failed rc %Rrc", rc)); 2340 #endif 2223 2341 } 2224 2342 } 2225 2343 else 2226 2344 { 2227 Assert(0);2228 2345 DEBUG_MSG_1(("BlitStretched: CrVrScrCompositorEntryRegionsGet failed rc %d\n", rc)); 2346 AssertMsgFailed(("BlitStretched: CrVrScrCompositorEntryRegionsGet failed rc %Rrc\n", rc)); 2229 2347 } 2230 2348 } … … 2253 2371 2254 2372 /* Send a display message to the dock tile in the main thread */ 2255 [[[NSApplication sharedApplication] dockTile] performSelectorOnMainThread:@selector(display) withObject:nil waitUntilDone:NO]; 2373 [[[NSApplication sharedApplication] dockTile] performSelectorOnMainThread:@selector(display) withObject:nil 2374 waitUntilDone:NO]; 2256 2375 } 2257 2376 } … … 2261 2380 { 2262 2381 DEBUG_FUNC_ENTER(); 2263 if (m_paClipRects)2382 if (m_paClipRects) 2264 2383 { 2265 2384 RTMemFree(m_paClipRects); … … 2286 2405 GLint cOldRects = m_cClipRects; 2287 2406 2288 DEBUG_MSG_1(("OVIW(%p): setVisibleRegions: cRects=%d\n", (void *)self, cRects));2407 DEBUG_MSG_1(("OVIW(%p): setVisibleRegions: cRects=%d\n", (void *)self, cRects)); 2289 2408 2290 2409 [self clearVisibleRegions]; … … 2293 2412 { 2294 2413 #ifdef DEBUG_poetzsch 2295 int i = 0;2414 int i = 0; 2296 2415 for (i = 0; i < cRects; ++i) 2297 DEBUG_MSG_1(("OVIW(%p): setVisibleRegions: %d - %d %d %d %d\n", (void *)self, i, paRects[i * 4], paRects[i * 4 + 1], paRects[i * 4 + 2], paRects[i * 4 + 3]));2416 DEBUG_MSG_1(("OVIW(%p): setVisibleRegions: %d - %d %d %d %d\n", (void *)self, i, paRects[i * 4], paRects[i * 4 + 1], paRects[i * 4 + 2], paRects[i * 4 + 3])); 2298 2417 #endif 2299 2418 … … 2306 2425 } 2307 2426 2308 - (NSView *)dockTileScreen2427 - (NSView *)dockTileScreen 2309 2428 { 2310 2429 DEBUG_FUNC_ENTER(); 2311 2430 NSView *contentView = [[[NSApplication sharedApplication] dockTile] contentView]; 2312 2431 NSView *screenContent = nil; 2313 /* First try the new variant which checks if this window is within the 2314 screen which is previewed in the dock. */ 2432 2433 /* 2434 * First try the new variant which checks if this window is within the 2435 * screen which is previewed in the dock. 2436 */ 2315 2437 if ([contentView respondsToSelector:@selector(screenContentWithParentView:)]) 2316 screenContent = [contentView performSelector:@selector(screenContentWithParentView:) withObject:(id)m_pParentView]; 2317 /* If it fails, fall back to the old variant (VBox...) */ 2438 screenContent = [contentView performSelector:@selector(screenContentWithParentView:) withObject:(id)m_pParentView]; 2439 /* 2440 * If it fails, fall back to the old variant (VBox...). 2441 */ 2318 2442 else if ([contentView respondsToSelector:@selector(screenContent)]) 2319 2443 screenContent = [contentView performSelector:@selector(screenContent)]; 2320 2444 2321 2445 DEBUG_FUNC_LEAVE(); … … 2332 2456 { 2333 2457 NSRect dockFrame = [pView frame]; 2334 /* todo: this is not correct, we should use framebuffer size here, while parent view frame size may differ in case of scrolling */ 2458 /** @todo This is not correct, we should use framebuffer size here, while 2459 * parent view frame size may differ in case of scrolling. */ 2335 2460 NSRect parentFrame = [m_pParentView frame]; 2336 2461 2337 2462 m_FBOThumbScaleX = (float)dockFrame.size.width / parentFrame.size.width; 2338 2463 m_FBOThumbScaleY = (float)dockFrame.size.height / parentFrame.size.height; 2339 newFrame = NSMakeRect((int)(m_Pos.x * m_FBOThumbScaleX), (int)(dockFrame.size.height - (m_Pos.y + m_Size.height - m_yInvRootOffset) * m_FBOThumbScaleY), (int)(m_Size.width * m_FBOThumbScaleX), (int)(m_Size.height * m_FBOThumbScaleY)); 2464 newFrame = NSMakeRect((int)(m_Pos.x * m_FBOThumbScaleX), 2465 (int)(dockFrame.size.height - (m_Pos.y + m_Size.height - m_yInvRootOffset) * m_FBOThumbScaleY), 2466 (int)(m_Size.width * m_FBOThumbScaleX), 2467 (int)(m_Size.height * m_FBOThumbScaleY)); 2340 2468 /* 2341 2469 NSRect newFrame = NSMakeRect ((int)roundf(m_Pos.x * m_FBOThumbScaleX), (int)roundf(dockFrame.size.height - (m_Pos.y + m_Size.height) * m_FBOThumbScaleY), (int)roundf(m_Size.width * m_FBOThumbScaleX), (int)roundf(m_Size.height * m_FBOThumbScaleY)); … … 2348 2476 } 2349 2477 2350 @end 2478 @end /* @implementation OverlayView */ 2479 2351 2480 2352 2481 /******************************************************************************** … … 2605 2734 2606 2735 DEBUG_WARN(("cocoaViewDisplay should never happen!\n")); 2607 DEBUG_MSG_1(("cocoaViewDisplay %p\n", (void *)pView));2736 DEBUG_MSG_1(("cocoaViewDisplay %p\n", (void *)pView)); 2608 2737 [(OverlayView*)pView swapFBO]; 2609 2738 … … 2639 2768 typedef struct CR_RCD_GETGEOMETRY 2640 2769 { 2641 OverlayView *pView;2642 NSRect rect;2770 OverlayView *pView; 2771 NSRect rect; 2643 2772 } CR_RCD_GETGEOMETRY; 2644 2773 2645 static DECLCALLBACK(void) vboxRcdGetGeomerty(void *pv Cb)2646 { 2647 DEBUG_FUNC_ENTER(); 2648 CR_RCD_GETGEOMETRY * pGetGeometry = (CR_RCD_GETGEOMETRY *)pvCb;2774 static DECLCALLBACK(void) vboxRcdGetGeomerty(void *pvUser) 2775 { 2776 DEBUG_FUNC_ENTER(); 2777 CR_RCD_GETGEOMETRY * pGetGeometry = (CR_RCD_GETGEOMETRY *)pvUser; 2649 2778 pGetGeometry->rect = [[pGetGeometry->pView window] frame]; 2650 2779 DEBUG_FUNC_LEAVE(); … … 2653 2782 void cocoaViewGetGeometry(NativeNSViewRef pView, int *pX, int *pY, int *pW, int *pH) 2654 2783 { 2655 DEBUG_FUNC_ENTER(); 2656 NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init]; 2784 NSAutoreleasePool *pPool; 2785 DEBUG_FUNC_ENTER(); 2786 pPool = [[NSAutoreleasePool alloc] init]; 2657 2787 2658 2788 NSRect frame; … … 2665 2795 { 2666 2796 CR_RCD_GETGEOMETRY GetGeometry; 2667 GetGeometry.pView = (OverlayView *)pView;2797 GetGeometry.pView = (OverlayView *)pView; 2668 2798 renderspuCalloutClient(vboxRcdGetGeomerty, &GetGeometry); 2669 2799 frame = GetGeometry.rect; … … 2722 2852 NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init]; 2723 2853 2724 DEBUG_MSG(("cocoaViewMakeCurrentContext(%p, %p)\n", (void *)pView, (void*)pCtx));2854 DEBUG_MSG(("cocoaViewMakeCurrentContext(%p, %p)\n", (void *)pView, (void *)pCtx)); 2725 2855 2726 2856 if (pView)
Note:
See TracChangeset
for help on using the changeset viewer.