Esempio n. 1
0
DECLEXPORT(void) STATE_APIENTRY crStateGLSLDestroy(CRContext *ctx)
{
    CRContext *g = GetCurrentContext();

    /*@todo: hack to allow crStateFreeGLSLProgram to work correctly, 
      as the current context isn't the one being destroyed*/
#ifdef CHROMIUM_THREADSAFE
    CRASSERT(g != ctx);
    VBoxTlsRefAddRef(ctx); /* <- this is a hack to avoid subsequent SetCurrentContext(g) do recursive Destroy for ctx */
    if (g)
        VBoxTlsRefAddRef(g); /* <- ensure the g is not destroyed by the following SetCurrentContext call */
    SetCurrentContext(ctx);
#else
    __currentContext = ctx;
#endif

    crFreeHashtable(ctx->glsl.programs, crStateFreeGLSLProgram);
    crFreeHashtable(ctx->glsl.shaders, crStateFreeGLSLShader);

#ifdef CHROMIUM_THREADSAFE
    SetCurrentContext(g);
    if (g)
        VBoxTlsRefRelease(g);
    VBoxTlsRefRelease(ctx); /* <- restore back the cRefs (see above) */
#else
    __currentContext = g;
#endif

}
Esempio n. 2
0
/*
 * Allocate the state (dirty) bits data structures.
 * This should be called before we create any contexts.
 * We'll also create the default/NULL context at this time and make
 * it the current context by default.  This means that if someone
 * tries to set GL state before calling MakeCurrent() they'll be
 * modifying the default state object, and not segfaulting on a NULL
 * pointer somewhere.
 */
