1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | struct vc{ struct vc_data; struct work_struct; }; 故而 struct vc_data 才是我們要的虛擬終端的定義。我們先來看看 struct vc_data 到底定義了什麼東西吧。 struct vc_data 的定義在 include/linux/console_struct.h, 定義摘錄如下,爲了不延長篇幅,有省略的部分: struct vc_data { struct tty_port port; /* Upper level data */ unsigned short vc_num; /* Console number */ unsigned int vc_cols; /* [#] Console size */ unsigned int vc_rows; 省略 ... const struct consw *vc_sw; unsigned short *vc_screenbuf; /* In-memory character/attribute buffer */ unsigned int vc_screenbuf_size; 省略 ... }; |
1 2 3 4 5 6 7 8 9 10 11 12 | vc_write(vc_data * vc, const char * string, int count){ for( ; count ; ){ /* 和当前编码有关,如果是 utf8 就以 utf8 方式解码不是 utf8 就按照 扩展的 ASCII 方式,也就是一个字节就是一个字母。*/ int glyph = next_char(vc->utf,&string,&count); int c = vc_build_attribute(vc)|(vc_glyph_mask& glyph); // 把当前设置的前景色背景色等属性结合 ,glyph 不能超过描述它的位段 ; vc->vc_screenbuf[vc->vc_pos] = c; // 写入当前位置 update_pos(); // 更新当前光标位置 } notify_redraw(vc); // 调用 cosole 这个观察者重会屏幕 } |
1 2 3 4 5 6 7 8 | notify_redraw(vc_data * vc){ for(int rows = 0 ; rows < vc->rows ; rows ++){ unsigned short * current_line = & vc->vc_screen_buf [vc_size_row * rows + vc->vc_visible_origin ] ; // 在屏幕的第 row 行第 0 列绘制一行 current_line 指向的内容共 vc->cols 个字符。 vc->vc_sw->con_puts(vc,current_line,vc->cols,0,rows); } } |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |