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

📄 frambufmgr.c

📁 Samsung公司S3C6400芯片的BSP源码包
💻 C
字号:
/*
 * Project Name MFC DRIVER 
 * Copyright  2007 Samsung Electronics Co, Ltd. All Rights Reserved. 
 *
 * This software is the confidential and proprietary information
 * of Samsung Electronics  ("Confidential Information").   
 * you shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement
 * you entered into with Samsung Electronics 
 *
 * This source file is for managing the Frame buffer.
 *
 * @name MFC DRIVER MODULE Module (FramBufMgr.c)
 * @author name(email address)
 * @date 03-28-07
 */

#include "MfcMemory.h"
#include "FramBufMgr.h"
#include "MfcTypes.h"
#include "LogMsg.h"


// The size in bytes of the BUF_SEGMENT.
// The buffers are fragemented into the segment unit of this size.
#define BUF_SEGMENT_SIZE	1024


typedef struct
{
	unsigned char *pBaseAddr;
	int            idx_commit;
} SEGMENT_INFO;


typedef struct
{
	int index_base_seg;
	int num_segs;
} COMMIT_INFO;


static SEGMENT_INFO  *_p_segment_info = NULL;
static COMMIT_INFO   *_p_commit_info  = NULL;


static unsigned char *_pBufferBase  = NULL;
static int            _nBufferSize  = 0;
static int            _nNumSegs		= 0;


//
// int FramBufMgrInit(unsigned char *pBufBase, int nBufSize)
//
// Description
//		This function initializes the MfcFramBufMgr(Buffer Segment Manager)
// Parameters
//		pBufBase [IN]: pointer to the buffer which will be managed by this MfcFramBufMgr functions.
//		nBufSize [IN]: buffer size in bytes
// Return Value
//		1 : Success
//		0 : Fail
//
BOOL FramBufMgrInit(unsigned char *pBufBase, int nBufSize)
{
	int   i;

	// check parameters
	if (pBufBase == NULL || nBufSize == 0)
		return FALSE;


	// 捞固 檬扁拳啊 登绢 乐绊
	// (1) 檬扁拳 搬苞客 涝仿 颇扼固磐 蔼捞 鞍促搁
	//     角荐肺 捞 窃荐啊 滴 锅 龋免等 巴捞骨肺 弊成 官肺 1阑 府畔
	// (2) 鞍瘤 臼促搁, 
	//     Finalize 矫挪 饶, 促矫 犁 檬扁拳 茄促. 
	if ((_pBufferBase != NULL) && (_nBufferSize != 0)) {
		if ((pBufBase == _pBufferBase) && (nBufSize == _nBufferSize))
			return TRUE;

		FramBufMgrFinal();
	}


	_pBufferBase = pBufBase;
	_nBufferSize = nBufSize;
	_nNumSegs = nBufSize / BUF_SEGMENT_SIZE;

	_p_segment_info = (SEGMENT_INFO *) Mem_Alloc(_nNumSegs * sizeof(SEGMENT_INFO));
	for (i=0; i<_nNumSegs; i++) {
		_p_segment_info[i].pBaseAddr   = pBufBase  +  (i * BUF_SEGMENT_SIZE);
		_p_segment_info[i].idx_commit  = 0;
	}

	_p_commit_info  = (COMMIT_INFO *) Mem_Alloc(_nNumSegs * sizeof(COMMIT_INFO));
	for (i=0; i<_nNumSegs; i++) {
		_p_commit_info[i].index_base_seg  = -1;
		_p_commit_info[i].num_segs        = 0;
	}


	return TRUE;
}


//
// void FramBufMgrFinal()
//
// Description
//		This function finalizes the MfcFramBufMgr(Buffer Segment Manager)
// Parameters
//		None
// Return Value
//		None
//
void FramBufMgrFinal()
{
	if (_p_segment_info != NULL) {
		Mem_Free(_p_segment_info);
		_p_segment_info = NULL;
	}

	if (_p_commit_info != NULL) {
		Mem_Free(_p_commit_info);
		_p_commit_info = NULL;
	}


	_pBufferBase  = NULL;
	_nBufferSize  = 0;
	_nNumSegs       = 0;
}


