static void
app_update( App *app )
{
     static const DFBColor colors[3] = {
          { 0xff, 0x30, 0xc0, 0xff },
          { 0xff, 0xff, 0xff, 0x30 },
          { 0xff, 0x30, 0xff, 0xc0 }
     };

     IDirectFBSurface *surface = app->surface;

     surface->Clear( surface, 0xff, 0xff, 0xff, 0x20 );

     surface->SetColor( surface, colors[app->index].r, colors[app->index].g, colors[app->index].b, colors[app->index].a );
     surface->FillRectangle( surface, app->anim_x, app->anim_y, 40, 300 );

     surface->Flip( surface, NULL, DSFLIP_WAITFORSYNC );


     app->anim_x += app->anim_dirx;
     if (app->anim_x >= app->resolution.w - 40)
          app->anim_dirx = -5;
     else if (app->anim_x <= 0)
          app->anim_dirx = 5;

     app->anim_y += app->anim_diry;
     if (app->anim_y >= app->resolution.h - 300)
          app->anim_diry = -5;
     else if (app->anim_y <= 0)
          app->anim_diry = 5;
          
}
示例#2
0
static void Display(vout_display_t *vd, picture_t *picture)
{
    vout_display_sys_t *sys = vd->sys;

    IDirectFBSurface *primary = sys->primary;

    void *pixels;
    int  pitch;
    if (primary->Lock(primary, DSLF_WRITE, &pixels, &pitch) == DFB_OK) {
        picture_resource_t rsc;

        memset(&rsc, 0, sizeof(rsc));
        rsc.p[0].p_pixels = pixels;
        rsc.p[0].i_lines  = sys->height;
        rsc.p[0].i_pitch  = pitch;

        picture_t *direct = picture_NewFromResource(&vd->fmt, &rsc);
        if (direct) {
            picture_Copy(direct, picture);
            picture_Release(direct);
        }

        if (primary->Unlock(primary) == DFB_OK)
            primary->Flip(primary, NULL, 0);
    }
    picture_Release(picture);
}
示例#3
0
static int OpenDisplay(vout_display_t *vd)
{
    vout_display_sys_t *sys = vd->sys;

    DFBSurfaceDescription dsc;
    /*dsc.flags = DSDESC_CAPS | DSDESC_HEIGHT | DSDESC_WIDTH;*/
    dsc.flags = DSDESC_CAPS;
    dsc.caps  = DSCAPS_PRIMARY | DSCAPS_FLIPPING;
    /*dsc.width = 352;*/
    /*dsc.height = 240;*/

    IDirectFB *directfb = NULL;
    if (DirectFBCreate(&directfb) != DFB_OK || !directfb)
        return VLC_EGENERIC;
    sys->directfb = directfb;

    IDirectFBSurface *primary = NULL;
    if (directfb->CreateSurface(directfb, &dsc, &primary) || !primary)
        return VLC_EGENERIC;
    sys->primary = primary;

    primary->GetSize(primary, &sys->width, &sys->height);
    primary->GetPixelFormat(primary, &sys->pixel_format);
    primary->FillRectangle(primary, 0, 0, sys->width, sys->height);
    primary->Flip(primary, NULL, 0);

    return VLC_SUCCESS;
}
示例#4
0
static int l_Flip (lua_State* L)
{
	// TEMP: NULL,0?
	// [ sfc ]
	IDirectFBSurface* sfc = * (IDirectFBSurface**) luaL_checkudata(L, 1, "ldirectfb.IDirectFBSurface");
	DFBCHECK (sfc->Flip (sfc, NULL, DSFLIP_WAITFORSYNC));
	//DFBCHECK (sfc->Flip (sfc, NULL, 0));
	//DFBCHECK (sfc->Flip (sfc, NULL, DSFLIP_BLIT));
	return 0;
}
示例#5
0
static mrb_value surface_flip(mrb_state *mrb, mrb_value self)
{
    IDirectFBSurface* surface = mrb_directfb_surface(mrb, self);
    DFBResult ret = -1;
    if (surface != NULL) {
        mrb_value o = mrb_nil_value();
        mrb_int flags = 0;
        mrb_get_args(mrb, "|oi", &o, &flags);
        ret = surface->Flip(surface, mrb_directfb_region(mrb, o), flags);
    }
    return mrb_fixnum_value(ret);
}
示例#6
0
//---------------------------------------------------------------------------------
status_t ServerWindow::Show (){

if (created){
  IDirectFBSurface *wsurface = NULL;
  
  DFBCHECK(window->SetStackingClass(window, DWSC_MIDDLE));
  DFBCHECK(window->RaiseToTop(window));
  DFBCHECK(window->GetSurface(window, &wsurface));  
  DFBCHECK (wsurface->Flip (wsurface, NULL, DSFLIP_WAITFORSYNC));
  window->SetOpacity (window, 0xff);
  hidden = false;
  active = true;
}
}
示例#7
0
static void
update( Context *context )
{
     unsigned long     t;
     IDirectFBSurface *surface = context->surface;
     static __u8  r = 0, g = 0, b = 0;
    
     
     context->gl->Lock( context->gl );

     glClearColor( r++/255.0, g++/255.0, b++/255.0, 1.0 );
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
     context->gl->Unlock( context->gl );
     
     if (context->fps) {
          char buf[16];

          snprintf(buf, sizeof(buf), "%.1f FPS\n", context->fps);

          surface->SetColor( surface, 0xff, 0x00, 0x00, 0xff );
          surface->DrawString( surface, buf, -1,
                               context->width - 5, 5, DSTF_TOPRIGHT );
     }
     
     surface->Flip( surface, NULL, 0 );

     context->frames++;

     t = get_millis();
     if (t - context->last_time >= 2000) {
          float seconds = (t - context->last_time) / 1000.0f;

          context->fps = context->frames / seconds;

          context->last_time = t;
          context->frames    = 0;
     }
}
示例#8
0
static void* render_loop (void *arg)
{
     IDirectFBSurface *view = (IDirectFBSurface*)arg;

     view->SetBlittingFlags( view, DSBLIT_SRC_COLORKEY | DSBLIT_COLORIZE );

     while (started_rendering()) {
          int i;

          pthread_testcancel();

          view->SetColor( view, 0, 0, 0, 0 );
          view->FillRectangle( view, 0, 0, xres, yres );

          for (i=0; i<STARFIELD_SIZE; i++) {
               int map = (int)(t_starfield[i].pos.v[Z]) >> 8;
               int light = 0xFF - ((int)(t_starfield[i].pos.v[Z] * t_starfield[i].pos.v[Z]) >> 12);

               if (map >= 0 && light > 0) {
                    if (map >= NUM_STARS)
                         map = NUM_STARS - 1;

                    view->SetColor( view, light, light, light, 0xff );
                    view->Blit( view, stars[map], NULL,
                                (int)(t_starfield[i].pos.v[X]),
                                (int)(t_starfield[i].pos.v[Y]) );
               }
          }

          view->Flip( view, NULL, DSFLIP_WAITFORSYNC );

          finished_rendering();
     }

     pthread_testcancel();

     return NULL;
}
int
main( int argc, char *argv[] )
{
     int                    i;
     DFBResult              ret;
     DFBSurfaceDescription  desc;
     IDirectFB             *dfb;
     IDirectFBSurface      *dest            = NULL;
     const char            *url             = NULL;
     DFBFontAttributes      attributes      = DFFA_NONE;
     DFBSurfaceTextFlags    text_flags      = DSTF_TOPLEFT;
     int                    outline_width   = 0x10000;
     int                    outline_opacity = 255;
     const DFBColorID       color_ids[2]    = { DCID_PRIMARY, DCID_OUTLINE };
     const DFBColor         colors[2]       = { { 0xff, 0xff, 0xff, 0xff },
                                                { 0xff, 0x00, 0x80, 0xff } };

     /* Initialize DirectFB. */
     ret = DirectFBInit( &argc, &argv );
     if (ret) {
          D_DERROR( ret, "DFBTest/Font: DirectFBInit() failed!\n" );
          return ret;
     }

     /* Parse arguments. */
     for (i=1; i<argc; i++) {
          const char *arg = argv[i];

          if (strcmp( arg, "-h" ) == 0 || strcmp (arg, "--help") == 0)
               return print_usage( argv[0] );
          else if (strcmp (arg, "-v") == 0 || strcmp (arg, "--version") == 0) {
               fprintf (stderr, "dfbtest_blit version %s\n", DIRECTFB_VERSION);
               return false;
          }
          else if (strcmp (arg, "-o") == 0 || strcmp (arg, "--outline") == 0) {
               attributes |= DFFA_OUTLINED;
               text_flags |= DSTF_OUTLINE;
          }
          else if (strcmp (arg, "-ow") == 0 || strcmp (arg, "--outline-width") == 0) {
               if (++i == argc)
                    return print_usage( argv[0] );

               if (sscanf( argv[i], "%d", &outline_width ) != 1)
                    return print_usage( argv[0] );

               outline_width <<= 16;
          }
          else if (strcmp (arg, "-oo") == 0 || strcmp (arg, "--outline-opacity") == 0) {
               if (++i == argc)
                    return print_usage( argv[0] );

               if (sscanf( argv[i], "%d", &outline_opacity ) != 1)
                    return print_usage( argv[0] );
          }
          else if (!url)
               url = arg;
          else
               return print_usage( argv[0] );
     }

     /* Check if we got an URL. */
     if (!url)
          return print_usage( argv[0] );

     /* Create super interface. */
     ret = DirectFBCreate( &dfb );
     if (ret) {
          D_DERROR( ret, "DFBTest/Font: DirectFBCreate() failed!\n" );
          return ret;
     }

     /* Fill description for a primary surface. */
     desc.flags = DSDESC_CAPS;
     desc.caps  = DSCAPS_PRIMARY | DSCAPS_FLIPPING;

     dfb->SetCooperativeLevel( dfb, DFSCL_FULLSCREEN );

     /* Create a primary surface. */
     ret = dfb->CreateSurface( dfb, &desc, &dest );
     if (ret) {
          D_DERROR( ret, "DFBTest/Font: IDirectFB::CreateSurface() failed!\n" );
          goto out;
     }

     dest->GetSize( dest, &desc.width, &desc.height );
     dest->GetPixelFormat( dest, &desc.pixelformat );

     D_INFO( "DFBTest/Font: Destination is %dx%d using %s\n",
             desc.width, desc.height, dfb_pixelformat_name(desc.pixelformat) );

     for (i=10; i<50; i++) {
          IDirectFBFont *font;

          font = CreateFont( dfb, url, i, attributes, outline_width, outline_opacity );

          RenderChecker( dest, 64, 64 );

          dest->SetColors( dest, color_ids, colors, 2 );

          dest->SetFont( dest, font );
          dest->DrawString( dest, "Test String AVAWA", -1, 100, 100, text_flags );

          dest->Flip( dest, NULL, DSFLIP_NONE );

          font->Release( font );

          usleep( 500000 );
     }


out:
     if (dest)
          dest->Release( dest );

     /* Shutdown DirectFB. */
     dfb->Release( dfb );

     return ret;
}
int
main( int argc, char *argv[] )
{
     DFBResult              ret;
     bool                   quit = false;
     int                    i;
     IDirectFB              dfb;
     IDirectFBDisplayLayer  layer;
     IDirectFBSurface       surface;
     DFBDisplayLayerConfig  config;
     DFBDimension           sizes[2]  = { {400, 400}, {600, 600} };
     size_t                 num_sizes = D_ARRAY_SIZE(sizes);
     DFBInputEvent          evt;
     IDirectFBEventBuffer   keybuffer;

     /* Initialize DirectFB. */
     DirectFB::Init( &argc, &argv );

     /* Create super interface. */
     dfb = DirectFB::Create();

     layer = dfb.GetDisplayLayer( DLID_PRIMARY );

     /* Create an input buffer for key events */
     keybuffer = dfb.CreateInputEventBuffer( DICAPS_KEYS, DFB_TRUE );

     layer.SetCooperativeLevel( DLSCL_EXCLUSIVE );

     layer.GetConfiguration( &config );

     config.width  = sizes[0].w;
     config.height = sizes[0].h;

     layer.SetConfiguration( config );

     surface = layer.GetSurface();

     while (true) {
          surface.Clear( 0, 0, 0, 0xff );

          surface.SetColor( 0x00, 0xff, 0x00, 0xff );
          surface.DrawRectangle( 0, 0, config.width, config.height );

          surface.Flip( NULL, DSFLIP_NONE );


          keybuffer.WaitForEventWithTimeout( 3, 0 );

          /* Process keybuffer */
          while (keybuffer.GetEvent( DFB_EVENT(&evt) )) {
              if (evt.type == DIET_KEYPRESS) {
                  switch (DFB_LOWER_CASE(evt.key_symbol)) {
                      case DIKS_ESCAPE:
                      case DIKS_SMALL_Q:
                      case DIKS_BACK:
                      case DIKS_STOP:
                      case DIKS_EXIT:
                          /* Quit main loop & test thread */
                          quit = 1;
                          break;

                      case DIKS_SPACE:
                      case DIKS_OK:
                          i++;

                          config.width  = sizes[i % num_sizes].w;
                          config.height = sizes[i % num_sizes].h;

                          layer.SetConfiguration( config );
                          break;

                      default:
                          break;
                  }
              }
          }
     }

     return 0;
}
示例#11
0
int
main( int argc, char *argv[] )
{
     int                     i;
     DFBResult               ret;
     DFBSurfaceDescription   desc;
     IDirectFB              *dfb;
     IDirectFBImageProvider *provider      = NULL;
     IDirectFBSurface       *source        = NULL;
     IDirectFBSurface       *dest          = NULL;
     const char             *url           = NULL;
     DFBSurfacePixelFormat   source_format = DSPF_UNKNOWN;
     DFBSurfacePixelFormat   dest_format   = DSPF_UNKNOWN;
     bool                    dest_resize   = false;

     /* Initialize DirectFB. */
     ret = DirectFBInit( &argc, &argv );
     if (ret) {
          D_DERROR( ret, "DFBTest/Blit: DirectFBInit() failed!\n" );
          return ret;
     }

     /* Parse arguments. */
     for (i=1; i<argc; i++) {
          const char *arg = argv[i];

          if (strcmp( arg, "-h" ) == 0 || strcmp (arg, "--help") == 0)
               return print_usage( argv[0] );
          else if (strcmp (arg, "-v") == 0 || strcmp (arg, "--version") == 0) {
               fprintf (stderr, "dfbtest_blit version %s\n", DIRECTFB_VERSION);
               return false;
          }
          else if (strcmp (arg, "-s") == 0 || strcmp (arg, "--source") == 0) {
               if (++i == argc) {
                    print_usage (argv[0]);
                    return false;
               }

               if (!parse_format( argv[i], &source_format ))
                    return false;
          }
          else if (strcmp (arg, "-d") == 0 || strcmp (arg, "--dest") == 0) {
               if (++i == argc) {
                    print_usage (argv[0]);
                    return false;
               }

               if (!parse_format( argv[i], &dest_format ))
                    return false;
          }
          else if (strcmp (arg, "-r") == 0 || strcmp (arg, "--resize") == 0)
               dest_resize = true;
          else if (!url)
               url = arg;
          else
               return print_usage( argv[0] );
     }

     /* Check if we got an URL. */
     if (!url)
          return print_usage( argv[0] );
          
     /* Create super interface. */
     ret = DirectFBCreate( &dfb );
     if (ret) {
          D_DERROR( ret, "DFBTest/Blit: DirectFBCreate() failed!\n" );
          return ret;
     }

     /* Create an image provider for the image to be loaded. */
     ret = dfb->CreateImageProvider( dfb, url, &provider );
     if (ret) {
          D_DERROR( ret, "DFBTest/Blit: IDirectFB::CreateImageProvider( '%s' ) failed!\n", url );
          goto out;
     }

     /* Get the surface description. */
     ret = provider->GetSurfaceDescription( provider, &desc );
     if (ret) {
          D_DERROR( ret, "DFBTest/Blit: IDirectFBImageProvider::GetSurfaceDescription() failed!\n" );
          goto out;
     }

     if (source_format != DSPF_UNKNOWN)
          desc.pixelformat = source_format;
     
     D_INFO( "DFBTest/Blit: Source is %dx%d using %s\n",
             desc.width, desc.height, dfb_pixelformat_name(desc.pixelformat) );

     /* Create a surface for the image. */
     ret = dfb->CreateSurface( dfb, &desc, &source );
     if (ret) {
          D_DERROR( ret, "DFBTest/Blit: IDirectFB::CreateSurface() failed!\n" );
          goto out;
     }
     
     ret = provider->RenderTo( provider, source, NULL );
     if (ret) {
          D_DERROR( ret, "DFBTest/Blit: IDirectFBImageProvider::RenderTo() failed!\n" );
          goto out;
     }

     /* Fill description for a primary surface. */
     desc.flags = DSDESC_CAPS;
     desc.caps  = DSCAPS_PRIMARY | DSCAPS_FLIPPING;

     if (dest_format != DSPF_UNKNOWN) {
          desc.flags       |= DSDESC_PIXELFORMAT;
          desc.pixelformat  = dest_format;
     }

     if (dest_resize)
          desc.flags |= DSDESC_WIDTH | DSDESC_HEIGHT;

     dfb->SetCooperativeLevel( dfb, DFSCL_FULLSCREEN );

     /* Create a primary surface. */
     ret = dfb->CreateSurface( dfb, &desc, &dest );
     if (ret) {
          D_DERROR( ret, "DFBTest/Blit: IDirectFB::CreateSurface() failed!\n" );
          goto out;
     }

     dest->GetSize( dest, &desc.width, &desc.height );
     dest->GetPixelFormat( dest, &desc.pixelformat );

     D_INFO( "DFBTest/Blit: Destination is %dx%d using %s\n",
             desc.width, desc.height, dfb_pixelformat_name(desc.pixelformat) );

     for (i=0; i<100000; i++) {
          int j,n = rand()%100;

          for (j=0; j<n; j++) {
               switch (rand()%3) {
                    case 0:
                         dest->SetDrawingFlags( dest, rand() & (DSDRAW_BLEND) );
                         dest->FillRectangle( dest, rand()%100, rand()%100, rand()%100, rand()%100 );
                         break;

                    case 1:
                         dest->SetBlittingFlags( dest, rand() & (DSBLIT_BLEND_ALPHACHANNEL |
                                                                 DSBLIT_BLEND_COLORALPHA   |
                                                                 DSBLIT_COLORIZE           |
                                                                 DSBLIT_ROTATE90) );
                         dest->Blit( dest, source, NULL, rand()%100, rand()%100 );
                         break;

                    case 2:
                         dest->SetBlittingFlags( dest, rand() & (DSBLIT_BLEND_ALPHACHANNEL |
                                                                 DSBLIT_BLEND_COLORALPHA   |
                                                                 DSBLIT_COLORIZE           |
                                                                 DSBLIT_ROTATE90) );
                         dest->StretchBlit( dest, source, NULL, NULL );
                         break;
               }
          }

          dfb->WaitIdle( dfb );

          dest->Flip( dest, NULL, DSFLIP_NONE );
     }

out:
     if (dest)
          dest->Release( dest );

     if (source)
          source->Release( source );

     if (provider)
          provider->Release( provider );

     /* Shutdown DirectFB. */
     dfb->Release( dfb );

     return ret;
}
示例#12
0
文件: test_pcba.c 项目: vonfritz/owl
static void *handle_record_button(DirectThread *thread, void *arg)
{
	IDirectFBSurface *surface = arg;
	IDirectFBFont 		*font, *font_s;
	DFBFontDescription 	font_desc;
	bool local_flg = false;
	int width, height;
	int font_big_height, font_little_height;
	
	char font_file[50] = "/misc/font/wqy-zenhei.ttc";
	
	DFBCHECK(surface->GetSize(surface, &width, &height));
	
	font_big_height = 48;
	while(font_big_height > (height / 2))
	{
		font_big_height -= 4;
	}
	font_desc.flags = DFDESC_HEIGHT;
	font_desc.height = font_big_height;
	DFBCHECK(dfb->CreateFont( dfb, font_file,  &font_desc, &font));
	
	font_little_height = 32;
	while(font_little_height > (height / 4))
	{
		font_little_height -= 4;
	}
	font_desc.height = font_little_height;
	DFBCHECK(dfb->CreateFont( dfb, font_file,  &font_desc, &font_s));
	
	printf("font size is %d %d\n", font_big_height, font_little_height);
	
	DFBCHECK(surface->SetFont(surface, font_s));
	
	DFBCHECK(surface->SetColor(surface, 0x8C, 0x8C, 0x8C, 0xff));
	DFBCHECK(surface->DrawString(surface, "点击录音", -1, width / 2, 0, DSTF_TOPCENTER));
	
	DFBCHECK(surface->SetColor(surface, 0x41, 0x41, 0x41, 0xff));
	DFBCHECK(surface->DrawString(surface, "测试TP请避开此区域", -1, width / 2, height / 4, DSTF_TOPCENTER));
	
	DFBCHECK(surface->SetFont(surface, font));
	DFBCHECK(surface->SetColor(surface, 0xE3, 0x6C, 0x4C, 0xff));
	DFBCHECK(surface->DrawString(surface, "状态:停止录音", -1, width / 2, height / 2, DSTF_TOPCENTER));
	DFBCHECK(surface->Flip(surface, NULL, 0));
	while(true)
	{
		if(record_flg != local_flg)
		{
			local_flg = record_flg;
			DFBCHECK(surface->SetColor(surface, 0xff, 0xff, 0xff, 0xff));
			DFBCHECK(surface->FillRectangle(surface, 0 , height / 2, width, font_big_height + 4));  //need fix
			DFBCHECK(surface->SetColor(surface, 0xE3, 0x6C, 0x4C, 0xff));
			if(local_flg)
			{
				DFBCHECK(surface->DrawString(surface, "状态:正在录音", -1, width / 2, height / 2, DSTF_TOPCENTER));
			}
			else
			{
				DFBCHECK(surface->DrawString(surface, "状态:停止录音", -1, width / 2, height / 2, DSTF_TOPCENTER));
			}
			DFBCHECK(surface->Flip(surface, NULL, 0));
		}
		direct_thread_sleep(100000);
	}
	
	font->Release(font);
	font_s->Release(font_s);
}
示例#13
0
 void EndRender()
 {
    mPrimarySurface->Flip(mPrimarySurface, NULL, (DFBSurfaceFlipFlags)0);
 }
