37
42
QImage ApplicationScreenshotProvider::requestImage(const QString &imageId, QSize *size,
38
43
const QSize &requestedSize)
40
// We ignore requestedSize here intentionally to avoid keeping scaled copies around
41
Q_UNUSED(requestedSize)
43
qCDebug(QTMIR_APPLICATIONS) << "ApplicationScreenshotProvider::requestImage - appId=" << imageId;
45
qCDebug(QTMIR_APPLICATIONS) << "ApplicationScreenshotProvider::requestImage - imageId=" << imageId;
45
47
QString appId = imageId.split('/').first();
60
QImage image = app->screenshotImage();
62
qCDebug(QTMIR_APPLICATIONS) << "ApplicationScreenshotProvider - working with size" << image;
63
size->setWidth(image.width());
64
size->setHeight(image.height());
62
QImage screenshotImage;
63
QMutex screenshotMutex;
64
QWaitCondition screenshotTakenCondition;
66
app->session()->take_snapshot(
67
[&](mir::scene::Snapshot const& snapshot)
69
qCDebug(QTMIR_APPLICATIONS) << "ApplicationScreenshotProvider - Mir snapshot ready with size"
70
<< snapshot.size.height.as_int() << "x" << snapshot.size.width.as_int();
73
// since we mirror, no need to offset starting position of the pixels
74
QImage fullSizeScreenshot = QImage( (const uchar*)snapshot.pixels,
75
snapshot.size.width.as_int(),
76
snapshot.size.height.as_int(),
77
QImage::Format_ARGB32_Premultiplied).mirrored();
79
QMutexLocker screenshotMutexLocker(&screenshotMutex);
81
if (requestedSize.isValid()) {
82
*size = requestedSize.boundedTo(fullSizeScreenshot.size());
83
screenshotImage = fullSizeScreenshot.scaled(*size, Qt::IgnoreAspectRatio,
84
Qt::SmoothTransformation);
86
*size = fullSizeScreenshot.size();
87
screenshotImage = fullSizeScreenshot;
90
screenshotTakenCondition.wakeAll();
95
QMutexLocker screenshotMutexLocker(&screenshotMutex);
96
if (screenshotImage.isNull()) {
97
// mir is taking a snapshot in a separate thread. Wait here until it's done.
98
screenshotTakenCondition.wait(&screenshotMutex);
100
// mir took a snapshot synchronously or it was asynchronous but already finished.
101
// In either case, there's no need to wait.
105
qCDebug(QTMIR_APPLICATIONS) << "ApplicationScreenshotProvider - working with size" << screenshotImage;
107
return screenshotImage;
69
110
} // namespace qtmir