This article is actually not original. I read the documents of my predecessors and added some of my own understandings. At the end of the article, I will provide some good materials.
If necessary, we can use qvfb to develop our own GUI graphics engine. qvfb is an application that simulates the/dev/fb0 framebuffer display mode and uses shared memory, external programs, such as MiniGUI, transmit data to the shared memory created by qvfb, and then qvfb refreshes the data to the qvfb software interface. Note that qvfb is not a strictly framebuffer, after the MiniGUI sends data to the shared memory of qvfb, qvfb does not immediately reflect the modified data to the qvfb software interface,
Instead, an external program is required, such as MiniGUI. First, set the update rectangle failure range under the shared space struct created by qvfb, that is, (left, top) and (right, bottom ),
Set the dirty control word under the shared space struct created by qvfb to 1,
In this way, after qvfb detects that the drity flag is 1, it will take out the description range of the rectangle to be refreshed in update, and then specify the update
The data in the interval is refreshed to the qvfb interface. Then, qvfb sets the drity flag of the shared space to 0, and sets update to invalid () and (-1,-1)
Qvfb has a simple principle. It creates a system
V shared memory. You only need to put the image to be displayed in the shared memory in qvfb in pixel format.
To connect to the System V shared memory, follow these steps:
1. Get the key through ftok
2. Use shmget to get shmid
3. Use shmat to connect to the shared memory
It should be noted that the key generation needs to pass in a file name agreed by both parties to ftok, for qvfb screen device, this file is/tmp/. qtvfb_mouse-0.
The shared memory created by qvfb contains a private data header, which indicates the pixel format and width. The header structure is defined as follows:
typedef struct tagrect_t{ int left; int top; int right; int bottom;}RECT_T;typedef struct tagQVFbHeader{ int width;//the width of qvfb screen device int height;//the height of qvfb screen device int depth;//the depth of qvfb screen device int linestep;//length of a line in bytes int dataoffset;//data in shared memory offset RECT_T update;//the area to be updated unsigned char dirty;//update flags,when dirty=1,the area will be updated int numcols;//number of colors unsigned int clut[256];//color index}QVFBHEADER;
In the development process, I think it is important.
1. Procedures
The specification here is not only the specification above the style, but also the legality verification and Memory leakage.
The following code verifies the returned results of the program. The code is robust.
if(dis_qvfb_init()){printf("qvfb init error!\n");return -1;}/*open input device */if(open_inputdev()){printf("open input device error!\n");return -2;}
Before the main () function ends, we must close the opened device file.
dis_qvfb_exit();close_inputdev();
2. In my main function, there is a while (1) function, which constantly reads mouse information from the mouse file and then displays it on the screen device of qvfb.
During GUI development, there is usually a process like this:
A. Write Data to the data address;
B. Update "framebuffer"
If an application such as constantly displaying mouse information is used, you must clear the area before writing data.
There are relatively few materials in this regard. Here we connect the original addresses of some good materials
1. Analysis of qvfb image display principle and mouse and keyboard Information Acquisition Method
2. Use qvfb to develop framebuffer applications under X11
3. qvfb
4. Example of framebuffer and qvfb programming in Linux
5. framebuffer driver
Here is the link to download the program source code: http://download.csdn.net/detail/fzu_dianzi/3718774
The above are purely personal study notes. If anything goes wrong, I hope to raise it. We hope to study and make progress together. My email address is: xzy@yingzhi8.com