blob: 9cd99ab1090c46492f569a222b75f63849e9f064 [file] [log] [blame]
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +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#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;
Constantin Kaplinsky1a845d02007-08-31 21:06:53 +000033 Rect video_area;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000034 bool is_empty() const {
Constantin Kaplinsky1a845d02007-08-31 21:06:53 +000035 return copied.is_empty() && changed.is_empty() && video_area.is_empty();
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000036 }
Constantin Kaplinsky604d7812007-08-31 15:50:37 +000037 // NOTE: We do not ever use UpdateInfo::numRects(), because Tight encoding
38 // complicates computing the number of rectangles.
39 /*
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000040 int numRects() const {
Constantin Kaplinsky1a845d02007-08-31 21:06:53 +000041 return copied.numRects() + changed.numRects() + !video_area.is_empty();
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000042 }
Constantin Kaplinsky604d7812007-08-31 15:50:37 +000043 */
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000044 };
45
46 class UpdateTracker {
47 public:
48 UpdateTracker() {};
49 virtual ~UpdateTracker() {};
50
51 virtual void add_changed(const Region &region) = 0;
52 virtual void add_copied(const Region &dest, const Point &delta) = 0;
Constantin Kaplinsky1a845d02007-08-31 21:06:53 +000053 virtual void set_video_area(const Rect &rect) = 0;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000054 };
55
56 class ClippingUpdateTracker : public UpdateTracker {
57 public:
58 ClippingUpdateTracker() : ut(0) {}
59 ClippingUpdateTracker(UpdateTracker* ut_, const Rect& r=Rect()) : ut(ut_), clipRect(r) {}
60
61 void setUpdateTracker(UpdateTracker* ut_) {ut = ut_;}
62 void setClipRect(const Rect& cr) {clipRect = cr;}
63
64 virtual void add_changed(const Region &region);
65 virtual void add_copied(const Region &dest, const Point &delta);
Constantin Kaplinsky1a845d02007-08-31 21:06:53 +000066 virtual void set_video_area(const Rect &rect);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000067 protected:
68 UpdateTracker* ut;
Constantin Kaplinsky604d7812007-08-31 15:50:37 +000069 Rect clipRect;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000070 };
71
72 class SimpleUpdateTracker : public UpdateTracker {
73 public:
74 SimpleUpdateTracker(bool use_copyrect=true);
75 virtual ~SimpleUpdateTracker();
76
77 virtual void enable_copyrect(bool enable);
78
79 virtual void add_changed(const Region &region);
80 virtual void add_copied(const Region &dest, const Point &delta);
Constantin Kaplinsky1a845d02007-08-31 21:06:53 +000081 virtual void set_video_area(const Rect &rect);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000082 virtual void subtract(const Region& region);
83
84 // Fill the supplied UpdateInfo structure with update information
Constantin Kaplinsky604d7812007-08-31 15:50:37 +000085 // FIXME: Provide getUpdateInfo() with no clipping, for better efficiency.
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000086 virtual void getUpdateInfo(UpdateInfo* info, const Region& cliprgn);
87
Constantin Kaplinsky6970b2d2008-06-13 18:07:53 +000088 // Get coordinates of the video rectangle
89 virtual const Rect& getVideoArea() const {
90 return video_area;
91 }
92
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000093 // Copy the contained updates to another tracker
94 virtual void copyTo(UpdateTracker* to) const;
95
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000096 // Move the entire update region by an offset
Constantin Kaplinsky1a845d02007-08-31 21:06:53 +000097 void translate(const Point& p) {
98 changed.translate(p);
99 copied.translate(p);
100 video_area.translate(p);
101 }
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000102
Constantin Kaplinsky1a845d02007-08-31 21:06:53 +0000103 virtual bool is_empty() const {
104 return changed.is_empty() && copied.is_empty() && video_area.is_empty();
105 }
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000106
Constantin Kaplinsky1a845d02007-08-31 21:06:53 +0000107 // NOTE: We do not clear video_area intentionally.
108 virtual void clear() {
109 changed.clear();
110 copied.clear();
111 }
112
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000113 protected:
114 Region changed;
115 Region copied;
116 Point copy_delta;
117 bool copy_enabled;
Constantin Kaplinsky1a845d02007-08-31 21:06:53 +0000118
119 // We can track one rectangle on the screen as a "video area". We assume
120 // it is changing continuously, in whole. Thus, we don't need to detect
121 // and track individual changes in the video area -- we can assume it's
122 // always in the changed state.
123 Rect video_area;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000124 };
125
126}
127
128#endif // __RFB_UPDATETRACKER_INCLUDED__