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

📄 khronos_egl.c

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

    pTls->lastError = EGL_SUCCESS;

    DPF ((DBG_MESSAGE, "egl (app->egl): eglGetDisplay()\n"));

	nativeDisplay = WS_MapEGLDisplay2WSDisplay(nativeDisplay);
	/* Check to see if the native display handle has been registered */
	for (iSlot = 0; iSlot < WS_GetDisplayCount(); ++iSlot)
	{
		if (pTls->dpys[iSlot].nativeDisplay == nativeDisplay)
		{
			return SLOT_INDEX_TO_EGLDISPLAY(iSlot);
		}
		else if ((iFirstFreeSlot == -1) && (pTls->dpys[iSlot].nativeDisplay == (NativeDisplayType) EGL_NO_DISPLAY))
		{
			iFirstFreeSlot = iSlot;
		}
	}

	if (iFirstFreeSlot == -1)
	{
		return EGL_NO_DISPLAY;
	}
    
	/* Ask the native window system to validate the native display handle */
    bValidDisplay = WS_ValidateDisplay(nativeDisplay, &pTls->dpys[iFirstFreeSlot]);

    /* Keep track of which display we are referring to */
    if ( bValidDisplay )
    {
    	eglDpy = SLOT_INDEX_TO_EGLDISPLAY(iFirstFreeSlot);
        pTls->dpys[iFirstFreeSlot].nativeDisplay = nativeDisplay;
	}

    return (eglDpy);
}


/*
   <function>
   FUNCTION   : eglInitialise
   PURPOSE    : API. Initialise a display.
   PARAMETERS : In:  eglDpy
                In:  major
                In:  minor
   RETURNS    : EGL_TRUE - success
                EGL_FALSE - failure
   </function>
 */
IMG_EXPORT EGLBoolean
eglInitialize (EGLDisplay eglDpy, EGLint *major, EGLint *minor)
{
    KEGL_DISPLAY *pDpy;
    TLS pTls;
    
    DPF ((DBG_MESSAGE, "eglInitialize ()"));

  	pTls = TLS_Open (_TlsInit);
	    if (pTls==IMG_NULL)
		{
			return EGL_FALSE;
		}
	
    pTls->lastError = EGL_SUCCESS;
    if (eglDpy==EGL_NO_DISPLAY)
    {
        pTls->lastError = EGL_BAD_DISPLAY;
        return EGL_FALSE;
    }
    pDpy = &pTls->dpys[EGLDISPLAY_TO_SLOT_INDEX(eglDpy)];

    if (major!=0)
        *major = 1;

    if (minor!=0)
        *minor = 0;

	if (!pDpy->isInitialised)
	{
	    if (!GLESServicesInit (&pTls->servicesContext))
	    {
	        pTls->lastError = EGL_BAD_ALLOC;
			return EGL_FALSE;
	    }
    
    pTls->lastError = WS_Open (&pTls->servicesContext, pDpy);
    if (pTls->lastError != EGL_SUCCESS)
    {
		/* ignore return indiction */ 
		GLESServicesDeInit (&pTls->servicesContext);
		return EGL_FALSE;
    }
    
    pDpy->isInitialised = EGL_TRUE;
    pDpy->pHeadSurface = IMG_NULL;
	}

    pTls->lastError = EGL_SUCCESS;
    return EGL_TRUE;
}

/*
   <function>
   FUNCTION   : eglTerminate
   PURPOSE    : Terminate a display.
   PARAMETERS : In:  eglDpy
   RETURNS    : EGL_TRUE - success.
                EGL_FALSE - failure.
   </function>
 */
