static int
DirectFB_RenderFillRects(SDL_Renderer * renderer, const SDL_FRect * rects, int count)
{
    DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
    IDirectFBSurface *destsurf = data->target;
    DFBRegion clip_region;
    int i;

    DirectFB_ActivateRenderer(renderer);

    PrepareDraw(renderer);

    destsurf->GetClip(destsurf, &clip_region);
    for (i=0; i<count; i++) {
        SDL_Rect dst = {rects[i].x, rects[i].y, rects[i].w, rects[i].h};
        dst.x += clip_region.x1;
        dst.y += clip_region.y1;
        SDL_DFB_CHECKERR(destsurf->FillRectangle(destsurf, dst.x, dst.y,
                dst.w, dst.h));
    }

    return 0;
  error:
    return -1;
}
Beispiel #2
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;
}
Beispiel #3
0
static int l_FillRectangle (lua_State* L)
{
	// [ sfc | x | y | w | h ]
	IDirectFBSurface* sfc = * (IDirectFBSurface**) luaL_checkudata(L, 1, "ldirectfb.IDirectFBSurface");
	DFBCHECK (sfc->FillRectangle(sfc, luaL_checknumber(L, 2), luaL_checknumber(L, 3), luaL_checknumber(L, 4), luaL_checknumber(L, 5)));
	return 0;
}
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;
          
}
Beispiel #5
0
static mrb_value surface_fill_rectangle(mrb_state *mrb, mrb_value self)
{
    IDirectFBSurface* surface = mrb_directfb_surface(mrb, self);
    DFBResult ret = -1;
    if (surface != NULL) {
        mrb_int x, y, width, height;
        mrb_get_args(mrb, "iiii", &x, &y, &width, &height);
        ret = surface->FillRectangle(surface, x, y, width, height);
    }
    return mrb_fixnum_value(ret);
}
static int
DirectFB_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect * rects, int count)
{
    DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
	IDirectFBSurface *destsurf = get_dfb_surface(data->window);
    int i;

    DirectFB_ActivateRenderer(renderer);

    PrepareDraw(renderer);

    for (i=0; i<count; i++)
    	SDL_DFB_CHECKERR(destsurf->FillRectangle(destsurf, rects[i].x, rects[i].y,
    			rects[i].w, rects[i].h));

    return 0;
  error:
    return -1;
}
Beispiel #7
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;
}
Beispiel #8
0
void
DirectFB_WM_RedrawLayout(_THIS, SDL_Window * window)
{
    SDL_DFB_WINDOWDATA(window);
    IDirectFBSurface *s = windata->window_surface;
    DFB_Theme *t = &windata->theme;
    int i;
    int d = (t->caption_size - t->font_size) / 2;
    int x, y, w;


    if (!windata->is_managed || (window->flags & SDL_WINDOW_FULLSCREEN))
        return;

    SDL_DFB_CHECK(s->SetSrcBlendFunction(s, DSBF_ONE));
    SDL_DFB_CHECK(s->SetDstBlendFunction(s, DSBF_ZERO));
    SDL_DFB_CHECK(s->SetDrawingFlags(s, DSDRAW_NOFX));
    SDL_DFB_CHECK(s->SetBlittingFlags(s, DSBLIT_NOFX));

    LoadFont(_this, window);
    /* s->SetDrawingFlags(s, DSDRAW_BLEND); */
    s->SetColor(s, COLOR_EXPAND(t->frame_color));
    /* top */
    for (i = 0; i < t->top_size; i++)
        s->DrawLine(s, 0, i, windata->size.w, i);
    /* bottom */
    for (i = windata->size.h - t->bottom_size; i < windata->size.h; i++)
        s->DrawLine(s, 0, i, windata->size.w, i);
    /* left */
    for (i = 0; i < t->left_size; i++)
        s->DrawLine(s, i, 0, i, windata->size.h);
    /* right */
    for (i = windata->size.w - t->right_size; i < windata->size.w; i++)
        s->DrawLine(s, i, 0, i, windata->size.h);
    /* Caption */
    s->SetColor(s, COLOR_EXPAND(t->caption_color));
    s->FillRectangle(s, t->left_size, t->top_size, windata->client.w,
                     t->caption_size);
    /* Close Button */
    w = t->caption_size;
    x = windata->size.w - t->right_size - w + d;
    y = t->top_size + d;
    s->SetColor(s, COLOR_EXPAND(t->close_color));
    DrawTriangle(s, 1, x, y, w - 2 * d);
    /* Max Button */
    s->SetColor(s, COLOR_EXPAND(t->max_color));
    DrawTriangle(s, window->flags & SDL_WINDOW_MAXIMIZED ? 1 : 0, x - w,
               y, w - 2 * d);

    /* Caption */
    if (*window->title) {
        s->SetColor(s, COLOR_EXPAND(t->font_color));
        DrawCraption(_this, s, (x - w) / 2, t->top_size + d, window->title);
    }
    /* Icon */
    if (windata->icon) {
        DFBRectangle dr;

        dr.x = t->left_size + d;
        dr.y = t->top_size + d;
        dr.w = w - 2 * d;
        dr.h = w - 2 * d;
        s->SetBlittingFlags(s, DSBLIT_BLEND_ALPHACHANNEL);

        s->StretchBlit(s, windata->icon, NULL, &dr);
    }
    windata->wm_needs_redraw = 0;
}
Beispiel #9
0
static DFBResult
Test_CreateSubWindow( IDirectFBDisplayLayer *layer, void *arg )
{
    IDirectFBWindow      *window;
    DFBWindowID           window_id;
    DFBDimension          size = { m_desc_sub.width, m_desc_sub.height };

    D_ASSERT( m_toplevel_id != 0 );

    /* Write window ID of top level into description */
    m_desc_sub.toplevel_id = m_toplevel_id;

    /*
     * Create a new sub window with 75% width/height and positioned at 20,20 within top level window
     */
    SHOW_TEST( "CreateWindow( %d,%d - %dx%d %s + toplevel ID %u, options 0x%08x )...",
               m_desc_sub.posx, m_desc_sub.posy, m_desc_sub.width, m_desc_sub.height,
               dfb_pixelformat_name( m_desc_sub.pixelformat ), m_desc_sub.toplevel_id, m_desc_top.options );

    _T( layer->CreateWindow( layer, &m_desc_sub, &window ) );

    if (m_subcolor.valid) {
        DFBColor c = m_subcolor.color;

        SHOW_INFO( "  - SetColor( 0x%02x, 0x%02x, 0x%02x, 0x%02x )...", c.r, c.g, c.b, c.a );

        _T( window->SetColor( window, c.r, c.g, c.b, c.a ) );
    }

    /*
     * Query its surface and clear it with light gray (if not input or color only)
     */
    if (!(m_desc_sub.caps & (DWCAPS_INPUTONLY | DWCAPS_COLOR) )) {
        IDirectFBSurface     *surface;

        SHOW_INFO( "  - GetSurface()..." );

        _T( window->GetSurface( window, &surface ) );

        SHOW_INFO( "  - Clear( 0xC0, 0xC0, 0xC0, 0xFF )..." );

        _T( surface->Clear( surface, 0xC0, 0xC0, 0xC0, 0xFF ) );

        _T( surface->DrawRectangle( surface, 0, 0, size.w, size.h ) );

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

        surface->Release( surface );
    }

    /*
     * Show the window
     */
    SHOW_INFO( "  - SetOpacity( 255 )..." );

    _T( window->SetOpacity( window, 0xff ) );

    /*
     * Query and print ID of new window
     */
    SHOW_INFO( "  - GetID()..." );

    _T( window->GetID( window, &window_id ) );

    /*
     * Set association of new window
     */
    if (m_desc_sub.parent_id) {
        SHOW_INFO( "  - SetAssociation( %u )...", m_desc_sub.parent_id );

        _T( window->SetAssociation( window, m_desc_sub.parent_id ) );
    }

    /*
     * Set top level window ID (user hasn't specified one)
     */
    m_subwindow_id = window_id;
    m_subwindow    = window;

    SHOW_RESULT( "...CreateWindow( %d,%d - %dx%d %s + toplevel ID %u ) done. => Sub Window ID %u",
                 m_desc_sub.posx, m_desc_sub.posy, m_desc_sub.width, m_desc_sub.height,
                 dfb_pixelformat_name( m_desc_sub.pixelformat ), m_desc_sub.toplevel_id, window_id );

    return DFB_OK;
}
Beispiel #10
0
int main (int argc,char *argv[])
{
  int videofd1 = open("/dev/video0",O_RDWR);
  int videofd2 = open("/dev/video0",O_RDWR);
  IDirectFBSurface     *SurfaceHandle;
  IDirectFBSurface     *SurfaceHandle2;
  void *ptr,*ptr2;
  int pitch,pitch2;
  int colour_palette[256];
  int colour_palette2_real[256]; /* random... */
  int *colour_palette2 = colour_palette2_real;
  int is_lut8;

  is_lut8 = (argc > 1 && !strcmp (argv[1], "both"));

  memset(&colour_palette,0x0,4*256);
  //memset(&colour_palette[1],0xff,255*4);

  colour_palette[0] = 0xff000000; // black
  colour_palette[1] = 0xffff0000; // red
  colour_palette[2] = 0xff00ff00; // green
  colour_palette[3] = 0xff0000ff; // blue
  colour_palette[4] = 0xffffffff; // white
  colour_palette[5] = 0x80808000; // half-transp yellow
  colour_palette[6] = 0x00000000; // transp black

  if (videofd1 < 0)
    perror("Couldn't open video device 1\n");

  if (videofd2 < 0)
    perror("Couldn't open video device 2\n");
  
  v4l2_list_outputs (videofd1);

  fb_make_transparent();

  init_dfb(&SurfaceHandle,is_lut8);
  init_dfb(&SurfaceHandle2,1);

  v4l2_set_output_by_name (videofd1, "RGB1");
  v4l2_set_output_by_name (videofd2, "RGB2");
  init_v4l(videofd1,0,0,1280,720,is_lut8);
  init_v4l(videofd2,0,0,1280,720,1);

  printf("%s:%d\n",__FUNCTION__,__LINE__);


//  memcpy (colour_palette, colour_palette2, sizeof (colour_palette));
  colour_palette2 = colour_palette;

  {
    int coords = 60;
    int size   = 100;

    // clear
    if (!is_lut8) SurfaceHandle->Clear (SurfaceHandle, 0x00, 0x00, 0x00, 0x00);
    else {
      SurfaceHandle->SetColorIndex (SurfaceHandle, 0x6);
      SurfaceHandle->FillRectangle (SurfaceHandle, 0, 0, 600, 600);
    }
    // White
    if (is_lut8) SurfaceHandle->SetColorIndex (SurfaceHandle, 0x4);
    else SurfaceHandle->SetColor (SurfaceHandle, 0xff, 0xff, 0xff, 0xff);
    SurfaceHandle->FillRectangle (SurfaceHandle, coords, coords, size, size);
    coords += size;
    // Red
    if (is_lut8) SurfaceHandle->SetColorIndex (SurfaceHandle, 0x1);
    else SurfaceHandle->SetColor (SurfaceHandle, 0xff, 0x00, 0x00, 0xff);
    SurfaceHandle->FillRectangle (SurfaceHandle, coords, coords, size, size);
    coords += size;
    // Green
    if (is_lut8) SurfaceHandle->SetColorIndex (SurfaceHandle, 0x2);
    else SurfaceHandle->SetColor (SurfaceHandle, 0x00, 0xff, 0x00, 0xff);
    SurfaceHandle->FillRectangle (SurfaceHandle, coords, coords, size, size);
    coords += size;
    // Blue
    if (is_lut8) SurfaceHandle->SetColorIndex (SurfaceHandle, 0x3);
    else SurfaceHandle->SetColor (SurfaceHandle, 0x00, 0x00, 0xff, 0xff);
    SurfaceHandle->FillRectangle (SurfaceHandle, coords, coords, size, size);
    coords += size;
    // half transp yellow
    if (is_lut8) SurfaceHandle->SetColorIndex (SurfaceHandle, 0x5);
    else SurfaceHandle->SetColor (SurfaceHandle, 0x80, 0x80, 0x00, 0x80);
    SurfaceHandle->FillRectangle (SurfaceHandle, coords, coords, size, size);
    coords += size;
    // transp
    if (is_lut8) SurfaceHandle->SetColorIndex (SurfaceHandle, 0x6);
    else SurfaceHandle->SetColor (SurfaceHandle, 0x00, 0x00, 0x00, 0x00);
    SurfaceHandle->FillRectangle (SurfaceHandle, coords, coords, size, size);
    coords += size;
  }

  {
    int xcoords = 60 + (100 * 6), ycoords = 60;
    int size   = 100;

    // clear
    SurfaceHandle2->SetColorIndex (SurfaceHandle2, 0x6);
    SurfaceHandle2->FillRectangle (SurfaceHandle2, 220, 220, 440, 440);
    // transp
    SurfaceHandle2->SetColorIndex (SurfaceHandle2, 0x6);
    SurfaceHandle2->FillRectangle (SurfaceHandle2, xcoords, ycoords, size, size);
    xcoords -= size; ycoords += size;
    // half transp yellow
    SurfaceHandle2->SetColorIndex (SurfaceHandle2, 0x5);
    SurfaceHandle2->FillRectangle (SurfaceHandle2, xcoords, ycoords, size, size);
    xcoords -= size; ycoords += size;
    // Blue
    SurfaceHandle2->SetColorIndex (SurfaceHandle2, 0x3);
    SurfaceHandle2->FillRectangle (SurfaceHandle2, xcoords, ycoords, size, size);
    xcoords -= size; ycoords += size;
    // Green
    SurfaceHandle2->SetColorIndex (SurfaceHandle2, 0x2);
    SurfaceHandle2->FillRectangle (SurfaceHandle2, xcoords, ycoords, size, size);
    xcoords -= size; ycoords += size;
    // Red
    SurfaceHandle2->SetColorIndex (SurfaceHandle2, 0x1);
    SurfaceHandle2->FillRectangle (SurfaceHandle2, xcoords, ycoords, size, size);
    xcoords -= size; ycoords += size;
    // White
    SurfaceHandle2->SetColorIndex (SurfaceHandle2, 0x4);
    SurfaceHandle2->FillRectangle (SurfaceHandle2, xcoords, ycoords, size, size);
    xcoords -= size; ycoords += size;
  }
    
  DFBCHECK (SurfaceHandle->Lock (SurfaceHandle, DSLF_READ, &ptr, &pitch));
  DFBCHECK (SurfaceHandle2->Lock (SurfaceHandle2, DSLF_READ, &ptr2, &pitch2));

  printf("%s:%d\n",__FUNCTION__,__LINE__);

  zorder(videofd2,V4L2_CID_STM_Z_ORDER_RGB2,1);
  zorder(videofd1,V4L2_CID_STM_Z_ORDER_RGB1,2);

  queue_buffer( videofd1, ptr, (is_lut8 ? colour_palette : 0), 0ULL);

  stream_on( videofd1 );

  getchar();
  queue_buffer( videofd2, ptr2, colour_palette2, 0ULL); 

  printf("%s:%d\n",__FUNCTION__,__LINE__);

  stream_on( videofd2 );

  printf("%s:%d\n",__FUNCTION__,__LINE__);


  getchar();

  zorder(videofd2,V4L2_CID_STM_Z_ORDER_RGB2,2);
  zorder(videofd1,V4L2_CID_STM_Z_ORDER_RGB1,1);

  fprintf(stderr,"Press Return/Enter to quit\n");
  getchar();

  // This seems to dequeue all buffers too, but that's what the spec says
  // so this is ok.
  stream_off( videofd1 );
  stream_off( videofd2 );

  deinit_dfb();
  close(videofd1);  

  return 0;
}
Beispiel #11
0
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);
}
Beispiel #12
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;
}
Beispiel #13
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;
}
Beispiel #14
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;
}
Beispiel #15
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;
}