-
[my-code/ivac.git] / dfb_api.c
1 /*
2  * dfb_api.c - api to dfb interface
3  */
4
5 /* std includes */
6 #include <stdio.h>
7 #include <string.h>
8 #include <unistd.h>
9
10 /* dfb includes */
11 #include <directfb.h>
12
13 #define MY_FONT_HEIGHT 18
14
15 /* global stuff */
16
17 /* well ... */
18 IDirectFB *dfb = NULL;
19
20 IDirectFBSurface *primary = NULL;
21 IDirectFBSurface *logo = NULL;
22 IDirectFBSurface *video = NULL;
23 IDirectFBSurface *window = NULL;
24
25 IDirectFBImageProvider *image_provider = NULL;
26 IDirectFBVideoProvider *video_provider = NULL;
27
28 int screen_width  = 0;
29 int screen_height = 0;
30
31 char dfb_video_dev[]="/dev/v4l/video0";
32 char text_top[]="Internet Video / Audio Conferencing";
33 char dfb_image[]="./images/ivac_logo.png";
34 char dfb_font[]="./fonts/decker.ttf";
35
36 /* small api - directfb usage kinda sux: foo->bar(foo,...) wtf?!?!?! */
37
38 int dfb_init(int *argc,char **argv) {
39  DirectFBInit(argc,&argv);
40  DirectFBCreate(&dfb);
41  dfb->SetCooperativeLevel(dfb,DFSCL_FULLSCREEN);
42  return 1;
43 }
44
45 int check_accel(void) {
46  DFBCardCapabilities caps;
47  dfb->GetCardCapabilities(dfb,&caps);
48  return (caps.acceleration_mask);
49 }
50
51 int create_primary_surface(void) {
52  DFBSurfaceDescription desc;
53  memset(&desc,0,sizeof(DFBSurfaceDescription));
54  desc.flags=DSDESC_CAPS;
55  desc.caps=DSCAPS_PRIMARY;
56  dfb->CreateSurface(dfb,&desc,&primary);
57  return 1;
58 }
59
60 int get_surface_size(IDirectFBSurface *surface,int *width,int *height) {
61  surface->GetSize(surface,width,height);
62  return 1;
63 }
64
65 int get_primary_surface_size(void) {
66  get_surface_size(primary,&screen_width,&screen_height);
67  return 1;
68 }
69
70 int create_logo_surface(void) {
71  DFBSurfaceDescription desc;
72  DFBImageDescription image_desc;
73  dfb->CreateImageProvider(dfb,dfb_image,&image_provider);
74  image_provider->GetSurfaceDescription(image_provider,&desc);
75  image_provider->GetImageDescription(image_provider,&image_desc);
76  printf("image description: caps=%x red=%hhd green=%hhd blue=%hhd\n",image_desc.caps,
77                                                         image_desc.colorkey_r,
78                                                         image_desc.colorkey_g,
79                                                         image_desc.colorkey_b);
80  dfb->CreateSurface(dfb,&desc,&logo);
81  image_provider->RenderTo(image_provider,logo,NULL);
82  image_provider->Release(image_provider);
83  return 1;
84 }
85  
86 int create_video_surface(void) {
87  DFBSurfaceDescription desc;
88  DFBVideoProviderCapabilities caps;
89  dfb->CreateVideoProvider(dfb,dfb_video_dev,&video_provider);
90  video_provider->GetSurfaceDescription(video_provider,&desc);
91  video_provider->GetCapabilities(video_provider,&caps);
92  printf("video capabilities: %x\n",caps);
93  dfb->CreateSurface(dfb,&desc,&video);
94  video_provider->PlayTo(video_provider,video,NULL,NULL,NULL);
95  video_provider->Release(video_provider);
96  return 1;
97 }
98
99 int clear_screen(IDirectFBSurface *surface) {
100  surface->FillRectangle(surface,0,0,screen_width,screen_height);
101  return 1;
102 }
103
104 int release_surface(IDirectFBSurface *surface) {
105  surface->Release(surface);
106  return 1;
107 }
108
109 int release_dfb(void) {
110  dfb->Release(dfb);
111  return 1;
112 }
113
114
115 /* test api app */
116 int main (int argc, char **argv) {
117
118  dfb_init(&argc,argv);
119
120  check_accel();
121
122  create_primary_surface();
123  printf("primary surface created\n");
124
125  // create_video_surface();
126  create_logo_surface();
127
128  get_primary_surface_size();
129
130  clear_screen(primary);
131
132  // primary->Flip(primary,NULL,DSFLIP_WAITFORSYNC);
133
134  sleep(5);
135
136  release_surface(primary);
137
138  return 1;
139 }