四. GAL分析

MiniGUI采用linux的framebuffer进行显示,打开/dev/fb0取得设备描述符,通过mmap映射将设备内存映射到用户空间,直接访问映射出来的用户空间就可以实现,通过内存写,就可以实现显示。

4.1 宏_MGGAL_FBCON的定义

static VideoBootStrap *bootstrap[] =
{
#ifdef _MGGAL_FBCON
&FBCON_bootstrap,
#endif
}
VideoBootStrap FBCON_bootstrap = {
"fbcon",
"Linux Framebuffer Console",
FB_Available,
FB_CreateDevice  //初始化结构GAL_VideoDevice *this;
//包括this->VideoInit = FB_VideoInit;,
//也包括this->SetVideoMode = FB_SetVideoMode;
};

4.2 GAL的初始化

GAL_Surface* __gal_screen;
int mg_InitGAL (void)//系统初始化GAL
{
……
if (GAL_VideoInit (engine, 0))
//即内部有上面提到的FB_VideoInit()
……
if (!(__gal_screen = GAL_SetVideoMode (w, h, depth, GAL_HWPALETTE))
//即内部有上面提到的FB_SetVideoMode()
……
}
FB_VideoInit()//打开fb,实现内存映射
{
……
console_fd = open(GAL_fbdev, O_RDWR, 0);
……
mapped_mem = mmap(NULL, mapped_memlen,
PROT_READ|PROT_WRITE, MAP_SHARED, console_fd, 0);
……
}
GAL_Surface *FB_SetVideoMode(_THIS, GAL_Surface *current,
int width, int height, int bpp, Uint32 flags)
//映射内存地址到GAL_Surface*的转变
{
……
current->flags = (GAL_FULLSCREEN|GAL_HWSURFACE);
current->w = vinfo.xres;
current->h = vinfo.yres;
current->pitch = finfo.line_length;
current->pixels = mapped_mem+mapped_offset;
……
return current;  即为__gal_screen
}

4.3设备上下文Device Context

struct tagDC
{
short DataType;  /* the data type, always be TYPE_HDC */
short DCType;    /* the dc type */
BOOL inuse;
HWND hwnd;
/* surface of this DC */
GAL_Surface* surface;//此处即初始化为__gal_screen,通过GetClientDC或者GetDC
/* background color */
gal_pixel bkcolor;
/* pen color */
gal_pixel pencolor;
/* solid brush color */
gal_pixel brushcolor;
/* text color */
gal_pixel textcolor;
int bkmode;
int tabstop;
int cExtra;     /* Character extra */
int alExtra;    /* Above line extra */
int blExtra;    /* Bellow line extra */
int mapmode;    /* mappping mode */
int ta_flags;   /* Text alignment flags */
#ifdef _MGHAVE_ADV_2DAPI
/* pen attributes */
int pen_type;
int pen_cap_style;
int pen_join_style;
unsigned int pen_width;
/* brush attributes */
int brush_type;
POINT brush_orig;
const BITMAP* brush_tile;
const STIPPLE* brush_stipple;
/* custom dash info */
int dash_offset;
const unsigned char* dash_list;
size_t dash_list_len;
#endif
PLOGFONT pLogFont;
POINT CurPenPos;
POINT CurTextPos;
POINT ViewOrig;
POINT ViewExtent;
POINT WindowOrig;
POINT WindowExtent;
/* raster operation */
int rop;
/* used by the text rendering for anti-aliasing fonts. */
gal_pixel gray_pixels [17];
/* used by the text rendering for low-pass filtering. */
gal_pixel filter_pixels [17];
GAL_PixelFormat* alpha_pixel_format;
/* pixel and line operation */
CB_COMP_SETPIXEL draw_pixel;
CB_COMP_SETHLINE draw_pixel_span;
CB_COMP_PUTHLINE draw_src_span;
DC_MOVE_TO move_to;
DC_STEP_X  step_x;
/* === context information. ============================================= */
/* DK[01/22/10]:This segment is binary compatible with _COMP_CTXT struct */
int step;
gal_uint8* cur_dst;
gal_pixel skip_pixel;
gal_pixel cur_pixel;
void * user_comp_ctxt;
/* ====================================================================== */
CLIPRECT* cur_ban;
RECT rc_output;
/* local clip region information */
CLIPRGN  lcrgn;
/* effective clip region information */
CLIPRGN  ecrgn;
/* device rect */
BOOL bIsClient;
RECT DevRC;
PGCRINFO pGCRInfo;
unsigned int oldage;
CB_BITMAP_SCALER_FUNC bitmap_scaler;
};

static void dc_InitDC (PDC pdc, HWND hWnd, BOOL bIsClient)

该函数负责初始化DC的各个成员变量,具体如下所示:

static void dc_InitDC (PDC pdc, HWND hWnd, BOOL bIsClient)
{
……
pdc->bkcolor = GAL_MapRGB (pdc->surface->format, 0xFF, 0xFF, 0xFF);
pdc->bkmode = 0;
pdc->pencolor = GAL_MapRGB (pdc->surface->format, 0x00, 0x00, 0x00);
pdc->brushcolor = GAL_MapRGB (pdc->surface->format, 0xFF, 0xFF, 0xFF);
pdc->textcolor = GAL_MapRGB (pdc->surface->format, 0x00, 0x00, 0x00);
if (!(pdc->pLogFont = GetWindowFont (hWnd)))
pdc->pLogFont = GetSystemFont (SYSLOGFONT_WCHAR_DEF);
pdc->tabstop = 8;
pdc->CurTextPos.x = pdc->CurTextPos.y = 0;
pdc->cExtra = pdc->alExtra = pdc->blExtra = 0;
pdc->mapmode = MM_TEXT;
pdc->ta_flags = TA_LEFT | TA_TOP | TA_NOUPDATECP;
pdc->ViewOrig.x = pdc->ViewOrig.y = 0;
pdc->ViewExtent.x = pdc->ViewExtent.y = 1;
pdc->WindowOrig.x = pdc->WindowOrig.y = 0;
pdc->WindowExtent.x = pdc->WindowExtent.y = 1;
…………
pdc->draw_pixel = draw_pixel_ops [pdc->rop]
[pdc->surface->format->BytesPerPixel - 1];
pdc->draw_pixel_span = draw_pixel_span_ops [pdc->rop]
[pdc->surface->format->BytesPerPixel - 1];
pdc->draw_src_span = draw_src_span_ops [pdc->rop]
[pdc->surface->format->BytesPerPixel - 1];
pdc->cur_dst = (BYTE*)pdc->surface->pixels + pdc->surface->pitch * pdc->DevRC.top
+ pdc->surface->format->BytesPerPixel * pdc->DevRC.left;
pdc->move_to = move_to_ops [pdc->surface->format->BytesPerPixel - 1];
pdc->step_x = step_x_ops [pdc->surface->format->BytesPerPixel - 1];
pdc->alpha_pixel_format = NULL;
SetBitmapScalerType((HDC)pdc, BITMAP_SCALER_DDA);
…………
}

4.4 窗口的绘制风格

目前的窗口的绘制风格有classic, flat, skin, 该结构的功能实现各个小的窗口部分的绘制,组合起来即成为控件,以 classic风格的代码为例:

WINDOW_ELEMENT_RENDERER __mg_wnd_rdr_classic = {
"classic",
init,
deinit,
calc_3dbox_color,
draw_3dbox,
draw_radio,
draw_checkbox,
draw_checkmark,
draw_arrow,
draw_fold,
draw_focus_frame,
draw_normal_item,
draw_hilite_item,
draw_disabled_item,
draw_significant_item,
draw_push_button,
draw_radio_button,
draw_check_button,
draw_border,
draw_caption,
draw_caption_button,
draw_scrollbar,
calc_trackbar_rect,
draw_trackbar,
calc_we_area,
calc_we_metrics,
hit_test,
NULL,
NULL,
calc_thumb_area,
disabled_text_out,
draw_tab,
draw_progress,
draw_header,
NULL,
NULL,
erase_bkgnd,
draw_normal_menu_item,
draw_hilite_menu_item,
draw_disabled_menu_item,
};

MiniGUI原理分析GAL相关推荐

  1. java signature 性能_Java常见bean mapper的性能及原理分析

    背景 在分层的代码架构中,层与层之间的对象避免不了要做很多转换.赋值等操作,这些操作重复且繁琐,于是乎催生出很多工具来优雅,高效地完成这个操作,有BeanUtils.BeanCopier.Dozer. ...

  2. Select函数实现原理分析

    转载自 http://blog.chinaunix.net/uid-20643761-id-1594860.html select需要驱动程序的支持,驱动程序实现fops内的poll函数.select ...

  3. spring ioc原理分析

    spring ioc原理分析 spring ioc 的概念 简单工厂方法 spirng ioc实现原理 spring ioc的概念 ioc: 控制反转 将对象的创建由spring管理.比如,我们以前用 ...

  4. 一次 SQL 查询优化原理分析(900W+ 数据,从 17s 到 300ms)

    点击上方"方志朋",选择"设为星标" 回复"666"获取新整理的面试文章 来源:Muscleape jianshu.com/p/0768eb ...

  5. 原理分析_变色近视眼镜原理分析

    随着眼镜的发展,眼镜的外型变得越来越好看,并且眼镜的颜色也变得多姿多彩,让佩戴眼镜的你变得越来越时尚.变色近视眼镜就是由此产生的新型眼镜.变色镜可以随着阳光的强弱变换不同的色彩. 变色眼镜的原理分析 ...

  6. jieba分词_从语言模型原理分析如何jieba更细粒度的分词

    jieba分词是作中文分词常用的一种工具,之前也记录过源码及原理学习.但有的时候发现分词的结果并不是自己最想要的.比如分词"重庆邮电大学",使用精确模式+HMM分词结果是[&quo ...

  7. EJB调用原理分析 (飞茂EJB)

    EJB调用原理分析 EJB调用原理分析 作者:robbin (MSN:robbin_fan AT hotmail DOT com) 版权声明:本文严禁转载,如有转载请求,请和作者联系 一个远程对象至少 ...

  8. 深入掌握Java技术 EJB调用原理分析

      深入掌握Java技术 EJB调用原理分析     一个远程对象至少要包括4个class文件:远程对象:远程对象的接口:实现远程接口的对象的stub:对象的skeleton这4个class文件. 在 ...

  9. 神经网络(NN)+反向传播算法(Backpropagation/BP)+交叉熵+softmax原理分析

    神经网络如何利用反向传播算法进行参数更新,加入交叉熵和softmax又会如何变化? 其中的数学原理分析:请点击这里. 转载于:https://www.cnblogs.com/code-wangjun/ ...

最新文章

  1. javaMe开发按钮
  2. 模型参数优化(三):模拟退火
  3. 2014 ACM/ICPC Asia Regional Xi'an Online
  4. mac python运行按哪个键_#mac python如何使用教程#怎么在mac终端运行python程序
  5. Linux的网卡由eth0变成了eth1,如何修复
  6. 关于solaris中 crontab -e 出现数字0的解决办法
  7. js 操作frameset frame 对象
  8. C#中的Attributes的用法
  9. 2021 年百度之星·程序设计大赛 - 初赛三(部分)
  10. 优思学院|IE的7大手法・8大浪费
  11. 离散题目16——自反闭包
  12. Spark程序编译报错error: object apache is not a member of package org
  13. LaTex Verbatim 环境下使用数学符号
  14. Android课题研究的主要观点,课题研究的主要内容
  15. R 语言中1 和1L的区别
  16. 背景信息在网上轻松群发短信程序
  17. android lcd,国产安卓机:LCD屏幕,正式再见
  18. ITK-SANP 使用指南
  19. 同字母异序词 python_Python初学者必学的20个重要技巧
  20. coalesce 函数详解与学习记录

热门文章

  1. SpringBoot实现阿里云短信服务
  2. H5 六边形消除游戏开发 1
  3. 正向代理与反向代理通俗版解释
  4. sapmto生产模式配置及操作详解_PP: 混合生产方式(MTO与MTS为例)
  5. inner join 和 outer join 的区别
  6. CSS3篮球场热力区域图
  7. 记一次cnpm install的各种报错深刻记忆
  8. 【Linux系统】第9节 linux系统中用户分类以及用户与组属性的修改示例
  9. Flutter 最佳扫码插件
  10. 2022-08-22 第六小组 瞒春 学习笔记