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()
35 int QtFrameBuffer::depth()
37 return fbImage
.depth();
40 int QtFrameBuffer::height()
42 return fbImage
.height();
45 int QtFrameBuffer::width()
47 return fbImage
.width();
50 void QtFrameBuffer::getServerFormat(rfbPixelFormat
& format
)
52 format
.bitsPerPixel
= 32;
54 format
.trueColour
= true;
56 format
.bigEndian
= false;
58 format
.greenShift
= 8;
61 format
.greenMax
= 0xff;
62 format
.blueMax
= 0xff;
65 void QtFrameBuffer::updateFrameBuffer()
67 QImage img
= QPixmap::grabWindow(win
).toImage();
68 QSize imgSize
= img
.size();
71 // verify what part of the image need to be marked as changed
72 // fbImage is the previous version of the image,
73 // img is the current one
75 #if 0 // This is actually slower than updating the whole desktop...
77 QImage
map(imgSize
, QImage::Format_Mono
);
80 for (int x
= 0; x
< imgSize
.width(); x
++) {
81 for (int y
= 0; y
< imgSize
.height(); y
++) {
82 if (img
.pixel(x
,y
) != fbImage
.pixel(x
,y
)) {
88 QRegion
r(QBitmap::fromImage(map
));
89 tiles
= tiles
+ r
.rects();
92 tiles
.append(img
.rect());
95 memcpy(fb
, (const char*)img
.bits(), img
.numBytes());
100 int QtFrameBuffer::paddedWidth()
102 return fbImage
.width() * 4;
105 void QtFrameBuffer::startMonitor()
107 t
->start(UPDATE_TIME
);
110 void QtFrameBuffer::stopMonitor()