//
// unsigned char *FramBufMgrCommit(int idx_commit, int commit_size)
//
// Description
//		This function requests the commit for commit_size buffer to be reserved.
// Parameters
//		idx_commit  [IN]: pointer to the buffer which will be managed by this MfcFramBufMgr functions.
//		commit_size [IN]: commit size in bytes
// Return Value
//		NULL : Failed to commit (Wrong parameters, commit_size too big, and so on.)
//		Otherwise it returns the pointer which was committed.
//
unsigned char *FramBufMgrCommit(int idx_commit, int commit_size)
{
	int  i, j;

	int  num_fram_buf_seg;		// 鞘夸茄 buffer甫 困茄 SEGMENT 俺荐 


	// 檬扁拳 咯何 眉农 
	if (_p_segment_info == NULL || _p_commit_info == NULL) {
		return NULL;
	}

	// check parameters
	if (idx_commit < 0 || idx_commit >= _nNumSegs)
		return NULL;
	if (commit_size <= 0 || commit_size > _nBufferSize)
		return NULL;

	// COMMIT_INFO 硅凯俊辑 idx_commit 锅掳 蔼捞
	// free牢瘤 捞固 commit 登菌绰瘤 犬牢茄促. 
	if (_p_commit_info[idx_commit].index_base_seg != -1)
		return NULL;


	// 鞘夸茄 FRAM_BUF_SEGMENT 俺荐甫 备茄促. 
	// Instance FRAM_BUF狼 鞘夸茄 农扁啊 FRAM_BUF_SEGMENT_SIZE 窜困甫 炼陛捞扼档 逞绢啊搁
	// FRAM_BUF_SEGMENT啊 烹掳肺 窍唱 歹 鞘夸窍霸 等促.
	if ((commit_size % BUF_SEGMENT_SIZE) == 0)
		num_fram_buf_seg = commit_size / BUF_SEGMENT_SIZE;
	else
		num_fram_buf_seg = (commit_size / BUF_SEGMENT_SIZE)  +  1;

	for (i=0; i<(_nNumSegs - num_fram_buf_seg); i++) {
		// SEGMENT 吝俊 commit 救等 巴捞 乐阑 锭鳖瘤 逻 八祸 
		if (_p_segment_info[i].idx_commit != 0)
			continue;

		for (j=0; j<num_fram_buf_seg; j++) {
			if (_p_segment_info[i+j].idx_commit != 0)
				break;
		}

		// j=0 ~ num_fram_buf_seg 鳖瘤 commit等 SEGMENT啊 绝促搁 
		// 捞 何盒阑 commit茄促. 
		if (j == num_fram_buf_seg) {

			for (j=0; j<num_fram_buf_seg; j++) {
				_p_segment_info[i+j].idx_commit = 1;
			}

			_p_commit_info[idx_commit].index_base_seg  = i;
			_p_commit_info[idx_commit].num_segs        = num_fram_buf_seg;

			return _p_segment_info[i].pBaseAddr;
		}
		else
		{
			// instance buffer甸 荤捞俊 后傍埃捞 惯积沁阑锭, 肚促弗 instance甫 困秦 滚欺甫 且寸且
			// 农扁啊 登瘤 臼栏搁 弊 后傍埃阑 扒呈顿绊, 后 滚欺甫 茫绰促. 
			i = i + j - 1;
		}
	}

	return NULL;
}


//
// void FramBufMgrFree(int idx_commit)
//
// Description
//		This function frees the committed region of buffer.
// Parameters
//		idx_commit  [IN]: pointer to the buffer which will be managed by this MfcFramBufMgr functions.
// Return Value
//		None
//
void FramBufMgrFree(int idx_commit)
{
	int  i;

	int  index_base_seg;		// 秦寸 commmit 何盒狼 base segment狼 index
	int  num_fram_buf_seg;		// 鞘夸茄 buffer甫 困茄 SEGMENT狼 俺荐 


	// 檬扁拳 咯何 眉农 
	if (_p_segment_info == NULL || _p_commit_info == NULL)
		return;

	// check parameters
	if (idx_commit < 0 || idx_commit >= _nNumSegs)
		return;

	// COMMIT_INFO 硅凯俊辑 idx_commit 锅掳 蔼捞 
	// free牢瘤 捞固 commit 登菌绰瘤 犬牢茄促 
	if (_p_commit_info[idx_commit].index_base_seg == -1)
		return;


	index_base_seg    =  _p_commit_info[idx_commit].index_base_seg;
	num_fram_buf_seg  =  _p_commit_info[idx_commit].num_segs;

	for (i=0; i<num_fram_buf_seg; i++) {
		_p_segment_info[index_base_seg + i].idx_commit = 0;
	}


	_p_commit_info[idx_commit].index_base_seg  =  -1;
	_p_commit_info[idx_commit].num_segs        =  0;

}




