Qt 4.8
qscreenvnc_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the plugins of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QSCREENVNC_P_H
43 #define QSCREENVNC_P_H
44 
45 //
46 // W A R N I N G
47 // -------------
48 //
49 // This file is not part of the Qt API. It exists for the convenience
50 // of the QLibrary class. This header file may change from version to version
51 // without notice, or even be removed.
52 //
53 // We mean it.
54 //
55 
56 #include "qscreenvnc_qws.h"
57 
58 #ifndef QT_NO_QWS_VNC
59 
60 #include <QtCore/qvarlengtharray.h>
61 #include <QtCore/qsharedmemory.h>
62 #include <QtNetwork/qtcpsocket.h>
63 #include <QtNetwork/qtcpserver.h>
64 
66 
67 class QVNCServer;
68 
69 #ifndef QT_NO_QWS_CURSOR
71 {
72 public:
74  ~QVNCCursor();
75 
76  void hide();
77  void show();
78  void set(const QImage &image, int hotx, int hoty);
79  void move(int x, int y);
80 
81 private:
82  void setDirty(const QRect &r) const;
84 };
85 
87 {
88 public:
91 
92  void set(const QImage &image, int hotx, int hoty);
93  void write() const;
94 
95 private:
97 };
98 #endif // QT_NO_QWS_CURSOR
99 
100 #define MAP_TILE_SIZE 16
101 #define MAP_WIDTH 1280 / MAP_TILE_SIZE
102 #define MAP_HEIGHT 1024 / MAP_TILE_SIZE
103 
105 {
106 public:
108  virtual ~QVNCDirtyMap();
109 
110  void reset();
111  bool dirty(int x, int y) const;
112  virtual void setDirty(int x, int y, bool force = false) = 0;
113  void setClean(int x, int y);
114 
116 
117  int numDirty;
118  int mapWidth;
120 
121 protected:
128  int numTiles;
129 };
130 
131 template <class T>
133 {
134 public:
137 
138  void setDirty(int x, int y, bool force = false);
139 };
140 
141 class QRfbRect
142 {
143 public:
144  QRfbRect() {}
146  x = _x; y = _y; w = _w; h = _h;
147  }
148 
149  void read(QTcpSocket *s);
150  void write(QTcpSocket *s) const;
151 
156 };
157 
159 {
160 public:
161  static int size() { return 16; }
162 
163  void read(QTcpSocket *s);
164  void write(QTcpSocket *s);
165 
167  int depth;
168  bool bigEndian;
169  bool trueColor;
170  int redBits;
172  int blueBits;
173  int redShift;
176 };
177 
179 {
180 public:
181  QRfbServerInit() { name = 0; }
182  ~QRfbServerInit() { delete[] name; }
183 
184  int size() const { return QRfbPixelFormat::size() + 8 + strlen(name); }
185  void setName(const char *n);
186 
187  void read(QTcpSocket *s);
188  void write(QTcpSocket *s);
189 
193  char *name;
194 };
195 
197 {
198 public:
199  bool read(QTcpSocket *s);
200 
202 };
203 
205 {
206 public:
207  bool read(QTcpSocket *s);
208 
211 };
212 
214 {
215 public:
216  bool read(QTcpSocket *s);
217 
218  char down;
219  int keycode;
220  int unicode;
221 };
222 
224 {
225 public:
226  bool read(QTcpSocket *s);
227 
231 };
232 
234 {
235 public:
236  bool read(QTcpSocket *s);
237 
239 };
240 
242 {
243 public:
246 
247  void setDirty(const QRect &rect, bool force = false);
248  void configure();
249 
256 
257 #if !defined(QT_NO_QWS_MULTIPROCESS) && !defined(QT_NO_SHAREDMEMORY)
259 #endif
260 
262 
264 };
265 
267 {
268 public:
270  virtual ~QRfbEncoder() {}
271 
272  virtual void write() = 0;
273 
274 protected:
276 };
277 
279 {
280 public:
282 
283  void write();
284 
285 private:
287 };
288 
289 template <class SRC> class QRfbHextileEncoder;
290 
291 template <class SRC>
293 {
294 public:
296  bool read(const uchar *data, int width, int height, int stride);
297  void write(QTcpSocket *socket) const;
298 
299 private:
301 };
302 
303 template <class SRC>
305 {
306 public:
308  bool read(const uchar *data, int width, int height, int stride);
309  void write(QTcpSocket *socket) const;
310 
311 private:
312  struct Rect {
315  } Q_PACKED rects[8 * 16];
316 
319 
320 private:
321  inline int lastx() const { return rectx(numRects); }
322  inline int lasty() const { return recty(numRects); }
323  inline int rectx(int r) const { return rects[r].xy >> 4; }
324  inline int recty(int r) const { return rects[r].xy & 0x0f; }
325  inline int width(int r) const { return (rects[r].wh >> 4) + 1; }
326  inline int height(int r) const { return (rects[r].wh & 0x0f) + 1; }
327 
328  inline void setX(int r, int x) {
329  rects[r].xy = (x << 4) | (rects[r].xy & 0x0f);
330  }
331  inline void setY(int r, int y) {
332  rects[r].xy = (rects[r].xy & 0xf0) | y;
333  }
334  inline void setWidth(int r, int width) {
335  rects[r].wh = ((width - 1) << 4) | (rects[r].wh & 0x0f);
336  }
337  inline void setHeight(int r, int height) {
338  rects[r].wh = (rects[r].wh & 0xf0) | (height - 1);
339  }
340 
341  inline void setWidth(int width) { setWidth(numRects, width); }
342  inline void setHeight(int height) { setHeight(numRects, height); }
343  inline void setX(int x) { setX(numRects, x); }
344  inline void setY(int y) { setY(numRects, y); }
345  void next();
346 };
347 
348 template <class SRC>
350 {
351 public:
353  bool read(const uchar *data, int width, int height, int stride);
354  void write(QTcpSocket *socket) const;
355 
356 private:
357  inline quint8* rect(int r) {
358  return rects.data() + r * (bpp + 2);
359  }
360  inline const quint8* rect(int r) const {
361  return rects.constData() + r * (bpp + 2);
362  }
363  inline void setX(int r, int x) {
364  quint8 *ptr = rect(r) + bpp;
365  *ptr = (x << 4) | (*ptr & 0x0f);
366  }
367  inline void setY(int r, int y) {
368  quint8 *ptr = rect(r) + bpp;
369  *ptr = (*ptr & 0xf0) | y;
370  }
371  void setColor(SRC color);
372  inline int rectx(int r) const {
373  const quint8 *ptr = rect(r) + bpp;
374  return *ptr >> 4;
375  }
376  inline int recty(int r) const {
377  const quint8 *ptr = rect(r) + bpp;
378  return *ptr & 0x0f;
379  }
380  inline void setWidth(int r, int width) {
381  quint8 *ptr = rect(r) + bpp + 1;
382  *ptr = ((width - 1) << 4) | (*ptr & 0x0f);
383  }
384  inline void setHeight(int r, int height) {
385  quint8 *ptr = rect(r) + bpp + 1;
386  *ptr = (*ptr & 0xf0) | (height - 1);
387  }
388 
389  bool beginRect();
390  void endRect();
391 
392  static const int maxRectsSize = 16 * 16;
394 
398 };
399 
400 template <class SRC>
401 class QRfbHextileEncoder : public QRfbEncoder
402 {
403 public:
405  void write();
406 
407 private:
408  enum SubEncoding {
409  Raw = 1,
410  BackgroundSpecified = 2,
411  ForegroundSpecified = 4,
412  AnySubrects = 8,
413  SubrectsColoured = 16
414  };
415 
420 
421  SRC bg;
422  SRC fg;
423  bool newBg;
424  bool newFg;
425 
426  friend class QRfbSingleColorHextile<SRC>;
427  friend class QRfbDualColorHextile<SRC>;
428  friend class QRfbMultiColorHextile<SRC>;
429 };
430 
431 class QVNCServer : public QObject
432 {
433  Q_OBJECT
434 public:
436  QVNCServer(QVNCScreen *screen, int id);
437  ~QVNCServer();
438 
439  void setDirty();
440  void setDirtyCursor() { dirtyCursor = true; setDirty(); }
441  inline bool isConnected() const { return state == Connected; }
442  inline void setRefreshRate(int rate) { refreshRate = rate; }
443 
444  enum ClientMsg { SetPixelFormat = 0,
445  FixColourMapEntries = 1,
446  SetEncodings = 2,
447  FramebufferUpdateRequest = 3,
448  KeyEvent = 4,
449  PointerEvent = 5,
450  ClientCutText = 6 };
451 
452  enum ServerMsg { FramebufferUpdate = 0,
453  SetColourMapEntries = 1 };
454 
455  void convertPixels(char *dst, const char *src, int count) const;
456 
457  inline int clientBytesPerPixel() const {
458  return pixelFormat.bitsPerPixel / 8;
459  }
460 
461  inline QVNCScreen* screen() const { return qvnc_screen; }
462  inline QVNCDirtyMap* dirtyMap() const { return qvnc_screen->d_ptr->dirty; }
463  inline QTcpSocket* clientSocket() const { return client; }
464  QImage screenImage() const;
465  inline bool doPixelConversion() const { return needConversion; }
466 #ifndef QT_NO_QWS_CURSOR
467  inline bool hasClientCursor() const { return qvnc_cursor != 0; }
468 #endif
469 
470 private:
471  void setPixelFormat();
472  void setEncodings();
473  void frameBufferUpdateRequest();
474  void pointerEvent();
475  void keyEvent();
476  void clientCutText();
477  bool pixelConversionNeeded() const;
478 
479 private slots:
480  void newConnection();
481  void readClient();
482  void checkUpdate();
483  void discardClient();
484 
485 private:
486  void init(uint port);
487  enum ClientState { Unconnected, Protocol, Init, Connected };
493  bool handleMsg;
495  Qt::KeyboardModifiers keymod;
508 #if Q_BYTE_ORDER == Q_BIG_ENDIAN
509  bool swapBytes;
510 #endif
514 #ifndef QT_NO_QWS_CURSOR
516 #endif
517 
519 };
520 
521 
523 #endif // QT_NO_QWS_VNC
524 #endif // QSCREENVNC_P_H
virtual ~QRfbEncoder()
Definition: qscreenvnc_p.h:270
virtual void pointerEvent(const QMouseEvent &event)
This method is called by Qt whenever a QMouseEvent is generated by the underlying pointer input...
Definition: fb_base.cpp:67
#define Q_PACKED
Definition: qglobal.h:815
quint8 * rect(int r)
Definition: qscreenvnc_p.h:357
The QProxyScreenCursor class provides a generic interface to QScreenCursor implementations.
double qreal
Definition: qglobal.h:1193
QRfbSingleColorHextile(QRfbHextileEncoder< SRC > *e)
Definition: qscreenvnc_p.h:295
bool dirty(int x, int y) const
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QRfbPixelFormat pixelFormat
Definition: qscreenvnc_p.h:494
uchar * buffer
Definition: qscreenvnc_p.h:124
quint16 x
Definition: qscreenvnc_p.h:152
QVNCScreen * qvnc_screen
Definition: qscreenvnc_p.h:513
QRfbEncoder * encoder
Definition: qscreenvnc_p.h:518
static void keyEvent(KeyAction action, QWidget *widget, char ascii, Qt::KeyboardModifiers modifier=Qt::NoModifier, int delay=-1)
static int size()
Definition: qscreenvnc_p.h:161
QRfbHextileEncoder< SRC > * encoder
Definition: qscreenvnc_p.h:300
bool isConnected() const
Definition: qscreenvnc_p.h:441
QVNCScreen * q_ptr
Definition: qscreenvnc_p.h:261
QTimer * timer
Definition: qscreenvnc_p.h:488
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
Q_CORE_EXPORT QTextStream & reset(QTextStream &s)
const quint8 * rect(int r) const
Definition: qscreenvnc_p.h:360
Qt::KeyboardModifiers keymod
Definition: qscreenvnc_p.h:495
void setWidth(int r, int width)
Definition: qscreenvnc_p.h:380
bool hasClientCursor() const
Definition: qscreenvnc_p.h:467
int cutTextPending
Definition: qscreenvnc_p.h:497
int rectx(int r) const
Definition: qscreenvnc_p.h:372
QRfbRawEncoder(QVNCServer *s)
Definition: qscreenvnc_p.h:281
unsigned char quint8
Definition: qglobal.h:934
ClientState state
Definition: qscreenvnc_p.h:491
int width(int r) const
Definition: qscreenvnc_p.h:325
QVNCServer * server
Definition: qscreenvnc_p.h:96
bool doPixelConversion() const
Definition: qscreenvnc_p.h:465
void setHeight(int r, int height)
Definition: qscreenvnc_p.h:337
bool swapBytes
Definition: qscreenvnc_p.h:509
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
uint supportCursor
Definition: qscreenvnc_p.h:503
QVNCScreen * screen
Definition: qscreenvnc_p.h:83
void setHeight(int height)
Definition: qscreenvnc_p.h:342
QImage image() const
Returns the cursor&#39;s image.
Definition: qscreen_qws.h:151
QVNCScreen * screen() const
Definition: qscreenvnc_p.h:461
bool wantUpdate
Definition: qscreenvnc_p.h:505
int height(int r) const
Definition: qscreenvnc_p.h:326
QTcpServer * serverSocket
Definition: qscreenvnc_p.h:489
unsigned char uchar
Definition: qglobal.h:994
uint supportRRE
Definition: qscreenvnc_p.h:499
uint supportDesktopSize
Definition: qscreenvnc_p.h:504
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void setRefreshRate(int rate)
Definition: qscreenvnc_p.h:442
uint supportHextile
Definition: qscreenvnc_p.h:501
The QVNCScreen class implements a screen driver for VNC servers.
int encodingsPending
Definition: qscreenvnc_p.h:496
QVNCCursor(QVNCScreen *s)
QScreen * screen
Definition: qscreenvnc_p.h:123
QVNCServer * server
Definition: qscreenvnc_p.h:275
static bool init
void setX(int r, int x)
Definition: qscreenvnc_p.h:363
const char * name
void show()
Reimplemented Function
void setWidth(int r, int width)
Definition: qscreenvnc_p.h:334
unsigned short quint16
Definition: qglobal.h:936
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
bool dirtyCursor
Definition: qscreenvnc_p.h:511
int recty(int r) const
Definition: qscreenvnc_p.h:376
static const char * data(const QByteArray &arr)
unsigned int uint
Definition: qglobal.h:996
void setX(int r, int x)
Definition: qscreenvnc_p.h:328
The QTcpSocket class provides a TCP socket.
Definition: qtcpsocket.h:56
QRfbPixelFormat format
Definition: qscreenvnc_p.h:192
const T * ptr(const T &t)
void setHeight(int r, int height)
Definition: qscreenvnc_p.h:384
void setWidth(int width)
Definition: qscreenvnc_p.h:341
#define Q_OBJECT
Definition: qobjectdefs.h:157
void setDirtyCursor()
Definition: qscreenvnc_p.h:440
quint16 h
Definition: qscreenvnc_p.h:155
QTcpSocket * client
Definition: qscreenvnc_p.h:490
QRfbHextileEncoder< SRC > * encoder
Definition: qscreenvnc_p.h:397
QByteArray buffer
Definition: qscreenvnc_p.h:286
QVarLengthArray< quint8, maxRectsSize > rects
Definition: qscreenvnc_p.h:393
int rectx(int r) const
Definition: qscreenvnc_p.h:323
QTcpSocket * clientSocket() const
Definition: qscreenvnc_p.h:463
QVNCDirtyMapOptimized(QScreen *screen)
Definition: qscreenvnc_p.h:135
uint supportZRLE
Definition: qscreenvnc_p.h:502
QVNCDirtyMap * dirtyMap() const
Definition: qscreenvnc_p.h:462
QSharedMemory shm
Definition: qscreenvnc_p.h:258
uint supportCopyRect
Definition: qscreenvnc_p.h:498
quint16 w
Definition: qscreenvnc_p.h:154
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
void hide()
Reimplemented Function
QVNCServer * server
Definition: qvnccursor.h:71
unsigned int quint32
Definition: qglobal.h:938
The QTcpServer class provides a TCP-based server.
Definition: qtcpserver.h:61
bool needConversion
Definition: qscreenvnc_p.h:507
quint16 y
Definition: qscreenvnc_p.h:153
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
The QSharedMemory class provides access to a shared memory segment.
Definition: qsharedmemory.h:57
void setY(int r, int y)
Definition: qscreenvnc_p.h:331
void setY(int r, int y)
Definition: qscreenvnc_p.h:367
int size() const
Definition: qscreenvnc_p.h:184
The QScreen class is a base class for screen drivers in Qt for Embedded Linux.
Definition: qscreen_qws.h:191
QRfbEncoder(QVNCServer *s)
Definition: qscreenvnc_p.h:269
QRfbMultiColorHextile(QRfbHextileEncoder< SRC > *e)
Definition: qscreenvnc_p.h:352
The QTimer class provides repetitive and single-shot timers.
Definition: qtimer.h:56
void move(int x, int y)
Reimplemented Function
uint supportCoRRE
Definition: qscreenvnc_p.h:500
#define slots
Definition: qobjectdefs.h:68
QRfbSingleColorHextile< SRC > singleColorHextile
Definition: qscreenvnc_p.h:417
QRfbMultiColorHextile< SRC > multiColorHextile
Definition: qscreenvnc_p.h:419
QRfbRect(quint16 _x, quint16 _y, quint16 _w, quint16 _h)
Definition: qscreenvnc_p.h:145
bool handleMsg
Definition: qscreenvnc_p.h:493
QRfbDualColorHextile< SRC > dualColorHextile
Definition: qscreenvnc_p.h:418
QVNCDirtyMap * dirty
Definition: qscreenvnc_p.h:253
virtual void setDirty()
Definition: fb_base.h:73
QRfbHextileEncoder< SRC > * encoder
Definition: qscreenvnc_p.h:318
QRfbDualColorHextile(QRfbHextileEncoder< SRC > *e)
Definition: qscreenvnc_p.h:307
quint8 msgType
Definition: qscreenvnc_p.h:492
int recty(int r) const
Definition: qscreenvnc_p.h:324
int clientBytesPerPixel() const
Definition: qscreenvnc_p.h:457
bool sameEndian
Definition: qscreenvnc_p.h:506
The KeyEvent object provides information about a key event.
QVNCClientCursor * qvnc_cursor
Definition: qscreenvnc_p.h:515
QVNCServer * vncServer
Definition: qscreenvnc_p.h:255