Input abstraction layer and NativeEngine implementation 1

Source: Internet
Author: User
Article title: input abstraction layer and NativeEngine implementation 1. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
   1 Introduction
  
In the development of MiniGUI 0.3.xx, we introduced the concepts of Graphics and Input Abstract Layer, GAL and IAL. The concept of the abstraction layer is similar to that of the Linux kernel virtual file system. It defines a set of abstract interfaces that do not depend on any special hardware. all top-level graphic operations and input processing are built on the abstract interfaces. The underlying code used to implement this abstract interface is called "graphics engine" or "input engine", similar to the driver in the operating system. This is actually an object-oriented program structure. Using GAL and IAL, MiniGUI can run on many existing graphic function libraries, such as SVGALib and LibGGI. MiniGUI can be easily transplanted to other POSIX systems, just implement a new graphics engine based on our abstract layer interface. For example, on a Linux-based system, we can build a general MiniGUI graphics engine based on the Linux FrameBuffer driver. In fact, the Native Engine included in MiniGUI 1.0.00 is a graphics Engine built on FrameBuffer. Generally, the Linux-based embedded system provides FrameBuffer support, so that the private graphics engine can run on a general PC or a specific embedded system.
  
Compared with graphics, it is more important to separate the underlying input of MiniGUI from the upper layer. In a Linux-based embedded system, the graphics engine can be obtained through FrameBuffer, but there is no unified interface for processing input devices. In PC, we usually use the keyboard and mouse, while in embedded systems, there may be only a touch screen and a few keys. In this case, it is especially important to provide an abstract input layer.
  
This article introduces the GAL and IAL interfaces of MiniGUI, and introduces the implementation of private graphics engines and input engines in specific embedded systems.
  
   2. GAL and IAL definitions of MiniGUI
  
The structure of GAL and IAL is similar. We use GAL as an example to describe the structure of the MiniGUI GAL and IAL abstraction layers.
  
2.1 GAL and graphics engine
See figure 1. The system maintains a registered graph engine array that stores the pointer of each graph engine data structure. The system uses a pointer to save the currently used graphics engine. Generally, there are at least two graphics engines in the system. one is the "dumb" graphics engine, which does not output any actual graphics. The other is the actual graphics engine, for example, LibGGI, SVGALib, or Native Engine. The data structure of each graphic engine defines some information of the graphic engine, such as identifiers and attributes. More importantly, it implements the interfaces defined by GAL, including initialization and termination, graphic context management, painting point processing function, painting line processing function, rectangular box filling function, and color palette function.
  
   GAL and graphics engine
If the graphics hardware used in a specific project is special, the existing graphics engine does not support it. In this case, we can implement our own graphics engine based on the interface defined by GAL, and specify MiniGUI to use this private graphics engine. This software technology is actually a concrete embodiment of object-oriented polymorphism.
  
Using GAL and IAL greatly improves the portability of MiniGUI and makes program development and debugging easier. We can develop and debug our own MiniGUI program on X Window. by re-compiling, we can run the MiniGUI application on a special embedded hardware platform.
  
In code implementation, MiniGUI uses the GFX data structure to represent the graphics engine, as shown in listing 1.
  
Figure 1 graphical engine structure (src/include/gal. h) in MiniGUI)
  
