Drawing on Java SWT Canvas using Xlib - Xwindows

This is a discussion on Drawing on Java SWT Canvas using Xlib - Xwindows ; I am trying to find any code/app that allow me to copy a xorg screen output to a java swt canvas. So far, I have only found xwatchwin(FreshPorts -- x11/xwatchwin) that is the closest to what I need, therefore I ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: Drawing on Java SWT Canvas using Xlib

  1. Drawing on Java SWT Canvas using Xlib

    I am trying to find any code/app that allow me to copy a xorg screen
    output to a java swt canvas.
    So far, I have only found xwatchwin(FreshPorts -- x11/xwatchwin) that
    is the closest to what I need, therefore I tried to modify the code to
    suit my needs.

    I have attempted to just change the Xlib Window object to the window
    id I have(Simply by casting the integer window id to a Window object).
    However when I am trying to draw using XPutImage in Xlib in C onto a
    Java SWT Canvas, its not painted onto it.

    The java swt canvas works when used with mplayer's -wid option.

    If there is a way to resize the XGetImage output for XPutImage, it
    would be wonderful also.

    Is there any C++ or Xlib guru that can help me?
    FYI, my C++ background is weak.

    Thanks in advance.

  2. Re: Drawing on Java SWT Canvas using Xlib

    zhixiong86@gmail.com wrote:
    > I am trying to find any code/app that allow me to copy a xorg screen
    > output to a java swt canvas.
    > So far, I have only found xwatchwin(FreshPorts -- x11/xwatchwin) that
    > is the closest to what I need, therefore I tried to modify the code to
    > suit my needs.
    >
    > I have attempted to just change the Xlib Window object to the window
    > id I have(Simply by casting the integer window id to a Window object).
    > However when I am trying to draw using XPutImage in Xlib in C onto a
    > Java SWT Canvas, its not painted onto it.


    Xlib uses XIDs which are typically unsigned long. Window, Pixmap,
    Drawable, and others types are XIDs.

    You might find that XDamage and Composite could help. With Composite
    you could redirect the tree of subwindows to offscreen buffers.
    XDamage is useful to detect changes/damage to windows and thereby update
    your Java SWT Canvas when you get an XDamageNotify event.

    If you don't use those extensions it's unfortunately likely that your
    app on the screen that you're copying to the canvas will have black
    areas where the content should be. The way that X by default renders
    the window hierarchy makes it difficult to capture the final window
    contents for individual children of the root window, especially if they
    are partially obscured.

    > The java swt canvas works when used with mplayer's -wid option.
    >
    > If there is a way to resize the XGetImage output for XPutImage, it
    > would be wonderful also.


    You could try to do this with XShmGetImage/XShmPutImage instead of
    XGetImage/XPutImage. The sad truth is that XGetImage and XPutImage are
    much slower (generally unusably slow for what I think you're proposing),
    though they are easier to use. It's very important to cleanup XShm
    shared memory segments properly. If an shm id, isn't cleaned up it
    persists after the processes using it exit.

    Composite and Render could be useful here as well, and might eliminate
    the need for XShm.
    XRenderSetPictureTransform could be used to scale a Picture.

    See this:
    http://ktown.kde.org/~fredrik/composite_howto.html

    > Is there any C++ or Xlib guru that can help me?
    > FYI, my C++ background is weak.


    Some of the X.org documentation is weak with regard to how to fit these
    extensions together. Be prepared to read a lot of code. I wrote a
    compositing manager for my window manager, because the existing
    compositing managers didn't work with the particular window hierarchy I
    use. XDamage, Composite, XFixes, and Render have use beyond compositing
    managers though.


    George

+ Reply to Thread