| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: http://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the Qt3D module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL3$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at http://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or later as published by the Free |
| 28 | ** Software Foundation and appearing in the file LICENSE.GPL included in |
| 29 | ** the packaging of this file. Please review the following information to |
| 30 | ** ensure the GNU General Public License version 2.0 requirements will be |
| 31 | ** met: http://www.gnu.org/licenses/gpl-2.0.html. |
| 32 | ** |
| 33 | ** $QT_END_LICENSE$ |
| 34 | ** |
| 35 | ****************************************************************************/ |
| 36 | |
| 37 | #include <Qt3DRender/private/qrendercapture_p.h> |
| 38 | #include <Qt3DRender/private/rendercapture_p.h> |
| 39 | #include <Qt3DCore/qpropertyupdatedchange.h> |
| 40 | #include <Qt3DCore/private/qaspectmanager_p.h> |
| 41 | #include <Qt3DCore/private/qaspectjobmanager_p.h> |
| 42 | |
| 43 | QT_BEGIN_NAMESPACE |
| 44 | |
| 45 | namespace Qt3DRender { |
| 46 | |
| 47 | namespace Render { |
| 48 | |
| 49 | RenderCapture::RenderCapture() |
| 50 | : FrameGraphNode(FrameGraphNode::RenderCapture, QBackendNode::ReadWrite) |
| 51 | { |
| 52 | |
| 53 | } |
| 54 | |
| 55 | void RenderCapture::requestCapture(const QRenderCaptureRequest &request) |
| 56 | { |
| 57 | QMutexLocker lock(&m_mutex); |
| 58 | m_requestedCaptures.push_back(t: request); |
| 59 | } |
| 60 | |
| 61 | // called by render view initializer job |
| 62 | bool RenderCapture::wasCaptureRequested() const |
| 63 | { |
| 64 | QMutexLocker lock(&m_mutex); |
| 65 | return m_requestedCaptures.size() > 0 && isEnabled(); |
| 66 | } |
| 67 | |
| 68 | // called by render view initializer job |
| 69 | QRenderCaptureRequest RenderCapture::takeCaptureRequest() |
| 70 | { |
| 71 | Q_ASSERT(!m_requestedCaptures.isEmpty()); |
| 72 | return m_requestedCaptures.takeFirst(); |
| 73 | } |
| 74 | |
| 75 | void RenderCapture::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) |
| 76 | { |
| 77 | const QRenderCapture *node = qobject_cast<const QRenderCapture *>(object: frontEnd); |
| 78 | if (!node) |
| 79 | return; |
| 80 | |
| 81 | FrameGraphNode::syncFromFrontEnd(frontEnd, firstTime); |
| 82 | |
| 83 | const QRenderCapturePrivate *d = static_cast<const QRenderCapturePrivate *>(QFrameGraphNodePrivate::get(node)); |
| 84 | const auto newPendingsCaptures = std::move(d->m_pendingRequests); |
| 85 | if (newPendingsCaptures.size() > 0) { |
| 86 | m_requestedCaptures.append(l: newPendingsCaptures); |
| 87 | markDirty(changes: AbstractRenderer::FrameGraphDirty); |
| 88 | } |
| 89 | |
| 90 | if (firstTime) |
| 91 | markDirty(changes: AbstractRenderer::FrameGraphDirty); |
| 92 | } |
| 93 | |
| 94 | // called by render thread |
| 95 | void RenderCapture::addRenderCapture(int captureId, const QImage &image) |
| 96 | { |
| 97 | QMutexLocker lock(&m_mutex); |
| 98 | auto data = RenderCaptureDataPtr::create(); |
| 99 | data.data()->captureId = captureId; |
| 100 | data.data()->image = image; |
| 101 | m_renderCaptureData.push_back(t: data); |
| 102 | } |
| 103 | |
| 104 | // called to send render capture in main thread |
| 105 | void RenderCapture::syncRenderCapturesToFrontend(Qt3DCore::QAspectManager *manager) |
| 106 | { |
| 107 | auto *frontend = manager->lookupNode(id: peerId()); |
| 108 | if (!frontend) |
| 109 | return; |
| 110 | QRenderCapturePrivate *dfrontend = static_cast<QRenderCapturePrivate *>(Qt3DCore::QNodePrivate::get(q: frontend)); |
| 111 | |
| 112 | QMutexLocker lock(&m_mutex); |
| 113 | for (const RenderCaptureDataPtr &data : qAsConst(t&: m_renderCaptureData)) { |
| 114 | QPointer<QRenderCaptureReply> reply = dfrontend->takeReply(captureId: data.data()->captureId); |
| 115 | // Note: QPointer has no operator bool, we must use isNull() to check it |
| 116 | if (!reply.isNull()) { |
| 117 | dfrontend->setImage(reply, image: data.data()->image); |
| 118 | emit reply->completed(); |
| 119 | QT_WARNING_PUSH |
| 120 | QT_WARNING_DISABLE_DEPRECATED |
| 121 | emit reply->completeChanged(isComplete: true); |
| 122 | QT_WARNING_POP |
| 123 | } |
| 124 | } |
| 125 | m_renderCaptureData.clear(); |
| 126 | } |
| 127 | |
| 128 | } // Render |
| 129 | |
| 130 | } // Qt3DRender |
| 131 | |
| 132 | QT_END_NAMESPACE |
| 133 | |