VirtualBox

Changeset 53556 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Dec 17, 2014 12:21:43 AM (10 years ago)
Author:
vboxsync
Message:

renderspu_cocoa_helper.m: Cleanups.

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  
    55
    66/*
    7  * Copyright (C) 2009-2012 Oracle Corporation
     7 * Copyright (C) 2009-2014 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3333ADD_COCOA_NATIVE_REF(NSOpenGLContext);
    3434
    35 /* OpenGL context management */
     35/** @name OpenGL context management
     36 * @{ */
    3637void cocoaGLCtxCreate(NativeNSOpenGLContextRef *ppCtx, GLbitfield fVisParams, NativeNSOpenGLContextRef pSharedCtx);
    3738void cocoaGLCtxDestroy(NativeNSOpenGLContextRef pCtx);
     39/** @} */
    3840
    39 /* View management */
     41/** @name View management
     42 * @{ */
    4043void cocoaViewCreate(NativeNSViewRef *ppView, struct WindowInfo *pWinInfo, NativeNSViewRef pParentView, GLbitfield fVisParams);
    4144void cocoaViewReparent(NativeNSViewRef pView, NativeNSViewRef pParentView);
     
    4447void cocoaViewShow(NativeNSViewRef pView, GLboolean fShowIt);
    4548void 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 
     49void cocoaViewSetSize(NativeNSViewRef pView, int cx, int cy);
     50void cocoaViewGetGeometry(NativeNSViewRef pView, int *px, int *py, int *pcx, int *pcy);
    4951void cocoaViewMakeCurrentContext(NativeNSViewRef pView, NativeNSOpenGLContextRef pCtx);
    50 void cocoaViewSetVisibleRegion(NativeNSViewRef pView, GLint cRects, const GLint* paRects);
     52void cocoaViewSetVisibleRegion(NativeNSViewRef pView, GLint cRects, const GLint *paRects);
    5153GLboolean cocoaViewNeedsEmptyPresent(NativeNSViewRef pView);
    5254void cocoaViewPresentComposition(NativeNSViewRef pView, const struct VBOXVR_SCR_COMPOSITOR_ENTRY *pChangedEntry);
     55/** @} */
    5356
    5457RT_C_DECLS_END
  • trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu_cocoa_helper.m

    r52625 r53556  
    1515 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
    1616 */
    17 
    18 #include "renderspu_cocoa_helper.h"
    19 
    20 #import <Cocoa/Cocoa.h>
    21 #undef PVM
    22 
    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_THUMBNAIL
    36 # include <cr_pixeldata.h>
    37 #endif
    38 
    39 
    40 #include "renderspu.h"
    4117
    4218/** @page pg_opengl_cocoa  OpenGL - Cocoa Window System Helper
     
    8561 */
    8662
     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*******************************************************************************/
    8794/* 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     
    93108#endif
    94109
     
    97112# define DEBUG_INFO(text) do { \
    98113        crWarning text ; \
    99         Assert(0); \
     114        AssertFailed(); \
    100115    } while (0)
    101 
    102 # define DEBUG_MSG(text) \
    103     printf text
    104116
    105117# define DEBUG_WARN(text) do { \
    106118        crWarning text ; \
    107         Assert(0); \
     119        AssertFailed(); \
    108120    } while (0)
    109121
    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)
    112124
    113125#else
     
    117129    } while (0)
    118130
    119 # define DEBUG_MSG(text) \
    120     do {} while (0)
    121 
    122131# define DEBUG_WARN(text) do { \
    123132        crWarning text ; \
    124133    } while (0)
    125134
    126 # define DEBUG_MSG_1(text) \
    127     do {} while (0)
     135# define DEBUG_MSG(text)   do {} while (0)
     136# define DEBUG_MSG_1(text) do {} while (0)
    128137
    129138#endif
    130139
    131140
    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 { \
    177146        glPushAttrib(GL_ALL_ATTRIB_BITS); \
    178147        glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS); \
     
    185154        glMatrixMode(GL_MODELVIEW); \
    186155        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 { \
    193160        glMatrixMode(GL_MODELVIEW); \
    194161        glPopMatrix(); \
     
    201168        glPopClientAttrib(); \
    202169        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);
     174static 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
     200static NSOpenGLContext *vboxCtxGetCurrent(void)
    207201{
    208202    GET_CONTEXT(pCtxInfo);
     
    216210}
    217211
    218 static bool vboxCtxSyncCurrentInfo()
     212static bool vboxCtxSyncCurrentInfo(void)
    219213{
    220214    GET_CONTEXT(pCtxInfo);
     
    226220        WindowInfo *pWinInfo = pCtxInfo->currentWindow;
    227221        Assert(pWinInfo);
    228         if (pCtxInfo->context != pCtx
    229             || pWinInfo->window != pView)
     222        if (   pCtxInfo->context != pCtx
     223            || pWinInfo->window  != pView)
    230224        {
    231225            renderspu_SystemMakeCurrent(pWinInfo, 0, pCtxInfo);
     
    233227        }
    234228    }
    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;
    242233    }
    243234   
     
    245236}
    246237
     238
     239/**
     240 * State carrying structure for use with vboxCtxEnter and vboxCtxLeave
     241 */
    247242typedef struct VBOX_CR_RENDER_CTX_INFO
    248243{
    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. */
     249typedef VBOX_CR_RENDER_CTX_INFO *PVBOX_CR_RENDER_CTX_INFO;
     250
     251static 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)
    267263            glFlush();
    268264       
    269         [pCtx makeCurrentContext];
     265        [pNewCtx makeCurrentContext];
    270266       
    271267        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;
    274271    }
    275272    else
    276273    {
     274        /* No context switch necessary. */
    277275        pCtxInfo->fIsValid = false;
    278276    }
     
    283281    if (pCtxInfo->fIsValid)
    284282    {
    285         NSOpenGLContext *pOldCtx = pCtxInfo->pCtx;
    286         NSView *pOldView = pCtxInfo->pView;
     283        NSOpenGLContext *pOldCtx  = pCtxInfo->pCtx;
     284        NSView          *pOldView = pCtxInfo->pView;
    287285   
    288286        glFlush();
    289287        if (pOldCtx != nil)
    290288        {
    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)
    292295            {
    293296                [pOldCtx setView: pOldView];
     
    296299            [pOldCtx makeCurrentContext];
    297300           
    298 #ifdef DEBUG
     301#ifdef VBOX_STRICT
    299302            {
    300                 NSOpenGLContext *pTstOldCtx = [NSOpenGLContext currentContext];
    301                 NSView *pTstOldView = (pTstOldCtx ? [pTstOldCtx view] : nil);
     303                NSOpenGLContext *pTstOldCtx  = [NSOpenGLContext currentContext];
     304                NSView          *pTstOldView = pTstOldCtx ? [pTstOldCtx view] : nil;
    302305                Assert(pTstOldCtx == pOldCtx);
    303306                Assert(pTstOldView == pOldView);
     
    312315}
    313316
    314 /** Custom OpenGL context class.
     317
     318/**
     319 * Custom OpenGL context class.
    315320 *
    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 */
    319325@interface OverlayOpenGLContext: NSOpenGLContext
    320326{
     
    323329    NSView              *m_pView;
    324330}
    325 - (NSOpenGLPixelFormat*)openGLPixelFormat;
     331- (NSOpenGLPixelFormat *)openGLPixelFormat;
    326332@end
    327333
     334/**
     335 * Abstrack task class.
     336 */
    328337@interface VBoxTask : NSObject
    329338{
     
    332341@end
    333342
     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 */
    334356@interface VBoxTaskPerformSelector : VBoxTask
    335357{
    336358@private
    337     id m_Object;
     359    id  m_Object;
    338360    SEL m_Selector;
    339     id m_Arg;
     361    id  m_Arg;
    340362}
    341363- (id)initWithObject:(id)aObject selector:(SEL)aSelector arg:(id)aArg;
     
    344366@end
    345367
    346 #if 0
    347 typedef DECLCALLBACKPTR(void, PFNVBOXTASKCALLBACK)(void *pvCb);
    348 
    349 @interface VBoxTaskCallback: VBoxTask
    350 {
    351 @private
    352     PFNVBOXTASKCALLBACK m_pfnCb;
    353     void *m_pvCb;
    354 }
    355 - (id)initWithCb:(PFNVBOXTASKCALLBACK)pfnCb arg:(void*)pvCb;
    356 - (void)run;
    357 @end
    358 #endif
    359 
    360 @interface VBoxTaskComposite: VBoxTask
    361 {
    362 @private
    363     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 @end
    372 
    373 @implementation VBoxTask
    374 @end
    375 
    376368@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 */
    377377- (id)initWithObject:(id)aObject selector:(SEL)aSelector arg:(id)aArg
    378378{
    379379    self = [super init];
    380 
    381380    if (self)
    382381    {
     
    407406@end
    408407
     408
     409#if 0
     410/** Callback function pointer type for VBoxTaskCallback. */
     411typedef 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
    409444@implementation VBoxTaskComposite
    410445- (id)init
     
    429464}
    430465
    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
    432472{
    433473    [pTask retain];
     
    447487- (void)run
    448488{
    449     for(;;)
    450     {
     489    for (;;)
     490    {
     491        /*
     492         * Dequeue a task.
     493         */
    451494        int rc = RTCritSectEnter(&m_Lock);
    452495        if (RT_FAILURE(rc))
     
    466509        }
    467510
    468         VBoxTask* pTask = (VBoxTask*)[m_pArray objectAtIndex:m_CurIndex];
     511        VBoxTask *pTask = (VBoxTask *)[m_pArray objectAtIndex:m_CurIndex];
    469512        Assert(pTask != nil);
    470513       
    471514        ++m_CurIndex;
    472515       
     516        /*
     517         * Remove the first 1025 empty entires.
     518         */
    473519        if (m_CurIndex > 1024)
    474520        {
     
    481527        RTCritSectLeave(&m_Lock);
    482528       
     529        /*
     530         * Run the task and release it.
     531         */
    483532        [pTask run];
    484533        [pTask release];
     
    489538{
    490539    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];
    494543        DEBUG_WARN(("dealloc with non-empty tasks! %p\n", pTask));
    495544        [pTask release];
     
    503552@end
    504553
     554
     555/**
     556 *
     557 *
     558 */
    505559@interface VBoxMainThreadTaskRunner : NSObject
    506560{
     
    509563}
    510564- (id)init;
    511 - (void)add:(VBoxTask*)pTask;
     565- (void)add:(VBoxTask *)pTask;
    512566- (void)addObj:(id)aObject selector:(SEL)aSelector arg:(id)aArg;
    513567- (void)runTasks;
    514568- (bool)runTasksSyncIfPossible;
    515569- (void)dealloc;
    516 + (VBoxMainThreadTaskRunner*) globalInstance;
     570+ (VBoxMainThreadTaskRunner *) globalInstance;
    517571@end
    518572
     
    529583}
    530584
    531 + (VBoxMainThreadTaskRunner*) globalInstance
    532 {
    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];
    537591    });
    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
    555596{
    556597    DEBUG_FUNC_ENTER();
    557598    [m_pTasks add:pTask];
     599    /** @todo r=bird: Unbalanced [self retain]. */
    558600    [self retain];
    559601
     
    567609}
    568610
     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 */
    569618- (void)addObj:(id)aObject selector:(SEL)aSelector arg:(id)aArg
    570619{
     
    574623}
    575624
     625   
     626/**
     627 * Internal method for running the pending tasks.
     628 */
    576629- (void)runTasks
    577630{
    578     BOOL fIsMain = [NSThread isMainThread];
    579     Assert(fIsMain);
    580     if (fIsMain)
     631    if ([NSThread isMainThread])
    581632    {
    582633        [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. */
    583640        [self release];
    584641    }
     
    586643    {
    587644        DEBUG_WARN(("run tasks called not on main thread!\n"));
     645#ifndef DEBUG_VERBOSE
     646        AssertFailed();
     647#endif
    588648        [self performSelectorOnMainThread:@selector(runTasks) withObject:nil waitUntilDone:YES];
    589649    }
    590650}
    591651
     652/**
     653 * Callback for calling runTasks via renderspuCalloutClient.
     654 * @param   pvUser      The VBoxMainThreadTaskRunner singleton.
     655 */
     656static 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 */
    592670- (bool)runTasksSyncIfPossible
    593671{
     672    /*
     673     * Call on main thread (?) via renderspuCalloutClient (whatever that is).
     674     */
    594675    if (renderspuCalloutAvailable())
    595676    {
    596         CR_RCD_RUN Run;
    597         Run.pRunner = self;
    598677        Assert(![NSThread isMainThread]);
    599         renderspuCalloutClient(vboxRcdRun, &Run);
     678        renderspuCalloutClient(VBoxMainThreadTaskRunner_RcdRunCallback, self);
    600679        return true;
    601680    }
    602681   
     682    /*
     683     * Run directly if on main thread.
     684     */
    603685    if ([NSThread isMainThread])
    604686    {
     
    607689    }
    608690   
     691    /* Not possible. */
    609692    return false;
    610693}
     
    612695- (void)dealloc
    613696{
     697    /** @todo r=bird: WTF is the point of the deallocator. The object is a singelton
     698     *        stored in an inaccessible static variable! */
    614699    [m_pTasks release];
     700    m_pTasks = nil;
     701
    615702    [super dealloc];
    616703}
     
    620707@class DockOverlayView;
    621708
    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
    631721{
    632722@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;
    641731
    642732    /** The corresponding dock tile view of this OpenGL view & all helper
    643733     * 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    /** @} */
    657751
    658752    /** 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;
    671765- (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;
    678772
    679773- (void)vboxSetPos:(NSPoint)pos;
    680774- (void)vboxSetPosUI:(NSPoint)pos;
    681 - (void)vboxSetPosUIObj:(NSValue*)pPos;
     775- (void)vboxSetPosUIObj:(NSValue *)pPos;
    682776- (NSPoint)pos;
    683777- (bool)isEverSized;
    684778- (void)vboxDestroy;
    685779- (void)vboxSetSizeUI:(NSSize)size;
    686 - (void)vboxSetSizeUIObj:(NSValue*)pSize;
     780- (void)vboxSetSizeUIObj:(NSValue *)pSize;
    687781- (void)vboxSetSize:(NSSize)size;
    688782- (NSSize)size;
     
    698792- (void)swapFBO;
    699793- (void)vboxSetVisible:(GLboolean)fVisible;
    700 - (void)vboxSetVisibleUIObj:(NSNumber*)pVisible;
     794- (void)vboxSetVisibleUIObj:(NSNumber *)pVisible;
    701795- (void)vboxSetVisibleUI:(GLboolean)fVisible;
    702796- (void)vboxTryDraw;
    703797- (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;
    711805- (void)vboxBlitterSyncWindow;
    712806
    713807- (void)clearVisibleRegions;
    714 - (void)setVisibleRegions:(GLint)cRects paRects:(const GLint*)paRects;
     808- (void)setVisibleRegions:(GLint)cRects paRects:(const GLint *)paRects;
    715809- (GLboolean)vboxNeedsEmptyPresent;
    716810
    717 - (NSView*)dockTileScreen;
     811- (NSView *)dockTileScreen;
    718812- (void)reshapeDockTile;
    719813- (void)cleanupData;
    720814@end
    721815
    722 /** Helper view.
     816/**
     817 * Helper view.
    723818 *
    724819 * This view is added as a sub view of the parent view to track
     
    726821 * (which happens on fullscreen/seamless entry/exit) the overlay
    727822 * window is informed & can add them self as a child window
    728  * again. */
     823 * again.
     824 */
    729825@class OverlayWindow;
    730826@interface OverlayHelperView: NSView
     
    733829    OverlayWindow *m_pOverlayWindow;
    734830}
    735 -(id)initWithOverlayWindow:(OverlayWindow*)pOverlayWindow;
     831-(id)initWithOverlayWindow:(OverlayWindow *)pOverlayWindow;
    736832@end
    737833
    738 /** Custom window class.
     834/**
     835 * Custom window class.
    739836 *
    740837 * This is the overlay window which contains our custom NSView.
    741838 * Its a direct child of the Qt Main window. It marks its background
    742839 * 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
    745843{
    746844@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;
    753851- (void)parentWindowFrameChanged:(NSNotification *)note;
    754 - (void)parentWindowChanged:(NSWindow*)pWindow;
     852- (void)parentWindowChanged:(NSWindow *)pWindow;
    755853@end
    756854
     855
     856/**
     857 * Dock overlay view class.
     858 */
    757859@interface DockOverlayView: NSView
    758860{
    759     NSBitmapImageRep *m_ThumbBitmap;
    760     NSImage          *m_ThumbImage;
    761     NSLock           *m_Lock;
     861    NSBitmapImageRep   *m_ThumbBitmap;
     862    NSImage            *m_ThumbImage;
     863    NSLock             *m_Lock;
    762864}
    763865- (void)dealloc;
     
    767869- (void)setFrame:(NSRect)frame;
    768870- (void)drawRect:(NSRect)aRect;
    769 - (NSBitmapImageRep*)thumbBitmap;
    770 - (NSImage*)thumbImage;
     871- (NSBitmapImageRep *)thumbBitmap;
     872- (NSImage *)thumbImage;
    771873@end
    772874
     
    776878    DEBUG_FUNC_ENTER();
    777879    self = [super init];
    778 
    779880    if (self)
    780881    {
    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
    782884         * 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         */
    784887        m_Lock = [[NSLock alloc] init];
    785888    }
     
    811914        m_ThumbImage = nil;
    812915    }
     916
    813917    if (m_ThumbBitmap != nil)
    814918    {
     
    856960            bitmapFormat:NSAlphaFirstBitmapFormat
    857961            bytesPerRow:frame.size.width * 4
    858             bitsPerPixel:8 * 4];
     962            bitsPerPixel:8 * 4
     963        ];
    859964        m_ThumbImage = [[NSImage alloc] initWithSize:[m_ThumbBitmap size]];
    860965        [m_ThumbImage addRepresentation:m_ThumbBitmap];
    861966    }
     967
    862968    [self unlock];
    863969    DEBUG_FUNC_LEAVE();
     
    873979- (void)drawRect:(NSRect)aRect
    874980{
    875     DEBUG_FUNC_ENTER();
    876981    NSRect frame;
    877 
     982    DEBUG_FUNC_ENTER();
    878983    [self lock];
     984
    879985#ifdef SHOW_WINDOW_BACKGROUND
    880986    [[NSColor colorWithCalibratedRed:1.0 green:0.0 blue:0.0 alpha:0.7] set];
     
    884990    if (m_ThumbImage != nil)
    885991        [m_ThumbImage drawAtPoint:NSMakePoint(0, 0) fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
     992
    886993    [self unlock];
    887994    DEBUG_FUNC_LEAVE();
    888995}
    889996
    890 - (NSBitmapImageRep*)thumbBitmap
     997- (NSBitmapImageRep *)thumbBitmap
    891998{
    892999    DEBUG_FUNC_ENTER();
     
    8951002}
    8961003
    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();
    9021008    return m_ThumbImage;
    9031009}
    9041010@end
     1011
    9051012
    9061013/********************************************************************************
     
    9111018@implementation OverlayOpenGLContext
    9121019
    913 -(id)initWithFormat:(NSOpenGLPixelFormat*)format shareContext:(NSOpenGLContext*)share
     1020-(id)initWithFormat:(NSOpenGLPixelFormat *)format shareContext:(NSOpenGLContext *)share
    9141021{
    9151022    DEBUG_FUNC_ENTER();
     
    9221029        m_pPixelFormat = format;
    9231030
    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();
    9281033    return self;
    9291034}
     
    9321037{
    9331038    DEBUG_FUNC_ENTER();
    934 
    935     DEBUG_MSG(("OCTX(%p): dealloc OverlayOpenGLContext\n", (void*)self));
     1039    DEBUG_MSG(("OCTX(%p): dealloc OverlayOpenGLContext\n", (void *)self));
    9361040
    9371041    [m_pPixelFormat release];
     
    9501054   
    9511055    DEBUG_FUNC_LEAVE();
    952    
    9531056    return val == GL_TRUE ? YES : NO;
    9541057}
    9551058
    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));
    9611063
    9621064#if 1 /* def FBO */
     
    9691071}
    9701072
    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();
    9761077#if 1 /* def FBO */
    9771078    return m_pView;
     
    9841085{
    9851086    DEBUG_FUNC_ENTER();
    986 
    987     DEBUG_MSG(("OCTX(%p): clearDrawable\n", (void*)self));
     1087    DEBUG_MSG(("OCTX(%p): clearDrawable\n", (void *)self));
    9881088
    9891089    m_pView = NULL;;
     
    9931093}
    9941094
    995 -(NSOpenGLPixelFormat*)openGLPixelFormat
     1095-(NSOpenGLPixelFormat *)openGLPixelFormat
    9961096{
    9971097    DEBUG_FUNC_ENTER();
     
    10011101}
    10021102
    1003 @end
     1103@end  /* @implementation OverlayOpenGLContext */
     1104
    10041105
    10051106/********************************************************************************
     
    10101111@implementation OverlayHelperView
    10111112
    1012 -(id)initWithOverlayWindow:(OverlayWindow*)pOverlayWindow
     1113-(id)initWithOverlayWindow:(OverlayWindow *)pOverlayWindow
    10131114{
    10141115    DEBUG_FUNC_ENTER();
     
    10181119    m_pOverlayWindow = pOverlayWindow;
    10191120
    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();
    10241123    return self;
    10251124}
     
    10281127{
    10291128    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]));
    10321130
    10331131    [m_pOverlayWindow parentWindowChanged:[self window]];
     
    10371135
    10381136@end
     1137
    10391138
    10401139/********************************************************************************
     
    10451144@implementation OverlayWindow
    10461145
    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();
    10511149    NSWindow *pParentWin = nil;
    10521150
    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)
    10541153    {
    10551154        m_pParentView = pParentView;
     
    10601159
    10611160        m_pOverlayHelperView = [[OverlayHelperView alloc] initWithOverlayWindow:self];
     1161
    10621162        /* Add the helper view as a child of the parent view to get notifications */
    10631163        [pParentView addSubview:m_pOverlayHelperView];
     
    10721172        [self setOpaque:NO];
    10731173        [self setAlphaValue:.999];
     1174
    10741175        /* Disable mouse events for this window */
    10751176        [self setIgnoresMouseEvents:YES];
     
    10901191        [pParentWin addChildWindow:self ordered:NSWindowAbove];
    10911192    }
    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();
    10961196    return self;
    10971197}
     
    11001200{
    11011201    DEBUG_FUNC_ENTER();
    1102 
    1103     DEBUG_MSG(("OWIN(%p): dealloc OverlayWindow\n", (void*)self));
     1202    DEBUG_MSG(("OWIN(%p): dealloc OverlayWindow\n", (void *)self));
    11041203
    11051204    [[NSNotificationCenter defaultCenter] removeObserver:self];
     
    11131212}
    11141213
    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     */
    11231223    /*
    11241224    [m_pOverlayView performSelector:@selector(vboxReshapePerform) onThread:m_Thread withObject:nil waitUntilDone:YES];
     
    11271227    if ([m_pOverlayView isEverSized])
    11281228    {   
    1129         if([NSThread isMainThread])
     1229        if ([NSThread isMainThread])
    11301230            [m_pOverlayView vboxReshapePerform];
    11311231        else
     
    11361236}
    11371237
    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));
    11431242
    11441243    [[NSNotificationCenter defaultCenter] removeObserver:self];
    11451244
    1146     if(pWindow != nil)
     1245    if (pWindow != nil)
    11471246    {
    11481247        /* Ask to get notifications when our parent window frame changes. */
     
    11521251            name:NSWindowDidResizeNotification
    11531252            object:pWindow];
     1253
    11541254        /* Add us self as child window */
    11551255        [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         */
    11581261        /*
    11591262        [m_pOverlayView performSelector:@selector(vboxReshapePerform) withObject:nil afterDelay:0.2];
     
    11631266        if ([m_pOverlayView isEverSized])
    11641267        {   
    1165             if([NSThread isMainThread])
     1268            if ([NSThread isMainThread])
    11661269                [m_pOverlayView vboxReshapePerform];
    11671270            else
     
    11731276}
    11741277
    1175 @end
     1278@end /* @implementation OverlayWindow */
     1279
     1280
    11761281
    11771282/********************************************************************************
     
    11821287@implementation OverlayView
    11831288
    1184 - (id)initWithFrame:(NSRect)frame thread:(RTTHREAD)aThread parentView:(NSView*)pParentView winInfo:(WindowInfo*)pWinInfo
     1289- (id)initWithFrame:(NSRect)frame thread:(RTTHREAD)aThread parentView:(NSView *)pParentView winInfo:(WindowInfo *)pWinInfo
    11851290{
    11861291    DEBUG_FUNC_ENTER();
     
    11901295    m_pGLCtx                  = nil;
    11911296    m_pSharedGLCtx            = nil;
    1192     mThread                   = aThread;
     1297    m_Thread                  = aThread;
    11931298    m_FBOId                   = 0;
    11941299    m_cClipRects              = 0;
     
    11991304    m_yInvRootOffset          = 0;
    12001305    m_pBlitter                = nil;
    1201     m_pWinInfo                    = pWinInfo;
     1306    m_pWinInfo                = pWinInfo;
    12021307    m_fNeedViewportUpdate     = true;       
    12031308    m_fNeedCtxUpdate          = true;
     
    12081313    self = [super initWithFrame:frame];
    12091314
    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();
    12141317    return self;
    12151318}
     
    12201323
    12211324    [self deleteDockTile];
    1222    
     1325
    12231326    [self setGLCtx:nil];
    12241327   
     
    12291332
    12301333        [m_pSharedGLCtx release];
    1231 
    12321334        m_pSharedGLCtx = nil;
    12331335       
    12341336        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    }
    12351384       
    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();
    12951392    return m_pGLCtx;
    12961393}
    12971394
    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();
    13031399    return m_pParentView;
    13041400}
    13051401
    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));
    13111406
    13121407    m_pParentView = pView;
     
    13151410}
    13161411
    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));
    13221416
    13231417    m_pOverlayWin = pWin;
     
    13261420}
    13271421
    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();
    13331426    return m_pOverlayWin;
    13341427}
     
    13461439}
    13471440
    1348 - (void)vboxSetPosUIObj:(NSValue*)pPos
     1441- (void)vboxSetPosUIObj:(NSValue *)pPos
    13491442{
    13501443    DEBUG_FUNC_ENTER();
     
    13561449}
    13571450
     1451#if 0 /* unused */
    13581452typedef struct CR_RCD_SETPOS
    13591453{
     
    13661460    DEBUG_FUNC_ENTER();
    13671461
    1368     CR_RCD_SETPOS * pPos = (CR_RCD_SETPOS*)pvCb;
     1462    CR_RCD_SETPOS *pPos = (CR_RCD_SETPOS*)pvCb;
    13691463    [pPos->pView vboxSetPosUI:pPos->pos];
    13701464
    13711465    DEBUG_FUNC_LEAVE();
    13721466}
     1467#endif
    13731468
    13741469- (void)vboxSetPos:(NSPoint)pos
     
    13761471    DEBUG_FUNC_ENTER();
    13771472
    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));
    13791474    VBoxMainThreadTaskRunner *pRunner = [VBoxMainThreadTaskRunner globalInstance];
    13801475    NSValue *pPos =  [NSValue valueWithPoint:pos];
     
    14011496{
    14021497    DEBUG_FUNC_ENTER();
    1403     BOOL fIsMain = [NSThread isMainThread];
    1404     NSWindow *pWin = nil;
     1498    BOOL        fIsMain = [NSThread isMainThread];
     1499    NSWindow   *pWin    = nil;
    14051500   
    14061501    Assert(fIsMain);
    14071502
    1408     /* Hide the view early */
     1503    /* Hide the view early. */
    14091504    [self setHidden: YES];
    14101505
     
    14211516           caused by main thread waiting xpcom thread, xpcom thread waiting to main hgcm thread,
    14221517           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. */
    14241519        [pWin performSelectorOnMainThread:@selector(release) withObject:nil waitUntilDone:NO];
    14251520    }
     
    14341529           caused by main thread waiting xpcom thread, xpcom thread waiting to main hgcm thread,
    14351530           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. */
    14371532        [self performSelectorOnMainThread:@selector(release) withObject:nil waitUntilDone:NO];
    14381533    }
     
    14431538}
    14441539
    1445 - (void)vboxSetSizeUIObj:(NSValue*)pSize
     1540- (void)vboxSetSizeUIObj:(NSValue *)pSize
    14461541{
    14471542    DEBUG_FUNC_ENTER();
     
    14541549{
    14551550    DEBUG_FUNC_ENTER();
     1551
    14561552    m_Size = size;
    1457    
    14581553    m_fEverSized = true;
    14591554
    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));
    14611556    [self vboxReshapeOnResizePerform];
    14621557
    14631558    /* ensure window contents is updated after that */
    14641559    [self vboxTryDrawUI];
    1465     DEBUG_FUNC_LEAVE();
    1466 }
    1467 
     1560
     1561    DEBUG_FUNC_LEAVE();
     1562}
     1563
     1564#if 0 /* unused */
    14681565typedef struct CR_RCD_SETSIZE
    14691566{
     
    14791576    DEBUG_FUNC_LEAVE();
    14801577}
     1578#endif
    14811579
    14821580- (void)vboxSetSize:(NSSize)size
     
    14941592{
    14951593    DEBUG_FUNC_ENTER();
     1594    DEBUG_FUNC_LEAVE();
    14961595    return m_Size;
    1497     DEBUG_FUNC_LEAVE();
    14981596}
    14991597
     
    15011599{
    15021600    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. */
    15061604    [m_pSharedGLCtx update];
    15071605
    15081606    [self vboxBlitterSyncWindow];
    15091607       
    1510     /* Clear background to transparent */
     1608    /* Clear background to transparent. */
    15111609    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    15121610    DEBUG_FUNC_LEAVE();
     
    15161614{
    15171615    DEBUG_FUNC_ENTER();
     1616   
    15181617    [self vboxReshapePerform];
    1519    
    15201618    [self createDockTile];
     1619
    15211620    /* have to rebind GL_TEXTURE_RECTANGLE_ARB as m_FBOTexId could be changed in updateFBO call */
    15221621    m_fNeedViewportUpdate = true;
     
    15341633    }
    15351634#endif
     1635
    15361636    DEBUG_FUNC_LEAVE();
    15371637}
     
    15531653    NSRect newFrame    = NSZeroRect;
    15541654
    1555     DEBUG_MSG(("OVIW(%p): vboxReshapePerform\n", (void*)self));
     1655    DEBUG_MSG(("OVIW(%p): vboxReshapePerform\n", (void *)self));
    15561656   
    15571657    parentFrame = [m_pParentView frame];
     
    15811681
    15821682    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));
    15861684    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));
    15901686         
    15911687    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));
    15951689
    15961690    /* Later we have to correct the texture position in the case the window is
     
    16021696   
    16031697    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));
    16071699   
    16081700       
     
    16241716    [[self window] setFrame:newFrame display:YES];
    16251717
    1626     /* Inform the dock tile view as well */
     1718    /* Inform the dock tile view as well. */
    16271719    [self reshapeDockTile];
    16281720
    1629     /* Make sure the context is updated according */
     1721    /* Make sure the context is updated accordingly. */
    16301722    /* [self updateViewport]; */
    16311723    if (m_pSharedGLCtx)
     
    16381730        vboxCtxLeave(&CtxInfo);
    16391731    }
     1732
    16401733    DEBUG_FUNC_LEAVE();
    16411734}
     
    16441737{
    16451738    DEBUG_FUNC_ENTER();
    1646         NSView *pDockScreen      = nil;
    1647         [self deleteDockTile];
     1739    NSView *pDockScreen = nil;
     1740
     1741    [self deleteDockTile];
    16481742       
    1649         /* Is there a dock tile preview enabled in the GUI? If so setup a
     1743    /* Is there a dock tile preview enabled in the GUI? If so setup a
    16501744     * additional thumbnail view for the dock tile. */
    1651         pDockScreen = [self dockTileScreen];
    1652         if (pDockScreen)
     1745    pDockScreen = [self dockTileScreen];
     1746    if (pDockScreen)
    16531747    {
    16541748        m_DockTileView = [[DockOverlayView alloc] init];
     
    16561750        [pDockScreen addSubview:m_DockTileView];
    16571751    }
     1752
    16581753    DEBUG_FUNC_LEAVE();
    16591754}
     
    16621757{
    16631758    DEBUG_FUNC_ENTER();
    1664         if (m_DockTileView != nil)
     1759    if (m_DockTileView != nil)
    16651760    {
    16661761        [m_DockTileView removeFromSuperview];
     
    16731768- (void)makeCurrentFBO
    16741769{
    1675     DEBUG_MSG(("OVIW(%p): makeCurrentFBO\n", (void*)self));
     1770    DEBUG_MSG(("OVIW(%p): makeCurrentFBO\n", (void *)self));
    16761771
    16771772    if (m_pGLCtx)
     
    16801775        {
    16811776            /* We change the active view, so flush first */
    1682             if([NSOpenGLContext currentContext] != 0)
     1777            if ([NSOpenGLContext currentContext] != 0)
    16831778                glFlush();
    16841779            [m_pGLCtx setView: self];
    1685             CHECK_GL_ERROR();
     1780            DEBUG_CHECK_GL_ERROR();
    16861781        }
    16871782        /*
     
    16901785        {
    16911786            [m_pGLCtx makeCurrentContext];
    1692             CHECK_GL_ERROR();
     1787            DEBUG_CHECK_GL_ERROR();
    16931788            if (m_fNeedCtxUpdate == true)
    16941789            {
     
    17031798            Assert(m_FBOId);
    17041799        }
    1705        
    17061800    }
    17071801}
     
    17101804{
    17111805    DEBUG_FUNC_ENTER();
     1806    GLint                   opaque = 0;
     1807    NSOpenGLContext        *pSharedGLCtx;
     1808    NSOpenGLPixelFormat    *pPixelFormat;
     1809
    17121810    if (m_pSharedGLCtx)
    17131811    {
     
    17181816    Assert(!m_pBlitter);
    17191817    m_pBlitter = RTMemAlloc(sizeof (*m_pBlitter));
    1720     if (!m_pBlitter)
     1818    if (RT_UNLIKELY(!m_pBlitter))
    17211819    {
    17221820        DEBUG_WARN(("m_pBlitter allocation failed"));
     
    17261824       
    17271825    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))
    17331827    {
    17341828        DEBUG_WARN(("CrBltInit failed, rc %d", rc));
     
    17381832        return false;
    17391833    }       
    1740    
    1741     GLint opaque       = 0;
     1834
     1835    DEBUG_MSG(("blitter created successfully for view 0x%p\n", (void *)self));
     1836
    17421837    /* 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];
    17441840       
    17451841    /* Set the new context as non opaque */
    17461842    [pSharedGLCtx setValues:&opaque forParameter:NSOpenGLCPSurfaceOpacity];
     1843
    17471844    /* Set this view as the drawable for the new context */
    1748     [pSharedGLCtx setView: self];
     1845    [pSharedGLCtx setView:self];
    17491846    m_fNeedViewportUpdate = true;
    1750    
     1847
    17511848    m_pSharedGLCtx = pSharedGLCtx;
    17521849   
     
    17591856    glFlush();
    17601857                 
     1858    /* Issue to the gui thread. */
    17611859    DEBUG_MSG(("My[%p]: Draw\n", self));     
    1762     /* issue to the gui thread */
    17631860    [self performSelectorOnMainThread:@selector(vboxTryDrawUI) withObject:nil waitUntilDone:NO];
    17641861}
    17651862
     1863#if 0 /* unused */
    17661864typedef struct CR_RCD_SETVISIBLE
    17671865{
     
    17781876    DEBUG_FUNC_LEAVE();
    17791877}
     1878#endif
    17801879
    17811880- (void)vboxSetVisible:(GLboolean)fVisible
     
    18051904}
    18061905
     1906#if 0 /* unused */
    18071907typedef struct CR_RCD_REPARENT
    18081908{
     
    18181918    DEBUG_FUNC_LEAVE();
    18191919}
    1820 
    1821 - (void)vboxReparent:(NSView*)pParentView
     1920#endif
     1921
     1922- (void)vboxReparent:(NSView *)pParentView
    18221923{
    18231924    DEBUG_FUNC_ENTER();
     
    18291930}
    18301931
    1831 - (void)vboxReparentUI:(NSView*)pParentView
    1832 {
    1833     DEBUG_FUNC_ENTER();
     1932- (void)vboxReparentUI:(NSView *)pParentView
     1933{
     1934    DEBUG_FUNC_ENTER();
     1935
    18341936    /* Make sure the window is removed from any previous parent window. */
    18351937    if ([[self overlayWin] parentWindow] != nil)
     
    18541956- (void)vboxTryDrawUI
    18551957{
     1958    const VBOXVR_SCR_COMPOSITOR *pCompositor;
    18561959    DEBUG_MSG(("My[%p]: DrawUI\n", self));
    1857     const VBOXVR_SCR_COMPOSITOR *pCompositor;
    18581960   
    18591961    if ([self isHidden])
     
    19442046{
    19452047    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));   
    19482049   
    19492050    Assert(pCompositor);
     
    19562057}
    19572058
    1958 - (void)vboxPresentCS:(const VBOXVR_SCR_COMPOSITOR*)pCompositor
    1959 {
    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             /* change to #if 0 to see thumbnail image */           
     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 */           
    19792080#if 1
    1980             [self vboxPresentToViewCS:pCompositor];
     2081    [self vboxPresentToViewCS:pCompositor];
    19812082#else
    1982             glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
    1983             [m_pSharedGLCtx flushBuffer];
     2083    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
     2084    [m_pSharedGLCtx flushBuffer];
    19842085#endif
    1985            
    1986         }
    19872086}
    19882087
    19892088DECLINLINE(void) vboxNSRectToRect(const NSRect *pR, RTRECT *pRect)
    19902089{
    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);
    19942093    pRect->yBottom = (int)(pR->origin.y + pR->size.height);
    19952094}
     
    19972096DECLINLINE(void) vboxNSRectToRectUnstretched(const NSRect *pR, RTRECT *pRect, float xStretch, float yStretch)
    19982097{
    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);
    20022101    pRect->yBottom = (int)((pR->origin.y + pR->size.height) / yStretch);
    20032102}
     
    20052104DECLINLINE(void) vboxNSRectToRectStretched(const NSRect *pR, RTRECT *pRect, float xStretch, float yStretch)
    20062105{
    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);
    20102109    pRect->yBottom = (int)((pR->origin.y + pR->size.height) * yStretch);
    20112110}
     
    20142113{
    20152114    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));
    20182118
    20192119#if 1 /* Set to 0 to see the docktile instead of the real output */
     
    20412141        if (RT_SUCCESS(rc))
    20422142        {
    2043             uint32_t i;
    2044             int rc = CrBltEnter(m_pBlitter);
     2143            rc = CrBltEnter(m_pBlitter);
    20452144            if (RT_SUCCESS(rc))
    20462145            {                   
     2146                uint32_t i;
    20472147                for (i = 0; i < cRegions; ++i)
    20482148                {
    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;
    20532154
    20542155                    vboxNSRectToRect(&m_RootRect, &RestrictDstRect);
     
    20612162
    20622163                    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);
    20642167                    VBoxRectIntersected(&RestrictSrcRect, pSrcRect, &SrcRect);
    20652168                   
     
    20702173                    pDstRect = &DstRect;
    20712174                   
    2072                     const CR_TEXDATA *pTexData = CrVrScrCompositorEntryTexGet(pEntry);
     2175                    pTexData = CrVrScrCompositorEntryTexGet(pEntry);
    20732176                   
    20742177                    CrBltBlitTexMural(m_pBlitter, true, CrTdTexGet(pTexData), pSrcRect, pDstRect, 1, fFlags | CRBLT_F_NOALPHA);
     
    20812184            {
    20822185                DEBUG_WARN(("CrBltEnter failed rc %d", rc));
     2186# ifndef DEBUG_VERBOSE
     2187                AssertMsgFailed(("CrBltEnter failed rc %Rrc", rc));
     2188# endif
    20832189            }
    20842190        }
    20852191        else
    20862192        {
    2087             Assert(0);
     2193            AssertMsgFailed(("BlitStretched: CrVrScrCompositorEntryRegionsGet failed rc %Rrc\n", rc));
    20882194            DEBUG_MSG_1(("BlitStretched: CrVrScrCompositorEntryRegionsGet failed rc %d\n", rc));
    20892195        }
    20902196    }
    20912197#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
    21002207{
    21012208    [self vboxTryDraw];
     
    21042211- (void)vboxBlitterSyncWindow
    21052212{
    2106     CR_BLITTER_WINDOW WinInfo;
    2107     NSRect r;
     2213    CR_BLITTER_WINDOW   WinInfo;
     2214    NSRect              r;
    21082215   
    21092216    if (!m_pBlitter)
    21102217        return;
    21112218       
    2112     memset(&WinInfo, 0, sizeof (WinInfo));
     2219    RT_ZERO(WinInfo);
    21132220   
    21142221    r = [self frame];
     
    21302237- (void)vboxPresentToDockTileCS:(const VBOXVR_SCR_COMPOSITOR*)pCompositor
    21312238{
    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;
    21352242    NSDockTile *pDT = nil;
    2136     float xStretch, yStretch;
     2243    float       xStretch;
     2244    float       yStretch;
    21372245
    21382246    if ([m_DockTileView thumbBitmap] != nil)
    21392247    {
    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;
    21452255       
    2146         if (uiNewTime - m_uiDockUpdateTime > 200)
     2256        if (msTS - m_msDockUpdateTS > 200)
    21472257        {
    2148             m_uiDockUpdateTime = uiNewTime;
     2258            m_msDockUpdateTS = msTS;
    21492259#if 0
    21502260            /* todo: check this for optimization */
     
    21762286            while ((pEntry = CrVrScrCompositorConstIterNext(&CIter)) != NULL)
    21772287            {
    2178                 uint32_t cRegions;
    2179                 const RTRECT *paSrcRegions, *paDstRegions;
     2288                uint32_t    cRegions;
     2289                PCRTRECT    paSrcRegions;
     2290                PCRTRECT    paDstRegions;
    21802291                int rc = CrVrScrCompositorEntryRegionsGet(pCompositor, pEntry, &cRegions, &paSrcRegions, &paDstRegions, NULL);
    2181                 uint32_t fFlags = CrVrScrCompositorEntryFlagsCombinedGet(pCompositor, pEntry);
     2292                uint32_t    fFlags = CrVrScrCompositorEntryFlagsCombinedGet(pCompositor, pEntry);
    21822293                if (RT_SUCCESS(rc))
    21832294                {
    2184                     uint32_t i;
    21852295                    int rc = CrBltEnter(m_pBlitter);
    21862296                    if (RT_SUCCESS(rc))
    21872297                    {                   
     2298                        uint32_t i;
    21882299                        for (i = 0; i < cRegions; ++i)
    21892300                        {
    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;
    21932306                   
    21942307                            vboxNSRectToRect(&m_RootRect, &RestrictDstRect);
     
    22032316                       
    22042317                            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);
    22062321                            VBoxRectIntersected(&RestrictSrcRect, pSrcRect, &SrcRect);
    22072322                   
     
    22122327                            pDstRect = &DstRect;
    22132328                           
    2214                             const CR_TEXDATA *pTexData = CrVrScrCompositorEntryTexGet(pEntry);
     2329                            pTexData = CrVrScrCompositorEntryTexGet(pEntry);
    22152330                           
    22162331                            CrBltBlitTexMural(m_pBlitter, true, CrTdTexGet(pTexData), pSrcRect, pDstRect, 1, fFlags);
     
    22212336                    {
    22222337                        DEBUG_WARN(("CrBltEnter failed rc %d", rc));
     2338#ifndef DEBUG_VERBOSE
     2339                        AssertMsgFailed(("CrBltEnter failed rc %Rrc", rc));
     2340#endif
    22232341                    }
    22242342                }
    22252343                else
    22262344                {
    2227                     Assert(0);
    22282345                    DEBUG_MSG_1(("BlitStretched: CrVrScrCompositorEntryRegionsGet failed rc %d\n", rc));
     2346                    AssertMsgFailed(("BlitStretched: CrVrScrCompositorEntryRegionsGet failed rc %Rrc\n", rc));
    22292347                }
    22302348            }
     
    22532371
    22542372            /* 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];
    22562375        }
    22572376    }
     
    22612380{
    22622381    DEBUG_FUNC_ENTER();
    2263     if(m_paClipRects)
     2382    if (m_paClipRects)
    22642383    {
    22652384        RTMemFree(m_paClipRects);
     
    22862405    GLint cOldRects = m_cClipRects;
    22872406
    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));
    22892408
    22902409    [self clearVisibleRegions];
     
    22932412    {
    22942413#ifdef DEBUG_poetzsch
    2295         int i =0;
     2414        int i = 0;
    22962415        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]));
    22982417#endif
    22992418
     
    23062425}
    23072426
    2308 - (NSView*)dockTileScreen
     2427- (NSView *)dockTileScreen
    23092428{
    23102429    DEBUG_FUNC_ENTER();
    23112430    NSView *contentView = [[[NSApplication sharedApplication] dockTile] contentView];
    23122431    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     */
    23152437    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     */
    23182442    else if ([contentView respondsToSelector:@selector(screenContent)])
    2319          screenContent = [contentView performSelector:@selector(screenContent)];
     2443        screenContent = [contentView performSelector:@selector(screenContent)];
    23202444   
    23212445    DEBUG_FUNC_LEAVE();
     
    23322456    {
    23332457        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. */
    23352460        NSRect parentFrame = [m_pParentView frame];
    23362461
    23372462        m_FBOThumbScaleX = (float)dockFrame.size.width / parentFrame.size.width;
    23382463        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));
    23402468        /*
    23412469        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));
     
    23482476}
    23492477
    2350 @end
     2478@end /* @implementation OverlayView */
     2479
    23512480
    23522481/********************************************************************************
     
    26052734
    26062735    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));
    26082737    [(OverlayView*)pView swapFBO];
    26092738
     
    26392768typedef struct CR_RCD_GETGEOMETRY
    26402769{
    2641     OverlayView *pView;
    2642     NSRect rect;
     2770    OverlayView    *pView;
     2771    NSRect          rect;
    26432772} CR_RCD_GETGEOMETRY;
    26442773
    2645 static DECLCALLBACK(void) vboxRcdGetGeomerty(void *pvCb)
    2646 {
    2647     DEBUG_FUNC_ENTER();
    2648     CR_RCD_GETGEOMETRY * pGetGeometry = (CR_RCD_GETGEOMETRY*)pvCb;
     2774static DECLCALLBACK(void) vboxRcdGetGeomerty(void *pvUser)
     2775{
     2776    DEBUG_FUNC_ENTER();
     2777    CR_RCD_GETGEOMETRY * pGetGeometry = (CR_RCD_GETGEOMETRY *)pvUser;
    26492778    pGetGeometry->rect = [[pGetGeometry->pView window] frame];
    26502779    DEBUG_FUNC_LEAVE();
     
    26532782void cocoaViewGetGeometry(NativeNSViewRef pView, int *pX, int *pY, int *pW, int *pH)
    26542783{
    2655     DEBUG_FUNC_ENTER();
    2656     NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
     2784    NSAutoreleasePool *pPool;
     2785    DEBUG_FUNC_ENTER();
     2786    pPool = [[NSAutoreleasePool alloc] init];
    26572787
    26582788    NSRect frame;
     
    26652795    {
    26662796        CR_RCD_GETGEOMETRY GetGeometry;
    2667         GetGeometry.pView = (OverlayView*)pView;
     2797        GetGeometry.pView = (OverlayView *)pView;
    26682798        renderspuCalloutClient(vboxRcdGetGeomerty, &GetGeometry);
    26692799        frame = GetGeometry.rect;
     
    27222852    NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
    27232853
    2724     DEBUG_MSG(("cocoaViewMakeCurrentContext(%p, %p)\n", (void*)pView, (void*)pCtx));
     2854    DEBUG_MSG(("cocoaViewMakeCurrentContext(%p, %p)\n", (void *)pView, (void *)pCtx));
    27252855
    27262856    if (pView)
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette