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; |
Constantin Kaplinsky | 1a845d0 | 2007-08-31 21:06:53 +0000 | [diff] [blame] | 33 | Rect video_area; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 34 | bool is_empty() const { |
Constantin Kaplinsky | 1a845d0 | 2007-08-31 21:06:53 +0000 | [diff] [blame] | 35 | return copied.is_empty() && changed.is_empty() && video_area.is_empty(); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 36 | } |
Constantin Kaplinsky | 604d781 | 2007-08-31 15:50:37 +0000 | [diff] [blame] | 37 | // NOTE: We do not ever use UpdateInfo::numRects(), because Tight encoding |
| 38 | // complicates computing the number of rectangles. |
| 39 | /* |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 40 | int numRects() const { |
Constantin Kaplinsky | 1a845d0 | 2007-08-31 21:06:53 +0000 | [diff] [blame] | 41 | return copied.numRects() + changed.numRects() + !video_area.is_empty(); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 42 | } |
Constantin Kaplinsky | 604d781 | 2007-08-31 15:50:37 +0000 | [diff] [blame] | 43 | */ |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 44 | }; |
| 45 | |
| 46 | class UpdateTracker { |
| 47 | public: |
| 48 | UpdateTracker() {}; |
| 49 | virtual ~UpdateTracker() {}; |
| 50 | |
| 51 | virtual void add_changed(const Region ®ion) = 0; |
| 52 | virtual void add_copied(const Region &dest, const Point &delta) = 0; |
Constantin Kaplinsky | 1a845d0 | 2007-08-31 21:06:53 +0000 | [diff] [blame] | 53 | virtual void set_video_area(const Rect &rect) = 0; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | class ClippingUpdateTracker : public UpdateTracker { |
| 57 | public: |
| 58 | ClippingUpdateTracker() : ut(0) {} |
| 59 | ClippingUpdateTracker(UpdateTracker* ut_, const Rect& r=Rect()) : ut(ut_), clipRect(r) {} |
| 60 | |
| 61 | void setUpdateTracker(UpdateTracker* ut_) {ut = ut_;} |
| 62 | void setClipRect(const Rect& cr) {clipRect = cr;} |
| 63 | |
| 64 | virtual void add_changed(const Region ®ion); |
| 65 | virtual void add_copied(const Region &dest, const Point &delta); |
Constantin Kaplinsky | 1a845d0 | 2007-08-31 21:06:53 +0000 | [diff] [blame] | 66 | virtual void set_video_area(const Rect &rect); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 67 | protected: |
| 68 | UpdateTracker* ut; |
Constantin Kaplinsky | 604d781 | 2007-08-31 15:50:37 +0000 | [diff] [blame] | 69 | Rect clipRect; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | class SimpleUpdateTracker : public UpdateTracker { |
| 73 | public: |
| 74 | SimpleUpdateTracker(bool use_copyrect=true); |
| 75 | virtual ~SimpleUpdateTracker(); |
| 76 | |
| 77 | virtual void enable_copyrect(bool enable); |
| 78 | |
| 79 | virtual void add_changed(const Region ®ion); |
| 80 | virtual void add_copied(const Region &dest, const Point &delta); |
Constantin Kaplinsky | 1a845d0 | 2007-08-31 21:06:53 +0000 | [diff] [blame] | 81 | virtual void set_video_area(const Rect &rect); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 82 | virtual void subtract(const Region& region); |
| 83 | |
| 84 | // Fill the supplied UpdateInfo structure with update information |
Constantin Kaplinsky | 604d781 | 2007-08-31 15:50:37 +0000 | [diff] [blame] | 85 | // FIXME: Provide getUpdateInfo() with no clipping, for better efficiency. |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 86 | virtual void getUpdateInfo(UpdateInfo* info, const Region& cliprgn); |
| 87 | |
Constantin Kaplinsky | 6970b2d | 2008-06-13 18:07:53 +0000 | [diff] [blame] | 88 | // Get coordinates of the video rectangle |
| 89 | virtual const Rect& getVideoArea() const { |
| 90 | return video_area; |
| 91 | } |
| 92 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 93 | // Copy the contained updates to another tracker |
| 94 | virtual void copyTo(UpdateTracker* to) const; |
| 95 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 96 | // Move the entire update region by an offset |
Constantin Kaplinsky | 1a845d0 | 2007-08-31 21:06:53 +0000 | [diff] [blame] | 97 | void translate(const Point& p) { |
| 98 | changed.translate(p); |
| 99 | copied.translate(p); |
| 100 | video_area.translate(p); |
| 101 | } |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 102 | |
Constantin Kaplinsky | 1a845d0 | 2007-08-31 21:06:53 +0000 | [diff] [blame] | 103 | virtual bool is_empty() const { |
| 104 | return changed.is_empty() && copied.is_empty() && video_area.is_empty(); |
| 105 | } |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 106 | |
Constantin Kaplinsky | 1a845d0 | 2007-08-31 21:06:53 +0000 | [diff] [blame] | 107 | // NOTE: We do not clear video_area intentionally. |
| 108 | virtual void clear() { |
| 109 | changed.clear(); |
| 110 | copied.clear(); |
| 111 | } |
| 112 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 113 | protected: |
| 114 | Region changed; |
| 115 | Region copied; |
| 116 | Point copy_delta; |
| 117 | bool copy_enabled; |
Constantin Kaplinsky | 1a845d0 | 2007-08-31 21:06:53 +0000 | [diff] [blame] | 118 | |
| 119 | // We can track one rectangle on the screen as a "video area". We assume |
| 120 | // it is changing continuously, in whole. Thus, we don't need to detect |
| 121 | // and track individual changes in the video area -- we can assume it's |
| 122 | // always in the changed state. |
| 123 | Rect video_area; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | } |
| 127 | |
| 128 | #endif // __RFB_UPDATETRACKER_INCLUDED__ |