Initial work on a VNC QPA plugin
The basics work and the VNC client is showing pixels Change-Id: Ie31efce2f31dd5f57af209dcc9c8f9aace730afd Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
This commit is contained in:
parent
05aedf4e1d
commit
6d70e543aa
67
src/plugins/platforms/vnc/main.cpp
Normal file
67
src/plugins/platforms/vnc/main.cpp
Normal file
@ -0,0 +1,67 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the QtGui module of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL3 included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 3 requirements
|
||||
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 2.0 or (at your option) the GNU General
|
||||
** Public license version 3 or any later version approved by the KDE Free
|
||||
** Qt Foundation. The licenses are as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
|
||||
** https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <qpa/qplatformintegrationplugin.h>
|
||||
#include "qvncintegration.h"
|
||||
#include "qvnc_p.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QVncIntegrationPlugin : public QPlatformIntegrationPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PLUGIN_METADATA(IID QPlatformIntegrationFactoryInterface_iid FILE "vnc.json")
|
||||
public:
|
||||
QPlatformIntegration *create(const QString&, const QStringList&) Q_DECL_OVERRIDE;
|
||||
};
|
||||
|
||||
QPlatformIntegration* QVncIntegrationPlugin::create(const QString& system, const QStringList& paramList)
|
||||
{
|
||||
QT_VNC_DEBUG() << "loading vnc plugin" << system;
|
||||
Q_UNUSED(paramList);
|
||||
if (!system.compare(QLatin1String("vnc"), Qt::CaseInsensitive))
|
||||
return new QVncIntegration(paramList);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#include "main.moc"
|
||||
|
1419
src/plugins/platforms/vnc/qvnc.cpp
Normal file
1419
src/plugins/platforms/vnc/qvnc.cpp
Normal file
File diff suppressed because it is too large
Load Diff
476
src/plugins/platforms/vnc/qvnc_p.h
Normal file
476
src/plugins/platforms/vnc/qvnc_p.h
Normal file
@ -0,0 +1,476 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the QtGui module of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL3 included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 3 requirements
|
||||
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 2.0 or (at your option) the GNU General
|
||||
** Public license version 3 or any later version approved by the KDE Free
|
||||
** Qt Foundation. The licenses are as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
|
||||
** https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QVNC_P_H
|
||||
#define QVNC_P_H
|
||||
|
||||
#include <QtCore/qdebug.h>
|
||||
#if 0
|
||||
#define QT_VNC_DEBUG if (1) {} else qDebug
|
||||
#else
|
||||
#define QT_VNC_DEBUG qDebug
|
||||
#endif
|
||||
|
||||
#include "qvncscreen.h"
|
||||
|
||||
#include <QtCore/qbytearray.h>
|
||||
#include <QtCore/qvarlengtharray.h>
|
||||
#include <qpa/qplatformcursor.h>
|
||||
|
||||
class QTcpSocket;
|
||||
class QTcpServer;
|
||||
|
||||
class QVncScreen;
|
||||
class QVncServer;
|
||||
class QVncClientCursor;
|
||||
|
||||
#define MAP_TILE_SIZE 16
|
||||
#define MAP_WIDTH 1280 / MAP_TILE_SIZE
|
||||
#define MAP_HEIGHT 1024 / MAP_TILE_SIZE
|
||||
|
||||
class QVncDirtyMap
|
||||
{
|
||||
public:
|
||||
QVncDirtyMap(QVncScreen *screen);
|
||||
virtual ~QVncDirtyMap();
|
||||
|
||||
void reset();
|
||||
bool dirty(int x, int y) const;
|
||||
virtual void setDirty(int x, int y, bool force = false) = 0;
|
||||
void setClean(int x, int y);
|
||||
|
||||
QVncScreen *screen;
|
||||
int bytesPerPixel;
|
||||
int numDirty;
|
||||
int mapWidth;
|
||||
int mapHeight;
|
||||
|
||||
protected:
|
||||
uchar *map;
|
||||
uchar *buffer;
|
||||
int bufferWidth;
|
||||
int bufferHeight;
|
||||
int bufferStride;
|
||||
int numTiles;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class QVncDirtyMapOptimized : public QVncDirtyMap
|
||||
{
|
||||
public:
|
||||
QVncDirtyMapOptimized(QVncScreen *screen) : QVncDirtyMap(screen) {}
|
||||
~QVncDirtyMapOptimized() {}
|
||||
|
||||
void setDirty(int x, int y, bool force = false);
|
||||
};
|
||||
|
||||
|
||||
class QRfbRect
|
||||
{
|
||||
public:
|
||||
QRfbRect() {}
|
||||
QRfbRect(quint16 _x, quint16 _y, quint16 _w, quint16 _h) {
|
||||
x = _x; y = _y; w = _w; h = _h;
|
||||
}
|
||||
|
||||
void read(QTcpSocket *s);
|
||||
void write(QTcpSocket *s) const;
|
||||
|
||||
quint16 x;
|
||||
quint16 y;
|
||||
quint16 w;
|
||||
quint16 h;
|
||||
};
|
||||
|
||||
class QRfbPixelFormat
|
||||
{
|
||||
public:
|
||||
static int size() { return 16; }
|
||||
|
||||
void read(QTcpSocket *s);
|
||||
void write(QTcpSocket *s);
|
||||
|
||||
int bitsPerPixel;
|
||||
int depth;
|
||||
bool bigEndian;
|
||||
bool trueColor;
|
||||
int redBits;
|
||||
int greenBits;
|
||||
int blueBits;
|
||||
int redShift;
|
||||
int greenShift;
|
||||
int blueShift;
|
||||
};
|
||||
|
||||
class QRfbServerInit
|
||||
{
|
||||
public:
|
||||
QRfbServerInit() { name = 0; }
|
||||
~QRfbServerInit() { delete[] name; }
|
||||
|
||||
int size() const { return QRfbPixelFormat::size() + 8 + strlen(name); }
|
||||
void setName(const char *n);
|
||||
|
||||
void read(QTcpSocket *s);
|
||||
void write(QTcpSocket *s);
|
||||
|
||||
quint16 width;
|
||||
quint16 height;
|
||||
QRfbPixelFormat format;
|
||||
char *name;
|
||||
};
|
||||
|
||||
class QRfbSetEncodings
|
||||
{
|
||||
public:
|
||||
bool read(QTcpSocket *s);
|
||||
|
||||
quint16 count;
|
||||
};
|
||||
|
||||
class QRfbFrameBufferUpdateRequest
|
||||
{
|
||||
public:
|
||||
bool read(QTcpSocket *s);
|
||||
|
||||
char incremental;
|
||||
QRfbRect rect;
|
||||
};
|
||||
|
||||
class QRfbKeyEvent
|
||||
{
|
||||
public:
|
||||
bool read(QTcpSocket *s);
|
||||
|
||||
char down;
|
||||
int keycode;
|
||||
int unicode;
|
||||
};
|
||||
|
||||
class QRfbPointerEvent
|
||||
{
|
||||
public:
|
||||
bool read(QTcpSocket *s);
|
||||
|
||||
uint buttons;
|
||||
quint16 x;
|
||||
quint16 y;
|
||||
};
|
||||
|
||||
class QRfbClientCutText
|
||||
{
|
||||
public:
|
||||
bool read(QTcpSocket *s);
|
||||
|
||||
quint32 length;
|
||||
};
|
||||
|
||||
class QRfbEncoder
|
||||
{
|
||||
public:
|
||||
QRfbEncoder(QVncServer *s) : server(s) {}
|
||||
virtual ~QRfbEncoder() {}
|
||||
|
||||
virtual void write() = 0;
|
||||
|
||||
protected:
|
||||
QVncServer *server;
|
||||
};
|
||||
|
||||
class QRfbRawEncoder : public QRfbEncoder
|
||||
{
|
||||
public:
|
||||
QRfbRawEncoder(QVncServer *s) : QRfbEncoder(s) {}
|
||||
|
||||
void write();
|
||||
|
||||
private:
|
||||
QByteArray buffer;
|
||||
};
|
||||
|
||||
template <class SRC> class QRfbHextileEncoder;
|
||||
|
||||
template <class SRC>
|
||||
class QRfbSingleColorHextile
|
||||
{
|
||||
public:
|
||||
QRfbSingleColorHextile(QRfbHextileEncoder<SRC> *e) : encoder(e) {}
|
||||
bool read(const uchar *data, int width, int height, int stride);
|
||||
void write(QTcpSocket *socket) const;
|
||||
|
||||
private:
|
||||
QRfbHextileEncoder<SRC> *encoder;
|
||||
};
|
||||
|
||||
template <class SRC>
|
||||
class QRfbDualColorHextile
|
||||
{
|
||||
public:
|
||||
QRfbDualColorHextile(QRfbHextileEncoder<SRC> *e) : encoder(e) {}
|
||||
bool read(const uchar *data, int width, int height, int stride);
|
||||
void write(QTcpSocket *socket) const;
|
||||
|
||||
private:
|
||||
struct Rect {
|
||||
quint8 xy;
|
||||
quint8 wh;
|
||||
} Q_PACKED rects[8 * 16];
|
||||
|
||||
quint8 numRects;
|
||||
QRfbHextileEncoder<SRC> *encoder;
|
||||
|
||||
private:
|
||||
inline int lastx() const { return rectx(numRects); }
|
||||
inline int lasty() const { return recty(numRects); }
|
||||
inline int rectx(int r) const { return rects[r].xy >> 4; }
|
||||
inline int recty(int r) const { return rects[r].xy & 0x0f; }
|
||||
inline int width(int r) const { return (rects[r].wh >> 4) + 1; }
|
||||
inline int height(int r) const { return (rects[r].wh & 0x0f) + 1; }
|
||||
|
||||
inline void setX(int r, int x) {
|
||||
rects[r].xy = (x << 4) | (rects[r].xy & 0x0f);
|
||||
}
|
||||
inline void setY(int r, int y) {
|
||||
rects[r].xy = (rects[r].xy & 0xf0) | y;
|
||||
}
|
||||
inline void setWidth(int r, int width) {
|
||||
rects[r].wh = ((width - 1) << 4) | (rects[r].wh & 0x0f);
|
||||
}
|
||||
inline void setHeight(int r, int height) {
|
||||
rects[r].wh = (rects[r].wh & 0xf0) | (height - 1);
|
||||
}
|
||||
|
||||
inline void setWidth(int width) { setWidth(numRects, width); }
|
||||
inline void setHeight(int height) { setHeight(numRects, height); }
|
||||
inline void setX(int x) { setX(numRects, x); }
|
||||
inline void setY(int y) { setY(numRects, y); }
|
||||
void next();
|
||||
};
|
||||
|
||||
template <class SRC>
|
||||
class QRfbMultiColorHextile
|
||||
{
|
||||
public:
|
||||
QRfbMultiColorHextile(QRfbHextileEncoder<SRC> *e) : encoder(e) {}
|
||||
bool read(const uchar *data, int width, int height, int stride);
|
||||
void write(QTcpSocket *socket) const;
|
||||
|
||||
private:
|
||||
inline quint8* rect(int r) {
|
||||
return rects.data() + r * (bpp + 2);
|
||||
}
|
||||
inline const quint8* rect(int r) const {
|
||||
return rects.constData() + r * (bpp + 2);
|
||||
}
|
||||
inline void setX(int r, int x) {
|
||||
quint8 *ptr = rect(r) + bpp;
|
||||
*ptr = (x << 4) | (*ptr & 0x0f);
|
||||
}
|
||||
inline void setY(int r, int y) {
|
||||
quint8 *ptr = rect(r) + bpp;
|
||||
*ptr = (*ptr & 0xf0) | y;
|
||||
}
|
||||
void setColor(SRC color);
|
||||
inline int rectx(int r) const {
|
||||
const quint8 *ptr = rect(r) + bpp;
|
||||
return *ptr >> 4;
|
||||
}
|
||||
inline int recty(int r) const {
|
||||
const quint8 *ptr = rect(r) + bpp;
|
||||
return *ptr & 0x0f;
|
||||
}
|
||||
inline void setWidth(int r, int width) {
|
||||
quint8 *ptr = rect(r) + bpp + 1;
|
||||
*ptr = ((width - 1) << 4) | (*ptr & 0x0f);
|
||||
}
|
||||
inline void setHeight(int r, int height) {
|
||||
quint8 *ptr = rect(r) + bpp + 1;
|
||||
*ptr = (*ptr & 0xf0) | (height - 1);
|
||||
}
|
||||
|
||||
bool beginRect();
|
||||
void endRect();
|
||||
|
||||
static const int maxRectsSize = 16 * 16;
|
||||
QVarLengthArray<quint8, maxRectsSize> rects;
|
||||
|
||||
quint8 bpp;
|
||||
quint8 numRects;
|
||||
QRfbHextileEncoder<SRC> *encoder;
|
||||
};
|
||||
|
||||
template <class SRC>
|
||||
class QRfbHextileEncoder : public QRfbEncoder
|
||||
{
|
||||
public:
|
||||
QRfbHextileEncoder(QVncServer *s);
|
||||
void write();
|
||||
|
||||
private:
|
||||
enum SubEncoding {
|
||||
Raw = 1,
|
||||
BackgroundSpecified = 2,
|
||||
ForegroundSpecified = 4,
|
||||
AnySubrects = 8,
|
||||
SubrectsColoured = 16
|
||||
};
|
||||
|
||||
QByteArray buffer;
|
||||
QRfbSingleColorHextile<SRC> singleColorHextile;
|
||||
QRfbDualColorHextile<SRC> dualColorHextile;
|
||||
QRfbMultiColorHextile<SRC> multiColorHextile;
|
||||
|
||||
SRC bg;
|
||||
SRC fg;
|
||||
bool newBg;
|
||||
bool newFg;
|
||||
|
||||
friend class QRfbSingleColorHextile<SRC>;
|
||||
friend class QRfbDualColorHextile<SRC>;
|
||||
friend class QRfbMultiColorHextile<SRC>;
|
||||
};
|
||||
|
||||
class QVncClientCursor : public QPlatformCursor
|
||||
{
|
||||
public:
|
||||
QVncClientCursor(QVncServer *s);
|
||||
~QVncClientCursor();
|
||||
|
||||
void write() const;
|
||||
|
||||
void changeCursor(QCursor *widgetCursor, QWindow *window);
|
||||
|
||||
QImage cursor;
|
||||
QPoint hotspot;
|
||||
QVncServer *server;
|
||||
};
|
||||
|
||||
|
||||
class QVncServer : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QVncServer(QVncScreen *screen);
|
||||
QVncServer(QVncScreen *screen, int id);
|
||||
~QVncServer();
|
||||
|
||||
void setDirty();
|
||||
void setDirtyCursor() { dirtyCursor = true; setDirty(); }
|
||||
inline bool isConnected() const { return state == Connected; }
|
||||
inline void setRefreshRate(int rate) { refreshRate = rate; }
|
||||
|
||||
enum ClientMsg { SetPixelFormat = 0,
|
||||
FixColourMapEntries = 1,
|
||||
SetEncodings = 2,
|
||||
FramebufferUpdateRequest = 3,
|
||||
KeyEvent = 4,
|
||||
PointerEvent = 5,
|
||||
ClientCutText = 6 };
|
||||
|
||||
enum ServerMsg { FramebufferUpdate = 0,
|
||||
SetColourMapEntries = 1 };
|
||||
|
||||
void convertPixels(char *dst, const char *src, int count) const;
|
||||
|
||||
inline int clientBytesPerPixel() const {
|
||||
return pixelFormat.bitsPerPixel / 8;
|
||||
}
|
||||
|
||||
inline QVncScreen* screen() const { return qvnc_screen; }
|
||||
inline QVncDirtyMap* dirtyMap() const { return qvnc_screen->dirty; }
|
||||
inline QTcpSocket* clientSocket() const { return client; }
|
||||
QImage screenImage() const;
|
||||
inline bool doPixelConversion() const { return needConversion; }
|
||||
#ifndef QT_NO_QWS_CURSOR
|
||||
inline bool hasClientCursor() const { return qvnc_cursor != 0; }
|
||||
#endif
|
||||
|
||||
private:
|
||||
void setPixelFormat();
|
||||
void setEncodings();
|
||||
void frameBufferUpdateRequest();
|
||||
void pointerEvent();
|
||||
void keyEvent();
|
||||
void clientCutText();
|
||||
bool pixelConversionNeeded() const;
|
||||
|
||||
private slots:
|
||||
void newConnection();
|
||||
void readClient();
|
||||
void checkUpdate();
|
||||
void discardClient();
|
||||
void init();
|
||||
|
||||
private:
|
||||
enum ClientState { Disconnected, Protocol, Init, Connected };
|
||||
QTimer *timer;
|
||||
QTcpServer *serverSocket;
|
||||
QTcpSocket *client;
|
||||
ClientState state;
|
||||
quint8 msgType;
|
||||
bool handleMsg;
|
||||
QRfbPixelFormat pixelFormat;
|
||||
Qt::KeyboardModifiers keymod;
|
||||
int encodingsPending;
|
||||
int cutTextPending;
|
||||
uint supportCopyRect : 1;
|
||||
uint supportRRE : 1;
|
||||
uint supportCoRRE : 1;
|
||||
uint supportHextile : 1;
|
||||
uint supportZRLE : 1;
|
||||
uint supportCursor : 1;
|
||||
uint supportDesktopSize : 1;
|
||||
bool wantUpdate;
|
||||
bool sameEndian;
|
||||
bool needConversion;
|
||||
#if Q_BYTE_ORDER == Q_BIG_ENDIAN
|
||||
bool swapBytes;
|
||||
#endif
|
||||
bool dirtyCursor;
|
||||
int refreshRate;
|
||||
QVncScreen *qvnc_screen;
|
||||
#ifndef QT_NO_QWS_CURSOR
|
||||
QVncClientCursor *qvnc_cursor;
|
||||
#endif
|
||||
|
||||
QRfbEncoder *encoder;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
131
src/plugins/platforms/vnc/qvncintegration.cpp
Normal file
131
src/plugins/platforms/vnc/qvncintegration.cpp
Normal file
@ -0,0 +1,131 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2015 The Qt Company Ltd.
|
||||
** Contact: http://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the FOO module of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL3$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see http://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at http://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPLv3 included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 3 requirements
|
||||
** will be met: https://www.gnu.org/licenses/lgpl.html.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 2.0 or later as published by the Free
|
||||
** Software Foundation and appearing in the file LICENSE.GPL included in
|
||||
** the packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 2.0 requirements will be
|
||||
** met: http://www.gnu.org/licenses/gpl-2.0.html.
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qvncintegration.h"
|
||||
#include "qvncscreen.h"
|
||||
#include "qvnc_p.h"
|
||||
|
||||
#include <QtPlatformSupport/private/qgenericunixfontdatabase_p.h>
|
||||
#include <QtPlatformSupport/private/qgenericunixservices_p.h>
|
||||
#include <QtPlatformSupport/private/qgenericunixeventdispatcher_p.h>
|
||||
|
||||
#include <QtPlatformSupport/private/qfbbackingstore_p.h>
|
||||
#include <QtPlatformSupport/private/qfbwindow_p.h>
|
||||
#include <QtPlatformSupport/private/qfbcursor_p.h>
|
||||
|
||||
#include <QtGui/private/qguiapplication_p.h>
|
||||
#include <qpa/qplatforminputcontextfactory_p.h>
|
||||
|
||||
#ifndef QT_NO_LIBINPUT
|
||||
#include <QtPlatformSupport/private/qlibinputhandler_p.h>
|
||||
#endif
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
QVncIntegration::QVncIntegration(const QStringList ¶mList)
|
||||
: m_fontDb(new QGenericUnixFontDatabase),
|
||||
m_services(new QGenericUnixServices)
|
||||
{
|
||||
m_primaryScreen = new QVncScreen(paramList);
|
||||
m_server = new QVncServer(m_primaryScreen);
|
||||
m_primaryScreen->vncServer = m_server;
|
||||
}
|
||||
|
||||
QVncIntegration::~QVncIntegration()
|
||||
{
|
||||
delete m_server;
|
||||
destroyScreen(m_primaryScreen);
|
||||
}
|
||||
|
||||
void QVncIntegration::initialize()
|
||||
{
|
||||
if (m_primaryScreen->initialize())
|
||||
screenAdded(m_primaryScreen);
|
||||
else
|
||||
qWarning("vnc: Failed to initialize screen");
|
||||
|
||||
m_inputContext = QPlatformInputContextFactory::create();
|
||||
|
||||
m_nativeInterface.reset(new QPlatformNativeInterface);
|
||||
}
|
||||
|
||||
bool QVncIntegration::hasCapability(QPlatformIntegration::Capability cap) const
|
||||
{
|
||||
switch (cap) {
|
||||
case ThreadedPixmaps: return true;
|
||||
case WindowManagement: return false;
|
||||
default: return QPlatformIntegration::hasCapability(cap);
|
||||
}
|
||||
}
|
||||
|
||||
QPlatformBackingStore *QVncIntegration::createPlatformBackingStore(QWindow *window) const
|
||||
{
|
||||
return new QFbBackingStore(window);
|
||||
}
|
||||
|
||||
QPlatformWindow *QVncIntegration::createPlatformWindow(QWindow *window) const
|
||||
{
|
||||
return new QFbWindow(window);
|
||||
}
|
||||
|
||||
QAbstractEventDispatcher *QVncIntegration::createEventDispatcher() const
|
||||
{
|
||||
return createUnixEventDispatcher();
|
||||
}
|
||||
|
||||
QList<QPlatformScreen *> QVncIntegration::screens() const
|
||||
{
|
||||
QList<QPlatformScreen *> list;
|
||||
list.append(m_primaryScreen);
|
||||
return list;
|
||||
}
|
||||
|
||||
QPlatformFontDatabase *QVncIntegration::fontDatabase() const
|
||||
{
|
||||
return m_fontDb.data();
|
||||
}
|
||||
|
||||
QPlatformServices *QVncIntegration::services() const
|
||||
{
|
||||
return m_services.data();
|
||||
}
|
||||
|
||||
QPlatformNativeInterface *QVncIntegration::nativeInterface() const
|
||||
{
|
||||
return m_nativeInterface.data();
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
85
src/plugins/platforms/vnc/qvncintegration.h
Normal file
85
src/plugins/platforms/vnc/qvncintegration.h
Normal file
@ -0,0 +1,85 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the QtGui module of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL3 included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 3 requirements
|
||||
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 2.0 or (at your option) the GNU General
|
||||
** Public license version 3 or any later version approved by the KDE Free
|
||||
** Qt Foundation. The licenses are as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
|
||||
** https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QVNCINTEGRATION_H
|
||||
#define QVNCINTEGRATION_H
|
||||
|
||||
#include <qpa/qplatformintegration.h>
|
||||
#include <qpa/qplatformnativeinterface.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QAbstractEventDispatcher;
|
||||
class QVncScreen;
|
||||
class QVncServer;
|
||||
|
||||
class QVncIntegration : public QPlatformIntegration, public QPlatformNativeInterface
|
||||
{
|
||||
public:
|
||||
QVncIntegration(const QStringList ¶mList);
|
||||
~QVncIntegration();
|
||||
|
||||
void initialize() Q_DECL_OVERRIDE;
|
||||
bool hasCapability(QPlatformIntegration::Capability cap) const Q_DECL_OVERRIDE;
|
||||
|
||||
QPlatformWindow *createPlatformWindow(QWindow *window) const Q_DECL_OVERRIDE;
|
||||
QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const Q_DECL_OVERRIDE;
|
||||
|
||||
QAbstractEventDispatcher *createEventDispatcher() const Q_DECL_OVERRIDE;
|
||||
|
||||
QPlatformFontDatabase *fontDatabase() const Q_DECL_OVERRIDE;
|
||||
QPlatformServices *services() const Q_DECL_OVERRIDE;
|
||||
QPlatformInputContext *inputContext() const Q_DECL_OVERRIDE { return m_inputContext; }
|
||||
|
||||
QPlatformNativeInterface *nativeInterface() const Q_DECL_OVERRIDE;
|
||||
|
||||
QList<QPlatformScreen *> screens() const;
|
||||
|
||||
private:
|
||||
mutable QVncServer *m_server;
|
||||
QVncScreen *m_primaryScreen;
|
||||
QPlatformInputContext *m_inputContext;
|
||||
QScopedPointer<QPlatformFontDatabase> m_fontDb;
|
||||
QScopedPointer<QPlatformServices> m_services;
|
||||
QScopedPointer<QPlatformNativeInterface> m_nativeInterface;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QVNCINTEGRATION_H
|
175
src/plugins/platforms/vnc/qvncscreen.cpp
Normal file
175
src/plugins/platforms/vnc/qvncscreen.cpp
Normal file
@ -0,0 +1,175 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the QtGui module of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL3 included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 3 requirements
|
||||
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 2.0 or (at your option) the GNU General
|
||||
** Public license version 3 or any later version approved by the KDE Free
|
||||
** Qt Foundation. The licenses are as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
|
||||
** https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qvncscreen.h"
|
||||
#include "qvnc_p.h"
|
||||
#include <QtPlatformSupport/private/qfbwindow_p.h>
|
||||
|
||||
#include <QtGui/QPainter>
|
||||
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
|
||||
QVncScreen::QVncScreen(const QStringList &args)
|
||||
: mArgs(args)
|
||||
{
|
||||
initialize();
|
||||
}
|
||||
|
||||
QVncScreen::~QVncScreen()
|
||||
{
|
||||
}
|
||||
|
||||
bool QVncScreen::initialize()
|
||||
{
|
||||
mGeometry = QRect(0, 0, 1024, 768);
|
||||
mFormat = QImage::Format_ARGB32_Premultiplied;
|
||||
mDepth = 32;
|
||||
mPhysicalSize = QSizeF(mGeometry.width()/96.*25.4, mGeometry.height()/96.*25.4);
|
||||
|
||||
QFbScreen::initializeCompositor();
|
||||
QT_VNC_DEBUG() << "QVncScreen::init" << geometry();
|
||||
|
||||
mCursor = new QFbCursor(this);
|
||||
|
||||
switch (depth()) {
|
||||
#if 1//def QT_QWS_DEPTH_32
|
||||
case 32:
|
||||
dirty = new QVncDirtyMapOptimized<quint32>(this);
|
||||
break;
|
||||
#endif
|
||||
//#if 1//def QT_QWS_DEPTH_24
|
||||
// case 24:
|
||||
// dirty = new QVncDirtyMapOptimized<qrgb888>(this);
|
||||
// break;
|
||||
//#endif
|
||||
//#if 1//def QT_QWS_DEPTH_24
|
||||
// case 18:
|
||||
// dirty = new QVncDirtyMapOptimized<qrgb666>(this);
|
||||
// break;
|
||||
//#endif
|
||||
#if 1//def QT_QWS_DEPTH_24
|
||||
case 16:
|
||||
dirty = new QVncDirtyMapOptimized<quint16>(this);
|
||||
break;
|
||||
#endif
|
||||
//#if 1//def QT_QWS_DEPTH_24
|
||||
// case 15:
|
||||
// dirty = new QVncDirtyMapOptimized<qrgb555>(this);
|
||||
// break;
|
||||
//#endif
|
||||
//#if 1//def QT_QWS_DEPTH_24
|
||||
// case 12:
|
||||
// dirty = new QVncDirtyMapOptimized<qrgb444>(this);
|
||||
// break;
|
||||
//#endif
|
||||
#if 1//def QT_QWS_DEPTH_24
|
||||
case 8:
|
||||
dirty = new QVncDirtyMapOptimized<quint8>(this);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
qWarning("QVNCScreen::initDevice: No support for screen depth %d",
|
||||
depth());
|
||||
dirty = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// const bool ok = QProxyScreen::initDevice();
|
||||
//#ifndef QT_NO_QWS_CURSOR
|
||||
// qt_screencursor = new QVNCCursor(this);
|
||||
//#endif
|
||||
// if (QProxyScreen::screen())
|
||||
// return ok;
|
||||
|
||||
// // Disable painting if there is only 1 display and nothing is attached to the VNC server
|
||||
// if (!d_ptr->noDisablePainting)
|
||||
// QWSServer::instance()->enablePainting(false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QRegion QVncScreen::doRedraw()
|
||||
{
|
||||
QRegion touched = QFbScreen::doRedraw();
|
||||
QT_VNC_DEBUG() << "qvncscreen::doRedraw()" << touched.rectCount();
|
||||
|
||||
if (touched.isEmpty())
|
||||
return touched;
|
||||
dirtyRegion += touched;
|
||||
|
||||
QVector<QRect> rects = touched.rects();
|
||||
for (int i = 0; i < rects.size(); i++) {
|
||||
// ### send to client
|
||||
}
|
||||
vncServer->setDirty();
|
||||
return touched;
|
||||
}
|
||||
|
||||
// grabWindow() grabs "from the screen" not from the backingstores.
|
||||
// In linuxfb's case it will also include the mouse cursor.
|
||||
QPixmap QVncScreen::grabWindow(WId wid, int x, int y, int width, int height) const
|
||||
{
|
||||
if (!wid) {
|
||||
if (width < 0)
|
||||
width = mScreenImage->width() - x;
|
||||
if (height < 0)
|
||||
height = mScreenImage->height() - y;
|
||||
return QPixmap::fromImage(*mScreenImage).copy(x, y, width, height);
|
||||
}
|
||||
|
||||
QFbWindow *window = windowForId(wid);
|
||||
if (window) {
|
||||
const QRect geom = window->geometry();
|
||||
if (width < 0)
|
||||
width = geom.width() - x;
|
||||
if (height < 0)
|
||||
height = geom.height() - y;
|
||||
QRect rect(geom.topLeft() + QPoint(x, y), QSize(width, height));
|
||||
rect &= window->geometry();
|
||||
return QPixmap::fromImage(*mScreenImage).copy(rect);
|
||||
}
|
||||
|
||||
return QPixmap();
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
83
src/plugins/platforms/vnc/qvncscreen.h
Normal file
83
src/plugins/platforms/vnc/qvncscreen.h
Normal file
@ -0,0 +1,83 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the QtGui module of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL3 included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 3 requirements
|
||||
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 2.0 or (at your option) the GNU General
|
||||
** Public license version 3 or any later version approved by the KDE Free
|
||||
** Qt Foundation. The licenses are as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
|
||||
** https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QVncScreen_H
|
||||
#define QVncScreen_H
|
||||
|
||||
#include <QtPlatformSupport/private/qfbscreen_p.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QPainter;
|
||||
class QFbCursor;
|
||||
class QTcpSocket;
|
||||
class QVncServer;
|
||||
class QVncDirtyMap;
|
||||
|
||||
class QVncScreen : public QFbScreen
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QVncScreen(const QStringList &args);
|
||||
~QVncScreen();
|
||||
|
||||
bool initialize();
|
||||
|
||||
QPixmap grabWindow(WId wid, int x, int y, int width, int height) const Q_DECL_OVERRIDE;
|
||||
|
||||
QRegion doRedraw() Q_DECL_OVERRIDE;
|
||||
QImage *image() const { return mScreenImage; }
|
||||
|
||||
void clearDirty() { dirtyRegion = QRegion(); }
|
||||
|
||||
QStringList mArgs;
|
||||
|
||||
qreal dpiX = 96;
|
||||
qreal dpiY = 96;
|
||||
QVncDirtyMap *dirty = 0;
|
||||
QRegion dirtyRegion;
|
||||
int refreshRate = 30;
|
||||
QVncServer *vncServer = 0;
|
||||
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QVncScreen_H
|
||||
|
3
src/plugins/platforms/vnc/vnc.json
Normal file
3
src/plugins/platforms/vnc/vnc.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"Keys": [ "vnc" ]
|
||||
}
|
15
src/plugins/platforms/vnc/vnc.pro
Normal file
15
src/plugins/platforms/vnc/vnc.pro
Normal file
@ -0,0 +1,15 @@
|
||||
TARGET = qvnc
|
||||
|
||||
PLUGIN_TYPE = platforms
|
||||
PLUGIN_CLASS_NAME = QVncIntegrationPlugin
|
||||
!equals(TARGET, $$QT_DEFAULT_QPA_PLUGIN): PLUGIN_EXTENDS = -
|
||||
load(qt_plugin)
|
||||
|
||||
QT += core-private gui-private platformsupport-private network
|
||||
|
||||
SOURCES = main.cpp qvncintegration.cpp qvncscreen.cpp qvnc.cpp
|
||||
HEADERS = qvncintegration.h qvncscreen.h qvnc_p.h
|
||||
|
||||
CONFIG += qpa/genericunixfontdatabase
|
||||
|
||||
OTHER_FILES += vnc.json
|
Loading…
Reference in New Issue
Block a user