You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UpdateTracker.cxx 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. // -=- rfbUpdateTracker.cpp
  19. //
  20. // Tracks updated regions and a region-copy event, too
  21. //
  22. #include <rfb/UpdateTracker.h>
  23. #include <rfb/LogWriter.h>
  24. using namespace rfb;
  25. static LogWriter vlog("UpdateTracker");
  26. // -=- ClippingUpdateTracker
  27. void ClippingUpdateTracker::add_changed(const Region &region) {
  28. ut->add_changed(region.intersect(clipRect));
  29. }
  30. void ClippingUpdateTracker::add_copied(const Region &dest, const Point &delta) {
  31. // Clip the destination to the display area
  32. Region clipdest = dest.intersect(clipRect);
  33. if (clipdest.is_empty()) return;
  34. // Clip the source to the screen
  35. Region tmp = clipdest;
  36. tmp.translate(delta.negate());
  37. tmp.assign_intersect(clipRect);
  38. if (!tmp.is_empty()) {
  39. // Translate the source back to a destination region
  40. tmp.translate(delta);
  41. // Pass the copy region to the child tracker
  42. ut->add_copied(tmp, delta);
  43. }
  44. // And add any bits that we had to remove to the changed region
  45. tmp = clipdest.subtract(tmp);
  46. if (!tmp.is_empty())
  47. ut->add_changed(tmp);
  48. }
  49. // SimpleUpdateTracker
  50. SimpleUpdateTracker::SimpleUpdateTracker() {
  51. }
  52. SimpleUpdateTracker::~SimpleUpdateTracker() {
  53. }
  54. void SimpleUpdateTracker::add_changed(const Region &region) {
  55. changed.assign_union(region);
  56. }
  57. void SimpleUpdateTracker::add_copied(const Region &dest, const Point &delta) {
  58. // Is there anything to do?
  59. if (dest.is_empty()) return;
  60. // Calculate whether any of this copy can be treated as a continuation
  61. // of an earlier one
  62. Region src = dest;
  63. src.translate(delta.negate());
  64. Region overlap = src.intersect(copied);
  65. if (overlap.is_empty()) {
  66. // There is no overlap
  67. Rect newbr = dest.get_bounding_rect();
  68. Rect oldbr = copied.get_bounding_rect();
  69. if (oldbr.area() > newbr.area()) {
  70. // Old copyrect is (probably) bigger - use it
  71. changed.assign_union(dest);
  72. } else {
  73. // New copyrect is probably bigger
  74. // Use the new one
  75. // But be careful not to copy stuff that still needs
  76. // to be updated.
  77. Region invalid_src = src.intersect(changed);
  78. invalid_src.translate(delta);
  79. changed.assign_union(invalid_src);
  80. changed.assign_union(copied);
  81. copied = dest;
  82. copy_delta = delta;
  83. }
  84. return;
  85. }
  86. Region invalid_src = overlap.intersect(changed);
  87. invalid_src.translate(delta);
  88. changed.assign_union(invalid_src);
  89. overlap.translate(delta);
  90. Region nonoverlapped_copied = dest.union_(copied).subtract(overlap);
  91. changed.assign_union(nonoverlapped_copied);
  92. copied = overlap;
  93. copy_delta = copy_delta.translate(delta);
  94. return;
  95. }
  96. void SimpleUpdateTracker::subtract(const Region& region) {
  97. copied.assign_subtract(region);
  98. changed.assign_subtract(region);
  99. }
  100. void SimpleUpdateTracker::getUpdateInfo(UpdateInfo* info, const Region& clip)
  101. {
  102. copied.assign_subtract(changed);
  103. info->changed = changed.intersect(clip);
  104. info->copied = copied.intersect(clip);
  105. info->copy_delta = copy_delta;
  106. }
  107. void SimpleUpdateTracker::copyTo(UpdateTracker* to) const {
  108. if (!copied.is_empty())
  109. to->add_copied(copied, copy_delta);
  110. if (!changed.is_empty())
  111. to->add_changed(changed);
  112. }