This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

using the Qt virtual frame buffer (qvfb) from ecos synth. target


Hi,

attached are two files which implement a simple interface to the Qt virtual 
frame buffer (qvfb). qvfb is a tool which comes with Qt and which simulates a 
frame buffer display by providing a shared memory segment and displaying its 
contents under X.

Simple example how to use it:

//connect
char *framebuffer=qvfb_connect(0x62062c07);
if (framebuffer==0)
   return;
printf("width: %d height: %d depth: %d\n", 
       qvfb_width(), qvfb_height(), qvfb_depth());

//"draw" something
memset(framebuffer, 0, qvfb_width()*qvfb_height()*qvfb_depth()/8);
//force update
qvfb_update(); 

//quit
qvfb_disconnect();

The qvfb_update() is required to force qvfb to update its display. You can 
either call it manually, or you could install a small thread which does 
nothing but calling qvfb_update() regularly, or if you have drawing functions 
you can call qvfb_update() or qvfb_update_rect() at the end of each drawing 
function.

I'd like to contribute this to ecos, so I'm waiting for comments now :-)
(haven't done CDL yet, will do)

Since it's for the synth. target, is GPL ok or does it have to be GPL
+exception ? I mean, nobody distributes a product running under ecos synth.

Bye
Alex
-- 
Work: alexander.neundorf@jenoptik.com - http://www.jenoptik-los.de
Home: neundorf@kde.org                - http://www.kde.org
      alex@neundorf.net               - http://www.neundorf.net
#include <cyg/hal/hal_io.h>

#include "qvfb.h"

struct QVFbHeader
{
   int width;
   int height;
   int depth;
   int linestep;
   int dataoffset;
   int update_x1;
   int update_y1;
   int update_x2;
   int update_y2;
   char dirty;
   int  numcols;
};

struct QVFbHeader* qvfb_header=NULL;
    
char* qvfb_connect(unsigned int ipckey)
{
   int sid=0;
   if (qvfb_header)
      return qvfb_header;
   sid=cyg_hal_sys_shmget(ipckey, 0, 0);
   if (sid<0)
      return NULL;
   char* qvfb_buf=(char*)cyg_hal_sys_shmat(sid, 0, 0);
   if (!qvfb_buf)
      return NULL;
   
   qvfb_header=(struct QVFbHeader*)qvfb_buf;
   return qvfb_buf+qvfb_header->dataoffset;
}

void qvfb_update()
{
   if (!qvfb_header)
      return;
   qvfb_header->update_x1=0;
   qvfb_header->update_y1=0;
   qvfb_header->update_x2=qvfb_header->width;
   qvfb_header->update_y2=qvfb_header->height;
   qvfb_header->dirty=0xff;
}

void qvfb_update_rect(int x1, int y1, int x2, int y2)
{
   if (!qvfb_header)
      return;
   qvfb_header->update_x1=x1;
   qvfb_header->update_y1=y1;
   qvfb_header->update_x2=x2;
   qvfb_header->update_y2=y2;
   qvfb_header->dirty=0xff;
}

void qvfb_disconnect()
{
   if (!qvfb_header)
      return;
   cyg_hal_sys_shmdt(qvfb_header);
   qvfb_header=NULL;
}

int qvfb_width()
{
   if (!qvfb_header)
      return -1;
   return qvfb_header->width;
}

int qvfb_height()
{
   if (!qvfb_header)
      return -1;
   return qvfb_header->height;
}

int qvfb_depth()
{
   if (!qvfb_header)
      return -1;
   return qvfb_header->depth;
}

int qvfb_linestep()
{
   if (!qvfb_header)
      return -1;
   return qvfb_header->linestep;
}
#ifndef ECOS_SYNTH_QVFB_H
#define ECOS_SYNTH_QVFB_H

#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */

/**Connect to the qvfb frame buffer, which is implemented using a 
shared memory segment. ipckey is the shared memory key of the 
qvfb frame buffer. You can get it e.g. using ipcs.
Returns NULL if it didn't succeed.
*/
char* qvfb_connect(unsigned int ipckey);

/// Disconnect from shared memory segment again.
void qvfb_disconnect();

///Update the complete display
void qvfb_update();

///Update the specified region of the display
void qvfb_update_rect(int x1, int y1, int x2, int y2);

///Return the width of the display, or -1 if not connected
int qvfb_width();

///Return the height of the display, or -1 if not connected
int qvfb_height();

///Return the bitdepth of the display, or -1 if not connected
int qvfb_depth();

///Return the offset in bytes between the start of two consecutive lines, or -1 if not connected
int qvfb_linestep();
    
#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif



-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]