Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 1 | /* 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 | |
| 26 | namespace 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 | } |
Constantin Kaplinsky | 604d781 | 2007-08-31 15:50:37 +0000 | [diff] [blame^] | 36 | // NOTE: We do not ever use UpdateInfo::numRects(), because Tight encoding |
| 37 | // complicates computing the number of rectangles. |
| 38 | /* |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 39 | int numRects() const { |
| 40 | return copied.numRects() + changed.numRects(); |
| 41 | } |
Constantin Kaplinsky | 604d781 | 2007-08-31 15:50:37 +0000 | [diff] [blame^] | 42 | */ |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | class UpdateTracker { |
| 46 | public: |
| 47 | UpdateTracker() {}; |
| 48 | virtual ~UpdateTracker() {}; |
| 49 | |
| 50 | virtual void add_changed(const Region ®ion) = 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 ®ion); |
| 63 | virtual void add_copied(const Region &dest, const Point &delta); |
| 64 | protected: |
| 65 | UpdateTracker* ut; |
Constantin Kaplinsky | 604d781 | 2007-08-31 15:50:37 +0000 | [diff] [blame^] | 66 | Rect clipRect; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 67 | }; |
| 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 ®ion); |
| 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 Kaplinsky | 604d781 | 2007-08-31 15:50:37 +0000 | [diff] [blame^] | 81 | // FIXME: Provide getUpdateInfo() with no clipping, for better efficiency. |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 82 | 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 Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 87 | // Move the entire update region by an offset |
| 88 | void translate(const Point& p) {changed.translate(p); copied.translate(p);} |
| 89 | |
| 90 | virtual bool is_empty() const {return changed.is_empty() && copied.is_empty();} |
| 91 | |
| 92 | virtual void clear() {changed.clear(); copied.clear();}; |
| 93 | protected: |
| 94 | Region changed; |
| 95 | Region copied; |
| 96 | Point copy_delta; |
| 97 | bool copy_enabled; |
| 98 | }; |
| 99 | |
| 100 | } |
| 101 | |
| 102 | #endif // __RFB_UPDATETRACKER_INCLUDED__ |