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

📄 cfg-core.c

📁 Lido PXA270平台开发板的最新BSP,包括源代码
💻 C
字号:
/* -*- c-file-style: "img" -*-
<module>
 * Name         : cfg-core.c
 * Title        : EGL Config Infrastructure.
 * Author       : Marcus Shawcroft
 * Created      : 4 Nov 2003
 *
 * Copyright    : 2003, 2004 by Imagination Technologies Limited.
 *                All rights reserved.  No part of this software, either
 *                material or conceptual may be copied or distributed,
 *                transmitted, transcribed, stored in a retrieval system
 *                or translated into any human or computer language in any
 *                form by any means, electronic, mechanical, manual or
 *                other-wise, or disclosed to third parties without the
 *                express written permission of Imagination Technologies
 *                Limited, Unit 8, HomePark Industrial Estate,
 *                King's Langley, Hertfordshire, WD4 8LZ, U.K.
 *
 * Description  : Refer to cfg.h
 * 
 * Platform     : ALL
 *
</module>
 */

#include "services.h"
#include "cfg-core.h"
#include "drvegl.h"
#include "hostfunc_um.h"
#include "ogles_types.h"
#include "osglue.h"


#define CFGC_GROW 8


struct _KEGL_CONFIG_
{
    KEGL_CONFIG *pNext;
    IMG_UINT32 uReferenceCount;
    IMG_BOOL bDeallocRequired;
    IMG_UINT32 uAttribSize;
    IMG_UINT32 uAttribCount;
    EGLint *pAttribArray;
};


/*
   <function>
   FUNCTION   : CFGC_Create
   PURPOSE    : Create an empty configuration.
   PARAMETERS : None
   RETURNS    : Configuration.
   </function>
 */
KEGL_CONFIG *CFGC_Create (void)
{
    KEGL_CONFIG *pCfg;

    pCfg = GLESMalloc (0, sizeof (*pCfg));

    if (pCfg!=IMG_NULL)
    {
        pCfg->pNext = IMG_NULL;
        pCfg->uReferenceCount = 1;
        pCfg->uAttribSize = 0;
        pCfg->uAttribCount = 0;
        pCfg->pAttribArray = IMG_NULL;
        pCfg->bDeallocRequired = IMG_TRUE;
    }

    return pCfg;
}


/*
   <function>
   FUNCTION   : CFGC_CreateAvArray
   PURPOSE    :

   Create a configuration with attributes and values defined in a
   constant attribue value array. The created configuration maintains
   a reference to the attribute value array, but the contents of the
   array are never modified and are not deallocated by the cfg module.
   The created configuration has one reference.
   
   PARAMETERS : In: - pV :

   Attribute value array. A sequence of attribute value pairs
   terminated with an EGL_NONE attribute.
   
   RETURNS    : Configuration.
   </function>
 */
KEGL_CONFIG *CFGC_CreateAvArray (const EGLint *pV)
{
    KEGL_CONFIG *pCfg;

    pCfg = CFGC_Create ();

	if (pCfg!=IMG_NULL)
	{
	    pCfg->bDeallocRequired = IMG_FALSE;
	    pCfg->pAttribArray = (EGLint *)pV;

	    for (pCfg->uAttribCount=0; pV[pCfg->uAttribCount]!=EGL_NONE; pCfg->uAttribCount+=2)
	        ;
	}

    return pCfg;
}


/*
   <function>
   FUNCTION   : CFGC_ModifyAvArrayNl
   PURPOSE    :

   Derive a new configuration from an old configuration redefining the
   attribute values specified in an attribute value array. The
   original configuration is not modified. The attribute value array
   is never modified and is not deallocated by the cfg module.
   The created configuration has one reference. An extra reference is
   not taken on the base configuration.
   
   PARAMETERS : In:  pBaseCfg - Configuration to derive from.
                In:  pV -

   Attribute value array. A sequence of attribute value pairs
   terminated with an EGL_NONE attribute.

   RETURNS    : Configuration
   </function>
 */
KEGL_CONFIG *CFGC_ModifyAvArrayNl (KEGL_CONFIG *pBaseCfg, const EGLint *pV)
{
    KEGL_CONFIG *pCfg;

    if (pBaseCfg==IMG_NULL)
    {
        return IMG_NULL;
    }

    pCfg = CFGC_Create ();

    if (pCfg == IMG_NULL)
    {
        CFGC_Unlink (pBaseCfg);
        return IMG_NULL;
    }
  
    pCfg->pNext = pBaseCfg;
    pCfg->bDeallocRequired = IMG_FALSE;
    pCfg->pAttribArray = (EGLint *) pV;

    for (pCfg->uAttribCount=0; pV[pCfg->uAttribCount]!=EGL_NONE; pCfg->uAttribCount+=2)
        ;

    return pCfg;
}


