[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Qt XRenderComposite question
From:       Twister Rodriguez <rodriguez.twister () gmail ! com>
Date:       2010-07-21 7:44:32
Message-ID: AANLkTinpzacBALdkeeLJ8FydZ9xJKcsJP0m3xKY5zN0a () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Hello,

I hope you could help with some code, which uses XRender XComposite and Qt.
The reason I'm asking, is because, I've seen similar code in the KDE source,
however, I can't make it work. May be you could help.

I'm trying to write a simple program, which redirects all the windows to the
backbuffer( as the composite manager does ), then write them to pixmap and
save to disk. Here is the code :

#include <QApplication>
#include <QDebug>
#include <X11/Xlib.h>
#include <QPaintDevice>
#include <QX11Info>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <X11/extensions/Xcomposite.h>
#include <X11/extensions/Xrender.h>
#include <X11/extensions/Xdamage.h>

#include <QPixmap>
#include <QWidget>

int main( int argc, char *argv[] )
{
    QApplication app( argc, argv );

    Picture frontBuffer;
    XRenderPictFormat *format;
    Window rootWindow;
    int depth;

    Display *dpy = XOpenDisplay( getenv("DISPLAY") );
    rootWindow = XRootWindow( dpy, XDefaultScreen( dpy ) );

    depth = DefaultDepth( dpy, DefaultScreen(dpy) );

    // Redirect all the windows
    XCompositeRedirectSubwindows( dpy, rootWindow, CompositeRedirectManual
);

    // Get the format
    format = XRenderFindVisualFormat( dpy, DefaultVisual( dpy,
DefaultScreen(dpy) ) );

    XRenderPictureAttributes pa;
    pa.subwindow_mode = IncludeInferiors;

    // Creating front buffer
    frontBuffer = XRenderCreatePicture( dpy, rootWindow, format,
CPSubwindowMode, &pa );

    uint nwindows;
    Window root_return, parent_return, *windows;

    XQueryTree( dpy, rootWindow, &root_return,
                    &parent_return, &windows, &nwindows );

    for ( uint i = 0; i < nwindows; i++ ) {
            XWindowAttributes attr;
            if ( !XGetWindowAttributes( dpy, windows[i], &attr ) )
                    continue;

            Pixmap pix = XCompositeNameWindowPixmap( dpy, windows[i] );

            Picture pic = XRenderCreatePicture( dpy, pix, format, 0, 0 );

            QPixmap pixmap(540, 900);
            XRenderComposite( dpy, PictOpSrc, pic, None,
pixmap.x11PictureHandle(),
                                          0, 0, 0, 0, 0 , 0, 540, 900 );
            pixmap.save( QString::number( i )+".png", "PNG" );
        }
    }
    XFree( windows );
    return app.exec();
}

The code works fine if I redirect the pic to the frontBuffer, as a result I
see the images of the windows on the screen. However, when I use
pixmap.x11PictureHandle(), I get just black images saved to disk and no
window pictures passed to them, so obviously I'm missing something. The
tutorial I used :
http://ktown.kde.org/~fredrik/composite_howto.html<http://ktown.kde.org/%7Efredrik/composite_howto.html>
.
Of course, I understand that some windows won't be rendered, but I can't get
at least one rendered.

What I'm missing or misunderstanding ?

Thank you in advance.

Regards,
Vladimir.

[Attachment #5 (text/html)]

Hello,<br><br>I hope you could help with some code, which uses XRender XComposite and \
Qt. The reason I&#39;m asking, is because, I&#39;ve seen similar code in the KDE \
source, however, I can&#39;t make it work. May be you could help.<br> <br>I&#39;m \
trying to write a simple program, which redirects all the windows to the backbuffer( \
as the composite manager does ), then write them to pixmap and save to disk. Here is \
the code : <br><br><code>#include &lt;QApplication&gt;<br>#include \
&lt;QDebug&gt;<br>#include &lt;X11/Xlib.h&gt;<br>#include \
&lt;QPaintDevice&gt;<br>#include &lt;QX11Info&gt;<br>#include &lt;X11/Xlib.h&gt;<br> \
#include &lt;X11/Xutil.h&gt;<br>#include &lt;X11/Xatom.h&gt;<br>#include \
&lt;X11/extensions/Xcomposite.h&gt;<br>#include \
&lt;X11/extensions/Xrender.h&gt;<br>#include \
&lt;X11/extensions/Xdamage.h&gt;<br><br>#include &lt;QPixmap&gt;<br> #include \
&lt;QWidget&gt;<br><br>int main( int argc, char *argv[] )<br>{<br>    QApplication \
app( argc, argv );<br><br>    Picture frontBuffer;<br>    XRenderPictFormat \
*format;<br>    Window rootWindow;<br>    int depth;<br> <br>    Display *dpy = \
XOpenDisplay( getenv(&quot;DISPLAY&quot;) );<br>    rootWindow = XRootWindow( dpy, \
XDefaultScreen( dpy ) );<br><br>    depth = DefaultDepth( dpy, DefaultScreen(dpy) \
);<br><br>    // Redirect all the windows<br>  XCompositeRedirectSubwindows( dpy, \
rootWindow, CompositeRedirectManual );<br><br>    // Get the format<br>    format = \
XRenderFindVisualFormat( dpy, DefaultVisual( dpy, DefaultScreen(dpy) ) );<br><br>    \
XRenderPictureAttributes pa;<br>  pa.subwindow_mode = IncludeInferiors;<br><br>    // \
Creating front buffer<br>    frontBuffer = XRenderCreatePicture( dpy, rootWindow, \
format, CPSubwindowMode, &amp;pa );<br><br>    uint nwindows;<br>    Window \
root_return, parent_return, *windows;<br> <br>    XQueryTree( dpy, rootWindow, \
&amp;root_return,<br>                    &amp;parent_return, &amp;windows, \
&amp;nwindows );<br><br>    for ( uint i = 0; i &lt; nwindows; i++ ) {<br>            \
XWindowAttributes attr;<br>  if ( !XGetWindowAttributes( dpy, windows[i], &amp;attr ) \
)<br>                    continue;<br><br>            Pixmap pix = \
XCompositeNameWindowPixmap( dpy, windows[i] );<br><br>            Picture pic = \
XRenderCreatePicture( dpy, pix, format, 0, 0 );<br>  <br>            QPixmap \
pixmap(540, 900);<br>            XRenderComposite( dpy, PictOpSrc, pic, None, \
pixmap.x11PictureHandle(),<br>                                          0, 0, 0, 0, 0 \
, 0, 540, 900 );<br>  pixmap.save( QString::number( i )+&quot;.png&quot;, \
&quot;PNG&quot; );<br>        }<br>    }<br>    XFree( windows );<br>    return \
app.exec();<br>}</code><br><br>The code works fine if I redirect the <span \
style="font-style: italic;">pic</span> to the <span style="font-style: \
italic;">frontBuffer</span>, as a result I see the images of the windows on the \
screen. However, when I use <span style="font-style: \
italic;">pixmap.x11PictureHandle()</span>, I get just black images saved to disk and \
no window pictures passed to them, so obviously I&#39;m missing something. The \
tutorial I used : <a class="postlink" \
href="http://ktown.kde.org/%7Efredrik/composite_howto.html">http://ktown.kde.org/~fredrik/composite_howto.html</a>.<br>Of \
course, I understand that some windows won&#39;t be rendered, but I can&#39;t get at \
least one rendered.<br> <br>What I&#39;m missing or misunderstanding ?<br><br>Thank \
you in advance.<br><br>Regards,<br>Vladimir.<br>



>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic