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 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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(bool use_copyrect) {
  51. copy_enabled = use_copyrect;
  52. }
  53. SimpleUpdateTracker::~SimpleUpdateTracker() {
  54. }
  55. void SimpleUpdateTracker::enable_copyrect(bool enable) {
  56. if (!enable && copy_enabled) {
  57. add_changed(copied);
  58. copied.clear();
  59. }
  60. copy_enabled=enable;
  61. }
  62. void SimpleUpdateTracker::add_changed(const Region &region) {
  63. changed.assign_union(region);
  64. }
  65. void SimpleUpdateTracker::add_copied(const Region &dest, const Point &delta) {
  66. // Do we support copyrect?
  67. if (!copy_enabled) {
  68. add_changed(dest);
  69. return;
  70. }
  71. // Is there anything to do?
  72. if (dest.is_empty()) return;
  73. // Calculate whether any of this copy can be treated as a continuation
  74. // of an earlier one
  75. Region src = dest;
  76. src.translate(delta.negate());
  77. Region overlap = src.intersect(copied);
  78. if (overlap.is_empty()) {
  79. // There is no overlap
  80. Rect newbr = dest.get_bounding_rect();
  81. Rect oldbr = copied.get_bounding_rect();
  82. if (oldbr.area() > newbr.area()) {
  83. // Old copyrect is (probably) bigger - use it
  84. changed.assign_union(dest);
  85. } else {
  86. // New copyrect is probably bigger
  87. // Use the new one
  88. // But be careful not to copy stuff that still needs
  89. // to be updated.
  90. Region invalid_src = src.intersect(changed);
  91. invalid_src.translate(delta);
  92. changed.assign_union(invalid_src);
  93. changed.assign_union(copied);
  94. copied = dest;
  95. copy_delta = delta;
  96. }
  97. return;
  98. }
  99. Region invalid_src = overlap.intersect(changed);
  100. invalid_src.translate(delta);
  101. changed.assign_union(invalid_src);
  102. overlap.translate(delta);
  103. Region nonoverlapped_copied = dest.union_(copied).subtract(overlap);
  104. changed.assign_union(nonoverlapped_copied);
  105. copied = overlap;
  106. copy_delta = copy_delta.translate(delta);
  107. return;
  108. }
  109. void SimpleUpdateTracker::subtract(const Region& region) {
  110. copied.assign_subtract(region);
  111. changed.assign_subtract(region);
  112. }
  113. void SimpleUpdateTracker::getUpdateInfo(UpdateInfo* info, const Region& clip)
  114. {
  115. copied.assign_subtract(changed);
  116. info->changed = changed.intersect(clip);
  117. info->copied = copied.intersect(clip);
  118. info->copy_delta = copy_delta;
  119. }
  120. void SimpleUpdateTracker::copyTo(UpdateTracker* to) const {
  121. if (!copied.is_empty())
  122. to->add_copied(copied, copy_delta);
  123. if (!changed.is_empty())
  124. to->add_changed(changed);
  125. }