近期碰到一个问题, 就是设定了DirectFB的主Surface输出到高清接口,比如HDMI, 而副Surface的内容则要输出到标清接口,比如CVBS。
我不想一条语句调用两次,分别向不同的Surface画, 研究了一下, Directfb是可以做到在输出到主Surface的同时,flip一份到副Surface的。
具体代码如下:
#include <stdio.h> #include <directfb.h> static IDirectFB *dfb = NULL; static IDirectFBSurface *primary = NULL; static IDirectFBDisplayLayer* secondaryLayer = NULL; static IDirectFBSurface* secondarySurface = NULL; static int screen_width = 0; static int screen_height = 0; #define DFBCHECK(x...) \ { \ DFBResult err = x; \ if (err != DFB_OK) \ {\ fprintf( stderr, "%s <%d>:\n\t", __FILE__, __LINE__ );\ DirectFBErrorFatal( #x, err );\ }\ } int main(int argc, char **argv) { DFBSurfaceDescription dsc; DFBDisplayLayerConfig layerCfg; DFBCHECK (DirectFBInit (&argc, &argv)); DFBCHECK (DirectFBCreate (&dfb)); // DFBCHECK (dfb->SetCooperativeLevel (dfb, DFSCL_FULLSCREEN)); dsc.flags = DSDESC_CAPS; dsc.caps = DSCAPS_PRIMARY | DSCAPS_FLIPPING; DFBCHECK (dfb->CreateSurface( dfb, &dsc, &primary )); DFBCHECK (primary->SetColor (primary, 0xff, 0x00, 0x00, 0xff)); DFBCHECK (primary->GetSize (primary, &screen_width, &screen_height)); DFBCHECK (primary->FillRectangle (primary, 0, 0, screen_width, screen_height)); DFBCHECK (primary->SetColor (primary, 0x80, 0x80, 0xff, 0xff)); DFBCHECK (primary->DrawLine (primary, 0, screen_height / 6, screen_width - 1, screen_height / 6)); DFBCHECK (primary->Flip (primary, NULL, 0)); dfb->GetDisplayLayer(dfb, DLID_PRIMARY+1, &secondaryLayer); secondaryLayer->SetCooperativeLevel(secondaryLayer, DLSCL_ADMINISTRATIVE); layerCfg.flags = DLCONF_SOURCE; layerCfg.source = DLSID_SURFACE; secondaryLayer->SetConfiguration(secondaryLayer, &layerCfg); secondaryLayer->GetSurface(secondaryLayer, &secondarySurface); secondarySurface->Flip(secondarySurface, NULL, DSFLIP_NONE); sleep(10); secondaryLayer->Release( secondaryLayer ); secondarySurface->Release( secondarySurface ); primary->Release(primary); dfb->Release(dfb); return 0; }