DirectFB:Development FAQ
From DirectFBWiki
| Table of contents |
How do I compile a simple DirectFB application?
The easiest way to get the correct compiler and linker flags to compile a DirectFB application is to use pkg-config. If you don't have it already installed, download it load from http://www.freedesktop.org/ . A DirectFB application that consists of the single source file test.c can then be compiled and linked using this simple command:
gcc `pkg-config --cflags directfb` -o test test.c `pkg-config --libs directfb`
pkg-config offers more features like for example checking the installed version of DirectFB. See the pkg-config man page for more details.
Simple Example Makefile
This Makefile may be useful as starting point. Insert your object files in the OBJS variable, enter the name of your executable in TARGET. Be sure that the name of your working directory is the same as $(TARGET), otherwise the command 'make tar' won't work correctly.
If you copy'n'paste this sample Makefile into your editor you may need to remove the leading whitespaces and replace the 8 whitespaces before commands by a real <tab>:
RM = rm -f
CC = gcc
CFLAGS = -g -Wall -O2 -MD `pkg-config --cflags directfb`
LFLAGS = -g -Wall -O2 `pkg-config --libs directfb`
TARGET = test_application
OBJS = test.o main.o
all: $(TARGET)
$(TARGET): $(OBJS)
$(CC) $(LFLAGS) $(OBJS) -o $(TARGET)
.c.o:
$(CC) $(CFLAGS) -c $<
tar: clean
( cd .. && tar cvfz $(TARGET)-`date "+%Y-%m-%d"`.tar.gz $(TARGET) ; cd - )
clean:
$(RM) *.d *.o $(TARGET)
-include $(wildcard *.d) -
What are the relationships among the main DirectFB types?
There are several one-to-one and one-to-many relationships here:
- 1 IDirectFB (top-level) <--> N Screens
- 1 Screen <--> N Layers
- 1 Layer <--> 1 Primary Surface
- 1 Layer <--> N Windows
- 1 Window <--> 1 Window Surface
- 1 Surface <--> N Subsurfaces
The most common case is one screen with one display layer, but DFB supports multiple instances of each.
Layers and Screens
Each screen can have one or more layers. Usually, a screen will have only one, but system that support overlays may have multiple layers with the hardware letting one layer show through another.
Screens and Windows
A screen cannot directly create a window, but you can ask a screen for the ID of its primary layer, then ask the IDirectFB interface to give you an interface to that layer, then use that interface to create a window.
Surfaces and Windows
Each window has a surface associated with it; drawing to that surface isn't immediately visible on the screen, as the window manager is responsible for compositing the surfaces of the windows to the primary surface based on their update regions and the stacking order, and the window manager is notified of changes by using the Flip() method of the surface.
Surfaces and Layers
A layer also has a surface associated with it; this surface is a direct representation of the layer's screen memory. You can only access this surface when you're in exclusive mode, otherwise you need to create a window and have the window manager draw to the surface.
