~alan-griffiths/qtmir/MirServer-is-an-implementation-detail

« back to all changes in this revision

Viewing changes to src/modules/Unity/Application/applicationscreenshotprovider.cpp

  • Committer: CI Train Bot
  • Author(s): Daniel d'Andrada
  • Date: 2016-04-13 18:38:36 UTC
  • mfrom: (466.2.3 removeApplicationScreenshot)
  • Revision ID: ci-train-bot@canonical.com-20160413183836-k6cnj7sdzj3mp7qn
Remove application screenshot provider

It's no longer needed now that QML provides a "item-snapshot" feature.

Besides, it has no purpose in a surface-based window management.
Approved by: Lukáš Tinkl, Gerry Boland

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2013-2015 Canonical, Ltd.
3
 
 *
4
 
 * This program is free software: you can redistribute it and/or modify it under
5
 
 * the terms of the GNU Lesser General Public License version 3, as published by
6
 
 * the Free Software Foundation.
7
 
 *
8
 
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 
 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10
 
 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11
 
 * Lesser General Public License for more details.
12
 
 *
13
 
 * You should have received a copy of the GNU Lesser General Public License
14
 
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
 
 */
16
 
 
17
 
// local
18
 
#include "applicationscreenshotprovider.h"
19
 
#include "application_manager.h"
20
 
#include "application.h"
21
 
#include "session.h"
22
 
 
23
 
// QPA-mirserver
24
 
#include "logging.h"
25
 
 
26
 
// mir
27
 
#include <mir/scene/session.h>
28
 
 
29
 
// Qt
30
 
#include <QMutex>
31
 
#include <QMutexLocker>
32
 
#include <QWaitCondition>
33
 
 
34
 
namespace qtmir
35
 
{
36
 
 
37
 
ApplicationScreenshotProvider::ApplicationScreenshotProvider(ApplicationManager *appManager)
38
 
    : QQuickImageProvider(QQuickImageProvider::Image)
39
 
    , m_appManager(appManager)
40
 
{
41
 
}
42
 
 
43
 
QImage ApplicationScreenshotProvider::requestImage(const QString &imageId, QSize *size,
44
 
                                                   const QSize &requestedSize)
45
 
{
46
 
    qCDebug(QTMIR_APPLICATIONS) << "ApplicationScreenshotProvider::requestImage - imageId=" << imageId;
47
 
 
48
 
    QString appId = imageId.split('/').first();
49
 
 
50
 
    Application* app = static_cast<Application*>(m_appManager->findApplication(appId));
51
 
    if (app == nullptr) {
52
 
        qWarning() << "ApplicationScreenshotProvider - app with appId" << appId << "not found";
53
 
        return QImage();
54
 
    }
55
 
 
56
 
    // TODO: if app not ready, return an app-provided splash image. If app has been stopped with saved state
57
 
    // return the screenshot that was saved to disk.
58
 
    SessionInterface* session = app->session();
59
 
    if (!session || !session->session() || !session->session()->default_surface()) {
60
 
        qWarning() << "ApplicationScreenshotProvider - app session not found - asking for screenshot too early";
61
 
        return QImage();
62
 
    }
63
 
 
64
 
    QImage screenshotImage;
65
 
    QMutex screenshotMutex;
66
 
    QWaitCondition screenshotTakenCondition;
67
 
    bool screenShotDone = false;
68
 
 
69
 
    session->session()->take_snapshot(
70
 
        [&](mir::scene::Snapshot const& snapshot)
71
 
        {
72
 
            qCDebug(QTMIR_APPLICATIONS) << "ApplicationScreenshotProvider - Mir snapshot ready with size"
73
 
                                        << snapshot.size.height.as_int() << "x" << snapshot.size.width.as_int();
74
 
 
75
 
            {
76
 
                // since we mirror, no need to offset starting position of the pixels
77
 
                QImage fullSizeScreenshot = QImage( (const uchar*)snapshot.pixels,
78
 
                            snapshot.size.width.as_int(),
79
 
                            snapshot.size.height.as_int(),
80
 
                            QImage::Format_ARGB32_Premultiplied).mirrored();
81
 
 
82
 
                if (!fullSizeScreenshot.isNull()) {
83
 
                    if (requestedSize.isValid()) {
84
 
                        *size = requestedSize.boundedTo(fullSizeScreenshot.size());
85
 
                        screenshotImage = fullSizeScreenshot.scaled(*size, Qt::IgnoreAspectRatio,
86
 
                            Qt::SmoothTransformation);
87
 
                    } else {
88
 
                        *size = fullSizeScreenshot.size();
89
 
                        screenshotImage = fullSizeScreenshot;
90
 
                    }
91
 
                }
92
 
 
93
 
                { // Sync point with Qt's ImageProviderThread
94
 
                    QMutexLocker screenshotMutexLocker(&screenshotMutex);
95
 
                    screenShotDone = true;
96
 
                }
97
 
 
98
 
                screenshotTakenCondition.wakeAll();
99
 
            }
100
 
        });
101
 
 
102
 
    { // Sync point with Mir's snapshot thread
103
 
        QMutexLocker screenshotMutexLocker(&screenshotMutex);
104
 
        if (!screenShotDone) {
105
 
            screenshotTakenCondition.wait(&screenshotMutex);
106
 
        }
107
 
    }
108
 
 
109
 
    qCDebug(QTMIR_APPLICATIONS) << "ApplicationScreenshotProvider - working with size" << screenshotImage;
110
 
 
111
 
    return screenshotImage;
112
 
}
113
 
 
114
 
} // namespace qtmir