1/****************************************************************************
2**
3** Copyright (C) 2017 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt WebGL module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL$
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 https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 or (at your option) any later version
20** approved by the KDE Free Qt Foundation. The licenses are as published by
21** the Free Software Foundation and appearing in the file LICENSE.GPL3
22** included in the packaging of this file. Please review the following
23** information to ensure the GNU General Public License requirements will
24** be met: https://www.gnu.org/licenses/gpl-3.0.html.
25**
26** $QT_END_LICENSE$
27**
28****************************************************************************/
29
30#include "qwebglfunctioncall.h"
31
32#include <QtCore/qjsonobject.h>
33#include <QtCore/qjsonvalue.h>
34#include <QtCore/qstring.h>
35#include <QtCore/qthread.h>
36#include <QtGui/qpa/qplatformsurface.h>
37
38QT_BEGIN_NAMESPACE
39
40class QWebGLFunctionCallPrivate
41{
42public:
43 QString functionName;
44 QPlatformSurface *surface = nullptr;
45 QVariantList parameters;
46 bool wait = false;
47 int id = -1;
48 QThread *thread = nullptr;
49 static QAtomicInt nextId;
50 static int type;
51};
52
53QAtomicInt QWebGLFunctionCallPrivate::nextId(1);
54int QWebGLFunctionCallPrivate::type(QEvent::registerEventType());
55
56QWebGLFunctionCall::QWebGLFunctionCall(const QString &functionName,
57 QPlatformSurface *surface,
58 bool wait) :
59 QEvent(type()),
60 d_ptr(new QWebGLFunctionCallPrivate)
61{
62 Q_D(QWebGLFunctionCall);
63 d->functionName = functionName;
64 d->surface = surface;
65 d->wait = wait;
66 if (wait)
67 d->id = QWebGLFunctionCallPrivate::nextId.fetchAndAddOrdered(valueToAdd: 1);
68 d->thread = QThread::currentThread();
69}
70
71QWebGLFunctionCall::~QWebGLFunctionCall()
72{}
73
74QEvent::Type QWebGLFunctionCall::type()
75{
76 return Type(QWebGLFunctionCallPrivate::type);
77}
78
79int QWebGLFunctionCall::id() const
80{
81 Q_D(const QWebGLFunctionCall);
82 return d->id;
83}
84
85QThread *QWebGLFunctionCall::thread() const
86{
87 Q_D(const QWebGLFunctionCall);
88 return d->thread;
89}
90
91bool QWebGLFunctionCall::isBlocking() const
92{
93 Q_D(const QWebGLFunctionCall);
94 return d->wait;
95}
96
97QPlatformSurface *QWebGLFunctionCall::surface() const
98{
99 Q_D(const QWebGLFunctionCall);
100 return d->surface;
101}
102
103QString QWebGLFunctionCall::functionName() const
104{
105 Q_D(const QWebGLFunctionCall);
106 return d->functionName;
107}
108
109void QWebGLFunctionCall::addString(const QString &value)
110{
111 Q_D(QWebGLFunctionCall);
112 d->parameters.append(t: value);
113}
114
115void QWebGLFunctionCall::addInt(int value)
116{
117 Q_D(QWebGLFunctionCall);
118 d->parameters.append(t: value);
119}
120
121void QWebGLFunctionCall::addUInt(uint value)
122{
123 Q_D(QWebGLFunctionCall);
124 d->parameters.append(t: value);
125}
126
127void QWebGLFunctionCall::addFloat(float value)
128{
129 Q_D(QWebGLFunctionCall);
130 d->parameters.append(t: static_cast<double>(value));
131}
132
133void QWebGLFunctionCall::addData(const QByteArray &data)
134{
135 Q_D(QWebGLFunctionCall);
136 d->parameters.append(t: data);
137}
138
139void QWebGLFunctionCall::addList(const QVariantList &list)
140{
141 Q_D(QWebGLFunctionCall);
142 d->parameters.append(t: QVariant::fromValue(value: list));
143}
144
145void QWebGLFunctionCall::addNull()
146{
147 Q_D(QWebGLFunctionCall);
148 d->parameters.append(t: QVariant());
149}
150
151QVariantList QWebGLFunctionCall::parameters() const
152{
153 Q_D(const QWebGLFunctionCall);
154 return d->parameters;
155}
156
157QT_END_NAMESPACE
158

source code of qtwebglplugin/src/plugins/platforms/webgl/qwebglfunctioncall.cpp