Example #1
0
//we're not going to change icdTable at runtime, so callback is unused
PICDTABLE APIENTRY DrvSetContext(HDC hdc, HGLRC hglrc, void *callback)
{
    ContextInfo *pContext;
    WindowInfo  *pWindowInfo;
    BOOL ret = false;

    CR_DDI_PROLOGUE();

    (void) (callback);

    crHashtableLock(stub.windowTable);
    crHashtableLock(stub.contextTable);

    pContext = (ContextInfo *) crHashtableSearch(stub.contextTable, (unsigned long) hglrc);
    if (pContext)
    {
        pWindowInfo = stubGetWindowInfo(hdc);
        if (pWindowInfo)
            ret = stubMakeCurrent(pWindowInfo, pContext);
        else
            crError("no window info available.");
    }
    else
        crError("No context found.");

    crHashtableUnlock(stub.contextTable);
    crHashtableUnlock(stub.windowTable);

    return ret ? &icdTable : NULL;
}
Example #2
0
BOOL WINAPI wglMakeCurrent_prox( HDC hdc, HGLRC hglrc )
{
    ContextInfo *context;
    WindowInfo *window;
    BOOL ret;

    CR_DDI_PROLOGUE();

    crHashtableLock(stub.windowTable);
    crHashtableLock(stub.contextTable);

    context = (ContextInfo *) crHashtableSearch(stub.contextTable, (unsigned long) hglrc);
    window = stubGetWindowInfo(hdc);

    if (hglrc!=0 && !context)
    {
        crWarning("wglMakeCurrent got unexpected hglrc 0x%x", hglrc);
    }

    ret = stubMakeCurrent( window, context );

    crHashtableUnlock(stub.contextTable);
    crHashtableUnlock(stub.windowTable);

    return ret;
}
Example #3
0
DECLEXPORT(GLint) WINAPI VBoxGetContextId( HGLRC hglrc )
{
    ContextInfo *context;
    GLint ctxid = 0;

    CR_DDI_PROLOGUE();

//    crHashtableLock(stub.windowTable);
    crHashtableLock(stub.contextTable);

    context = (ContextInfo *) crHashtableSearch(stub.contextTable, (unsigned long) hglrc);
    if (!context)
    {
        crWarning("crHashtableSearch: context not found!");
        goto end;
    }

    if (context->type != CHROMIUM)
    {
        crWarning("unexpected context type %d", context->type);
        goto end;
    }

    if (context->spuContext <= 0)
    {
        crWarning("no spuSontext defined");
        goto end;
    }

    ctxid = context->spuContext;

end:
    crHashtableUnlock(stub.contextTable);
    return ctxid;
}
Example #4
0
DECLEXPORT(GLint) WINAPI VBoxGetWindowId( HDC hdc )
{
    WindowInfo *window;
    GLint winid = 0;

    CR_DDI_PROLOGUE();

    crHashtableLock(stub.windowTable);

    window = stubGetWindowInfo(hdc);
    if (!window)
    {
        crWarning("stubGetWindowInfo: window not found!");
        goto end;
    }
    if (!window->spuWindow)
    {
        crWarning("stubGetWindowInfo: window is null!");
        goto end;
    }

    winid = window->spuWindow;

end:
    crHashtableUnlock(stub.windowTable);
    return winid;
}
Example #5
0
void APIENTRY crWindowDestroy( GLint window )
{
    WindowInfo *winInfo = (WindowInfo *)
        crHashtableSearch(stub.windowTable, (unsigned int) window);
    if (winInfo && winInfo->type == CHROMIUM && stub.spu)
    {
        crHashtableLock(stub.windowTable);

        stub.spu->dispatch_table.WindowDestroy( winInfo->spuWindow );

#ifdef WINDOWS
        if (winInfo->hVisibleRegion != INVALID_HANDLE_VALUE)
        {
            DeleteObject(winInfo->hVisibleRegion);
        }
#elif defined(GLX)
        if (winInfo->pVisibleRegions)
        {
            XFree(winInfo->pVisibleRegions);
        }
# ifdef CR_NEWWINTRACK
        if (winInfo->syncDpy)
        {
            XCloseDisplay(winInfo->syncDpy);
        }
# endif
#endif
        crForcedFlush();
        crHashtableDelete(stub.windowTable, window, crFree);

        crHashtableUnlock(stub.windowTable);
    }
}
Example #6
0
BOOL APIENTRY DrvDeleteContext(HGLRC hglrc)
{
#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
    ContextInfo *pContext;
    PVBOXUHGSMI pHgsmi = NULL;
#endif

    CR_DDI_PROLOGUE();
    crDebug( "DrvDeleteContext(0x%x) called", hglrc );

#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
    crHashtableLock(stub.contextTable);

    pContext = (ContextInfo *) crHashtableSearch(stub.contextTable, (unsigned long) hglrc);
    if (pContext)
        pHgsmi = pContext->pHgsmi;

    crHashtableUnlock(stub.contextTable);
#endif

    stubDestroyContext( (unsigned long) hglrc );

#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
    if (pHgsmi)
        VBoxCrHgsmiDestroy(pHgsmi);
#endif

    return true;
}
Example #7
0
static void stubCheckWindowsState(void)
{
    ContextInfo *context = stubGetCurrentContext();

    CRASSERT(stub.trackWindowSize || stub.trackWindowPos);

    if (!context)
        return;

#if defined(WINDOWS) && defined(VBOX_WITH_WDDM)
    if (stub.bRunningUnderWDDM)
        return;
#endif

    /* Try to keep a consistent locking order. */
    crHashtableLock(stub.windowTable);
#if defined(CR_NEWWINTRACK) && !defined(WINDOWS)
    crLockMutex(&stub.mutex);
#endif

    stubCheckWindowState(context->currentDrawable, GL_TRUE);
    crHashtableWalkUnlocked(stub.windowTable, stubCheckWindowsCB, context);

#if defined(CR_NEWWINTRACK) && !defined(WINDOWS)
    crUnlockMutex(&stub.mutex);
#endif
    crHashtableUnlock(stub.windowTable);
}
Example #8
0
File: load.c Project: OSLL/vboxhsm
/**
 * This is called when we exit.
 * We call all the SPU's cleanup functions.
 */
