Constantin Kaplinsky | af1891c | 2005-09-29 06:18:28 +0000 | [diff] [blame] | 1 | /* 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 | |
Constantin Kaplinsky | b247d7d | 2006-02-15 16:14:07 +0000 | [diff] [blame^] | 26 | #include <sys/time.h> |
| 27 | |
Constantin Kaplinsky | af1891c | 2005-09-29 06:18:28 +0000 | [diff] [blame] | 28 | #include <X11/Xlib.h> |
| 29 | #include <rfb/VNCServer.h> |
| 30 | |
| 31 | #include <x0vncserver/Image.h> |
| 32 | |
| 33 | using namespace rfb; |
| 34 | |
| 35 | class PollingManager { |
| 36 | |
| 37 | public: |
| 38 | |
| 39 | PollingManager(Display *dpy, Image *image, ImageFactory *factory); |
Constantin Kaplinsky | 14cd547 | 2005-09-29 17:12:11 +0000 | [diff] [blame] | 40 | virtual ~PollingManager(); |
Constantin Kaplinsky | af1891c | 2005-09-29 06:18:28 +0000 | [diff] [blame] | 41 | |
Constantin Kaplinsky | 14cd547 | 2005-09-29 17:12:11 +0000 | [diff] [blame] | 42 | void setVNCServer(VNCServer *s); |
Constantin Kaplinsky | ce676c6 | 2006-02-08 13:36:58 +0000 | [diff] [blame] | 43 | |
| 44 | void setPointerPos(const Point &pos); |
| 45 | void unsetPointerPos(); |
| 46 | |
Constantin Kaplinsky | af1891c | 2005-09-29 06:18:28 +0000 | [diff] [blame] | 47 | void poll(); |
| 48 | |
Constantin Kaplinsky | ce676c6 | 2006-02-08 13:36:58 +0000 | [diff] [blame] | 49 | // Configurable parameters. |
| 50 | static BoolParameter pollPointer; |
| 51 | static IntParameter pollingType; |
| 52 | |
Constantin Kaplinsky | af1891c | 2005-09-29 06:18:28 +0000 | [diff] [blame] | 53 | protected: |
| 54 | |
Constantin Kaplinsky | c42eab2 | 2006-02-01 05:59:21 +0000 | [diff] [blame] | 55 | // |
| 56 | // Implementations of different polling algorithms. |
| 57 | // Return value of true reports that some changes were detected. |
| 58 | // |
| 59 | bool poll_DetectVideo(); |
| 60 | bool poll_SkipCycles(); |
| 61 | bool poll_Traditional(); |
| 62 | bool poll_Dumb(); |
Constantin Kaplinsky | 14cd547 | 2005-09-29 17:12:11 +0000 | [diff] [blame] | 63 | |
Constantin Kaplinsky | ce676c6 | 2006-02-08 13:36:58 +0000 | [diff] [blame] | 64 | // Separate polling for the area around current pointer position. |
| 65 | void computePointerArea(Rect *r); |
| 66 | bool pollPointerArea(); |
| 67 | |
Constantin Kaplinsky | 14cd547 | 2005-09-29 17:12:11 +0000 | [diff] [blame] | 68 | Display *m_dpy; |
| 69 | VNCServer *m_server; |
| 70 | |
| 71 | Image *m_image; |
| 72 | int m_width; |
| 73 | int m_height; |
| 74 | int m_widthTiles; |
| 75 | int m_heightTiles; |
| 76 | |
Constantin Kaplinsky | ce676c6 | 2006-02-08 13:36:58 +0000 | [diff] [blame] | 77 | // Tracking pointer position for polling improvements. |
| 78 | bool m_pointerPosKnown; |
| 79 | Point m_pointerPos; |
Constantin Kaplinsky | af2ebeb | 2006-02-10 12:19:11 +0000 | [diff] [blame] | 80 | time_t m_pointerPosTime; |
Constantin Kaplinsky | ce676c6 | 2006-02-08 13:36:58 +0000 | [diff] [blame] | 81 | |
Constantin Kaplinsky | 6df6990 | 2006-02-03 11:42:00 +0000 | [diff] [blame] | 82 | private: |
| 83 | |
| 84 | void adjustVideoArea(); |
| 85 | |
Constantin Kaplinsky | ce676c6 | 2006-02-08 13:36:58 +0000 | [diff] [blame] | 86 | // Additional images used in polling algorithms. |
| 87 | Image *m_rowImage; // One row of the framebuffer |
| 88 | Image *m_tileImage; // One tile (32x32 or less) |
| 89 | Image *m_areaImage; // Area around the pointer (up to 128x128) |
Constantin Kaplinsky | 14cd547 | 2005-09-29 17:12:11 +0000 | [diff] [blame] | 90 | |
| 91 | char *m_statusMatrix; |
| 92 | |
Constantin Kaplinsky | dc54fc1 | 2005-10-19 13:57:16 +0000 | [diff] [blame] | 93 | char *m_rateMatrix; |
| 94 | char *m_videoFlags; |
| 95 | char *m_changedFlags; |
| 96 | |
Constantin Kaplinsky | af1891c | 2005-09-29 06:18:28 +0000 | [diff] [blame] | 97 | unsigned int m_pollingStep; |
| 98 | static const int m_pollingOrder[]; |
Constantin Kaplinsky | af1891c | 2005-09-29 06:18:28 +0000 | [diff] [blame] | 99 | |
Constantin Kaplinsky | b247d7d | 2006-02-15 16:14:07 +0000 | [diff] [blame^] | 100 | #ifdef DEBUG |
| 101 | private: |
| 102 | |
| 103 | void debugBeforePoll(); |
| 104 | void debugAfterPoll(); |
| 105 | |
| 106 | struct timeval m_timeSaved; |
| 107 | #endif |
| 108 | |
Constantin Kaplinsky | af1891c | 2005-09-29 06:18:28 +0000 | [diff] [blame] | 109 | }; |
| 110 | |
| 111 | #endif // __POLLINGMANAGER_H__ |