//
// unsigned char *FramBufMgrGetBuf(int idx_commit)
//
// Description
//		This function obtains the committed buffer of 'idx_commit'.
// Parameters
//		idx_commit  [IN]: commit index of the buffer which will be obtained
// Return Value
//		NULL : Failed to get the indicated buffer (Wrong parameters, not committed, and so on.)
//		Otherwise it returns the pointer which was committed.
//
unsigned char *FramBufMgrGetBuf(int idx_commit)
{
	int index_base_seg;

	// 檬扁拳 咯何 眉农 
	if (_p_segment_info == NULL || _p_commit_info == NULL)
		return NULL;

	// check parameters
	if (idx_commit < 0 || idx_commit >= _nNumSegs)
		return NULL;

	// COMMIT_INFO 硅凯俊辑 idx_commit 锅掳 蔼捞 
	// free牢瘤 捞固 commit 登菌绰瘤 犬牢茄促. 
	if (_p_commit_info[idx_commit].index_base_seg == -1)
		return NULL;


	index_base_seg  =  _p_commit_info[idx_commit].index_base_seg;

	return _p_segment_info[index_base_seg].pBaseAddr;
}

//
// int FramBufMgrGetBufSize(int idx_commit)
//
// Description
//		This function obtains the size of the committed buffer of 'idx_commit'.
// Parameters
//		idx_commit  [IN]: commit index of the buffer which will be obtained
// Return Value
//		0 : Failed to get the size of indicated buffer (Wrong parameters, not committed, and so on.)
//		Otherwise it returns the size of the buffer.
//		Note that the size is multiples of the BUF_SEGMENT_SIZE.
//
int FramBufMgrGetBufSize(int idx_commit)
{
	// 檬扁拳 咯何 眉农 
	if (_p_segment_info == NULL || _p_commit_info == NULL)
		return 0;

	// check parameters
	if (idx_commit < 0 || idx_commit >= _nNumSegs)
		return 0;

	// COMMIT_INFO 硅凯俊辑 idx_commit 锅掳 蔼捞 
	// free牢瘤 捞固 commit 登菌绰瘤 犬牢茄促. 
	if (_p_commit_info[idx_commit].index_base_seg == -1)
		return 0;


	return (_p_commit_info[idx_commit].num_segs * BUF_SEGMENT_SIZE);
}


//
// void FramBufMgrPrintCommitInfo()
//
// Description
//		This function prints the commited information on the console screen.
// Parameters
//		None
// Return Value
//		None
//
void FramBufMgrPrintCommitInfo()
{
	int  i;

	// 檬扁拳 咯何 眉农 
	if (_p_segment_info == NULL || _p_commit_info == NULL) {
		LOG_MSG(LOG_TRACE, "FramBufMgrPrintCommitInfo", "\n The FramBufMgr is not initialized.\n");
		return;
	}


	for (i=0; i<_nNumSegs; i++) {
		if (_p_commit_info[i].index_base_seg != -1)  {
			LOG_MSG(LOG_TRACE, "FramBufMgrPrintCommitInfo", "\n\nCOMMIT INDEX = [%03d], BASE_SEG_IDX = %d", i, _p_commit_info[i].index_base_seg);
			LOG_MSG(LOG_TRACE, "FramBufMgrPrintCommitInfo", "\nCOMMIT INDEX = [%03d], NUM OF SEGS  = %d", i, _p_commit_info[i].num_segs);
		}
	}
}

⌨️ 快捷键说明

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