⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 khronos_egl.c

📁 Lido PXA270平台开发板的最新BSP,包括源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
    }

    pDpy = &pTls->dpys[EGLDISPLAY_TO_SLOT_INDEX(eglDpy)];
    if (!pDpy->isInitialised)
    {
        pTls->lastError = EGL_NOT_INITIALIZED;
        return EGL_FALSE;
    }

    if (pSurface==EGL_NO_SURFACE)
    {
        pTls->lastError = EGL_BAD_SURFACE;
        return EGL_FALSE;
    }

    if (pSurface->currentCount>0)
        pSurface->isDeleting = EGL_TRUE;
    else
        _SurfaceDelete (&pTls->servicesContext, pSurface);

    pTls->lastError = EGL_SUCCESS;
    return EGL_TRUE;
}

/*
   <function>
   FUNCTION   : eglQuerySurface
   PURPOSE    : Query an attribute of a surface.
   PARAMETERS : In:  eglDpy - Display.
                In:  pSurface - Surface.
                In:  attribute - Attribute to query.
                In:  value - Receives the value of the queried attribute.
   RETURNS    : EGL_TRUE - Success
                EGL_FALSE - Failure
   </function>
 */
IMG_EXPORT EGLBoolean
eglQuerySurface (EGLDisplay eglDpy,
                 EGLSurface pSurface, 
                 EGLint attribute,
                 EGLint *value)
{
    KEGL_DISPLAY *pDpy;
    TLS pTls;
	GLESDrawableParams sParams;

    	pTls = TLS_Open (_TlsInit);
	    if (pTls==IMG_NULL)
		{
			return EGL_FALSE;
		}
    
    pTls->lastError = EGL_SUCCESS;

    DPF((DBG_VERBOSE, "egl (app->egl): eglQuerySurface()"));
  
    if (eglDpy==EGL_NO_DISPLAY)
    {
        pTls->lastError = EGL_BAD_DISPLAY;
        return EGL_FALSE;
    }

    pDpy = &pTls->dpys[EGLDISPLAY_TO_SLOT_INDEX(eglDpy)];
    if (!pDpy->isInitialised)
    {
        pTls->lastError = EGL_NOT_INITIALIZED;
        return EGL_FALSE;
    }

    if (pSurface==EGL_NO_SURFACE)
    {
        pTls->lastError = EGL_BAD_SURFACE;
        return EGL_FALSE;
    }

    if (value==0)
    {
        pTls->lastError = EGL_BAD_PARAMETER;
        return EGL_FALSE;
    }

	if (!GLESGetDrawableParameters (pSurface, &sParams))
	{
		pTls->lastError = EGL_BAD_SURFACE;
        return EGL_FALSE;
	}

    switch (attribute)
    {
    case EGL_WIDTH:
    	*value = sParams.ui32Width;
		if (CFGC_GetAttrib(pSurface->pCfg, EGL_SURFACE_TYPE) & EGL_WINDOW_BIT)
		{
			if ((pSurface->u.window.ws.ui32RotationAngle == 90) ||
                (pSurface->u.window.ws.ui32RotationAngle == 270))
			{
				*value = pSurface->sCurrentRenderSurface.ui32PixelHeight;		
			}
			else
			{
				*value = pSurface->sCurrentRenderSurface.ui32PixelWidth;
			}
		}
		else
		{
			*value = pSurface->sCurrentRenderSurface.ui32PixelWidth;
		}
        break;
    case EGL_HEIGHT:
    	*value = sParams.ui32Height;
		if (CFGC_GetAttrib(pSurface->pCfg, EGL_SURFACE_TYPE) & EGL_WINDOW_BIT)
		{
			if ((pSurface->u.window.ws.ui32RotationAngle == 90) ||
                (pSurface->u.window.ws.ui32RotationAngle == 270))
			{
				*value = pSurface->sCurrentRenderSurface.ui32PixelWidth;		
			}
			else
			{
				*value = pSurface->sCurrentRenderSurface.ui32PixelHeight;
			}
		}
		else
		{
			*value = pSurface->sCurrentRenderSurface.ui32PixelHeight;
		}
        break;
    case EGL_CONFIG_ID:
        *value = CFGC_GetAttrib (pSurface->pCfg, attribute);
        break;
    case EGL_LARGEST_PBUFFER:
        if (pSurface->type==EGL_SURFACE_PBUFFER)
            *value = CFGC_GetAttrib (pSurface->pCfg, attribute);
        /* note for other window types *value is not updated! */
        break;
    default:
        pTls->lastError = EGL_BAD_ATTRIBUTE;
        return EGL_FALSE;
    }
  
    pTls->lastError = EGL_SUCCESS;
    return EGL_TRUE;
}

