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

📄 khronos_egl.c

📁 Lido PXA270平台开发板的最新BSP,包括源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
            pTls->lastError = EGL_BAD_ALLOC;
            return EGL_FALSE;
        }
        if (imgResult == IMG_GLES_MEMORY_INVALID_ERROR)
        {
            pTls->lastError = EGL_CONTEXT_LOST_IMG;
            return EGL_FALSE;
        }

        pTls->currentContext->isCurrent = EGL_TRUE;
        pTls->currentContext->boundThread = ENV_CurrentThread ();
      
        pTls->currentReadSurface = read;
        if (read!=EGL_NO_SURFACE)
        {
            read->currentCount++;
            read->boundThread = ENV_CurrentThread ();
        }
      
        pTls->currentDrawSurface = draw;
        if (draw!=EGL_NO_SURFACE)
        {
            draw->currentCount++;
            draw->boundThread = ENV_CurrentThread ();
        }
    }
  
    return EGL_TRUE;
}

/*
   <function>
   FUNCTION   : eglGetCurrentContext
   PURPOSE    : Retreive the current context, if any.
   PARAMETERS : None.
   RETURNS    : Current context or EGL_NO_CONTEXT.
   </function>
 */
IMG_EXPORT EGLContext
eglGetCurrentContext (void)
{
    TLS pTls;

    	pTls = TLS_Open (_TlsInit);
	    if (pTls==IMG_NULL)
		{
			return EGL_FALSE;
		}
    
    pTls->lastError = EGL_SUCCESS;
    DPF((DBG_VERBOSE, "egl (app->egl): eglGetCurrentContext()"));
    pTls->lastError = EGL_SUCCESS;
    return pTls->currentContext;
}

/*
   <function>
   FUNCTION   : eglGetCurrentSurface
   PURPOSE    : Retreive the current draw or read surface if any.
   PARAMETERS : In:  readdraw - retreive the draw or read surface.
   RETURNS    : Surface or EGL_NO_SURFACE.
   </function>
 */
IMG_EXPORT EGLSurface
eglGetCurrentSurface (EGLint readdraw)
{
    TLS pTls;

    	pTls = TLS_Open (_TlsInit);
	    if (pTls==IMG_NULL)
		{
			return EGL_FALSE;
		}
    
    pTls->lastError = EGL_SUCCESS;
    DPF((DBG_VERBOSE, "egl (app->egl): eglGetCurrentSurface()"));
    pTls->lastError = EGL_BAD_PARAMETER;
    switch (readdraw)
    {
    case EGL_READ:
        pTls->lastError = EGL_SUCCESS;
        return pTls->currentReadSurface;
    case EGL_DRAW:
        pTls->lastError = EGL_SUCCESS;
        return pTls->currentDrawSurface;
    }
    return EGL_NO_SURFACE;
}

/*
   <function>
   FUNCTION   : eglGetCurrentDisplay
   PURPOSE    : Retreive the current display, if any.
   PARAMETERS : None.
   RETURNS    : Display or EGL_NO_DISPLAY.
   </function>
 */
IMG_EXPORT EGLDisplay
eglGetCurrentDisplay (void)
{
    TLS pTls;

    	pTls = TLS_Open (_TlsInit);
	    if (pTls==IMG_NULL)
		{
			return EGL_FALSE;
		}
    
    pTls->lastError = EGL_SUCCESS;
    DPF((DBG_VERBOSE, "egl (app->egl): eglGetCurrentDisplay()"));
    if (pTls->currentContext==EGL_NO_CONTEXT)
        return EGL_NO_DISPLAY;
    pTls->lastError = EGL_SUCCESS;
    return pTls->currentContext->eglDpy;
}

/*
   <function>
   FUNCTION   : eglQueryContext
   PURPOSE    : Query an attribute of a context.
   PARAMETERS : In:  eglDpy - Display.
                In:  pCtx - Context.
                In:  attribute - Attribute to query.
                Out: value - Receives the queried attribute value.
   RETURNS    : EGL_TRUE - Success.
                EGL_FALSE - Failure.
   </function>
 */
