~ubuntu-branches/ubuntu/karmic/italc/karmic-updates

« back to all changes in this revision

Viewing changes to ica/src/demo_server.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Stéphane Graber
  • Date: 2008-02-11 23:40:20 UTC
  • mto: This revision was merged to the branch mainline in revision 7.
  • Revision ID: james.westby@ubuntu.com-20080211234020-o9fixmzxpa1ybhlq
Tags: upstream-1.0.6
Import upstream version 1.0.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * demo_server.cpp - multi-threaded slim VNC-server for demo-purposes (optimized
3
3
 *                   for lot of clients accessing server in read-only-mode)
4
4
 *
5
 
 * Copyright (c) 2006-2007 Tobias Doerffel <tobydox/at/users/dot/sf/dot/net>
 
5
 * Copyright (c) 2006-2008 Tobias Doerffel <tobydox/at/users/dot/sf/dot/net>
6
6
 *  
7
7
 * This file is part of iTALC - http://italc.sourceforge.net
8
8
 *
141
141
        m_socketDescriptor( _sd ),
142
142
        m_sock( NULL ),
143
143
        m_conn( _conn ),
 
144
        m_otherEndianess( FALSE ),
144
145
        m_lzoWorkMem( new Q_UINT8[sizeof( lzo_align_t ) *
145
146
                        ( ( ( LZO1X_1_MEM_COMPRESS ) +
146
147
                                        ( sizeof( lzo_align_t ) - 1 ) ) /
164
165
 
165
166
 
166
167
 
167
 
void demoServerClient::updateRegion( const rectList & _reg )
 
168
void demoServerClient::updateRegion( const QRegion & _reg )
168
169
{
169
170
        m_dataMutex.lock();
170
171
        m_changedRegion += _reg;
264
265
                // e.g. if we didn't get an update-request for a quite long time
265
266
                // and there were a lot of updates - at the end we don't send
266
267
                // more than the whole screen one time
267
 
                //QVector<QRect> rects = m_changedRegion.rects();
268
 
                const rectList r = m_changedRegion.nonOverlappingRects();
 
268
                const QVector<QRect> r = m_changedRegion.rects();
269
269
 
270
270
                // no we gonna post all changed rects!
271
271
                const rfbFramebufferUpdateMsg m =
278
278
 
279
279
                m_sock->write( (const char *) &m, sizeof( m ) );
280
280
                // process each rect
281
 
                for( rectList::const_iterator it = r.begin();
 
281
                for( QVector<QRect>::const_iterator it = r.begin();
282
282
                                                        it != r.end(); ++it )
283
283
                {
284
284
                        const rfbRectangle rr =
312
312
        QRgb last_pix = *( (QRgb *) i.scanLine( it->y() ) + it->x() );
313
313
        Q_UINT8 rle_cnt = 0;
314
314
        Q_UINT8 rle_sub = 1;
315
 
        Q_UINT8 * out = new Q_UINT8[w * h * sizeof( QRgb )];
 
315
        Q_UINT8 * out = new Q_UINT8[w * h * sizeof( QRgb )+16];
316
316
        Q_UINT8 * out_ptr = out;
317
317
        for( Q_UINT16 y = it->y(); y < it->y() + h; ++y )
318
318
        {
322
322
                {
323
323
                        if( data[x] != last_pix || rle_cnt > 254 )
324
324
                        {
325
 
                                *( (QRgb *) out_ptr ) = last_pix;
 
325
                                *( (QRgb *) out_ptr ) = swap32IfBE( last_pix );
326
326
                                *( out_ptr + 3 ) = rle_cnt - rle_sub;
327
327
                                out_ptr += 4;
328
328
                                last_pix = data[x];
341
341
        out_ptr += 4;
342
342
 
343
343
        hdr.bytesRLE = out_ptr - out;
344
 
        hdr.bytesLZO = hdr.bytesRLE + hdr.bytesRLE / 16 + 67;
345
 
        Q_UINT8 * comp = new Q_UINT8[hdr.bytesLZO];
 
344
        lzo_uint bytes_lzo = hdr.bytesRLE + hdr.bytesRLE / 16 + 67;
 
345
        Q_UINT8 * comp = new Q_UINT8[bytes_lzo];
346
346
        lzo1x_1_compress( (const unsigned char *) out, (lzo_uint) hdr.bytesRLE,
347
347
                                (unsigned char *) comp,
348
 
                                (lzo_uint *) &hdr.bytesLZO, m_lzoWorkMem );
 
348
                                &bytes_lzo, m_lzoWorkMem );
349
349
        hdr.bytesRLE = swap32IfLE( hdr.bytesRLE );
350
 
        hdr.bytesLZO = swap32IfLE( hdr.bytesLZO );
 
350
        hdr.bytesLZO = swap32IfLE( bytes_lzo );
351
351
 
352
352
        m_sock->write( (const char *) &hdr, sizeof( hdr ) );
353
353
        m_sock->write( (const char *) comp, swap32IfLE( hdr.bytesLZO ) );
357
357
                        }
358
358
                        else
359
359
                        {
360
 
 
361
360
        m_sock->write( (const char *) &hdr, sizeof( hdr ) );
362
 
        for( Q_UINT16 y = 0; y < h; ++y )
363
 
        {
364
 
                m_sock->write( (const char *)
365
 
                        ( (const QRgb *) i.scanLine( it->y() + y ) + it->x() ),
366
 
                                                        w * sizeof( QRgb ) );
 
361
        if( m_otherEndianess )
 
362
        {
 
363
                Q_UINT32 * buf = new Q_UINT32[w];
 
364
                for( Q_UINT16 y = 0; y < h; ++y )
 
365
                {
 
366
                        const QRgb * src = (const QRgb *) i.scanLine( it->y() + y ) +
 
367
                                                                                it->x();
 
368
                        for( Q_UINT16 x = 0; x < w; ++x, ++src )
 
369
                        {
 
370
                                buf[x] = swap32( *src );
 
371
                        }
 
372
                        m_sock->write( (const char *) buf, w * sizeof( QRgb ) );
 
373
                }
 
374
                delete[] buf;
 
375
        }
 
376
        else
 
377
        {
 
378
                for( Q_UINT16 y = 0; y < h; ++y )
 
379
                {
 
380
                        m_sock->write( (const char *)
 
381
                                ( (const QRgb *) i.scanLine( it->y() + y ) + it->x() ),
 
382
                                                                w * sizeof( QRgb ) );
 
383
                }
367
384
        }
368
385
                        }
369
386
                }
392
409
                }
393
410
 
394
411
                // reset vars
395
 
                m_changedRegion.clear();
 
412
                //m_changedRegion.clear();
 
413
                m_changedRegion = QRegion();
396
414
                m_cursorShapeChanged = FALSE;
397
415
        }
398
416
        //m_sock->waitForBytesWritten();
444
462
        si.format.greenMax = swap16IfLE( si.format.greenMax );
445
463
        si.format.blueMax = swap16IfLE( si.format.blueMax );
446
464
        si.nameLength = swap32IfLE( si.nameLength );
447
 
 
 
465
        si.format.bigEndian = ( QSysInfo::ByteOrder == QSysInfo::BigEndian )
 
466
                                                                        ? 1 : 0;
448
467
        if( !sd.write( ( const char *) &si, sizeof( si ) ) )
449
468
        {
450
469
                deleteLater();
471
490
                return;
472
491
        }
473
492
 
 
493
        // we have to do server-side endianess-conversion in case it differs
 
494
        // between client and server
 
495
        if( spf.format.bigEndian != si.format.bigEndian )
 
496
        {
 
497
                m_otherEndianess = TRUE;
 
498
        }
 
499
 
474
500
        char buf[sizeof( rfbSetPixelFormatMsg ) + MAX_ENCODINGS *
475
501
                                                        sizeof( Q_UINT32 )];
476
502
        rfbSetEncodingsMsg * se = (rfbSetEncodingsMsg *) buf;
509
535
 
510
536
        // for some reason we have to do this to make the following connection
511
537
        // working
512
 
        qRegisterMetaType<rectList>( "rectList" );
513
538
 
514
539
        connect( m_conn, SIGNAL( cursorShapeChanged() ),
515
540
                                this, SLOT( updateCursorShape() ) );
516
 
        connect( m_conn, SIGNAL( regionUpdated( const rectList & ) ),
517
 
                        this, SLOT( updateRegion( const rectList & ) ) );
 
541
        connect( m_conn, SIGNAL( regionUpdated( const QRegion & ) ),
 
542
                        this, SLOT( updateRegion( const QRegion & ) ) );
518
543
 
519
544
        ml.unlock();
520
545