enabled flipping
[my-code/ivac.git] / dfb_api.c
index fbc67fb..3488f8b 100644 (file)
--- a/dfb_api.c
+++ b/dfb_api.c
@@ -19,21 +19,22 @@ IDirectFB *dfb = NULL;
 
 IDirectFBSurface *primary = NULL;
 IDirectFBSurface *logo = NULL;
-IDirectFBSurface *subsurface = NULL;
+IDirectFBSurface *video = NULL;
 IDirectFBSurface *window = NULL;
 
 IDirectFBImageProvider *image_provider = NULL;
 IDirectFBVideoProvider *video_provider = NULL;
 
-static int screen_width  = 0;
-static int screen_height = 0;
+int screen_width  = 0;
+int screen_height = 0;
 
-char dfb_video_dev[]="/dev/video";
+char dfb_video_dev[]=VIDEO_DEV;
 char text_top[]="Internet Video / Audio Conferencing";
 char dfb_image[]="./images/ivac_logo.png";
 char dfb_font[]="./fonts/decker.ttf";
 
-/* small api */
+/* small api - directfb usage kinda sux: foo->bar(foo,...) wtf?!?!?! */
+
 int dfb_init(int *argc,char **argv) {
  DirectFBInit(argc,&argv);
  DirectFBCreate(&dfb);
@@ -51,22 +52,52 @@ int create_primary_surface(void) {
  DFBSurfaceDescription desc;
  memset(&desc,0,sizeof(DFBSurfaceDescription));
  desc.flags=DSDESC_CAPS;
- desc.caps=DSCAPS_PRIMARY;
+ desc.caps=DSCAPS_PRIMARY|DSCAPS_FLIPPING;
  dfb->CreateSurface(dfb,&desc,&primary);
  return 1;
 }
 
-int create_image_provider(IDirectFBSurface *surface) {
+int get_surface_size(IDirectFBSurface *surface,int *width,int *height) {
+ surface->GetSize(surface,width,height);
+ return 1;
+}
+
+int get_primary_surface_size(void) {
+ get_surface_size(primary,&screen_width,&screen_height);
+ return 1;
+}
+
+int create_logo_surface(void) {
+ DFBSurfaceDescription desc;
+ DFBImageDescription image_desc;
  dfb->CreateImageProvider(dfb,dfb_image,&image_provider);
- image_provider->RenderTo(image_provider,surface,NULL);
+ image_provider->GetSurfaceDescription(image_provider,&desc);
+ image_provider->GetImageDescription(image_provider,&image_desc);
+ printf("image description: caps=%x red=%hhd green=%hhd blue=%hhd\n",image_desc.caps,
+                                                       image_desc.colorkey_r,
+                                                       image_desc.colorkey_g,
+                                                       image_desc.colorkey_b);
+ dfb->CreateSurface(dfb,&desc,&logo);
+ image_provider->RenderTo(image_provider,logo,NULL);
  image_provider->Release(image_provider);
  return 1;
 }
-
-int create_video_provider(IDirectFBSurface *surface) {
+int create_video_surface(void) {
+ DFBSurfaceDescription desc;
+ DFBVideoProviderCapabilities caps;
  dfb->CreateVideoProvider(dfb,dfb_video_dev,&video_provider);
- video_provider->PlayTo(video_provider,surface,NULL,NULL,NULL);
- // video_provider->Release(video_provider);
+ video_provider->GetSurfaceDescription(video_provider,&desc);
+ video_provider->GetCapabilities(video_provider,&caps);
+ printf("video capabilities: %x\n",caps);
+ dfb->CreateSurface(dfb,&desc,&video);
+ video_provider->PlayTo(video_provider,video,NULL,NULL,NULL);
+ video_provider->Release(video_provider);
+ return 1;
+}
+
+int clear_screen(IDirectFBSurface *surface) {
+ surface->FillRectangle(surface,0,0,screen_width,screen_height);
  return 1;
 }
 
@@ -80,6 +111,30 @@ int release_dfb(void) {
  return 1;
 }
 
+int blit_surface(IDirectFBSurface *source,int x,int y) {
+ primary->Blit(primary,source,NULL,x,y);
+ return 1;
+}
+
+int blit_logo(void) {
+ int x,y;
+ get_surface_size(logo,&x,&y);
+ printf("size of logo width/height: %d/%d\n",x,y);
+ blit_surface(logo,((screen_width-x)/2),((screen_height-y)/2));
+ return 1;
+}
+
+int blit_video(void) {
+ int x,y;
+ get_surface_size(video,&x,&y);
+ blit_surface(video,((screen_width-x)/2),((screen_height-y)/2));
+ return 1;
+}
+
+int flip_it(void) {
+ primary->Flip(primary,NULL,DSFLIP_WAITFORSYNC);
+ return 1;
+}
 
 /* test api app */
 int main (int argc, char **argv) {
@@ -90,11 +145,25 @@ int main (int argc, char **argv) {
 
  create_primary_surface();
 
- create_image_provider(primary);
+ // create_video_surface();
+ create_logo_surface();
+
+ get_primary_surface_size();
+ printf("primary surface width/height: %d/%d\n",screen_width,screen_height);
+
+ clear_screen(primary);
+
+ blit_logo();
 
- sleep(5);
+ flip_it();
+
+ sleep(10);
+
+ release_surface(logo);
 
  release_surface(primary);
 
+ release_dfb();
+
  return 1;
 }