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 | } |
| 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 ®ion) = 0; |
| 47 | virtual void add_copied(const Region &dest, const Point &delta) = 0; |
| 48 | }; |
| 49 | |
| 50 | class ClippingUpdateTracker : public UpdateTracker { |
| 51 | public: |
| 52 | 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;} |
| 57 | |
| 58 | virtual void add_changed(const Region ®ion); |
| 59 | virtual void add_copied(const Region &dest, const Point &delta); |
| 60 | protected: |
| 61 | UpdateTracker* ut; |
| 62 | Region clipRect; |
| 63 | }; |
| 64 | |
| 65 | class SimpleUpdateTracker : public UpdateTracker { |
| 66 | public: |
| 67 | SimpleUpdateTracker(bool use_copyrect=true); |
| 68 | virtual ~SimpleUpdateTracker(); |
| 69 | |
| 70 | virtual void enable_copyrect(bool enable); |
| 71 | |
| 72 | virtual void add_changed(const Region ®ion); |
| 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 |
| 77 | virtual void getUpdateInfo(UpdateInfo* info, const Region& cliprgn); |
| 78 | |
| 79 | // Copy the contained updates to another tracker |
| 80 | virtual void copyTo(UpdateTracker* to) const; |
| 81 | |
| 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__ |