This forum has been archived. All content is frozen. Please use KDE Discuss instead.

QPixmap + XRenderComposite

Tags: None
(comma "," separated)
twister
Registered Member
Posts
3
Karma
0

QPixmap + XRenderComposite

Tue Jul 20, 2010 1:41 pm
Firstly, Hi to all.
I'm new here. Didn't know where else to post this question, but I hope, that KDE developers will help to solve the problem I've been facing recently. I've examined the KDE source, and found some places where the similar techniques have been used.

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 :

Code: Select all

#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.
Of course, I understand that some windows won't be rendered, but I can't get at least one rendered.

Thanks for help in advance.
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS

Re: QPixmap + XRenderComposite

Wed Jul 21, 2010 5:26 am
If you don't get a reply here, you may wish to ask on kde-devel@kde.org.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
twister
Registered Member
Posts
3
Karma
0

Re: QPixmap + XRenderComposite

Wed Jul 21, 2010 7:43 am
Thanks a lot, I'll try that too. :)
twister
Registered Member
Posts
3
Karma
0

Re: QPixmap + XRenderComposite  Topic is solved

Thu Aug 12, 2010 9:14 am
Ok, the reason x11PictureHandle didn't work has been found.
By default, the QApplication uses "raster" graphics system, to render elements. In this case the x11PictureHandle for QPixmap does not work, as other buffers are used for QPixmap to be stored. If to set for QApplication in the main() function setGraphicsSystem( "native" ), then, the QPixmap is controlled by X11, so it has Picture Handle, and everything works fine.


Bookmarks



Who is online

Registered users: Bing [Bot], claydoh, Google [Bot], markhm, rblackwell, sethaaaa, Sogou [Bot], Yahoo [Bot]