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.

SDisplayCorePolling.cxx 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. 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. // -=- SDisplayCorePolling.cxx
  19. #ifdef HAVE_CONFIG_H
  20. #include <config.h>
  21. #endif
  22. #include <rfb_win32/SDisplayCorePolling.h>
  23. #include <rfb/LogWriter.h>
  24. #include <rfb/util.h>
  25. using namespace rfb;
  26. using namespace rfb::win32;
  27. static LogWriter vlog("SDisplayCorePolling");
  28. const int POLLING_SEGMENTS = 16;
  29. const unsigned int SDisplayCorePolling::pollTimerId = 1;
  30. SDisplayCorePolling::SDisplayCorePolling(SDisplay* d, UpdateTracker* ut, int pollInterval_)
  31. : MsgWindow(_T("rfb::win32::SDisplayCorePolling")),
  32. pollTimer(getHandle(), pollTimerId), pollNextStrip(false), display(d), updateTracker(ut) {
  33. pollInterval = __rfbmax(10, (pollInterval_ / POLLING_SEGMENTS));
  34. copyrect.setUpdateTracker(ut);
  35. }
  36. SDisplayCorePolling::~SDisplayCorePolling() {
  37. }
  38. LRESULT SDisplayCorePolling::processMessage(UINT msg, WPARAM wParam, LPARAM lParam) {
  39. if (msg == WM_TIMER && wParam == pollTimerId) {
  40. pollNextStrip = true;
  41. SetEvent(display->getUpdateEvent());
  42. return 0;
  43. }
  44. return MsgWindow::processMessage(msg, wParam, lParam);
  45. }
  46. void SDisplayCorePolling::setScreenRect(const Rect& screenRect_) {
  47. vlog.info("setScreenRect");
  48. screenRect = screenRect_;
  49. pollIncrementY = (screenRect.height()+POLLING_SEGMENTS-1)/POLLING_SEGMENTS;
  50. pollNextY = screenRect.tl.y;
  51. pollTimer.start(pollInterval);
  52. }
  53. void SDisplayCorePolling::flushUpdates() {
  54. vlog.write(120, "flushUpdates");
  55. // Check for window movement
  56. while (copyrect.processEvent()) {}
  57. if (pollNextStrip) {
  58. // Poll the next strip of the screen (in Screen coordinates)
  59. pollNextStrip = false;
  60. Rect pollrect = screenRect;
  61. if (pollNextY >= pollrect.br.y) {
  62. // Yes. Reset the counter and return
  63. pollNextY = pollrect.tl.y;
  64. } else {
  65. // No. Poll the next section
  66. pollrect.tl.y = pollNextY;
  67. pollNextY += pollIncrementY;
  68. pollrect.br.y = __rfbmin(pollNextY, pollrect.br.y);
  69. updateTracker->add_changed(pollrect);
  70. }
  71. }
  72. }