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

📄 resmemmgr.c

📁 MTK手机平台的MMI部分的源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
 *****************************************************************************/
U8 *mmi_frm_resmem_load_multi_image(U16 id, const mmi_frm_resmem_res_info_struct *info_array, U32 res_cnt)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U32 buf_size;
    U8 i;
    U8 *ret_ptr = 0;
    static enfb_scatter scatter[MMI_FRM_RESMEM_SCATTER_MAX_NUMBER];
    kal_bool kal_rslt;
    KAL_ADM_ID adm_id;
    MMI_BOOL ret_bool;
    mmi_frm_resmem_enum mem_type;
    const mmi_frm_resmem_res_info_struct *info;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MMI_FRM_RESMEM_CS_ENTER;

    MMI_ASSERT(id != MMI_FRM_RESMEM_INVALID_RES_ID);
    MMI_ASSERT(info_array != 0);
    MMI_ASSERT(res_cnt != 0);
    MMI_ASSERT(res_cnt < MMI_FRM_RESMEM_SCATTER_MAX_NUMBER);

    /* check whether already exist in in RAM */
    ret_ptr = mmi_frm_resmem_if_ramed(id);
    if (ret_ptr != NULL)
    {
        MMI_FRM_RESMEM_CS_LEAVE;
        return ret_ptr;
    }

    /* decide which kind of memory */
    if (mmi_frm_resmem_if_res_to_always_keep(id) == MMI_TRUE)
    {
        mem_type = MMI_FRM_RESMEM_TYPE_ALWAYS_EXIST;
        adm_id = g_mmi_frm_resmem_cntx.adm_always_id;
    }
    else
    {
        mem_type = MMI_FRM_RESMEM_TYPE_LOD_ON_DEMAND;
        adm_id = g_mmi_frm_resmem_cntx.adm_lod_id[g_mmi_frm_resmem_cntx.lod_active_screen];
    }
    MMI_ASSERT(adm_id != (KAL_ADM_ID) NULL);

    /* allocate RAM block */
    for (i = 0, info = info_array; i < res_cnt; i++, info++)
    {
        buf_size = info->size;

    #if defined(MMI_FRM_RESMEM_DEBUG_DANGLING_POINTER)
        buf_size =
            (buf_size >= MMI_FRM_RESMEM_SPOT_ICON_RESERVED_SIZE ? buf_size : MMI_FRM_RESMEM_SPOT_ICON_RESERVED_SIZE);
    #endif /* defined(MMI_FRM_RESMEM_DEBUG_DANGLING_POINTER) */ 
        ret_ptr = kal_adm_alloc(adm_id, buf_size);
        MMI_ASSERT(ret_ptr != NULL);
        /* 4-byte alignment for GDI API requirement, at least necessary for target */
        MMI_ASSERT(((U32) ret_ptr & 0x00000003) == 0);

        scatter[i].dst_addr = ret_ptr;
        scatter[i].offset = info->offset;
        scatter[i].length = info->size;

        if (mem_type == MMI_FRM_RESMEM_TYPE_LOD_ON_DEMAND)
        {
            g_mmi_frm_resmem_cntx.lod_mem_using += buf_size;
            if (g_mmi_frm_resmem_cntx.lod_mem_using > g_mmi_frm_resmem_cntx.lod_mem_max_used)
            {
                g_mmi_frm_resmem_cntx.lod_mem_max_used = g_mmi_frm_resmem_cntx.lod_mem_using;
                MMI_ASSERT(g_mmi_frm_resmem_cntx.lod_mem_max_used < MMI_FRM_RESMEM_POOL_LOD_ON_DEMAND_SIZE);
            }
        }
        else
        {
            g_mmi_frm_resmem_cntx.always_mem_using += buf_size;
            if (g_mmi_frm_resmem_cntx.always_mem_using > g_mmi_frm_resmem_cntx.always_mem_max_used)
            {
                g_mmi_frm_resmem_cntx.always_mem_max_used = g_mmi_frm_resmem_cntx.always_mem_using;
            }
            MMI_ASSERT(g_mmi_frm_resmem_cntx.always_mem_max_used < MMI_FRM_RESMEM_POOL_ALWASY_EXIST_SIZE);
        }
    }

    /* load via driver */
    kal_rslt = NFB_RES_Loadv(ENFB_CONTENT_IMAGERES, scatter, res_cnt);
    MMI_ASSERT(kal_rslt == KAL_TRUE);
    if (kal_rslt == KAL_FALSE)
    {
        for (i = 0; i < res_cnt; i++)
        {
            kal_adm_free(adm_id, scatter[i].dst_addr);
        }
        ret_ptr = NULL;
        MMI_FRM_RESMEM_CS_LEAVE;
        return NULL;
    }

    /* update managment records */
    for (i = 0, info = info_array; i < res_cnt; i++, info++)
    {
        ret_bool = mmi_frm_resmem_rec_add(mem_type, info->id, scatter[i].dst_addr, scatter[i].length);
        MMI_ASSERT(ret_bool == MMI_TRUE);

        if (id == info->id)
        {
            ret_ptr = scatter[i].dst_addr;
        }
    }

    MMI_FRM_RESMEM_CS_LEAVE;
    return ret_ptr;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_frm_resmem_reset
 * DESCRIPTION
 *  check whether the memory of the specificed resurce is existing in memory.
 * PARAMETERS
 *  flag        [IN]        Bit-wise flag: combination of MMI_FRM_RESMEM_MEMORY_LOAD_ON_DEMAND, MMI_FRM_RESMEM_MEMORY_ALWAYS_EXIST
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_frm_resmem_reset(U32 flag)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 *mem_addr;

