Framebuffer in Linux

Source: Internet
Author: User

1 Development overview of GUI system based on embedded Linux
Currently, popular commercial GUI systems include WindowsCE and symbianos. These guis provide excellent performance and generally provide complete solutions, which provide better support for Java and multimedia. They can be used to easily build their own embedded systems to form products, shorten the development cycle as much as possible. However, these products are commercial products, and they are inevitably subject to expensive authorization costs. Without open source code, users cannot freely customize their own products. The emergence of Linux has brought new vigor to the development of embedded products. It has many excellent features and is very suitable for Embedded Development: open source code and rich software resources; robust and powerful kernel; supports a variety of architectures, including x86, arm, MIPS, and other mainstream CPUs; sound network communication, graphics, and file management mechanisms; supports a large number of peripheral hardware devices and rich drivers. The size function can be customized to fully meet the customizable requirements of embedded devices. It is precisely because Linux has so many advantages that it has made great strides in the field of embedded development, so it is particularly necessary to develop a Linux-based GUI system. In the Linux System of the desktop version, the common GUI is xwindows, but it is obviously too large compared with the embedded system, embedded systems require a lightweight, reliable, and customizable gui. Therefore, you need to re-develop a GUI suitable for embedded systems. At present, many Linux-based GUI products have been launched at home and abroad. Some popular GUI products include MiniGUI, Microwindows, opengui, QT
Among them, QT embedded is a commercial product, and others are open-source software. Qt embedded is an excellent GUI system in terms of performance and functions, but it requires high authorization fees. It is generally applied to high-end PDA, smartphone, and other products, some other open-source GUI systems have their own characteristics and application fields, but the overall performance is not as good as QT embedded.

2 framebuffer Composition Structure
2.1 Introduction to framebuffer
Framebuffer, as a basic graphics infrastructure, is a driver interface that appears in the Linux 2.2.xx kernel and serves as a basic function library for other advanced graphics or graphics applications. This interface will display the device abstraction as a frame buffer. Users can regard it as a display of an image of the memory without having to close the location of the physical display and page feed mechanism. These are all driven by the framebuffer device, after ing it to the process address space, you can perform read/write operations directly, and write operations can immediately respond to the screen. Frame Buffer increases the drawing speed and overall performance.
The source file of framebuffer is in the Linux/Drivers/Video/directory. The total abstract device file is fbcon. C, which contains the source files related to various graphics/card drivers. When frame buffering is used, Linux places the video card in graphic mode. With framebuffer, your applications can make good graphics without having to have a deep understanding of the underlying drivers. For users, it is no different from other devices under/dev. Users can regard framebuffer as a piece of memory, which can write data to this piece of memory, you can also read data from this memory. The minor of the first registered framebuffer is equal to 0, the minor of the second registered framebuffer is equal to 1, and so on.

2.2 framebuffer Structure Analysis
The framebuffer structure is divided into three layers: 1.
 
Figure 1 framebuffer Structure
Bottom layer: Basic console Driver (Drivers/Char/console. c), which provides a part of the common interface of the text console. By using the console driver function, you can display text on the screen, but it cannot display graphics or animations.
Middle Layer: (Drivers/Video/fbcon. c) use the video mode function to implement graphics or animation functions. The middle layer driver provides a conventional interface for drawing in video mode.
Top layer: A driver related to a specific hardware. It must support different hardware aspects of the video card, such as enable/disable the video card controller, support for depth and mode, and color palette, this is also the top-level driver that attracts attention. All three layers depend on each other to implement the correct video function.
Linux devices are classified into character devices, Block devices, and network device interfaces. What kind of framebuffer devices do? It is easy to confuse people at the beginning of the design. In fact, there is no difference between the frame buffer device, framebufferdevice, and other devices in the Linux system directory/dev. The device file corresponding to the frame buffer device is/dev/FB *. If the system has multiple display cards, Linux supports multiple frame buffer devices, up to 32, they are/dev/fb0 to/dev/fb31, while/dev/FB is the default frame buffer device, which usually points to/dev/fb0. Of course, it is enough to support a display device in an embedded system. The frame buffer device is a standard character device. The primary device number is 29, and the secondary device number ranges from 0 to 31. Corresponding to/dev/fb0/dev/fb31 respectively.
The framebuffer device relies heavily on the following three data structures. The three structures are declared in FB. h.
1) struct fb_var_screeninfo: describes the features of the graphics card. It is usually set by the user.
2) struct fb_fix_screeninfo: defines the hardware features of the graphics card and cannot be changed. If you select a graphics card, the hardware features of the card will be determined.
3) struct fb_info: defines the independent status of the framebuffer device of the current graphics card. A graphics card may have two framebuffers. In this case, two fb_info structures are required. This structure is only visible in the kernel space.

3 framebuffer function implementation
In any Linux embedded system, framebuffer plays an extremely important role. Without framebuffer support, it is impossible for us to operate and display graphical images on many embedded devices, for example, hand-written input on a smartphone and touch-sensing operations on household devices cannot be completed. Specifically, framebuffer has the following functions in Embedded Linux:
1) The framebuffer device can obtain some fixed information about the display device. (Such as the Display memory size), variable information related to the display mode (such as resolution, pixel structure, byte width of each scanned line), and color palette information in pseudo-color mode. These information is obtained through the ioctl Command provided by framebuffer. IOCTL is a function used to manage the I/O channel of the device in the device driver. It controls some features of the device, for example, the Serial Transmission baud rate and the motor speed. The function call is as follows: int IOCTL (int
FD, IND cmd ,......); FD is the File Identifier returned by the open function when the user program opens the device. CMD is the control command of the user program on the device. As for the ellipsis, It is a supplement parameter, generally, there is at most one, or is not related to the meaning of CMD.
2) use the framebuffer device to obtain the type of the accelerated display card supported by the current kernel (obtained through fixed information ). This type is usually related to a specific display chip. After obtaining the acceleration chip type, the application can map the graphics card memory I/O (called memio) to the address space of the process. These memio are generally used to control the registers of the display card. By operating these registers, the application can control the acceleration function of a specific video card.
3) The display device can map its control registers to the physical memory space. Then, access to these control registers becomes access to the physical memory. Once mapped to the physical memory, normal Linux processes can map these memory I/O to the process address space through the ing operation (MMAP), so that they can directly access these registers.
In embedded devices that support framebuffer, applications can perform operations on framebuffer, including:
1) read/write (read/write)/dev/FB: equivalent to the read/write screen buffer;
2) MMAP operation: Linux maps the physical address of the screen buffer to a virtual address in the user space through the MMAP function ing operation provided in the file_operations structure of file operations, then, the user can access the screen buffer to draw on the screen by reading and writing this virtual address. Several processes can be mapped to the same display buffer. In fact, all applications that use frame buffering devices use ing operations to display images. Since all the ing operations are completed by the kernel, there is not much work left by the frame buffer driver for developers.
3) I/O Control: completed by IOCTL.
The memory block distribution in framebuffer is shown in figure 2.
 
Figure 2 memory block distribution chart

4 using framebuffer in Linux
4.1 supports compiling the framebuffer Linux Kernel
Before implementing framebuffer programming in Linux, you also need to compile the kernel to generate a kernel that supports framebuffer. The method to compile the kernel is the same as that of the traditional method, but there are also some differences, log on to Linux as a root user (administrator. After compilation, restart the system and choose to enter the kernel mode generated by the compilation. However, before logon, set "linuxvga" to a working mode conforming to framebuffer, for example, if "linuxvga = 771" is set, the system enters the 800*600*256 color working mode. After logging on to the startup page, the penguin image is displayed, indicating that you have successfully logged on to the kernel mode that supports framebuffer. After the startup, log on as the root user to enter the kernel mode that supports framebuffer, now you can program the corresponding framebuffer in this terminal.

4.2 framebuffer Application Programming
After compiling the framebuffer-based Linux kernel, you can program functions in Linux. However, the most common and representative applications are the direct screen writing through framebuffer in Linux. This technology has been applied to smartphones, PDAs, and other embedded devices, such as handwriting Input Functions on PDAs. The specific implementation process is as follows. In actual programming, the procedure of the application to perform framebuffer operations is as follows:
1) Open the/dev/FB device file;
2) use ioctrl to obtain the parameters of the current display screen, such as the screen resolution and the number of bits per pixel. The screen buffer size can be calculated based on screen parameters.
3) map the screen buffer to the user space.
4) After ing, you can directly read and write the screen buffer for plotting and image display.
After the kernel compilation and initialization settings are complete, run the framebuffer written in C language in Linux to directly write the screen program based on the above operations. We can see that on the Linux system desktop, we can use the mouse to write Chinese characters and plot them directly, and apply them to PDAs, smartphones, and other embedded devices to implement the handwriting input function.
Of course, there are still many operations and functions implemented using framebuffer. As a hardware graphic interface, framebuffer can be used to perform operations on underlying hardware devices, the most representative is to implement graphic operations and display them on the application layer.

5 conclusion
Embedded GUI is an intermediate product between an embedded operating system and upper-layer applications. For an embedded system solution based on a Linux operating system, there is little difference between different manufacturers at the operating system level, therefore, the advantages and disadvantages of GUI are especially important for a product. Framebuffer, as a basic graphic facility, abstracts the video memory into a device and performs operations on the video memory directly by reading and writing the device. Therefore, it is a good interface for users to access the graphic interface, this greatly helps users design a high-performance GUI, which not only satisfies users' high requirements, but also makes their embedded products highly competitive. With the further development and wide application of embedded technology, frambufer will play an increasingly important role in Embedded GUI systems.

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.