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