IMG_EXPORT EGLBoolean 
eglTerminate (EGLDisplay eglDpy)
{
    KEGL_DISPLAY *pDpy;
    TLS pTls;

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

    DPF((DBG_MESSAGE, "egl (app->egl): eglTerminate()"));

    if (eglDpy==EGL_NO_DISPLAY)
    {
        pTls->lastError = EGL_BAD_DISPLAY;
        return EGL_FALSE;
    }

    pDpy = &pTls->dpys[EGLDISPLAY_TO_SLOT_INDEX(eglDpy)];

	if(pDpy->isInitialised)
	{ 
		WS_Close (pDpy);
		
		pDpy->isInitialised = EGL_FALSE;
		
		if (pTls->currentContext == EGL_NO_CONTEXT && pTls->currentDrawSurface == EGL_NO_SURFACE)
		{
			if (!GLESServicesDeInit (&pTls->servicesContext))
				pTls->lastError = EGL_BAD_ALLOC;
		}
		else
		{
			pTls->currentContext->isDeleting = EGL_TRUE;
			pTls->currentDrawSurface->isDeleting = EGL_TRUE;
			pTls->currentReadSurface->isDeleting = EGL_TRUE;
		}
	}

	TLS_Close ();
	return EGL_TRUE;
}

/*
   <function>
   FUNCTION   : eglQueryString
   PURPOSE    :

   Query one of the predefined strings associated with a display.
              
   PARAMETERS : In:  eglDpy - Display handle to query.
                In:  name - String identifier.
   RETURNS    : Queried string or IMG_NULL.
   </function>
 */
IMG_EXPORT const char *
eglQueryString (EGLDisplay eglDpy, EGLint name)
{
    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): eglQueryString()"));

    if (eglDpy==EGL_NO_DISPLAY)
    {
        pTls->lastError = EGL_BAD_DISPLAY;
        return 0;
    }

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

    pTls->lastError = EGL_SUCCESS;
    switch (name)
    {
    case EGL_VENDOR:
        return "Imagination Technologies";
    case EGL_VERSION:
        return "1.0 build 1";
    case EGL_EXTENSIONS:
        return
            "EGL_IMG_power_management "
#ifdef OES_SWAP_CONTROL
            " EGL_OES_swap_control"
#endif
            ;

    default:
        pTls->lastError = EGL_BAD_PARAMETER;
        return 0;
    }
}

/*
   <function>
   FUNCTION   : eglGetProcAddress
   PURPOSE    : Retrieve extension functions.
                No extension functions are currently implemented.
   PARAMETERS : In:  procname - Extension function name.
   RETURNS    : Extension function or IMG_NULL.
   </function>
 */
void (* eglGetProcAddress (const char *procname))(void)
{
    TLS pTls;
    EGLint uIndex;
    /* This table defines the procedures which can be queried and the
     * associated function */
    const static struct
    {
        const char *pProcname;
        void       (*pfnProc)(void);
    } aProcedure[] =
        {
#ifdef OES_SWAP_CONTROL
            {"eglSwapIntervalOES", (void(*)(void))eglSwapIntervalOES},
#endif
            {0, 0}
        };

    DPF((DBG_VERBOSE, "egl (app->egl): eglGetProcAddress (%s)", procname));

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

    /* Check the table of procedures aProcedure, for a match, if found
       return the associated function pointer. */
    for (uIndex=0; aProcedure[uIndex].pProcname!=0; uIndex++)
    {
        if (strncmp (aProcedure[uIndex].pProcname,
                     procname,
                     strlen (aProcedure[uIndex].pProcname)+1) == 0)
        {             
            return aProcedure[uIndex].pfnProc;
        }
	}
	
    return 	__GetProcAddress(procname);
}

/*
   <function>
   FUNCTION   : eglGetConfigs
   PURPOSE    : Retreive the configurations associated with a display.
   PARAMETERS : In:  eglDpy - Display.
                Out: configs - Receives the config array.
                In:  config_size - The size of the config array.
                Out: num_config - Receives the actual number of configs
                     received.
   RETURNS    : EGL_TRUE - Success.
                EGL_FALSE - Failure.
   </function>
 */
