mirror of
https://github.com/KDE/krfb
synced 2026-07-01 07:41:17 -07:00
Apply KDELibs code style with astyle to clear up the mess that was there before.
svn path=/trunk/KDE/kdenetwork/krfb/; revision=1189254
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
const int UPDATE_TIME = 500;
|
||||
|
||||
QtFrameBuffer::QtFrameBuffer(WId id, QObject *parent)
|
||||
: FrameBuffer(id, parent)
|
||||
: FrameBuffer(id, parent)
|
||||
{
|
||||
fbImage = QPixmap::grabWindow(win).toImage();
|
||||
fb = new char[fbImage.numBytes()];
|
||||
@@ -49,7 +49,7 @@ int QtFrameBuffer::width()
|
||||
return fbImage.width();
|
||||
}
|
||||
|
||||
void QtFrameBuffer::getServerFormat(rfbPixelFormat& format)
|
||||
void QtFrameBuffer::getServerFormat(rfbPixelFormat &format)
|
||||
{
|
||||
format.bitsPerPixel = 32;
|
||||
format.depth = 32;
|
||||
@@ -80,12 +80,12 @@ void QtFrameBuffer::updateFrameBuffer()
|
||||
map.fill(0);
|
||||
|
||||
for (int x = 0; x < imgSize.width(); x++) {
|
||||
for (int y = 0; y < imgSize.height(); y++) {
|
||||
if (img.pixel(x,y) != fbImage.pixel(x,y)) {
|
||||
map.setPixel(x,y,1);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int y = 0; y < imgSize.height(); y++) {
|
||||
if (img.pixel(x, y) != fbImage.pixel(x, y)) {
|
||||
map.setPixel(x, y, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QRegion r(QBitmap::fromImage(map));
|
||||
tiles = tiles + r.rects();
|
||||
@@ -94,7 +94,7 @@ void QtFrameBuffer::updateFrameBuffer()
|
||||
tiles.append(img.rect());
|
||||
#endif
|
||||
|
||||
memcpy(fb, (const char*)img.bits(), img.numBytes());
|
||||
memcpy(fb, (const char *)img.bits(), img.numBytes());
|
||||
fbImage = img;
|
||||
|
||||
}
|
||||
|
||||
@@ -15,11 +15,11 @@
|
||||
|
||||
class QTimer;
|
||||
/**
|
||||
@author Alessandro Praduroux <pradu@pradu.it>
|
||||
@author Alessandro Praduroux <pradu@pradu.it>
|
||||
*/
|
||||
class QtFrameBuffer : public FrameBuffer
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit QtFrameBuffer(WId id, QObject *parent = 0);
|
||||
|
||||
@@ -29,7 +29,7 @@ public:
|
||||
virtual int height();
|
||||
virtual int width();
|
||||
virtual int paddedWidth();
|
||||
virtual void getServerFormat(rfbPixelFormat& format);
|
||||
virtual void getServerFormat(rfbPixelFormat &format);
|
||||
virtual void startMonitor();
|
||||
virtual void stopMonitor();
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
|
||||
QtFrameBufferPlugin::QtFrameBufferPlugin(QObject *parent, const QVariantList &args)
|
||||
: FrameBufferPlugin(parent, args)
|
||||
: FrameBufferPlugin(parent, args)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,8 @@
|
||||
#include <X11/extensions/XShm.h>
|
||||
#endif
|
||||
|
||||
class X11FrameBuffer::P {
|
||||
class X11FrameBuffer::P
|
||||
{
|
||||
|
||||
public:
|
||||
#ifdef HAVE_XDAMAGE
|
||||
@@ -50,8 +51,8 @@ public:
|
||||
bool running;
|
||||
};
|
||||
|
||||
X11FrameBuffer::X11FrameBuffer(WId id, QObject* parent)
|
||||
:FrameBuffer(id, parent), d(new X11FrameBuffer::P)
|
||||
X11FrameBuffer::X11FrameBuffer(WId id, QObject *parent)
|
||||
: FrameBuffer(id, parent), d(new X11FrameBuffer::P)
|
||||
{
|
||||
#ifdef HAVE_XSHM
|
||||
d->useShm = XShmQueryExtension(QX11Info::display());
|
||||
@@ -68,10 +69,11 @@ X11FrameBuffer::X11FrameBuffer(WId id, QObject* parent)
|
||||
QApplication::desktop()->height(),
|
||||
AllPlanes,
|
||||
ZPixmap);
|
||||
|
||||
if (d->useShm) {
|
||||
#ifdef HAVE_XSHM
|
||||
d->updateTile = XShmCreateImage(QX11Info::display(),
|
||||
DefaultVisual( QX11Info::display(), 0 ),
|
||||
DefaultVisual(QX11Info::display(), 0),
|
||||
d->framebufferImage->bits_per_pixel,
|
||||
ZPixmap,
|
||||
NULL,
|
||||
@@ -83,7 +85,7 @@ X11FrameBuffer::X11FrameBuffer(WId id, QObject* parent)
|
||||
IPC_CREAT | 0777);
|
||||
|
||||
d->shminfo.shmaddr = d->updateTile->data = (char *)
|
||||
shmat(d->shminfo.shmid, 0, 0);
|
||||
shmat(d->shminfo.shmid, 0, 0);
|
||||
d->shminfo.readOnly = False;
|
||||
|
||||
XShmAttach(QX11Info::display(), &d->shminfo);
|
||||
@@ -91,11 +93,12 @@ X11FrameBuffer::X11FrameBuffer(WId id, QObject* parent)
|
||||
} else {
|
||||
;
|
||||
}
|
||||
|
||||
kDebug() << "Got image. bpp: " << d->framebufferImage->bits_per_pixel
|
||||
<< ", depth: " << d->framebufferImage->depth
|
||||
<< ", padded width: " << d->framebufferImage->bytes_per_line
|
||||
<< " (sent: " << d->framebufferImage->width * 4 << ")"
|
||||
<< endl;
|
||||
<< ", depth: " << d->framebufferImage->depth
|
||||
<< ", padded width: " << d->framebufferImage->bytes_per_line
|
||||
<< " (sent: " << d->framebufferImage->width * 4 << ")"
|
||||
<< endl;
|
||||
|
||||
fb = d->framebufferImage->data;
|
||||
#ifdef HAVE_XDAMAGE
|
||||
@@ -142,14 +145,14 @@ int X11FrameBuffer::paddedWidth()
|
||||
return d->framebufferImage->bytes_per_line;
|
||||
}
|
||||
|
||||
void X11FrameBuffer::getServerFormat(rfbPixelFormat& format)
|
||||
void X11FrameBuffer::getServerFormat(rfbPixelFormat &format)
|
||||
{
|
||||
format.bitsPerPixel = d->framebufferImage->bits_per_pixel;
|
||||
format.depth = d->framebufferImage->depth;
|
||||
format.trueColour = true;
|
||||
format.bigEndian = ((d->framebufferImage->bitmap_bit_order == MSBFirst) ? true : false);
|
||||
|
||||
if ( format.bitsPerPixel == 8 ) {
|
||||
if (format.bitsPerPixel == 8) {
|
||||
format.redShift = 0;
|
||||
format.greenShift = 3;
|
||||
format.blueShift = 6;
|
||||
@@ -158,24 +161,33 @@ void X11FrameBuffer::getServerFormat(rfbPixelFormat& format)
|
||||
format.blueMax = 3;
|
||||
} else {
|
||||
format.redShift = 0;
|
||||
if ( d->framebufferImage->red_mask )
|
||||
while ( ! ( d->framebufferImage->red_mask & (1 << format.redShift) ) )
|
||||
|
||||
if (d->framebufferImage->red_mask)
|
||||
while (!(d->framebufferImage->red_mask & (1 << format.redShift))) {
|
||||
format.redShift++;
|
||||
}
|
||||
|
||||
format.greenShift = 0;
|
||||
if ( d->framebufferImage->green_mask )
|
||||
while ( ! ( d->framebufferImage->green_mask & (1 << format.greenShift) ) )
|
||||
|
||||
if (d->framebufferImage->green_mask)
|
||||
while (!(d->framebufferImage->green_mask & (1 << format.greenShift))) {
|
||||
format.greenShift++;
|
||||
}
|
||||
|
||||
format.blueShift = 0;
|
||||
if ( d->framebufferImage->blue_mask )
|
||||
while ( ! ( d->framebufferImage->blue_mask & (1 << format.blueShift) ) )
|
||||
|
||||
if (d->framebufferImage->blue_mask)
|
||||
while (!(d->framebufferImage->blue_mask & (1 << format.blueShift))) {
|
||||
format.blueShift++;
|
||||
}
|
||||
|
||||
format.redMax = d->framebufferImage->red_mask >> format.redShift;
|
||||
format.greenMax = d->framebufferImage->green_mask >> format.greenShift;
|
||||
format.blueMax = d->framebufferImage->blue_mask >> format.blueShift;
|
||||
}
|
||||
}
|
||||
|
||||
void X11FrameBuffer::handleXDamage(XEvent * event)
|
||||
void X11FrameBuffer::handleXDamage(XEvent *event)
|
||||
{
|
||||
#ifdef HAVE_XDAMAGE
|
||||
XDamageNotifyEvent *dev = (XDamageNotifyEvent *)event;
|
||||
@@ -189,118 +201,141 @@ void X11FrameBuffer::handleXDamage(XEvent * event)
|
||||
}
|
||||
|
||||
|
||||
void X11FrameBuffer::cleanupRects() {
|
||||
void X11FrameBuffer::cleanupRects()
|
||||
{
|
||||
|
||||
QList<QRect> cpy = tiles;
|
||||
bool inserted = false;
|
||||
tiles.clear();
|
||||
// kDebug() << "before cleanup: " << cpy.size();
|
||||
foreach (const QRect &r, cpy) {
|
||||
foreach(const QRect & r, cpy) {
|
||||
if (tiles.size() > 0) {
|
||||
for(int i = 0; i < tiles.size(); i++) {
|
||||
// kDebug() << r << tiles[i];
|
||||
for (int i = 0; i < tiles.size(); i++) {
|
||||
// kDebug() << r << tiles[i];
|
||||
if (r.intersects(tiles[i])) {
|
||||
tiles[i] |= r;
|
||||
inserted = true;
|
||||
break;
|
||||
// kDebug() << "merged into " << tiles[i];
|
||||
// kDebug() << "merged into " << tiles[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (!inserted) {
|
||||
tiles.append(r);
|
||||
// kDebug() << "appended " << r;
|
||||
// kDebug() << "appended " << r;
|
||||
}
|
||||
} else {
|
||||
// kDebug() << "appended " << r;
|
||||
// kDebug() << "appended " << r;
|
||||
tiles.append(r);
|
||||
}
|
||||
}
|
||||
for(int i = 0; i < tiles.size(); i++) {
|
||||
tiles[i].adjust(-30,-30,30,30);
|
||||
if (tiles[i].top() < 0){
|
||||
|
||||
for (int i = 0; i < tiles.size(); i++) {
|
||||
tiles[i].adjust(-30, -30, 30, 30);
|
||||
|
||||
if (tiles[i].top() < 0) {
|
||||
tiles[i].setTop(0);
|
||||
}
|
||||
if (tiles[i].left() < 0){
|
||||
|
||||
if (tiles[i].left() < 0) {
|
||||
tiles[i].setLeft(0);
|
||||
}
|
||||
|
||||
if (tiles[i].bottom() > d->framebufferImage->height) {
|
||||
tiles[i].setBottom(d->framebufferImage->height);
|
||||
}
|
||||
|
||||
if (tiles[i].right() > d->framebufferImage->width) {
|
||||
tiles[i].setRight(d->framebufferImage->width);
|
||||
}
|
||||
}
|
||||
|
||||
// kDebug() << "after cleanup: " << tiles.size();
|
||||
}
|
||||
|
||||
void X11FrameBuffer::acquireEvents() {
|
||||
void X11FrameBuffer::acquireEvents()
|
||||
{
|
||||
|
||||
XEvent ev;
|
||||
while (XCheckTypedEvent(QX11Info::display(), d->xdamageBaseEvent+XDamageNotify, &ev)) {
|
||||
|
||||
while (XCheckTypedEvent(QX11Info::display(), d->xdamageBaseEvent + XDamageNotify, &ev)) {
|
||||
handleXDamage(&ev);
|
||||
}
|
||||
XDamageSubtract(QX11Info::display(),d->damage, None, None);
|
||||
|
||||
XDamageSubtract(QX11Info::display(), d->damage, None, None);
|
||||
}
|
||||
|
||||
QList< QRect > X11FrameBuffer::modifiedTiles()
|
||||
{
|
||||
QList<QRect> ret;
|
||||
if (!d->running) return ret;
|
||||
|
||||
if (!d->running) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
kapp->processEvents(); // try to make sure every damage event goes trough;
|
||||
cleanupRects();
|
||||
QRect gl;
|
||||
|
||||
//d->useShm = false;
|
||||
if (tiles.size() > 0) {
|
||||
if (d->useShm) {
|
||||
#ifdef HAVE_XSHM
|
||||
|
||||
foreach(const QRect &r, tiles) {
|
||||
foreach(const QRect & r, tiles) {
|
||||
// kDebug() << r;
|
||||
gl |= r;
|
||||
int y = r.y();
|
||||
int x = r.x();
|
||||
while (x < r.right() ) {
|
||||
while (y < r.bottom() ) {
|
||||
if (y+d->updateTile->height > d->framebufferImage->height) {
|
||||
|
||||
while (x < r.right()) {
|
||||
while (y < r.bottom()) {
|
||||
if (y + d->updateTile->height > d->framebufferImage->height) {
|
||||
y = d->framebufferImage->height - d->updateTile->height;
|
||||
}
|
||||
if (x+d->updateTile->width > d->framebufferImage->width) {
|
||||
|
||||
if (x + d->updateTile->width > d->framebufferImage->width) {
|
||||
x = d->framebufferImage->width - d->updateTile->width;
|
||||
}
|
||||
|
||||
// kDebug() << "x: " << x << " (" << r.x() << ") y: " << y << " (" << r.y() << ") " << r;
|
||||
XShmGetImage(QX11Info::display(), win, d->updateTile, x, y, AllPlanes);
|
||||
int pxsize = d->framebufferImage->bits_per_pixel / 8;
|
||||
char *dest = fb + ((d->framebufferImage->bytes_per_line * y) + (x*pxsize));
|
||||
char *dest = fb + ((d->framebufferImage->bytes_per_line * y) + (x * pxsize));
|
||||
char *src = d->updateTile->data;
|
||||
|
||||
for (int i = 0; i < d->updateTile->height; i++) {
|
||||
memcpy(dest, src, d->updateTile->bytes_per_line);
|
||||
dest += d->framebufferImage->bytes_per_line;
|
||||
src += d->updateTile->bytes_per_line;
|
||||
}
|
||||
|
||||
y += d->updateTile->height;
|
||||
}
|
||||
|
||||
x += d->updateTile->width;
|
||||
y = r.y();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
foreach(const QRect &r, tiles) {
|
||||
foreach(const QRect & r, tiles) {
|
||||
XGetSubImage(QX11Info::display(),
|
||||
win,
|
||||
r.left(),
|
||||
r.top(),
|
||||
r.width(),
|
||||
r.height(),
|
||||
AllPlanes,
|
||||
ZPixmap,
|
||||
d->framebufferImage,
|
||||
r.left(),
|
||||
r.top()
|
||||
);
|
||||
win,
|
||||
r.left(),
|
||||
r.top(),
|
||||
r.width(),
|
||||
r.height(),
|
||||
AllPlanes,
|
||||
ZPixmap,
|
||||
d->framebufferImage,
|
||||
r.left(),
|
||||
r.top()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// kDebug() << "tot: " << gl;
|
||||
// kDebug() << tiles.size();
|
||||
ret = tiles;
|
||||
@@ -313,7 +348,7 @@ void X11FrameBuffer::startMonitor()
|
||||
d->running = true;
|
||||
#ifdef HAVE_XDAMAGE
|
||||
d->damage = XDamageCreate(QX11Info::display(), win, XDamageReportRawRectangles);
|
||||
XDamageSubtract(QX11Info::display(),d->damage, None, None);
|
||||
XDamageSubtract(QX11Info::display(), d->damage, None, None);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -321,14 +356,14 @@ void X11FrameBuffer::stopMonitor()
|
||||
{
|
||||
d->running = false;
|
||||
#ifdef HAVE_XDAMAGE
|
||||
XDamageDestroy(QX11Info::display(),d->damage);
|
||||
XDamageDestroy(QX11Info::display(), d->damage);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
EvWidget::EvWidget(X11FrameBuffer * x11fb)
|
||||
:QWidget(0), fb(x11fb)
|
||||
EvWidget::EvWidget(X11FrameBuffer *x11fb)
|
||||
: QWidget(0), fb(x11fb)
|
||||
{
|
||||
#ifdef HAVE_XDAMAGE
|
||||
int er;
|
||||
@@ -336,13 +371,15 @@ EvWidget::EvWidget(X11FrameBuffer * x11fb)
|
||||
#endif
|
||||
}
|
||||
|
||||
bool EvWidget::x11Event(XEvent * event)
|
||||
bool EvWidget::x11Event(XEvent *event)
|
||||
{
|
||||
#ifdef HAVE_XDAMAGE
|
||||
if (event->type == xdamageBaseEvent+XDamageNotify) {
|
||||
|
||||
if (event->type == xdamageBaseEvent + XDamageNotify) {
|
||||
fb->handleXDamage(event);
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -14,14 +14,15 @@
|
||||
|
||||
class X11FrameBuffer;
|
||||
|
||||
class EvWidget: public QWidget {
|
||||
class EvWidget: public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
EvWidget(X11FrameBuffer *x11fb);
|
||||
|
||||
protected:
|
||||
bool x11Event ( XEvent * event );
|
||||
bool x11Event(XEvent *event);
|
||||
|
||||
private:
|
||||
X11FrameBuffer *fb;
|
||||
@@ -29,13 +30,13 @@ private:
|
||||
};
|
||||
|
||||
/**
|
||||
@author Alessandro Praduroux <pradu@pradu.it>
|
||||
@author Alessandro Praduroux <pradu@pradu.it>
|
||||
*/
|
||||
class X11FrameBuffer : public FrameBuffer
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
X11FrameBuffer(WId id, QObject* parent = 0);
|
||||
X11FrameBuffer(WId id, QObject *parent = 0);
|
||||
|
||||
~X11FrameBuffer();
|
||||
|
||||
@@ -44,18 +45,18 @@ public:
|
||||
virtual int height();
|
||||
virtual int width();
|
||||
virtual int paddedWidth();
|
||||
virtual void getServerFormat(rfbPixelFormat& format);
|
||||
virtual void getServerFormat(rfbPixelFormat &format);
|
||||
virtual void startMonitor();
|
||||
virtual void stopMonitor();
|
||||
|
||||
|
||||
void handleXDamage( XEvent *event);
|
||||
void handleXDamage(XEvent *event);
|
||||
private:
|
||||
void cleanupRects();
|
||||
void acquireEvents();
|
||||
|
||||
class P;
|
||||
P * const d;
|
||||
P *const d;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
|
||||
X11FrameBufferPlugin::X11FrameBufferPlugin(QObject *parent, const QVariantList &args)
|
||||
: FrameBufferPlugin(parent, args)
|
||||
: FrameBufferPlugin(parent, args)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user