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.9KB

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