Constantin Kaplinsky | 9ee8dc6 | 2007-10-09 07:46:32 +0000 | [diff] [blame^] | 1 | /* Copyright (C) 2004-2007 Constantin Kaplinsky. All Rights Reserved. |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 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 | |
| 35 | using namespace rfb; |
| 36 | |
| 37 | class PollingManager { |
| 38 | |
| 39 | public: |
| 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 Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 54 | |
| 55 | protected: |
| 56 | |
Constantin Kaplinsky | 9ee8dc6 | 2007-10-09 07:46:32 +0000 | [diff] [blame^] | 57 | // Screen polling. Returns true if some changes were detected. |
| 58 | bool pollScreen(); |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 59 | |
| 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 | |
| 80 | private: |
| 81 | |
| 82 | inline void getScreen() { |
| 83 | m_image->get(DefaultRootWindow(m_dpy), m_offsetLeft, m_offsetTop); |
| 84 | } |
| 85 | |
Constantin Kaplinsky | a119b48 | 2007-10-04 06:02:02 +0000 | [diff] [blame] | 86 | 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 Kaplinsky | bc6b9e2 | 2007-10-04 11:43:41 +0000 | [diff] [blame] | 92 | inline void getFullRow(int y) { |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 93 | m_rowImage->get(DefaultRootWindow(m_dpy), m_offsetLeft, m_offsetTop + y); |
| 94 | } |
| 95 | |
Constantin Kaplinsky | bc6b9e2 | 2007-10-04 11:43:41 +0000 | [diff] [blame] | 96 | 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 Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 106 | 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 Kaplinsky | bc6b9e2 | 2007-10-04 11:43:41 +0000 | [diff] [blame] | 118 | int checkRow(int x, int y, int w, bool *pmxChanged); |
Constantin Kaplinsky | a79255b | 2007-10-07 13:03:55 +0000 | [diff] [blame] | 119 | void sendChanges(bool *pmxChanged); |
Constantin Kaplinsky | c1984e0 | 2007-10-08 14:54:18 +0000 | [diff] [blame] | 120 | bool detectVideo(bool *pmxChanged); |
Constantin Kaplinsky | bc6b9e2 | 2007-10-04 11:43:41 +0000 | [diff] [blame] | 121 | |
Constantin Kaplinsky | 5664998 | 2007-09-04 09:15:35 +0000 | [diff] [blame] | 122 | void getVideoAreaRect(Rect *result); |
| 123 | |
Constantin Kaplinsky | 0fc9f17 | 2007-09-29 04:00:02 +0000 | [diff] [blame] | 124 | // 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 Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 129 | // Additional images used in polling algorithms. |
| 130 | Image *m_rowImage; // One row of the framebuffer |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 131 | Image *m_areaImage; // Area around the pointer (up to 128x128) |
| 132 | |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 133 | char *m_rateMatrix; |
| 134 | char *m_videoFlags; |
| 135 | char *m_changedFlags; |
| 136 | |
| 137 | unsigned int m_pollingStep; |
| 138 | static const int m_pollingOrder[]; |
| 139 | |
| 140 | #ifdef DEBUG |
| 141 | private: |
| 142 | |
| 143 | void debugBeforePoll(); |
| 144 | void debugAfterPoll(); |
| 145 | |
| 146 | TimeMillis m_timeSaved; |
| 147 | #endif |
| 148 | |
| 149 | }; |
| 150 | |
| 151 | #endif // __POLLINGMANAGER_H__ |