static void stubSPUTearDownLocked(void)
{
    crDebug("stubSPUTearDownLocked");

#ifdef WINDOWS
# ifndef CR_NEWWINTRACK
    stubUninstallWindowMessageHook();
# endif
#endif

#ifdef CR_NEWWINTRACK
    ASMAtomicWriteBool(&stub.bShutdownSyncThread, true);
#endif

    //delete all created contexts
    stubMakeCurrent( NULL, NULL);

    /* the lock order is windowTable->contextTable (see wglMakeCurrent_prox, glXMakeCurrent)
     * this is why we need to take a windowTable lock since we will later do stub.windowTable access & locking */
    crHashtableLock(stub.windowTable);
    crHashtableWalk(stub.contextTable, hsWalkStubDestroyContexts, NULL);
    crHashtableUnlock(stub.windowTable);

    /* shutdown, now trap any calls to a NULL dispatcher */
    crSPUCopyDispatchTable(&glim, &stubNULLDispatch);

    crSPUUnloadChain(stub.spu);
    stub.spu = NULL;

#ifndef Linux
    crUnloadOpenGL();
#endif

#ifndef WINDOWS
    crNetTearDown();
#endif

#ifdef GLX
    if (stub.xshmSI.shmid>=0)
    {
        shmctl(stub.xshmSI.shmid, IPC_RMID, 0);
        shmdt(stub.xshmSI.shmaddr);
    }
    crFreeHashtable(stub.pGLXPixmapsHash, crFree);
#endif

    crFreeHashtable(stub.windowTable, crFree);
    crFreeHashtable(stub.contextTable, NULL);

    crMemset(&stub, 0, sizeof(stub));

}
Example #9
0
PCR_BLITTER renderspuVBoxPresentBlitterGet( WindowInfo *window )
{
    PCR_BLITTER pBlitter = window->pBlitter;
    if (!pBlitter)
    {
        if (render_spu.blitterTable)
        {
            crHashtableLock(render_spu.blitterTable);
            pBlitter = (PCR_BLITTER)crHashtableSearch(render_spu.blitterTable, window->visual->visAttribs);
        }

        if (!pBlitter)
        {
            int rc;
            CR_BLITTER_CONTEXT ctx;
            pBlitter = (PCR_BLITTER)crCalloc(sizeof (*pBlitter));
            if (!pBlitter)
            {
                crWarning("failed to allocate blitter");
                return NULL;
            }

            /* @todo: this is the assumption that crserverlib uses context 1 as a default one
             * need to do it in a more proper way */
            ctx.Base.id = 1;
            ctx.Base.visualBits = window->visual->visAttribs;
            rc = CrBltInit(pBlitter, &ctx, true, true, render_spu.blitterDispatch);
            if (!RT_SUCCESS(rc))
            {
                crWarning("CrBltInit failed, rc %d", rc);
                crFree(pBlitter);
                return NULL;
            }

            if (render_spu.blitterTable)
            {
                crHashtableAdd( render_spu.blitterTable, window->visual->visAttribs, pBlitter );
            }
        }

        if (render_spu.blitterTable)
            crHashtableUnlock(render_spu.blitterTable);

        Assert(pBlitter);
        window->pBlitter = pBlitter;
    }

    CrBltMuralSetCurrent(pBlitter, &window->BltInfo);
    return pBlitter;
}
Example #10
0
//we're not going to change icdTable at runtime, so callback is unused
PICDTABLE APIENTRY DrvSetContext(HDC hdc, HGLRC hglrc, void *callback)
{
    ContextInfo *context;
    WindowInfo *window;
    BOOL ret;

    CR_DDI_PROLOGUE();

    /*crDebug( "DrvSetContext called(0x%x, 0x%x)", hdc, hglrc );*/
    (void) (callback);

    crHashtableLock(stub.windowTable);
    crHashtableLock(stub.contextTable);

    context = (ContextInfo *) crHashtableSearch(stub.contextTable, (unsigned long) hglrc);
    window = stubGetWindowInfo(hdc);

    ret = stubMakeCurrent(window, context);

    crHashtableUnlock(stub.contextTable);
    crHashtableUnlock(stub.windowTable);

    return ret ? &icdTable:NULL;
}
void
stubDestroyContext( unsigned long contextId )
{
    ContextInfo *context;

    if (!stub.contextTable) {
        return;
    }

    /* the lock order is windowTable->contextTable (see wglMakeCurrent_prox, glXMakeCurrent)
     * this is why we need to take a windowTable lock since we will later do stub.windowTable access & locking */
    crHashtableLock(stub.windowTable);
    crHashtableLock(stub.contextTable);

    context = (ContextInfo *) crHashtableSearch(stub.contextTable, contextId);
    if (context)
        stubDestroyContextLocked(context);
    else
        crError("No context.");

#ifdef CHROMIUM_THREADSAFE
    if (stubGetCurrentContext() == context) {
        stubSetCurrentContext(NULL);
    }

    VBoxTlsRefMarkDestroy(context);
    VBoxTlsRefRelease(context);
#else
    if (stubGetCurrentContext() == context) {
        stubSetCurrentContext(NULL);
    }
    stubContextFree(context);
#endif
    crHashtableUnlock(stub.contextTable);
    crHashtableUnlock(stub.windowTable);
}
Example #12
0
DECLEXPORT(void) WINAPI VBoxFlushToHost ( HGLRC hglrc )
{
    ContextInfo *context;

    CR_DDI_PROLOGUE();

//    crHashtableLock(stub.windowTable);
    crHashtableLock(stub.contextTable);

    context = (ContextInfo *) crHashtableSearch(stub.contextTable, (unsigned long) hglrc);

    if (context)
        stubConFlush(CR_CTX_CON(context));

    crHashtableUnlock(stub.contextTable);
//    crHashtableUnlock(stub.windowTable);
}
Example #13
0
DECLEXPORT(BOOL) WINAPI wglShareLists_prox( HGLRC hglrc1, HGLRC hglrc2 )
{
    ContextInfo *context1, *context2;
    GLint aSpuContexts[2];

    CR_DDI_PROLOGUE();

//    crHashtableLock(stub.windowTable);
    crHashtableLock(stub.contextTable);

    context1 = (ContextInfo *) crHashtableSearch(stub.contextTable, (unsigned long) hglrc1);

    if (!context1)
    {
        WARN(("invalid hglrc1"));
        return FALSE;
    }

    stubCtxCheckCreate(context1);

    context2 = (ContextInfo *) crHashtableSearch(stub.contextTable, (unsigned long) hglrc2);

    if (!context2)
    {
        WARN(("invalid hglrc2"));
        return FALSE;
    }

    stubCtxCheckCreate(context2);

    aSpuContexts[0] = context1->spuContext;
    aSpuContexts[1] = context2->spuContext;

    stubConChromiumParametervCR(CR_CTX_CON(context2), GL_SHARE_LISTS_CR, GL_INT, 2, aSpuContexts);

    crHashtableUnlock(stub.contextTable);

    return TRUE;
}
Example #14
0
DECLEXPORT(void) WINAPI VBoxCtxChromiumParameteriCR(HGLRC hglrc, GLenum param, GLint value)
{
    ContextInfo *context;

    CR_DDI_PROLOGUE();

//    crHashtableLock(stub.windowTable);
    crHashtableLock(stub.contextTable);

    context = (ContextInfo *) crHashtableSearch(stub.contextTable, (unsigned long) hglrc);

    if (context)
    {
        stubCtxCheckCreate(context);
        stubConChromiumParameteriCR(CR_CTX_CON(context), param, value);
    }
    else
        crWarning("invalid context %#x", hglrc);

    crHashtableUnlock(stub.contextTable);
//    crHashtableUnlock(stub.windowTable);
}
void stubDestroyWindow( GLint con, GLint window )
{
    WindowInfo *winInfo = (WindowInfo *)
        crHashtableSearch(stub.windowTable, (unsigned int) window);
    if (winInfo && winInfo->type == CHROMIUM && stub.spu)
    {
        crHashtableLock(stub.windowTable);

        stub.spu->dispatch_table.VBoxWindowDestroy(con, winInfo->spuWindow );

#ifdef WINDOWS
        if (winInfo->hVisibleRegion != INVALID_HANDLE_VALUE)
        {
            DeleteObject(winInfo->hVisibleRegion);
        }
#elif defined(GLX)
        if (winInfo->pVisibleRegions)
        {
            XFree(winInfo->pVisibleRegions);
        }
# ifdef CR_NEWWINTRACK
        if (winInfo->syncDpy)
        {
            XCloseDisplay(winInfo->syncDpy);
        }
# endif
#endif

        stubForcedFlush(con);

        crHashtableWalk(stub.contextTable, stubWindowCleanupForContextsCB, winInfo);

        crHashtableDelete(stub.windowTable, window, crFree);

        crHashtableUnlock(stub.windowTable);
    }
}
Example #16
0
static DECLCALLBACK(int) stubSyncThreadProc(RTTHREAD ThreadSelf, void *pvUser)
{
#ifdef WINDOWS
    MSG msg;
# ifdef VBOX_WITH_WDDM
    HMODULE hVBoxD3D = NULL;
    GLint spuConnection = 0;
# endif
#endif

    (void) pvUser;

    crDebug("Sync thread started");
#ifdef WINDOWS
    PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);