示例#14
0
int
main( int argc, char *argv[] )
{
     DFBResult               ret;
     int                     i;
     DFBSurfaceDescription   desc;
     IDirectFB              *dfb;
     IDirectFBSurface       *dest          = NULL;
     DFBSurfacePixelFormat   dest_format   = DSPF_UNKNOWN;
     char                    pixel_buffer[100*100*4];
     IDirectFBSurface       *source        = NULL;
     IDirectFBEventBuffer   *keybuffer;
     DFBInputEvent           evt;
     bool                    quit          = false;

     /* Initialize DirectFB. */
     ret = DirectFBInit( &argc, &argv );
     if (ret) {
          D_DERROR( ret, "DFBTest/PreAlloc: DirectFBInit() failed!\n" );
          return ret;
     }

     /* Parse arguments. */
     for (i=1; i<argc; i++) {
          const char *arg = argv[i];

          if (strcmp( arg, "-h" ) == 0 || strcmp (arg, "--help") == 0)
               return print_usage( argv[0] );
          else if (strcmp (arg, "-v") == 0 || strcmp (arg, "--version") == 0) {
               fprintf (stderr, "dfbtest_blit version %s\n", DIRECTFB_VERSION);
               return false;
          }
          else if (strcmp (arg, "-d") == 0 || strcmp (arg, "--dest") == 0) {
               if (++i == argc) {
                    print_usage (argv[0]);
                    return false;
               }

               if (!parse_format( argv[i], &dest_format ))
                    return false;
          }
          else if (strcmp (arg, "-s") == 0 || strcmp (arg, "--static") == 0) {
               static_caps = DSCAPS_STATIC_ALLOC;
          }
          else
               return print_usage( argv[0] );
     }

     /* Create super interface. */
     ret = DirectFBCreate( &dfb );
     if (ret) {
          D_DERROR( ret, "DFBTest/PreAlloc: DirectFBCreate() failed!\n" );
          return ret;
     }

     /* Fill description for a primary surface. */
     desc.flags = DSDESC_CAPS;
     desc.caps  = DSCAPS_PRIMARY | DSCAPS_FLIPPING;

     if (dest_format != DSPF_UNKNOWN) {
          desc.flags       |= DSDESC_PIXELFORMAT;
          desc.pixelformat  = dest_format;
     }

     dfb->SetCooperativeLevel( dfb, DFSCL_FULLSCREEN );

     /* Create an input buffer for key events */
     dfb->CreateInputEventBuffer( dfb, DICAPS_KEYS,
                                  DFB_TRUE, &keybuffer);

     /* Create a primary surface. */
     ret = dfb->CreateSurface( dfb, &desc, &dest );
     if (ret) {
          D_DERROR( ret, "DFBTest/PreAlloc: IDirectFB::CreateSurface() for the destination failed!\n" );
          goto out;
     }

     dest->GetSize( dest, &desc.width, &desc.height );
     dest->GetPixelFormat( dest, &desc.pixelformat );

     D_INFO( "DFBTest/PreAlloc: Destination is %dx%d using %s\n",
             desc.width, desc.height, dfb_pixelformat_name(desc.pixelformat) );

     /* Create a preallocated surface. */
     desc.flags                 = DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS | DSDESC_PREALLOCATED;
     desc.width                 = 100;
     desc.height                = 100;
     desc.pixelformat           = DSPF_ARGB;
     desc.caps                  = static_caps;
     desc.preallocated[0].data  = pixel_buffer;
     desc.preallocated[0].pitch = 100 * 4;

     ret = dfb->CreateSurface( dfb, &desc, &source );
     if (ret) {
          D_DERROR( ret, "DFBTest/PreAlloc: IDirectFB::CreateSurface() for the preallocated source failed!\n" );
          goto out;
     }

     /* Before any other operation the pixel data can be written to without locking */
     gen_pixels( pixel_buffer, 100 * 4, 100 );

     while (!quit) {
          void *ptr;
          int   pitch;


          /* Lock source surface for writing before making updates to the pixel buffer */
          source->Lock( source, DSLF_WRITE, &ptr, &pitch );

          if (ptr == pixel_buffer)
               D_INFO( "DFBTest/PreAlloc: Locking preallocated source gave original preallocated pixel buffer :-)\n" );
          else {
               if (static_caps)
                    D_INFO( "DFBTest/PreAlloc: Locking preallocated source gave different pixel buffer, ERROR with static alloc!\n" );
               else
                    D_INFO( "DFBTest/PreAlloc: Locking preallocated source gave different pixel buffer, but OK (no static alloc)\n" );
          }

          update_pixels( ptr, pitch, 100 );

          /* Unlock source surface after writing, before making further Blits,
             to have the buffer be transfered to master again */
          source->Unlock( source );


          dest->Clear( dest, 0, 0, 0, 0xff );

          /* First Blit from preallocated source, data will be transfered to master */
          dest->Blit( dest, source, NULL, 50, 50 );

          /* Second Blit from preallocated source, data is already master */
          dest->Blit( dest, source, NULL, 150, 150 );

          dest->Flip( dest, NULL, DSFLIP_NONE );

          /* This will upload again the preallocated buffer to the master, where it is
             modified and outdates the preallocated buffer. Now it depends on the static
             alloc flag whether the next Lock will directly go into the shared memory
             allocation or the preallocated buffer again (with a transfer back from master
             to us). */
          source->FillRectangle( source, 0, 0, 10, 10 );

          /* Process keybuffer */
          while (keybuffer->GetEvent( keybuffer, DFB_EVENT(&evt)) == DFB_OK)
          {
              if (evt.type == DIET_KEYPRESS) {
                  switch (DFB_LOWER_CASE(evt.key_symbol)) {
                      case DIKS_ESCAPE:
                      case DIKS_SMALL_Q:
                      case DIKS_BACK:
                      case DIKS_STOP:
                      case DIKS_EXIT:
                          /* Quit main loop & test thread */
                          quit = true;
                          break;
                      default:
                          break;
                  }
              }
          }
          if (!quit)
          sleep( 5 );
     }

out:
     if (source)
          source->Release( source );

     if (dest)
          dest->Release( dest );

     keybuffer->Release( keybuffer );

     /* Shutdown DirectFB. */
     dfb->Release( dfb );

     return ret;
}
示例#15
0
//------------------------------------------------------------------------------
//  Unit Test main
//------------------------------------------------------------------------------
int main (int argc, char **argv)
{
    int i, j;
    DFBResult rle_build_databuffer_err;

    //    File name to load logo image from
    char *filename                           = NULL;

    //    Basic directfb elements
    IDirectFB               *dfb             = NULL;
    IDirectFBSurface        *primary         = NULL;
    int                      screen_width    = 0;
    int                      screen_height   = 0;

    //    The image is to be loaded into a surface that we can blit from.
    IDirectFBSurface         *logo           = NULL;

    //    Loading an image is done with an Image Provider.
    IDirectFBImageProvider   *provider       = NULL;

    //    An Image provider instance can also be created from a directfb buffer
    IDirectFBDataBuffer      *databuffer     = NULL;

    //    Surface description
    DFBSurfaceDescription     surface_dsc;



    //    Initialize directfb first
    DFBCHECK (DirectFBInit (&argc, &argv));
    DFBCHECK (DirectFBCreate (&dfb));
    DFBCHECK (dfb->SetCooperativeLevel (dfb, DFSCL_FULLSCREEN));


    //  Create primary surface
    surface_dsc.flags = DSDESC_CAPS;
    surface_dsc.caps  = DSCAPS_PRIMARY | DSCAPS_FLIPPING;
    DFBCHECK (dfb->CreateSurface( dfb, &surface_dsc, &primary ));
    DFBCHECK (primary->GetSize (primary, &screen_width, &screen_height));

    if (argc==1)
    {
        argv[1] = "./data/directfb.rle";
        argc++;
    }

    DISPLAY_INFO ("Rendering %d files\n",argc-1);
    for (j=1; j<argc; j++)
    {

        //
        //  --- WE CREATE OUR IMAGE PROVIDER INSTANCE HERE
        //
        filename     =     argv[j];
        DISPLAY_INFO ("Rendering : %s\n",filename);

        //  We create a directfb data buffer holding RLE image contents that we
        //  pick up from a file (could get the RLE contents from memory as well).
        //  "rle_build_databuffer" details the process of dealing with a memory
        //  RLE packet as a matter of fact.
        rle_build_databuffer_err = rle_build_databuffer (dfb, filename, &databuffer);
        if (rle_build_databuffer_err == DFB_OK) {
            //  We want to create an Image Provider tied to a directfb data buffer.
            //  DirectFB will find (or not) an Image Provider for the data type
            //  depending on Image Providers probe method (sniffing data headers)
            DFBCHECK (databuffer->CreateImageProvider (databuffer, &provider));
        }
        else {
#       ifdef   USE_PACKET_BUILDER_ONLY
            DFBFAIL(rle_build_databuffer_err);
#       else
            //  We could also create an Image Provider by passing a filename.
            //  DirectFB will find (or not) an Image Provider matching the file type.
            DFBCHECK (dfb->CreateImageProvider (dfb, filename, &provider));
#       endif
        }



        //    Get a surface description from the provider. It will contain the width,
        //    height, bits per pixel and the flag for an alphachannel if the image
        //    has one. If the image has no alphachannel the bits per pixel is set to
        //    the bits per pixel of the primary layer to use simple blitting without
        //    pixel format conversion.
        DFBCHECK (provider->GetSurfaceDescription (provider, &surface_dsc));

        //    Create a surface based on the description of the provider.
        DFBCHECK (dfb->CreateSurface( dfb, &surface_dsc, &logo ));

        //    Let the provider render to our surface. Image providers are supposed
        //    to support every destination pixel format and size. If the size
        //    differs the image will be scaled (bilinear). The last parameter allows
        //    to specify an optional destination rectangle. We use NULL here so that
        //    our image covers the whole logo surface.
        DFBCHECK (provider->RenderTo (provider, logo, NULL));
        //    Note: RLE Image Provider allows for direct non-scaled LUT-8 surface
        //          rendering without any attached colormap.

        #ifdef CLEVER_APPROACH
        //    Let's setup our logo surface palette outside of the RLE Image
        //    Provider if we got a colormap from rle_build_databuffer ...
        if (color_palette)
        {
            IDirectFBPalette *palette;
            DFBCHECK (logo->GetPalette (logo, &palette));
            palette->SetEntries (palette, color_palette, number_of_colors, 0);
            palette->Release (palette);
        }
        #endif

        //
        //  --- WE GET RID OF OUR IMAGE PROVIDER INSTANCE HERE
        //
        //    Release the provider, we don't need it anymore.
        provider->Release (provider);           provider    = NULL;
        //    Destroy the databuffer as well, we don't need it anymore.
        rle_destroy_databuffer (databuffer);    databuffer  = NULL;


#   ifndef SUBTITLES_MODE
        //    We want to let the logo slide in on the left and slide out on the
        //    right.
        for (i = -surface_dsc.width; i < screen_width; i++)
#   else
        //    We want to let the logo slide in on the right and slide out on the
        //    left.
        for (i = screen_width-1; i >= -surface_dsc.width; i--)
#   endif
        {
            //    Clear the screen.
            DFBCHECK (primary->FillRectangle (primary, 0, 0,
                                              screen_width, screen_height));

            //    Blit the logo vertically centered with "i" as the X coordinate.
            //    NULL means that we want to blit the whole surface.
            DFBCHECK (primary->Blit (primary, logo, NULL, i,
                                     (screen_height - surface_dsc.height) / 2));

            //    Flip the front and back buffer, but wait for the vertical
            //    retrace to avoid tearing.
            DFBCHECK (primary->Flip (primary, NULL, DSFLIP_WAITFORSYNC));

            if (argc < 3)
            {
                usleep(1000*5);
            }
        }

        //    Release the image.
        if (logo)
        {
            logo->Release (logo);
        }

   }

   //    Release everything else
   primary->Release (primary);
   dfb->Release (dfb);

   return 0;
}
示例#16
0
static DFBResult
app_init( App                   *app,
          IDirectFBDisplayLayer *layer,
          int                    x,
          int                    y,
          int                    width,
          int                    height,
          int                    index )
{
     DFBResult             ret;
     DFBWindowDescription  desc;
     IDirectFBWindow      *window;
     IDirectFBSurface     *surface;

     desc.flags  = DWDESC_WIDTH | DWDESC_HEIGHT | DWDESC_POSX | DWDESC_POSY | DWDESC_CAPS;
     desc.width  = width;
     desc.height = height;
     desc.posx   = x;
     desc.posy   = y;
     desc.caps   = DWCAPS_NONE; //| DWCAPS_ALPHACHANNEL | DWCAPS_DOUBLEBUFFER;

     /* Create a surface for the image. */
     ret = layer->CreateWindow( layer, &desc, &window );
     if (ret) {
          D_DERROR( ret, "DFBTest/WindowFlip: IDirectFBDisplayLayer::CreateWindow() failed!\n" );
          return ret;
     }

     /* Get the surface. */
     ret = window->GetSurface( window, &surface );
     if (ret) {
          D_DERROR( ret, "DFBTest/WindowFlip: IDirectFBWindow::GetSurface() failed!\n" );
          return ret;
     }

     surface->Clear( surface, 0xff, 0xff, 0xff, 0xff );

     surface->Flip( surface, NULL, DSFLIP_NONE );


     direct_thread_sleep( 2000000 );
     D_INFO( "Showing window...\n" );
     direct_thread_sleep( 500000 );

     window->SetOpacity( window, 0xff );

     direct_thread_sleep( 500000 );
     D_INFO( "Done.\n" );
     direct_thread_sleep( 1000000 );

     app->window       = window;
     app->surface      = surface;
     app->index        = index;
     app->resolution.w = width;
     app->resolution.h = height;

     app->anim_dirx    = 5;
     app->anim_diry    = 5;
     app->anim_x       = 0;
     app->anim_y       = 0;

     return DFB_OK;
}
示例#17
0
int
main( int argc, char *argv[] )
{
     DFBResult              ret;
     int                    i;
     int                    x, y;
     int                    dx, dy;
     int                    sw3, sh3;
     int                    opacity       = 255;
     int                    opacity_delta = -1;
     IDirectFB             *dfb;
     IDirectFBDisplayLayer *layer;
     IDirectFBSurface      *surface;
     DFBDisplayLayerConfig  config;
     DFBDimension           size;
     DFBInputEvent          evt;

     /* Initialize DirectFB. */
     ret = DirectFBInit( &argc, &argv );
     if (ret) {
          D_DERROR( ret, "DFBTest/Layer: DirectFBInit() failed!\n" );
          return ret;
     }


     /* Create super interface. */
     ret = DirectFBCreate( &dfb );
     if (ret) {
          D_DERROR( ret, "DFBTest/Layer: DirectFBCreate() failed!\n" );
          return ret;
     }

     dfb->GetDisplayLayer( dfb, DLID_PRIMARY, &layer );

     /* Create an input buffer for key events */
     dfb->CreateInputEventBuffer( dfb, DICAPS_KEYS,
                                  DFB_TRUE, &keybuffer);

     layer->SetCooperativeLevel( layer, DFSCL_EXCLUSIVE );

     layer->GetConfiguration( layer, &config );


     config.options    = DLOP_OPACITY | DLOP_SRC_COLORKEY;
     config.buffermode = DLBM_FRONTONLY;

     layer->SetConfiguration( layer, &config );
     layer->SetSrcColorKey( layer, 0x00, 0xff, 0x00 );



     ret = layer->GetSurface( layer, &surface );
     if (ret) {
          D_DERROR( ret, "DFBTest/Layer: GetSurface() failed!\n" );
          dfb->Release( dfb );
          return ret;
     }

     surface->GetSize( surface, &size.w, &size.h );

     sw3 = ((size.w / 3) + 1) & ~1;
     sh3 = ((size.h / 3) + 1) & ~1;


     surface->Clear( surface, 0, 0, 0, 0xff );

     for (i=0; i<10; i++) {
          surface->SetColor( surface, 0xff - i*16, 0xff - i*16, 0xff - i*16, 0xff );
          surface->DrawRectangle( surface, i, i, size.w - i*2, size.h - i*2 );
     }

     surface->FillRectangle( surface, 10, size.h/2, size.w - 20, 1 );
     surface->FillRectangle( surface, size.w/2, 10, 1, size.h - 20 );

     surface->SetColor( surface, 0xff, 0x00, 0x00, 0xff );
     surface->FillRectangle( surface, size.w/3, size.h/3, size.w/3, size.h/3 );

     surface->SetColor( surface, 0x00, 0xff, 0x00, 0xff );
     surface->FillRectangle( surface, size.w/3 + size.w/9, size.h/3 + size.h/9, size.w/9, size.h/9 );

     surface->Flip( surface, NULL, DSFLIP_NONE );

#ifdef BUILD_AUTOMATION
     sleep( 2 );
#else
     sleep( 12 );
#endif
     layer->SetSourceRectangle( layer, 0, 0, size.w - sw3, size.h - sh3 );

     layer->SetScreenPosition( layer, 100, 100 );
     layer->SetScreenRectangle( layer, 100, 100, size.w - sw3, size.h - sh3 );

     sleep( 2 );
#ifdef BUILD_AUTOMATION
     sleep( 20 );
     quit = 1;
#endif

     for (x=0, y=0, dx=1, dy=1; !quit ; x+=dx, y+=dy) {
          layer->SetOpacity( layer, opacity );

          if (opacity == 255)
               opacity_delta = -1;
          else if (opacity == 0)
               opacity_delta = 1;

          opacity += opacity_delta;


          layer->SetSourceRectangle( layer, x, y, size.w - sw3, size.h - sh3 );

          surface->Flip( surface, NULL, DSFLIP_UPDATE );

          if (dx > 0) {
               if (x == size.w/3) {
                    dx = -1;

                    usleep( 500000 );
               }
          }
          else if (x == 0) {
               dx = 1;

               usleep( 500000 );
          }

          if (dy > 0) {
               if (y == size.h/3) {
                    dy = -1;

                    usleep( 500000 );
               }
          }
          else if (y == 0) {
               dy = 1;

               usleep( 500000 );
          }

          usleep( 10000 );

          /* Process keybuffer */
          while (keybuffer->GetEvent( keybuffer, DFB_EVENT(&evt)) == DFB_OK)
          {
              if (evt.type == DIET_KEYPRESS) {
                  switch (DFB_LOWER_CASE(evt.key_symbol)) {
                      case DIKS_ESCAPE:
                      case DIKS_SMALL_Q:
                      case DIKS_BACK:
                      case DIKS_STOP:
                      case DIKS_EXIT:
                          /* Quit main loop & test thread */
                          quit = 1;
                          break;
                      default:
                          break;
                  }
              }
          }

     }

     surface->Release( surface );
     layer->Release( layer );

     /* Shutdown DirectFB. */
     dfb->Release( dfb );

     return ret;
}