From dc3af6a164f82c1f9fadf86e910656504ccc48e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 16 Dec 2015 15:27:21 +0100 Subject: iOS: Implement support for QScreen::grabWindow() Only windows that are part of the application can be grabbed. This excludes the system statusbar and other system overlays, as well as windows of other applications. This is a limitation due to the security model of iOS. There exists APIs to grab a snapshot of the complete screen, but these APIs return a view that can be used as a placeholder e.g. during view transformations, and doesn't match our API that require reading of pixels. Task-number: QTBUG-49944 Change-Id: I8fd5b4c2777be1486f0ff22762d5e9b64c927e70 Reviewed-by: Jake Petroules --- src/plugins/platforms/ios/qiosscreen.mm | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'src/plugins/platforms/ios/qiosscreen.mm') diff --git a/src/plugins/platforms/ios/qiosscreen.mm b/src/plugins/platforms/ios/qiosscreen.mm index b9c77e9bba..bd2aa0e7e7 100644 --- a/src/plugins/platforms/ios/qiosscreen.mm +++ b/src/plugins/platforms/ios/qiosscreen.mm @@ -47,6 +47,7 @@ #include "quiview.h" #include +#include #include @@ -457,6 +458,38 @@ void QIOSScreen::setOrientationUpdateMask(Qt::ScreenOrientations mask) } } +QPixmap QIOSScreen::grabWindow(WId window, int x, int y, int width, int height) const +{ + if (window && ![reinterpret_cast(window) isKindOfClass:[UIView class]]) + return QPixmap(); + + UIView *view = window ? reinterpret_cast(window) : m_uiWindow; + + if (width < 0) + width = qMax(view.bounds.size.width - x, CGFloat(0)); + if (height < 0) + height = qMax(view.bounds.size.height - y, CGFloat(0)); + + CGRect captureRect = [m_uiWindow convertRect:CGRectMake(x, y, width, height) fromView:view]; + captureRect = CGRectIntersection(captureRect, m_uiWindow.bounds); + + UIGraphicsBeginImageContextWithOptions(captureRect.size, NO, 0.0); + CGContextRef context = UIGraphicsGetCurrentContext(); + CGContextTranslateCTM(context, -captureRect.origin.x, -captureRect.origin.y); + + // Draws the complete view hierarchy of m_uiWindow into the given rect, which + // needs to be the same aspect ratio as the m_uiWindow's size. Since we've + // translated the graphics context, and are potentially drawing into a smaller + // context than the full window, the resulting image will be a subsection of the + // full screen. + [m_uiWindow drawViewHierarchyInRect:m_uiWindow.bounds afterScreenUpdates:NO]; + + UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext(); + UIGraphicsEndImageContext(); + + return QPixmap::fromImage(qt_mac_toQImage(screenshot.CGImage)); +} + UIScreen *QIOSScreen::uiScreen() const { return m_uiScreen; -- cgit v1.2.3 From 04cb6e2754529d503050ec5841e23c273afaae96 Mon Sep 17 00:00:00 2001 From: Jake Petroules Date: Sun, 18 Sep 2016 18:40:13 -0700 Subject: Fix namespaced build on iOS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I682fabe8891e0325e6545b4499a59af4ad584c41 Reviewed-by: Mike Krus Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/ios/qiosscreen.mm | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/plugins/platforms/ios/qiosscreen.mm') diff --git a/src/plugins/platforms/ios/qiosscreen.mm b/src/plugins/platforms/ios/qiosscreen.mm index bd2aa0e7e7..013061a6d2 100644 --- a/src/plugins/platforms/ios/qiosscreen.mm +++ b/src/plugins/platforms/ios/qiosscreen.mm @@ -176,6 +176,8 @@ static QIOSScreen* qtPlatformScreenFor(UIScreen *uiScreen) // ------------------------------------------------------------------------- +QT_BEGIN_NAMESPACE + /*! Returns the model identifier of the device. -- cgit v1.2.3