| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/items/qquickitemgrabresult.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||
| 2 | - | |||||||||||||
| 3 | - | |||||||||||||
| 4 | - | |||||||||||||
| 5 | - | |||||||||||||
| 6 | - | |||||||||||||
| 7 | - | |||||||||||||
| 8 | - | |||||||||||||
| 9 | const QEvent::Type Event_Grab_Completed = static_cast<QEvent::Type>(QEvent::User + 1); | - | ||||||||||||
| 10 | - | |||||||||||||
| 11 | class QQuickItemGrabResultPrivate : public QObjectPrivate | - | ||||||||||||
| 12 | { | - | ||||||||||||
| 13 | public: | - | ||||||||||||
| 14 | QQuickItemGrabResultPrivate() | - | ||||||||||||
| 15 | : cacheEntry(nullptr) | - | ||||||||||||
| 16 | , qmlEngine(nullptr) | - | ||||||||||||
| 17 | , texture(nullptr) | - | ||||||||||||
| 18 | { | - | ||||||||||||
| 19 | } executed 8 times by 2 tests: end of blockExecuted by:
| 8 | ||||||||||||
| 20 | - | |||||||||||||
| 21 | ~QQuickItemGrabResultPrivate() | - | ||||||||||||
| 22 | { | - | ||||||||||||
| 23 | delete cacheEntry; | - | ||||||||||||
| 24 | } executed 8 times by 2 tests: end of blockExecuted by:
| 8 | ||||||||||||
| 25 | - | |||||||||||||
| 26 | void ensureImageInCache() const { | - | ||||||||||||
| 27 | if (url.isEmpty()
| 0-4 | ||||||||||||
| 28 | url.setScheme(QQuickPixmap::itemGrabberScheme); | - | ||||||||||||
| 29 | url.setPath(QVariant::fromValue(item.data()).toString()); | - | ||||||||||||
| 30 | static uint counter = 0; | - | ||||||||||||
| 31 | url.setFragment(QString::number(++counter)); | - | ||||||||||||
| 32 | cacheEntry = new QQuickPixmap(url, image); | - | ||||||||||||
| 33 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||
| 34 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||
| 35 | - | |||||||||||||
| 36 | static QQuickItemGrabResult *create(QQuickItem *item, const QSize &size); | - | ||||||||||||
| 37 | - | |||||||||||||
| 38 | QImage image; | - | ||||||||||||
| 39 | - | |||||||||||||
| 40 | mutable QUrl url; | - | ||||||||||||
| 41 | mutable QQuickPixmap *cacheEntry; | - | ||||||||||||
| 42 | - | |||||||||||||
| 43 | QQmlEngine *qmlEngine; | - | ||||||||||||
| 44 | QJSValue callback; | - | ||||||||||||
| 45 | - | |||||||||||||
| 46 | QPointer<QQuickItem> item; | - | ||||||||||||
| 47 | QPointer<QQuickWindow> window; | - | ||||||||||||
| 48 | QSGLayer *texture; | - | ||||||||||||
| 49 | QSizeF itemSize; | - | ||||||||||||
| 50 | QSize textureSize; | - | ||||||||||||
| 51 | }; | - | ||||||||||||
| 52 | QQuickItemGrabResult::QQuickItemGrabResult(QObject *parent) | - | ||||||||||||
| 53 | : QObject(*new QQuickItemGrabResultPrivate, parent) | - | ||||||||||||
| 54 | { | - | ||||||||||||
| 55 | } executed 8 times by 2 tests: end of blockExecuted by:
| 8 | ||||||||||||
| 56 | bool QQuickItemGrabResult::saveToFile(const QString &fileName) const | - | ||||||||||||
| 57 | { | - | ||||||||||||
| 58 | const QQuickItemGrabResultPrivate * const d = d_func(); | - | ||||||||||||
| 59 | return never executed: d->image.save(fileName);return d->image.save(fileName);never executed: return d->image.save(fileName); | 0 | ||||||||||||
| 60 | } | - | ||||||||||||
| 61 | - | |||||||||||||
| 62 | - | |||||||||||||
| 63 | - | |||||||||||||
| 64 | - | |||||||||||||
| 65 | - | |||||||||||||
| 66 | - | |||||||||||||
| 67 | bool QQuickItemGrabResult::saveToFile(const QString &fileName) | - | ||||||||||||
| 68 | { | - | ||||||||||||
| 69 | return never executed: qAsConst(*this).saveToFile(fileName);return qAsConst(*this).saveToFile(fileName);never executed: return qAsConst(*this).saveToFile(fileName); | 0 | ||||||||||||
| 70 | } | - | ||||||||||||
| 71 | - | |||||||||||||
| 72 | - | |||||||||||||
| 73 | QUrl QQuickItemGrabResult::url() const | - | ||||||||||||
| 74 | { | - | ||||||||||||
| 75 | const QQuickItemGrabResultPrivate * const d = d_func(); | - | ||||||||||||
| 76 | d->ensureImageInCache(); | - | ||||||||||||
| 77 | return executed 4 times by 1 test: d->url;return d->url;Executed by:
executed 4 times by 1 test: return d->url;Executed by:
| 4 | ||||||||||||
| 78 | } | - | ||||||||||||
| 79 | - | |||||||||||||
| 80 | QImage QQuickItemGrabResult::image() const | - | ||||||||||||
| 81 | { | - | ||||||||||||
| 82 | const QQuickItemGrabResultPrivate * const d = d_func(); | - | ||||||||||||
| 83 | return executed 28 times by 2 tests: d->image;return d->image;Executed by:
executed 28 times by 2 tests: return d->image;Executed by:
| 28 | ||||||||||||
| 84 | } | - | ||||||||||||
| 85 | - | |||||||||||||
| 86 | - | |||||||||||||
| 87 | - | |||||||||||||
| 88 | - | |||||||||||||
| 89 | bool QQuickItemGrabResult::event(QEvent *e) | - | ||||||||||||
| 90 | { | - | ||||||||||||
| 91 | QQuickItemGrabResultPrivate * const d = d_func(); | - | ||||||||||||
| 92 | if (e->type() == Event_Grab_Completed
| 0-6 | ||||||||||||
| 93 | - | |||||||||||||
| 94 | if (d->qmlEngine
| 0-6 | ||||||||||||
| 95 | d->callback.call(QJSValueList() << d->qmlEngine->newQObject(this)); never executed: d->callback.call(QJSValueList() << d->qmlEngine->newQObject(this)); | 0 | ||||||||||||
| 96 | else | - | ||||||||||||
| 97 | ready(); executed 6 times by 2 tests: ready();Executed by:
| 6 | ||||||||||||
| 98 | return executed 6 times by 2 tests: true;return true;Executed by:
executed 6 times by 2 tests: return true;Executed by:
| 6 | ||||||||||||
| 99 | } | - | ||||||||||||
| 100 | return never executed: QObject::event(e);return QObject::event(e);never executed: return QObject::event(e); | 0 | ||||||||||||
| 101 | } | - | ||||||||||||
| 102 | - | |||||||||||||
| 103 | void QQuickItemGrabResult::setup() | - | ||||||||||||
| 104 | { | - | ||||||||||||
| 105 | QQuickItemGrabResultPrivate * const d = d_func(); | - | ||||||||||||
| 106 | if (!d->item
| 0-8 | ||||||||||||
| 107 | disconnect(d->window.data(), &QQuickWindow::beforeSynchronizing, this, &QQuickItemGrabResult::setup); | - | ||||||||||||
| 108 | disconnect(d->window.data(), &QQuickWindow::afterRendering, this, &QQuickItemGrabResult::render); | - | ||||||||||||
| 109 | QCoreApplication::postEvent(this, new QEvent(Event_Grab_Completed)); | - | ||||||||||||
| 110 | return; never executed: return; | 0 | ||||||||||||
| 111 | } | - | ||||||||||||
| 112 | - | |||||||||||||
| 113 | QSGRenderContext *rc = QQuickWindowPrivate::get(d->window.data())->context; | - | ||||||||||||
| 114 | d->texture = rc->sceneGraphContext()->createLayer(rc); | - | ||||||||||||
| 115 | d->texture->setItem(QQuickItemPrivate::get(d->item)->itemNode()); | - | ||||||||||||
| 116 | d->itemSize = QSizeF(d->item->width(), d->item->height()); | - | ||||||||||||
| 117 | } executed 8 times by 2 tests: end of blockExecuted by:
| 8 | ||||||||||||
| 118 | - | |||||||||||||
| 119 | void QQuickItemGrabResult::render() | - | ||||||||||||
| 120 | { | - | ||||||||||||
| 121 | QQuickItemGrabResultPrivate * const d = d_func(); | - | ||||||||||||
| 122 | if (!d->texture
| 0-8 | ||||||||||||
| 123 | return; never executed: return; | 0 | ||||||||||||
| 124 | - | |||||||||||||
| 125 | d->texture->setRect(QRectF(0, d->itemSize.height(), d->itemSize.width(), -d->itemSize.height())); | - | ||||||||||||
| 126 | const QSize minSize = QQuickWindowPrivate::get(d->window.data())->context->sceneGraphContext()->minimumFBOSize(); | - | ||||||||||||
| 127 | d->texture->setSize(QSize(qMax(minSize.width(), d->textureSize.width()), | - | ||||||||||||
| 128 | qMax(minSize.height(), d->textureSize.height()))); | - | ||||||||||||
| 129 | d->texture->scheduleUpdate(); | - | ||||||||||||
| 130 | d->texture->updateTexture(); | - | ||||||||||||
| 131 | d->image = d->texture->toImage(); | - | ||||||||||||
| 132 | - | |||||||||||||
| 133 | delete d->texture; | - | ||||||||||||
| 134 | d->texture = nullptr; | - | ||||||||||||
| 135 | - | |||||||||||||
| 136 | disconnect(d->window.data(), &QQuickWindow::beforeSynchronizing, this, &QQuickItemGrabResult::setup); | - | ||||||||||||
| 137 | disconnect(d->window.data(), &QQuickWindow::afterRendering, this, &QQuickItemGrabResult::render); | - | ||||||||||||
| 138 | QCoreApplication::postEvent(this, new QEvent(Event_Grab_Completed)); | - | ||||||||||||
| 139 | } executed 8 times by 2 tests: end of blockExecuted by:
| 8 | ||||||||||||
| 140 | - | |||||||||||||
| 141 | QQuickItemGrabResult *QQuickItemGrabResultPrivate::create(QQuickItem *item, const QSize &targetSize) | - | ||||||||||||
| 142 | { | - | ||||||||||||
| 143 | QSize size = targetSize; | - | ||||||||||||
| 144 | if (size.isEmpty()
| 2-6 | ||||||||||||
| 145 | size = QSize(item->width(), item->height()); executed 6 times by 2 tests: size = QSize(item->width(), item->height());Executed by:
| 6 | ||||||||||||
| 146 | - | |||||||||||||
| 147 | if (size.width() < 1
| 0-8 | ||||||||||||
| 148 | qmlWarning(item) << "grabToImage: item has invalid dimensions"; | - | ||||||||||||
| 149 | return never executed: nullptr;return nullptr;never executed: return nullptr; | 0 | ||||||||||||
| 150 | } | - | ||||||||||||
| 151 | - | |||||||||||||
| 152 | if (!item->window()
| 0-8 | ||||||||||||
| 153 | qmlWarning(item) << "grabToImage: item is not attached to a window"; | - | ||||||||||||
| 154 | return never executed: nullptr;return nullptr;never executed: return nullptr; | 0 | ||||||||||||
| 155 | } | - | ||||||||||||
| 156 | - | |||||||||||||
| 157 | if (!item->window()->isVisible()
| 0-8 | ||||||||||||
| 158 | qmlWarning(item) << "grabToImage: item's window is not visible"; | - | ||||||||||||
| 159 | return never executed: nullptr;return nullptr;never executed: return nullptr; | 0 | ||||||||||||
| 160 | } | - | ||||||||||||
| 161 | - | |||||||||||||
| 162 | QQuickItemGrabResult *result = new QQuickItemGrabResult(); | - | ||||||||||||
| 163 | QQuickItemGrabResultPrivate *d = result->d_func(); | - | ||||||||||||
| 164 | d->item = item; | - | ||||||||||||
| 165 | d->window = item->window(); | - | ||||||||||||
| 166 | d->textureSize = size; | - | ||||||||||||
| 167 | - | |||||||||||||
| 168 | QQuickItemPrivate::get(item)->refFromEffectItem(false); | - | ||||||||||||
| 169 | - | |||||||||||||
| 170 | - | |||||||||||||
| 171 | item->window()->update(); | - | ||||||||||||
| 172 | - | |||||||||||||
| 173 | return executed 8 times by 2 tests: result;return result;Executed by:
executed 8 times by 2 tests: return result;Executed by:
| 8 | ||||||||||||
| 174 | } | - | ||||||||||||
| 175 | QSharedPointer<QQuickItemGrabResult> QQuickItem::grabToImage(const QSize &targetSize) | - | ||||||||||||
| 176 | { | - | ||||||||||||
| 177 | QQuickItemGrabResult *result = QQuickItemGrabResultPrivate::create(this, targetSize); | - | ||||||||||||
| 178 | if (!result
| 0-8 | ||||||||||||
| 179 | return never executed: QSharedPointer<QQuickItemGrabResult>();return QSharedPointer<QQuickItemGrabResult>();never executed: return QSharedPointer<QQuickItemGrabResult>(); | 0 | ||||||||||||
| 180 | - | |||||||||||||
| 181 | connect(window(), &QQuickWindow::beforeSynchronizing, result, &QQuickItemGrabResult::setup, Qt::DirectConnection); | - | ||||||||||||
| 182 | connect(window(), &QQuickWindow::afterRendering, result, &QQuickItemGrabResult::render, Qt::DirectConnection); | - | ||||||||||||
| 183 | - | |||||||||||||
| 184 | return executed 8 times by 2 tests: QSharedPointer<QQuickItemGrabResult>(result);return QSharedPointer<QQuickItemGrabResult>(result);Executed by:
executed 8 times by 2 tests: return QSharedPointer<QQuickItemGrabResult>(result);Executed by:
| 8 | ||||||||||||
| 185 | } | - | ||||||||||||
| 186 | bool QQuickItem::grabToImage(const QJSValue &callback, const QSize &targetSize) | - | ||||||||||||
| 187 | { | - | ||||||||||||
| 188 | QQmlEngine *engine = qmlEngine(this); | - | ||||||||||||
| 189 | if (!engine
| 0 | ||||||||||||
| 190 | qmlWarning(this) << "grabToImage: item has no QML engine"; | - | ||||||||||||
| 191 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||
| 192 | } | - | ||||||||||||
| 193 | - | |||||||||||||
| 194 | if (!callback.isCallable()
| 0 | ||||||||||||
| 195 | qmlWarning(this) << "grabToImage: 'callback' is not a function"; | - | ||||||||||||
| 196 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||
| 197 | } | - | ||||||||||||
| 198 | - | |||||||||||||
| 199 | QSize size = targetSize; | - | ||||||||||||
| 200 | if (size.isEmpty()
| 0 | ||||||||||||
| 201 | size = QSize(width(), height()); never executed: size = QSize(width(), height()); | 0 | ||||||||||||
| 202 | - | |||||||||||||
| 203 | if (size.width() < 1
| 0 | ||||||||||||
| 204 | qmlWarning(this) << "grabToImage: item has invalid dimensions"; | - | ||||||||||||
| 205 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||
| 206 | } | - | ||||||||||||
| 207 | - | |||||||||||||
| 208 | if (!window()
| 0 | ||||||||||||
| 209 | qmlWarning(this) << "grabToImage: item is not attached to a window"; | - | ||||||||||||
| 210 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||
| 211 | } | - | ||||||||||||
| 212 | - | |||||||||||||
| 213 | QQuickItemGrabResult *result = QQuickItemGrabResultPrivate::create(this, size); | - | ||||||||||||
| 214 | if (!result
| 0 | ||||||||||||
| 215 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||
| 216 | - | |||||||||||||
| 217 | connect(window(), &QQuickWindow::beforeSynchronizing, result, &QQuickItemGrabResult::setup, Qt::DirectConnection); | - | ||||||||||||
| 218 | connect(window(), &QQuickWindow::afterRendering, result, &QQuickItemGrabResult::render, Qt::DirectConnection); | - | ||||||||||||
| 219 | - | |||||||||||||
| 220 | QQuickItemGrabResultPrivate *d = result->d_func(); | - | ||||||||||||
| 221 | d->qmlEngine = engine; | - | ||||||||||||
| 222 | d->callback = callback; | - | ||||||||||||
| 223 | return never executed: true;return true;never executed: return true; | 0 | ||||||||||||
| 224 | } | - | ||||||||||||
| 225 | - | |||||||||||||
| 226 | - | |||||||||||||
| 227 | - | |||||||||||||
| Switch to Source code | Preprocessed file |