Skip to content

Commit

Permalink
restore region merging, but better: only use merged region if it ends…
Browse files Browse the repository at this point in the history
… up using less resources than many smaller ones

git-svn-id: https://xpra.org/svn/Xpra/trunk@5425 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Feb 10, 2014
1 parent 018f5e3 commit 03d5f42
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/xpra/gtk_common/region.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ def __init__(self, x, y, w, h):
def __eq__(self, other):
return self.x==other.x and self.y==other.y and self.width==other.width and self.height==other.height

def merge(self, x, y, w, h):
self.x = min(self.x, x)
self.y = min(self.y, y)
self.width = max(self.x+self.width, x+w)-self.x
self.height = max(self.y+self.height, y+h)-self.y

def clone(self):
return rectangle(self.x, self.y, self.width, self.height)


def _contains(regions, x, y, w, h):
x2 = x+w
y2 = y+h
Expand Down
16 changes: 14 additions & 2 deletions src/xpra/server/window_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,12 +626,24 @@ def send_full_window_update():

bytes_threshold = ww*wh*self.max_bytes_percent/100
pixel_count = sum([rect.width*rect.height for rect in regions])
if pixel_count+self.small_packet_cost*len(regions)>=bytes_threshold:
bytes_cost = pixel_count+self.small_packet_cost*len(regions)
if bytes_cost>=bytes_threshold:
#too many bytes
send_full_window_update()
return
log("send_delayed_regions: %s regions with %s pixels", len(regions), pixel_count)

if len(regions)>1:
#try to merge all regions to see if we save anything:
merged = regions[0].clone()
for r in regions[1:]:
merged.merge(r.x, r.y, r.width, r.height)
merged_pixel_count = merged.width*merged.height
merged_bytes_cost = pixel_count+self.small_packet_cost*1
if merged_bytes_cost<bytes_cost or merged_pixel_count<pixel_count:
#replace with just one region:
regions = [merged]

log("send_delayed_regions: %s regions with %s pixels", len(regions), pixel_count)
actual_encoding = self.get_best_encoding(True, window, pixel_count, ww, wh, coding)
if self.must_encode_full_frame(window, actual_encoding):
#use full screen dimensions:
Expand Down

0 comments on commit 03d5f42

Please sign in to comment.