blob: 3cb1e8bbe77e30b770a805c5affc429b8da62780 [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
Constantin Kaplinskyd0b15c62007-10-09 08:15:25 +000047 // Currently, these functions do nothing. In past versions, we used
48 // to poll area around the pointer if its position has been changed
49 // recently. But that rather decreased overal polling performance,
50 // so we don't do that any more. However, pointer position may be a
51 // useful hint and might be used in future code, so we do not remove
52 // these functions, just in case.
53 void setPointerPos(const Point &pos) {}
54 void unsetPointerPos() {}
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +000055
56 void poll();
57
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +000058protected:
59
Constantin Kaplinsky9ee8dc62007-10-09 07:46:32 +000060 // Screen polling. Returns true if some changes were detected.
61 bool pollScreen();
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +000062
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +000063 Display *m_dpy;
64 VNCServer *m_server;
65
66 Image *m_image;
67 int m_offsetLeft;
68 int m_offsetTop;
69 int m_width;
70 int m_height;
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +000071
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +000072private:
73
74 inline void getScreen() {
75 m_image->get(DefaultRootWindow(m_dpy), m_offsetLeft, m_offsetTop);
76 }
77
Constantin Kaplinskya119b482007-10-04 06:02:02 +000078 inline void getScreenRect(const Rect& r) {
79 m_image->get(DefaultRootWindow(m_dpy),
80 m_offsetLeft + r.tl.x, m_offsetTop + r.tl.y,
81 r.width(), r.height(), r.tl.x, r.tl.y);
82 }
83
Constantin Kaplinskybc6b9e22007-10-04 11:43:41 +000084 inline void getFullRow(int y) {
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +000085 m_rowImage->get(DefaultRootWindow(m_dpy), m_offsetLeft, m_offsetTop + y);
86 }
87
Constantin Kaplinskybc6b9e22007-10-04 11:43:41 +000088 inline void getRow(int x, int y, int w) {
89 m_rowImage->get(DefaultRootWindow(m_dpy),
90 m_offsetLeft + x, m_offsetTop + y, w, 1);
91 }
92
93 inline void getColumn(int x, int y, int h) {
Constantin Kaplinskyed3cf5d2007-12-28 17:59:10 +000094 m_columnImage->get(DefaultRootWindow(m_dpy),
95 m_offsetLeft + x, m_offsetTop + y, 1, h);
Constantin Kaplinskybc6b9e22007-10-04 11:43:41 +000096 }
97
Constantin Kaplinskybd390352007-12-28 08:44:59 +000098 int checkRow(int x, int y, int w, bool *pChangeFlags);
Constantin Kaplinsky553340c2007-12-28 18:37:04 +000099 int checkColumn(int x, int y, int h, bool *pChangeFlags);
Constantin Kaplinsky1a032112008-01-09 10:22:42 +0000100 int sendChanges(const bool *pChangeFlags);
Constantin Kaplinsky48792632007-12-28 18:21:42 +0000101 void handleVideo(const bool *pChangeFlags);
Constantin Kaplinskybd390352007-12-28 08:44:59 +0000102 void flagVideoArea(bool *pChangeFlags, bool value);
103
Constantin Kaplinsky553340c2007-12-28 18:37:04 +0000104 // Check neighboring tiles and update pmxChanged[] matrix.
105 void checkNeighbors(bool *pChangeFlags);
106
Constantin Kaplinskyf50bd7f2008-01-10 15:27:42 +0000107 // DEBUG: Print the list of changed tiles.
108 void printChanges(const char *header, const bool *pChangeFlags);
109
Constantin Kaplinskybd390352007-12-28 08:44:59 +0000110 // Video detection functions.
Constantin Kaplinsky6bb4bf12007-10-09 12:03:15 +0000111 void detectVideo();
Constantin Kaplinsky56649982007-09-04 09:15:35 +0000112 void getVideoAreaRect(Rect *result);
Constantin Kaplinsky0fc9f172007-09-29 04:00:02 +0000113 void constructLengthMatrices(int **pmx_h, int **pmx_v);
114 void destroyLengthMatrices(int *mx_h, int *mx_v);
115 void findMaxLocalRect(Rect *r, int *mx_h, int *mx_v);
116
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +0000117 // Additional images used in polling algorithms.
Constantin Kaplinskyed3cf5d2007-12-28 17:59:10 +0000118 Image *m_rowImage; // one row of the framebuffer
119 Image *m_columnImage; // one column of the framebuffer
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +0000120
Constantin Kaplinsky20390a22008-01-17 15:17:36 +0000121 int m_widthTiles; // shortcut for ((m_width + 31) / 32)
122 int m_heightTiles; // shortcut for ((m_height + 31) / 32)
123 int m_numTiles; // shortcut for (m_widthTiles * m_heightTiles)
124
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +0000125 char *m_rateMatrix;
126 char *m_videoFlags;
Constantin Kaplinsky646998a2007-10-09 09:31:41 +0000127 Rect m_videoRect;
Constantin Kaplinsky1d378022007-12-25 17:43:09 +0000128 int m_numVideoPasses;
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +0000129
130 unsigned int m_pollingStep;
131 static const int m_pollingOrder[];
132
Constantin Kaplinsky1d378022007-12-25 17:43:09 +0000133 static IntParameter m_videoPriority;
134
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +0000135#ifdef DEBUG
136private:
137
138 void debugBeforePoll();
139 void debugAfterPoll();
140
141 TimeMillis m_timeSaved;
142#endif
143
144};
145
146#endif // __POLLINGMANAGER_H__