Constantin Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2002-2004 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 ClippedUpdateTracker : public UpdateTracker { |
| 51 | public: |
| 52 | ClippedUpdateTracker(UpdateTracker &child_) : child(child_) {}; |
| 53 | ClippedUpdateTracker(UpdateTracker &child_, |
| 54 | const Region &cliprgn_) : child(child_), cliprgn(cliprgn_) {}; |
| 55 | virtual ~ClippedUpdateTracker() {}; |
| 56 | |
| 57 | virtual void set_clip_region(const Region cliprgn_) {cliprgn = cliprgn_;}; |
| 58 | |
| 59 | virtual void add_changed(const Region ®ion); |
| 60 | virtual void add_copied(const Region &dest, const Point &delta); |
| 61 | protected: |
| 62 | UpdateTracker &child; |
| 63 | Region cliprgn; |
| 64 | }; |
| 65 | |
| 66 | class SimpleUpdateTracker : public UpdateTracker { |
| 67 | public: |
| 68 | SimpleUpdateTracker(bool use_copyrect=false); |
| 69 | virtual ~SimpleUpdateTracker(); |
| 70 | |
| 71 | virtual void enable_copyrect(bool enable); |
| 72 | |
| 73 | virtual void add_changed(const Region ®ion); |
| 74 | virtual void add_copied(const Region &dest, const Point &delta); |
| 75 | virtual void subtract(const Region& region); |
| 76 | |
| 77 | // Fill the supplied UpdateInfo structure with update information |
| 78 | virtual void get_update(UpdateInfo* info, const Region& cliprgn); |
| 79 | |
| 80 | // Pass the current updates to the supplied tracker |
| 81 | virtual void get_update(UpdateTracker &to) const; |
| 82 | |
| 83 | // Also removes the updates that are returned from this update tracker |
| 84 | virtual void flush_update(UpdateTracker &to, const Region &cliprgn); |
| 85 | |
| 86 | |
| 87 | // Get the changed/copied regions |
| 88 | const Region& get_changed() const {return changed;} |
| 89 | const Region& get_copied() const {return copied;} |
| 90 | const Point& get_delta() const {return copy_delta;} |
| 91 | |
| 92 | // Move the entire update region by an offset |
| 93 | void translate(const Point& p) {changed.translate(p); copied.translate(p);} |
| 94 | |
| 95 | virtual bool is_empty() const {return changed.is_empty() && copied.is_empty();} |
| 96 | |
| 97 | virtual void clear() {changed.clear(); copied.clear();}; |
| 98 | protected: |
| 99 | Region changed; |
| 100 | Region copied; |
| 101 | Point copy_delta; |
| 102 | bool copy_enabled; |
| 103 | }; |
| 104 | |
| 105 | } |
| 106 | |
| 107 | #endif // __RFB_UPDATETRACKER_INCLUDED__ |