1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
/* Copyright (C) 2004-2008 Constantin Kaplinsky. All Rights Reserved.
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
* USA.
*/
//
// PollingManager.h
//
#ifndef __POLLINGMANAGER_H__
#define __POLLINGMANAGER_H__
#include <X11/Xlib.h>
#include <rfb/VNCServer.h>
#include <x0vncserver/Image.h>
#include <x0vncserver/XPixelBuffer.h>
#ifdef DEBUG
#include <x0vncserver/TimeMillis.h>
#endif
using namespace rfb;
class PollingManager {
public:
PollingManager(Display *dpy, XPixelBuffer *buffer, ImageFactory *factory,
int offsetLeft = 0, int offsetTop = 0);
virtual ~PollingManager();
// Currently, these functions do nothing. In past versions, we used
// to poll area around the pointer if its position has been changed
// recently. But that rather decreased overal polling performance,
// so we don't do that any more. However, pointer position may be a
// useful hint and might be used in future code, so we do not remove
// these functions, just in case.
void setPointerPos(const Point &pos) {}
void unsetPointerPos() {}
void poll(VNCServer *server);
protected:
// Screen polling. Returns true if some changes were detected.
bool pollScreen(VNCServer *server);
Display *m_dpy;
const Image *m_image;
const int m_bytesPerPixel;
const int m_offsetLeft;
const int m_offsetTop;
const int m_width;
const int m_height;
private:
inline void getRow(int x, int y, int w) {
if (w == m_width) {
// Getting full row may be more efficient.
m_rowImage->get(DefaultRootWindow(m_dpy),
m_offsetLeft, m_offsetTop + y);
} else {
m_rowImage->get(DefaultRootWindow(m_dpy),
m_offsetLeft + x, m_offsetTop + y, w, 1);
}
}
inline void getColumn(int x, int y, int h) {
m_columnImage->get(DefaultRootWindow(m_dpy),
m_offsetLeft + x, m_offsetTop + y, 1, h);
}
inline int getTileIndex(int x, int y) {
int tile_x = x / 32;
int tile_y = y / 32;
return tile_y * m_widthTiles + tile_x;
}
int checkRow(int x, int y, int w);
int checkColumn(int x, int y, int h, bool *pChangeFlags);
int sendChanges(VNCServer *server);
// Check neighboring tiles and update m_changeFlags[].
void checkNeighbors();
// DEBUG: Print the list of changed tiles.
void printChanges(const char *header) const;
// Additional images used in polling algorithms.
Image *m_rowImage; // one row of the framebuffer
Image *m_columnImage; // one column of the framebuffer
const int m_widthTiles; // shortcut for ((m_width + 31) / 32)
const int m_heightTiles; // shortcut for ((m_height + 31) / 32)
const int m_numTiles; // shortcut for (m_widthTiles * m_heightTiles)
// m_changeFlags[] array will hold boolean values corresponding to
// each 32x32 tile. If a value is true, then we've detected a change
// in that tile.
bool *m_changeFlags;
unsigned int m_pollingStep;
static const int m_pollingOrder[];
#ifdef DEBUG
private:
void debugBeforePoll();
void debugAfterPoll();
TimeMillis m_timeSaved;
#endif
};
#endif // __POLLINGMANAGER_H__
|