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 | |
Constantin Kaplinsky | d0b15c6 | 2007-10-09 08:15:25 +0000 | [diff] [blame] | 47 | // 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 Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 55 | |
| 56 | void poll(); |
| 57 | |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 58 | protected: |
| 59 | |
Constantin Kaplinsky | 9ee8dc6 | 2007-10-09 07:46:32 +0000 | [diff] [blame] | 60 | // Screen polling. Returns true if some changes were detected. |
| 61 | bool pollScreen(); |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 62 | |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 63 | 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; |
| 71 | int m_widthTiles; |
| 72 | int m_heightTiles; |
| 73 | |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 74 | private: |
| 75 | |
| 76 | inline void getScreen() { |
| 77 | m_image->get(DefaultRootWindow(m_dpy), m_offsetLeft, m_offsetTop); |
| 78 | } |
| 79 | |
Constantin Kaplinsky | a119b48 | 2007-10-04 06:02:02 +0000 | [diff] [blame] | 80 | inline void getScreenRect(const Rect& r) { |
| 81 | m_image->get(DefaultRootWindow(m_dpy), |
| 82 | m_offsetLeft + r.tl.x, m_offsetTop + r.tl.y, |
| 83 | r.width(), r.height(), r.tl.x, r.tl.y); |
| 84 | } |
| 85 | |
Constantin Kaplinsky | bc6b9e2 | 2007-10-04 11:43:41 +0000 | [diff] [blame] | 86 | inline void getFullRow(int y) { |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 87 | m_rowImage->get(DefaultRootWindow(m_dpy), m_offsetLeft, m_offsetTop + y); |
| 88 | } |
| 89 | |
Constantin Kaplinsky | bc6b9e2 | 2007-10-04 11:43:41 +0000 | [diff] [blame] | 90 | inline void getRow(int x, int y, int w) { |
| 91 | m_rowImage->get(DefaultRootWindow(m_dpy), |
| 92 | m_offsetLeft + x, m_offsetTop + y, w, 1); |
| 93 | } |
| 94 | |
| 95 | inline void getColumn(int x, int y, int h) { |
| 96 | m_rowImage->get(DefaultRootWindow(m_dpy), |
| 97 | m_offsetLeft + x, m_offsetTop + y, 1, h); |
| 98 | } |
| 99 | |
Constantin Kaplinsky | bc6b9e2 | 2007-10-04 11:43:41 +0000 | [diff] [blame] | 100 | int checkRow(int x, int y, int w, bool *pmxChanged); |
Constantin Kaplinsky | a79255b | 2007-10-07 13:03:55 +0000 | [diff] [blame] | 101 | void sendChanges(bool *pmxChanged); |
Constantin Kaplinsky | c1984e0 | 2007-10-08 14:54:18 +0000 | [diff] [blame] | 102 | bool detectVideo(bool *pmxChanged); |
Constantin Kaplinsky | bc6b9e2 | 2007-10-04 11:43:41 +0000 | [diff] [blame] | 103 | |
Constantin Kaplinsky | 5664998 | 2007-09-04 09:15:35 +0000 | [diff] [blame] | 104 | void getVideoAreaRect(Rect *result); |
| 105 | |
Constantin Kaplinsky | 0fc9f17 | 2007-09-29 04:00:02 +0000 | [diff] [blame] | 106 | // Functions called by getVideoAreaRect(). |
| 107 | void constructLengthMatrices(int **pmx_h, int **pmx_v); |
| 108 | void destroyLengthMatrices(int *mx_h, int *mx_v); |
| 109 | void findMaxLocalRect(Rect *r, int *mx_h, int *mx_v); |
| 110 | |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 111 | // Additional images used in polling algorithms. |
| 112 | Image *m_rowImage; // One row of the framebuffer |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 113 | |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 114 | char *m_rateMatrix; |
| 115 | char *m_videoFlags; |
Constantin Kaplinsky | 646998a | 2007-10-09 09:31:41 +0000 | [diff] [blame^] | 116 | Rect m_videoRect; |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 117 | |
| 118 | unsigned int m_pollingStep; |
| 119 | static const int m_pollingOrder[]; |
| 120 | |
| 121 | #ifdef DEBUG |
| 122 | private: |
| 123 | |
| 124 | void debugBeforePoll(); |
| 125 | void debugAfterPoll(); |
| 126 | |
| 127 | TimeMillis m_timeSaved; |
| 128 | #endif |
| 129 | |
| 130 | }; |
| 131 | |
| 132 | #endif // __POLLINGMANAGER_H__ |