VirtualBox

Changeset 52494 in vbox


Ignore:
Timestamp:
Aug 25, 2014 1:23:57 PM (10 years ago)
Author:
vboxsync
Message:

crOpenGL/osx: more sync with main thread

Location:
trunk/src/VBox/HostServices/SharedOpenGL
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_presenter.cpp

    r52451 r52494  
    64096409DECLEXPORT(void) crVBoxServerCalloutEnable(VBOXCRCMDCTL *pCtl)
    64106410{
    6411 #ifdef CR_SERVER_WITH_CLIENT_CALLOUTS
     6411#if 1 //def CR_SERVER_WITH_CLIENT_CALLOUTS
    64126412    Assert(!cr_server.pCurrentCalloutCtl);
    64136413    cr_server.pCurrentCalloutCtl = pCtl;
     
    64196419extern DECLEXPORT(void) crVBoxServerCalloutDisable()
    64206420{
    6421 #ifdef CR_SERVER_WITH_CLIENT_CALLOUTS
     6421#if 1 //def CR_SERVER_WITH_CLIENT_CALLOUTS
    64226422    Assert(cr_server.pCurrentCalloutCtl);
    64236423
  • trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu.c

    r52429 r52494  
    14531453    if (render_spu.pfnClientCallout)
    14541454    {
    1455         pfnCb(pvCb);
     1455        render_spu.pfnClientCallout(pfnCb, pvCb);
    14561456        return true;
    14571457    }
  • trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu_cocoa_helper.m

    r52429 r52494  
    311311@end
    312312
     313@interface VBoxTask : NSObject
     314{
     315}
     316- (void)run;
     317@end
     318
     319@interface VBoxTaskPerformSelector : VBoxTask
     320{
     321@private
     322    id m_Object;
     323    SEL m_Selector;
     324    id m_Arg;
     325}
     326- (id)initWithObject:(id)aObject selector:(SEL)aSelector arg:(id)aArg;
     327- (void)run;
     328- (void)dealloc;
     329@end
     330
     331#if 0
     332typedef DECLCALLBACKPTR(void, PFNVBOXTASKCALLBACK)(void *pvCb);
     333
     334@interface VBoxTaskCallback: VBoxTask
     335{
     336@private
     337    PFNVBOXTASKCALLBACK m_pfnCb;
     338    void *m_pvCb;
     339}
     340- (id)initWithCb:(PFNVBOXTASKCALLBACK)pfnCb arg:(void*)pvCb;
     341- (void)run;
     342@end
     343#endif
     344
     345@interface VBoxTaskComposite: VBoxTask
     346{
     347@private
     348    NSUInteger m_CurIndex;
     349    RTCRITSECT m_Lock;
     350    NSMutableArray *m_pArray;
     351}
     352- (id)init;
     353- (void)add:(VBoxTask*)pTask;
     354- (void)run;
     355- (void)dealloc;
     356@end
     357
     358@implementation VBoxTask
     359@end
     360
     361@implementation VBoxTaskPerformSelector
     362- (id)initWithObject:(id)aObject selector:(SEL)aSelector arg:(id)aArg
     363{
     364    [aObject retain];
     365    m_Object = aObject;
     366    m_Selector = aSelector;
     367    if (aArg != nil)
     368        [aArg retain];
     369    m_Arg = aArg;
     370   
     371    return self;
     372}
     373
     374- (void)run
     375{
     376    [m_Object performSelector:m_Selector withObject:m_Arg];
     377}
     378
     379- (void)dealloc
     380{
     381    [m_Object release];
     382    if (m_Arg != nil)
     383        [m_Arg release];
     384}
     385@end
     386
     387@implementation VBoxTaskComposite
     388- (id)init
     389{
     390    int rc = RTCritSectInit(&m_Lock);
     391    if (!RT_SUCCESS(rc))
     392    {
     393        DEBUG_WARN(("RTCritSectInit failed %d\n", rc));
     394        return nil;
     395    }
     396
     397    m_CurIndex = 0;
     398   
     399    m_pArray = [[NSMutableArray alloc] init];
     400    return self;
     401}
     402
     403- (void)add:(VBoxTask*)pTask
     404{
     405    [pTask retain];
     406    int rc = RTCritSectEnter(&m_Lock);
     407    if (RT_SUCCESS(rc))
     408    {
     409        [m_pArray addObject:pTask];
     410        RTCritSectLeave(&m_Lock);
     411    }
     412    else
     413    {
     414        DEBUG_WARN(("RTCritSectEnter failed %d\n", rc));
     415        [pTask release];
     416    }
     417}
     418
     419- (void)run
     420{
     421    for(;;)
     422    {
     423        int rc = RTCritSectEnter(&m_Lock);
     424        if (RT_FAILURE(rc))
     425        {
     426            DEBUG_WARN(("RTCritSectEnter failed %d\n", rc));
     427            break;
     428        }
     429       
     430        NSUInteger count = [m_pArray count];
     431        Assert(m_CurIndex <= count);
     432        if (m_CurIndex == count)
     433        {
     434            [m_pArray removeAllObjects];
     435            m_CurIndex = 0;
     436            RTCritSectLeave(&m_Lock);
     437            break;
     438        }
     439
     440        VBoxTask* pTask = (VBoxTask*)[m_pArray objectAtIndex:m_CurIndex];
     441        Assert(pTask != nil);
     442       
     443        ++m_CurIndex;
     444       
     445        if (m_CurIndex > 1024)
     446        {
     447            NSRange range;
     448            range.location = 0;
     449            range.length = m_CurIndex;
     450            [m_pArray removeObjectsInRange:range];
     451            m_CurIndex = 0;
     452        }
     453        RTCritSectLeave(&m_Lock);
     454       
     455        [pTask run];
     456        [pTask release];
     457    }
     458}
     459
     460- (void)dealloc
     461{
     462    NSUInteger count = [m_pArray count];
     463    for(;m_CurIndex < count; ++m_CurIndex)
     464    {
     465        VBoxTask* pTask = (VBoxTask*)[m_pArray objectAtIndex:m_CurIndex];
     466        DEBUG_WARN(("dealloc with non-empty tasks! %p\n", pTask));
     467        [pTask release];
     468    }
     469   
     470    [m_pArray release];
     471    RTCritSectDelete(&m_Lock);
     472}
     473@end
     474
     475@interface VBoxMainThreadTaskRunner : NSObject
     476{
     477@private
     478    VBoxTaskComposite *m_pTasks;
     479}
     480- (id)init;
     481- (void)add:(VBoxTask*)pTask;
     482- (void)addObj:(id)aObject selector:(SEL)aSelector arg:(id)aArg;
     483- (void)runTasks;
     484- (bool)runTasksSyncIfPossible;
     485- (void)dealloc;
     486+ (VBoxMainThreadTaskRunner*) globalInstance;
     487@end
     488
     489@implementation VBoxMainThreadTaskRunner
     490- (id)init
     491{
     492    self = [super init];
     493    if (self)
     494    {
     495        m_pTasks = [[VBoxTaskComposite alloc] init];
     496    }
     497   
     498    return self;
     499}
     500
     501+ (VBoxMainThreadTaskRunner*) globalInstance
     502{
     503    static dispatch_once_t dispatchOnce;
     504    static VBoxMainThreadTaskRunner *pRunner = nil;
     505    dispatch_once(&dispatchOnce, ^{
     506        pRunner = [[VBoxMainThreadTaskRunner alloc] init];
     507    });
     508    return pRunner;
     509}
     510
     511typedef struct CR_RCD_RUN
     512{
     513    VBoxMainThreadTaskRunner *pRunner;
     514} CR_RCD_RUN;
     515
     516static DECLCALLBACK(void) vboxRcdRun(void *pvCb)
     517{
     518    DEBUG_FUNC_ENTER();
     519    CR_RCD_RUN * pRun = (CR_RCD_RUN*)pvCb;
     520    [pRun->pRunner runTasks];
     521    DEBUG_FUNC_LEAVE();
     522}
     523
     524- (void)add:(VBoxTask*)pTask
     525{
     526    DEBUG_FUNC_ENTER();
     527    [m_pTasks add:pTask];
     528    [self retain];
     529
     530    if (![self runTasksSyncIfPossible])
     531    {
     532        DEBUG_MSG(("task will be processed async\n"));
     533        [self performSelectorOnMainThread:@selector(runTasks) withObject:nil waitUntilDone:NO];
     534    }
     535   
     536    DEBUG_FUNC_LEAVE();
     537}
     538
     539- (void)addObj:(id)aObject selector:(SEL)aSelector arg:(id)aArg
     540{
     541    VBoxTaskPerformSelector *pSelTask = [[VBoxTaskPerformSelector alloc] initWithObject:aObject selector:aSelector arg:aArg];
     542    [self add:pSelTask];
     543    [pSelTask release];
     544}
     545
     546- (void)runTasks
     547{
     548    BOOL fIsMain = [NSThread isMainThread];
     549    Assert(fIsMain);
     550    if (fIsMain)
     551    {
     552        [m_pTasks run];
     553        [self release];
     554    }
     555    else
     556    {
     557        DEBUG_WARN(("run tasks called not on main thread!\n"));
     558        [self performSelectorOnMainThread:@selector(runTasks) withObject:nil waitUntilDone:YES];
     559    }
     560}
     561
     562- (bool)runTasksSyncIfPossible
     563{
     564    if (renderspuCalloutAvailable())
     565    {
     566        CR_RCD_RUN Run;
     567        Run.pRunner = self;
     568        Assert(![NSThread isMainThread]);
     569        renderspuCalloutClient(vboxRcdRun, &Run);
     570        return true;
     571    }
     572   
     573    if ([NSThread isMainThread])
     574    {
     575        [self runTasks];
     576        return true;
     577    }
     578   
     579    return false;
     580}
     581
     582- (void)dealloc
     583{
     584    [m_pTasks release];
     585}
     586
     587@end
     588
    313589@class DockOverlayView;
    314590
     
    10451321    NSPoint pos = [pPos pointValue];
    10461322    [self vboxSetPosUI:pos];
    1047     [pPos release];
    10481323
    10491324    DEBUG_FUNC_LEAVE();
     
    10711346
    10721347    DEBUG_MSG(("OVIW(%p): vboxSetPos: new pos: %d, %d\n", (void*)self, (int)pos.x, (int)pos.y));
    1073 
    1074     if (renderspuCalloutAvailable())
    1075     {
    1076         CR_RCD_SETPOS SetPos;
    1077         SetPos.pView = self;
    1078         SetPos.pos = pos;
    1079         renderspuCalloutClient(vboxRcdSetPos, &SetPos);
    1080     }
    1081     else
    1082     {
    1083         DEBUG_MSG(("no callout available on setPos\n"));
    1084         NSValue *pPos =  [NSValue valueWithPoint:pos];
    1085         [pPos retain];
    1086         [self performSelectorOnMainThread:@selector(vboxSetPosUIObj:) withObject:pPos waitUntilDone:NO];
    1087     }
     1348    VBoxMainThreadTaskRunner *pRunner = [VBoxMainThreadTaskRunner globalInstance];
     1349    NSValue *pPos =  [NSValue valueWithPoint:pos];
     1350    [pRunner addObj:self selector:@selector(vboxSetPosUIObj:) arg:pPos];
    10881351
    10891352    DEBUG_FUNC_LEAVE();
     
    11091372    BOOL fIsMain = [NSThread isMainThread];
    11101373    NSWindow *pWin = nil;
     1374   
     1375    Assert(fIsMain);
    11111376
    11121377    /* Hide the view early */
     
    11491414    NSSize size = [pSize sizeValue];
    11501415    [self vboxSetSizeUI:size];
    1151 //    [pSize release];
    11521416    DEBUG_FUNC_LEAVE();
    11531417}
     
    11851449{
    11861450    DEBUG_FUNC_ENTER();
    1187     if (renderspuCalloutAvailable())
    1188     {
    1189         CR_RCD_SETSIZE SetSize;
    1190         SetSize.pView = self;
    1191         SetSize.size = size;
    1192         renderspuCalloutClient(vboxRcdSetSize, &SetSize);
    1193     }
    1194     else
    1195     {
    1196         NSValue *pSize = [NSValue valueWithSize:size];
    1197         [pSize retain];
    1198         DEBUG_MSG(("no callout available on setSize\n"));
    1199         [self performSelectorOnMainThread:@selector(vboxSetSizeUIObj:) withObject:pSize waitUntilDone:NO];
    1200     }
     1451   
     1452    VBoxMainThreadTaskRunner *pRunner = [VBoxMainThreadTaskRunner globalInstance];
     1453    NSValue *pSize = [NSValue valueWithSize:size];
     1454    [pRunner addObj:self selector:@selector(vboxSetSizeUIObj:) arg:pSize];
     1455
    12011456    DEBUG_FUNC_LEAVE();
    12021457}
     
    14931748{
    14941749    DEBUG_FUNC_ENTER();
    1495     if (renderspuCalloutAvailable())
    1496     {
    1497         CR_RCD_SETVISIBLE Visible;
    1498         Visible.pView = self;
    1499         Visible.fVisible = fVisible;
    1500         renderspuCalloutClient(vboxRcdSetVisible, &Visible);
    1501     }
    1502     else
    1503     {
    1504         DEBUG_MSG(("no callout available on setVisible\n"));
    1505         NSNumber* pVisObj = [NSNumber numberWithBool:fVisible];
    1506         [pVisObj retain];
    1507         [self performSelectorOnMainThread:@selector(vboxSetVisibleUIObj:) withObject:pVisObj waitUntilDone:NO];
    1508     }
     1750   
     1751    VBoxMainThreadTaskRunner *pRunner = [VBoxMainThreadTaskRunner globalInstance];
     1752    NSNumber* pVisObj = [NSNumber numberWithBool:fVisible];
     1753    [pRunner addObj:self selector:@selector(vboxSetVisibleUIObj:) arg:pVisObj];
     1754
    15091755    DEBUG_FUNC_LEAVE();
    15101756}
     
    15221768    BOOL fVisible = [pVisible boolValue];
    15231769    [self vboxSetVisibleUI:fVisible];
    1524     [pVisible release];
    15251770    DEBUG_FUNC_LEAVE();
    15261771}
     
    15431788{
    15441789    DEBUG_FUNC_ENTER();
    1545     [pParentView retain];
    1546     if (renderspuCalloutAvailable())
    1547     {
    1548         CR_RCD_REPARENT Reparent;
    1549         Reparent.pView = self;
    1550         Reparent.pParent = pParentView;
    1551         renderspuCalloutClient(vboxRcdReparent, &Reparent);
    1552     }
    1553     else
    1554     {
    1555         DEBUG_MSG(("no callout available on reparent %p %p\n", self, pParentView));
    1556         [self performSelectorOnMainThread:@selector(vboxReparentUI:) withObject:pParentView waitUntilDone:NO];
    1557     }
     1790   
     1791    VBoxMainThreadTaskRunner *pRunner = [VBoxMainThreadTaskRunner globalInstance];
     1792    [pRunner addObj:self selector:@selector(vboxReparentUI:) arg:pParentView];
     1793
    15581794    DEBUG_FUNC_LEAVE();
    15591795}
     
    15781814            [self vboxReshapeOnReparentPerform];
    15791815    }
    1580    
    1581     [pParentView release];
    15821816   
    15831817    DEBUG_FUNC_LEAVE();
     
    21902424} CR_RCD_CREATEVIEW;
    21912425
    2192 static OverlayView * vboxViewCreate(WindowInfo *pWinInfo, NativeNSViewRef pParentView, GLbitfield fVisParams)
     2426static OverlayView * vboxViewCreate(WindowInfo *pWinInfo, NativeNSViewRef pParentView)
    21932427{
    21942428    DEBUG_FUNC_ENTER();
     
    22132447    DEBUG_FUNC_ENTER();
    22142448    CR_RCD_CREATEVIEW * pCreateView = (CR_RCD_CREATEVIEW*)pvCb;
    2215     pCreateView->pView = vboxViewCreate(pCreateView->pWinInfo, pCreateView->pParentView, pCreateView->fVisParams);
     2449    pCreateView->pView = vboxViewCreate(pCreateView->pWinInfo, pCreateView->pParentView);
    22162450    DEBUG_FUNC_LEAVE();
    22172451}
     
    22212455    DEBUG_FUNC_ENTER();
    22222456    NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
     2457
     2458    VBoxMainThreadTaskRunner *pRunner = [VBoxMainThreadTaskRunner globalInstance];
     2459    /* make sure all tasks are run, to preserve the order */
     2460    [pRunner runTasksSyncIfPossible];
    22232461
    22242462    if (renderspuCalloutAvailable())
     
    22382476        dispatch_sync(dispatch_get_main_queue(), ^{
    22392477#endif
    2240             *ppView = vboxViewCreate(pWinInfo, pParentView, fVisParams);
     2478            *ppView = vboxViewCreate(pWinInfo, pParentView);
    22412479#if 0
    22422480        });
     
    22842522    NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
    22852523
    2286     if (renderspuCalloutAvailable())
    2287     {
    2288         CR_RCD_DESTROYVIEW DestroyView;
    2289         DestroyView.pView = (OverlayView*)pView;
    2290         renderspuCalloutClient(vboxRcdDestroyView, &DestroyView);
    2291     }
    2292     else
    2293     {
    2294         DEBUG_MSG(("no callout available on destroyView\n"));
    2295         [(OverlayView*)pView performSelectorOnMainThread:@selector(vboxDestroy) withObject:nil waitUntilDone:NO];
    2296     }
     2524    VBoxMainThreadTaskRunner *pRunner = [VBoxMainThreadTaskRunner globalInstance];
     2525    [pRunner addObj:pView selector:@selector(vboxDestroy) arg:nil];
    22972526
    22982527    [pPool release];
     2528
    22992529    DEBUG_FUNC_LEAVE();
    23002530}
     
    23692599
    23702600    NSRect frame;
     2601    VBoxMainThreadTaskRunner *pRunner = [VBoxMainThreadTaskRunner globalInstance];
     2602    /* make sure all tasks are run, to preserve the order */
     2603    [pRunner runTasksSyncIfPossible];
     2604   
    23712605   
    23722606    if (renderspuCalloutAvailable())
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