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, const QPointF &scenePos) const;
147#endif
148
149 void clearFocusObject() override;
150 void setFocusToTarget(FocusTarget, Qt::FocusReason) override;
151
152 void maybeSynthesizeContextMenuEvent(QMouseEvent *event) override;
153
154 void dirtyItem(QQuickItem *);
155 void cleanup(QSGNode *);
156
157 void ensureCustomRenderTarget();
158 void setCustomCommandBuffer(QRhiCommandBuffer *cb);
159
160 void polishItems();
161 void forcePolish();
162 void invalidateFontData(QQuickItem *item);
163 void syncSceneGraph();
164 void renderSceneGraph();
165
166 bool isRenderable() const;
167
168 bool emitError(QQuickWindow::SceneGraphError error, const QString &msg);
169
170 enum TextureFromNativeTextureFlag {
171 NativeTextureIsExternalOES = 0x01
172 };
173 Q_DECLARE_FLAGS(TextureFromNativeTextureFlags, TextureFromNativeTextureFlag)
174
175 QSGTexture *createTextureFromNativeTexture(quint64 nativeObjectHandle,
176 int nativeLayoutOrState,
177 uint nativeFormat,
178 const QSize &size,
179 QQuickWindow::CreateTextureOptions options,
180 TextureFromNativeTextureFlags flags = {}) const;
181 QSGTexture *createTextureFromNativeTexture(quint64 nativeObjectHandle,
182 int nativeLayoutOrState,
183 const QSize &size,
184 QQuickWindow::CreateTextureOptions options,
185 TextureFromNativeTextureFlags flags = {}) const {
186 return createTextureFromNativeTexture(nativeObjectHandle, nativeLayoutOrState, 0, size, options, flags);
187 }
188
189 QQuickItem::UpdatePaintNodeData updatePaintNodeData;
190
191 QQuickItem *dirtyItemList;
192 QList<QSGNode *> cleanupNodeList;
193
194 QVector<QQuickItem *> itemsToPolish;
195
196 qreal lastReportedItemDevicePixelRatio;
197 QMetaObject::Connection physicalDpiChangedConnection;
198 std::array<QMetaObject::Connection, 7> connections;
199
200 void updateDirtyNodes();
201 void cleanupNodes();
202 void cleanupNodesOnShutdown();
203 bool updateEffectiveOpacity(QQuickItem *);
204 void updateEffectiveOpacityRoot(QQuickItem *, qreal);
205 void updateDirtyNode(QQuickItem *);
206
207 void fireFrameSwapped() { Q_EMIT q_func()->frameSwapped(); }
208 void fireAboutToStop() { Q_EMIT q_func()->sceneGraphAboutToStop(); }
209
210 bool needsChildWindowStackingOrderUpdate = false;
211 void updateChildWindowStackingOrder(QQuickItem *item = nullptr);
212
213 int multiViewCount();
214 QRhiRenderTarget *activeCustomRhiRenderTarget();
215
216 QSGRenderContext *context;
217 QSGRenderer *renderer;
218 QByteArray visualizationMode; // Default renderer supports "clip", "overdraw", "changes", "batches" and blank.
219
220 QSGRenderLoop *windowManager;
221 QQuickRenderControl *renderControl;
222 QScopedPointer<QQuickAnimatorController> animationController;
223
224 QColor clearColor;
225
226 uint persistentGraphics : 1;
227 uint persistentSceneGraph : 1;
228 uint inDestructor : 1;
229
230 // Storage for setRenderTarget(QQuickRenderTarget).
231 // Gets baked into redirect.renderTarget by ensureCustomRenderTarget() when rendering the next frame.
232 QQuickRenderTarget customRenderTarget;
233
234 struct Redirect {
235 QRhiCommandBuffer *commandBuffer = nullptr;
236 QQuickWindowRenderTarget rt;
237 bool renderTargetDirty = false;
238 } redirect;
239
240 QQuickGraphicsDevice customDeviceObjects;
241
242 QQuickGraphicsConfiguration graphicsConfig;
243
244 mutable QQuickWindowIncubationController *incubationController;
245
246 static bool defaultAlphaBuffer;
247 static QQuickWindow::TextRenderType textRenderType;
248
249 // data property
250 static void data_append(QQmlListProperty<QObject> *, QObject *);
251 static qsizetype data_count(QQmlListProperty<QObject> *);
252 static QObject *data_at(QQmlListProperty<QObject> *, qsizetype);
253 static void data_clear(QQmlListProperty<QObject> *);
254 static void data_removeLast(QQmlListProperty<QObject> *);
255
256 static void rhiCreationFailureMessage(const QString &backendName,
257 QString *translatedMessage,
258 QString *untranslatedMessage);
259
260 static void emitBeforeRenderPassRecording(void *ud);
261 static void emitAfterRenderPassRecording(void *ud);
262
263 QMutex renderJobMutex;
264 QList<QRunnable *> beforeSynchronizingJobs;
265 QList<QRunnable *> afterSynchronizingJobs;
266 QList<QRunnable *> beforeRenderingJobs;
267 QList<QRunnable *> afterRenderingJobs;
268 QList<QRunnable *> afterSwapJobs;
269
270 void runAndClearJobs(QList<QRunnable *> *jobs);
271 QOpenGLContext *openglContext();
272
273 QQuickWindow::GraphicsStateInfo rhiStateInfo;
274 QRhi *rhi = nullptr;
275 QRhiSwapChain *swapchain = nullptr;
276 QRhiRenderBuffer *depthStencilForSwapchain = nullptr;
277 QRhiRenderPassDescriptor *rpDescForSwapchain = nullptr;
278 uint hasActiveSwapchain : 1;
279 uint hasRenderableSwapchain : 1;
280 uint swapchainJustBecameRenderable : 1;
281 uint updatesEnabled : 1;
282 bool pendingFontUpdate = false;
283 bool windowEventDispatch = false;
284 bool rmbContextMenuEventEnabled = false; // true after right-mouse press, false when menu opened
285 QPointer<QQuickPalette> windowPaletteRef;
286
287private:
288 static void cleanupNodesOnShutdown(QQuickItem *);
289};
290
292{
293public:
295 void run() override { delete object; }
297 static void schedule(QQuickWindow *window, QObject *object) {
298 Q_ASSERT(window);
299 Q_ASSERT(object);
300 window->scheduleRenderJob(new QQuickWindowQObjectCleanupJob(object), QQuickWindow::AfterSynchronizingStage);
301 }
302};
303
304Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickWindowPrivate::TextureFromNativeTextureFlags)
305
306QT_END_NAMESPACE
307
308#endif // QQUICKWINDOW_P_H
bool contains(const QPointF &point) const override
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
Q_STATIC_LOGGING_CATEGORY(lcAccessibilityCore, "qt.accessibility.core")
QDebug operator<<(QDebug dbg, const NSObject *nsObject)
Definition qcore_mac.mm:201
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