Ejemplo n.º 1
0
int testing_multicore() {
    IDirectFB *dfb = NULL;
    IDirectFBSurface *surface = NULL;
    DFBSurfaceDescription dsc;

    pid_t n_pid = fork();

    if (n_pid) {
        sleep(1);
    }

    DFBCHECK(DirectFBInit(NULL, NULL));
    DFBCHECK(DirectFBCreate(&dfb));
    push_release(dfb, dfb->Release);

    DFBCHECK(dfb->SetCooperativeLevel (dfb, DFSCL_FULLSCREEN));
    dsc.flags = DSDESC_CAPS;
    dsc.caps  = DSCAPS_PRIMARY | DSCAPS_FLIPPING;
    DFBCHECK (dfb->CreateSurface( dfb, &dsc, &surface ));
    push_release(surface, surface->Release);

    if (!n_pid) {
        sleep(1);
    }
    sleep(2);

    //DFBCHECK(surface->Release(surface));
    //DFBCHECK(dfb->Release(dfb));
    release_all();

    if (n_pid) {
        wait(NULL);
    }
    return 0;
}
Ejemplo n.º 2
0
IDirectFBSurface *QDirectFbTextureGlyphCache::sourceSurface()
{
    if (m_surface.isNull()) {
        const QImage &source = image();
        DFBSurfaceDescription desc;
        memset(&desc, 0, sizeof(desc));
        desc.flags = DFBSurfaceDescriptionFlags(DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_PREALLOCATED | DSDESC_CAPS);
        desc.width = source.width();
        desc.height = source.height();
        desc.caps = DSCAPS_SYSTEMONLY;

        switch (source.format()) {
        case QImage::Format_Mono:
            desc.pixelformat = DSPF_A1;
            break;
        case QImage::Format_Alpha8:
            desc.pixelformat = DSPF_A8;
            break;
        default:
            qFatal("QDirectFBTextureGlyphCache: Unsupported source texture image format.");
            break;
        }

        desc.preallocated[0].data = const_cast<void*>(static_cast<const void*>(source.bits()));
        desc.preallocated[0].pitch = source.bytesPerLine();
        desc.preallocated[1].data = 0;
        desc.preallocated[1].pitch = 0;

        IDirectFB *dfb = QDirectFbConvenience::dfbInterface();
        dfb->CreateSurface(dfb , &desc, m_surface.outPtr());
    }
    return m_surface.data();
}
Ejemplo n.º 3
0
void QDirectFBPixmapData::resize(int width, int height)
{
    if (width <= 0 || height <= 0) {
        setSerialNumber(0);
        return;
    }

    IDirectFB *dfb = QDirectFBScreen::instance()->dfb();
    if (!dfb)
        qFatal("QDirectFBPixmapData::resize(): "
               "Unable to get DirectFB handle!");

    DFBSurfaceDescription description;
    description.flags = DFBSurfaceDescriptionFlags(DSDESC_WIDTH |
                                                   DSDESC_HEIGHT);
    description.width = width;
    description.height = height;

    DFBResult result = dfb->CreateSurface(dfb, &description, &surface);
    if (result != DFB_OK) {
        DirectFBErrorFatal("QDirectFBPixmapData::resize(): "
                           "Unable to allocate surface", result);
    }

    setSerialNumber(++global_ser_no);
}
Ejemplo n.º 4
0
QDirectFbBlitter::QDirectFbBlitter(const QSize &rect, bool alpha)
    : QBlittable(rect, dfb_blitter_capabilities())
    , m_premult(false)
    , m_debugPaint(false)
{
    DFBSurfaceDescription surfaceDesc;
    memset(&surfaceDesc,0,sizeof(DFBSurfaceDescription));
    surfaceDesc.width = rect.width();
    surfaceDesc.height = rect.height();

    // force alpha format to get AlphaFillRectCapability and ExtendedPixmapCapability support
    alpha = true;

    if (alpha) {
        m_premult = true;
        surfaceDesc.caps = DSCAPS_PREMULTIPLIED;
        surfaceDesc.pixelformat = QDirectFbBlitter::alphaPixmapFormat();
        surfaceDesc.flags = DFBSurfaceDescriptionFlags(DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_CAPS | DSDESC_PIXELFORMAT);
    } else {
        surfaceDesc.flags = DFBSurfaceDescriptionFlags(DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT);
        surfaceDesc.pixelformat = QDirectFbBlitter::pixmapFormat();
    }

    if (qEnvironmentVariableIntValue("QT_DIRECTFB_BLITTER_DEBUGPAINT"))
        m_debugPaint = true;

    IDirectFB *dfb = QDirectFbConvenience::dfbInterface();
    dfb->CreateSurface(dfb , &surfaceDesc, m_surface.outPtr());
    m_surface->Clear(m_surface.data(), 0, 0, 0, 0);
}
Ejemplo n.º 5
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;
}
Ejemplo n.º 6
0
void QDirectFBPixmapData::fill(const QColor &color)
{
    if (!serialNumber())
        return;

    Q_ASSERT(surface);

    if (color.alpha() < 255 && !hasAlphaChannel()) {
        // convert to surface supporting alpha channel
        DFBSurfacePixelFormat format;
        surface->GetPixelFormat(surface, &format);
        switch (format) {
        case DSPF_YUY2:
        case DSPF_UYVY:
            format = DSPF_AYUV;
            break;
#if (Q_DIRECTFB_VERSION >= 0x010100)
        case DSPF_RGB444:
            format = DSPF_ARGB4444;
            break;
        case DSPF_RGB555:
#endif
        case DSPF_RGB18:
            format = DSPF_ARGB6666;
            break;
        default:
            format = DSPF_ARGB;
            break;
        }

        DFBSurfaceDescription description;
        description.flags = DFBSurfaceDescriptionFlags(DSDESC_WIDTH |
                                                       DSDESC_HEIGHT |
                                                       DSDESC_PIXELFORMAT);
        surface->GetSize(surface, &description.width, &description.height);
        description.pixelformat = format;
        surface->Release(surface); // release old surface

        IDirectFB *fb = QDirectFBScreen::instance()->dfb();
        DFBResult result = fb->CreateSurface(fb, &description, &surface);
        if (result != DFB_OK) {
            DirectFBError("QDirectFBPixmapData::fill()", result);
            setSerialNumber(0);
            return;
        }
    }

    surface->Clear(surface, color.red(), color.green(), color.blue(),
                   color.alpha());
}
Ejemplo n.º 7
0
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
}
Ejemplo n.º 8
0
static int l_new (lua_State* L)
{
	// [ IDFBSurface | dfb | dsc ]
	IDirectFB* dfb = * (IDirectFB**) luaL_checkudata(L, 2, "ldirectfb.IDirectFB");
	DFBSurfaceDescription dsc;
	table2DFBSurfaceDescription (L, &dsc);
	IDirectFBSurface* sfc;
	//dsc.flags = dsc.flags & DSDESC_PIXELFORMAT;
	//dsc.pixelformat = DSPF_LUT8;
	//dsc.caps = DSCAPS_ALL;
	//printf("SFC: %d, %d\n", dsc.width, dsc.height);
	DFBCHECK( dfb->CreateSurface(dfb, &dsc, &sfc) );
	lua_pushlightuserdata(L, sfc);    // [ IDFBSurface | dfb | dsc | win ]
	l_IDirectFBSurface_toudata(L);    // [ IDFBSurface | dfb | dsc | _win ]
	return 1;
}
Ejemplo n.º 9
0
     Surface( EGL                  &egl,
              IDirectFB             dfb,
              int                   width,
              int                   height,
              IDirectFBEventBuffer  events )
          :
          egl( egl )
     {
          DFBSurfaceDescription desc;

          /* Fill description for a shared offscreen surface. */
          desc.flags  = (DFBSurfaceDescriptionFlags)(DSDESC_CAPS | DSDESC_WIDTH | DSDESC_HEIGHT);
          desc.caps   = (DFBSurfaceCapabilities)(DSCAPS_SHARED | DSCAPS_TRIPLE);
          desc.width  = width;
          desc.height = height;

          /* Create a primary surface. */
          surface = dfb.CreateSurface( desc );

          surface.MakeClient();

          /* Create event buffer */
          surface.AttachEventBuffer( events );

          surface_id = surface.GetID();

          surface.AllowAccess( "*" );

          surface.Clear( 0xff, 0xff, 0xff, 0xff );

          D_INFO( "DFBTest/EGLCompositor: Created new surface with ID %u\n", surface_id );

          image = egl.CreateImage( EGL_NO_CONTEXT, EGL_IMAGE_IDIRECTFBSURFACE_DIRECTFB, (EGLClientBuffer) surface.iface, NULL );

          glGenTextures( 1, &tex );

          glBindTexture( GL_TEXTURE_2D, tex );

          egl.EGLImageTargetTexture2D( GL_TEXTURE_2D, image );

          glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
          glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );


          glDisable( GL_CULL_FACE );
          glDisable( GL_DEPTH_TEST );
     }
