blob: 8e96d55ed007dbff9cfdf0e9074d15eaa3a188b1 [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;
33 bool is_empty() const {
Pierre Ossman02e43d72009-03-05 11:57:11 +000034 return copied.is_empty() && changed.is_empty();
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000035 }
Constantin Kaplinsky604d7812007-08-31 15:50:37 +000036 // NOTE: We do not ever use UpdateInfo::numRects(), because Tight encoding
37 // complicates computing the number of rectangles.
38 /*
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000039 int numRects() const {
Pierre Ossman02e43d72009-03-05 11:57:11 +000040 return copied.numRects() + changed.numRects();
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000041 }
Constantin Kaplinsky604d7812007-08-31 15:50:37 +000042 */
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000043 };
44
45 class UpdateTracker {
46 public:
47 UpdateTracker() {};
48 virtual ~UpdateTracker() {};
49
50 virtual void add_changed(const Region &region) = 0;
51 virtual void add_copied(const Region &dest, const Point &delta) = 0;
52 };
53
54 class ClippingUpdateTracker : public UpdateTracker {
55 public:
56 ClippingUpdateTracker() : ut(0) {}
57 ClippingUpdateTracker(UpdateTracker* ut_, const Rect& r=Rect()) : ut(ut_), clipRect(r) {}
58
59 void setUpdateTracker(UpdateTracker* ut_) {ut = ut_;}
60 void setClipRect(const Rect& cr) {clipRect = cr;}
61
62 virtual void add_changed(const Region &region);
63 virtual void add_copied(const Region &dest, const Point &delta);
64 protected:
65 UpdateTracker* ut;
Constantin Kaplinsky604d7812007-08-31 15:50:37 +000066 Rect clipRect;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000067 };
68
69 class SimpleUpdateTracker : public UpdateTracker {
70 public:
71 SimpleUpdateTracker(bool use_copyrect=true);
72 virtual ~SimpleUpdateTracker();
73
74 virtual void enable_copyrect(bool enable);
75
76 virtual void add_changed(const Region &region);
77 virtual void add_copied(const Region &dest, const Point &delta);
78 virtual void subtract(const Region& region);
79
80 // Fill the supplied UpdateInfo structure with update information
Constantin Kaplinsky604d7812007-08-31 15:50:37 +000081 // FIXME: Provide getUpdateInfo() with no clipping, for better efficiency.
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000082 virtual void getUpdateInfo(UpdateInfo* info, const Region& cliprgn);
83
84 // Copy the contained updates to another tracker
85 virtual void copyTo(UpdateTracker* to) const;
86
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000087 // Move the entire update region by an offset
Pierre Ossman02e43d72009-03-05 11:57:11 +000088 void translate(const Point& p) {changed.translate(p); copied.translate(p);}
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000089
Pierre Ossman02e43d72009-03-05 11:57:11 +000090 virtual bool is_empty() const {return changed.is_empty() && copied.is_empty();}
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000091
Pierre Ossman02e43d72009-03-05 11:57:11 +000092 virtual void clear() {changed.clear(); copied.clear();};
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000093 protected:
94 Region changed;
95 Region copied;
96 Point copy_delta;
97 bool copy_enabled;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000098 };
99
100}
101
102#endif // __RFB_UPDATETRACKER_INCLUDED__