IMG_EXPORT EGLBoolean
eglQueryContext (EGLDisplay eglDpy,
                 EGLContext pCtx,
                 EGLint attribute,
                 EGLint *value)
{
    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): eglQueryContext()"));
    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 (attribute<_EGL_CONFIG_ATTR_FIRST || attribute >=_EGL_CONFIG_ATTR_LAST)
    {
        pTls->lastError = EGL_BAD_ATTRIBUTE;
        return EGL_FALSE;
    }

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

    if (attribute != EGL_CONFIG_ID)
    {
        /* The k-egl specification is not clear what should be happening
           here, complaining seems like an appropriate response. */
        pTls->lastError = EGL_BAD_PARAMETER;
        return EGL_FALSE;
    }
    pTls->lastError = EGL_SUCCESS;
    *value = CFGC_GetAttrib (pCtx->pCfg, attribute);
    return EGL_TRUE;
}

/*
   <function>
   FUNCTION   : eglWaitGL
   PURPOSE    : Wait for OpenGL to complete rendering.
   PARAMETERS : None
   RETURNS    : EGL_TRUE - Success
                EGL_FALSE - Failure
   </function>
 */
IMG_EXPORT EGLBoolean 
eglWaitGL (void)
{
    TLS pTls;

    	pTls = TLS_Open (_TlsInit);
	    if (pTls==IMG_NULL)
		{
			return EGL_FALSE;
		}
    
    pTls->lastError = EGL_SUCCESS;
    DPF((DBG_VERBOSE, "egl (app->egl): eglWaitGL()"));
    /*
      todo: Bengi how to do this.
      imgResult = GLESFlushContext ();
    */
    return EGL_TRUE;
}

/*
   <function>
   FUNCTION   : eglWaitNative
   PURPOSE    : Wait for a native rendering engine to finish rendering.
   PARAMETERS : In:  engine - Native graphics engine to synchronise with.
   RETURNS    : EGL_TRUE - success.
                EGL_FALSE - failure.
   </function>
 */
IMG_EXPORT EGLBoolean 
eglWaitNative (EGLint engine)
{
    TLS pTls;

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

    DPF((DBG_VERBOSE, "egl (app->egl): eglWaitNative()"));

    pTls->lastError = EGL_SUCCESS;
    if (pTls->currentContext==EGL_NO_CONTEXT)
	return EGL_TRUE;

    pTls->lastError = WS_WaitNative (pTls->currentDrawSurface, engine);
    if (pTls->lastError != EGL_SUCCESS)
	return EGL_FALSE;
    
    return EGL_TRUE;
}

/*
   <function>
   FUNCTION   : eglSwapBuffers
   PURPOSE    : Present the current back buffer.
   PARAMETERS : In:  eglDpy - Display.
                In:  draw - Surface.
   RETURNS    : EGL_TRUE - Success.
                EGL_FALSE - Failure.
   </function>
 */
IMG_EXPORT EGLBoolean 
eglSwapBuffers (EGLDisplay eglDpy, EGLSurface draw)
{
    KEGL_DISPLAY *pDpy;
    TLS pTls;
	IMG_GLESERROR eError;

    	pTls = TLS_Open (_TlsInit);
	    if (pTls==IMG_NULL)
		{
			return EGL_FALSE;
		}
    
    pTls->lastError = EGL_SUCCESS;
    DPF((DBG_VERBOSE, "egl (app->egl): eglSwapBuffers()"));
    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 (draw==EGL_NO_SURFACE)
    {
        pTls->lastError = EGL_BAD_SURFACE;
        return EGL_FALSE;
    }

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

    switch (draw->type)
    {
    case EGL_SURFACE_WINDOW:
        eError = GLESFlushBuffersGC (pTls->currentContext->hOGL, IMG_FALSE);
	
        if (eError == IMG_GLES_MEMORY_INVALID_ERROR)
        {
            pTls->lastError = EGL_CONTEXT_LOST_IMG;
            return EGL_FALSE;
        }

        /* We may have lost a scene (from power management). Just omit the swap */
        if (eError == IMG_GLES_NO_ERROR)
        {
            WS_SwapDrawable (draw);
        }
        break;
    case EGL_SURFACE_PIXMAP:
    case EGL_SURFACE_PBUFFER:
        /* no affect on non window surfaces */
        break;
    }
    pTls->lastError = EGL_SUCCESS;
    return EGL_TRUE;
}

