コード例 #1
0
ファイル: gl_drawing_area.py プロジェクト: cattaka/Xpra
class GLDrawingArea(GLWindowBackingBase):
    def __repr__(self):
        return "gtk%i.GLDrawingArea(%s, %s, %s)" % (
            gtk_version(), self.wid, self.size, self.pixel_format)

    def idle_add(self, *args, **kwargs):
        glib.idle_add(*args, **kwargs)

    def init_gl_config(self, window_alpha):
        self.context = GLContext(window_alpha)
        self.window_context = None

    def is_double_buffered(self):
        return self.context.is_double_buffered()

    def init_backing(self):
        da = gtk.DrawingArea()
        #da.connect('configure_event', self.on_configure_event)
        #da.connect('draw', self.on_draw)
        #double-buffering is enabled by default anyway, so this is redundant:
        #da.set_double_buffered(True)
        da.set_size_request(*self.size)
        da.set_events(da.get_events() | POINTER_MOTION_MASK
                      | POINTER_MOTION_HINT_MASK)
        da.show()
        self._backing = da

    def get_bit_depth(self, pixel_depth):
        return self.context.get_bit_depth() or pixel_depth or 24

    def gl_context(self):
        b = self._backing
        if not b:
            return None
        gdk_window = b.get_window()
        assert gdk_window
        self.window_context = self.context.get_paint_context(gdk_window)
        return self.window_context

    def do_gl_show(self, _rect_count):
        if self.is_double_buffered():
            # Show the backbuffer on screen
            log("%s.gl_show() swapping buffers now", self)
            self.window_context.swap_buffers()
        else:
            #glFlush was enough
            pass

    def close(self):
        GLWindowBackingBase.close(self)
        c = self.context
        if c:
            self.context = None
            c.destroy()

    def cairo_draw(self, _context):
        w, h = self.size
        with self.gl_context():
            self.gl_init()
            self.present_fbo(0, 0, w, h)
コード例 #2
0
ファイル: gl_check.py プロジェクト: tardyp/Xpra
def main():
    from xpra.platform import program_context
    from xpra.platform.gui import init as gui_init
    from xpra.util import print_nested_dict
    from xpra.log import enable_color
    with program_context("OpenGL-Check"):
        gui_init()
        enable_color()
        verbose = "-v" in sys.argv or "--verbose" in sys.argv
        if verbose:
            log.enable_debug()
        if POSIX and not OSX:
            from xpra.x11.gtk_x11.gdk_display_source import init_gdk_display_source
            init_gdk_display_source()
        force_enable = "-f" in sys.argv or "--force" in sys.argv
        from xpra.platform.gl_context import GLContext
        log("testing %s", GLContext)
        gl_context = GLContext()
        log("GLContext=%s", gl_context)
        #replace ImportError with a log message:
        global gl_check_error, raise_fatal_error
        errors = []

        def log_error(msg):
            log.error("ERROR: %s", msg)
            errors.append(msg)

        gl_check_error = log_error
        raise_fatal_error = log_error
        try:
            props = gl_context.check_support(force_enable)
        except Exception as e:
            props = {}
            log("check_support", exc_info=True)
            errors.append(e)
        log.info("")
        if len(errors) > 0:
            log.info("OpenGL errors:")
            for e in errors:
                log.info("  %s", e)
        if props:
            log.info("")
            log.info("OpenGL properties:")
            print_nested_dict(props)
        return len(errors)
コード例 #3
0
 def init_gl_config(self, window_alpha):
     self.context = GLContext(window_alpha)  #pylint: disable=not-callable
     self.window_context = None
コード例 #4
0
ファイル: gl_drawing_area.py プロジェクト: cattaka/Xpra
 def init_gl_config(self, window_alpha):
     self.context = GLContext(window_alpha)
     self.window_context = None
コード例 #5
0
 def init_gl_config(self):
     self.context = GLContext(self._alpha_enabled)  #pylint: disable=not-callable
     self.window_context = None
コード例 #6
0
ファイル: gl_drawing_area.py プロジェクト: chewi/xpra
class GLDrawingArea(GLWindowBackingBase):
    def __init__(self, wid: int, window_alpha: bool, pixel_depth: int = 0):
        self.on_realize_cb = []
        super().__init__(wid, window_alpha, pixel_depth)

    def __repr__(self):
        return "GLDrawingArea(%s, %s, %s)" % (self.wid, self.size,
                                              self.pixel_format)

    def idle_add(self, *args, **kwargs):
        GLib.idle_add(*args, **kwargs)

    def init_gl_config(self):
        self.context = GLContext(self._alpha_enabled)  #pylint: disable=not-callable
        self.window_context = None

    def is_double_buffered(self):
        return self.context.is_double_buffered()

    def init_backing(self):
        da = Gtk.DrawingArea()
        da.connect_after("realize", self.on_realize)
        #da.connect('configure_event', self.on_configure_event)
        #da.connect('draw', self.on_draw)
        #double-buffering is enabled by default anyway, so this is redundant:
        #da.set_double_buffered(True)
        da.set_size_request(*self.size)
        da.set_events(da.get_events() | Gdk.EventMask.POINTER_MOTION_MASK
                      | Gdk.EventMask.POINTER_MOTION_HINT_MASK)
        da.show()
        self._backing = da

    def on_realize(self, *args):
        onrcb = self.on_realize_cb
        log("GLDrawingArea.on_realize%s callbacks=%s", args, onrcb)
        self.on_realize_cb = []
        gl_context = self.gl_context()
        with gl_context:
            for x, args in onrcb:
                try:
                    x(gl_context, *args)
                except Exception:
                    log.error("Error calling realize callback %s",
                              x,
                              exc_info=True)

    def with_gl_context(self, cb, *args):
        da = self._backing
        if da and da.get_mapped():
            gl_context = self.gl_context()
            if gl_context:
                with gl_context:
                    cb(gl_context, *args)
            else:
                cb(None, *args)
        else:
            log("GLDrawingArea.with_gl_context delayed: %s%s", cb,
                ellipsizer(args))
            self.on_realize_cb.append((cb, args))

    def get_bit_depth(self, pixel_depth=0):
        return pixel_depth or self.context.get_bit_depth() or 24

    def gl_context(self):
        b = self._backing
        if not b:
            return None
        gdk_window = b.get_window()
        if not gdk_window:
            raise Exception("backing %s does not have a gdk window!" % b)
        self.window_context = self.context.get_paint_context(gdk_window)
        return self.window_context

    def do_gl_show(self, rect_count):
        if self.is_double_buffered():
            # Show the backbuffer on screen
            log("%s.do_gl_show(%s) swapping buffers now", rect_count, self)
            self.window_context.swap_buffers()
        else:
            #glFlush was enough
            pass

    def close_gl_config(self):
        c = self.context
        if c:
            self.context = None
            c.destroy()

    def draw_fbo(self, _context):
        w, h = self.size
        with self.gl_context():
            self.gl_init()
            self.present_fbo(0, 0, w, h)