/*
   <function>
   FUNCTION   : eglCreateContext
   PURPOSE    : Create a rendering context.
   PARAMETERS : In:  eglDpy - Display.
                In:  eglCfg - Configuration.
                In:  pShareList - Shared context or IMG_NULL.
                In:  pAttribList - Attributes or IMG_NULL.
   RETURNS    : Context or EGL_NO_CONTEXT.
   </function>
 */
IMG_EXPORT EGLContext
eglCreateContext (EGLDisplay eglDpy, 
                  EGLConfig eglCfg, 
                  EGLContext pShareList, 
                  const EGLint *pAttribList)
{
    KEGL_DISPLAY *pDpy;
    EGLContext pCtx = EGL_NO_CONTEXT;
    IMG_BOOL imgResult;
    GLESContextHandle share_ctx = IMG_NULL;
	GLESAppHints sAppHints;

    TLS pTls;

    	pTls = TLS_Open (_TlsInit);
	    if (pTls==IMG_NULL)
		{
			return EGL_FALSE;
		}
    
    pTls->lastError = EGL_SUCCESS;

    DPF((DBG_VERBOSE, "egl (app->egl): eglCreateContext()"));
    if (eglDpy==EGL_NO_DISPLAY)
    {
        pTls->lastError = EGL_BAD_DISPLAY;
        return EGL_FALSE;
    }

    pDpy = &pTls->dpys[EGLDISPLAY_TO_SLOT_INDEX(eglDpy)];
    if (!pDpy->isInitialised)
    {
        pTls->lastError = EGL_NOT_INITIALIZED;
        return EGL_FALSE;
    }

    /* The k-egl specification is not clear how we should deal with
       the attribute list if we don;t accept attributes, complaining seems
       like a sensible response. */
    if (pAttribList != IMG_NULL && *pAttribList != EGL_NONE)
    {
        pTls->lastError = EGL_BAD_PARAMETER;
        return EGL_NO_CONTEXT;
    }

    if (pShareList != IMG_NULL && pShareList->pDpy != pDpy)
    {
        pTls->lastError = EGL_BAD_MATCH;
        return EGL_NO_CONTEXT;
    }
      
    pCtx = GLESMalloc (0,sizeof (*pCtx));
    if (pCtx==0)
    {
        pTls->lastError = EGL_BAD_ALLOC;
        return EGL_NO_CONTEXT;
    }

    pCtx->isFirstMakeCurrent = EGL_TRUE;
    pCtx->isCurrent = EGL_FALSE;
    pCtx->boundThread = 0;
    pCtx->isDeleting = EGL_FALSE;
    pCtx->pDpy = pDpy;
    pCtx->eglDpy = eglDpy;

    pTls->lastError = CFG_GenerateVariant (pDpy, eglCfg, &pCtx->pCfg);
    if (pTls->lastError!=EGL_SUCCESS)
    {
        GLESFree(0,pCtx);
        return EGL_NO_CONTEXT;
    }
    
    _InitialiseContextMode (&pCtx->contextMode, pCtx->pCfg);

    /* check the configs of this context and the shared context are
     * compatible */
    if (pShareList!=EGL_NO_CONTEXT
        && !CFG_CompatibleConfigs (pCtx->pCfg, pShareList->pCfg))
    {
        CFGC_Unlink (pCtx->pCfg);
        GLESFree(0,pCtx);
        pTls->lastError = EGL_BAD_MATCH;
        return EGL_NO_CONTEXT;
    }

	GetApplicationHints (&sAppHints);

    if (pShareList!=IMG_NULL)
        share_ctx = pShareList->hOGL;
    else
        share_ctx = IMG_NULL;

    imgResult = GLESCreateGC (&pTls->servicesContext,
                              &pCtx->hOGL,
                              &pCtx->contextMode,
                              share_ctx,
                              &sAppHints);
    if (!imgResult)
    {
        CFGC_Unlink (pCtx->pCfg);
        GLESFree (0, pCtx);
        pTls->lastError = EGL_BAD_ALLOC;
        return EGL_NO_CONTEXT;
    }
    return pCtx;
}

