Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquickwindow_p.h
Go to the documentation of this file.
1// Copyright (C) 2020 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// Qt-Security score:significant reason:default
4
5#ifndef QQUICKWINDOW_P_H
6#define QQUICKWINDOW_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtQuick/private/qquickdeliveryagent_p_p.h>
20#include <QtQuick/private/qquickevents_p_p.h>
21#include <QtQuick/private/qsgcontext_p.h>
22#include <QtQuick/private/qquickpaletteproviderprivatebase_p.h>
23#include <QtQuick/private/qquickrendertarget_p.h>
24#include <QtQuick/private/qquickgraphicsdevice_p.h>
25#include <QtQuick/private/qquickgraphicsconfiguration_p.h>
26#include <QtQuick/qquickitem.h>
27#include <QtQuick/qquickwindow.h>
28
29#include <QtCore/qthread.h>
30#include <QtCore/qmutex.h>
31#include <QtCore/qwaitcondition.h>
32#include <QtCore/qrunnable.h>
33#include <QtCore/qstack.h>
34
35#include <QtGui/private/qevent_p.h>
36#include <QtGui/private/qpointingdevice_p.h>
37#include <QtGui/private/qwindow_p.h>
38#include <QtGui/qevent.h>
39#include <QtGui/qstylehints.h>
40#include <QtGui/qguiapplication.h>
41
42QT_BEGIN_NAMESPACE
43
44class QOpenGLContext;
45class QQuickAnimatorController;
47class QQuickItemPrivate;
48class QPointingDevice;
49class QQuickRenderControl;
51class QQuickWindowPrivate;
52class QSGRenderLoop;
53class QTouchEvent;
54class QRhi;
55class QRhiSwapChain;
56class QRhiRenderBuffer;
57class QRhiRenderPassDescriptor;
58class QRhiTexture;
59
60Q_DECLARE_LOGGING_CATEGORY(lcQuickWindow)
61
62//Make it easy to identify and customize the root item if needed
63class Q_QUICK_EXPORT QQuickRootItem : public QQuickItem
64{
65 Q_OBJECT
66 QML_ANONYMOUS
67 QML_ADDED_IN_VERSION(2, 0)
68public:
69 QQuickRootItem();
70
71public Q_SLOTS:
72 void setWidth(int w) {QQuickItem::setWidth(qreal(w));}
73 void setHeight(int h) {QQuickItem::setHeight(qreal(h));}
74};
75
77{
78 enum class ResetFlag {
80 };
81 Q_DECLARE_FLAGS(ResetFlags, ResetFlag)
82 void reset(QRhi *rhi, ResetFlags flags = {});
83
84 struct {
86 bool owns = false;
88 } rt;
89 struct {
90 QRhiTexture *texture = nullptr;
91 QRhiRenderBuffer *renderBuffer = nullptr;
92 QRhiRenderPassDescriptor *rpDesc = nullptr;
93 } res;
95 QRhiRenderBuffer *depthStencil = nullptr;
96 QRhiTexture *depthStencilTexture = nullptr;
97 QRhiTexture *multisampleTexture = nullptr;
98 void reset(QRhi *rhi);
99 } implicitBuffers;
100 struct {
102 bool owns = false;
103 } sw;
104};
105
106Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickWindowRenderTarget::ResetFlags)
107
108class Q_QUICK_EXPORT QQuickWindowPrivate
109 : public QWindowPrivate
110 , public QQuickPaletteProviderPrivateBase<QQuickWindow, QQuickWindowPrivate>
111{
112public:
113 Q_DECLARE_PUBLIC(QQuickWindow)
114
115 enum CustomEvents {
116 FullUpdateRequest = QEvent::User + 1,
117 TriggerContextCreationFailure = QEvent::User + 2
118 };
119
120 static inline QQuickWindowPrivate *get(QQuickWindow *c) { return c->d_func(); }
121 static inline const QQuickWindowPrivate *get(const QQuickWindow *c) { return c->d_func(); }
122
123 QQuickWindowPrivate();
124 ~QQuickWindowPrivate() override;
125
126 void setPalette(QQuickPalette *p) override;
127 void updateWindowPalette();
128 void updateChildrenPalettes(const QPalette &parentPalette) override;
129
130 void init(QQuickWindow *, QQuickRenderControl *control = nullptr);
131
132 QQuickRootItem *contentItem;
133 QSet<QQuickItem *> parentlessItems;
134 QQmlListProperty<QObject> data();
135
136 // primary delivery agent for the whole scene, used by default for events that arrive in this window;
137 // but any subscene root can have a QQuickItemPrivate::ExtraData::subsceneDeliveryAgent
138 QQuickDeliveryAgent *deliveryAgent = nullptr;
139 QQuickDeliveryAgentPrivate *deliveryAgentPrivate() const
140 { return deliveryAgent ? static_cast<QQuickDeliveryAgentPrivate *>(QQuickDeliveryAgentPrivate::get(deliveryAgent)) : nullptr; }
141
142#if QT_CONFIG(cursor)
143 QQuickItem *cursorItem = nullptr;
144 QQuickPointerHandler *cursorHandler = nullptr;
145 void updateCursor(const QPointF &scenePos, QQuickItem *rootItem = nullptr);
146 std::pair<QQuickItem*, QQuickPointerHandler*> findCursorItemAndHandler(QQuickItem *item,
147 const QPointF &localPos, const QPointF &scenePos) const;
148#endif
149
150 void clearFocusObject() override;
151 void setFocusToTarget(FocusTarget, Qt::FocusReason) override;
152
153 void maybeSynthesizeContextMenuEvent(QMouseEvent *event) override;
154
155 void dirtyItem(QQuickItem *);
156 void cleanup(QSGNode *);
157
158 void ensureCustomRenderTarget();
159 void setCustomCommandBuffer(QRhiCommandBuffer *cb);
160
161 void polishItems();
162 void forcePolish();
163 void invalidateFontData(QQuickItem *item);
164 void syncSceneGraph();
165 void renderSceneGraph();
166
167 bool isRenderable() const;
168
169 bool emitError(QQuickWindow::SceneGraphError error, const QString &msg);
170
171 enum TextureFromNativeTextureFlag {
172 NativeTextureIsExternalOES = 0x01
173 };
174 Q_DECLARE_FLAGS(TextureFromNativeTextureFlags, TextureFromNativeTextureFlag)
175
176 QSGTexture *createTextureFromNativeTexture(quint64 nativeObjectHandle,
177 int nativeLayoutOrState,
178 uint nativeFormat,
179 const QSize &size,
180 QQuickWindow::CreateTextureOptions options,
181 TextureFromNativeTextureFlags flags = {}) const;
182 QSGTexture *createTextureFromNativeTexture(quint64 nativeObjectHandle,
183 int nativeLayoutOrState,
184 const QSize &size,
185 QQuickWindow::CreateTextureOptions options,
186 TextureFromNativeTextureFlags flags = {}) const {
187 return createTextureFromNativeTexture(nativeObjectHandle, nativeLayoutOrState, 0, size, options, flags);
188 }
189
190 QQuickItem::UpdatePaintNodeData updatePaintNodeData;
191
192 QQuickItem *dirtyItemList;
193 QList<QSGNode *> cleanupNodeList;
194
195 QList<QQuickItem *> itemsToPolish;
196
197 qreal lastReportedItemDevicePixelRatio;
198 QMetaObject::Connection physicalDpiChangedConnection;
199 std::array<QMetaObject::Connection, 7> connections;
200
201 void updateDirtyNodes();
202 void cleanupNodes();
203 void cleanupNodesOnShutdown();
204 bool updateEffectiveOpacity(QQuickItem *);
205 void updateEffectiveOpacityRoot(QQuickItem *, qreal);
206 void updateDirtyNode(QQuickItem *);
207
208 void fireFrameSwapped() { Q_EMIT q_func()->frameSwapped(); }
209 void fireAboutToStop() { Q_EMIT q_func()->sceneGraphAboutToStop(); }
210
211 bool needsChildWindowStackingOrderUpdate = false;
212 void updateChildWindowStackingOrder(QQuickItem *item = nullptr);
213
214 int multiViewCount();
215 QRhiRenderTarget *activeCustomRhiRenderTarget();
216
217 QSGRenderContext *context;
218 QSGRenderer *renderer;
219 QByteArray visualizationMode; // Default renderer supports "clip", "overdraw", "changes", "batches" and blank.
220
221 QSGRenderLoop *windowManager;
222 QQuickRenderControl *renderControl;
223 QScopedPointer<QQuickAnimatorController> animationController;
224
225 QColor clearColor;
226
227 uint persistentGraphics : 1;
228 uint persistentSceneGraph : 1;
229 uint inDestructor : 1;
230
231 // Storage for setRenderTarget(QQuickRenderTarget).
232 // Gets baked into redirect.renderTarget by ensureCustomRenderTarget() when rendering the next frame.
233 QQuickRenderTarget customRenderTarget;
234
235 struct Redirect {
236 QRhiCommandBuffer *commandBuffer = nullptr;
237 QQuickWindowRenderTarget rt;
238 bool renderTargetDirty = false;
239 } redirect;
240
241 QQuickGraphicsDevice customDeviceObjects;
242
243 QQuickGraphicsConfiguration graphicsConfig;
244
245 mutable QQuickWindowIncubationController *incubationController;
246
247 static bool defaultAlphaBuffer;
248 static QQuickWindow::TextRenderType textRenderType;
249
250 // data property
251 static void data_append(QQmlListProperty<QObject> *, QObject *);
252 static qsizetype data_count(QQmlListProperty<QObject> *);
253 static QObject *data_at(QQmlListProperty<QObject> *, qsizetype);
254 static void data_clear(QQmlListProperty<QObject> *);
255 static void data_removeLast(QQmlListProperty<QObject> *);
256
257 static void rhiCreationFailureMessage(const QString &backendName,
258 QString *translatedMessage,
259 QString *untranslatedMessage);
260
261 static void emitBeforeRenderPassRecording(void *ud);
262 static void emitAfterRenderPassRecording(void *ud);
263
264 QMutex renderJobMutex;
265 QList<QRunnable *> beforeSynchronizingJobs;
266 QList<QRunnable *> afterSynchronizingJobs;
267 QList<QRunnable *> beforeRenderingJobs;
268 QList<QRunnable *> afterRenderingJobs;
269 QList<QRunnable *> afterSwapJobs;
270
271 void runAndClearJobs(QList<QRunnable *> *jobs);
272 QOpenGLContext *openglContext();
273
274 QQuickWindow::GraphicsStateInfo rhiStateInfo;
275 QRhi *rhi = nullptr;
276 QRhiSwapChain *swapchain = nullptr;
277 QRhiRenderBuffer *depthStencilForSwapchain = nullptr;
278 QRhiRenderPassDescriptor *rpDescForSwapchain = nullptr;
279 uint hasActiveSwapchain : 1;
280 uint hasRenderableSwapchain : 1;
281 uint swapchainJustBecameRenderable : 1;
282 uint updatesEnabled : 1;
283 bool pendingFontUpdate = false;
284 bool windowEventDispatch = false;
285 bool rmbContextMenuEventEnabled = false; // true after right-mouse press, false when menu opened
286 QPointer<QQuickPalette> windowPaletteRef;
287
288private:
289 static void cleanupNodesOnShutdown(QQuickItem *);
290};
291
293{
294public:
296 void run() override { delete object; }
298 static void schedule(QQuickWindow *window, QObject *object) {
299 Q_ASSERT(window);
300 Q_ASSERT(object);
301 window->scheduleRenderJob(new QQuickWindowQObjectCleanupJob(object), QQuickWindow::AfterSynchronizingStage);
302 }
303};
304
305Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickWindowPrivate::TextureFromNativeTextureFlags)
306
307QT_END_NAMESPACE
308
309#endif // QQUICKWINDOW_P_H
bool contains(const QPointF &point) const override
QQuickFlickableContentItem(QQuickItem *parent=nullptr)
bool startTransition(QQuickFlickablePrivate::AxisData *data, qreal toPos)
QQuickFlickableReboundTransition(QQuickFlickable *f, const QString &name)
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:64
void run() override
Implement this pure virtual function in your subclass.
static void schedule(QQuickWindow *window, QObject *object)
\qmltype Window \nativetype QQuickWindow \inqmlmodule QtQuick
Combined button and popup list for selecting options.
QDebug operator<<(QDebug dbg, const NSObject *nsObject)
Definition qcore_mac.mm:207
QT_BEGIN_NAMESPACE Q_STATIC_LOGGING_CATEGORY(lcSynthesizedIterableAccess, "qt.iterable.synthesized", QtWarningMsg)
static bool fuzzyLessThanOrEqualTo(qreal a, qreal b)
static qreal EaseOvershoot(qreal t)
const qreal _q_MaximumWheelDeceleration
#define QML_FLICK_SAMPLEBUFFER
#define QML_FLICK_OVERSHOOT
#define QML_FLICK_MULTIFLICK_MAXBOOST
#define QML_FLICK_MULTIFLICK_THRESHOLD
#define QML_FLICK_OVERSHOOTFRICTION
#define QML_FLICK_DISCARDSAMPLES
#define QML_FLICK_MULTIFLICK_RATIO
QDebug Q_QUICK_EXPORT operator<<(QDebug debug, const QQuickWindow *item)
QRhiRenderPassDescriptor * rpDesc
QRhiRenderBuffer * renderBuffer
QRhiRenderTarget * renderTarget