Use qvfb to develop framebuffer applications in X11

Source: Internet
Author: User
Use qvfb to develop framebuffer applications in X11

11:32:59 | classification: Linux
| Font size subscription

Qvfb is short for Qt virtualframebuffer. It is a framebuffer simulator of QT in X11. With it, we can use many convenient tools in X11 to develop framebuffer-based applications. The principle of qvfb is very simple. It creates a systemv shared memory. You only need to put the images to be displayed in the shared memory in pixel format. qvfb can be displayed.

To connect to the System V shared memory, follow these steps:

1. Get the key through ftok
2. Use shmget to get shmid
3. Use shmat to connect to the shared memory

It should be noted that the key generation needs to pass in a file name agreed by both parties to ftok, for qvfb screen device, this file is/tmp/. qtvfb_mouse-0.

The shared memory created by qvfb contains a private data header, which indicates the pixel format and width. The header structure is defined as follows:
Struct qvfbheader
{
Int width;
Int height;
Int depth;
Int linestep;
Int dataoffset;
Int update [4];
Char dirty;
Int numcols;
Unsigned int clut [256];
};

Dataoffset is the offset position of virtual framebuffer relative to the header structure. Data written to the offset address can be reflected to qvfb. The following is an example,

Int key = ftok ("/tmp/. qtvfb_mouse-0", 'B ');
Int shmid = shmget (Key, 0, 0 );
If (shmid! =-1)
{
Struct qvfbheader * qvfb_data = shmat (shmid, 0, 0 );
If (qvfb_data! = NULL)
Memset (char *) qvfb_data + qvfb_data-> dataoffset, 0xff, 65535 );

}

A piece of code in qtopia:

Bool qvfbscreen: connect (const qstring & displayspec)
220 {
221 screen_optype = & qvfb_dummy;
222 screen_lastop = & qvfb_dummy;
223
224 if (displayspec. indexof (": Gray")> = 0)
225 grayscale = true;
226
227 key_t key = ftok (qbytearray (qt_vfb_mouse_pipe). Replace ("% 1", qbytearray: Number (displayid), 'B ');
228
229 If (Key =-1)
230 return false;
231
232 int shmid = shmget (Key, 0, 0 );
233 If (shmid! =-1)
234 shmrgn = (unsigned char *) shmat (shmid, 0, 0 );
235 else
236 return false;
237
238 If (long) shmrgn =-1 | shmrgn = 0 ){
239 qdebug ("No shmrgn % lD", (long) shmrgn );
240 return false;
241}
HDR = (qvfbheader *) shmrgn;
244 DATA = shmrgn + HDR-> dataoffset;
245
246 DW = W = HDR-> width;
247 DH = H = HDR-> height;
248 d = HDR-& gt; depth;
249 lstep = HDR-> linestep;
250
251 qdebug ("connected to vfb server: % d x % d \ n", W, H, d );
252 qdebug ("\ n \ r file: % s \ tfunction: % s \ n" ,__ file __,__ function __);
253
254 size = lstep * h;
255 amp; mapsize = size;
256 screencols = HDR-> numcols;
257 memcpy (screenclut, HDR-> clut, sizeof (qrgb) * screencols );
If (qapp-> type () = qapplication: guiserver ){
260 // we handle mouse and keyboard here
261 qwsserver: setdefamouse mouse ("NONE ");
262 qwsserver: setdefakeykeyboard ("NONE ");
263 qdebug ("\ n \ r$ $ new mouse, new keyboard $ \ n ");
264 mousehandler = new qvfbmousehandler (displayid );
265 keyboardhandler = new qvfbkeyboardhandler (displayid );
266 If (HDR-> dataoffset >=( INT) sizeof (qvfbheader )){
267 HDR-> serverversion = qt_version;
268}
269}
270
271 return true;
272}
Void qvfbscreen: disconnect ()
275 {
276 if (long) shmrgn! =-1 & shmrgn ){
277 if (qapp-> type () = qapplication: guiserver & HDR-> dataoffset >=( INT) sizeof (qvfbheader )){
278 HDR-> serverversion = 0;
279}
280 shmdt (char *) shmrgn );
281}
282 If (qapp-> type () = qapplication: guiserver ){
283 Delete mousehandler;
284 mousehandler = 0;
285 Delete keyboardhandler;
286 keyboardhandler = 0;
287}
288}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.