Constantin Kaplinsky | 82f7b01 | 2008-05-30 10:03:30 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2004-2008 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 | |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 35 | class PollingManager { |
| 36 | |
| 37 | public: |
| 38 | |
Constantin Kaplinsky | 303433a | 2008-06-04 05:57:06 +0000 | [diff] [blame] | 39 | PollingManager(Display *dpy, const Image *image, ImageFactory &factory, |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 40 | int offsetLeft = 0, int offsetTop = 0); |
| 41 | virtual ~PollingManager(); |
| 42 | |
Peter Åstrand (astrand) | f523ee1 | 2017-10-09 14:59:24 +0200 | [diff] [blame] | 43 | void poll(rfb::VNCServer *server); |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 44 | |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 45 | protected: |
| 46 | |
Constantin Kaplinsky | 9ee8dc6 | 2007-10-09 07:46:32 +0000 | [diff] [blame] | 47 | // Screen polling. Returns true if some changes were detected. |
Peter Åstrand (astrand) | f523ee1 | 2017-10-09 14:59:24 +0200 | [diff] [blame] | 48 | bool pollScreen(rfb::VNCServer *server); |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 49 | |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 50 | Display *m_dpy; |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 51 | |
Constantin Kaplinsky | 429ea96 | 2008-06-02 11:56:57 +0000 | [diff] [blame] | 52 | const Image *m_image; |
Constantin Kaplinsky | adebffb | 2008-01-18 14:33:05 +0000 | [diff] [blame] | 53 | const int m_bytesPerPixel; |
Constantin Kaplinsky | ec45c48 | 2008-01-18 14:13:16 +0000 | [diff] [blame] | 54 | |
Constantin Kaplinsky | adebffb | 2008-01-18 14:33:05 +0000 | [diff] [blame] | 55 | const int m_offsetLeft; |
| 56 | const int m_offsetTop; |
| 57 | const int m_width; |
| 58 | const int m_height; |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 59 | |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 60 | private: |
| 61 | |
Constantin Kaplinsky | bc6b9e2 | 2007-10-04 11:43:41 +0000 | [diff] [blame] | 62 | inline void getRow(int x, int y, int w) { |
Constantin Kaplinsky | 41de242 | 2008-01-19 09:03:47 +0000 | [diff] [blame] | 63 | if (w == m_width) { |
| 64 | // Getting full row may be more efficient. |
| 65 | m_rowImage->get(DefaultRootWindow(m_dpy), |
| 66 | m_offsetLeft, m_offsetTop + y); |
| 67 | } else { |
| 68 | m_rowImage->get(DefaultRootWindow(m_dpy), |
| 69 | m_offsetLeft + x, m_offsetTop + y, w, 1); |
| 70 | } |
Constantin Kaplinsky | bc6b9e2 | 2007-10-04 11:43:41 +0000 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | inline void getColumn(int x, int y, int h) { |
Constantin Kaplinsky | ed3cf5d | 2007-12-28 17:59:10 +0000 | [diff] [blame] | 74 | m_columnImage->get(DefaultRootWindow(m_dpy), |
| 75 | m_offsetLeft + x, m_offsetTop + y, 1, h); |
Constantin Kaplinsky | bc6b9e2 | 2007-10-04 11:43:41 +0000 | [diff] [blame] | 76 | } |
| 77 | |
Constantin Kaplinsky | 04aa520 | 2008-01-18 15:37:15 +0000 | [diff] [blame] | 78 | inline int getTileIndex(int x, int y) { |
| 79 | int tile_x = x / 32; |
| 80 | int tile_y = y / 32; |
| 81 | return tile_y * m_widthTiles + tile_x; |
| 82 | } |
| 83 | |
Constantin Kaplinsky | 9d37e5c | 2008-01-18 11:17:26 +0000 | [diff] [blame] | 84 | int checkRow(int x, int y, int w); |
Constantin Kaplinsky | 553340c | 2007-12-28 18:37:04 +0000 | [diff] [blame] | 85 | int checkColumn(int x, int y, int h, bool *pChangeFlags); |
Peter Åstrand (astrand) | f523ee1 | 2017-10-09 14:59:24 +0200 | [diff] [blame] | 86 | int sendChanges(rfb::VNCServer *server) const; |
Constantin Kaplinsky | bd39035 | 2007-12-28 08:44:59 +0000 | [diff] [blame] | 87 | |
Constantin Kaplinsky | 850de2b | 2008-01-17 19:14:37 +0000 | [diff] [blame] | 88 | // Check neighboring tiles and update m_changeFlags[]. |
| 89 | void checkNeighbors(); |
Constantin Kaplinsky | 553340c | 2007-12-28 18:37:04 +0000 | [diff] [blame] | 90 | |
Constantin Kaplinsky | f50bd7f | 2008-01-10 15:27:42 +0000 | [diff] [blame] | 91 | // DEBUG: Print the list of changed tiles. |
Constantin Kaplinsky | 850de2b | 2008-01-17 19:14:37 +0000 | [diff] [blame] | 92 | void printChanges(const char *header) const; |
Constantin Kaplinsky | f50bd7f | 2008-01-10 15:27:42 +0000 | [diff] [blame] | 93 | |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 94 | // Additional images used in polling algorithms. |
Constantin Kaplinsky | ed3cf5d | 2007-12-28 17:59:10 +0000 | [diff] [blame] | 95 | Image *m_rowImage; // one row of the framebuffer |
| 96 | Image *m_columnImage; // one column of the framebuffer |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 97 | |
Constantin Kaplinsky | adebffb | 2008-01-18 14:33:05 +0000 | [diff] [blame] | 98 | const int m_widthTiles; // shortcut for ((m_width + 31) / 32) |
| 99 | const int m_heightTiles; // shortcut for ((m_height + 31) / 32) |
| 100 | const int m_numTiles; // shortcut for (m_widthTiles * m_heightTiles) |
Constantin Kaplinsky | 20390a2 | 2008-01-17 15:17:36 +0000 | [diff] [blame] | 101 | |
Constantin Kaplinsky | 85b5eb9 | 2008-01-17 17:41:48 +0000 | [diff] [blame] | 102 | // m_changeFlags[] array will hold boolean values corresponding to |
| 103 | // each 32x32 tile. If a value is true, then we've detected a change |
| 104 | // in that tile. |
| 105 | bool *m_changeFlags; |
| 106 | |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 107 | unsigned int m_pollingStep; |
| 108 | static const int m_pollingOrder[]; |
| 109 | |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 110 | #ifdef DEBUG |
| 111 | private: |
| 112 | |
| 113 | void debugBeforePoll(); |
| 114 | void debugAfterPoll(); |
| 115 | |
| 116 | TimeMillis m_timeSaved; |
| 117 | #endif |
| 118 | |
| 119 | }; |
| 120 | |
| 121 | #endif // __POLLINGMANAGER_H__ |