DirectFB Overview V0.1
DirectFB Overview V0.1
1)
Andreas Hundt [email protected]
Abstract
This document discusses features and concepts of DirectFB. It is work in
progress.
Contents
1 Introduction 2
1.1 Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2 Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2.1 Graphic Operations . . . . . . . . . . . . . . . . . . . . . 2
1.2.2 Windowing System . . . . . . . . . . . . . . . . . . . . . 3
1.2.3 Resource Management . . . . . . . . . . . . . . . . . . . 3
1.2.4 Graphic Drivers . . . . . . . . . . . . . . . . . . . . . . . 3
1.2.5 Input Drivers . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2.6 Image Loading . . . . . . . . . . . . . . . . . . . . . . . 4
1.2.7 Video Playback . . . . . . . . . . . . . . . . . . . . . . . 4
1.2.8 Font Rendering . . . . . . . . . . . . . . . . . . . . . . . 4
2 DirectFB architecture 5
2.1 Access to the graphics hardware by DirectFB . . . . . . . . . . . 5
2.2 Access to input devices by DirectFB . . . . . . . . . . . . . . . . 5
2.3 Important terms used by DirectFB . . . . . . . . . . . . . . . . . 5
2.3.1 Blitting . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.3.2 Surface . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.3.3 SubSurface . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.3.4 Layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.3.5 Window / Windowstack . . . . . . . . . . . . . . . . . . 7
2.4 Example of a Layer/Window configuration . . . . . . . . . . . . . 7
1
1 Introduction
DirectFB is a thin library that provides hardware graphics acceleration, input
device handling and abstraction, integrated windowing system with support for
translucent windows and multiple display layers on top of the Linux Framebuffer
Device. It is a complete hardware abstraction layer with software fallbacks for ev-
ery graphics operation that is not supported by the underlying hardware. DirectFB
was designed with embedded systems in mind. It offers maximum hardware accel-
erated performance at a minimum of resource usage and overhead.
1.1 Goals
1.2 Features
1.2.1 Graphic Operations
DirectFB supports the the following graphics operations. These can be done in
hardware if supported by the chipset driver, or as software fallback:
Rectangle filling/drawing
Triangle filling/drawing
Line drawing
(Stretched) blitting
2
1.2.2 Windowing System
DirectFB has a fast integrated windowing system, that supports translucent win-
dows. Windows using ARGB Surfaces can be blended on per pixel basis. In addi-
tion each window has its own global transparency.
Matrox G200/G400/G450
3dfx Voodoo3/Banshee
NeoMagic
standard keyboards
joysticks
3
1.2.6 Image Loading
DirectFB includes image providers, which allow loading of the following image
formats directly into DirectFB surfaces:
GIF
video4linux (/dev/video)
4
2 DirectFB architecture
2.1 Access to the graphics hardware by DirectFB
To access the graphics hardware DirectFB relies on the existing kernel interface,
which the framebuffer device provides (/dev/fb). That means that DirectFB needs
a working framebuffer driver to work. For some chipsets there is a special frame-
buffer driver in the linux kernel. For unsupported chipsets a vesa framebuffer will
also work (although with some limitations). No matter if graphics acceleration is
used or not, DirectFB will use the framebuffer device to perform the following
tasks:
5
DirectFB Application
linux
framebuffer driver kernel space
Figure 1: Access to the framebuffer device and the graphics hardware by a Di-
rectFB application
2.3.2 Surface
A Surface is a reserved area in memory where pixel data for one image is stored
in a specific pixel format. A Surface can reside in video and/or system memory.
It is possible to perform drawing operations on a surface or to Blit the surface to
another (see section 1.2.1).
In fullscreen mode, the visible screen is represented by the ”Primary Surface”,
so it is possible to perform graphics operations directly on the visible screen.
Every Surface can optionally use double buffering, graphics operations are then
first executed on a secondary buffer and become valid after Flip() is called. To
prevent flickering it is advised to use Doublebuffering on the primary Surface in
most cases.
2.3.3 SubSurface
A SubSurface uses the same interface as a regular Surface. It represents a part of a
parent Surface and does not allocate any system or video memory itself.
2.3.4 Layer
Depending on the graphics hardware, there are one or more display Layers. A
standard PC graphics card has only one Layer, but sophisticated devices like TV set
top boxes may support two or more layers. Layers occupy different areas in video
ram, and are usually combined by using alpha blending. This in done automatically
6
by the display hardware. If the content of the lowest Layer changes, no repaint has
to be done and the contents of the above layers remain untouched.
Figure 2: The lower Layer is in fullscreen mode, a background image has been ren-
dered to its primary Surface. The video area is a SubSurface where a live video is
displayed. The upper Layer uses a Windowstack, where an application has opened
a Window. The video is visible through the application Window, since the upper
Layer uses a global alpha value.
7
3 DirectFB API Concept
The DirectFB API is structured using Interfaces. An Interface is a C structure that
contains function pointers. Depending on the implementation of the Interface these
pointers point to different core functions. A good example is IDirectFBSurface,
which can represent the whole screen, the contents of a Window or a SubSurface.
The application uses the same API and the same code can be used in each case.
«Super Interface»
IDirectFB
Create
Get Get
Create
IDirectFBDisplayLayer IDirectFBSurface
IDirectFBInputDevice
Get
8
the PNG module will notice that it can handle the file. Finding a suitable imple-
mentation for video formats works the same way.
GfxCard (internal interface only, not accessible by applications, see 1.2.4 for
supported cards)
Input and and graphics card drivers are loaded during initialization of DirectFB
depending on the hardware configuration of the system DirectFB runs on.
It is possible to implement and use new graphics card drivers, input drivers and
media providers without changing or recompiling DirectFB.
/* DirectFB interfaces */
IDirectFB *dfb;
IDirectFBSurface *primary;
IDirectFBImageProvider *provider;
/* get the primary surface, i.e. the surface of the primary layer we have
exclusive access to */
memset( &dsc, 0, sizeof(DFBSurfaceDescription) );
dsc.flags = DSDESC_CAPS; /* only the caps field of the description is valid.
height, width and pixelformat are not set, since
the resolution and pixel are determined by the
current video mode */
dsc.caps = DSCAPS_PRIMARY; /* we want the primary surface (the whole screen) */
9
provider->RenderTo( provider, primary );
sleep (5);
/* clean up */
primary->Release( primary );
dfb->Release( dfb );
10