]> www.hackdaworld.org Git - my-code/ivac.git/blob - old/dfb_api.c
added some \n's
[my-code/ivac.git] / old / 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 #include "dfb_api.h"
14
15 #define MY_FONT_HEIGHT 18
16
17 /* global stuff */
18
19 /* well ... */
20 IDirectFB *dfb = NULL;
21
22 IDirectFBSurface *primary = NULL;
23 IDirectFBSurface *logo = NULL;
24 IDirectFBSurface *video = NULL;
25 IDirectFBSurface *window = NULL;
26
27 IDirectFBImageProvider *image_provider = NULL;
28 IDirectFBVideoProvider *video_provider = NULL;
29
30 int screen_width  = 0;
31 int screen_height = 0;
32
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";
37
38 /* variable definitions */
39 // struct user_info {
40  
41
42 /* functions */
43
44 int dfb_init(int *argc,char **argv) {
45  DirectFBInit(argc,&argv);
46  DirectFBCreate(&dfb);
47  dfb->SetCooperativeLevel(dfb,DFSCL_FULLSCREEN);
48  return 1;
49 }
50
51 int check_accel(void) {
52  DFBCardCapabilities caps;
53  dfb->GetCardCapabilities(dfb,&caps);
54  return (caps.acceleration_mask);
55 }
56
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);
63  return 1;
64 }
65
66 int get_surface_size(IDirectFBSurface *surface,int *width,int *height) {
67  surface->GetSize(surface,width,height);
68  return 1;
69 }
70
71 int get_primary_surface_size(void) {
72  get_surface_size(primary,&screen_width,&screen_height);
73  return 1;
74 }
75
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);
89  return 1;
90 }
91
92 int create_video_surface(void) {
93  float q;
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);
107  return 1;
108 }
109
110 int clear_screen(IDirectFBSurface *surface) {
111  surface->FillRectangle(surface,0,0,screen_width,screen_height);
112  return 1;
113 }
114
115 int release_surface(IDirectFBSurface *surface) {
116  surface->Release(surface);
117  return 1;
118 }
119
120 int release_dfb(void) {
121  dfb->Release(dfb);
122  return 1;
123 }
124
125 int blit_surface(IDirectFBSurface *source,int x,int y) {
126  primary->Blit(primary,source,NULL,x,y);
127  return 1;
128 }
129
130 int blit_logo(void) {
131  int x,y;
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));
135  return 1;
136 }
137
138 int blit_video(void) {
139  int x,y;
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);
144  return 1;
145 }
146
147 int flip_it(void) {
148  primary->Flip(primary,NULL,DSFLIP_WAITFORSYNC);
149  return 1;
150 }
151
152 DVFrameCallback video_callback(void) {
153  puts("callback flip");
154  flip_it;
155  return DFENUM_OK;
156 }
157
158 /* test api app */
159 int main (int argc, char **argv) {
160
161  dfb_init(&argc,argv);
162
163  check_accel();
164
165  create_primary_surface();
166
167  // create_video_surface();
168  create_logo_surface();
169
170  get_primary_surface_size();
171  printf("primary surface width/height: %d/%d\n",screen_width,screen_height);
172
173  clear_screen(primary);
174
175  puts("main: blit video");
176  // blit_video();
177  blit_logo();
178
179  // puts("main: flip");
180  flip_it();
181
182  sleep(10);
183
184  release_surface(logo);
185
186  release_surface(primary);
187
188  release_dfb();
189
190  return 1;
191 }