Skip to content

Commit

Permalink
refactor all root window models so they all use a capture class
Browse files Browse the repository at this point in the history
git-svn-id: https://xpra.org/svn/Xpra/trunk@19178 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed May 3, 2018
1 parent 77cb74c commit 5fa14f0
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 55 deletions.
11 changes: 10 additions & 1 deletion src/xpra/platform/darwin/shadow_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,21 @@ def pixels_to_bytes(v):
picture_encode.pixels_to_bytes = pixels_to_bytes


class OSXRootWindowModel(RootWindowModel):
class OSXRootCapture(object):

def get_image(self, x, y, width, height):
rect = (x, y, width, height)
return get_CG_imagewrapper(rect)

def get_info(self):
return {}


class OSXRootWindowModel(RootWindowModel):

def __init__(self, root_window):
RootWindowModel.__init__(root_window, OSXRootCapture())

def take_screenshot(self):
log("grabbing screenshot")
return take_screenshot()
Expand Down
2 changes: 2 additions & 0 deletions src/xpra/platform/win32/gdi_screen_capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ def take_screenshot(self):
out.close()
return screenshot


def main():
import sys
import os.path
Expand All @@ -234,5 +235,6 @@ def main():
with open(filename, 'wb') as f:
f.write(image[4])


if __name__ == "__main__":
main()
21 changes: 1 addition & 20 deletions src/xpra/platform/win32/shadow_server.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# This file is part of Xpra.
# Copyright (C) 2012-2017 Antoine Martin <antoine@devloop.org.uk>
# Copyright (C) 2012-2018 Antoine Martin <antoine@devloop.org.uk>
# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
# later version. See the file COPYING for details.

Expand All @@ -19,7 +19,6 @@
from collections import namedtuple
from xpra.util import XPRA_APP_ID, XPRA_IDLE_NOTIFICATION_ID
from xpra.scripts.config import InitException
from xpra.codecs.codec_constants import CodecStateException, TransientCodecException
from xpra.server.gtk_server_base import GTKServerBase
from xpra.server.shadow.gtk_shadow_server_base import GTKShadowServerBase
from xpra.server.shadow.root_window_model import RootWindowModel
Expand Down Expand Up @@ -227,24 +226,6 @@ def get_root_window_size(self):
h = GetSystemMetrics(win32con.SM_CYVIRTUALSCREEN)
return w, h

def get_image(self, x, y, width, height):
try:
return self.capture.get_image(x, y, width, height)
except CodecStateException as e:
log("%s.get_image%s", self.capture, (x, y, width, height), exc_info=True)
#maybe we should exit here?
log.warn("Warning: %s", e)
del e
except TransientCodecException as e:
log("%s.get_image%s", self.capture, (x, y, width, height), exc_info=True)
log.warn("Warning: %s", e)
del e
self.cleanup_capture()
return None

def take_screenshot(self):
return self.capture.take_screenshot()


class ShadowServer(GTKShadowServerBase):

Expand Down
15 changes: 11 additions & 4 deletions src/xpra/server/shadow/gtk_root_window_model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# This file is part of Xpra.
# Copyright (C) 2012-2017 Antoine Martin <antoine@devloop.org.uk>
# Copyright (C) 2012-2018 Antoine Martin <antoine@devloop.org.uk>
# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
# later version. See the file COPYING for details.

Expand All @@ -11,7 +11,6 @@
from xpra.os_util import monotonic_time, strtobytes
from xpra.codecs.image_wrapper import ImageWrapper
from xpra.gtk_common.gtk_util import get_pixbuf_from_window, is_gtk3
from xpra.server.shadow.root_window_model import RootWindowModel


def get_rgb_rawdata(window, x, y, width, height):
Expand Down Expand Up @@ -54,10 +53,18 @@ def save_to_memory(data, *_args, **_kwargs):
return w, h, "png", rowstride, b"".join(buf)


class GTKRootWindowModel(RootWindowModel):
class GTKImageCapture(object):
def __init__(self, window):
self.window = window

def __repr__(self):
return "GTKRootWindowModel(%s)" % self.window
return "GTKImageCapture(%s)" % self.window

def clean(self):
pass

def refresh(self):
return True

def get_image(self, x, y, width, height):
v = get_rgb_rawdata(self.window, x, y, width, height)
Expand Down
8 changes: 6 additions & 2 deletions src/xpra/server/shadow/root_window_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ def get_info(self):
info["capture"] = c.get_info()
return info

def take_screenshot(self):
return self.capture.take_screenshot()

def get_image(self, *args):
return self.capture.get_image(*args)

def cleanup(self):
pass

Expand Down Expand Up @@ -66,8 +72,6 @@ def get_geometry(self):
w, h = self.get_dimensions()
return (0, 0, w, h)

def get_image(self, x, y, width, height):
raise NotImplementedError()

def get_property_names(self):
return self.property_names
Expand Down
32 changes: 4 additions & 28 deletions src/xpra/x11/shadow_x11_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
from xpra.os_util import monotonic_time
from xpra.util import envbool, envint, XPRA_APP_ID
from xpra.gtk_common.gtk_util import get_xwindow, is_gtk3
from xpra.codecs.image_wrapper import ImageWrapper
from xpra.server.shadow.root_window_model import RootWindowModel
from xpra.server.shadow.gtk_shadow_server_base import GTKShadowServerBase
from xpra.server.shadow.gtk_root_window_model import GTKRootWindowModel, get_rgb_rawdata, take_png_screenshot
from xpra.server.shadow.gtk_root_window_model import GTKImageCapture
from xpra.x11.bindings.ximage import XImageBindings #@UnresolvedImport
from xpra.gtk_common.error import xsync
XImage = XImageBindings()
Expand Down Expand Up @@ -98,29 +98,6 @@ def get_image(self, x, y, width, height):
log("X11 shadow captured %s pixels at %i MPixels/s using %s", width*height, (width*height/(end-start))//1024//1024, ["GTK", "XSHM"][USE_XSHM])


class GTKImageCapture(object):
def __init__(self, window):
self.window = window

def __repr__(self):
return "GTKImageCapture(%s)" % self.window

def clean(self):
pass

def refresh(self):
return True

def get_image(self, x, y, width, height):
v = get_rgb_rawdata(self.window, x, y, width, height)
if v is None:
return None
return ImageWrapper(*v)

def take_screenshot(self):
return take_png_screenshot(self.window)


def setup_capture(window):
ww, wh = window.get_geometry()[2:4]
capture = None
Expand All @@ -147,12 +124,11 @@ def setup_capture(window):
return capture


class GTKX11RootWindowModel(GTKRootWindowModel):
class GTKX11RootWindowModel(RootWindowModel):

def __init__(self, root_window, capture=None):
GTKRootWindowModel.__init__(self, root_window)
RootWindowModel.__init__(self, root_window, capture)
self.geometry = root_window.get_geometry()[:4]
self.capture = capture

def __repr__(self):
return "GTKX11RootWindowModel(%#x - %s - %s)" % (get_xwindow(self.window), self.geometry, self.capture)
Expand Down

0 comments on commit 5fa14f0

Please sign in to comment.