diff options
author | Artem Dyomin <artem.dyomin@qt.io> | 2023-02-07 16:10:59 +0100 |
---|---|---|
committer | Artem Dyomin <artem.dyomin@qt.io> | 2023-02-07 17:44:48 +0100 |
commit | a128d5ecf40d8d670d4d3aa8b9ddc860baa3cb5e (patch) | |
tree | 954a77cf20648b188eed61703b8e81ae9e540a5d /tests | |
parent | 0220951e712322e4e80253431a322317063e104a (diff) |
Rewrite screen capturing on macos
The previous generic implementation uses QScreen::grabWindow that
is not stable for both cases, screens and windows capturing.
In order to fix it, I've reimplemented it via native macos
functionality. Some part of the functionality is shared with avfcamera.
As a result, we got the following:
- fix not capturing of some windows on the screen
- enable hw acceleration for screens capturing
(shared with camera functionality)
- enable foreign app windows capturing (by CGWindowID as WId).
We might need some additional api for getting the list of ids.
Probably, the code is reusable for ios, to be investigated.
Screen capturing tests work locally if permissions are granted;
on CI some problems with giving the permissions.
Task-number: QTBUG-103226
Pick-to: 6.5
Change-Id: Iada34467e4b9074eb43a1fbbdc4409e663ea668a
Reviewed-by: Lars Knoll <lars@knoll.priv.no>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/integration/qscreencapture_integration/tst_qscreencapture_integration.cpp | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/tests/auto/integration/qscreencapture_integration/tst_qscreencapture_integration.cpp b/tests/auto/integration/qscreencapture_integration/tst_qscreencapture_integration.cpp index c5baab359..617eacf97 100644 --- a/tests/auto/integration/qscreencapture_integration/tst_qscreencapture_integration.cpp +++ b/tests/auto/integration/qscreencapture_integration/tst_qscreencapture_integration.cpp @@ -208,7 +208,7 @@ void tst_QScreenCaptureIntegration::capture(QTestWidget &widget, const QPoint &d QTest::qWait(delay); const auto expectedFramesCount = - delay / static_cast<int>(1000 / widget.screen()->refreshRate()); + delay / static_cast<int>(1000 / std::min(widget.screen()->refreshRate(), 60.)); const int framesCount = static_cast<int>(sink.images().size()); @@ -284,7 +284,8 @@ void tst_QScreenCaptureIntegration::initTestCase() void tst_QScreenCaptureIntegration::captureWindowById() { - auto widget = QTestWidget::createAndShow(Qt::Window, QRect{ 200, 100, 430, 351 }); + auto widget = QTestWidget::createAndShow(Qt::Window | Qt::FramelessWindowHint, + QRect{ 200, 100, 430, 351 }); QVERIFY(QTest::qWaitForWindowExposed(widget.get())); capture(*widget, { 0, 0 }, { 430, 351 }, @@ -293,7 +294,8 @@ void tst_QScreenCaptureIntegration::captureWindowById() void tst_QScreenCaptureIntegration::captureWindow() { - auto widget = QTestWidget::createAndShow(Qt::Window, QRect{ 200, 100, 430, 351 }); + auto widget = QTestWidget::createAndShow(Qt::Window | Qt::FramelessWindowHint, + QRect{ 200, 100, 430, 351 }); QVERIFY(QTest::qWaitForWindowExposed(widget.get())); capture(*widget, { 0, 0 }, { 430, 351 }, @@ -302,10 +304,12 @@ void tst_QScreenCaptureIntegration::captureWindow() void tst_QScreenCaptureIntegration::captureOverlappedWindow() { - auto overlappedWidget = QTestWidget::createAndShow(Qt::Window, QRect{ 200, 100, 430, 351 }); + auto overlappedWidget = QTestWidget::createAndShow(Qt::Window | Qt::FramelessWindowHint, + QRect{ 200, 100, 430, 351 }); QVERIFY(QTest::qWaitForWindowExposed(overlappedWidget.get())); - auto overlappingWidget = QTestWidget::createAndShow(Qt::Window, QRect{ 210, 110, 430, 351 }); + auto overlappingWidget = QTestWidget::createAndShow(Qt::Window | Qt::FramelessWindowHint, + QRect{ 210, 110, 430, 351 }); QVERIFY(QTest::qWaitForWindowExposed(overlappingWidget.get())); capture(*overlappedWidget, { 0, 0 }, { 430, 351 }, [&overlappedWidget](QScreenCapture &sc) { @@ -366,6 +370,8 @@ void tst_QScreenCaptureIntegration::removeWindowWhileCapture() void tst_QScreenCaptureIntegration::removeScreenWhileCapture() { + QSKIP("TODO: find a reliable way to emulate it"); + removeWhileCapture([](QScreenCapture &sc) { sc.setScreen(QApplication::primaryScreen()); }, []() { // It's something that doesn't look safe but it performs required flow |