/*
   <function>
   FUNCTION   : eglDestroyContext
   PURPOSE    : Delete a rendering context.
   PARAMETERS : In:  eglDpy - Display that the context was created on.
                In:  pCtx - The context to destroy.
   RETURNS    : EGL_TRUE - Success.
                EGL_FALSE - Failure.
   </function>
 */
IMG_EXPORT EGLBoolean
eglDestroyContext (EGLDisplay eglDpy, EGLContext pCtx)
{
    KEGL_DISPLAY *pDpy;
    TLS pTls;

    	pTls = TLS_Open (_TlsInit);
	    if (pTls==IMG_NULL)
		{
			return EGL_FALSE;
		}
    
    pTls->lastError = EGL_SUCCESS;

    DPF((DBG_VERBOSE, "egl (app->egl): eglDestroyContext()"));
    if (eglDpy==EGL_NO_DISPLAY)
    {
        pTls->lastError = EGL_BAD_DISPLAY;
        return EGL_FALSE;
    }

    pDpy = &pTls->dpys[EGLDISPLAY_TO_SLOT_INDEX(eglDpy)];
    if (!pDpy->isInitialised)
    {
        pTls->lastError = EGL_NOT_INITIALIZED;
        return EGL_FALSE;
    }

    if (pCtx==EGL_NO_CONTEXT)
    {
        pTls->lastError = EGL_BAD_CONTEXT;
        return EGL_FALSE;
    }

   	if (pCtx->isCurrent)
	{
		pCtx->isDeleting = EGL_TRUE;
	}
    else
    {
		pTls->lastError =_ContextDelete (pCtx);
        if (pTls->lastError != EGL_SUCCESS)
        {         
            return EGL_FALSE;
		}
    }

    pTls->lastError = EGL_SUCCESS;
    return EGL_TRUE;
}

/*
   <function>
   FUNCTION   : eglMakeCurrent
   PURPOSE    : Bind draw and read surfaces to a context making them current. 
   PARAMETERS : In:  eglDpy - Display.
                In:  draw - Draw surface or EGL_NO_SURFACE.
                In:  read - Read surface or EGL_NO_SURFACE.
                In:  pCtx - Context or EGL_NO_CONTEXT.
   RETURNS    : EGL_TRUE - Success
                EGL_FALSE - Failure.
   </function>
 */
