linux应用程序_1_文本浏览器_4_display_1_disp_manager

本文详细介绍了在Linux环境下,一种抽象显示管理器的设计与实现。该管理器通过定义通用显示结构体,支持设备初始化、像素显示、屏幕清理等功能,并利用链表注册与管理多种显示设备。文中还提供了关键代码示例,包括显示设备的注册、获取及初始化过程。

linux应用程序_1_文本浏览器_4_display_1_disp_manager

 

抽象显示结构体依据:

应含有设备名字、分辨率、像素深度

应具备设备初始化、显示像素、清屏等功能

应具有链表,同其他结构体建立联系

 

 

 

抽象出显示结构体

typedef struct DispOpr {
	char *pcName;
	int iXres;
	int iYres;
	int iBpp;
	int (*DeviceInit)(void);
	int (*DeviceExit)(void);
	int (*ShowPixel)(int iPenX, int iPenY, unsigned int dwColor);
	int (*CleanScreen)(unsigned int dwBackColor);
	struct DispOpr *ptNext;
}T_DispOpr, *PT_DispOpr;

 

注册:

将显示结构体存入显示链表

int RegisterDispOpr(PT_DispOpr ptDispOpr)
{
	PT_DispOpr ptDispOprTmp;

	if(!g_ptDispOpr)
	{
		g_ptDispOpr = ptDispOpr;
		return 0;
	}

	ptDispOprTmp = g_ptDispOpr;

	while(ptDispOprTmp->ptNext)
	{
		ptDispOprTmp = ptDispOprTmp->ptNext;
	}
	ptDispOprTmp->ptNext = ptDispOpr;
	ptDispOpr->ptNext = NULL;

	DBG_PRINT("display:\r\n");
	ptDispOprTmp = g_ptDispOpr->ptNext;
	
	DBG_PRINT("%s,%s\r\n",g_ptDispOpr->pcName,ptDispOprTmp->pcName);

	return 0;
}

 

获取显示结构体:

根据名字取出目前支持的显示结构体

PT_DispOpr GetDispOpr(char *pcName)
{
	PT_DispOpr ptDispOprTmp = g_ptDispOpr;

	
	while(ptDispOprTmp)
	{
		if(strcmp(ptDispOprTmp->pcName, pcName) == 0)
		{
			return ptDispOprTmp;
		}
		ptDispOprTmp = ptDispOprTmp->ptNext;
	}
	return NULL;
}

 

显示初始化:

注册各个显示结构体

int DisplaysInit(void)
{
	int iError = 1;
	
	iError  = FBInit();
	
#ifdef 	ONPC
	iError |= OnpucInit();
#endif

	return iError;
}

退出显示:

对于不同设备有不同操作

对LCD    :这里不做任何事情(可以关闭LCD控制器、电源等)

对控制台:需要从图片模式切换到文本模式

void DisplayExit(void)
{
	PT_DispOpr ptDispOprTmp = g_ptDispOpr;
	
	while(ptDispOprTmp)
	{		
		if(ptDispOprTmp->DeviceExit)
		{
			ptDispOprTmp->DeviceExit();
		}
		ptDispOprTmp = ptDispOprTmp->ptNext;
	}	
}

 

 

 

完整代码:

disp_manager.h

#ifndef __DISP_MANAGER_H
#define __DISP_MANAGER_H


typedef struct DispOpr {
	char *pcName;
	int iXres;
	int iYres;
	int iBpp;
	int (*DeviceInit)(void);
	int (*DeviceExit)(void);
	int (*ShowPixel)(int iPenX, int iPenY, unsigned int dwColor);
	int (*CleanScreen)(unsigned int dwBackColor);
	struct DispOpr *ptNext;
}T_DispOpr, *PT_DispOpr;

int FBInit(void);
int OnpucInit(void);


int RegisterDispOpr(PT_DispOpr ptDispOpr);
PT_DispOpr GetDispOpr(char *pcName);
void ShowDispOpr(void);
int DisplaysInit(void);
void DisplayExit(void);

#endif

 

disp_manager.c

#include <config.h>
#include <disp_manager.h>
#include <string.h>
#include <stdio.h>

PT_DispOpr g_ptDispOpr;


int RegisterDispOpr(PT_DispOpr ptDispOpr)
{
	PT_DispOpr ptDispOprTmp;

	if(!g_ptDispOpr)
	{
		g_ptDispOpr = ptDispOpr;
		return 0;
	}

	ptDispOprTmp = g_ptDispOpr;

	while(ptDispOprTmp->ptNext)
	{
		ptDispOprTmp = ptDispOprTmp->ptNext;
	}
	ptDispOprTmp->ptNext = ptDispOpr;
	ptDispOpr->ptNext = NULL;

	DBG_PRINT("display:\r\n");
	ptDispOprTmp = g_ptDispOpr->ptNext;
	
	DBG_PRINT("%s,%s\r\n",g_ptDispOpr->pcName,ptDispOprTmp->pcName);

	return 0;
}

PT_DispOpr GetDispOpr(char *pcName)
{
	PT_DispOpr ptDispOprTmp = g_ptDispOpr;

	
	while(ptDispOprTmp)
	{
		if(strcmp(ptDispOprTmp->pcName, pcName) == 0)
		{
			return ptDispOprTmp;
		}
		ptDispOprTmp = ptDispOprTmp->ptNext;
	}
	return NULL;
}

void ShowDispOpr(void)
{
	PT_DispOpr ptDispOprTmp = g_ptDispOpr;
	int iCnt = 0;

	printf("\r\n");	
	printf("supported display:\r\n");
	while(ptDispOprTmp)
	{
		printf("%02d : %s\r\n",++iCnt, ptDispOprTmp->pcName);
		ptDispOprTmp = ptDispOprTmp->ptNext;
	}
}

int DisplaysInit(void)
{
	int iError = 1;
	
	iError  = FBInit();

#ifdef ONPC
	iError |= OnpucInit();
#endif

	return iError;
}

void DisplayExit(void)
{
	PT_DispOpr ptDispOprTmp = g_ptDispOpr;
	
	while(ptDispOprTmp)
	{		
		if(ptDispOprTmp->DeviceExit)
		{
			ptDispOprTmp->DeviceExit();
		}
		ptDispOprTmp = ptDispOprTmp->ptNext;
	}	
}

 

 

 

 

 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值