# ifdef VBOX_WITH_WDDM
    hVBoxD3D = NULL;
    if (!GetModuleHandleEx(0, VBOX_MODNAME_DISPD3D, &hVBoxD3D))
    {
        crDebug("GetModuleHandleEx failed err %d", GetLastError());
        hVBoxD3D = NULL;
    }

    if (hVBoxD3D)
    {
                    crDebug("running with " VBOX_MODNAME_DISPD3D);
                    stub.trackWindowVisibleRgn = 0;
                    stub.bRunningUnderWDDM = true;
    }
# endif /* VBOX_WITH_WDDM */
#endif /* WINDOWS */

    crLockMutex(&stub.mutex);
#if defined(WINDOWS) && defined(VBOX_WITH_WDDM)
    spuConnection =
#endif
            stub.spu->dispatch_table.VBoxPackSetInjectThread(NULL);
#if defined(WINDOWS) && defined(VBOX_WITH_WDDM)
    if (stub.bRunningUnderWDDM && !spuConnection)
    {
        crError("VBoxPackSetInjectThread failed!");
    }
#endif
    crUnlockMutex(&stub.mutex);

    RTThreadUserSignal(ThreadSelf);

    while(!stub.bShutdownSyncThread)
    {
#ifdef WINDOWS
        if (!PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
        {
# ifdef VBOX_WITH_WDDM
            if (stub.bRunningUnderWDDM)
            {

            }
            else
# endif
            {
                crHashtableWalk(stub.windowTable, stubSyncTrCheckWindowsCB, NULL);
                RTThreadSleep(50);
            }
        }
        else
        {
            if (WM_QUIT==msg.message)
            {
                crDebug("Sync thread got WM_QUIT");
                break;
            }
            else
            {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
        }
#else
        /* Try to keep a consistent locking order. */
        crHashtableLock(stub.windowTable);
        crLockMutex(&stub.mutex);
        crHashtableWalkUnlocked(stub.windowTable, stubSyncTrCheckWindowsCB, NULL);
        crUnlockMutex(&stub.mutex);
        crHashtableUnlock(stub.windowTable);
        RTThreadSleep(50);
#endif
    }

#ifdef VBOX_WITH_WDDM
    if (spuConnection)
    {
        stub.spu->dispatch_table.VBoxConDestroy(spuConnection);
    }
    if (hVBoxD3D)
    {
        FreeLibrary(hVBoxD3D);
    }
#endif
    crDebug("Sync thread stopped");
    return 0;
}