1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qscene2d.h"
5#include "qscene2d_p.h"
6#include "scene2d_p.h"
7#include "scene2dmanager_p.h"
8#include "scene2devent_p.h"
9#include "scene2dsharedobject_p.h"
10
11QT_BEGIN_NAMESPACE
12
13using namespace Qt3DCore;
14
15namespace Qt3DRender {
16
17namespace Quick {
18
19
20/*!
21 \internal
22 Constructs object shared by the front-end and back-end to synchronize the rendering.
23 */
24Scene2DSharedObject::Scene2DSharedObject(Scene2DManager *manager)
25 : m_renderControl(nullptr)
26 , m_quickWindow(nullptr)
27 , m_renderManager(manager)
28 , m_surface(nullptr)
29 , m_renderThread(nullptr)
30 , m_renderObject(nullptr)
31 , m_disallowed(false)
32 , m_quit(false)
33 , m_requestSync(false)
34 , m_prepared(false)
35 , m_initialized(false)
36{
37}
38
39Scene2DSharedObject::~Scene2DSharedObject()
40{
41}
42
43void Scene2DSharedObject::cleanup()
44{
45 delete m_renderControl;
46 delete m_quickWindow;
47 delete m_surface;
48 m_renderControl = nullptr;
49 m_quickWindow = nullptr;
50 m_surface = nullptr;
51 m_initialized = false;
52}
53
54bool Scene2DSharedObject::canRender() const
55{
56 return m_initialized && m_prepared && !m_disallowed;
57}
58
59bool Scene2DSharedObject::isInitialized() const
60{
61 return m_initialized;
62}
63
64void Scene2DSharedObject::disallowRender()
65{
66 m_disallowed = true;
67}
68
69void Scene2DSharedObject::setInitialized()
70{
71 m_initialized = true;
72}
73
74bool Scene2DSharedObject::isPrepared() const
75{
76 return m_prepared;
77}
78
79void Scene2DSharedObject::setPrepared()
80{
81 m_prepared = true;
82}
83
84// not protected, call only from main thread
85bool Scene2DSharedObject::isQuit() const
86{
87 Q_ASSERT(QThread::currentThread() == QCoreApplication::instance()->thread());
88 return m_quit;
89}
90
91// not protected, call only from main thread
92void Scene2DSharedObject::requestQuit()
93{
94 Q_ASSERT(QThread::currentThread() == QCoreApplication::instance()->thread());
95 m_quit = true;
96 QCoreApplication::postEvent(receiver: m_renderObject, event: new Scene2DEvent(Scene2DEvent::Quit));
97}
98
99bool Scene2DSharedObject::isSyncRequested() const
100{
101 return m_requestSync;
102}
103
104void Scene2DSharedObject::requestRender(bool sync)
105{
106 m_requestSync = sync;
107 QCoreApplication::postEvent(receiver: m_renderObject, event: new Scene2DEvent(Scene2DEvent::Render));
108}
109
110void Scene2DSharedObject::wait()
111{
112 m_cond.wait(lockedMutex: &m_mutex);
113}
114
115void Scene2DSharedObject::wake()
116{
117 m_cond.wakeOne();
118}
119
120void Scene2DSharedObject::clearSyncRequest()
121{
122 m_requestSync = false;
123}
124
125} // namespace Quick
126} // namespace Qt3DRender
127
128QT_END_NAMESPACE
129

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