Skip to content

Commit

Permalink
use cairo scaling if none of the csc modules can handle it
Browse files Browse the repository at this point in the history
limited backport of 65bb2fd
  • Loading branch information
totaam committed May 2, 2024
1 parent d382473 commit 9988cbd
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions xpra/client/gui/window_backing_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,10 +691,14 @@ def make_csc(self, src_width: int, src_height: int, src_format: str,
if not specs:
continue
for spec in specs:
score = - (spec.quality + spec.speed + spec.score_boost)
if not spec.can_scale and (src_width != dst_width or src_height != dst_height):
# prefer csc scaling to cairo's own scaling
score += 100
v = self.validate_csc_size(spec, src_width, src_height, dst_width, dst_height)
if v:
# not suitable
continue
score = - (spec.quality + spec.speed + spec.score_boost)
csc_scores.setdefault(score, []).append((dst_format, spec))

videolog(f"csc scores: {csc_scores}")
Expand All @@ -712,8 +716,10 @@ def make_csc(self, src_width: int, src_height: int, src_format: str,
for dst_format, spec in csc_scores.get(score):
try:
csc = spec.codec_class()
width = dst_width if spec.can_scale else src_width
height = dst_height if spec.can_scale else src_height
csc.init_context(src_width, src_height, src_format,
dst_width, dst_height, dst_format, options)
width, height, dst_format, options)
return csc
except Exception as e:
videolog("make_csc%s",
Expand Down Expand Up @@ -744,8 +750,6 @@ def make_csc(self, src_width: int, src_height: int, src_format: str,

@staticmethod
def validate_csc_size(spec, src_width: int, src_height: int, dst_width: int, dst_height: int):
if not spec.can_scale and (src_width != dst_width or src_height != dst_height):
return "scaling not supported"
if src_width < spec.min_w:
return "source width %i is out of range: minimum is %i", src_width, spec.min_w
if src_height < spec.min_h:
Expand Down Expand Up @@ -889,10 +893,12 @@ def do_video_paint(self, img, x: int, y: int, enc_width: int, enc_height: int, w

def paint():
data = rgb.get_pixels()
rgb_width = rgb.get_width()
rgb_height = rgb.get_height()
rowstride = rgb.get_rowstride()
try:
self.do_paint_rgb(rgb_format, data,
x, y, width, height, width, height, rowstride, paint_options, callbacks)
x, y, rgb_width, rgb_height, width, height, rowstride, paint_options, callbacks)
finally:
rgb.free()

Expand Down

0 comments on commit 9988cbd

Please sign in to comment.