2 * dfb_api.c - api to dfb interface
15 #define MY_FONT_HEIGHT 18
20 IDirectFB *dfb = NULL;
22 IDirectFBSurface *primary = NULL;
23 IDirectFBSurface *logo = NULL;
24 IDirectFBSurface *video = NULL;
25 IDirectFBSurface *window = NULL;
27 IDirectFBImageProvider *image_provider = NULL;
28 IDirectFBVideoProvider *video_provider = NULL;
31 int screen_height = 0;
33 char dfb_video_dev[]=VIDEO_DEV;
34 char text_top[]="Internet Video / Audio Conferencing";
35 char dfb_image[]="./images/ivac_logo.png";
36 char dfb_font[]="./fonts/decker.ttf";
38 /* variable definitions */
44 int dfb_init(int *argc,char **argv) {
45 DirectFBInit(argc,&argv);
47 dfb->SetCooperativeLevel(dfb,DFSCL_FULLSCREEN);
51 int check_accel(void) {
52 DFBCardCapabilities caps;
53 dfb->GetCardCapabilities(dfb,&caps);
54 return (caps.acceleration_mask);
57 int create_primary_surface(void) {
58 DFBSurfaceDescription desc;
59 memset(&desc,0,sizeof(DFBSurfaceDescription));
60 desc.flags=DSDESC_CAPS;
61 desc.caps=DSCAPS_PRIMARY|DSCAPS_FLIPPING;
62 dfb->CreateSurface(dfb,&desc,&primary);
66 int get_surface_size(IDirectFBSurface *surface,int *width,int *height) {
67 surface->GetSize(surface,width,height);
71 int get_primary_surface_size(void) {
72 get_surface_size(primary,&screen_width,&screen_height);
76 int create_logo_surface(void) {
77 DFBSurfaceDescription desc;
78 DFBImageDescription image_desc;
79 dfb->CreateImageProvider(dfb,dfb_image,&image_provider);
80 image_provider->GetSurfaceDescription(image_provider,&desc);
81 image_provider->GetImageDescription(image_provider,&image_desc);
82 printf("image description: caps=%x red=%hhd green=%hhd blue=%hhd\n",image_desc.caps,
83 image_desc.colorkey_r,
84 image_desc.colorkey_g,
85 image_desc.colorkey_b);
86 dfb->CreateSurface(dfb,&desc,&logo);
87 image_provider->RenderTo(image_provider,logo,NULL);
88 image_provider->Release(image_provider);
92 int create_video_surface(void) {
94 DFBSurfaceDescription desc;
95 DFBVideoProviderCapabilities caps;
96 dfb->CreateVideoProvider(dfb,dfb_video_dev,&video_provider);
97 video_provider->GetSurfaceDescription(video_provider,&desc);
98 q=(((float)screen_height/desc.height>=(float)screen_width/desc.width)?
99 (float)screen_height/desc.height:(float)screen_width/desc.width);
100 desc.width=(int)(screen_width/q);
101 desc.height=(int)(screen_height/q);
102 video_provider->GetCapabilities(video_provider,&caps);
103 printf("video capabilities: %x\n",caps);
104 dfb->CreateSurface(dfb,&desc,&video);
105 video_provider->PlayTo(video_provider,video,NULL,video_callback,NULL);
106 video_provider->Release(video_provider);
110 int clear_screen(IDirectFBSurface *surface) {
111 surface->FillRectangle(surface,0,0,screen_width,screen_height);
115 int release_surface(IDirectFBSurface *surface) {
116 surface->Release(surface);
120 int release_dfb(void) {
125 int blit_surface(IDirectFBSurface *source,int x,int y) {
126 primary->Blit(primary,source,NULL,x,y);
130 int blit_logo(void) {
132 get_surface_size(logo,&x,&y);
133 printf("size of logo width/height: %d/%d\n",x,y);
134 blit_surface(logo,((screen_width-x)/2),((screen_height-y)/2));
138 int blit_video(void) {
140 get_surface_size(video,&x,&y);
141 printf("size of logo width/height: %d/%d\n",x,y);
142 // blit_surface(video,((screen_width-x)/2),((screen_height-y)/2));
143 blit_surface(video,0,0);
148 primary->Flip(primary,NULL,DSFLIP_WAITFORSYNC);
152 DVFrameCallback video_callback(void) {
153 primary->Blit(primary,video,NULL,0,0);
159 int main (int argc, char **argv) {
161 dfb_init(&argc,argv);
165 create_primary_surface();
167 create_video_surface();
168 // create_logo_surface();
170 get_primary_surface_size();
171 printf("primary surface width/height: %d/%d\n",screen_width,screen_height);
173 clear_screen(primary);
175 puts("main: blit video");
179 // puts("main: flip");
184 release_surface(logo);
186 release_surface(primary);