blob: 8983b378ae3a3042f55eab8d69ec8029be43e4c4 [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:
Pierre Ossmana114c342018-06-18 16:29:55 +020071 SimpleUpdateTracker();
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000072 virtual ~SimpleUpdateTracker();
73
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000074 virtual void add_changed(const Region &region);
75 virtual void add_copied(const Region &dest, const Point &delta);
76 virtual void subtract(const Region& region);
77
78 // Fill the supplied UpdateInfo structure with update information
Constantin Kaplinsky604d7812007-08-31 15:50:37 +000079 // FIXME: Provide getUpdateInfo() with no clipping, for better efficiency.
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000080 virtual void getUpdateInfo(UpdateInfo* info, const Region& cliprgn);
81
82 // Copy the contained updates to another tracker
83 virtual void copyTo(UpdateTracker* to) const;
84
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000085 // Move the entire update region by an offset
Pierre Ossman02e43d72009-03-05 11:57:11 +000086 void translate(const Point& p) {changed.translate(p); copied.translate(p);}
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000087
Pierre Ossman02e43d72009-03-05 11:57:11 +000088 virtual bool is_empty() const {return changed.is_empty() && copied.is_empty();}
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000089
Pierre Ossman02e43d72009-03-05 11:57:11 +000090 virtual void clear() {changed.clear(); copied.clear();};
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000091 protected:
92 Region changed;
93 Region copied;
94 Point copy_delta;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000095 };
96
97}
98
99#endif // __RFB_UPDATETRACKER_INCLUDED__