blob: a67901be1cab13564199a4f994b6f1e654a5125e [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 //
Constantin Kaplinskya119b482007-10-04 06:02:02 +000062 bool poll_New();
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +000063 bool poll_DetectVideo();
64 bool poll_SkipCycles();
65 bool poll_Traditional();
66 bool poll_Dumb();
67
68 // Separate polling for the area around current pointer position.
69 void computePointerArea(Rect *r);
70 bool pollPointerArea();
71
72 Display *m_dpy;
73 VNCServer *m_server;
74
75 Image *m_image;
76 int m_offsetLeft;
77 int m_offsetTop;
78 int m_width;
79 int m_height;
80 int m_widthTiles;
81 int m_heightTiles;
82
83 // Tracking pointer position for polling improvements.
84 bool m_pointerPosKnown;
85 Point m_pointerPos;
86 time_t m_pointerPosTime;
87
88private:
89
90 inline void getScreen() {
91 m_image->get(DefaultRootWindow(m_dpy), m_offsetLeft, m_offsetTop);
92 }
93
Constantin Kaplinskya119b482007-10-04 06:02:02 +000094 inline void getScreenRect(const Rect& r) {
95 m_image->get(DefaultRootWindow(m_dpy),
96 m_offsetLeft + r.tl.x, m_offsetTop + r.tl.y,
97 r.width(), r.height(), r.tl.x, r.tl.y);
98 }
99
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +0000100 inline void getRow(int y) {
101 m_rowImage->get(DefaultRootWindow(m_dpy), m_offsetLeft, m_offsetTop + y);
102 }
103
104 inline void getTile32(int tx, int ty, int w, int h) {
105 if (w == 32 && h == 32) {
106 // This version of get() may be better optimized.
107 m_tileImage->get(DefaultRootWindow(m_dpy),
108 m_offsetLeft + tx * 32, m_offsetTop + ty * 32);
109 } else {
110 // Generic version of get() for arbitrary width and height.
111 m_tileImage->get(DefaultRootWindow(m_dpy),
112 m_offsetLeft + tx * 32, m_offsetTop + ty * 32, w, h);
113 }
114 }
115
116 inline void getArea128(int x, int y, int w, int h) {
117 if (w == 128 && h == 128) {
118 // This version of get() may be better optimized.
119 m_areaImage->get(DefaultRootWindow(m_dpy),
120 m_offsetLeft + x, m_offsetTop + y);
121 } else {
122 // Generic version of get() for arbitrary width and height.
123 m_areaImage->get(DefaultRootWindow(m_dpy),
124 m_offsetLeft + x, m_offsetTop + y, w, h);
125 }
126 }
127
128 void adjustVideoArea();
129
Constantin Kaplinsky56649982007-09-04 09:15:35 +0000130 void getVideoAreaRect(Rect *result);
131
Constantin Kaplinsky0fc9f172007-09-29 04:00:02 +0000132 // Functions called by getVideoAreaRect().
133 void constructLengthMatrices(int **pmx_h, int **pmx_v);
134 void destroyLengthMatrices(int *mx_h, int *mx_v);
135 void findMaxLocalRect(Rect *r, int *mx_h, int *mx_v);
136
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +0000137 // Additional images used in polling algorithms.
138 Image *m_rowImage; // One row of the framebuffer
139 Image *m_tileImage; // One tile (32x32 or less)
140 Image *m_areaImage; // Area around the pointer (up to 128x128)
141
142 char *m_statusMatrix;
143
144 char *m_rateMatrix;
145 char *m_videoFlags;
146 char *m_changedFlags;
147
148 unsigned int m_pollingStep;
149 static const int m_pollingOrder[];
150
151#ifdef DEBUG
152private:
153
154 void debugBeforePoll();
155 void debugAfterPoll();
156
157 TimeMillis m_timeSaved;
158#endif
159
160};
161
162#endif // __POLLINGMANAGER_H__