blob: 5b51317a19618955ed7bd07f62e58fb8c3cffaac [file] [log] [blame]
Constantin Kaplinskyde179d42006-04-16 06:53:44 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
2 *
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +00003 * 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#ifndef __RFB_UPDATETRACKER_INCLUDED__
20#define __RFB_UPDATETRACKER_INCLUDED__
21
22#include <rfb/Rect.h>
23#include <rfb/Region.h>
24#include <rfb/PixelBuffer.h>
25
26namespace rfb {
27
28 class UpdateInfo {
29 public:
30 Region changed;
31 Region copied;
32 Point copy_delta;
33 bool is_empty() const {
34 return copied.is_empty() && changed.is_empty();
35 }
36 int numRects() const {
37 return copied.numRects() + changed.numRects();
38 }
39 };
40
41 class UpdateTracker {
42 public:
43 UpdateTracker() {};
44 virtual ~UpdateTracker() {};
45
46 virtual void add_changed(const Region &region) = 0;
47 virtual void add_copied(const Region &dest, const Point &delta) = 0;
48 };
49
Constantin Kaplinskyde179d42006-04-16 06:53:44 +000050 class ClippingUpdateTracker : public UpdateTracker {
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000051 public:
Constantin Kaplinskyde179d42006-04-16 06:53:44 +000052 ClippingUpdateTracker() : ut(0) {}
53 ClippingUpdateTracker(UpdateTracker* ut_, const Rect& r=Rect()) : ut(ut_), clipRect(r) {}
54
55 void setUpdateTracker(UpdateTracker* ut_) {ut = ut_;}
56 void setClipRect(const Rect& cr) {clipRect = cr;}
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000057
58 virtual void add_changed(const Region &region);
59 virtual void add_copied(const Region &dest, const Point &delta);
60 protected:
Constantin Kaplinskyde179d42006-04-16 06:53:44 +000061 UpdateTracker* ut;
62 Region clipRect;
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000063 };
64
65 class SimpleUpdateTracker : public UpdateTracker {
66 public:
Constantin Kaplinskyde179d42006-04-16 06:53:44 +000067 SimpleUpdateTracker(bool use_copyrect=true);
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000068 virtual ~SimpleUpdateTracker();
69
70 virtual void enable_copyrect(bool enable);
71
72 virtual void add_changed(const Region &region);
73 virtual void add_copied(const Region &dest, const Point &delta);
74 virtual void subtract(const Region& region);
75
76 // Fill the supplied UpdateInfo structure with update information
Constantin Kaplinskyde179d42006-04-16 06:53:44 +000077 virtual void getUpdateInfo(UpdateInfo* info, const Region& cliprgn);
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000078
Constantin Kaplinskyde179d42006-04-16 06:53:44 +000079 // Copy the contained updates to another tracker
80 virtual void copyTo(UpdateTracker* to) const;
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000081
82
83 // Get the changed/copied regions
84 const Region& get_changed() const {return changed;}
85 const Region& get_copied() const {return copied;}
86 const Point& get_delta() const {return copy_delta;}
87
88 // Move the entire update region by an offset
89 void translate(const Point& p) {changed.translate(p); copied.translate(p);}
90
91 virtual bool is_empty() const {return changed.is_empty() && copied.is_empty();}
92
93 virtual void clear() {changed.clear(); copied.clear();};
94 protected:
95 Region changed;
96 Region copied;
97 Point copy_delta;
98 bool copy_enabled;
99 };
100
101}
102
103#endif // __RFB_UPDATETRACKER_INCLUDED__