Skip to content

Commit

Permalink
#2217 generalize gravity adjustments so all backends can honour it an…
Browse files Browse the repository at this point in the history
…d fix some renaming bugs caused by r23396

git-svn-id: https://xpra.org/svn/Xpra/trunk@23402 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Aug 3, 2019
1 parent a566317 commit bd5b789
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 190 deletions.
145 changes: 1 addition & 144 deletions src/xpra/client/gl/gl_window_backing_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,31 +212,6 @@ def py_gl_debug_callback(source, error_type, error_id, severity, length, message
RGBP2RGB_SHADER = 1
YUV2RGB_FULL_SHADER = 2

#X11 constants we use for gravity:
NorthWestGravity = 1
NorthGravity = 2
NorthEastGravity = 3
WestGravity = 4
CenterGravity = 5
EastGravity = 6
SouthWestGravity = 7
SouthGravity = 8
SouthEastGravity = 9
StaticGravity = 10

GRAVITY_STR = {
NorthWestGravity : "NorthWest",
NorthGravity : "North",
NorthEastGravity : "NorthEast",
WestGravity : "West",
CenterGravity : "Center",
EastGravity : "East",
SouthWestGravity : "SouthWest",
SouthGravity : "South",
SouthEastGravity : "SouthEast",
StaticGravity : "South",
}


"""
The logic is as follows:
Expand Down Expand Up @@ -337,8 +312,6 @@ def get_encoding_properties(self):
props = WindowBackingBase.get_encoding_properties(self)
if SCROLL_ENCODING:
props["encoding.scrolling"] = True
if FBO_RESIZE:
props["encoding.send-window-size"] = True
props["encoding.bit-depth"] = self.bit_depth
return props

Expand Down Expand Up @@ -367,65 +340,8 @@ def resize_fbo(self, oldw, oldh, bw, bh):
#if we have a valid context and an existing offscreen fbo,
#preserve the existing pixels by copying them onto the new tmp fbo (new size)
#and then doing the gl_init() call but without initializing the offscreen fbo.
sx, sy, dx, dy, w, h = self.gravity_copy_coords(oldw, oldh, bw, bh)
with context:
sx = sy = dx = dy = 0
w = min(bw, oldw)
h = min(bh, oldh)
def center_y():
if bh>=oldh:
#take the whole source, paste it in the middle
return 0, (bh-oldh)//2
#skip the edges of the source, paste all of it
return (oldh-bh)//2, 0
def center_x():
if bw>=oldw:
return 0, (bw-oldw)//2
return (oldw-bw)//2, 0
def east_x():
if bw>=oldw:
return 0, bw-oldw
return oldw-bw, 0
def west_x():
return 0, 0
def north_y():
return 0, 0
def south_y():
if bh>=oldh:
return 0, bh-oldh
return oldh-bh, 0
g = self.gravity
if not g or g==NorthWestGravity:
#undefined (or 0), use NW
sx, dx = west_x()
sy, dy = north_y()
elif g==NorthGravity:
sx, dx = center_x()
sy, dy = north_y()
elif g==NorthEastGravity:
sx, dx = east_x()
sy, dy = north_y()
elif g==WestGravity:
sx, dx = west_x()
sy, dy = center_y()
elif g==CenterGravity:
sx, dx = center_x()
sy, dy = center_y()
elif g==EastGravity:
sx, dx = east_x()
sy, dy = center_y()
elif g==SouthWestGravity:
sx, dx = west_x()
sy, dy = south_y()
elif g==SouthGravity:
sx, dx = center_x()
sy, dy = south_y()
elif g==SouthEastGravity:
sx, dx = east_x()
sy, dy = south_y()
elif g==StaticGravity:
if first_time("StaticGravity-%i" % self.wid):
log.warn("Warning: static gravity is not handled")

#invert Y coordinates for OpenGL:
sy = (oldh-h)-sy
dy = (bh-h)-dy
Expand Down Expand Up @@ -1117,8 +1033,6 @@ def do_paint_rgb(self, rgb_format, img_data, x, y, width, height, rowstride, opt
glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER)
glTexImage2D(target, 0, self.internal_format, width, height, 0, pformat, ptype, img_data)

x, y = self.gravity_adjust(x, y, options)

# Draw textured RGB quad at the right coordinates
glBegin(GL_QUADS)
glTexCoord2i(0, 0)
Expand Down Expand Up @@ -1147,62 +1061,6 @@ def do_paint_rgb(self, rgb_format, img_data, x, y, width, height, rowstride, opt
log("Error in %s paint of %i bytes, options=%s", rgb_format, len(img_data), options, exc_info=True)
fire_paint_callbacks(callbacks, False, message)

def gravity_adjust(self, x, y, options):
#if the window size has changed,
#adjust the coordinates honouring the window gravity:
window_size = options.intlistget("window-size", None)
if not window_size:
return x, y
window_size = tuple(window_size)
if window_size==self.size:
return x, y
if self.window_gravity==0 or self.window_gravity==NorthWestGravity:
return x, y
log("adjusting for %s gravity and window-size=%s, size=%s",
GRAVITY_STR.get(self.window_gravity, "unknown"), window_size, self.size)
oldw, oldh = window_size
bw, bh = self.size
def center_y():
if bh>=oldh:
return y + (bh-oldh)//2
return y - (oldh-bh)//2
def center_x():
if bw>=oldw:
return x + (bw-oldw)//2
return x - (oldw-bw)//2
def east_x():
if bw>=oldw:
return x + (bw-oldw)
return x - (oldw-bw)
def west_x():
return x
def north_y():
return y
def south_y():
if bh>=oldh:
return y + (bh-oldh)
return y - (oldh-bh)
g = self.window_gravity
if g==NorthGravity:
return center_x(), north_y()
if g==NorthEastGravity:
return east_x(), north_y()
if g==WestGravity:
return west_x(), center_y()
if g==CenterGravity:
return center_x(), center_y()
if g==EastGravity:
return east_x(), center_y()
if g==SouthWestGravity:
return west_x(), south_y()
if g==SouthGravity:
return center_x(), south_y()
if g==SouthEastGravity:
return east_x(), south_y()
#if self.gravity==StaticGravity:
# pass
return x, y


def do_video_paint(self, img, x, y, enc_width, enc_height, width, height, options, callbacks):
if not zerocopy_upload or FORCE_CLONE:
Expand Down Expand Up @@ -1238,7 +1096,6 @@ def gl_paint_planar(self, shader, flush, encoding, img, x, y, enc_width, enc_hei
x_scale = float(width)/enc_width
y_scale = float(height)/enc_height

x, y = self.gravity_adjust(x, y, options)
self.render_planar_update(x, y, enc_width, enc_height, x_scale, y_scale, shader)
self.paint_box(encoding, False, x, y, width, height)
fire_paint_callbacks(callbacks, True)
Expand Down
26 changes: 7 additions & 19 deletions src/xpra/client/gtk2/pixmap_backing.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,32 +83,20 @@ def do_init_new_backing_instance(self):
self._backing = None

def copy_backing(self, old_backing):
w, h = self.size
bw, bh = self.size
cr = self._backing.cairo_create()
cr.set_source_rgb(1, 1, 1)
if old_backing is not None:
# Really we should respect bit-gravity here but... meh.
old_w, old_h = old_backing.get_size()
if w>old_w and h>old_h:
#both width and height are bigger:
cr.rectangle(old_w, 0, w-old_w, h)
cr.fill()
cr.new_path()
cr.rectangle(0, old_h, old_w, h-old_h)
cr.fill()
elif w>old_w:
#enlarged in width only
cr.rectangle(old_w, 0, w-old_w, h)
cr.fill()
if h>old_h:
#enlarged in height only
cr.rectangle(0, old_h, w, h-old_h)
cr.fill()
oldw, oldh = old_backing.get_size()
sx, sy, dx, dy, w, h = self.gravity_copy_coords(oldw, oldh, bw, bh)
cr.translate(dx-sx, dy-sy)
cr.rectangle(sx, sy, w, h)
cr.fill()
cr.set_operator(cairo.OPERATOR_SOURCE)
cr.set_source_pixmap(old_backing, 0, 0)
cr.paint()
else:
cr.rectangle(0, 0, w, h)
cr.rectangle(0, 0, bw, bh)
cr.fill()

def paint_scroll(self, img_data, _options, callbacks):
Expand Down
35 changes: 10 additions & 25 deletions src/xpra/client/gtk_base/cairo_backing_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,45 +38,30 @@ def __init__(self, wid, window_alpha, _pixel_depth=0):
WindowBackingBase.__init__(self, wid, window_alpha and self.HAS_ALPHA)
self.idle_add = glib.idle_add

def init(self, ww, wh, w, h):
self.size = w, h
def init(self, ww, wh, bw, bh):
self.size = bw, bh
self.render_size = ww, wh
old_backing = self._backing
#should we honour self.depth here?
self._backing = None
if w==0 or h==0:
if bw==0 or bh==0:
#this can happen during cleanup
return
self._backing = cairo.ImageSurface(cairo.FORMAT_ARGB32, w, h)
self._backing = cairo.ImageSurface(cairo.FORMAT_ARGB32, bw, bh)
cr = cairo.Context(self._backing)
cr.set_operator(cairo.OPERATOR_CLEAR)
cr.set_source_rgba(1, 1, 1, 1)
cr.rectangle(0, 0, w, h)
cr.rectangle(0, 0, bw, bh)
cr.fill()
if old_backing is not None:
# Really we should respect bit-gravity here but... meh.
old_w = old_backing.get_width()
old_h = old_backing.get_height()
oldw, oldh = old_backing.get_width(), old_backing.get_height()
sx, sy, dx, dy, w, h = self.gravity_copy_coords(oldw, oldh, bw, bh)
cr.translate(dx-sx, dy-sy)
cr.rectangle(sx, sy, w, h)
cr.fill()
cr.set_operator(cairo.OPERATOR_SOURCE)
if w>old_w and h>old_h:
#both width and height are bigger:
cr.rectangle(old_w, 0, w-old_w, h)
cr.fill()
cr.new_path()
cr.rectangle(0, old_h, old_w, h-old_h)
cr.fill()
elif w>old_w:
#enlarged in width only
cr.rectangle(old_w, 0, w-old_w, h)
cr.fill()
if h>old_h:
#enlarged in height only
cr.rectangle(0, old_h, w, h-old_h)
cr.fill()
#cr.set_operator(cairo.OPERATOR_CLEAR)
cr.set_source_surface(old_backing, 0, 0)
cr.paint()
#old_backing.finish()

def close(self):
if self._backing:
Expand Down
Loading

0 comments on commit bd5b789

Please sign in to comment.