mirror of
https://github.com/KDE/krfb
synced 2026-07-01 07:31:16 -07:00
small XUpdateScanner improvement
svn path=/trunk/kdenetwork/krfb/; revision=137469
This commit is contained in:
@@ -16,12 +16,46 @@
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
/*
|
||||
* TODOs:
|
||||
* - override configuration in KDEHOME
|
||||
* - set listening ip address
|
||||
*/
|
||||
|
||||
#include "kinetd.h"
|
||||
#include <kservicetype.h>
|
||||
#include <kservice.h>
|
||||
#include <kdebug.h>
|
||||
|
||||
PortListener::PortListener(KService::Ptr s) {
|
||||
|
||||
serviceName = s->name();
|
||||
|
||||
// TODO: load KConfig to override these settings
|
||||
|
||||
port = s->property("port");
|
||||
enabled = s->property("enabled");
|
||||
execPath = s->exec();
|
||||
|
||||
socket = new KSocket(defaultPort, false);
|
||||
connect(socket, SIGNAL(accepted(KSocket*)),
|
||||
SLOT(accepted(KSocket*)));
|
||||
|
||||
if (!socket->bindAndListen()) {
|
||||
// TODO: do something
|
||||
kdDebug() << "bind failed" <<endl;
|
||||
}
|
||||
}
|
||||
|
||||
PortListener::accepted(KSocket *sock) {
|
||||
// TODO: do the inetd thing
|
||||
kdDebug() << "got connection" << endl;
|
||||
delete sock;
|
||||
}
|
||||
|
||||
PortListener::~PortListener() {
|
||||
if (socket)
|
||||
delete socket;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +66,7 @@ class KInetD : public KDEDModule {
|
||||
portListeners.setAutoDelete(true);
|
||||
loadServiceList();
|
||||
}
|
||||
|
||||
|
||||
void KInetD::loadServiceList()
|
||||
{
|
||||
portListeners.clear();
|
||||
@@ -50,8 +84,6 @@ class KInetD : public KDEDModule {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
extern "C" {
|
||||
KDEDModule *create_kinetd(QCString *name)
|
||||
{
|
||||
|
||||
@@ -20,12 +20,26 @@
|
||||
#define _KINETD_H_
|
||||
|
||||
#include <kdedmodule.h>
|
||||
#include "portlistener.h"
|
||||
#include <kservice.h>
|
||||
|
||||
class PortListener {
|
||||
private:
|
||||
QString serviceName;
|
||||
int port;
|
||||
QCString execPath;
|
||||
bool enabled;
|
||||
|
||||
KServerSocket *socket;
|
||||
public:
|
||||
PortListener(KService::Ptr s);
|
||||
~PortListener();
|
||||
|
||||
private slots:
|
||||
void accepted(KSocket*);
|
||||
}
|
||||
|
||||
class KInetD : public KDEDModule {
|
||||
Q_OBJECT
|
||||
K_DCOP
|
||||
private:
|
||||
QPtrList<PortListener> portListeners;
|
||||
|
||||
@@ -35,9 +49,8 @@ class KInetD : public KDEDModule {
|
||||
|
||||
|
||||
|
||||
k_dcop:
|
||||
// DCOP functions
|
||||
void reloadPortListenerList();
|
||||
PortListener *findPortListener(QString name);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -21,8 +21,8 @@
|
||||
|
||||
#include <kservice.h>
|
||||
|
||||
class PortListener : public DCOPObject {
|
||||
K_DCOP
|
||||
class PortListener {
|
||||
|
||||
private:
|
||||
QString serviceName;
|
||||
int port;
|
||||
@@ -35,8 +35,6 @@ private:
|
||||
|
||||
|
||||
|
||||
k_dcop:
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -87,6 +87,7 @@ XUpdateScanner::XUpdateScanner(Display *_dpy,
|
||||
tilesX = (width + tileWidth - 1) / tileWidth;
|
||||
tilesY = (height + tileHeight - 1) / tileHeight;
|
||||
tileMap = new bool[tilesX * tilesY];
|
||||
tileRegionMap = new struct TileChangeRegion[tilesX * tilesY];
|
||||
|
||||
unsigned int i;
|
||||
for (i = 0; i < tilesX * tilesY; i++)
|
||||
@@ -119,6 +120,7 @@ XUpdateScanner::~XUpdateScanner()
|
||||
shmdt(shminfo_scanline.shmaddr);
|
||||
shmctl(shminfo_scanline.shmid, IPC_RMID, 0);
|
||||
delete tileMap;
|
||||
delete tileRegionMap;
|
||||
XShmDetach(dpy, &shminfo_tile);
|
||||
XDestroyImage(tile);
|
||||
shmdt(shminfo_tile.shmaddr);
|
||||
@@ -126,7 +128,7 @@ XUpdateScanner::~XUpdateScanner()
|
||||
}
|
||||
|
||||
|
||||
void XUpdateScanner::copyTile(int x, int y)
|
||||
bool XUpdateScanner::copyTile(int x, int y, int tx, int ty)
|
||||
{
|
||||
unsigned int maxWidth = width - x;
|
||||
unsigned int maxHeight = height - y;
|
||||
@@ -145,21 +147,59 @@ void XUpdateScanner::copyTile(int x, int y)
|
||||
int pixelsize = bitsPerPixel >> 3;
|
||||
unsigned char *src = (unsigned char*) tile->data;
|
||||
unsigned char *dest = fb + y * bytesPerLine + x * pixelsize;
|
||||
|
||||
unsigned char *ssrc = src;
|
||||
unsigned char *sdest = dest;
|
||||
int firstLine = maxHeight;
|
||||
|
||||
for (line = 0; line < maxHeight; line++) {
|
||||
memcpy(dest, src, maxWidth * pixelsize );
|
||||
src += tile->bytes_per_line;
|
||||
dest += bytesPerLine;
|
||||
if (memcmp(sdest, ssrc, maxWidth * pixelsize)) {
|
||||
firstLine = line;
|
||||
break;
|
||||
}
|
||||
ssrc += tile->bytes_per_line;
|
||||
sdest += bytesPerLine;
|
||||
}
|
||||
|
||||
if (firstLine == maxHeight) {
|
||||
tileMap[tx + ty * tilesX] = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned char *msrc = src + (tile->bytes_per_line * maxHeight);
|
||||
unsigned char *mdest = dest + (bytesPerLine * maxHeight);
|
||||
int lastLine = firstLine;
|
||||
|
||||
for (line = maxHeight-1; line > firstLine; line--) {
|
||||
msrc -= tile->bytes_per_line;
|
||||
mdest -= bytesPerLine;
|
||||
if (memcmp(mdest, msrc, maxWidth * pixelsize)) {
|
||||
lastLine = line;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (line = firstLine; line <= lastLine; line++) {
|
||||
memcpy(sdest, ssrc, maxWidth * pixelsize );
|
||||
ssrc += tile->bytes_per_line;
|
||||
sdest += bytesPerLine;
|
||||
}
|
||||
|
||||
struct TileChangeRegion *r = &tileRegionMap[tx + (ty * tilesX)];
|
||||
r->firstLine = firstLine;
|
||||
r->lastLine = lastLine;
|
||||
|
||||
return lastLine >= (maxHeight-1);
|
||||
}
|
||||
|
||||
void XUpdateScanner::copyAllTiles()
|
||||
{
|
||||
unsigned int x, y;
|
||||
// TODO: is it useful to compare again instead of only copying?
|
||||
for (y = 0; y < tilesY; y++) {
|
||||
for (x = 0; x < tilesX; x++) {
|
||||
if (tileMap[x + y * tilesX])
|
||||
copyTile(x*tileWidth, y*tileHeight);
|
||||
for (unsigned int y = 0; y < tilesY; y++) {
|
||||
for (unsigned int x = 0; x < tilesX; x++) {
|
||||
if (tileMap[x + y * tilesX])
|
||||
if (copyTile(x*tileWidth, y*tileHeight, x, y) &&
|
||||
((y+1) < tilesY))
|
||||
tileMap[x + (y+1) * tilesX] = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -57,6 +57,11 @@ class Hint {
|
||||
}
|
||||
};
|
||||
|
||||
struct TileChangeRegion {
|
||||
short firstLine, lastLine;
|
||||
};
|
||||
|
||||
|
||||
class XUpdateScanner
|
||||
{
|
||||
public:
|
||||
@@ -70,7 +75,7 @@ class XUpdateScanner
|
||||
|
||||
~XUpdateScanner();
|
||||
|
||||
void copyTile( int x, int y);
|
||||
bool copyTile(int x, int y, int tx, int ty);
|
||||
void copyAllTiles();
|
||||
void searchUpdates( QPtrList<Hint> &hintList);
|
||||
void flushHint(int x, int y, int &x0, Hint &hint,
|
||||
@@ -95,6 +100,7 @@ class XUpdateScanner
|
||||
|
||||
unsigned int tilesX, tilesY;
|
||||
bool *tileMap;
|
||||
struct TileChangeRegion *tileRegionMap;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user