void crStateInit(void)
{
    unsigned int i;

    /* Purely initialize the context bits */
    if (!__currentBits) {
        __currentBits = (CRStateBits *) crCalloc( sizeof(CRStateBits) );
        crStateClientInitBits( &(__currentBits->client) );
        crStateLightingInitBits( &(__currentBits->lighting) );
    } else
        crWarning("State tracker is being re-initialized..\n");

    for (i=0;i<CR_MAX_CONTEXTS;i++)
        g_availableContexts[i] = 0;

#ifdef CHROMIUM_THREADSAFE
    if (!__isContextTLSInited)
    {
# ifndef RT_OS_WINDOWS
        /* tls destructor is implemented for all platforms except windows*/
        crInitTSDF(&__contextTSD, crStateThreadTlsDtor);
# else
        /* windows should do cleanup via DllMain THREAD_DETACH notification */
        crInitTSD(&__contextTSD);
# endif
        __isContextTLSInited = 1;
    }
#endif

    if (defaultContext) {
        /* Free the default/NULL context.
         * Ensures context bits are reset */
#ifdef CHROMIUM_THREADSAFE
        SetCurrentContext(NULL);
        VBoxTlsRefRelease(defaultContext);
#else
        crStateFreeContext(defaultContext);
        __currentContext = NULL;
#endif
    }

    /* Reset diff_api */
    crMemZero(&diff_api, sizeof(SPUDispatchTable));

    /* Allocate the default/NULL context */
    defaultContext = crStateCreateContextId(0, NULL, CR_RGB_BIT, NULL);
    CRASSERT(g_availableContexts[0] == 0);
    g_availableContexts[0] = 1; /* in use forever */

#ifdef CHROMIUM_THREADSAFE
    SetCurrentContext(defaultContext);
#else
    __currentContext = defaultContext;
#endif
}
Esempio n. 3
0
void AndroidEGL::SetCurrentRenderingContext()
{
	PImplData->CurrentContextType = CONTEXT_Rendering;
	if(GUseThreadedRendering)
	{
		SetCurrentContext(PImplData->RenderingContext.eglContext, PImplData->RenderingContext.eglSurface);
	}
	else
	{
		SetCurrentContext(PImplData->SingleThreadedContext.eglContext, PImplData->SingleThreadedContext.eglSurface);
	}
}
Esempio n. 4
0
void AndroidEGL::SetCurrentSharedContext()
{
	check(IsInGameThread());
	PImplData->CurrentContextType = CONTEXT_Shared;

	if(GUseThreadedRendering)
	{
		SetCurrentContext(PImplData->SharedContext.eglContext, PImplData->SharedContext.eglSurface);
	}
	else
	{
		SetCurrentContext(PImplData->SingleThreadedContext.eglContext, PImplData->SingleThreadedContext.eglSurface);
	}
}
Esempio n. 5
0
void AndroidEGL::SetSharedContext()
{
	check(IsInGameThread());
	PImplData->CurrentContextType = CONTEXT_Shared;

	SetCurrentContext(PImplData->SharedContext.eglContext, PImplData->SharedContext.eglSurface);
}
Esempio n. 6
0
void crStateMakeCurrent( CRContext *ctx )
{
    CRContext *current = GetCurrentContext();

    if (ctx == NULL)
        ctx = defaultContext;

    if (current == ctx)
        return; /* no-op */

    CRASSERT(ctx);

    if (current) {
        /* Check to see if the differencer exists first,
           we may not have one, aka the packspu */
        if (diff_api.AlphaFunc)
            crStateSwitchContext( current, ctx );
    }

#ifdef CHROMIUM_THREADSAFE
    SetCurrentContext(ctx);
#else
    __currentContext = ctx;
#endif

    /* ensure matrix state is also current */
    crStateMatrixMode(ctx->transform.matrixMode);
}
Esempio n. 7
0
void crStateDestroyContext( CRContext *ctx )
{
    CRContext *current = GetCurrentContext();

    if (current == ctx) {
        /* destroying the current context - have to be careful here */
        CRASSERT(defaultContext);
        /* Check to see if the differencer exists first,
           we may not have one, aka the packspu */
        if (diff_api.AlphaFunc)
            crStateSwitchContext(current, defaultContext);
#ifdef CHROMIUM_THREADSAFE
        SetCurrentContext(defaultContext);
#else
        __currentContext = defaultContext;
#endif
        /* ensure matrix state is also current */
        crStateMatrixMode(defaultContext->transform.matrixMode);
    }
    g_availableContexts[ctx->id] = 0;

#ifdef CHROMIUM_THREADSAFE
    VBoxTlsRefRelease(ctx);
#else
    crStateFreeContext(ctx);
#endif
}
Esempio n. 8
0
void crStateOnThreadAttachDetach(GLboolean attach)
{
    if (attach)
        return;

    /* release the context ref so that it can be freed */
    SetCurrentContext(NULL);
}
Esempio n. 9
0
void PUBLIC
glXDestroyContext(Display *dpy, GLXContext ctx)
{
   struct _glxapi_table *t;
   GET_DISPATCH(dpy, t);
   if (!t)
      return;
   if (glXGetCurrentContext() == ctx)
      SetCurrentContext(NULL);
   (t->DestroyContext)(dpy, ctx);
}
Esempio n. 10
0
Bool PUBLIC
glXMakeContextCurrent(Display *dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx)
{
   Bool b;
   struct _glxapi_table *t;
   GET_DISPATCH(dpy, t);
   if (!t)
      return False;
   b = (t->MakeContextCurrent)(dpy, draw, read, ctx);
   if (b) {
      SetCurrentContext(ctx);
   }
   return b;
}
Esempio n. 11
0
/*
 * As above, but don't call crStateSwitchContext().
 */
