static void directfb_unregister_bitmap (struct bitmap *bmp) { IDirectFBSurface *surface = bmp->flags; surface->Release (surface); }
void DFBDeviceScreen::releaseSurface(void* sur) { set<IDirectFBSurface*>::iterator i; IDirectFBSurface* s; s = (IDirectFBSurface*)sur; pthread_mutex_lock(&surMutex); if (surfacePool != NULL) { i = surfacePool->find(s); if (i != surfacePool->end()) { surfacePool->erase(i); pthread_mutex_unlock(&surMutex); } else { pthread_mutex_unlock(&surMutex); } } else { pthread_mutex_unlock(&surMutex); } s->Clear(s, 0, 0, 0, 0); s->Release(s); s = NULL; sur = NULL; }
DFBResult IImageProvider_Real::RenderTo( CoreSurface *destination, const DFBRectangle *rect ) { DFBResult ret; IDirectFBSurface *surface; D_MAGIC_ASSERT( obj, ImageProviderDispatch ); DIRECT_ALLOCATE_INTERFACE( surface, IDirectFBSurface ); if (!surface) return (DFBResult) D_OOM(); ret = IDirectFBSurface_Construct( surface, NULL, NULL, NULL, NULL, destination, DSCAPS_NONE, core, obj->idirectfb ); if (ret) return ret; ret = obj->provider->RenderTo( obj->provider, surface, rect ); surface->Release( surface ); return ret; }
LOCAL void dfb_drawbuffer(DFBDISPLAY *mod, struct TVRequest *req) { DFBWINDOW *v = req->tvr_Op.DrawBuffer.Window; TINT w = req->tvr_Op.DrawBuffer.RRect[2]; TINT h = req->tvr_Op.DrawBuffer.RRect[3]; TINT xd = req->tvr_Op.DrawBuffer.RRect[0]; TINT yd = req->tvr_Op.DrawBuffer.RRect[1]; TAPTR buf = req->tvr_Op.DrawBuffer.Buf; if (!buf) return; TINT totw = req->tvr_Op.DrawBuffer.TotWidth; IDirectFBSurface *surface = NULL; DFBSurfaceDescription dsc; DFBRectangle rect = { 0, 0, w, h }; dsc.flags = DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_PREALLOCATED; dsc.width = w; dsc.height = h; dsc.pixelformat = DSPF_RGB32; dsc.preallocated[0].data = buf; dsc.preallocated[0].pitch = totw * DFB_BYTES_PER_PIXEL(DSPF_RGB32); if (mod->dfb_DFB->CreateSurface(mod->dfb_DFB, &dsc, &surface) == DFB_OK) { v->winsurface->Blit(v->winsurface, surface, &rect, xd, yd); surface->Release(surface); } }
u32 DirectFBVid_BlitWrapper(DirectFBVidCtx *ctx, u32 video_src_width, u32 video_src_height, u32 video_src_pixel_format, char *video_src_buffer, s32 video_src_pitch_y, u32 src_wnd_x, u32 src_wnd_y, u32 src_wnd_w, u32 src_wnd_h, u32 dst_wnd_x, u32 dst_wnd_y, u32 dst_wnd_w, u32 dst_wnd_h, u32 overlay_type) { DFBResult res; DFBSurfaceDescription srcdesc; IDirectFBSurface *src; DFBRectangle dfbsrc, dfbdst; if (overlay_type != 0) return 1; if (ctx->disable_display) return 0; memset(&srcdesc, 0, sizeof(srcdesc)); srcdesc.flags = DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_PREALLOCATED; srcdesc.width = video_src_width; srcdesc.height = video_src_height; srcdesc.pixelformat = DirectFBVid_TranslatePixelFormatFromGPAC(video_src_pixel_format); srcdesc.preallocated[0].data = video_src_buffer; srcdesc.preallocated[0].pitch = video_src_pitch_y; switch (video_src_pixel_format) { case GF_PIXEL_ARGB: //return DSPF_ARGB; case GF_PIXEL_RGBA: //return DSPF_ARGB; ctx->primary->SetBlittingFlags(ctx->primary, DSBLIT_BLEND_ALPHACHANNEL); break; default: ctx->primary->SetBlittingFlags(ctx->primary, DSBLIT_NOFX); } // create a surface with the new surface description res = ctx->dfb->CreateSurface(ctx->dfb, &srcdesc, &src); if (res != DFB_OK) { //GF_LOG(GF_LOG_ERROR, GF_LOG_MMIO, ("[DirectFB] cannot create blit source surface for pixel format %s: %s (%d)\n", gf_4cc_to_str(video_src->pixel_format), DirectFBErrorString(res), res)); return 1; } dfbsrc.x = src_wnd_x; dfbsrc.y = src_wnd_y; dfbsrc.w = src_wnd_w; dfbsrc.h = src_wnd_h; // blit on the surface if (!src_wnd_x && !src_wnd_y && (dst_wnd_w==src_wnd_w) && (dst_wnd_h==src_wnd_h)) { ctx->primary->Blit(ctx->primary, src, &dfbsrc, dst_wnd_x, dst_wnd_y); // blit an area scaled from the source to the destination rectangle } else { dfbdst.x = dst_wnd_x; dfbdst.y = dst_wnd_y; dfbdst.w = dst_wnd_w; dfbdst.h = dst_wnd_h; ctx->primary->StretchBlit(ctx->primary, src, &dfbsrc, &dfbdst); } src->Release(src); return 0; }
static void mrb_directfb_surface_free(mrb_state* mrb, void* p) { struct mrb_directfb_surface_data* data = (struct mrb_directfb_surface_data*)p; if (data != NULL) { IDirectFBSurface* surface = (IDirectFBSurface*)data->surface; if (surface != NULL) { surface->Release(surface); } mrb_free(mrb, data); } }
static void CloseDisplay(vout_display_t *vd) { vout_display_sys_t *sys = vd->sys; IDirectFBSurface *primary = sys->primary; if (primary) primary->Release(primary); IDirectFB *directfb = sys->directfb; if (directfb) directfb->Release(directfb); }
QImage QDirectFBPixmapData::toImage() const { if (!surface) return QImage(); #ifdef QT_NO_DIRECTFB_PREALLOCATED QDirectFBPixmapData *that = const_cast<QDirectFBPixmapData*>(this); const QImage *img = that->buffer(); const QImage copied = img->copy(); that->unlockDirectFB(); return copied; #else int w, h; surface->GetSize(surface, &w, &h); DFBSurfacePixelFormat format; surface->GetPixelFormat(surface, &format); QImage::Format imageFormat = QDirectFBScreen::getImageFormat(format); if (imageFormat == QImage::Format_Invalid) imageFormat = QImage::Format_ARGB32_Premultiplied; imageFormat = QImage::Format_ARGB32; QImage image(w, h, imageFormat); DFBSurfaceDescription description; description = QDirectFBScreen::getSurfaceDescription(image); IDirectFB *fb = QDirectFBScreen::instance()->dfb(); IDirectFBSurface *imgSurface; DFBResult result = fb->CreateSurface(fb, &description, &imgSurface); if (result != DFB_OK) { DirectFBError("QDirectFBPixmapData::toImage()", result); return QImage(); } imgSurface->SetBlittingFlags(imgSurface, DSBLIT_NOFX); result = imgSurface->Blit(imgSurface, surface, 0, 0, 0); if (result != DFB_OK) { DirectFBError("QDirectFBPixmapData::toImage() blit failed", result); return QImage(); } imgSurface->Release(imgSurface); return image; #endif // QT_NO_DIRECTFB_PREALLOCATED }
void QDirectFBPixmapData::fromImage(const QImage &img, Qt::ImageConversionFlags flags) { alpha = QDirectFBPixmapData::hasAlphaChannel(img, flags); imageFormat = alpha ? screen->alphaPixmapFormat() : screen->pixelFormat(); QImage image; if ((flags & ~Qt::NoOpaqueDetection) != Qt::AutoColor) { image = img.convertToFormat(imageFormat, flags); flags = Qt::AutoColor; } else if (img.format() == QImage::Format_RGB32 || img.depth() == 1) { image = img.convertToFormat(imageFormat, flags); } else { image = img; } IDirectFBSurface *imageSurface = screen->createDFBSurface(image, image.format(), QDirectFBScreen::DontTrackSurface); if (!imageSurface) { qWarning("QDirectFBPixmapData::fromImage()"); invalidate(); return; } dfbSurface = screen->createDFBSurface(image.size(), imageFormat, QDirectFBScreen::TrackSurface); if (!dfbSurface) { qWarning("QDirectFBPixmapData::fromImage()"); invalidate(); return; } if (image.hasAlphaChannel()) { dfbSurface->Clear(dfbSurface, 0, 0, 0, 0); dfbSurface->SetBlittingFlags(dfbSurface, DSBLIT_BLEND_ALPHACHANNEL); } else { dfbSurface->SetBlittingFlags(dfbSurface, DSBLIT_NOFX); } dfbSurface->Blit(dfbSurface, imageSurface, 0, 0, 0); imageSurface->Release(imageSurface); w = image.width(); h = image.height(); is_null = (w <= 0 || h <= 0); d = QDirectFBScreen::depth(imageFormat); setSerialNumber(++global_ser_no); #ifdef QT_NO_DIRECTFB_OPAQUE_DETECTION Q_UNUSED(flags); #endif }
int main(int argc, char** argv) { IDirectFB *dfb = NULL; IDirectFBDisplayLayer *layer = NULL; IDirectFBSurface *surface = NULL; IDirectFBVideoProvider *vp = NULL; CHECK(DirectFBInit (&argc, &argv)); if (argc != 2) { return 1; } CHECK(DirectFBCreate(&dfb)); /* Signals */ signal(SIGINT, signal_handler); signal(SIGTERM, signal_handler); signal(SIGUSR1, signal_handler); signal(SIGUSR2, signal_handler); CHECK(dfb->GetDisplayLayer(dfb, 0, &layer)); CHECK(dfb->CreateVideoProvider(dfb, argv[1], &vp)); CHECK(layer->GetSurface(layer, &surface)); CHECK(vp->PlayTo(vp, surface, NULL, flip, surface)); while(to_exit == 0) { sleep(1); } CHECK(vp->Stop(vp)); CHECK(vp->Release(vp)); CHECK(surface->Release(surface)); CHECK(layer->Release(layer)); CHECK(dfb->Release(dfb)); return 0; }
void CFbAccel::blit2FB(void *fbbuff, uint32_t width, uint32_t height, uint32_t xoff, uint32_t yoff, uint32_t xp, uint32_t yp, bool transp) { DFBRectangle src; DFBResult err; IDirectFBSurface *surf; DFBSurfaceDescription dsc; src.x = xp; src.y = yp; src.w = width - xp; src.h = height - yp; dsc.flags = (DFBSurfaceDescriptionFlags)(DSDESC_CAPS | DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PREALLOCATED); dsc.caps = DSCAPS_NONE; dsc.width = width; dsc.height = height; dsc.preallocated[0].data = fbbuff; dsc.preallocated[0].pitch = width * sizeof(fb_pixel_t); err = dfb->CreateSurface(dfb, &dsc, &surf); /* TODO: maybe we should not die if this fails? */ if (err != DFB_OK) { fprintf(stderr, "CFbAccel::blit2FB: "); DirectFBErrorFatal("dfb->CreateSurface(dfb, &dsc, &surf)", err); } if (transp) { surf->SetSrcColorKey(surf, 0, 0, 0); dfbdest->SetBlittingFlags(dfbdest, DSBLIT_SRC_COLORKEY); } else dfbdest->SetBlittingFlags(dfbdest, DSBLIT_BLEND_ALPHACHANNEL); dfbdest->Blit(dfbdest, surf, &src, xoff, yoff); surf->Release(surf); return; }
static IDirectFBSurface * load_image (const char *filename) { IDirectFBImageProvider *provider; IDirectFBSurface *tmp = NULL; IDirectFBSurface *surface = NULL; DFBSurfaceDescription dsc; DFBResult err; err = dfb->CreateImageProvider( dfb, filename, &provider ); if (err != DFB_OK) { fprintf( stderr, "Couldn't load image from file '%s': %s\n", filename, DirectFBErrorString( err )); return NULL; } provider->GetSurfaceDescription( provider, &dsc ); dsc.flags = DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT; dsc.pixelformat = DSPF_ARGB; if (dfb->CreateSurface( dfb, &dsc, &tmp ) == DFB_OK) provider->RenderTo( provider, tmp, NULL ); provider->Release( provider ); if (tmp) { primary->GetPixelFormat( primary, &dsc.pixelformat ); if (dfb->CreateSurface( dfb, &dsc, &surface ) == DFB_OK) { surface->Clear( surface, 0, 0, 0, 0xFF ); surface->SetBlittingFlags( surface, DSBLIT_BLEND_ALPHACHANNEL ); surface->Blit( surface, tmp, NULL, 0, 0 ); } tmp->Release( tmp ); } return surface; }
int main( int argc, char *argv[] ) { DFBResult ret; IDirectFB *dfb; IDirectFBDisplayLayer *layer; /* Initialize DirectFB. */ ret = DirectFBInit( &argc, &argv ); if (ret) { D_DERROR( ret, "DFBTest/Window_Surface: DirectFBInit() failed!\n" ); return ret; } /* Create super interface. */ ret = DirectFBCreate( &dfb ); if (ret) { D_DERROR( ret, "DFBTest/Window_Surface: DirectFBCreate() failed!\n" ); return ret; } dfb->GetDisplayLayer( dfb, DLID_PRIMARY, &layer ); while (true) { DFBWindowDescription desc; IDirectFBWindow *window; IDirectFBSurface *surface; desc.flags = DWDESC_POSX | DWDESC_POSY | DWDESC_WIDTH | DWDESC_HEIGHT | DWDESC_CAPS; desc.posx = 150; desc.posy = 150; desc.width = 300; desc.height = 300; desc.caps = DWCAPS_ALPHACHANNEL; ret = layer->CreateWindow( layer, &desc, &window ); if (ret) { D_DERROR( ret, "DFBTest/Window_Surface: CreateWindow() failed!\n" ); return ret; } window->GetSurface( window, &surface ); D_INFO( "Created window and surface, going to release window... (in 2 seconds)\n" ); usleep( 2000000 ); D_INFO("Releasing window...\n"); window->Release( window ); D_INFO("Window released, going to release surface... (in 2 seconds)\n"); usleep( 2000000 ); D_INFO("Releasing surface...\n"); surface->Release( surface ); D_INFO("Surface released, done.\n"); usleep( 5000000 ); } /* Shutdown DirectFB. */ dfb->Release( dfb ); return ret; }
int main( int argc, char *argv[] ) { int quit = 0; pthread_t render_loop_thread = -1; IDirectFBSurface *primary; IDirectFBEventBuffer *buffer; DFBSurfaceDescription dsc; srand((long)time(0)); DFBCHECK(DirectFBInit( &argc, &argv )); /* create the super interface */ DFBCHECK(DirectFBCreate( &dfb )); /* get an interface to the primary keyboard and create an input buffer for it */ DFBCHECK(dfb->CreateInputEventBuffer( dfb, DICAPS_ALL, DFB_FALSE, &buffer )); /* set our cooperative level to DFSCL_FULLSCREEN for exclusive access to the primary layer */ dfb->SetCooperativeLevel( dfb, DFSCL_FULLSCREEN ); /* get the primary surface, i.e. the surface of the primary layer we have exclusive access to */ dsc.flags = DSDESC_CAPS; dsc.caps = DSCAPS_PRIMARY | DSCAPS_DOUBLE; DFBCHECK(dfb->CreateSurface( dfb, &dsc, &primary )); DFBCHECK(primary->GetSize( primary, &xres, &yres )); /* load font */ { DFBFontDescription desc; desc.flags = DFDESC_HEIGHT; desc.height = yres/10; DFBCHECK(dfb->CreateFont( dfb, FONT, &desc, &font )); DFBCHECK(primary->SetFont( primary, font )); } projection = matrix_new_perspective( 400 ); camera = matrix_new_identity(); load_stars(); generate_starfield(); pthread_mutex_lock( &render_start ); pthread_mutex_lock( &render_finish ); pthread_create( &render_loop_thread, NULL, render_loop, (void*)primary ); /* main loop */ while (!quit) { static float translation[3] = { 0, 0, 0 }; DFBInputEvent evt; /* transform world to screen coordinates */ transform_starfield(); /* start rendering before waiting for events */ start_rendering(); buffer->WaitForEvent( buffer ); /* process event buffer */ while (buffer->GetEvent( buffer, DFB_EVENT(&evt)) == DFB_OK) { if (evt.type == DIET_KEYPRESS) { switch (evt.key_id) { case DIKI_ESCAPE: /* quit main loop */ quit = 1; break; case DIKI_LEFT: translation[0] = 10; break; case DIKI_RIGHT: translation[0] = -10; break; case DIKI_UP: translation[2] = -10; break; case DIKI_DOWN: translation[2] = 10; break; default: break; } } else if (evt.type == DIET_KEYRELEASE) { switch (evt.key_id) { case DIKI_LEFT: case DIKI_RIGHT: translation[0] = 0; break; case DIKI_UP: case DIKI_DOWN: translation[2] = 0; break; default: break; } } else if (evt.type == DIET_AXISMOTION && (evt.flags & DIEF_AXISREL)) { switch (evt.axis) { case DIAI_X: matrix_rotate( camera, Y, -evt.axisrel/80.0f ); break; case DIAI_Y: matrix_rotate( camera, X, evt.axisrel/80.0f ); break; default: break; } } } matrix_translate( camera, translation[0], translation[1], translation[2] ); /* finish rendering before retransforming the world */ finish_rendering(); } pthread_cancel( render_loop_thread ); pthread_mutex_unlock( &render_start ); pthread_join( render_loop_thread, NULL ); render_loop_thread = -1; unload_stars(); free( camera ); free( projection ); buffer->Release( buffer ); primary->Release( primary ); dfb->Release( dfb ); return 0; }
static int l_gc (lua_State* L) { IDirectFBSurface* sfc = * (IDirectFBSurface**) luaL_checkudata(L, 1, "ldirectfb.IDirectFBSurface"); sfc->Release(sfc); return 0; }
DFBResult lite_theme_frame_load( LiteThemeFrame *frame, const char **filenames ) { int i, y; int width = 0; int height = 0; DFBResult ret; D_ASSERT( frame != NULL ); D_ASSERT( filenames != NULL ); for (i=0; i<_LITE_THEME_FRAME_PART_NUM; i++) { D_ASSERT( filenames[i] != NULL ); ret = lite_util_load_image( filenames[i], DSPF_UNKNOWN, &frame->parts[i].source, &frame->parts[i].rect.w, &frame->parts[i].rect.h, NULL ); if (ret) { D_DERROR( ret, "Lite/ThemeFrame: Loading '%s' failed!\n", filenames[i] ); while (i--) frame->parts[i].source->Release( frame->parts[i].source ); return ret; } if (width < frame->parts[i].rect.w) width = frame->parts[i].rect.w; height += frame->parts[i].rect.h; } IDirectFB *dfb; IDirectFBSurface *compact; DFBSurfaceDescription desc; desc.flags = DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT; desc.width = width; desc.height = height; desc.pixelformat = DSPF_ARGB; //FIXME DirectFBCreate( &dfb ); dfb->CreateSurface( dfb, &desc, &compact ); compact->Clear( compact, 0, 0, 0, 0 ); for (i=0, y=0; i<_LITE_THEME_FRAME_PART_NUM; i++) { compact->Blit( compact, frame->parts[i].source, &frame->parts[i].rect, 0, y ); compact->AddRef( compact ); frame->parts[i].source->Release( frame->parts[i].source ); frame->parts[i].source = compact; frame->parts[i].rect.x = 0; frame->parts[i].rect.y = y; y += frame->parts[i].rect.h; } compact->ReleaseSource( compact ); compact->Release( compact ); dfb->Release( dfb ); D_MAGIC_SET( frame, LiteThemeFrame ); return DFB_OK; }
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; }
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; /* Parse arguments. */ for (i=1; i<argc; i++) { if (!strcmp( argv[i], "-h" )) return show_usage( argv[0] ); else if (!url) url = argv[i]; else return show_usage( argv[0] ); } /* Check if we got an URL. */ if (!url) return show_usage( argv[0] ); /* Initialize DirectFB. */ ret = DirectFBInit( &argc, &argv ); if (ret) { D_DERROR( ret, "DFBTest/Scale: DirectFBInit() failed!\n" ); return ret; } /* Create super interface. */ ret = DirectFBCreate( &dfb ); if (ret) { D_DERROR( ret, "DFBTest/Scale: 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/Scale: IDirectFB::CreateImageProvider( '%s' ) failed!\n", url ); goto out; } /* Get the surface description. */ ret = provider->GetSurfaceDescription( provider, &desc ); if (ret) { D_DERROR( ret, "DFBTest/Scale: IDirectFBImageProvider::GetSurfaceDescription() failed!\n" ); goto out; } desc.pixelformat = DSPF_LUT8; D_INFO( "DFBTest/Scale: 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/Scale: IDirectFB::CreateSurface() failed!\n" ); goto out; } ret = provider->RenderTo( provider, source, NULL ); if (ret) { D_DERROR( ret, "DFBTest/Scale: IDirectFBImageProvider::RenderTo() failed!\n" ); goto out; } desc.width = desc.width * 3 / 4; desc.height = desc.height * 3 / 4; if (DFB_PIXELFORMAT_IS_INDEXED( desc.pixelformat )) desc.pixelformat = DSPF_ARGB; D_INFO( "DFBTest/Scale: Destination 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, &dest ); if (ret) { D_DERROR( ret, "DFBTest/Scale: IDirectFB::CreateSurface() failed!\n" ); goto out; } dest->SetBlittingFlags( dest, DSBLIT_SRC_PREMULTIPLY ); dest->StretchBlit( dest, source, NULL, NULL ); dest->Dump( dest, "dfbtest_scale", NULL ); out: if (dest) dest->Release( dest ); if (source) source->Release( source ); if (provider) provider->Release( provider ); /* Shutdown DirectFB. */ dfb->Release( dfb ); return ret; }
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; }
//------------------------------------------------------------------------------ // 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; }
GdkCursor * gdk_cursor_new_for_display (GdkDisplay *display, GdkCursorType cursor_type) { GdkCursor *cursor; GdkDisplayDFB *dfb_display = GDK_DISPLAY_DFB (display); if (cursor_type >= sizeof (stock_cursors) / sizeof (stock_cursors[0])) return NULL; cursor = stock_cursors[cursor_type].cursor; if (!cursor) { GdkCursorDirectFB *private; DFBResult ret; IDirectFBSurface *temp; IDirectFBSurface *temp2; IDirectFBSurface *shape; int width = stock_cursors[cursor_type+1].width; int height = stock_cursors[cursor_type+1].height; temp = gdk_display_dfb_create_surface (dfb_display, DSPF_ARGB, width, height); if (!temp) { return NULL; } else { u32 *dst; int pitch; ret = temp->Lock (temp, DSLF_WRITE, (void**)&dst, &pitch); if (ret) { DirectFBError ("gdkcursor-directfb.c (gdk_cursor_new): " "temp->Lock", ret); temp->Release (temp); return NULL; } else { gint x, y; gint mx, my; gint p = ((stock_cursors[cursor_type].width + 7) / 8) * 8; gint mp = ((stock_cursors[cursor_type + 1].width + 7) / 8) * 8; const guchar *src; const guchar *mask; pitch >>= 2; src = stock_cursors[cursor_type].bits; mask = stock_cursors[cursor_type+1].bits; mx = stock_cursors[cursor_type+1].hotx - stock_cursors[cursor_type].hotx; my = stock_cursors[cursor_type+1].hoty - stock_cursors[cursor_type].hoty; for (y = 0; y < height; y++) { for (x = 0; x < width; x++) { gint bit = x-mx + (y-my) * p; gint mbit = x + y * mp; u32 color = ((x - mx) < 0 || (y - my) < 0 || (x - mx) >= stock_cursors[cursor_type].width || (y - my) >= stock_cursors[cursor_type].height) ? 0x00FFFFFF : (src[bit/8] & (1 << bit%8) ? 0 : 0x00FFFFFF); u8 a = color ? 0xE0 : 0xFF; u32 alpha = mask[mbit/8] & (1 << mbit%8) ? (a << 24) : 0; dst[x + y*pitch] = alpha | color; } } temp->Unlock (temp); } } width += 2; height += 2; temp2 = gdk_display_dfb_create_surface (dfb_display, DSPF_ARGB, width, height); if (!temp2) { temp->Release (temp); return NULL; } temp2->Clear (temp2, 0x80, 0x80, 0x80, 0); temp2->SetBlittingFlags (temp2, (DSBLIT_BLEND_COLORALPHA | DSBLIT_BLEND_ALPHACHANNEL)); temp2->SetColor (temp2, 0, 0, 0, 0x30); temp2->Blit (temp2, temp, NULL, 0, 0); temp2->Blit (temp2, temp, NULL, 0, 2); temp2->Blit (temp2, temp, NULL, 2, 0); temp2->Blit (temp2, temp, NULL, 2, 2); temp2->SetColor (temp2, 0, 0, 0, 0xA0); temp2->Blit (temp2, temp, NULL, 1, 0); temp2->Blit (temp2, temp, NULL, 0, 1); temp2->Blit (temp2, temp, NULL, 2, 1); temp2->Blit (temp2, temp, NULL, 1, 2); temp2->SetColor (temp2, 0, 0, 0, 0xE0); temp2->Blit (temp2, temp, NULL, 1, 1); temp->Release (temp); // creating stretch width = width * 2; height = height * 2; shape = gdk_display_dfb_create_surface (dfb_display, DSPF_ARGB, width, height); if (!shape) { temp2->Release (temp2); return NULL; } shape->StretchBlit(shape, temp2, NULL, NULL); temp2->Release (temp2); private = g_new0 (GdkCursorDirectFB, 1);
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; }
void DFBDeviceScreen::setBackgroundImage(string uri) { DFBResult ret; DFBSurfaceDescription desc; IDirectFBSurface *surface; IDirectFBImageProvider *provider; ret = dfb->CreateImageProvider(dfb, uri.c_str(), &provider); if (ret) { DirectFBError("IDirectFB::CreateImageProvider() failed", ret); return; } ret = provider->GetSurfaceDescription(provider, &desc); if (ret) { DirectFBError( "DFBDeviceScreen::setBackgroundImage surdsc failed", ret); provider->Release(provider); return; } desc.width = this->wRes; desc.height = this->hRes; ret = dfb->CreateSurface(dfb, &desc, &surface); if (ret) { DirectFBError( "DFBDeviceScreen::setBackgroundImage sur failed", ret); provider->Release(provider); return; } ret = provider->RenderTo(provider, surface, NULL); if (ret) { DirectFBError( "DFBDeviceScreen::setBackgroundImage renderto failed", ret); surface->Release(surface); provider->Release(provider); return; } ret = gfxLayer->SetBackgroundImage(gfxLayer, surface); if (ret) { DirectFBError( "DFBDeviceScreen::setBackgroundImage bg failed", ret); surface->Release(surface); provider->Release(provider); return; } ret = gfxLayer->SetBackgroundMode(gfxLayer, DLBM_IMAGE); if (ret) { DirectFBError( "DFBDeviceScreen::setBackgroundImage bgm failed", ret); } surface->Release(surface); provider->Release(provider); cout << endl << endl; cout << "DFBScreen::setBackgroundImage '" << uri << "'" << endl; cout << endl << endl; }
static void TestResize( IDirectFB *dfb ) { DFBResult ret; DirectThread *thread; DFBWindowDescription desc; IDirectFBDisplayLayer *layer; IDirectFBWindow *window; IDirectFBSurface *surface; DFBInputEvent evt; IDirectFBEventBuffer *keybuffer; quit = 0; /* Create an input buffer for key events */ ret = dfb->CreateInputEventBuffer( dfb, DICAPS_KEYS, DFB_FALSE, &keybuffer); if (ret) { D_DERROR( ret, "DFBTest/Resize: CreateInputBuffer() failed!\n" ); return; } ret = dfb->GetDisplayLayer( dfb, DLID_PRIMARY, &layer ); if (ret) { D_DERROR( ret, "DFBTest/Resize: Failed to get display layer!\n" ); keybuffer->Release( keybuffer ); return; } desc.flags = DWDESC_WIDTH | DWDESC_HEIGHT | DWDESC_PIXELFORMAT; desc.width = 500; desc.height = 500; desc.pixelformat = DSPF_ARGB; ret = layer->CreateWindow( layer, &desc, &window ); if (ret) { D_DERROR( ret, "DFBTest/Resize: CreateWindow() failed!\n" ); keybuffer->Release( keybuffer ); layer->Release( layer ); return; } ret = window->GetSurface( window, &surface ); if (ret) { D_DERROR( ret, "DFBTest/Resize: GetSurface() failed!\n" ); keybuffer->Release( keybuffer ); window->Release( window ); layer->Release( layer ); return; } thread = direct_thread_create( DTT_DEFAULT, TestThread, surface, "Test" ); while (!quit) { ret = window->Resize( window, 500, 400 ); if (ret) D_DERROR( ret, "DFBTest/Resize: Resize() failed!\n" ); ret = window->Resize( window, 500, 500 ); if (ret) D_DERROR( ret, "DFBTest/Resize: Resize() failed!\n" ); /* 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; direct_thread_join(thread); break; default: break; } } } } keybuffer->Release( keybuffer ); surface->Release( surface ); window->Release( window ); layer->Release( layer ); }
int main( int argc, char *argv[] ) { DFBResult ret; DFBSurfaceDescription desc; IDirectFB *dfb; IDirectFBSurface *surface; IWater *water; D_INFO( "Tests/Water: Starting up...\n" ); /* Initialize DirectFB including command line parsing. */ ret = DirectFBInit( &argc, &argv ); if (ret) { DirectFBError( "DirectFBInit() failed", ret ); return -1; } /* Parse the command line. */ if (!parse_command_line( argc, argv )) return -2; /* Create the super interface. */ ret = DirectFBCreate( &dfb ); if (ret) { DirectFBError( "DirectFBCreate() failed", ret ); return -3; } /* Fill surface description, flipping primary. */ desc.flags = DSDESC_CAPS; desc.caps = DSCAPS_PRIMARY | DSCAPS_FLIPPING; /* Set width or height? */ if (m_width > 0) { desc.flags |= DSDESC_WIDTH; desc.width = m_width; } if (m_height > 0) { desc.flags |= DSDESC_HEIGHT; desc.height = m_height; } /* Set pixel format? */ if (m_format != DSPF_UNKNOWN) { desc.flags |= DSDESC_PIXELFORMAT; desc.pixelformat = m_format; } dfb->SetCooperativeLevel( dfb, DFSCL_FULLSCREEN ); /* Create a primary surface. */ ret = dfb->CreateSurface( dfb, &desc, &surface ); if (ret) { D_DERROR( ret, "IDirectFB::CreateSurface() failed!\n" ); dfb->Release( dfb ); return -4; } /* Get the extended rendering interface. */ ret = dfb->GetInterface( dfb, "IWater", NULL, dfb, (void**) &water ); if (ret) { DirectFBError( "IDirectFB::GetInterface( 'IWater' ) failed", ret ); surface->Release( surface ); dfb->Release( dfb ); return -5; } D_INFO( "Tests/Water: Got render interface, running tests...\n" ); RunTest( Test_Simple, water, surface ); RunTest( Test_RenderElement, water, surface ); RunTest( Test_RenderElements, water, surface ); RunTest( Test_RenderShape, water, surface ); RunTest( Test_RenderShapes, water, surface ); D_INFO( "Tests/Water: Dumping surface...\n" ); unlink( "dfbrender.pgm" ); unlink( "dfbrender.ppm" ); surface->Dump( surface, "dfbrender", NULL ); D_INFO( "Tests/Water: Shutting down...\n" ); /* Release the render interface. */ water->Release( water ); /* Release the surface. */ surface->Release( surface ); /* Release the super interface. */ dfb->Release( dfb ); return EXIT_SUCCESS; }
int main( int argc, char *argv[] ) { DFBResult ret; /* Initialize DirectFB including command line parsing. */ ret = DirectFBInit( &argc, &argv ); if (ret) { DirectFBError( "DirectFBInit() failed", ret ); return -1; } /* Parse the command line. */ if (!parse_command_line( argc, argv )) return -2; /* Create the super interface. */ ret = DirectFBCreate( &dfb ); if (ret) { DirectFBError( "DirectFBCreate() failed", ret ); return -3; } /* Get the primary display layer. */ ret = dfb->GetDisplayLayer( dfb, id, &layer ); if (ret) { if (ret == DFB_IDNOTFOUND) fprintf (stderr, "\nUnknown layer id, check 'dfbinfo' for valid values.\n\n"); else DirectFBError( "IDirectFB::GetDisplayLayer() failed", ret ); dfb->Release( dfb ); return -4; } /* Get a description of the layer. */ ret = layer->GetDescription( layer, &desc ); if (ret) { DirectFBError( "IDirectFBDisplayLayer::GetDescription() failed", ret ); layer->Release( layer ); dfb->Release( dfb ); return -5; } /* Acquire administrative cooperative level. */ ret = layer->SetCooperativeLevel( layer, DLSCL_ADMINISTRATIVE ); if (ret) { DirectFBError( "IDirectFBDisplayLayer::SetCooperativeLevel() failed", ret ); layer->Release( layer ); dfb->Release( dfb ); return -6; } /* Show/change the configuration. */ set_configuration(); /* Test Lock() on layer surface? */ if (test_lock) { IDirectFBSurface *surface; fprintf( stderr, "\nGetting layer surface...\n" ); ret = layer->GetSurface( layer, &surface ); if (ret) DirectFBError( "IDirectFBDisplayLayer::GetSurface() failed", ret ); else { void *data; int pitch; fprintf( stderr, "\nTesting Lock( %s ) on layer surface...\n", test_lock == DSLF_READ ? "read only" : test_lock == DSLF_WRITE ? "write only" : "read/write" ); ret = surface->Lock( surface, test_lock, &data, &pitch ); if (ret) DirectFBError( "IDirectFBSurface::Lock() failed", ret ); else fprintf( stderr, " => OK\n\n" ); surface->Release( surface ); } } /* Release the display layer. */ layer->Release( layer ); /* Release the super interface. */ dfb->Release( dfb ); return EXIT_SUCCESS; }
int main( int argc, char *argv[] ) { IDirectFB *dfb; IDirectFBDisplayLayer *layer; IDirectFBSurface *bgsurface; IDirectFBImageProvider *provider; IDirectFBWindow *window1; IDirectFBWindow *window2; IDirectFBSurface *window_surface1; IDirectFBSurface *window_surface2; IDirectFBEventBuffer *buffer; DFBDisplayLayerConfig layer_config; #if ((DIRECTFB_MAJOR_VERSION == 0) && (DIRECTFB_MINOR_VERSION == 9) && (DIRECTFB_MICRO_VERSION < 23)) DFBCardCapabilities caps; #else DFBGraphicsDeviceDescription caps; #endif IDirectFBWindow* upper; DFBWindowID id1; IDirectFBFont *font; int fontheight; int err; int quit = 0; DFBCHECK(DirectFBInit( &argc, &argv )); DFBCHECK(DirectFBCreate( &dfb )); #if ((DIRECTFB_MAJOR_VERSION == 0) && (DIRECTFB_MINOR_VERSION == 9) && (DIRECTFB_MICRO_VERSION < 23)) dfb->GetCardCapabilities( dfb, &caps ); #else dfb->GetDeviceDescription( dfb, &caps ); #endif dfb->GetDisplayLayer( dfb, DLID_PRIMARY, &layer ); if (!((caps.blitting_flags & DSBLIT_BLEND_ALPHACHANNEL) && (caps.blitting_flags & DSBLIT_BLEND_COLORALPHA ))) { layer_config.flags = DLCONF_BUFFERMODE; layer_config.buffermode = DLBM_BACKSYSTEM; layer->SetConfiguration( layer, &layer_config ); } layer->GetConfiguration( layer, &layer_config ); layer->EnableCursor ( layer, 1 ); { DFBFontDescription desc; desc.flags = DFDESC_HEIGHT; desc.height = layer_config.width/50; DFBCHECK(dfb->CreateFont( dfb, PACKAGE_DATA_DIR"/grunge.ttf", &desc, &font )); font->GetHeight( font, &fontheight ); } { DFBSurfaceDescription desc; DFBCHECK(dfb->CreateImageProvider( dfb, PACKAGE_DATA_DIR"/bg.png", &provider )); desc.flags = DSDESC_WIDTH | DSDESC_HEIGHT; desc.width = layer_config.width; desc.height = layer_config.height; DFBCHECK(dfb->CreateSurface( dfb, &desc, &bgsurface ) ); provider->RenderTo( provider, bgsurface, NULL ); provider->Release( provider ); DFBCHECK(bgsurface->SetFont( bgsurface, font )); bgsurface->SetColor( bgsurface, 0xCF, 0xCF, 0xFF, 0xFF ); bgsurface->DrawString( bgsurface, "Move the mouse over a window to activate it.", -1, 10, 0, DSTF_LEFT | DSTF_TOP ); bgsurface->SetColor( bgsurface, 0xFF, 0xCF, 0xFF, 0xFF ); bgsurface->DrawString( bgsurface, "You can drag them around, too, if you want.", -1, 10 , 40, DSTF_LEFT | DSTF_TOP ); bgsurface->SetColor( bgsurface, 0xCF, 0xCF, 0xFF, 0xFF ); bgsurface->DrawString( bgsurface, "The one with funky stuff happening and things flying around is an evas.", -1, 10, 80, DSTF_LEFT | DSTF_TOP ); layer->SetBackgroundImage( layer, bgsurface ); layer->SetBackgroundMode( layer, DLBM_IMAGE ); } { DFBWindowDescription desc; desc.flags = ( DWDESC_POSX | DWDESC_POSY | DWDESC_WIDTH | DWDESC_HEIGHT | DWDESC_CAPS ); desc.posx = 20; desc.posy = 120; desc.width = 200; desc.height = 200; desc.caps = DWCAPS_ALPHACHANNEL; DFBCHECK( layer->CreateWindow( layer, &desc, &window2 ) ); window2->GetSurface( window2, &window_surface2 ); window2->SetOpacity( window2, 0xFF ); window2->CreateEventBuffer( window2, &buffer ); { window_surface2->SetColor( window_surface2, 0x00, 0x30, 0x10, 0xc0 ); window_surface2->DrawRectangle( window_surface2, 0, 0, desc.width, desc.height ); window_surface2->SetColor( window_surface2, 0x80, 0xa0, 0x00, 0x90 ); window_surface2->FillRectangle( window_surface2, 1, 1, desc.width-2, desc.height-2 ); DFBCHECK(window_surface2->SetFont(window_surface2, font )); window_surface2->SetColor( window_surface2, 0xCF, 0xFF, 0xCF, 0xFF ); window_surface2->DrawString( window_surface2, "Pants!", -1,10, fontheight + 5, DSTF_LEFT | DSTF_TOP ); } window_surface2->Flip( window_surface2, NULL, 0 ); } { DFBWindowDescription desc; desc.flags = ( DWDESC_POSX | DWDESC_POSY | DWDESC_WIDTH | DWDESC_HEIGHT | DWDESC_CAPS ); desc.posx = 200; desc.posy = 200; desc.width = 240; desc.height = 320; desc.caps = DWCAPS_ALPHACHANNEL; DFBCHECK(layer->CreateWindow( layer, &desc, &window1 ) ); window1->GetSurface( window1, &window_surface1 ); window_surface1->SetColor( window_surface1, 0xFF, 0x20, 0x20, 0x90 ); window_surface1->DrawRectangle( window_surface1, 0, 0, desc.width, desc.height ); window_surface1->Flip( window_surface1, NULL, 0 ); window1->SetOpacity( window1, 0xFF ); window1->GetID( window1, &id1 ); window1->AttachEventBuffer( window1, buffer ); } window1->RequestFocus( window1 ); window1->RaiseToTop( window1 ); upper = window1; { evas_init(); evas = evas_new(); evas_output_method_set(evas, evas_render_method_lookup("directfb")); evas_output_size_set(evas, 240, 320); evas_output_viewport_set(evas, 0, 0, 240, 320); { Evas_Engine_Info_DirectFB *einfo; einfo = (Evas_Engine_Info_DirectFB *) evas_engine_info_get(evas); einfo->info.dfb = dfb; einfo->info.surface = window_surface1; einfo->info.flags = DSDRAW_BLEND; evas_engine_info_set(evas, (Evas_Engine_Info *) einfo); } setup(); evas_render(evas); start_time = get_time(); } while (!quit) { static IDirectFBWindow* active = NULL; static int grabbed = 0; static int startx = 0; static int starty = 0; static int endx = 0; static int endy = 0; DFBWindowEvent evt; buffer->WaitForEventWithTimeout( buffer, 0, 10 ); while (buffer->GetEvent( buffer, DFB_EVENT(&evt) ) == DFB_OK) { IDirectFBWindow* window; if (evt.window_id == id1) window = window1; else window = window2; if (active) { switch (evt.type) { case DWET_BUTTONDOWN: if (!grabbed && evt.button == DIBI_LEFT) { grabbed = 1; layer->GetCursorPosition( layer, &startx, &starty ); window->GrabPointer( window ); } break; case DWET_BUTTONUP: switch (evt.button) { case DIBI_LEFT: if (grabbed) { window->UngrabPointer( window ); grabbed = 0; } break; case DIBI_MIDDLE: upper->LowerToBottom( upper ); upper = (upper == window1) ? window2 : window1; break; case DIBI_RIGHT: quit = DIKS_DOWN; break; default: break; } break; case DWET_KEYDOWN: if (grabbed) break; switch (evt.key_id) { case DIKI_RIGHT: active->Move (active, 1, 0); break; case DIKI_LEFT: active->Move (active, -1, 0); break; case DIKI_UP: active->Move (active, 0, -1); break; case DIKI_DOWN: active->Move (active, 0, 1); break; default: break; } break; case DWET_LOSTFOCUS: if (!grabbed) active = NULL; break; default: break; } } else if (evt.type == DWET_GOTFOCUS) active = window; switch (evt.type) { case DWET_MOTION: endx = evt.cx; endy = evt.cy; break; case DWET_KEYDOWN: switch (evt.key_symbol) { case DIKS_ESCAPE: case DIKS_SMALL_Q: case DIKS_CAPITAL_Q: case DIKS_BACK: case DIKS_STOP: quit = 1; break; default: break; } break; default: break; } } if (active) { if (grabbed) { active->Move( active, endx - startx, endy - starty); startx = endx; starty = endy; } active->SetOpacity( active, (sin( myclock()/300.0 ) * 85) + 170 ); } loop(); { Eina_List *updates; updates = evas_render_updates(evas); /* efficient update.. only flip the rectangle regions that changed! */ if (updates) { DFBRegion region; Eina_List *l; for (l = updates; l; l = l->next) { Evas_Rectangle *rect; rect = l->data; region.x1 = rect->x; region.y1 = rect->y; region.x2 = rect->x + rect->w - 1; region.y2 = rect->y + rect->h - 1; window_surface1->Flip(window_surface1, ®ion, DSFLIP_BLIT); } evas_render_updates_free(updates); } } } buffer->Release( buffer ); window_surface2->Release( window_surface2 ); window_surface1->Release( window_surface1 ); window2->Release( window2 ); window1->Release( window1 ); layer->Release( layer ); bgsurface->Release( bgsurface ); dfb->Release( dfb ); evas_shutdown(); return 0; }
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[] ) { 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; }
void QDirectFBPixmapData::fromImage(const QImage &img, Qt::ImageConversionFlags) { QImage image; if (QDirectFBScreen::getSurfacePixelFormat(img) == DSPF_UNKNOWN) image = img.convertToFormat(QImage::Format_ARGB32_Premultiplied); else image = img; DFBSurfaceDescription description; description = QDirectFBScreen::getSurfaceDescription(image); IDirectFB *fb = QDirectFBScreen::instance()->dfb(); DFBResult result; #ifndef QT_NO_DIRECTFB_PREALLOCATED IDirectFBSurface *imgSurface; result = fb->CreateSurface(fb, &description, &imgSurface); if (result != DFB_OK) { DirectFBError("QDirectFBPixmapData::fromImage()", result); setSerialNumber(0); return; } #ifndef QT_NO_DIRECTFB_PALETTE QDirectFBScreen::setSurfaceColorTable(imgSurface, image); #endif #endif // QT_NO_DIRECTFB_PREALLOCATED description.flags = DFBSurfaceDescriptionFlags(description.flags ^ DSDESC_PREALLOCATED); result = fb->CreateSurface(fb, &description, &surface); if (result != DFB_OK) { DirectFBError("QDirectFBPixmapData::fromImage()", result); setSerialNumber(0); return; } #ifndef QT_NO_DIRECTFB_PALETTE QDirectFBScreen::setSurfaceColorTable(surface, image); #endif #ifdef QT_NO_DIRECTFB_PREALLOCATED char *mem; int bpl; surface->Lock(surface, DSLF_WRITE, (void**)&mem, &bpl); const int w = image.width() * image.depth() / 8; for (int i = 0; i < image.height(); ++i) { memcpy(mem, image.scanLine(i), w); mem += bpl; } surface->Unlock(surface); #else surface->SetBlittingFlags(surface, DSBLIT_NOFX); result = surface->Blit(surface, imgSurface, 0, 0, 0); if (result != DFB_OK) DirectFBError("QDirectFBPixmapData::fromImage()", result); surface->Flip(surface, 0, DSFLIP_NONE); imgSurface->Release(imgSurface); #endif // QT_NO_DIRECTFB_PREALLOCATED setSerialNumber(++global_ser_no); }