diff options
author | Paul Olav Tvete <paul.tvete@nokia.com> | 2010-01-22 09:42:43 (GMT) |
---|---|---|
committer | Paul Olav Tvete <paul.tvete@nokia.com> | 2010-01-22 09:42:43 (GMT) |
commit | 5628a07e554d220396548f6914c798da8a556585 (patch) | |
tree | 84a7f4d3f4d0de09ed7e13922542b8f11cf49aed /src/plugins/graphicssystems | |
parent | a8cf2de36dc570d2e73248d4cbe88ee3eb330dc0 (diff) | |
download | Qt-5628a07e554d220396548f6914c798da8a556585.zip Qt-5628a07e554d220396548f6914c798da8a556585.tar.gz Qt-5628a07e554d220396548f6914c798da8a556585.tar.bz2 |
Implement grabWindow()
Diffstat (limited to 'src/plugins/graphicssystems')
-rw-r--r-- | src/plugins/graphicssystems/testlite/qgraphicssystem_testlite.cpp | 4 | ||||
-rw-r--r-- | src/plugins/graphicssystems/testlite/x11util.cpp | 42 | ||||
-rw-r--r-- | src/plugins/graphicssystems/testlite/x11util.h | 1 |
3 files changed, 44 insertions, 3 deletions
diff --git a/src/plugins/graphicssystems/testlite/qgraphicssystem_testlite.cpp b/src/plugins/graphicssystems/testlite/qgraphicssystem_testlite.cpp index 72d364a..ed8f883 100644 --- a/src/plugins/graphicssystems/testlite/qgraphicssystem_testlite.cpp +++ b/src/plugins/graphicssystems/testlite/qgraphicssystem_testlite.cpp @@ -112,8 +112,8 @@ QWindowSurface *QTestLiteGraphicsSystem::createWindowSurface(QWidget *widget) co QPixmap QTestLiteGraphicsSystem::grabWindow(WId window, int x, int y, int width, int height) const { - qDebug() << "grabWindow" << hex << window << dec<< x << y << width << height; - return QPixmap(); + QImage img = xd->grabWindow(window, x, y, width, height); + return QPixmap::fromImage(img); } diff --git a/src/plugins/graphicssystems/testlite/x11util.cpp b/src/plugins/graphicssystems/testlite/x11util.cpp index de2a6d9..7ad3ed5 100644 --- a/src/plugins/graphicssystems/testlite/x11util.cpp +++ b/src/plugins/graphicssystems/testlite/x11util.cpp @@ -377,6 +377,45 @@ void MyDisplay::eventDispatcher() } } + +QImage MyDisplay::grabWindow(Window window, int x, int y, int w, int h) +{ + if (w == 0 || h ==0) + return QImage(); + + //WinId 0 means the desktop widget + if (!window) + window = rootWindow(); + + XWindowAttributes window_attr; + if (!XGetWindowAttributes(display, window, &window_attr)) + return QImage(); + + if (w < 0) + w = window_attr.width - x; + if (h < 0) + h = window_attr.height - y; + + // Ideally, we should also limit ourselves to the screen area, but the Qt docs say + // that it's "unsafe" to go outside the screen, so we can ignore that problem. + + //We're definitely not optimizing for speed... + XImage *xi = XGetImage(display, window, x, y, w, h, AllPlanes, ZPixmap); + + if (!xi) + return QImage(); + + //taking a copy to make sure we have ownership -- not fast + QImage result = QImage( (uchar*) xi->data, xi->width, xi->height, xi->bytes_per_line, QImage::Format_RGB32 ).copy(); + + XDestroyImage(xi); + + return result; +} + + + + struct MyShmImageInfo { MyShmImageInfo(Display *xdisplay) : image(0), display(xdisplay) {} ~MyShmImageInfo() { destroy(); } @@ -477,13 +516,14 @@ void MyWindow::closeEvent() void MyWindow::paintEvent() { - Visual *visual = DefaultVisual(xd->display, xd->screen); #ifdef MYX11_DEBUG qDebug() << "MyWindow::paintEvent" << shm_img.size(); #endif #ifdef DONT_USE_MIT_SHM // just convert the image every time... if (!shm_img.isNull()) { + Visual *visual = DefaultVisual(xd->display, xd->screen); + QImage image = shm_img; //img.convertToFormat( XImage *xi = XCreateImage(xd->display, visual, 24, ZPixmap, diff --git a/src/plugins/graphicssystems/testlite/x11util.h b/src/plugins/graphicssystems/testlite/x11util.h index 08fd0ce..db87d92 100644 --- a/src/plugins/graphicssystems/testlite/x11util.h +++ b/src/plugins/graphicssystems/testlite/x11util.h @@ -68,6 +68,7 @@ public: unsigned long whitePixel() { return WhitePixel(display, screen); } bool handleEvent(XEvent *xe); + QImage grabWindow(Window w, int x, int y, int w, int h); public slots: void eventDispatcher(); |