Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +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 | |
| 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; |
| 54 | static IntParameter pollingType; |
| 55 | |
| 56 | protected: |
| 57 | |
| 58 | // |
| 59 | // Implementations of different polling algorithms. |
| 60 | // Return value of true reports that some changes were detected. |
| 61 | // |
| 62 | bool poll_DetectVideo(); |
| 63 | bool poll_SkipCycles(); |
| 64 | bool poll_Traditional(); |
| 65 | bool poll_Dumb(); |
| 66 | |
| 67 | // Separate polling for the area around current pointer position. |
| 68 | void computePointerArea(Rect *r); |
| 69 | bool pollPointerArea(); |
| 70 | |
| 71 | Display *m_dpy; |
| 72 | VNCServer *m_server; |
| 73 | |
| 74 | Image *m_image; |
| 75 | int m_offsetLeft; |
| 76 | int m_offsetTop; |
| 77 | int m_width; |
| 78 | int m_height; |
| 79 | int m_widthTiles; |
| 80 | int m_heightTiles; |
| 81 | |
| 82 | // Tracking pointer position for polling improvements. |
| 83 | bool m_pointerPosKnown; |
| 84 | Point m_pointerPos; |
| 85 | time_t m_pointerPosTime; |
| 86 | |
| 87 | private: |
| 88 | |
| 89 | inline void getScreen() { |
| 90 | m_image->get(DefaultRootWindow(m_dpy), m_offsetLeft, m_offsetTop); |
| 91 | } |
| 92 | |
| 93 | inline void getRow(int y) { |
| 94 | m_rowImage->get(DefaultRootWindow(m_dpy), m_offsetLeft, m_offsetTop + y); |
| 95 | } |
| 96 | |
| 97 | inline void getTile32(int tx, int ty, int w, int h) { |
| 98 | if (w == 32 && h == 32) { |
| 99 | // This version of get() may be better optimized. |
| 100 | m_tileImage->get(DefaultRootWindow(m_dpy), |
| 101 | m_offsetLeft + tx * 32, m_offsetTop + ty * 32); |
| 102 | } else { |
| 103 | // Generic version of get() for arbitrary width and height. |
| 104 | m_tileImage->get(DefaultRootWindow(m_dpy), |
| 105 | m_offsetLeft + tx * 32, m_offsetTop + ty * 32, w, h); |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | inline void getArea128(int x, int y, int w, int h) { |
| 110 | if (w == 128 && h == 128) { |
| 111 | // This version of get() may be better optimized. |
| 112 | m_areaImage->get(DefaultRootWindow(m_dpy), |
| 113 | m_offsetLeft + x, m_offsetTop + y); |
| 114 | } else { |
| 115 | // Generic version of get() for arbitrary width and height. |
| 116 | m_areaImage->get(DefaultRootWindow(m_dpy), |
| 117 | m_offsetLeft + x, m_offsetTop + y, w, h); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | void adjustVideoArea(); |
| 122 | |
Constantin Kaplinsky | 5664998 | 2007-09-04 09:15:35 +0000 | [diff] [blame] | 123 | void getVideoAreaRect(Rect *result); |
| 124 | |
Constantin Kaplinsky | 0fc9f17 | 2007-09-29 04:00:02 +0000 | [diff] [blame^] | 125 | // Functions called by getVideoAreaRect(). |
| 126 | void constructLengthMatrices(int **pmx_h, int **pmx_v); |
| 127 | void destroyLengthMatrices(int *mx_h, int *mx_v); |
| 128 | void findMaxLocalRect(Rect *r, int *mx_h, int *mx_v); |
| 129 | |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 130 | // Additional images used in polling algorithms. |
| 131 | Image *m_rowImage; // One row of the framebuffer |
| 132 | Image *m_tileImage; // One tile (32x32 or less) |
| 133 | Image *m_areaImage; // Area around the pointer (up to 128x128) |
| 134 | |
| 135 | char *m_statusMatrix; |
| 136 | |
| 137 | char *m_rateMatrix; |
| 138 | char *m_videoFlags; |
| 139 | char *m_changedFlags; |
| 140 | |
| 141 | unsigned int m_pollingStep; |
| 142 | static const int m_pollingOrder[]; |
| 143 | |
| 144 | #ifdef DEBUG |
| 145 | private: |
| 146 | |
| 147 | void debugBeforePoll(); |
| 148 | void debugAfterPoll(); |
| 149 | |
| 150 | TimeMillis m_timeSaved; |
| 151 | #endif |
| 152 | |
| 153 | }; |
| 154 | |
| 155 | #endif // __POLLINGMANAGER_H__ |