31 Aug 2009, 4:58pm

leave a comment

Using DirectFB Part I – Prerequisites

No Gravatar

DirectFB is an open source lower level graphics framework that most likely lives below the graphics library you use in Linux (e.g. Cairo, GTK, etc). DirectFB has opened my eyes to the world of graphics programming and peaked my interest in how to apply my knowledge from other fields.
1. Surface – Conceptually a piece of memory (RAM) which represents what is sent to the display for viewing. This means that every pixel in the width X height of the output is represented by a piece of memory related to how the color and alpha is encoded. By default, each pixel is 24 bits of color (8 red, 8 green and 8 blue) and 8 bits of alpha. The surface can be double buffered. This means that for every pixel shown on the display, there are two areas in RAM that are used to show that. This is a fun concept, actually. Picture a two sided chalk board, with one side facing a classroom full of people and you on the other side. While the class is looking at what you drew, you’re drawing something new. When you’re done, you flip it over and start over again. Double buffered surfaces work just like this.
2. Alpha blending – From Wikipedia: “In computer graphics, alpha [blending] is the process of combining an image with a background to create the appearance of partial transparency.” This is done at it’s most basic level by reading the pixel data behind the pixel that is about to drawn and then running it through this equation: a(color_front) + (1 – a)(color_back), where “a” is alpha value from 0->1.
3. Display Layer – A layer is highly dependent on the hardware being used. The easiest example I can give for layers is to have you picture CNN or a similar channel. The live television feed is on a layer that is behind the ticker bar, time and information at the bottom of the screen. This could easily be done with two layers, but there may be more necessary (e.g. picture in picture video).
4. Window – A window is a sub-surface (not a full screen surface) which has attributes that are necessary in more than one subsurface. This can be as simple as a button, where all of the interactions are the same, the image(s) is the same but the text is different. Windows also make it easy to optimize. By blitting everything into one window, the window only has to blit onto the surface, rather than all of the items in the window. Windows are also easy to hide, send behind other windows and move around the layer.
5. Blit – This should have been listed first, but I felt other appealing background information is necessary first. A “Bit Blit” or Bit Block Transfer is the framework around moving one piece of “surface” memory to another. This can be as simple as a blit of a colored shape, which was pre-blitted into a sub-surface, to the primary surface shown on the display. Blits are very expensive operations and most graphics hardware has advanced algorithms to accelerate blitting to get the fastest frame rate possible.
6. Flip – The concept of a flip has already been mentioned. There are a couple parameters which are important to flipping. One is when to flip, the other is how much to flip. When to flip is easily answered: Do you want to flip the surface going out to the display or not? If so, wait for a vertical sync from the display. This is a signal from the display telling the hardware “I’m about to refresh, do you have anything new you’d like to show?” We would usually say yes because we want to show as much as we can at the frame rate of the display. Specifying how much is called “clipping”.