1/****************************************************************************
2**
3** Copyright (C) 2017 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 "qscene2d.h"
38#include "qscene2d_p.h"
39#include "scene2d_p.h"
40#include "scene2dmanager_p.h"
41#include "scene2devent_p.h"
42#include "scene2dsharedobject_p.h"
43
44QT_BEGIN_NAMESPACE
45
46using namespace Qt3DCore;
47
48namespace Qt3DRender {
49
50namespace Quick {
51
52
53/*!
54 \internal
55 Constructs object shared by the front-end and back-end to synchronize the rendering.
56 */
57Scene2DSharedObject::Scene2DSharedObject(Scene2DManager *manager)
58 : m_renderControl(nullptr)
59 , m_quickWindow(nullptr)
60 , m_renderManager(manager)
61 , m_surface(nullptr)
62 , m_renderThread(nullptr)
63 , m_renderObject(nullptr)
64 , m_disallowed(false)
65 , m_quit(false)
66 , m_requestSync(false)
67 , m_prepared(false)
68 , m_initialized(false)
69{
70}
71
72Scene2DSharedObject::~Scene2DSharedObject()
73{
74}
75
76void Scene2DSharedObject::cleanup()
77{
78 delete m_renderControl;
79 delete m_quickWindow;
80 delete m_surface;
81 m_renderControl = nullptr;
82 m_quickWindow = nullptr;
83 m_surface = nullptr;
84 m_initialized = false;
85}
86
87bool Scene2DSharedObject::canRender() const
88{
89 return m_initialized && m_prepared && !m_disallowed;
90}
91
92bool Scene2DSharedObject::isInitialized() const
93{
94 return m_initialized;
95}
96
97void Scene2DSharedObject::disallowRender()
98{
99 m_disallowed = true;
100}
101
102void Scene2DSharedObject::setInitialized()
103{
104 m_initialized = true;
105}
106
107bool Scene2DSharedObject::isPrepared() const
108{
109 return m_prepared;
110}
111
112void Scene2DSharedObject::setPrepared()
113{
114 m_prepared = true;
115}
116
117// not protected, call only from main thread
118bool Scene2DSharedObject::isQuit() const
119{
120 Q_ASSERT(QThread::currentThread() == QCoreApplication::instance()->thread());
121 return m_quit;
122}
123
124// not protected, call only from main thread
125void Scene2DSharedObject::requestQuit()
126{
127 Q_ASSERT(QThread::currentThread() == QCoreApplication::instance()->thread());
128 m_quit = true;
129 QCoreApplication::postEvent(receiver: m_renderObject, event: new Scene2DEvent(Scene2DEvent::Quit));
130}
131
132bool Scene2DSharedObject::isSyncRequested() const
133{
134 return m_requestSync;
135}
136
137void Scene2DSharedObject::requestRender(bool sync)
138{
139 m_requestSync = sync;
140 QCoreApplication::postEvent(receiver: m_renderObject, event: new Scene2DEvent(Scene2DEvent::Render));
141}
142
143void Scene2DSharedObject::wait()
144{
145 m_cond.wait(lockedMutex: &m_mutex);
146}
147
148void Scene2DSharedObject::wake()
149{
150 m_cond.wakeOne();
151}
152
153void Scene2DSharedObject::clearSyncRequest()
154{
155 m_requestSync = false;
156}
157
158} // namespace Quick
159} // namespace Qt3DRender
160
161QT_END_NAMESPACE
162

source code of qt3d/src/quick3d/quick3dscene2d/items/scene2dsharedobject.cpp