Changeset 52560 in vbox
- Timestamp:
- Sep 1, 2014 6:44:22 PM (10 years ago)
- Location:
- trunk/src/VBox/HostServices/SharedOpenGL/render
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu.c
r52494 r52560 316 316 } 317 317 318 WindowInfo* renderspuWinCreate(GLint visBits, GLint id) 319 { 320 WindowInfo* window = (WindowInfo *)crAlloc(sizeof (*window)); 321 if (!window) 322 { 323 crWarning("crAlloc failed"); 324 return NULL; 325 } 326 327 if (!renderspuWinInit(window, NULL, visBits, id)) 328 { 329 crWarning("renderspuWinInit failed"); 330 crFree(window); 331 return NULL; 332 } 333 334 return window; 335 } 336 337 void renderspuWinTermOnShutdown(WindowInfo *window) 338 { 339 renderspuVBoxCompositorSet(window, NULL); 340 renderspuVBoxPresentBlitterCleanup(window); 341 renderspu_SystemDestroyWindow( window ); 342 window->BltInfo.Base.id = -1; 343 } 344 345 static void renderspuCheckCurrentCtxWindowCB(unsigned long key, void *data1, void *data2) 346 { 347 ContextInfo *pCtx = (ContextInfo *) data1; 348 WindowInfo *pWindow = data2; 349 (void) key; 350 351 if (pCtx->currentWindow==pWindow) 352 { 353 WindowInfo* pDummy = renderspuGetDummyWindow(pCtx->BltInfo.Base.visualBits); 354 if (pDummy) 355 { 356 renderspuPerformMakeCurrent(pDummy, 0, pCtx); 357 } 358 else 359 { 360 crWarning("failed to get dummy window"); 361 renderspuMakeCurrent(CR_RENDER_DEFAULT_WINDOW_ID, 0, pCtx->BltInfo.Base.id); 362 } 363 } 364 } 365 366 void renderspuWinTerm( WindowInfo *window ) 367 { 368 if (!renderspuWinIsTermed(window)) 369 { 370 371 GET_CONTEXT(pOldCtx); 372 WindowInfo * pOldWindow = pOldCtx ? pOldCtx->currentWindow : NULL; 373 CRASSERT(!pOldCtx == !pOldWindow); 374 /* ensure no concurrent draws can take place */ 375 renderspuWinTermOnShutdown(window); 376 /* check if this window is bound to some ctx. Note: window pointer is already freed here */ 377 crHashtableWalk(render_spu.contextTable, renderspuCheckCurrentCtxWindowCB, window); 378 /* restore current context */ 379 { 380 GET_CONTEXT(pNewCtx); 381 WindowInfo * pNewWindow = pNewCtx ? pNewCtx->currentWindow : NULL; 382 CRASSERT(!pNewCtx == !pNewWindow); 383 384 if (pOldWindow == window) 385 renderspuMakeCurrent(CR_RENDER_DEFAULT_WINDOW_ID, 0, CR_RENDER_DEFAULT_CONTEXT_ID); 386 else if (pNewCtx != pOldCtx || pOldWindow != pNewWindow) 387 { 388 if (pOldCtx) 389 renderspuPerformMakeCurrent(pOldWindow, 0, pOldCtx); 390 else 391 renderspuMakeCurrent(CR_RENDER_DEFAULT_WINDOW_ID, 0, CR_RENDER_DEFAULT_CONTEXT_ID); 392 } 393 } 394 395 } 396 } 397 398 void renderspuWinCleanup(WindowInfo *window) 399 { 400 renderspuWinTerm( window ); 401 RTCritSectDelete(&window->CompositorLock); 402 } 403 404 void renderspuWinDestroy(WindowInfo *window) 405 { 406 renderspuWinCleanup(window); 407 crFree(window); 408 } 409 318 410 WindowInfo* renderspuGetDummyWindow(GLint visBits) 319 411 { … … 321 413 if (!window) 322 414 { 323 window = (WindowInfo *)crAlloc(sizeof (*window));415 window = renderspuWinCreate(visBits, -1); 324 416 if (!window) 325 417 { 326 crWarning("crAlloc failed"); 327 return NULL; 328 } 329 330 if (!renderspuWindowInit(window, NULL, visBits, -1)) 331 { 332 crWarning("renderspuWindowInit failed"); 333 crFree(window); 418 WARN(("renderspuWinCreate failed")); 334 419 return NULL; 335 420 } … … 446 531 } 447 532 448 GLboolean renderspuWin dowInitWithVisual( WindowInfo *window, VisualInfo *visual, GLboolean showIt, GLint id )533 GLboolean renderspuWinInitWithVisual( WindowInfo *window, VisualInfo *visual, GLboolean showIt, GLint id ) 449 534 { 450 535 crMemset(window, 0, sizeof (*window)); … … 494 579 window->visible = !!showIt; 495 580 581 window->cRefs = 1; 582 496 583 CRASSERT(window->visual == visual); 497 584 return GL_TRUE; … … 501 588 * Window functions 502 589 */ 503 GLboolean renderspuWin dowInit(WindowInfo *pWindow, const char *dpyName, GLint visBits, GLint id)590 GLboolean renderspuWinInit(WindowInfo *pWindow, const char *dpyName, GLint visBits, GLint id) 504 591 { 505 592 VisualInfo *visual; … … 521 608 */ 522 609 /* Have GLX/WGL/AGL create the window */ 523 if (!renderspuWin dowInitWithVisual( pWindow, visual, 0, id ))610 if (!renderspuWinInitWithVisual( pWindow, visual, 0, id )) 524 611 { 525 612 crWarning( "Render SPU: Couldn't create a window, renderspu_SystemCreateWindow failed" ); … … 553 640 554 641 /* Allocate WindowInfo */ 555 window = (WindowInfo *) crCalloc(sizeof(WindowInfo)); 642 window = renderspuWinCreate(visBits, id); 643 556 644 if (!window) 557 645 { 558 crWarning( "Render SPU: Couldn't create a window" ); 559 return -1; 560 } 561 562 if (!renderspuWindowInit(window, dpyName, visBits, id)) 563 { 564 crWarning("renderspuWindowInit failed"); 646 crWarning("renderspuWinCreate failed"); 565 647 crFree(window); 566 648 return -1; … … 577 659 } 578 660 579 static void renderspuCheckCurrentCtxWindowCB(unsigned long key, void *data1, void *data2) 580 { 581 ContextInfo *pCtx = (ContextInfo *) data1; 582 WindowInfo *pWindow = data2; 583 (void) key; 584 585 if (pCtx->currentWindow==pWindow) 586 { 587 WindowInfo* pDummy = renderspuGetDummyWindow(pCtx->BltInfo.Base.visualBits); 588 if (pDummy) 589 { 590 renderspuPerformMakeCurrent(pDummy, 0, pCtx); 591 } 592 else 593 { 594 crWarning("failed to get dummy window"); 595 renderspuMakeCurrent(CR_RENDER_DEFAULT_WINDOW_ID, 0, pCtx->BltInfo.Base.id); 596 } 597 } 598 } 599 600 void renderspuWindowTermBase( WindowInfo *window ) 601 { 602 renderspuVBoxCompositorSet(window, NULL); 603 renderspuVBoxPresentBlitterCleanup(window); 604 renderspu_SystemDestroyWindow( window ); 605 RTCritSectDelete(&window->CompositorLock); 606 } 607 608 void renderspuWindowTerm( WindowInfo *window ) 609 { 610 GET_CONTEXT(pOldCtx); 611 WindowInfo * pOldWindow = pOldCtx ? pOldCtx->currentWindow : NULL; 612 CRASSERT(!pOldCtx == !pOldWindow); 613 /* ensure no concurrent draws can take place */ 614 renderspuWindowTermBase(window); 615 /* check if this window is bound to some ctx. Note: window pointer is already freed here */ 616 crHashtableWalk(render_spu.contextTable, renderspuCheckCurrentCtxWindowCB, window); 617 /* restore current context */ 618 { 619 GET_CONTEXT(pNewCtx); 620 WindowInfo * pNewWindow = pNewCtx ? pNewCtx->currentWindow : NULL; 621 CRASSERT(!pNewCtx == !pNewWindow); 622 623 if (pOldWindow == window) 624 renderspuMakeCurrent(CR_RENDER_DEFAULT_WINDOW_ID, 0, CR_RENDER_DEFAULT_CONTEXT_ID); 625 else if (pNewCtx != pOldCtx || pOldWindow != pNewWindow) 626 { 627 if (pOldCtx) 628 renderspuPerformMakeCurrent(pOldWindow, 0, pOldCtx); 629 else 630 renderspuMakeCurrent(CR_RENDER_DEFAULT_WINDOW_ID, 0, CR_RENDER_DEFAULT_CONTEXT_ID); 631 } 632 } 661 void renderspuWinReleaseCb(void*pvWindow) 662 { 663 renderspuWinRelease((WindowInfo*)pvWindow); 633 664 } 634 665 … … 647 678 if (window) { 648 679 crDebug("Render SPU: Destroy window (%d)", win); 649 renderspuWindowTerm( window ); 680 /* since os-specific backend can hold its own reference to the window object (e.g. on OSX), 681 * we need to explicitly issue a window destroy command 682 * this ensures the backend will eventually release the reference, 683 * the window object itself will remain valid until its ref count reaches zero */ 684 renderspuWinTerm( window ); 650 685 651 686 /* remove window info from hash table, and free it */ 652 crHashtableDelete(render_spu.windowTable, win, crFree);687 crHashtableDelete(render_spu.windowTable, win, renderspuWinReleaseCb); 653 688 654 689 } -
trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu.h
r52429 r52560 98 98 99 99 VisualInfo *visual; 100 101 volatile uint32_t cRefs; 102 100 103 GLboolean mapPending; 101 104 GLboolean visible; … … 432 435 extern PCR_BLITTER renderspuVBoxPresentBlitterGetAndEnter( WindowInfo *window, int32_t i32MakeCurrentUserData, bool fRedraw ); 433 436 extern PCR_BLITTER renderspuVBoxPresentBlitterEnsureCreated( WindowInfo *window, int32_t i32MakeCurrentUserData ); 434 void renderspuWindowTermBase( WindowInfo *window ); 435 extern void renderspuWindowTerm( WindowInfo *window ); 437 WindowInfo* renderspuWinCreate(GLint visBits, GLint id); 438 void renderspuWinTermOnShutdown(WindowInfo *window); 439 void renderspuWinTerm( WindowInfo *window ); 440 void renderspuWinCleanup(WindowInfo *window); 441 void renderspuWinDestroy(WindowInfo *window); 442 GLboolean renderspuWinInitWithVisual( WindowInfo *window, VisualInfo *visual, GLboolean showIt, GLint id ); 443 GLboolean renderspuWinInit(WindowInfo *pWindow, const char *dpyName, GLint visBits, GLint id); 444 445 DECLINLINE(void) renderspuWinRetain(WindowInfo *window) 446 { 447 ASMAtomicIncU32(&window->cRefs); 448 } 449 450 DECLINLINE(bool) renderspuWinIsTermed(WindowInfo *window) 451 { 452 return window->BltInfo.Base.id < 0; 453 } 454 455 DECLINLINE(void) renderspuWinRelease(WindowInfo *window) 456 { 457 uint32_t cRefs = ASMAtomicDecU32(&window->cRefs); 458 if (!cRefs) 459 { 460 renderspuWinDestroy(window); 461 } 462 } 463 436 464 extern WindowInfo* renderspuGetDummyWindow(GLint visBits); 437 465 extern void renderspuPerformMakeCurrent(WindowInfo *window, GLint nativeWindow, ContextInfo *context); 438 extern GLboolean renderspuWindowInit(WindowInfo *pWindow, const char *dpyName, GLint visBits, GLint id);439 extern GLboolean renderspuWindowInitWithVisual( WindowInfo *window, VisualInfo *visual, GLboolean showIt, GLint id );440 466 extern GLboolean renderspuInitVisual(VisualInfo *pVisInfo, const char *displayName, GLbitfield visAttribs); 441 467 extern void renderspuVBoxCompositorBlit ( const struct VBOXVR_SCR_COMPOSITOR * pCompositor, PCR_BLITTER pBlitter); -
trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu_cocoa_helper.m
r52532 r52560 1413 1413 [self performSelectorOnMainThread:@selector(release) withObject:nil waitUntilDone:NO]; 1414 1414 } 1415 1416 renderspuWinRelease(m_pWinInfo); 1417 1415 1418 DEBUG_FUNC_LEAVE(); 1416 1419 } … … 2479 2482 /* make sure all tasks are run, to preserve the order */ 2480 2483 [pRunner runTasksSyncIfPossible]; 2484 2485 renderspuWinRetain(pWinInfo); 2481 2486 2482 2487 if (renderspuCalloutAvailable()) … … 2501 2506 #endif 2502 2507 } 2508 2509 if (!*ppView) 2510 renderspuWinRelease(pWinInfo); 2503 2511 2504 2512 [pPool release]; -
trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu_glx.c
r52261 r52560 448 448 if (bRc) 449 449 { 450 bRc = renderspuWin dowInitWithVisual(&render_spu.WinCmdWindow, &render_spu.WinCmdVisual, GL_FALSE, CR_RENDER_WINCMD_ID);450 bRc = renderspuWinInitWithVisual(&render_spu.WinCmdWindow, &render_spu.WinCmdVisual, GL_FALSE, CR_RENDER_WINCMD_ID); 451 451 if (bRc) 452 452 { … … 458 458 else 459 459 { 460 crError("renderspuWin dowInitWithVisual failed");460 crError("renderspuWinInitWithVisual failed"); 461 461 } 462 462 /* there is no visual destroy impl currently … … 486 486 /* the window is not in the table, this will just ensure the key is freed */ 487 487 crHashtableDelete(render_spu.windowTable, CR_RENDER_WINCMD_ID, NULL); 488 renderspuWin dowTerm(&render_spu.WinCmdWindow);488 renderspuWinCleanup(&render_spu.WinCmdWindow); 489 489 crFreeHashtable(render_spu.pWinToInfoTable, NULL); 490 490 /* we do not have visual destroy functionality -
trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu_init.c
r51064 r52560 428 428 { 429 429 WindowInfo *window = (WindowInfo *) data; 430 renderspuWin dowTermBase(window);431 crFree(window);430 renderspuWinTermOnShutdown(window); 431 renderspuWinRelease(window); 432 432 } 433 433
Note:
See TracChangeset
for help on using the changeset viewer.