1 /* This file is part of the KDE project
2 Copyright (C) 2007 Alessandro Praduroux <pradu@pradu.it>
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
10 #include "qtframebuffer.h"
11 #include "qtframebuffer.moc"
19 const int UPDATE_TIME
= 500;
21 QtFrameBuffer::QtFrameBuffer(WId id
, QObject
*parent
)
22 : FrameBuffer(id
, parent
)
24 fbImage
= QPixmap::grabWindow(win
).toImage();
25 fb
= new char[fbImage
.numBytes()];
27 connect(t
, SIGNAL(timeout()), SLOT(updateFrameBuffer()));
31 QtFrameBuffer::~QtFrameBuffer()
36 int QtFrameBuffer::depth()
38 return fbImage
.depth();
41 int QtFrameBuffer::height()
43 return fbImage
.height();
46 int QtFrameBuffer::width()
48 return fbImage
.width();
51 void QtFrameBuffer::getServerFormat(rfbPixelFormat
& format
)
53 format
.bitsPerPixel
= 32;
55 format
.trueColour
= true;
57 format
.bigEndian
= false;
59 format
.greenShift
= 8;
62 format
.greenMax
= 0xff;
63 format
.blueMax
= 0xff;
66 void QtFrameBuffer::updateFrameBuffer()
68 QImage img
= QPixmap::grabWindow(win
).toImage();
69 QSize imgSize
= img
.size();
72 // verify what part of the image need to be marked as changed
73 // fbImage is the previous version of the image,
74 // img is the current one
76 #if 0 // This is actually slower than updating the whole desktop...
78 QImage
map(imgSize
, QImage::Format_Mono
);
81 for (int x
= 0; x
< imgSize
.width(); x
++) {
82 for (int y
= 0; y
< imgSize
.height(); y
++) {
83 if (img
.pixel(x
,y
) != fbImage
.pixel(x
,y
)) {
89 QRegion
r(QBitmap::fromImage(map
));
90 tiles
= tiles
+ r
.rects();
93 tiles
.append(img
.rect());
96 memcpy(fb
, (const char*)img
.bits(), img
.numBytes());
101 int QtFrameBuffer::paddedWidth()
103 return fbImage
.width() * 4;
106 void QtFrameBuffer::startMonitor()
108 t
->start(UPDATE_TIME
);
111 void QtFrameBuffer::stopMonitor()