#if defined(MMI_FRM_RESMEM_DEBUG_DANGLING_POINTER)
    S32 size;
#endif 

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MMI_FRM_RESMEM_CS_ENTER;

    if (flag & MMI_FRM_RESMEM_TYPE_LOD_ON_DEMAND)
    {

    #if defined(MMI_FRM_RESMEM_DEBUG_DANGLING_POINTER)
        /* display "X" icon for invlaid pointer usage */
        U16 i, number;
        mmi_frm_resmem_alloc_struct *rec;
	    U8 *res_src = NULL;

        number = MMI_FRM_RESMEM_LOAD_ON_DEMAND_NUMBER;
        rec = g_mmi_frm_resmem_cntx.lod_ary[g_mmi_frm_resmem_cntx.lod_active_screen];

        for (i = 0; i < number; i++, rec++)
        {
            if (rec->mem_ptr != NULL)
            {
                /* dangling pointer. fill in special icon. this icon is not in 3rd ROM */
                res_src = NULL;
                res_src = (U8*) GetImage(IMG_GLOBAL_DEFAULT);
                MMI_ASSERT(res_src != NULL);
                size = ((S32) (res_src[2]) |
                        (S32) ((S32) res_src[3] << 8) |
                        (S32) ((S32) res_src[4] << 16) | (S32) ((S32) res_src[5] << 24));
                MMI_ASSERT(MMI_FRM_RESMEM_SPOT_ICON_RESERVED_SIZE > size);
                memcpy((char*)rec->mem_ptr, res_src, size);
                rec->size = size;
            }
        }
        /* prepare the memory for next screen usage */
        g_mmi_frm_resmem_cntx.lod_active_screen++;
        g_mmi_frm_resmem_cntx.lod_active_screen %= MMI_FRM_RESMEM_LOAD_ON_DEMAND_SCREEN_NUMBER;

    #else /* defined(MMI_FRM_RESMEM_DEBUG_DANGLING_POINTER) */ 
        MMI_ASSERT(g_mmi_frm_resmem_cntx.lod_active_screen == 0);
    #endif /* defined(MMI_FRM_RESMEM_DEBUG_DANGLING_POINTER) */ 

        /* delete and create again */
        do
        {
            mem_addr = mmi_frm_resmem_rec_del_one(
                        MMI_FRM_RESMEM_TYPE_LOD_ON_DEMAND,
                        g_mmi_frm_resmem_cntx.lod_active_screen,
                        NULL);

            if (mem_addr == NULL)
            {
                break;
            }
            kal_adm_free(g_mmi_frm_resmem_cntx.adm_lod_id[g_mmi_frm_resmem_cntx.lod_active_screen], mem_addr);
        } while (1);

        kal_adm_delete(g_mmi_frm_resmem_cntx.adm_lod_id[g_mmi_frm_resmem_cntx.lod_active_screen]);
        g_mmi_frm_resmem_cntx.adm_lod_id[g_mmi_frm_resmem_cntx.lod_active_screen] = kal_adm_create(
                                                                                        g_mmi_frm_resmem_lod_pool[g_mmi_frm_resmem_cntx.lod_active_screen],
                                                                                        MMI_FRM_RESMEM_POOL_LOD_ON_DEMAND_SIZE,
                                                                                        (kal_uint32*) g_mmi_frm_resmem_mem_pool_chunk_size,
                                                                                        KAL_TRUE);
    }

    g_mmi_frm_resmem_cntx.lod_mem_using = 0;

    /* should call this to avoid incorrect displaying because of GDI cache */
    gdi_image_cache_reset();

    MMI_FRM_RESMEM_CS_LEAVE;
    return;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_frm_resmem_reg_retain
 * DESCRIPTION
 *  Register what resource to be keept without auto-clear at screen change
 *  Please note that if the resource is already allocated in LOD, it will
 *  be moved Always_Exist area.
 * PARAMETERS
 *  id      [IN]        Resource ID
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_frm_resmem_reg_retain(U16 id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U16 i;
    U8 *mem_addr = NULL, *mem_addr_dst;
    U32 size;
    MMI_BOOL ret_bool;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MMI_FRM_RESMEM_CS_ENTER;
    /* registration */
    if (mmi_frm_resmem_if_res_to_always_keep(id) == MMI_FALSE)
    {
        for (i = 0; i < MMI_FRM_RESMEM_ALWAYS_EXIST_NUMBER; i++)
        {
            if (g_mmi_frm_resmem_cntx.always_keep_ID[i] == MMI_FRM_RESMEM_INVALID_RES_ID)
            {
                g_mmi_frm_resmem_cntx.always_keep_ID[i] = id;
                break;
            }
        }
    }

    /* consider already load in memory */
    /* alreay in Always Exist area? */
    if (NULL != mmi_frm_resmem_rec_if_exist(MMI_FRM_RESMEM_TYPE_ALWAYS_EXIST, id, NULL))
    {
        /* do nothing */
        MMI_FRM_RESMEM_CS_LEAVE;
        return;
    }

    /* already in LOD area? */
    mem_addr = mmi_frm_resmem_rec_if_exist(MMI_FRM_RESMEM_TYPE_LOD_ON_DEMAND, id, &size);
    if (mem_addr != NULL)
    {
        /* move to Always Exist area */
        mem_addr_dst = kal_adm_alloc(g_mmi_frm_resmem_cntx.adm_always_id, size);
        memcpy(mem_addr_dst, mem_addr, size);
        g_mmi_frm_resmem_cntx.always_mem_using += size;
        if (g_mmi_frm_resmem_cntx.always_mem_using > g_mmi_frm_resmem_cntx.always_mem_max_used)
        {
            g_mmi_frm_resmem_cntx.always_mem_max_used = g_mmi_frm_resmem_cntx.always_mem_using;
        }
        MMI_ASSERT(g_mmi_frm_resmem_cntx.always_mem_max_used < MMI_FRM_RESMEM_POOL_ALWASY_EXIST_SIZE);
        ret_bool = mmi_frm_resmem_rec_add(MMI_FRM_RESMEM_TYPE_ALWAYS_EXIST, id, mem_addr_dst, size);
        MMI_ASSERT(ret_bool == MMI_TRUE);

    #if 0
/* under construction !*/
/* under construction !*/
/* under construction !*/
    #endif /* 0 */ 
    }
    MMI_FRM_RESMEM_CS_LEAVE;
    return;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_frm_resmem_dereg_retain
 * DESCRIPTION
 *  de-register what resource to be keept without auto-clear at screen change
 *  Please note that the calling will also clear the memory of specified resource.
 *  So the allocated pointer, if any, will not valid any more.
 * PARAMETERS
 *  id      [IN]        Resource ID
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_frm_resmem_dereg_retain(U16 id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U16 i;
    U8 *mem_addr;
    U32 size;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MMI_FRM_RESMEM_CS_ENTER;
    for (i = 0; i < MMI_FRM_RESMEM_ALWAYS_EXIST_NUMBER; i++)
    {
        if (g_mmi_frm_resmem_cntx.always_keep_ID[i] == id)
        {
            g_mmi_frm_resmem_cntx.always_keep_ID[i] = MMI_FRM_RESMEM_INVALID_RES_ID;
            break;
        }
    }

    /* clear those res de-reg always attribute */
    mem_addr = mmi_frm_resmem_rec_if_exist(MMI_FRM_RESMEM_TYPE_ALWAYS_EXIST, id, &size);
    if (mem_addr != NULL)
    {
        mmi_frm_resmem_rec_del(MMI_FRM_RESMEM_TYPE_ALWAYS_EXIST, id);
        g_mmi_frm_resmem_cntx.always_mem_using -= size;
        kal_adm_free(g_mmi_frm_resmem_cntx.adm_always_id, mem_addr);

        /* should call this to avoid incorrect displaying because of GDI cache */
        gdi_image_cache_reset();
    }

    MMI_FRM_RESMEM_CS_LEAVE;
    return;
}

/*----------------------------------------------------------------*
  String resource
 *----------------------------------------------------------------*/


/*****************************************************************************
 * FUNCTION
 *  mmi_frm_resmem_load_str_suite
 * DESCRIPTION
 *  load the specificed string resurce suite into memory.
 * PARAMETERS
 *  ptr_ary         [OUT]       Array of memory pointers to string suite
 *  offset_ary      [IN]        Array of offset positions in flash file
 *  size_ary        [IN]        Array of size in flash file
 *  ary_count       [IN]        Number of entries in offset_ary and size_ary
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_frm_resmem_load_str_suite(U8 **ptr_ary, U32 *offset_ary, U32 *size_ary, U32 ary_count)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MMI_ASSERT(ptr_ary != NULL);
    MMI_ASSERT(offset_ary != NULL);
    MMI_ASSERT(size_ary != NULL);
    MMI_ASSERT(ary_count == 2);

    /* string content part */
    NFB_RES_Load(ENFB_CONTENT_STRINGRES, g_mmi_frm_resmem_str_pool, offset_ary[0], size_ary[0]);
    g_mmi_frm_resmem_cntx.str_content = g_mmi_frm_resmem_str_pool;

    /* string map part */
    NFB_RES_Load(ENFB_CONTENT_STRINGRES, g_mmi_frm_resmem_str_pool + size_ary[0], offset_ary[1], size_ary[1]);
    g_mmi_frm_resmem_cntx.str_map = g_mmi_frm_resmem_str_pool + size_ary[0];

    ptr_ary[0] = g_mmi_frm_resmem_cntx.str_content;
    ptr_ary[1] = g_mmi_frm_resmem_cntx.str_map;

    return;
}

#endif /* defined(__MMI_RESOURCE_ENFB_SUPPORT__) */ 

⌨️ 快捷键说明

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