Ejemplo n.º 10
0
void QDirectFBPixmapData::copy(const QPixmapData *data, const QRect &rect)
{
    if (data->classId() != DirectFBClass) {
        QPixmapData::copy(data, rect);
        return;
    }

    IDirectFBSurface *src = static_cast<const QDirectFBPixmapData*>(data)->surface;

    DFBSurfaceDescription description;
    description.flags = DFBSurfaceDescriptionFlags(DSDESC_WIDTH |
                                                   DSDESC_HEIGHT |
                                                   DSDESC_PIXELFORMAT);
    description.width = rect.width();
    description.height = rect.height();
    src->GetPixelFormat(src, &description.pixelformat);

    IDirectFB *fb = QDirectFBScreen::instance()->dfb();

    DFBResult result = fb->CreateSurface(fb, &description, &surface);
    if (result != DFB_OK) {
        DirectFBError("QDirectFBPixmapData::copy()", result);
        setSerialNumber(0);
        return;
    }

#ifndef QT_NO_DIRECTFB_PALETTE
    IDirectFBPalette *palette;
    src->GetPalette(src, &palette);
    surface->SetPalette(surface, palette);
#endif

    surface->SetBlittingFlags(surface, DSBLIT_NOFX);
    const DFBRectangle blitRect = { rect.x(), rect.y(),
                                    rect.width(), rect.height() };
    result = surface->Blit(surface, src, &blitRect, 0, 0);
    if (result != DFB_OK)
        DirectFBError("QDirectFBPixmapData::copy()", result);

    setSerialNumber(++global_ser_no);
}
Ejemplo n.º 11
0
QDirectFbBlitter::QDirectFbBlitter(const QSize &rect, bool alpha)
    : QBlittable(rect, dfb_blitter_capabilities())
{
    DFBSurfaceDescription surfaceDesc;
    memset(&surfaceDesc,0,sizeof(DFBSurfaceDescription));
    surfaceDesc.width = rect.width();
    surfaceDesc.height = rect.height();

    if (alpha) {
        surfaceDesc.caps = DSCAPS_PREMULTIPLIED;
        surfaceDesc.pixelformat = QDirectFbBlitter::alphaPixmapFormat();
        surfaceDesc.flags = DFBSurfaceDescriptionFlags(DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_CAPS | DSDESC_PIXELFORMAT);
    } else {
        surfaceDesc.flags = DFBSurfaceDescriptionFlags(DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT);
        surfaceDesc.pixelformat = QDirectFbBlitter::pixmapFormat();
    }


    IDirectFB *dfb = QDirectFbConvenience::dfbInterface();
    dfb->CreateSurface(dfb , &surfaceDesc, m_surface.outPtr());
    m_surface->Clear(m_surface.data(), 0, 0, 0, 0);
}
Ejemplo n.º 12
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;
}
Ejemplo n.º 13
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;
}
Ejemplo n.º 14
0
int testing_singlecore() {
    IDirectFB *dfb = NULL;
    IDirectFBSurface *surface = NULL;
    DFBSurfaceDescription dsc;
    DFBSurfaceCapabilities  caps;
    int width, height;
  	DFBSurfacePixelFormat p_format;
    int i;


    DFBCHECK(DirectFBInit(NULL, NULL));
    DFBCHECK(DirectFBCreate(&dfb));
    push_release(dfb, dfb->Release);

    DFBCHECK(dfb->SetCooperativeLevel (dfb, DFSCL_FULLSCREEN));
    dsc.flags = DSDESC_CAPS;
    dsc.caps  = DSCAPS_PRIMARY | DSCAPS_FLIPPING;
    DFBCHECK (dfb->CreateSurface( dfb, &dsc, &surface ));
    push_release(surface, surface->Release);

    DFBCHECK(surface->GetCapabilities(surface, &caps));

    if (caps & DSCAPS_PRIMARY) {
        printf("Surface Primary\n");
    }
    if (caps & DSCAPS_SYSTEMONLY) {
        printf("Surface SystemOnly\n");
    }
    if (caps & DSCAPS_VIDEOONLY) {
        printf("Surface VideoOnly\n");
    }
    if (caps & DSCAPS_DOUBLE) {
        printf("Surface Double buffered\n");
    }
    if (caps & DSCAPS_SUBSURFACE) {
        printf("Surface is a sub surface\n");
    }
    if (caps & DSCAPS_INTERLACED) {
        printf("Surface is Interlaced\n");
    }
    if (caps & DSCAPS_SEPARATED) {
        printf("Surface is separated\n");
    }
    if (caps & DSCAPS_STATIC_ALLOC) {
        printf("Surface is static alloc\n");
    }
    if (caps & DSCAPS_TRIPLE) {
        printf("Surface is triple buffered\n");
    }
    if (caps & DSCAPS_PREMULTIPLIED) {
        printf("Surface stores premiltiplied alpha\n");
    }
    if (caps & DSCAPS_DEPTH) {
        printf("Surface has a depth buffer\n");
    }
    DFBCHECK(surface->GetSize(surface, &width, &height));
    printf("Surface size: %dx%d\n", width, height);


    DFBCHECK(surface->GetPixelFormat(surface, &p_format));
    for(i = 0; pformat_names[i].format; i++) {
        if (pformat_names[i].format == p_format) {
            printf("Surface pixelformat: %s\n", pformat_names[i].name);
        }
    }

    release_all();
    return 0;

}
Ejemplo n.º 15
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;

     /* 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;
}
Ejemplo n.º 16
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;
}
Ejemplo n.º 17
0
DFBResult
EGLDisplayX11::Surface_Initialise( SurfaceXWindow &surface )
{
     D_DEBUG_AT( DFBX11_EGLDisplay, "EGL::SurfaceXWindow::%s( %p ) <- window 0x%08lx, handle 0x%08lx (class %d)\n",
                 __FUNCTION__, this, surface.window, surface.parent.native_handle.value, surface.parent.native_handle.clazz );

     DFBResult ret;


     ::Window              window = surface.window;
     bool                  is_pixmap = false;
     DFBSurfaceDescription desc;

     XWindowAttributes  attrs;

     //     xcb_generic_error_t *err = NULL;
     //
     //     D_DEBUG_AT( DFBX11_EGLDisplay, "  -> calling xcb_get_window_attributes...\n" );
     //     xcb_get_window_attributes_cookie_t  cookie = xcb_get_window_attributes( (xcb_connection_t*)display->x11_display, window );
     //
     //     D_DEBUG_AT( DFBX11_EGLDisplay, "  -> calling xcb_get_window_attributes_reply...\n" );
     //     xcb_get_window_attributes_reply_t  *reply  = xcb_get_window_attributes_reply( (xcb_connection_t*)display->x11_display, cookie, &err );
     //
     //     if (!reply) {
     //          D_ERROR( "DFBEGL/SurfaceXWindow: xcb_get_window_attributes() failed (error code %d)!\n", err ? err->error_code : 0 );
     //          return DFB_FAILURE;
     //     }

//     XMapWindow( x11_display, window );
     XSync( x11_display, False );
     XGetWindowAttributes( x11_display, window, &attrs );

     desc.width  = attrs.width;
     desc.height = attrs.height;

     D_DEBUG_AT( DFBX11_EGLDisplay, "  -> size %dx%d\n", desc.width, desc.height );

     desc.flags       = (DFBSurfaceDescriptionFlags)(DSDESC_WIDTH       | DSDESC_HEIGHT |
                                                     DSDESC_PIXELFORMAT | DSDESC_CAPS   |
                                                     DSDESC_RESOURCE_ID | DSDESC_HINTS);
     desc.pixelformat = (attrs.depth == 24) ? DSPF_RGB32 : DSPF_ARGB;
     desc.caps        = DSCAPS_SHARED;
     desc.resource_id = window;
     desc.hints       = DSHF_NONE;

     if (surface.parent.native_handle.clazz == DirectFB::EGL::NativeHandle::CLASS_WINDOW) {
          D_FLAGS_SET( desc.caps, DSCAPS_PRIMARY );
//          D_FLAGS_SET( desc.caps, DSCAPS_DOUBLE );
          D_FLAGS_SET( desc.hints, DSHF_WINDOW );
     }
     else {
          is_pixmap = true;
     }

     D_DEBUG_AT( DFBX11_EGLDisplay, "  -> caps %s\n", *ToString<DFBSurfaceCapabilities>( desc.caps ) );

     IDirectFB *dfb = parent.GetDFB();

//     dfb->SetCooperativeLevel( dfb, DFSCL_FULLSCREEN );

     ret = dfb->CreateSurface( dfb, &desc, &surface.parent.surface );
     if (ret) {
          D_DERROR( ret, "DFBEGL/SurfaceXWindow: IDirectFB::CreateSurface() failed!\n" );
          goto error;
     }

     ret = surface.parent.surface->Allocate( surface.parent.surface, DSBR_FRONT, DSSE_LEFT,
                                             is_pixmap ? "Pixmap/X11" : "Window/X11", window,
                                             &surface.allocation );
     if (ret) {
          D_DERROR( ret, "DFBEGL/SurfaceXWindow: IDirectFBSurface::Allocate() failed!\n" );
          goto error;
     }

     surface.parent.surface->AllowAccess( surface.parent.surface, "*" );

     return DFB_OK;

error:
     if (surface.parent.surface) {
          surface.parent.surface->Release( surface.parent.surface );
          surface.parent.surface = NULL;
     }
     return ret;
}
Ejemplo n.º 18
0
int
main( int argc, char *argv[] )
{
    int                     i;
    DFBResult               ret;
    DFBSurfaceDescription   desc;
    IDirectFB              *dfb;
    IDirectFBImageProvider *provider = NULL;
    IDirectFBSurface       *source   = NULL;
    IDirectFBSurface       *dest     = NULL;
    IDirectFBSurface       *dest2    = NULL;
    const char             *url      = NULL;

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

    /* 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] );

    /* 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_NV21;

    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;

    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;
    }

    DFBRectangle srect = {
        10, 10, 200, 200
    };

    DFBRectangle drect = {
        10, 10, 300, 300
    };

    DFBRegion clip = {
        40, 40, 199, 199
    };

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

    dest->SetClip( dest, &clip );
    dest->StretchBlit( dest, source, &srect, &drect );


    desc.pixelformat = DSPF_ARGB;

    D_INFO( "DFBTest/Scale: Destination2 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, &dest2 );
    if (ret) {
        D_DERROR( ret, "DFBTest/Scale: IDirectFB::CreateSurface() failed!\n" );
        goto out;
    }

    dest2->Blit( dest2, dest, NULL, 0, 0 );

    dest2->Dump( dest2, "dfbtest_scale_nv21", NULL );


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

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

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

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

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

    return ret;
}
Ejemplo n.º 19
0
int
main( int argc, char *argv[] )
{
     DFBResult ret;
     bool      quit = false;
     Test      test;
     int       n = 1;

     memset( &test, 0, sizeof(test) );

#if 1

     DFBSurfaceDescription  dsc;

     IDirectFB             *dfb;
//     IDirectFBDisplayLayer *layer;

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

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



     EGLDisplay gEGLDisplay = 0;
     EGLConfig  gEGLConfig;
     EGLContext gEGLContext;


    const char *s;
    //Display* display = sharedDisplay();
    //gEGLDisplay = eglGetDisplay(display);
    gEGLDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
    if (gEGLDisplay == EGL_NO_DISPLAY)
        return 0;
    if (!eglInitialize(gEGLDisplay, 0, 0))
        return 0;
    s = eglQueryString(gEGLDisplay, EGL_VERSION);
    printf("EGL_VERSION = %s\n", s);
    s = eglQueryString(gEGLDisplay, EGL_VENDOR);
    printf("EGL_VENDOR = %s\n", s);
    s = eglQueryString(gEGLDisplay, EGL_EXTENSIONS);
    printf("EGL_EXTENSIONS = %s\n", s);
    s = eglQueryString(gEGLDisplay, EGL_CLIENT_APIS);
    printf("EGL_CLIENT_APIS = %s\n", s);


     const int fbConfigAttrbs[] = {
//             EGL_BUFFER_SIZE, EGL_DONT_CARE,
         EGL_RED_SIZE, 1,
         EGL_GREEN_SIZE, 1,
         EGL_BLUE_SIZE, 1,
         EGL_ALPHA_SIZE, 1,
         EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
         EGL_SURFACE_TYPE, /*EGL_PIXMAP_BIT |*/ EGL_WINDOW_BIT,
         EGL_NONE
     };
     EGLint numOfConfig;
     if (!eglChooseConfig(gEGLDisplay, fbConfigAttrbs, &gEGLConfig, 1, &numOfConfig)) {
         printf("egl choose config failed\n");
         return 0;
     }
     if (!numOfConfig) {
         printf("no egl configs found\n");
         return 0;
     }


     const EGLint eglContextAttrbs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
     gEGLContext = eglCreateContext(gEGLDisplay, gEGLConfig, EGL_NO_CONTEXT, eglContextAttrbs);
     if (gEGLContext)
         eglBindAPI(EGL_OPENGL_ES_API);


     IDirectFBSurface *m_dfbsurface;
     EGLSurface        m_surface;

     {
         IDirectFB *dfb;
         if (DirectFBCreate(&dfb)) {
             printf("failed to DirectFBCreate\n");
             return -1;
         }

         DFBSurfaceDescription dsc;
         dsc.flags = (DFBSurfaceDescriptionFlags)(DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS);
         dsc.width = 1024;
         dsc.height = 1024;
         dsc.pixelformat = DSPF_ARGB;
         dsc.caps = DSCAPS_DOUBLE;

//         surf->GetSize( surf, &dsc.width, &dsc.height );
//         surf->GetPixelFormat( surf, &dsc.pixelformat );

         if (dfb->CreateSurface(dfb, &dsc, &m_dfbsurface)) {
             printf("failed to DFB::CreateSurface\n");
             return -1;
         }

         EGLint windowsAttr[] = { EGL_RENDER_BUFFER, EGL_BACK_BUFFER, EGL_NONE };

         m_surface = eglCreateWindowSurface(gEGLDisplay, gEGLConfig, (EGLNativeWindowType)m_dfbsurface, windowsAttr);
         if (m_surface == EGL_NO_SURFACE) {
             printf("failed to eglCreateWindowSurface()\n");
             return -1;
         }
     }


     eglMakeCurrent(gEGLDisplay, m_surface, m_surface, gEGLContext);
