summaryrefslogtreecommitdiffstats
path: root/src/platformsupport/eglconvenience/qeglplatformscreen.cpp
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@theqtcompany.com>2015-03-16 10:00:29 +0100
committerLaszlo Agocs <laszlo.agocs@theqtcompany.com>2015-03-16 13:24:55 +0000
commit60cdc6035d25441fd99a7d341892ee2fb1002741 (patch)
treea4d037dded9ac494bbaff8edac5fd7a3b2aeef8f /src/platformsupport/eglconvenience/qeglplatformscreen.cpp
parent3acd8d9aa463ffcc7d63d5262c0a66577c38f556 (diff)
Add support for grabWindow() on eglfs with widgets
For real OpenGL content it is still not supported because we have no reliable way to read back the contents at arbitrary times. Applications should rather use QQuickWindow::grabWindow() in that case. [ChangeLog][QtGui] Support for QScreen::grabWindow() is now available on embedded platforms (eglfs, linuxfb). Task-number: QTBUG-44937 Change-Id: I4ad046062782c160f5bb9f8f2a2fe82f2e7394cc Reviewed-by: Andy Nichols <andy.nichols@theqtcompany.com>
Diffstat (limited to 'src/platformsupport/eglconvenience/qeglplatformscreen.cpp')
-rw-r--r--src/platformsupport/eglconvenience/qeglplatformscreen.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/platformsupport/eglconvenience/qeglplatformscreen.cpp b/src/platformsupport/eglconvenience/qeglplatformscreen.cpp
index 6e2fc81c42..61f8cdd9b4 100644
--- a/src/platformsupport/eglconvenience/qeglplatformscreen.cpp
+++ b/src/platformsupport/eglconvenience/qeglplatformscreen.cpp
@@ -32,6 +32,7 @@
****************************************************************************/
#include "qeglplatformscreen_p.h"
+#include "qeglplatformwindow_p.h"
#include <QtGui/qwindow.h>
#include <qpa/qwindowsysteminterface.h>
#include <QtPlatformSupport/private/qopenglcompositor_p.h>
@@ -94,4 +95,52 @@ void QEGLPlatformScreen::handleCursorMove(const QPoint &pos)
QWindowSystemInterface::handleEnterLeaveEvent(enter, leave, enter->mapFromGlobal(pos), pos);
}
+QPixmap QEGLPlatformScreen::grabWindow(WId wid, int x, int y, int width, int height) const
+{
+ QOpenGLCompositor *compositor = QOpenGLCompositor::instance();
+ const QList<QOpenGLCompositorWindow *> windows = compositor->windows();
+ Q_ASSERT(!windows.isEmpty());
+
+ QImage img;
+
+ if (static_cast<QEGLPlatformWindow *>(windows.first()->sourceWindow()->handle())->isRaster()) {
+ // Request the compositor to render everything into an FBO and read it back. This
+ // is of course slow, but it's safe and reliable. It will not include the mouse
+ // cursor, which is a plus.
+ img = compositor->grab();
+ } else {
+ // Just a single OpenGL window without compositing. Do not support this case for now. Doing
+ // glReadPixels is not an option since it would read from the back buffer which may have
+ // undefined content when calling right after a swapBuffers (unless preserved swap is
+ // available and enabled, but we have no support for that).
+ qWarning("grabWindow: Not supported for non-composited OpenGL content. Use QQuickWindow::grabWindow() instead.");
+ return QPixmap();
+ }
+
+ if (!wid) {
+ const QSize screenSize = geometry().size();
+ if (width < 0)
+ width = screenSize.width() - x;
+ if (height < 0)
+ height = screenSize.height() - y;
+ return QPixmap::fromImage(img).copy(x, y, width, height);
+ }
+
+ foreach (QOpenGLCompositorWindow *w, windows) {
+ const QWindow *window = w->sourceWindow();
+ if (window->winId() == wid) {
+ const QRect geom = window->geometry();
+ if (width < 0)
+ width = geom.width() - x;
+ if (height < 0)
+ height = geom.height() - y;
+ QRect rect(geom.topLeft() + QPoint(x, y), QSize(width, height));
+ rect &= window->geometry();
+ return QPixmap::fromImage(img).copy(rect);
+ }
+ }
+
+ return QPixmap();
+}
+
QT_END_NAMESPACE