void crStateSetCurrent( CRContext *ctx )
{
    CRContext *current = GetCurrentContext();

    if (ctx == NULL)
        ctx = defaultContext;

    if (current == ctx)
        return; /* no-op */

    CRASSERT(ctx);

#ifdef CHROMIUM_THREADSAFE
    SetCurrentContext(ctx);
#else
    __currentContext = ctx;
#endif

    /* ensure matrix state is also current */
    crStateMatrixMode(ctx->transform.matrixMode);
}
Esempio n. 12
0
void AndroidEGL::SetMultithreadRenderingContext()
{
	PImplData->CurrentContextType = CONTEXT_Rendering;
	SetCurrentContext(PImplData->RenderingContext.eglContext, PImplData->RenderingContext.eglSurface);
}
Esempio n. 13
0
BOOL CUploadThread::RunThread()
{
	DFUThreadContext Context;
	BOOL bRet=TRUE;
	BOOL bReDownload=FALSE;
	BOOL NeedsToChangeElement;
	DWORD dwPercentCalc;
	
	// UploadState Machine
	m_PollTime=0;

	GetCurrentContext(&Context);

	switch (Context.LastDFUStatus.bState)
	{
	case 0xFF:
		m_Retry=NB_TRIALS;
		Context.LastDFUStatus.bState=0xFE;
		Context.CurrentRequest=STDFU_RQ_OPEN;
		SetCurrentContext(&Context);
		// We start our state machine. Let's open the handle
		if (STDFU_Open(Context.szDevLink, &Context.hDevice)!=STDFU_NOERROR)
		{
			Context.ErrorCode=STDFU_OPENDRIVERERROR;
			bRet=FALSE; // Stops here
			SetCurrentContext(&Context);
		}
		else
		{
			Context.CurrentRequest=STDFU_RQ_SELECT_ALTERNATE;
			SetCurrentContext(&Context);
			CImage *pImage=(CImage*)Context.hImage;
			if (STDFU_SelectCurrentConfiguration(&Context.hDevice, 0, 0, pImage->GetAlternate())!=STDFU_NOERROR)
			{
				Context.ErrorCode=STDFUPRT_UNEXPECTEDERROR;
				SetCurrentContext(&Context);
				bRet=FALSE;
				STDFU_Abort(&Context.hDevice); // Reset State machine
			}
			else
			{
				bRet=EnsureIdleMode(&Context);
				if (bRet)
				{
					CImage *pImage=(CImage*)Context.hImage;

					if (pImage->GetNbElements()==0)
					{
						Context.Percent=100;
						SetCurrentContext(&Context);
						bRet=FALSE;
					}
					else
					{
						Context.CurrentImageElement=0;
						bRet=SetAddressAndGetStatus(&Context);
					}
				}
			}
		}
		break;
	case STATE_DFU_DOWNLOAD_BUSY:
	case STATE_DFU_UPLOAD_BUSY:
		// End of PollTimeOut
		Context.CurrentRequest=STDFU_RQ_GET_STATUS;
		SetCurrentContext(&Context);
		// We finished to wait. Let's get the status
		if (STDFU_Getstatus(&Context.hDevice, &Context.LastDFUStatus)!=STDFU_NOERROR) 
		{
			Context.ErrorCode=STDFUPRT_UNEXPECTEDERROR;
			SetCurrentContext(&Context);
			bRet=FALSE; // Stops here
			STDFU_Abort(&Context.hDevice); // Reset State machine
		}
		else
		{
			SetCurrentContext(&Context);
			if (Context.LastDFUStatus.bStatus!=STATUS_OK)
			{
				Context.CurrentRequest=STDFU_RQ_CLR_STATUS;
				SetCurrentContext(&Context);
				if (Context.LastDFUStatus.bState==STATE_DFU_ERROR)
					STDFU_Clrstatus(&Context.hDevice);
				m_Retry--;
				if (!m_Retry)
				{
					Context.ErrorCode=STDFUPRT_UNEXPECTEDERROR;
					bRet=FALSE; // Stops here
					SetCurrentContext(&Context);
					STDFU_Abort(&Context.hDevice); // Reset State machine
				}
				else
					bReDownload=TRUE;
			}
			else
			{
				if ( (Context.LastDFUStatus.bStatus!=STATUS_OK) ||
					 ( (Context.LastDFUStatus.bState!=STATE_DFU_DOWNLOAD_IDLE) &&
					   (Context.LastDFUStatus.bState!=STATE_DFU_UPLOAD_IDLE) &&
					   (Context.LastDFUStatus.bState!=STATE_DFU_UPLOAD_IDLE) &&
					   (Context.LastDFUStatus.bState!=STATE_DFU_DOWNLOAD_BUSY) ) )
				{
					if (Context.LastDFUStatus.bStatus!=STATUS_OK)
						Context.ErrorCode=STDFUPRT_DFUERROR;	
					else
						Context.ErrorCode=STDFUPRT_BADFIRMWARESTATEMACHINE;
					bRet=FALSE; // Stops here
					SetCurrentContext(&Context);
					STDFU_Abort(&Context.hDevice); // Reset State machine
				}
				else
				{
					if ( (Context.LastDFUStatus.bState==STATE_DFU_DOWNLOAD_BUSY) ||
						 (Context.LastDFUStatus.bState==STATE_DFU_UPLOAD_BUSY) )
						m_PollTime=Context.LastDFUStatus.bwPollTimeout[0]+0x100*Context.LastDFUStatus.bwPollTimeout[1]+0x10000*Context.LastDFUStatus.bwPollTimeout[2];
					m_Retry=NB_TRIALS;
				}
			}
		}
		if (!bReDownload)
			break;
	case STATE_DFU_DOWNLOAD_IDLE:
	case STATE_DFU_UPLOAD_IDLE:
		{
			bRet=FALSE;
			NeedsToChangeElement=FALSE;
			
			if (Context.CurrentNBlock>=2)
			{
				dwPercentCalc=Context.CurrentNBlock-2;

				DFUIMAGEELEMENT Element;
				CImage *pImage=(CImage*)Context.hImage;
				DWORD i, NbEl=pImage->GetNbElements();
				for (i=0;i<Context.CurrentImageElement;i++)
				{
					memset(&Element, 0, sizeof(Element));
					pImage->GetImageElement(i, &Element);
					dwPercentCalc+=(Element.dwDataLength/m_Context.wTransferSize);
					if (Element.dwDataLength % m_Context.wTransferSize!=0)
						dwPercentCalc++;
				}

				Context.Percent=(dwPercentCalc*99)/m_NumBlockMax;
				SetCurrentContext(&Context);
			}
			else
			{
				if (Context.LastDFUStatus.bState==STATE_DFU_DOWNLOAD_IDLE)
				{
					// We just set the address of the current transfer, we need to go back to idle state 
					Context.CurrentRequest=STDFU_RQ_ABORT;
					SetCurrentContext(&Context);
					STDFU_Abort(&Context.hDevice); // Go to IDLE mode
				}
			}
			if (!bReDownload)
			{
				while (SetNextBlockDataParameters(&Context, &NeedsToChangeElement))
				{
					if (NeedsToChangeElement)
					{
						// We need to set the address of the current transfer, we need to go back to idle state 
						Context.CurrentRequest=STDFU_RQ_ABORT;
						SetCurrentContext(&Context);
						STDFU_Abort(&Context.hDevice); // Go to IDLE mode

						Context.CurrentImageElement++;
						bRet=SetAddressAndGetStatus(&Context);
						if (bRet)
							break;
					}
					else
					{
						bRet=TRUE;
						break;
					}
				}
				if ( (bRet) && (!NeedsToChangeElement) )
					bRet=UploadAndGetStatus(&Context);
				else
				if ( (!bRet) && (NeedsToChangeElement) )
				{
					// Success !
					EnsureIdleMode(&Context);
					Context.Percent=100;
					SetCurrentContext(&Context);
					bRet=FALSE;
				}
			}
			else
			{
				if (Context.CurrentNBlock>=2)
					bRet=UploadAndGetStatus(&Context);
				else							
					bRet=SetAddressAndGetStatus(&Context);
			}
		}
		break;
	default:
		Context.ErrorCode=STDFUPRT_BADFIRMWARESTATEMACHINE;
		bRet=FALSE; // Stops here
		SetCurrentContext(&Context);
		STDFU_Abort(&Context.hDevice); // Reset State machine
		break;
	}
	return bRet;
}