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

📄 khronos_egl.c

📁 Lido PXA270平台开发板的最新BSP,包括源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
        CFGC_Unlink (working_configs[(*num_config)]);
    }

    GLESFree(0,working_configs);
    return EGL_SUCCESS;
}

/*
   <function>
   FUNCTION   : eglGetConfigAttrib
   PURPOSE    : Retreive an attribute from a configuration.
   PARAMETERS : In:  eglDpy
                In:  config
                In:  attribute
                Out: value
   RETURNS    : EGL_TRUE - Success.
                EGL_FALSE - Failure.
   </function>
 */
IMG_EXPORT EGLBoolean 
eglGetConfigAttrib (EGLDisplay eglDpy,
                    EGLConfig eglCfg,
                    EGLint attribute,
                    EGLint *value)
{
    KEGL_DISPLAY *pDpy;
    KEGL_CONFIG *pCfg;
    
    TLS pTls;

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

    DPF((DBG_VERBOSE, "egl (app->egl): eglGetConfigAttrib()"));
  
    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 (value==IMG_NULL)
    {
        pTls->lastError = EGL_BAD_PARAMETER;
        return EGL_FALSE;
    }

    if (attribute<_EGL_CONFIG_ATTR_FIRST || attribute >_EGL_CONFIG_ATTR_LAST)
    {
        pTls->lastError = EGL_BAD_ATTRIBUTE;
        return EGL_FALSE;
    }

    pTls->lastError = CFG_GenerateVariant (pDpy, eglCfg, &pCfg);
    if (pTls->lastError!=EGL_SUCCESS)
        return EGL_FALSE;
    
    *value = CFGC_GetAttrib (pCfg, attribute);
    CFGC_Unlink (pCfg);
    
    pTls->lastError = EGL_SUCCESS;
    return EGL_TRUE;
}

/*
   <function>
   FUNCTION   :  eglCreateWindowSurface
   PURPOSE    :  Create a window surface.
   PARAMETERS :  In:  eglDpy -
                 In:  config -
                 In:  window -
                 In:  pAttribList -
   RETURNS    :  Created surface or EGL_NO_SURFACE.
   </function>
 */
IMG_EXPORT EGLSurface
eglCreateWindowSurface (EGLDisplay eglDpy,
                        EGLConfig eglCfg,
                        NativeWindowType window,
                        const EGLint *pAttribList)
{
    KEGL_DISPLAY *pDpy;
    EGLSurface pSurface;
  
    TLS pTls;
    	pTls = TLS_Open (_TlsInit);
	    if (pTls==IMG_NULL)
		{
			return EGL_FALSE;
		}
    
    pTls->lastError = EGL_SUCCESS;

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

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

    /* 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_SURFACE;
    }

    if  (_FindWindowSurface (pDpy, window)!=IMG_NULL)
    {
        pTls->lastError = EGL_BAD_ALLOC;
        return EGL_NO_SURFACE;
    }
  
    pSurface = GLESMalloc (0,sizeof *pSurface);
    if (pSurface == 0)
    {
        pTls->lastError = EGL_BAD_ALLOC;
        return EGL_NO_SURFACE;
    }
    pSurface->currentCount = 0;
    pSurface->boundThread = 0;
    pSurface->isDeleting = EGL_FALSE;
    pSurface->type = EGL_SURFACE_WINDOW;
    pSurface->u.window.native = window;
    pSurface->pDpy = pDpy;
    pSurface->pvrsrv_context = &pTls->servicesContext;

    pTls->lastError = CFG_GenerateVariant (pDpy, eglCfg, &pSurface->pCfg);
    if (pTls->lastError!=EGL_SUCCESS)
    {
        GLESFree(0,pSurface);
        return EGL_NO_SURFACE;
    }
    
    if (!(CFGC_GetAttrib (pSurface->pCfg, EGL_SURFACE_TYPE) & EGL_WINDOW_BIT))
    {
        CFGC_Unlink (pSurface->pCfg);
        GLESFree(0,pSurface);
        pTls->lastError = EGL_BAD_MATCH;
        return EGL_NO_SURFACE;
    }

    pTls->lastError = WS_CreateWindowDrawable (pDpy, pSurface, window);
    if (pTls->lastError != EGL_SUCCESS)
    {
        CFGC_Unlink (pSurface->pCfg);
        GLESFree(0,pSurface);
        return EGL_NO_SURFACE;
    }
  
    /* Chain the new surface onto the displays surface list */
    pSurface->pNextSurface = pDpy->pHeadSurface;
    pDpy->pHeadSurface = pSurface;
  
    pTls->lastError = EGL_SUCCESS;
    return pSurface;
}