IMG_EXPORT EGLBoolean 
eglGetConfigs (EGLDisplay eglDpy, 
               EGLConfig *configs,
               EGLint config_size,
               EGLint *num_config)
{
    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): eglGetConfigs()"));

    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 (num_config==0)
    {
        pTls->lastError = EGL_BAD_PARAMETER;
        return EGL_FALSE;
    }

    if (configs==0)
        *num_config = CFG_Variants (pDpy);
    else
    {
        EGLint count = CFG_Variants (pDpy);
        for ((*num_config)=0;
             (*num_config) < count && (*num_config) < config_size;
             (*num_config)++)
            configs[*num_config] = *num_config+1;
    }
    pTls->lastError = EGL_SUCCESS;
    return EGL_TRUE;
}

/*
   <function>
   FUNCTION   : eglChooseConfig
   PURPOSE    : Retrieve configurations which match a selection criteria.
   PARAMETERS : In:  dpy - Display.
                In:  pAttribList -
                     List of required attribute identifiers and
                     attribute values, terminated with identifier
                     EGL_NONE.
                Out: configs - Receives the config array.
                In:  config_size - The size of the config array.
                Out: num_config - Receives the actual number of configs
                     received.
   RETURNS    : EGL_TRUE - Success.
                EGL_FALSE - Failure.
   </function>
 */
IMG_EXPORT EGLBoolean 
eglChooseConfig (EGLDisplay eglDpy,
                 const EGLint *pAttribList,
                 EGLConfig *configs,
                 EGLint config_size,
                 EGLint *num_config)
{
    KEGL_DISPLAY *pDpy;
    KEGL_CONFIG **working_configs;
    EGLint match_count;
    EGLint i;
    EGLint cfg_variants;
    KEGL_CONFIG *requested_cfg;
    TLS pTls;

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

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

    pTls->lastError = _ValidateAttribList (pAttribList);
    if (pTls->lastError != EGL_SUCCESS)
        return EGL_FALSE;
    
    requested_cfg = CFG_PrepareConfigFilter (pAttribList);
    if (requested_cfg==IMG_NULL)
        return EGL_FALSE;

    /* The k-egl specification states that EGL_LEVEL may not be set to
       don;t care */
    if (CFGC_GetAttrib (requested_cfg, EGL_LEVEL) == EGL_DONT_CARE)
    {
        CFGC_Unlink (requested_cfg);
        pTls->lastError = EGL_BAD_PARAMETER;
        return EGL_FALSE;
    }

    cfg_variants = CFG_Variants (pDpy);
    working_configs = GLESMalloc (0,sizeof (*working_configs) * cfg_variants);
    if (working_configs==IMG_NULL)
    {
        CFGC_Unlink (requested_cfg);
        pTls->lastError = EGL_BAD_ALLOC;
        return EGL_FALSE;
    }

    for (match_count=0,i=1; i<=cfg_variants; i++)
    {
        KEGL_CONFIG *pCfg;
        pTls->lastError = CFG_GenerateVariant (pDpy, i, &pCfg);
        if (pTls->lastError!=EGL_SUCCESS)
        {
            for (i=0; i<match_count; i++)
                CFGC_Unlink (working_configs[i]);
            GLESFree(0,working_configs);
            CFGC_Unlink (requested_cfg);
            pTls->lastError = EGL_BAD_ALLOC;
            return EGL_FALSE;
        }
        if (CFG_Match (requested_cfg, pCfg))
        {
            working_configs[match_count] = pCfg;
            match_count ++;
        }
        else
            CFGC_Unlink (pCfg);
    }
    
    if (configs==0)
    {
        for (i=0; i<match_count; i++)
            CFGC_Unlink (working_configs[i]);
        GLESFree(0,working_configs);
        CFGC_Unlink (requested_cfg);
        *num_config = match_count;
        return EGL_TRUE;
    }

    /* sort the results */
    PVR_qsort_s (working_configs, match_count, sizeof (*working_configs),
                 CFG_Compare, requested_cfg);
    CFGC_Unlink (requested_cfg);
    
    for ((*num_config)=0;
         (*num_config)<config_size && (*num_config) < match_count;
         (*num_config)++)
    {
        configs[(*num_config)] =
            CFGC_GetAttrib (working_configs[(*num_config)], EGL_CONFIG_ID);

⌨️ 快捷键说明

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