diff options
author | Artem Dyomin <artem.dyomin@qt.io> | 2023-05-12 17:49:13 +0200 |
---|---|---|
committer | Artem Dyomin <artem.dyomin@qt.io> | 2023-06-02 13:12:21 +0200 |
commit | 24c854fff9af00461b0920074b23d156e345a804 (patch) | |
tree | 6f71d2c9a8e1b76d12eaa2e25e7da839bad02d5c /tests | |
parent | dda06373eba84999a89e539035860fc45f2fa5f5 (diff) |
Add QWindowCapure and QCapturableWindow for window capturing
The design of QMediaCaptureSession already uses different types and
setters/gettes for each video source, like QCamera, QImageCapture,
and QScreenCapture, so a new source type, QWindowCapure, has been
added instead of extending QScreenCapture.
For now we only cover the case of capturing windows enumerated though
the capturing API itself, via a list of QCapturableWindow instances,
as this is considered the primary use-case for such an API.
An extension to this would be to add a QWindow overload to either
QCapturableWindow's constructor or QWindowCapture::setWindow, to
allow capturing of windows in the application itself, either created
by Qt, or via QWindow::fromWinId(), but this has been left out
for the initial API to keep things minimal.
A WId overload has been intentionally left out of this API, as
the path for capturing by WId should go via QWindow::fromWinId().
Finally, capture of windows from other applications without
enumerating them via QWindowCapure is left out, as adding such
an API would require us to build a more generic WId replacement
that isn't tied to a single type for each OS, like WId is (it's
a NSView* on macOS e.g., but windows can also be represented by
CGWindowID).
Task-number: QTBUG-103226
Change-Id: I99e3b8bde62250aba35abcedbc8680a299a3cbb2
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/integration/qscreencapture_integration/tst_qscreencapture_integration.cpp | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/tests/auto/integration/qscreencapture_integration/tst_qscreencapture_integration.cpp b/tests/auto/integration/qscreencapture_integration/tst_qscreencapture_integration.cpp index 931748837..a33b5c51e 100644 --- a/tests/auto/integration/qscreencapture_integration/tst_qscreencapture_integration.cpp +++ b/tests/auto/integration/qscreencapture_integration/tst_qscreencapture_integration.cpp @@ -116,15 +116,17 @@ class tst_QScreenCaptureIntegration : public QObject private slots: void initTestCase(); void setActive_startsAndStopsCapture(); +#if 0 // to be reimplemented with QWindowCapture void setWindowId_selectsCaptureWindow(); void setWindow_selectsCaptureWindow(); void setWindow_selectsWindow_whenWindowIsOverlapped(); + void capture_fails_whenCapturedWindowIsRemoved(); +#endif void setScreen_selectsScreen_whenCalledWithWidgetsScreen(); void constructor_selectsPrimaryScreenAsDefault(); void setScreen_selectsSecondaryScreen_whenCalledWithSecondaryScreen(); - void capture_fails_whenCapturedWindowIsRemoved(); - void capture_capturesToFile_whenConnectedToMediaRecorder(); + void capture_capturesToFile_whenConnectedToMediaRecorder(); void removeScreenWhileCapture(); // Keep the test last defined. TODO: find a way to restore // application screens. }; @@ -305,6 +307,7 @@ void tst_QScreenCaptureIntegration::initTestCase() QSKIP("Screen capturing not supported"); } +#if 0 // to be reimplemented with QWindowCapture void tst_QScreenCaptureIntegration::setWindowId_selectsCaptureWindow() { #if defined(Q_OS_ANDROID) || defined(Q_OS_IOS) @@ -349,6 +352,19 @@ void tst_QScreenCaptureIntegration::setWindow_selectsWindow_whenWindowIsOverlapp }); } +void tst_QScreenCaptureIntegration::capture_fails_whenCapturedWindowIsRemoved() +{ +#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS) + QSKIP("It is not the underlying windowing system"); +#endif + auto widget = QTestWidget::createAndShow(Qt::Window, QRect{ 200, 100, 430, 351 }); + QVERIFY(QTest::qWaitForWindowExposed(widget.get())); + + removeWhileCapture([&widget](QScreenCapture &sc) { sc.setWindowId(widget->winId()); }, + [&widget]() { widget.reset(); }); +} +#endif + void tst_QScreenCaptureIntegration::setScreen_selectsScreen_whenCalledWithWidgetsScreen() { auto widget = QTestWidget::createAndShow(Qt::Window | Qt::FramelessWindowHint @@ -399,18 +415,6 @@ void tst_QScreenCaptureIntegration::setScreen_selectsSecondaryScreen_whenCalledW [&screens](QScreenCapture &sc) { sc.setScreen(screens.back()); }); } -void tst_QScreenCaptureIntegration::capture_fails_whenCapturedWindowIsRemoved() -{ -#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS) - QSKIP("It is not the underlying windowing system"); -#endif - auto widget = QTestWidget::createAndShow(Qt::Window, QRect{ 200, 100, 430, 351 }); - QVERIFY(QTest::qWaitForWindowExposed(widget.get())); - - removeWhileCapture([&widget](QScreenCapture &sc) { sc.setWindowId(widget->winId()); }, - [&widget]() { widget.reset(); }); -} - void tst_QScreenCaptureIntegration::capture_capturesToFile_whenConnectedToMediaRecorder() { // Create widget with blue color |