//        WKViewPaintToCurrentGLContext(_view->wkView());

     glClearColor( 0, 0, 1, 1 );
     glClear( GL_COLOR_BUFFER_BIT );

     eglSwapBuffers(gEGLDisplay, m_surface);

//     m_dfbsurface->Dump( m_dfbsurface, ".", "dfbsurface" );
//sleep(1);
//     m_dfbsurface->Dump( m_dfbsurface, ".", "dfbsurface" );
//sleep(999);
//exit(1);




#endif




     ret = Initialize( &test, &argc, &argv );
     if (ret)
          goto error;

     ret = InitGL( &test );
     if (ret)
          goto error;

     shader_init();

     /*
      * Main Loop
      */
     while (!quit) {
          DFBInputEvent evt;
#if 0
          GLfloat       color[4] = { n * 100 / 100.0f, n * 100 / 100.0f, n * 100 / 100.0f, 1.0f };

          const static GLfloat v[6] = { -1.0, -1.0,  1.0, 0.0,  -1.0, 1.0 };

          glClearColor(n/10.0, n/10.0, n/10.0, 1.0);
          glClear(GL_COLOR_BUFFER_BIT);

          glDisable( GL_CULL_FACE );
          glDisable( GL_DEPTH_TEST );

          glEnableVertexAttribArray( 0 );
          glVertexAttribPointer( 0, 2, GL_FLOAT, GL_TRUE, 0, v );

          glUniform4fv( color_location, 4, color );

          glDrawArrays( GL_TRIANGLE_FAN, 0, 3 );

          eglSwapBuffers( display, surface );
          test.offscreen->Dump( test.offscreen, ".", "offscreen" );
//exit(0);
#endif
          // behaves like eglCopyBuffers( display, surface, test.primary );
          //test.primary->Blit( test.primary, test.offscreen, NULL, 0, 0 );
          test.primary->Blit( test.primary, m_dfbsurface, NULL, 0, 0 );

          test.primary->Flip( test.primary, NULL, DSFLIP_NONE );

          /*
           * Process events
           */
          sleep( 3 );

          while (test.events->GetEvent( test.events, DFB_EVENT(&evt) ) == DFB_OK) {
               switch (evt.type) {
                    case DIET_KEYPRESS:
                         switch (evt.key_symbol) {
                              case DIKS_ESCAPE:
                                   quit = true;
                                   break;
                              default:
                                   ;
                         }
                         break;
                    default:
                         ;
               }
          }

          n++;
     }


