You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PollingManager.h 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* Copyright (C) 2004-2008 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. // PollingManager.h
  20. //
  21. #ifndef __POLLINGMANAGER_H__
  22. #define __POLLINGMANAGER_H__
  23. #include <X11/Xlib.h>
  24. #include <rfb/VNCServer.h>
  25. #include <x0vncserver/Image.h>
  26. #ifdef DEBUG
  27. #include <x0vncserver/TimeMillis.h>
  28. #endif
  29. class PollingManager {
  30. public:
  31. PollingManager(Display *dpy, const Image *image, ImageFactory &factory,
  32. int offsetLeft = 0, int offsetTop = 0);
  33. virtual ~PollingManager();
  34. void poll(rfb::VNCServer *server);
  35. protected:
  36. // Screen polling. Returns true if some changes were detected.
  37. bool pollScreen(rfb::VNCServer *server);
  38. Display *m_dpy;
  39. const Image *m_image;
  40. const int m_bytesPerPixel;
  41. const int m_offsetLeft;
  42. const int m_offsetTop;
  43. const int m_width;
  44. const int m_height;
  45. private:
  46. inline void getRow(int x, int y, int w) {
  47. if (w == m_width) {
  48. // Getting full row may be more efficient.
  49. m_rowImage->get(DefaultRootWindow(m_dpy),
  50. m_offsetLeft, m_offsetTop + y);
  51. } else {
  52. m_rowImage->get(DefaultRootWindow(m_dpy),
  53. m_offsetLeft + x, m_offsetTop + y, w, 1);
  54. }
  55. }
  56. inline void getColumn(int x, int y, int h) {
  57. m_columnImage->get(DefaultRootWindow(m_dpy),
  58. m_offsetLeft + x, m_offsetTop + y, 1, h);
  59. }
  60. inline int getTileIndex(int x, int y) {
  61. int tile_x = x / 32;
  62. int tile_y = y / 32;
  63. return tile_y * m_widthTiles + tile_x;
  64. }
  65. int checkRow(int x, int y, int w);
  66. int checkColumn(int x, int y, int h, bool *pChangeFlags);
  67. int sendChanges(rfb::VNCServer *server) const;
  68. // Check neighboring tiles and update m_changeFlags[].
  69. void checkNeighbors();
  70. // DEBUG: Print the list of changed tiles.
  71. void printChanges(const char *header) const;
  72. // Additional images used in polling algorithms.
  73. Image *m_rowImage; // one row of the framebuffer
  74. Image *m_columnImage; // one column of the framebuffer
  75. const int m_widthTiles; // shortcut for ((m_width + 31) / 32)
  76. const int m_heightTiles; // shortcut for ((m_height + 31) / 32)
  77. const int m_numTiles; // shortcut for (m_widthTiles * m_heightTiles)
  78. // m_changeFlags[] array will hold boolean values corresponding to
  79. // each 32x32 tile. If a value is true, then we've detected a change
  80. // in that tile.
  81. bool *m_changeFlags;
  82. unsigned int m_pollingStep;
  83. static const int m_pollingOrder[];
  84. #ifdef DEBUG
  85. private:
  86. void debugBeforePoll();
  87. void debugAfterPoll();
  88. TimeMillis m_timeSaved;
  89. #endif
  90. };
  91. #endif // __POLLINGMANAGER_H__