/*
   <function>
   FUNCTION   : eglCreatePixmapSurface
   PURPOSE    : Create a pixmap surface.
                There are no attributes defined for pAttribList is the
                current implementation.
   PARAMETERS : In:  eglDpy - Display
                In:  eglCfg - Configuration.
                In:  pixmap - Native pixmap.
                In:  pAttribList - List of required attributes.
   RETURNS    : Created surface or EGL_NO_SURFACE.
   </function>
 */
IMG_EXPORT EGLSurface
eglCreatePixmapSurface (EGLDisplay eglDpy,
                        EGLConfig eglCfg,
                        NativePixmapType pixmap,
                        const EGLint *pAttribList)
{
    KEGL_DISPLAY *pDpy;
    EGLSurface pSurface;
  
    TLS pTls;
pTls = TLS_Open (_TlsInit);
	    if (pTls==IMG_NULL)
		{
			return EGL_FALSE;
		}
    
    pTls->lastError = EGL_SUCCESS;

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

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

    /* 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_SURFACE;
    }

    /* Check to see if this pixmap is already associated with a surface on
       this display */
    if (_FindPixmapSurface (pDpy, pixmap))
    {
        pTls->lastError = EGL_BAD_ALLOC;
        return EGL_NO_SURFACE;
    }
  
    pSurface = GLESMalloc (0,sizeof *pSurface);
    if (pSurface == 0)
    {
        pTls->lastError = EGL_BAD_ALLOC;
        return EGL_NO_SURFACE;
    }
    pSurface->currentCount = 0;
    pSurface->boundThread = 0;
    pSurface->isDeleting = EGL_FALSE;
    pSurface->type = EGL_SURFACE_PIXMAP;
    pSurface->u.pixmap.native = pixmap;
    pSurface->pDpy = pDpy;
    pSurface->pvrsrv_context = &pTls->servicesContext;

    pTls->lastError = CFG_GenerateVariant (pDpy, eglCfg, &pSurface->pCfg);
    if (pTls->lastError!=EGL_SUCCESS)
    {
        GLESFree(0,pSurface);
        return EGL_NO_SURFACE;
    }

    if (!(CFGC_GetAttrib(pSurface->pCfg, EGL_SURFACE_TYPE) & EGL_PIXMAP_BIT))
    {
        CFGC_Unlink (pSurface->pCfg);
        GLESFree(0,pSurface);
        pTls->lastError = EGL_BAD_MATCH;
        return EGL_NO_SURFACE;
    }

    pTls->lastError = WS_CreatePixmapDrawable (pDpy, pSurface, pixmap);
    if (pTls->lastError != EGL_SUCCESS)
    {
        CFGC_Unlink (pSurface->pCfg);
        GLESFree(0,pSurface);
        return EGL_NO_SURFACE;
    }
  
    /* chain this surface onto the displays surface list */
    pSurface->pNextSurface = pDpy->pHeadSurface;
    pDpy->pHeadSurface = pSurface;

    pTls->lastError = EGL_SUCCESS;
    return pSurface;
}

/*
   <function>
   FUNCTION   : eglCreatePbufferSurface
   PURPOSE    : Create a Pbuffer surface.
   PARAMETERS : In:  eglDpy - Display.
                In:  eglCfg - Configuration.
                In:  pAttribList - Required attributes.
   RETURNS    : Created surface or EGL_NO_SURFACE.
   </function>
 */