55 typedef struct tagGFX
56 {
57 char * id;
58
59 // Initialization and termination
60 BOOL (* initgfx) (struct tagGFX * gfx );
61 void (* termgfx) (struct tagGFX * gfx );
62
63 // Phisical graphics context
64 GAL_GC phygc;
65 int bytes_per_phypixel;
66 int bits_per_phypixel;
67 int width_phygc;
68 int height_phygc;
69 int colors_phygc;
70 BOOL grayscale_screen;
71
72 // GC properties
73 int (* bytesperpixel) (GAL_GC gc );
74 int (* bitsperpixel) (GAL_GC gc );
75 int (* width) (GAL_GC gc );
76 int (* height) (GAL_GC gc );
77 int (* colors) (GAL_GC gc );
78
79 // Allocation and release of graphics context
80 int (* allocategc) (GAL_GC gc, int width, int height, int depth,
81 GAL_GC * newgc );
82 void (* freegc) (GAL_GC gc );
83 void (* setgc) (GAL_GC gc );
84
85 // Clipping of graphics context
86 void (* enableclipping) (GAL_GC gc );
87 void (* disableclipping) (GAL_GC gc );
88 int (* setclipping) (GAL_GC gc, int x1, int y1, int x2, int y2 );
89 int (* getclipping) (GAL_GC gc, int * x1, int * y1, int * x2, int * y2 );
90
91 // Background and foreground colors
92 int (* getbgcolor) (GAL_GC gc, gal_pixel * color );
93 int (* setbgcolor) (GAL_GC gc, gal_pixel color );
94 int (* getfgcolor) (GAL_GC gc, gal_pixel * color );
95 int (* setfgcolor) (GAL_GC gc, gal_pixel color );
96
97 // Convertion between gal_color and gal_pixel
98 gal_pixel (* mapcolor) (GAL_GC gc, gal_color * color );
99 int (* unmappixel) (GAL_GC gc, gal_pixel pixel, gal_color * color );
100 int (* packcolors) (GAL_GC gc, void * buf, gal_color * colors, int len );
101 int (* unpackpixels) (GAL_GC gc, void * buf, gal_color * colors, int len );
102
103 // Palette operations
104 int (* getpalette) (GAL_GC gc, int s, int len, gal_color * cmap );
105 int (* setpalette) (GAL_GC gc, int s, int len, gal_color * cmap );
106 int (* setcolorfulpalette) (GAL_GC gc );
107
108 // Box operations
109 size_t (* boxsize) (GAL_GC gc, int w, int h );
110 int (* fillbox) (GAL_GC gc, int x, int y, int w, int h,
111 gal_pixel pixel );
112 int (* putbox) (GAL_GC gc, int x, int y, int w, int h, void * buf );
113 int (* getbox) (GAL_GC gc, int x, int y, int w, int h, void * buf );
114 int (* putboxmask) (GAL_GC gc, int x, int y, int w, int h, void * buf, gal_pixel cxx );
115 int (* putboxpart) (GAL_GC gc, int x, int y, int w, int h, int bw,
116 int bh, void * buf, int xo, int yo );
117 int (* putboxwithop) (GAL_GC gc, int x, int y, int w, int h,
118 void * buf, int raster_op );
119 int (* scalebox) (GAL_GC gc, int sw, int sh, void * srcbuf,
120 int dw, int dh, void * dstbuf );
121
122 int (* copybox) (GAL_GC gc, int x, int y, int w, int h, int nx, int ny );
123 int (* Crossbits) (GAL_GC src, int sx, int sy, int sw, int sh,
124 GAL_GC dst, int dx, int dy );
125
126 // Horizontal line operaions
127 int (* drawhline) (GAL_GC gc, int x, int y, int w, gal_pixel pixel );
128 int (* puthline) (GAL_GC gc, int x, int y, int w, void * buf );
129 int (* gethline) (GAL_GC gc, int x, int y, int w, void * buf );
130
131 // Vertical line operations
132 int (* drawvline) (GAL_GC gc, int x, int y, int h, gal_pixel pixel );
133 int (* putvline) (GAL_GC gc, int x, int y, int h, void * buf );
134 int (* getvline) (GAL_GC gc, int x, int y, int h, void * buf );
135
136 // Pixel operations
137 int (* drawpixel) (GAL_GC gc, int x, int y, gal_pixel pixel );
138 int (* putpixel) (GAL_GC gc, int x, int y, gal_pixel color );
139 int (* getpixel) (GAL_GC gc, int x, int y, gal_pixel * color );
140
141 // Other drawing
142 int (* circle) (GAL_GC gc, int x, int y, int r, gal_pixel pixel );
143 int (* line) (GAL_GC gc, int x1, int y1, int x2, int y2,
144 gal_pixel pixel );
145 int (* rectangle) (GAL_GC gc, int l, int t, int r, int B,
146 gal_pixel pixel );
147
148 // Simple Character output
149 int (* putchar) (GAL_GC gc, int x, int y, char c );
150 int (* putstr) (GAL_GC gc, int x, int y, const char * str );
151 int (*
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.