IMG_EXPORT EGLBoolean
eglMakeCurrent (EGLDisplay eglDpy,
                EGLSurface draw,
                EGLSurface read,
                EGLContext pCtx)
{
    TLS pTls;

    	pTls = TLS_Open (_TlsInit);
	    if (pTls==IMG_NULL)
		{
			return EGL_FALSE;
		}
    
    pTls->lastError = EGL_SUCCESS;

    DPF((DBG_VERBOSE, "egl (app->egl): eglMakeCurrent()"));
  
    /* If pCtx is bound to another thread or draw or read are bound to
       contexts in another thread then BAD_ACCESS. Currently we don;t
       support other threads so this should never be the case. */ 

    if (_ContextBoundToOtherThread (pCtx)
        || _SurfaceBoundToOtherThread (read)
        || _SurfaceBoundToOtherThread (draw))
    {
        pTls->lastError = EGL_BAD_ACCESS; 
        return EGL_FALSE; 
    }

    if (pCtx==EGL_NO_CONTEXT && (read!=EGL_NO_SURFACE || draw!=EGL_NO_SURFACE))
    {
        pTls->lastError = EGL_BAD_MATCH;
        return EGL_FALSE;
    }

    if (pCtx!=EGL_NO_CONTEXT && (read==EGL_NO_SURFACE && draw==EGL_NO_SURFACE))
    {
        pTls->lastError = EGL_BAD_MATCH;
        return EGL_FALSE;
    }

    if (pCtx!=EGL_NO_CONTEXT)
    {
        if (read!=EGL_NO_SURFACE)
            if (!_CompatibleContextAndSurface (pCtx, read))
            {
                pTls->lastError = EGL_BAD_MATCH;
                return EGL_FALSE;
            }
        if (draw!=EGL_NO_SURFACE)
            if (!_CompatibleContextAndSurface (pCtx, draw))
            {
                pTls->lastError = EGL_BAD_MATCH;
                return EGL_FALSE;
            }
    }
  
    /* if native window behind draw has become invalid */
    /* todo: can a pixmap become invalid? */
    if (draw!=EGL_NO_SURFACE && draw->type == EGL_SURFACE_WINDOW &&
        !WS_WindowValid (draw->u.window.native))
    {
        pTls->lastError = EGL_BAD_NATIVE_WINDOW;
        return EGL_FALSE;
    }

    /* if native window behind read has become invalid */
    /* todo: can a pixmap become invalid? */
    if (read!=EGL_NO_SURFACE && read->type == EGL_SURFACE_WINDOW &&
        !WS_WindowValid (read->u.window.native))
    {
        pTls->lastError = EGL_BAD_NATIVE_WINDOW;
        return EGL_FALSE;
    }

    /** @todo if draw and read cannot fit into graphics memory */
    if (0)
    {
        pTls->lastError = EGL_BAD_MATCH;
        return EGL_FALSE;
    }

    if (pTls->currentContext != EGL_NO_CONTEXT)
    {
	
        pTls->currentContext->isCurrent = EGL_FALSE;

        if (pTls->currentContext->isDeleting)
        {
            /* The previous current context has been marked for
             * deletion. Deletion of a context ?might? fail in which
             * case we report the failure here. The sequence is odd,
             * the app called eglDestroyContext which reported success
             * followed eventually by eglMakeCurrent which actually
             * detects a problem with destroying the context and
             * reports an error. This behaviour is preferable to
             * simply hiding the failure from the application. */
            pTls->lastError = _ContextDelete (pTls->currentContext);
            pTls->currentContext = EGL_NO_CONTEXT;
            if (pTls->lastError!=EGL_SUCCESS)
                return EGL_FALSE;
        }
        pTls->currentContext = EGL_NO_CONTEXT;
    }

    if (pTls->currentReadSurface!=EGL_NO_SURFACE)
    {
        _SurfaceUnbind (&pTls->servicesContext, pTls->currentReadSurface);
        pTls->currentReadSurface = EGL_NO_SURFACE;
    }
  
    if (pTls->currentDrawSurface!=EGL_NO_SURFACE)
    {
        _SurfaceUnbind (&pTls->servicesContext, pTls->currentDrawSurface);
        pTls->currentDrawSurface = EGL_NO_SURFACE;
    }

    if (pCtx!=EGL_NO_CONTEXT)
    {
        IMG_GLESERROR imgResult;
        
        if (pCtx->isFirstMakeCurrent)
        {
            pCtx->isFirstMakeCurrent = EGL_FALSE;
        }

        pTls->currentContext = pCtx;

        imgResult = GLESMakeCurrentGC (draw,read, pCtx->hOGL);
        if (imgResult == IMG_GLES_GENERIC_ERROR)
        {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -