Principles of FrameBuffer

Source: Internet
Author: User

I. <! -- [Endif] --> principle of FrameBuffer
FrameBuffer is a driver interface that appears in the 2.2.xx kernel.

Linux is working in the protection mode, so user-mode processes cannot use the interrupt call provided in the graphics card BIOS as DOS to achieve direct screen writing, linux abstracts the FrameBuffer device for the user-state process to directly write the screen. The Framebuffer mechanism imitates the function of the video card, abstracts the hardware structure of the video card, and can directly perform operations on the video memory through the read and write operations of Framebuffer. Users can regard Framebuffer as an image showing the memory. After ing it to the process address space, they can directly perform read/write operations, and write operations can immediately respond to the screen. Such operations are abstract and unified. Users do not have to worry about the location of Physical video memory, page feed mechanism, and other details. These are all driven by the Framebuffer device.

But Framebuffer itself does not have any ability to operate data, so it is better than a pool that temporarily stores water. the CPU puts the result after calculation into this pool, and the pool then streams the result to the display. data is not processed in the middle. the application can also directly read and write the contents of this pool. in this mechanism, although Framebuffer requires the support of the real graphics driver, all display tasks are completed by the CPU, so the CPU burden is very heavy.

The device files of framebuffer are usually/dev/fb0,/dev/fb1, and so on.

Run the following command: # dd if =/dev/zero of =/dev/fb to clear the screen.

If the display mode is 1024x7688-bit, run the command $ dd if =/dev/zero of =/dev/fb0 bs = 1024 count = 768 to clear the screen.

Run the command: # dd if =/dev/fb of = fbfile to save the content in fb;

You can write back the screen: # dd if = fbfile of =/dev/fb

When Framebuffer is used, Linux places the video card in graphic mode.

In applications, the FrameBuffer device is usually used by ing the FrameBuffer device to the process address space. For example, the following program opens the/dev/fb0 device and performs address ing through the mmap system call, then use memset to clear the screen (Here we assume the display mode is 1024x7688-bit color mode, linear memory mode ):

Int fb;

Unsigned char * fb_mem;

Fb = open ("/dev/fb0", O_RDWR );

Fb_mem = mmap (NULL, 1024*768, PROT_READ | PROT_WRITE, MAP_SHARED, fb, 0 );

Memset (fb_mem, 0, 1024*768 );

The FrameBuffer device also provides several ioctl commands to 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.

The FrameBuffer device can also obtain the type of the accelerated display card supported by the current kernel (obtained through fixed information), which is usually related to a specific display chip. For example, the latest kernel (2.4.9) supports acceleration of popular display chips such as S3, Matrox, nVidia, and 3Dfx. After obtaining the acceleration chip type, the application can map the memory I/O (memio) of the PCI device 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.

The PCI device can map its own control registers to the physical memory space. Then, access to these control registers becomes access to the physical memory. Therefore, these registers are also called "memio ". Once mapped to the physical memory, common processes in Linux can map these memory I/O to the process address space through mmap, so that these registers can be directly accessed.

Of course, because different display chips have different acceleration capabilities, the use and definition of memio are also different. At this time, you need to write different acceleration functions for different types of acceleration chips. For example, most chips provide hardware acceleration for Rectangle filling, but different chip implementation methods are different, you need to write different functions for filling the rectangle for different chip types.

FrameBuffer is only a device that provides Display memory and display chip registers ing from physical memory to process address space. Therefore, for applications, If You Want To program graphics on FrameBuffer, you also need to do a lot of work by yourself.

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.