blob: c8d6451ce33c9f9628001784d65451f824dce252 [file] [log] [blame]
Constantin Kaplinsky9ee8dc62007-10-09 07:46:32 +00001/* Copyright (C) 2004-2007 Constantin Kaplinsky. All Rights Reserved.
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +00002 *
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;
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +000054
55protected:
56
Constantin Kaplinsky9ee8dc62007-10-09 07:46:32 +000057 // Screen polling. Returns true if some changes were detected.
58 bool pollScreen();
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +000059
60 // Separate polling for the area around current pointer position.
61 void computePointerArea(Rect *r);
62 bool pollPointerArea();
63
64 Display *m_dpy;
65 VNCServer *m_server;
66
67 Image *m_image;
68 int m_offsetLeft;
69 int m_offsetTop;
70 int m_width;
71 int m_height;
72 int m_widthTiles;
73 int m_heightTiles;
74
75 // Tracking pointer position for polling improvements.
76 bool m_pointerPosKnown;
77 Point m_pointerPos;
78 time_t m_pointerPosTime;
79
80private:
81
82 inline void getScreen() {
83 m_image->get(DefaultRootWindow(m_dpy), m_offsetLeft, m_offsetTop);
84 }
85
Constantin Kaplinskya119b482007-10-04 06:02:02 +000086 inline void getScreenRect(const Rect& r) {
87 m_image->get(DefaultRootWindow(m_dpy),
88 m_offsetLeft + r.tl.x, m_offsetTop + r.tl.y,
89 r.width(), r.height(), r.tl.x, r.tl.y);
90 }
91
Constantin Kaplinskybc6b9e22007-10-04 11:43:41 +000092 inline void getFullRow(int y) {
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +000093 m_rowImage->get(DefaultRootWindow(m_dpy), m_offsetLeft, m_offsetTop + y);
94 }
95
Constantin Kaplinskybc6b9e22007-10-04 11:43:41 +000096 inline void getRow(int x, int y, int w) {
97 m_rowImage->get(DefaultRootWindow(m_dpy),
98 m_offsetLeft + x, m_offsetTop + y, w, 1);
99 }
100
101 inline void getColumn(int x, int y, int h) {
102 m_rowImage->get(DefaultRootWindow(m_dpy),
103 m_offsetLeft + x, m_offsetTop + y, 1, h);
104 }
105
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +0000106 inline void getArea128(int x, int y, int w, int h) {
107 if (w == 128 && h == 128) {
108 // This version of get() may be better optimized.
109 m_areaImage->get(DefaultRootWindow(m_dpy),
110 m_offsetLeft + x, m_offsetTop + y);
111 } else {
112 // Generic version of get() for arbitrary width and height.
113 m_areaImage->get(DefaultRootWindow(m_dpy),
114 m_offsetLeft + x, m_offsetTop + y, w, h);
115 }
116 }
117
Constantin Kaplinskybc6b9e22007-10-04 11:43:41 +0000118 int checkRow(int x, int y, int w, bool *pmxChanged);
Constantin Kaplinskya79255b2007-10-07 13:03:55 +0000119 void sendChanges(bool *pmxChanged);
Constantin Kaplinskyc1984e02007-10-08 14:54:18 +0000120 bool detectVideo(bool *pmxChanged);
Constantin Kaplinskybc6b9e22007-10-04 11:43:41 +0000121
Constantin Kaplinsky56649982007-09-04 09:15:35 +0000122 void getVideoAreaRect(Rect *result);
123
Constantin Kaplinsky0fc9f172007-09-29 04:00:02 +0000124 // Functions called by getVideoAreaRect().
125 void constructLengthMatrices(int **pmx_h, int **pmx_v);
126 void destroyLengthMatrices(int *mx_h, int *mx_v);
127 void findMaxLocalRect(Rect *r, int *mx_h, int *mx_v);
128
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +0000129 // Additional images used in polling algorithms.
130 Image *m_rowImage; // One row of the framebuffer
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +0000131 Image *m_areaImage; // Area around the pointer (up to 128x128)
132
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +0000133 char *m_rateMatrix;
134 char *m_videoFlags;
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +0000135
136 unsigned int m_pollingStep;
137 static const int m_pollingOrder[];
138
139#ifdef DEBUG
140private:
141
142 void debugBeforePoll();
143 void debugAfterPoll();
144
145 TimeMillis m_timeSaved;
146#endif
147
148};
149
150#endif // __POLLINGMANAGER_H__