#ifdef OES_SWAP_CONTROL
IMG_EXPORT EGLBoolean
eglSwapIntervalOES (EGLint interval)
{
    TLS pTls;

    pTls = TLS_Open (_TlsInit);
    if (pTls==IMG_NULL)
    {
        return EGL_FALSE;
    }

    pTls->lastError = EGL_SUCCESS;
    DPF ((DBG_VERBOSE, "egl (app->egl): eglSwapIntervalIMG ()"));

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

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

    /* The specification requires that the requested interval is
     * silently clamped to the implementations maximum supported
     * interval
     */
    if (interval > CFGC_GetAttrib (pTls->currentContext->cfg, EGL_MAX_SWAP_INTERVAL_OES))
        interval = CFGC_GetAttrib (pTls->currentContext->cfg, EGL_MAX_SWAP_INTERVAL_OES);

    /* The specification is vague on behaviour when the requested
     * interval is non zero, but below the minimum value supported by
     * the implementation. We clamp silently.
     */
    if (interval > 0 && interval < CFGC_GetAttrib (pTls->currentContext->cfg, EGL_MIN_SWAP_INTERVAL_OES))
        interval = CFGC_GetAttrib (pTls->currentContext->cfg, EGL_MIN_SWAP_INTERVAL_OES);

    if (pTls->currentDrawSurface->type == EGL_SURFACE_WINDOW)
      WS_SwapControlInterval (&pTls->currentDrawSurface->u.window.ws, interval);

    return EGL_TRUE;
}

#endif

/*
   <function>
   FUNCTION   : eglCopyBuffers
   PURPOSE    : Copy a render to a native pixmap.
   PARAMETERS : In:  eglDpy - Display.
                In:  pSurface - Surface.
                In:  target - Native pixmap 
   RETURNS    : EGL_TRUE - Success.
                EGL_FALSE - Failure.
   </function>
 */
IMG_EXPORT EGLBoolean 
eglCopyBuffers (EGLDisplay eglDpy,
                EGLSurface pSurface,
                NativePixmapType target)
{
  KEGL_DISPLAY *pDpy;
  TLS pTls;
  IMG_GLESERROR eError;

      pTls = TLS_Open (_TlsInit);
      if (pTls==IMG_NULL)
	{
	  return EGL_FALSE;
	}
    
  pTls->lastError = EGL_SUCCESS;
    DPF((DBG_VERBOSE, "egl (app->egl): eglCopyBuffers()"));
  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 (target==0)
    {
      pTls->lastError = EGL_BAD_PARAMETER;
      return EGL_FALSE;
    }

  /* todo: deal with native window resize? */
  eError = GLESFlushBuffersGC (pTls->currentContext->hOGL, IMG_TRUE);
    switch (eError)
    {
    case IMG_GLES_NO_ERROR:
        /* success */
        break;
    case IMG_GLES_MEMORY_INVALID_ERROR:
      pTls->lastError = EGL_CONTEXT_LOST_IMG;
      return EGL_FALSE;
    default:
        pTls->lastError = EGL_BAD_ALLOC;
        return EGL_FALSE;
    }

	/* We may have lost a scene (from power management). Just omit the copy */
	if (eError == IMG_GLES_NO_ERROR)
    {
		pTls->lastError = WS_CopyBuffers (pSurface, target);
    }
	
	if (pTls->lastError!=EGL_SUCCESS)
    {
		return EGL_FALSE;
    }
	
  return EGL_TRUE;
}

/**************************************************************************
 End of file (khronos_egl.c)
**************************************************************************/

⌨️ 快捷键说明

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