IMG_EXPORT EGLSurface
eglCreatePbufferSurface (EGLDisplay eglDpy,
                         EGLConfig eglCfg,
                         const EGLint *pAttribList)
{
    KEGL_DISPLAY *pDpy;
    EGLSurface pSurface;
    EGLint pbuffer_width = 0;
    EGLint pbuffer_height = 0;
    EGLBoolean pbuffer_largest = EGL_FALSE;
    EGLint pixel_width = 0;
    PVRSRV_PIXEL_FORMAT pvr_pf;
    TLS pTls;

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

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

    if (pAttribList!=IMG_NULL)
        while (*pAttribList!=EGL_NONE)
        {
            EGLint attrib = *pAttribList++;
            EGLint value;
            if (attrib<EGL_HEIGHT || attrib > EGL_LARGEST_PBUFFER)
            {
                pTls->lastError = EGL_BAD_PARAMETER;
                return EGL_NO_SURFACE;
            }
            value = *pAttribList++;
            switch (attrib)
            {
            case EGL_WIDTH:
                pbuffer_width = value;
                break;
            case EGL_HEIGHT:
                pbuffer_height = value;
                break;
            case EGL_LARGEST_PBUFFER:
                pbuffer_largest = EGL_TRUE;
                break;
            }
        }

    pSurface = GLESMalloc (0,sizeof *pSurface);
    if (pSurface == 0)
    {
        pTls->lastError = EGL_BAD_ALLOC;
        return EGL_NO_SURFACE;
    }
    pSurface->currentCount = 0;
    pSurface->boundThread = 0;
    pSurface->isDeleting = EGL_FALSE;
    pSurface->type = EGL_SURFACE_PBUFFER;
    pSurface->pDpy = pDpy;
    pSurface->pvrsrv_context = &pTls->servicesContext;

    pTls->lastError = CFG_GenerateVariant (pDpy, eglCfg, &pSurface->pCfg);
    if (pTls->lastError!=EGL_SUCCESS)
    {
        GLESFree(0,pSurface);
        return EGL_NO_SURFACE;
    }
    
    if (!(CFGC_GetAttrib(pSurface->pCfg, EGL_SURFACE_TYPE) & EGL_PBUFFER_BIT))
    {
        CFGC_Unlink (pSurface->pCfg);
        GLESFree(0,pSurface);
        pTls->lastError = EGL_BAD_MATCH;
        return EGL_NO_SURFACE;
    }

    if (( pbuffer_width >
          CFGC_GetAttrib (pSurface->pCfg, EGL_MAX_PBUFFER_WIDTH))
        || (pbuffer_height >
            CFGC_GetAttrib (pSurface->pCfg, EGL_MAX_PBUFFER_HEIGHT))
        || (pbuffer_width * pbuffer_height >
            CFGC_GetAttrib (pSurface->pCfg, EGL_MAX_PBUFFER_PIXELS)))
    {
        CFGC_Unlink (pSurface->pCfg);
        GLESFree(0,pSurface);
        pTls->lastError = EGL_BAD_PARAMETER;
        return EGL_NO_SURFACE;
    }

    if (!SRV_FindPVRPixelFormat (CFGC_GetAttrib (pSurface->pCfg, EGL_ALPHA_SIZE),
                                 CFGC_GetAttrib (pSurface->pCfg, EGL_RED_SIZE),
                                 CFGC_GetAttrib (pSurface->pCfg, EGL_GREEN_SIZE),
                                 CFGC_GetAttrib (pSurface->pCfg, EGL_BLUE_SIZE),
                                 &pvr_pf,
                                 &pixel_width))
	{
	    /* this is not a sane failure mode, in theory the configuration
	       can only represent a valid pixel format and width! */
	    assert (0);
	}

    
    pTls->lastError = GWS_CreatePBufferDrawable (&pTls->servicesContext,
                                                pDpy,
                                                pSurface,
                                                pbuffer_width,
                                                pbuffer_height,
                                                pbuffer_largest,
                                                pixel_width,
                                                pvr_pf);
    if (pTls->lastError != EGL_SUCCESS)
    {
        CFGC_Unlink (pSurface->pCfg);
        GLESFree(0,pSurface);
        return EGL_NO_SURFACE;
    }
  
    /* chain this surface onto the displays surface list */
    pSurface->pNextSurface = pDpy->pHeadSurface;
    pDpy->pHeadSurface = pSurface;

    pTls->lastError = EGL_SUCCESS;
    return pSurface;
}

/*
   <function>
   FUNCTION   : eglDestroySurface
   PURPOSE    : Destroy a window, pixmap or pbuffer surface.
   PARAMETERS : In:  pDpy
                In:  pSurface
   RETURNS    : EGL_TRUE - Success.
                EGL_FALSE
                Failure. The error code can be retreived with eglGetError.
   </function>
 */
IMG_EXPORT EGLBoolean
eglDestroySurface (EGLDisplay eglDpy, EGLSurface pSurface)
{
    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): eglDestroySurface()"));
  
    if (eglDpy==EGL_NO_DISPLAY)
    {
        pTls->lastError = EGL_BAD_DISPLAY;
        return EGL_FALSE;

⌨️ 快捷键说明

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