iOS: Implement QPlatformWindow::setMask() for masking rendering and input

Same implementation as for macOS.

[ChangeLog][iOS] QWindow::setMask() is now supported for masking the
rendering and touch input of child windows.

Change-Id: I2f9429f0f8fa278fdd8edc15c7b242c7c6bc0ff0
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
(cherry picked from commit ed7c7a1458a0d903cea250e8b7272c6b5bf9c624)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Tor Arne Vestbø 2023-08-02 16:32:15 +02:00 committed by Qt Cherry-pick Bot
parent 1b583f39d3
commit 99d0f997aa
2 changed files with 20 additions and 0 deletions

View File

@ -56,6 +56,8 @@ public:
void requestUpdate() override;
void setMask(const QRegion &region) override;
#if QT_CONFIG(opengl)
CAEAGLLayer *eaglLayer() const;
#endif

View File

@ -11,7 +11,10 @@
#include "quiview.h"
#include "qiosinputcontext.h"
#include <QtCore/private/qcore_mac_p.h>
#include <QtGui/private/qwindow_p.h>
#include <QtGui/private/qhighdpiscaling_p.h>
#include <qpa/qplatformintegration.h>
#if QT_CONFIG(opengl)
@ -54,6 +57,7 @@ QIOSWindow::QIOSWindow(QWindow *window)
setWindowState(window->windowStates());
setOpacity(window->opacity());
setMask(QHighDpi::toNativeLocalRegion(window->mask(), window));
Qt::ScreenOrientation initialOrientation = window->contentOrientation();
if (initialOrientation != Qt::PrimaryOrientation) {
@ -355,6 +359,20 @@ void QIOSWindow::requestUpdate()
static_cast<QIOSScreen *>(screen())->setUpdatesPaused(false);
}
void QIOSWindow::setMask(const QRegion &region)
{
if (!region.isEmpty()) {
QCFType<CGMutablePathRef> maskPath = CGPathCreateMutable();
for (const QRect &r : region)
CGPathAddRect(maskPath, nullptr, r.toCGRect());
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.path = maskPath;
m_view.layer.mask = maskLayer;
} else {
m_view.layer.mask = nil;
}
}
#if QT_CONFIG(opengl)
CAEAGLLayer *QIOSWindow::eaglLayer() const
{