/*
   <function>
   FUNCTION   : CFGC_Link
   PURPOSE    : Take an extra reference on a configuration.
   PARAMETERS : In:  pCfg - configuration
   RETURNS    : Configuration provided as parameter one.
   </function>
 */
KEGL_CONFIG *CFGC_Link (KEGL_CONFIG *pCfg)
{
	if (pCfg!=IMG_NULL)
	{
	    pCfg->uReferenceCount++;
	}

    return pCfg;
}


/*
   <function>
   FUNCTION   : CFGC_CopyNl
   PURPOSE    : Create a copy of a configuration. The new configuration is
                derived from the base configuration but does not initially
                override any attribute values.
   PARAMETERS : In:  pCfg - configuration
   RETURNS    : New configuration.
   </function>
 */
KEGL_CONFIG *CFGC_CopyNl (KEGL_CONFIG *pCfg)
{
    KEGL_CONFIG *pCfgCopy;

    if (pCfg==IMG_NULL)
    {
        return IMG_NULL;
    }

    pCfgCopy = CFGC_Create ();

    if (pCfgCopy==IMG_NULL)
    {
        CFGC_Unlink (pCfg);
        return IMG_NULL;
    }

    pCfgCopy->pNext = pCfg;

    return pCfgCopy;
}


/*
   <function>
   FUNCTION   : CFGC_Unlink
   PURPOSE    :

   Unlink a configuration. Decremements the configurations reference
   count. Once the reference count hits zero the configuration is
   deleted and the base configuration if any is unlinked recursively.
   
   PARAMETERS : In:  pCfg - Configuration to unlink.
   RETURNS    : None
   </function>
 */
void CFGC_Unlink (KEGL_CONFIG *pCfg)
{
    if (pCfg!=IMG_NULL)
    {
        if (--pCfg->uReferenceCount == 0)
        {
            CFGC_Unlink (pCfg->pNext);

            if (pCfg->pAttribArray!=IMG_NULL && pCfg->bDeallocRequired)
            {
                GLESFree (0, pCfg->pAttribArray);
            }

            GLESFree (0, pCfg);
        }
    }
}


/*
   <function>
   FUNCTION   : CFGC_SetAttrib
   PURPOSE    :

   Change the value of an attribute in a configuration. This will also
   modify the value of the attribute in all configurations derived
   from the specified configuration that do not redefine the attribute
   explicitly.
                
   PARAMETERS : In:  pCfg - Configuration to modify.
                In:  iAttrib - Attribute to change.
                In:  iValue - New attribute value.
   RETURNS    : EGL_TRUE - Success.
                EGL_FALSE - Failure
   </function>
 */
EGLBoolean CFGC_SetAttrib (KEGL_CONFIG *pCfg, EGLint iAttrib, EGLint iValue)
{
    EGLint *av;

	if ((pCfg==IMG_NULL) || !pCfg->bDeallocRequired)
	{
        return EGL_FALSE;
	}

    if (pCfg->uAttribSize <= pCfg->uAttribCount+2)
    {
        EGLint iSize = pCfg->uAttribSize + CFGC_GROW;

        av = GLESRealloc (0, pCfg->pAttribArray, sizeof (*av) * iSize);

        if (av==IMG_NULL)
        {
            return EGL_FALSE;
        }

        pCfg->pAttribArray = av;
        pCfg->uAttribSize = iSize;
    }
  
    pCfg->pAttribArray[pCfg->uAttribCount++] = iAttrib;
    pCfg->pAttribArray[pCfg->uAttribCount++] = iValue;

    return EGL_TRUE;
}


/*
   <function>
   FUNCTION   : CFGC_GetAttrib
   PURPOSE    : Query the value of an attribute in a configuration.
   PARAMETERS : In:  pCfg - Configuration to query.
                In:  iAttrib - Attribute to query.
   RETURNS    : Queried attribute value.
   </function>
 */
EGLint CFGC_GetAttrib (KEGL_CONFIG *pCfg, EGLint iAttrib)
{
	if (pCfg!=IMG_NULL)
	{
	    for (; pCfg!=IMG_NULL; pCfg=pCfg->pNext)
	    {
	        IMG_UINT32 i;

	        for (i=0; i<pCfg->uAttribCount; i+=2)
	        {
	            if (pCfg->pAttribArray[i] == iAttrib)
	            {
	                return pCfg->pAttribArray[i+1];
	            }
	        }
	    }
	}

    return EGL_DONT_CARE;
}

⌨️ 快捷键说明

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