Changeset 52494 in vbox
- Timestamp:
- Aug 25, 2014 1:23:57 PM (10 years ago)
- Location:
- trunk/src/VBox/HostServices/SharedOpenGL
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_presenter.cpp
r52451 r52494 6409 6409 DECLEXPORT(void) crVBoxServerCalloutEnable(VBOXCRCMDCTL *pCtl) 6410 6410 { 6411 #if def CR_SERVER_WITH_CLIENT_CALLOUTS6411 #if 1 //def CR_SERVER_WITH_CLIENT_CALLOUTS 6412 6412 Assert(!cr_server.pCurrentCalloutCtl); 6413 6413 cr_server.pCurrentCalloutCtl = pCtl; … … 6419 6419 extern DECLEXPORT(void) crVBoxServerCalloutDisable() 6420 6420 { 6421 #if def CR_SERVER_WITH_CLIENT_CALLOUTS6421 #if 1 //def CR_SERVER_WITH_CLIENT_CALLOUTS 6422 6422 Assert(cr_server.pCurrentCalloutCtl); 6423 6423 -
trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu.c
r52429 r52494 1453 1453 if (render_spu.pfnClientCallout) 1454 1454 { 1455 pfnCb(pvCb);1455 render_spu.pfnClientCallout(pfnCb, pvCb); 1456 1456 return true; 1457 1457 } -
trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu_cocoa_helper.m
r52429 r52494 311 311 @end 312 312 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 332 typedef 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 511 typedef struct CR_RCD_RUN 512 { 513 VBoxMainThreadTaskRunner *pRunner; 514 } CR_RCD_RUN; 515 516 static 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 313 589 @class DockOverlayView; 314 590 … … 1045 1321 NSPoint pos = [pPos pointValue]; 1046 1322 [self vboxSetPosUI:pos]; 1047 [pPos release];1048 1323 1049 1324 DEBUG_FUNC_LEAVE(); … … 1071 1346 1072 1347 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]; 1088 1351 1089 1352 DEBUG_FUNC_LEAVE(); … … 1109 1372 BOOL fIsMain = [NSThread isMainThread]; 1110 1373 NSWindow *pWin = nil; 1374 1375 Assert(fIsMain); 1111 1376 1112 1377 /* Hide the view early */ … … 1149 1414 NSSize size = [pSize sizeValue]; 1150 1415 [self vboxSetSizeUI:size]; 1151 // [pSize release];1152 1416 DEBUG_FUNC_LEAVE(); 1153 1417 } … … 1185 1449 { 1186 1450 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 1201 1456 DEBUG_FUNC_LEAVE(); 1202 1457 } … … 1493 1748 { 1494 1749 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 1509 1755 DEBUG_FUNC_LEAVE(); 1510 1756 } … … 1522 1768 BOOL fVisible = [pVisible boolValue]; 1523 1769 [self vboxSetVisibleUI:fVisible]; 1524 [pVisible release];1525 1770 DEBUG_FUNC_LEAVE(); 1526 1771 } … … 1543 1788 { 1544 1789 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 1558 1794 DEBUG_FUNC_LEAVE(); 1559 1795 } … … 1578 1814 [self vboxReshapeOnReparentPerform]; 1579 1815 } 1580 1581 [pParentView release];1582 1816 1583 1817 DEBUG_FUNC_LEAVE(); … … 2190 2424 } CR_RCD_CREATEVIEW; 2191 2425 2192 static OverlayView * vboxViewCreate(WindowInfo *pWinInfo, NativeNSViewRef pParentView , GLbitfield fVisParams)2426 static OverlayView * vboxViewCreate(WindowInfo *pWinInfo, NativeNSViewRef pParentView) 2193 2427 { 2194 2428 DEBUG_FUNC_ENTER(); … … 2213 2447 DEBUG_FUNC_ENTER(); 2214 2448 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); 2216 2450 DEBUG_FUNC_LEAVE(); 2217 2451 } … … 2221 2455 DEBUG_FUNC_ENTER(); 2222 2456 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]; 2223 2461 2224 2462 if (renderspuCalloutAvailable()) … … 2238 2476 dispatch_sync(dispatch_get_main_queue(), ^{ 2239 2477 #endif 2240 *ppView = vboxViewCreate(pWinInfo, pParentView , fVisParams);2478 *ppView = vboxViewCreate(pWinInfo, pParentView); 2241 2479 #if 0 2242 2480 }); … … 2284 2522 NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init]; 2285 2523 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]; 2297 2526 2298 2527 [pPool release]; 2528 2299 2529 DEBUG_FUNC_LEAVE(); 2300 2530 } … … 2369 2599 2370 2600 NSRect frame; 2601 VBoxMainThreadTaskRunner *pRunner = [VBoxMainThreadTaskRunner globalInstance]; 2602 /* make sure all tasks are run, to preserve the order */ 2603 [pRunner runTasksSyncIfPossible]; 2604 2371 2605 2372 2606 if (renderspuCalloutAvailable())
Note:
See TracChangeset
for help on using the changeset viewer.