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.6KB

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