blob: b8eef509ef520425e15bb1245f390f130e4d4aac [file] [log] [blame]
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +00001/* Copyright (C) 2004-2005 Constantin Kaplinsky. All Rights Reserved.
2 *
3 * This is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This software is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16 * USA.
17 */
18
19//
20// PollingManager.h
21//
22
23#ifndef __POLLINGMANAGER_H__
24#define __POLLINGMANAGER_H__
25
26#include <X11/Xlib.h>
27#include <rfb/VNCServer.h>
28
29#include <x0vncserver/Image.h>
30
31#ifdef DEBUG
32#include <x0vncserver/TimeMillis.h>
33#endif
34
35using namespace rfb;
36
37class PollingManager {
38
39public:
40
41 PollingManager(Display *dpy, Image *image, ImageFactory *factory,
42 int offsetLeft = 0, int offsetTop = 0);
43 virtual ~PollingManager();
44
45 void setVNCServer(VNCServer *s);
46
47 void setPointerPos(const Point &pos);
48 void unsetPointerPos();
49
50 void poll();
51
52 // Configurable parameters.
53 static BoolParameter pollPointer;
54 static IntParameter pollingType;
55
56protected:
57
58 //
59 // Implementations of different polling algorithms.
60 // Return value of true reports that some changes were detected.
61 //
62 bool poll_DetectVideo();
63 bool poll_SkipCycles();
64 bool poll_Traditional();
65 bool poll_Dumb();
66
67 // Separate polling for the area around current pointer position.
68 void computePointerArea(Rect *r);
69 bool pollPointerArea();
70
71 Display *m_dpy;
72 VNCServer *m_server;
73
74 Image *m_image;
75 int m_offsetLeft;
76 int m_offsetTop;
77 int m_width;
78 int m_height;
79 int m_widthTiles;
80 int m_heightTiles;
81
82 // Tracking pointer position for polling improvements.
83 bool m_pointerPosKnown;
84 Point m_pointerPos;
85 time_t m_pointerPosTime;
86
87private:
88
89 inline void getScreen() {
90 m_image->get(DefaultRootWindow(m_dpy), m_offsetLeft, m_offsetTop);
91 }
92
93 inline void getRow(int y) {
94 m_rowImage->get(DefaultRootWindow(m_dpy), m_offsetLeft, m_offsetTop + y);
95 }
96
97 inline void getTile32(int tx, int ty, int w, int h) {
98 if (w == 32 && h == 32) {
99 // This version of get() may be better optimized.
100 m_tileImage->get(DefaultRootWindow(m_dpy),
101 m_offsetLeft + tx * 32, m_offsetTop + ty * 32);
102 } else {
103 // Generic version of get() for arbitrary width and height.
104 m_tileImage->get(DefaultRootWindow(m_dpy),
105 m_offsetLeft + tx * 32, m_offsetTop + ty * 32, w, h);
106 }
107 }
108
109 inline void getArea128(int x, int y, int w, int h) {
110 if (w == 128 && h == 128) {
111 // This version of get() may be better optimized.
112 m_areaImage->get(DefaultRootWindow(m_dpy),
113 m_offsetLeft + x, m_offsetTop + y);
114 } else {
115 // Generic version of get() for arbitrary width and height.
116 m_areaImage->get(DefaultRootWindow(m_dpy),
117 m_offsetLeft + x, m_offsetTop + y, w, h);
118 }
119 }
120
121 void adjustVideoArea();
122
123 // Additional images used in polling algorithms.
124 Image *m_rowImage; // One row of the framebuffer
125 Image *m_tileImage; // One tile (32x32 or less)
126 Image *m_areaImage; // Area around the pointer (up to 128x128)
127
128 char *m_statusMatrix;
129
130 char *m_rateMatrix;
131 char *m_videoFlags;
132 char *m_changedFlags;
133
134 unsigned int m_pollingStep;
135 static const int m_pollingOrder[];
136
137#ifdef DEBUG
138private:
139
140 void debugBeforePoll();
141 void debugAfterPoll();
142
143 TimeMillis m_timeSaved;
144#endif
145
146};
147
148#endif // __POLLINGMANAGER_H__