error:
     Shutdown( &test );

     return ret;
}
Ejemplo n.º 20
0
/** entry point */
int main(int argc, char *argv[])
{
    const char *uuid = NULL;
    int c;
    int listHostModes = 0;
    int quit = 0;
    const struct option options[] =
    {
        { "help",          no_argument,       NULL, 'h' },
        { "startvm",       required_argument, NULL, 's' },
        { "fixedres",      required_argument, NULL, 'f' },
        { "listhostmodes", no_argument,       NULL, 'l' },
        { "scale",         no_argument,       NULL, 'c' }
    };

    printf("VirtualBox DirectFB GUI built %s %s\n"
           "(C) 2004-" VBOX_C_YEAR " " VBOX_VENDOR "\n"
           "(C) 2004-2005 secunet Security Networks AG\n", __DATE__, __TIME__);

    for (;;)
    {
        c = getopt_long(argc, argv, "s:", options, NULL);
        if (c == -1)
            break;
        switch (c)
        {
            case 'h':
            {
                showusage();
                exit(0);
                break;
            }
            case 's':
            {
                // UUID as string, parse it
                RTUUID buuid;
                if (!RT_SUCCESS(RTUuidFromStr((PRTUUID)&buuid, optarg)))
                {
                    printf("Error, invalid UUID format given!\n");
                    showusage();
                    exit(-1);
                }
                uuid = optarg;
                break;
            }
            case 'f':
            {
                if (sscanf(optarg, "%ux%ux%u", &fixedVideoMode.width, &fixedVideoMode.height,
                           &fixedVideoMode.bpp) != 3)
                {
                    printf("Error, invalid resolution argument!\n");
                    showusage();
                    exit(-1);
                }
                useFixedVideoMode = 1;
                break;
            }
            case 'l':
            {
                listHostModes = 1;
                break;
            }
            case 'c':
            {
                scaleGuest = 1;
                break;
            }
            default:
                break;
        }
    }

    // check if we got a UUID
    if (!uuid)
    {
        printf("Error, no UUID given!\n");
        showusage();
        exit(-1);
    }


    /**
     * XPCOM setup
     */

    nsresult rc;
    /*
     * Note that we scope all nsCOMPtr variables in order to have all XPCOM
     * objects automatically released before we call NS_ShutdownXPCOM at the
     * end. This is an XPCOM requirement.
     */
    {
        nsCOMPtr<nsIServiceManager> serviceManager;
        rc = NS_InitXPCOM2(getter_AddRefs(serviceManager), nsnull, nsnull);
        if (NS_FAILED(rc))
        {
            printf("Error: XPCOM could not be initialized! rc=0x%x\n", rc);
            exit(-1);
        }

        // register our component
        nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(serviceManager);
        if (!registrar)
        {
            printf("Error: could not query nsIComponentRegistrar interface!\n");
            exit(-1);
        }
        registrar->AutoRegister(nsnull);

        /*
         * Make sure the main event queue is created. This event queue is
         * responsible for dispatching incoming XPCOM IPC messages. The main
         * thread should run this event queue's loop during lengthy non-XPCOM
         * operations to ensure messages from the VirtualBox server and other
         * XPCOM IPC clients are processed. This use case doesn't perform such
         * operations so it doesn't run the event loop.
         */
        nsCOMPtr<nsIEventQueue> eventQ;
        rc = NS_GetMainEventQ(getter_AddRefs (eventQ));
        if (NS_FAILED(rc))
        {
            printf("Error: could not get main event queue! rc=%08X\n", rc);
            return -1;
        }

        /*
         * Now XPCOM is ready and we can start to do real work.
         * IVirtualBox is the root interface of VirtualBox and will be
         * retrieved from the XPCOM component manager. We use the
         * XPCOM provided smart pointer nsCOMPtr for all objects because
         * that's very convenient and removes the need deal with reference
         * counting and freeing.
         */
        nsCOMPtr<nsIComponentManager> manager;
        rc = NS_GetComponentManager (getter_AddRefs (manager));
        if (NS_FAILED(rc))
        {
            printf("Error: could not get component manager! rc=%08X\n", rc);
            exit(-1);
        }

        nsCOMPtr<IVirtualBox> virtualBox;
        rc = manager->CreateInstanceByContractID(NS_VIRTUALBOX_CONTRACTID,
                                                 nsnull,
                                                 NS_GET_IID(IVirtualBox),
                                                 getter_AddRefs(virtualBox));
        if (NS_FAILED(rc))
        {
            printf("Error, could not instantiate object! rc=0x%x\n", rc);
            exit(-1);
        }

        nsCOMPtr<ISession> session;
        rc = manager->CreateInstance(CLSID_Session,
                                     nsnull,
                                     NS_GET_IID(ISession),
                                     getter_AddRefs(session));
        if (NS_FAILED(rc))
        {
            printf("Error: could not instantiate Session object! rc = %08X\n", rc);
            exit(-1);
        }

        // open session for this VM
        rc = virtualBox->OpenSession(session, NS_ConvertUTF8toUTF16(uuid).get());
        if (NS_FAILED(rc))
        {
            printf("Error: given machine not found!\n");
            exit(-1);
        }
        nsCOMPtr<IMachine> machine;
        session->GetMachine(getter_AddRefs(machine));
        if (!machine)
        {
            printf("Error: given machine not found!\n");
            exit(-1);
        }
        nsCOMPtr<IConsole> console;
        session->GetConsole(getter_AddRefs(console));
        if (!console)
        {
            printf("Error: cannot get console!\n");
            exit(-1);
        }

        nsCOMPtr<IDisplay> display;
        console->GetDisplay(getter_AddRefs(display));
        if (!display)
        {
            printf("Error: could not get display object!\n");
            exit(-1);
        }

        nsCOMPtr<IKeyboard> keyboard;
        nsCOMPtr<IMouse> mouse;
        VBoxDirectFB *frameBuffer = NULL;

        /**
         * Init DirectFB
         */
        IDirectFB *dfb = NULL;
        IDirectFBSurface *surface = NULL;
        IDirectFBInputDevice *dfbKeyboard = NULL;
        IDirectFBInputDevice *dfbMouse = NULL;
        IDirectFBEventBuffer *dfbEventBuffer = NULL;
        DFBSurfaceDescription dsc;
        int screen_width, screen_height;

        DFBCHECK(DirectFBInit(&argc, &argv));
        DFBCHECK(DirectFBCreate(&dfb));
        DFBCHECK(dfb->SetCooperativeLevel(dfb, DFSCL_FULLSCREEN));
        // populate our structure of supported video modes
        DFBCHECK(dfb->EnumVideoModes(dfb, enumVideoModesHandler, NULL));

        if (listHostModes)
        {
            printf("*****************************************************\n");
            printf("Number of available host video modes: %u\n", numVideoModes);
            for (uint32_t i = 0; i < numVideoModes; i++)
            {
                printf("Mode %u: xres = %u, yres = %u, bpp = %u\n", i,
                       videoModes[i].width, videoModes[i].height, videoModes[i].bpp);
            }
            printf("Note: display modes with bpp < have been filtered out\n");
            printf("*****************************************************\n");
            goto Leave;
        }

        if (useFixedVideoMode)
        {
            int32_t bestVideoMode = getBestVideoMode(fixedVideoMode.width,
                                                     fixedVideoMode.height,
                                                     fixedVideoMode.bpp);
            // validate the fixed mode
            if ((bestVideoMode == -1) ||
                ((fixedVideoMode.width  != videoModes[bestVideoMode].width) ||
                (fixedVideoMode.height != videoModes[bestVideoMode].height) ||
                (fixedVideoMode.bpp    != videoModes[bestVideoMode].bpp)))
            {
                printf("Error: the specified fixed video mode is not available!\n");
                exit(-1);
            }
        } else
        {
            initialVideoMode = getBestVideoMode(640, 480, 16);
            if (initialVideoMode == -1)
            {
                printf("Error: initial video mode 640x480x16 is not available!\n");
                exit(-1);
            }
        }

        dsc.flags = DSDESC_CAPS;
        dsc.caps = DSCAPS_PRIMARY;
        DFBCHECK(dfb->CreateSurface(dfb, &dsc, &surface));
        DFBCHECK(surface->Clear(surface, 0, 0, 0, 0));
        DFBCHECK(surface->GetSize(surface, &screen_width, &screen_height));
        DFBCHECK(dfb->GetInputDevice(dfb, DIDID_KEYBOARD, &dfbKeyboard));
        DFBCHECK(dfbKeyboard->CreateEventBuffer(dfbKeyboard, &dfbEventBuffer));
        DFBCHECK(dfb->GetInputDevice(dfb, DIDID_MOUSE, &dfbMouse));
        DFBCHECK(dfbMouse->AttachEventBuffer(dfbMouse, dfbEventBuffer));


        if (useFixedVideoMode)
        {
            printf("Information: setting video mode to %ux%ux%u\n", fixedVideoMode.width,
                   fixedVideoMode.height, fixedVideoMode.bpp);
            DFBCHECK(dfb->SetVideoMode(dfb, fixedVideoMode.width,
                                       fixedVideoMode.height, fixedVideoMode.bpp));
        } else
        {
            printf("Information: starting with default video mode %ux%ux%u\n",
                   videoModes[initialVideoMode].width, videoModes[initialVideoMode].height,
                   videoModes[initialVideoMode].bpp);
            DFBCHECK(dfb->SetVideoMode(dfb, videoModes[initialVideoMode].width,
                                            videoModes[initialVideoMode].height,
                                            videoModes[initialVideoMode].bpp));
        }

        // register our framebuffer
        frameBuffer = new VBoxDirectFB(dfb, surface);
        display->SetFramebuffer(0, frameBuffer);

        /**
         * Start the VM execution thread
         */
        console->PowerUp(NULL);

        console->GetKeyboard(getter_AddRefs(keyboard));
        console->GetMouse(getter_AddRefs(mouse));

        /**
         * Main event loop
         */
        #define MAX_KEYEVENTS 10
        PRInt32 keyEvents[MAX_KEYEVENTS];
        int numKeyEvents;

        while (!quit)
        {
            DFBInputEvent event;

            numKeyEvents = 0;
            DFBCHECK(dfbEventBuffer->WaitForEvent(dfbEventBuffer));
            while (dfbEventBuffer->GetEvent(dfbEventBuffer, DFB_EVENT(&event)) == DFB_OK)
            {
                int mouseXDelta = 0;
                int mouseYDelta = 0;
                int mouseZDelta = 0;
                switch (event.type)
                {
                    #define QUEUEEXT() keyEvents[numKeyEvents++] = 0xe0
                    #define QUEUEKEY(scan) keyEvents[numKeyEvents++] = scan | (event.type == DIET_KEYRELEASE ? 0x80 : 0x00)
                    #define QUEUEKEYRAW(scan) keyEvents[numKeyEvents++] = scan
                    case DIET_KEYPRESS:
                    case DIET_KEYRELEASE:
                    {
                        // @@@AH development hack to get out of it!
                        if ((event.key_id == DIKI_ESCAPE) && (event.modifiers & (DIMM_CONTROL | DIMM_ALT)))
                            quit = 1;

                        if (numKeyEvents < MAX_KEYEVENTS)
                        {
                            //printf("%s: key_code: 0x%x\n", event.type == DIET_KEYPRESS ? "DIET_KEYPRESS" : "DIET_KEYRELEASE", event.key_code);
                            switch ((uint32_t)event.key_id)
                            {
                                case DIKI_CONTROL_R:
                                    QUEUEEXT();
                                    QUEUEKEY(0x1d);
                                    break;
                                case DIKI_INSERT:
                                    QUEUEEXT();
                                    QUEUEKEY(0x52);
                                    break;
                                case DIKI_DELETE:
                                    QUEUEEXT();
                                    QUEUEKEY(0x53);
                                    break;
                                case DIKI_HOME:
                                    QUEUEEXT();
                                    QUEUEKEY(0x47);
                                    break;
                                case DIKI_END:
                                    QUEUEEXT();
                                    QUEUEKEY(0x4f);
                                    break;
                                case DIKI_PAGE_UP:
                                    QUEUEEXT();
                                    QUEUEKEY(0x49);
                                    break;
                                case DIKI_PAGE_DOWN:
                                    QUEUEEXT();
                                    QUEUEKEY(0x51);
                                    break;
                                case DIKI_LEFT:
                                    QUEUEEXT();
                                    QUEUEKEY(0x4b);
                                    break;
                                case DIKI_RIGHT:
                                    QUEUEEXT();
                                    QUEUEKEY(0x4d);
                                    break;
                                case DIKI_UP:
                                    QUEUEEXT();
                                    QUEUEKEY(0x48);
                                    break;
                                case DIKI_DOWN:
                                    QUEUEEXT();
                                    QUEUEKEY(0x50);
                                    break;
                                case DIKI_KP_DIV:
                                    QUEUEEXT();
                                    QUEUEKEY(0x35);
                                    break;
                                case DIKI_KP_ENTER:
                                    QUEUEEXT();
                                    QUEUEKEY(0x1c);
                                    break;
                                case DIKI_PRINT:
                                    // the break code is inverted!
                                    if (event.type == DIET_KEYPRESS)
                                    {
                                        QUEUEEXT();
                                        QUEUEKEY(0x2a);
                                        QUEUEEXT();
                                        QUEUEKEY(0x37);
                                    } else
                                    {
                                        QUEUEEXT();
                                        QUEUEKEY(0x37);
                                        QUEUEEXT();
                                        QUEUEKEY(0x2a);
                                    }
                                    break;
                                case DIKI_PAUSE:
                                    // This is a super weird key. No break code and a 6 byte
                                    // combination.
                                    if (event.type == DIET_KEYPRESS)
                                    {
                                        QUEUEKEY(0xe1);
                                        QUEUEKEY(0x1d);
                                        QUEUEKEY(0x45);
                                        QUEUEKEY(0xe1);
                                        QUEUEKEY(0x9d);
                                        QUEUEKEY(0xc5);
                                    }
                                    break;
                                case DIKI_META_L:
                                    // the left Windows logo is a bit different
                                    if (event.type == DIET_KEYPRESS)
                                    {
                                        QUEUEEXT();
                                        QUEUEKEYRAW(0x1f);
                                    } else
                                    {
                                        QUEUEEXT();
                                        QUEUEKEYRAW(0xf0);
                                        QUEUEKEYRAW(0x1f);
                                    }
                                    break;
                                case DIKI_META_R:
                                    // the right Windows logo is a bit different
                                    if (event.type == DIET_KEYPRESS)
                                    {
                                        QUEUEEXT();
                                        QUEUEKEYRAW(0x27);
                                    } else
                                    {
                                        QUEUEEXT();
                                        QUEUEKEYRAW(0xf0);
                                        QUEUEKEYRAW(0x27);
                                    }
                                    break;
                                case DIKI_SUPER_R:
                                    // the popup menu is a bit different
                                    if (event.type == DIET_KEYPRESS)
                                    {
                                        QUEUEEXT();
                                        QUEUEKEYRAW(0x2f);
                                    } else
                                    {
                                        QUEUEEXT();
                                        QUEUEKEYRAW(0xf0);
                                        QUEUEKEYRAW(0x2f);
                                    }
                                    break;

                                default:
                                    // check if we got a hardware scancode
                                    if (event.key_code != -1)
                                    {
                                        // take the scancode from DirectFB as is
                                        QUEUEKEY(event.key_code);
                                    } else
                                    {
                                        // XXX need extra handling!
                                    }
                            }
                        }
                        break;
                    }
                    #undef QUEUEEXT
                    #undef QUEUEKEY
                    #undef QUEUEKEYRAW

                    case DIET_AXISMOTION:
                    {
                        switch (event.axis)
                        {
                            case DIAI_X:
                                mouseXDelta += event.axisrel;
                                break;
                            case DIAI_Y:
                                mouseYDelta += event.axisrel;
                                break;
                            case DIAI_Z:
                                mouseZDelta += event.axisrel;
                                break;
                            default:
                                break;
                        }
                        // fall through
                    }
                    case DIET_BUTTONPRESS:
                        // fall through;
                    case DIET_BUTTONRELEASE:
                    {
                        int buttonState = 0;
                        if (event.buttons & DIBM_LEFT)
                            buttonState |= MouseButtonState::LeftButton;
                        if (event.buttons & DIBM_RIGHT)
                            buttonState |= MouseButtonState::RightButton;
                        if (event.buttons & DIBM_MIDDLE)
                            buttonState |= MouseButtonState::MiddleButton;
                        mouse->PutMouseEvent(mouseXDelta, mouseYDelta, mouseZDelta,
                                             buttonState);
                        break;
                    }
                    default:
                        break;
                }
            }
            // did we get any keyboard events?
            if (numKeyEvents > 0)
            {
                uint32_t codesStored;
                if (numKeyEvents > 1)
                {
                    keyboard->PutScancodes(numKeyEvents, keyEvents,
                                           &codesStored);
                } else
                {
                    keyboard->PutScancode(keyEvents[0]);
                }
            }
        }
        {
            nsCOMPtr<IProgress> progress;
            console->PowerDown(getter_AddRefs(progress));
            progress->WaitForCompletion(-1);
        }
    }

Leave:
    /*
     * Perform the standard XPCOM shutdown procedure.
     */
    NS_ShutdownXPCOM(nsnull);

    return 0;
}
Ejemplo n.º 21
0
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;
}
Ejemplo n.º 22
0
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, &region,
					     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;
}
Ejemplo n.º 23
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;
}
Ejemplo n.º 24
0
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);
}
Ejemplo n.º 25
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;
}