Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qquickcanvasitem.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 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 <private/qsgadaptationlayer_p.h>
6#include <private/qquickitem_p.h>
7#include <private/qquickcanvascontext_p.h>
8#include <private/qquickcontext2d_p.h>
9#include <private/qquickcontext2dtexture_p.h>
10#include <private/qsgadaptationlayer_p.h>
11#include <qsgtextureprovider.h>
12#include <QtQuick/private/qquickpixmapcache_p.h>
13#include <QtGui/QGuiApplication>
14#include <qsgtextureprovider.h>
15
16#include <qqmlinfo.h>
17#include <private/qqmlengine_p.h>
18#include <QtCore/QBuffer>
19#include <QtCore/qdatetime.h>
20
21#include <private/qv4value_p.h>
22#include <private/qv4functionobject_p.h>
23#include <private/qv4scopedvalue_p.h>
24#include <private/qv4jscall_p.h>
25#include <private/qv4qobjectwrapper_p.h>
26#include <private/qjsvalue_p.h>
27
29
31{
32public:
34 QSGTexture *texture() const override { return tex; }
36};
37
39 : m_pixmap(nullptr)
40 , m_image(image)
41{
42
43}
44
46 : m_pixmap(pixmap)
47{
48
49}
50
52{
53 delete m_pixmap;
54}
55
57{
58 if (m_pixmap)
59 return m_pixmap->width();
60
61 return m_image.width();
62}
63
65{
66 if (m_pixmap)
67 return m_pixmap->height();
68
69 return m_image.height();
70}
71
73{
74 if (m_pixmap)
75 return m_pixmap->isReady();
76 return !m_image.isNull();
77}
78
80{
81 if (m_image.isNull() && m_pixmap)
82 m_image = m_pixmap->image();
83
84 return m_image;
85}
86
87QHash<QQmlEngine *,QQuickContext2DRenderThread*> QQuickContext2DRenderThread::renderThreads;
88QMutex QQuickContext2DRenderThread::renderThreadsMutex;
89
91 : QThread(eng), m_engine(eng), m_eventLoopQuitHack(nullptr)
92{
93 Q_ASSERT(eng);
94 m_eventLoopQuitHack = new QObject;
95 m_eventLoopQuitHack->moveToThread(this);
96 connect(m_eventLoopQuitHack, SIGNAL(destroyed(QObject*)), SLOT(quit()), Qt::DirectConnection);
98}
99
101{
102 renderThreadsMutex.lock();
103 renderThreads.remove(m_engine);
104 renderThreadsMutex.unlock();
105
106 m_eventLoopQuitHack->deleteLater();
107 wait();
108}
109
111{
113 renderThreadsMutex.lock();
114 if (renderThreads.contains(engine))
115 thread = renderThreads.value(engine);
116 else {
118 renderThreads.insert(engine, thread);
119 }
120 renderThreadsMutex.unlock();
121 return thread;
122}
123
125{
126public:
147};
148
152 , canvasSize(1, 1)
153 , tileSize(1, 1)
154 , hasCanvasSize(false)
155 , hasTileSize(false)
156 , hasCanvasWindow(false)
157 , available(false)
158 , renderTarget(QQuickCanvasItem::Image)
159 , renderStrategy(QQuickCanvasItem::Immediate)
160 , textureProvider(nullptr)
161 , node(nullptr)
162 , nodeTexture(nullptr)
163{
165}
166
168{
169 pixmaps.clear();
170}
171
172
260{
262}
263
265{
266 Q_D(QQuickCanvasItem);
267 delete d->context;
268 if (d->textureProvider)
270}
271
279{
280 return d_func()->available;
281}
282
299{
300 return d_func()->contextType;
301}
302
304{
305 Q_D(QQuickCanvasItem);
306
307 if (contextType.compare(d->contextType, Qt::CaseInsensitive) == 0)
308 return;
309
310 if (d->context) {
311 qmlWarning(this) << "Canvas already initialized with a different context type";
312 return;
313 }
314
315 d->contextType = contextType;
316
317 if (d->available)
318 createContext(contextType);
319
321}
322
333{
334 Q_D(const QQuickCanvasItem);
335 return d->context ? QJSValuePrivate::fromReturnedValue(d->context->v4value()) : QJSValue();
336}
337
353{
354 Q_D(const QQuickCanvasItem);
355 return d->canvasSize;
356}
357
359{
360 Q_D(QQuickCanvasItem);
361 if (d->canvasSize != size) {
362 d->hasCanvasSize = true;
363 d->canvasSize = size;
365
366 if (d->context)
367 polish();
368 }
369}
370
389{
390 Q_D(const QQuickCanvasItem);
391 return d->tileSize;
392}
393
395{
396 Q_D(QQuickCanvasItem);
397 if (d->tileSize != size) {
398 d->hasTileSize = true;
399 d->tileSize = size;
400
402
403 if (d->context)
404 polish();
405 }
406}
407
424{
425 Q_D(const QQuickCanvasItem);
426 return d->canvasWindow;
427}
428
430{
431 Q_D(QQuickCanvasItem);
432 if (d->canvasWindow != rect) {
433 d->canvasWindow = rect;
434
435 d->hasCanvasWindow = true;
437
438 if (d->context)
439 polish();
440 }
441}
442
459{
460 Q_D(const QQuickCanvasItem);
461 return d->renderTarget;
462}
463
465{
466 Q_D(QQuickCanvasItem);
467 if (d->renderTarget != target) {
468 if (d->context) {
469 qmlWarning(this) << "Canvas:renderTarget not changeble once context is active.";
470 return;
471 }
472
473 d->renderTarget = target;
475 }
476}
477
502{
503 return d_func()->renderStrategy;
504}
505
507{
508 Q_D(QQuickCanvasItem);
509 if (d->renderStrategy != strategy) {
510 if (d->context) {
511 qmlWarning(this) << "Canvas:renderStrategy not changeable once context is active.";
512 return;
513 }
514 d->renderStrategy = strategy;
516 }
517}
518
520{
521 return d_func()->context;
522}
523
524bool QQuickCanvasItem::isPaintConnected()
525{
527}
528
529void QQuickCanvasItem::sceneGraphInitialized()
530{
531 Q_D(QQuickCanvasItem);
532
533 d->available = true;
534 connect(this, SIGNAL(visibleChanged()), SLOT(checkAnimationCallbacks()));
535 QMetaObject::invokeMethod(this, "availableChanged", Qt::QueuedConnection);
536
537 if (!d->contextType.isNull())
538 QMetaObject::invokeMethod(this, "delayedCreate", Qt::QueuedConnection);
539 else if (isPaintConnected())
540 QMetaObject::invokeMethod(this, "requestPaint", Qt::QueuedConnection);
541}
542
543void QQuickCanvasItem::geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry)
544{
545 Q_D(QQuickCanvasItem);
546
547 QQuickItem::geometryChange(newGeometry, oldGeometry);
548
549 // Due to indirect recursion, newGeometry may be outdated
550 // after this call, so we use width and height instead.
551 QSizeF newSize = QSizeF(width(), height());
552 if (!d->hasCanvasSize && d->canvasSize != newSize) {
553 d->canvasSize = newSize;
555 }
556
557 if (!d->hasTileSize && d->tileSize != newSize) {
558 d->tileSize = newSize.toSize();
560 }
561
562 const QRectF rect = QRectF(QPointF(0, 0), newSize);
563
564 if (!d->hasCanvasWindow && d->canvasWindow != rect) {
565 d->canvasWindow = rect;
567 }
568
569 if (d->available && newSize != oldGeometry.size()) {
570 if (isVisible() || (d->extra.isAllocated() && d->extra->effectRefCount > 0))
571 requestPaint();
572 }
573}
574
576{
577 Q_D(QQuickCanvasItem);
578
579 if (d->context) {
580 delete d->context;
581 d->context = nullptr;
582 }
583 d->node = nullptr; // managed by the scene graph, just reset the pointer
584 if (d->textureProvider) {
586 d->textureProvider = nullptr;
587 }
588 if (d->nodeTexture) {
590 d->nodeTexture = nullptr;
591 }
592}
593
595{
596 switch (event->type()) {
598 polish();
599 return true;
600 default:
601 return QQuickItem::event(event);
602 }
603}
604
605void QQuickCanvasItem::invalidateSceneGraph()
606{
607 Q_D(QQuickCanvasItem);
608 if (d->context)
609 d->context->deleteLater();
610 d->context = nullptr;
611 d->node = nullptr; // managed by the scene graph, just reset the pointer
612 delete d->textureProvider;
613 d->textureProvider = nullptr;
614 delete d->nodeTexture;
615 d->nodeTexture = nullptr;
616
617 // As we can expect(/hope) that the SG will be "good again", we can requestPaint ( which does 'markDirty(canvasWindow);' )
618 // Otherwise this Canvas will be "blank" when SG comes back
619 requestPaint();
620}
621
622void QQuickCanvasItem::schedulePolish()
623{
624 auto polishRequestEvent = new QEvent(QEvent::PolishRequest);
625 QCoreApplication::postEvent(this, polishRequestEvent);
626}
627
629{
631
632 Q_D(QQuickCanvasItem);
633 d->baseUrl = qmlEngine(this)->contextForObject(this)->baseUrl();
634}
635
637{
639 if (change != QQuickItem::ItemSceneChange)
640 return;
641
642 Q_D(QQuickCanvasItem);
643 if (d->available) {
644 if (d->dirtyAttributes & QQuickItemPrivate::ContentUpdateMask)
645 requestPaint();
646 return;
647 }
648
649 if (value.window== nullptr)
650 return;
651
652 d->window = value.window;
654
655 // Rendering to FramebufferObject needs a valid OpenGL context.
656 if (context != nullptr && (d->renderTarget != FramebufferObject || context->isValid())) {
657 // Defer the call. In some (arguably incorrect) cases we get here due
658 // to ItemSceneChange with the user-supplied property values not yet
659 // set. Work this around by a deferred invoke. (QTBUG-49692)
660 QMetaObject::invokeMethod(this, "sceneGraphInitialized", Qt::QueuedConnection);
661 } else {
662 connect(d->window, SIGNAL(sceneGraphInitialized()), SLOT(sceneGraphInitialized()));
663 }
664}
665
667{
669
670 Q_D(QQuickCanvasItem);
671 if (d->context && d->renderStrategy != QQuickCanvasItem::Cooperative)
672 d->context->prepare(d->canvasSize.toSize(), d->tileSize, d->canvasWindow.toRect(), d->dirtyRect.toRect(), d->smooth, antialiasing());
673
674 if (d->animationCallbacks.size() > 0 && isVisible()) {
675 QMap<int, QV4::PersistentValue> animationCallbacks = d->animationCallbacks;
676 d->animationCallbacks.clear();
677
679 QV4::Scope scope(v4);
681 QV4::JSCallArguments jsCall(scope, 1);
682 *jsCall.thisObject = QV4::QObjectWrapper::wrap(v4, this);
683
684 for (auto it = animationCallbacks.cbegin(), end = animationCallbacks.cend(); it != end; ++it) {
685 function = it.value().value();
687 function->call(jsCall);
688 }
689 }
690 else {
691 if (d->dirtyRect.isValid()) {
692 if (d->hasTileSize && d->hasCanvasWindow)
693 emit paint(tiledRect(d->canvasWindow.intersected(d->dirtyRect.toAlignedRect()), d->tileSize));
694 else
695 emit paint(d->dirtyRect.toRect());
696 d->dirtyRect = QRectF();
697 }
698 }
699
700 if (d->context) {
701 if (d->renderStrategy == QQuickCanvasItem::Cooperative)
702 update();
703 else
704 d->context->flush();
705 }
706}
707
709{
710 Q_D(QQuickCanvasItem);
711
712 if (!d->context || d->canvasWindow.size().isEmpty()) {
713 if (d->textureProvider) {
714 d->textureProvider->tex = nullptr;
715 d->textureProvider->fireTextureChanged();
716 }
717 delete oldNode;
718 return nullptr;
719 }
720
721 QSGInternalImageNode *node = static_cast<QSGInternalImageNode *>(oldNode);
722 if (!node) {
725 d->node = node;
726 }
727
728
729 if (d->smooth)
731 else
733
734 if (d->renderStrategy == QQuickCanvasItem::Cooperative) {
735 d->context->prepare(d->canvasSize.toSize(), d->tileSize, d->canvasWindow.toRect(), d->dirtyRect.toRect(), d->smooth, antialiasing());
736 d->context->flush();
737 }
738
739 QQuickContext2D *ctx = qobject_cast<QQuickContext2D *>(d->context);
740 QQuickContext2DTexture *factory = ctx->texture();
741 QSGTexture *texture = factory->textureForNextFrame(d->nodeTexture, window());
742 if (!texture) {
743 delete node;
744 d->node = nullptr;
745 d->nodeTexture = nullptr;
746 if (d->textureProvider) {
747 d->textureProvider->tex = nullptr;
748 d->textureProvider->fireTextureChanged();
749 }
750 return nullptr;
751 }
752
753 d->nodeTexture = texture;
754 node->setTexture(texture);
755 node->setTargetRect(QRectF(QPoint(0, 0), d->canvasWindow.size()));
756 node->setInnerTargetRect(QRectF(QPoint(0, 0), d->canvasWindow.size()));
757 node->update();
758
759 if (d->textureProvider) {
760 d->textureProvider->tex = d->nodeTexture;
761 d->textureProvider->fireTextureChanged();
762 }
763 return node;
764}
765
767{
768 return true;
769}
770
772{
773 // When Item::layer::enabled == true, QQuickItem will be a texture
774 // provider. In this case we should prefer to return the layer rather
775 // than the canvas itself.
778
779 Q_D(const QQuickCanvasItem);
780
781 QQuickWindow *w = window();
782 if (!w || !w->isSceneGraphInitialized()
784 qWarning("QQuickCanvasItem::textureProvider: can only be queried on the rendering thread of an exposed window");
785 return nullptr;
786 }
787
788 if (!d->textureProvider)
789 d->textureProvider = new QQuickCanvasTextureProvider;
790 d->textureProvider->tex = d->nodeTexture;
791 return d->textureProvider;
792}
793
814{
815 Q_D(QQuickCanvasItem);
816
817 QV4::Scope scope(args->v4engine());
818 QV4::ScopedString str(scope, (*args)[0]);
819 if (!str) {
820 qmlWarning(this) << "getContext should be called with a string naming the required context type";
821 args->setReturnValue(QV4::Encode::null());
822 return;
823 }
824
825 if (!d->available) {
826 qmlWarning(this) << "Unable to use getContext() at this time, please wait for available: true";
827 args->setReturnValue(QV4::Encode::null());
828 return;
829 }
830
831 QString contextId = str->toQString();
832
833 if (d->context != nullptr) {
834 if (d->context->contextNames().contains(contextId, Qt::CaseInsensitive)) {
835 args->setReturnValue(d->context->v4value());
836 return;
837 }
838
839 qmlWarning(this) << "Canvas already initialized with a different context type";
840 args->setReturnValue(QV4::Encode::null());
841 return;
842 }
843
844 if (createContext(contextId))
845 args->setReturnValue(d->context->v4value());
846 else
847 args->setReturnValue(QV4::Encode::null());
848}
849
858{
859 QV4::Scope scope(args->v4engine());
860 QV4::ScopedFunctionObject f(scope, (*args)[0]);
861 if (!f) {
862 qmlWarning(this) << "requestAnimationFrame should be called with an animation callback function";
863 args->setReturnValue(QV4::Encode::null());
864 return;
865 }
866
867 Q_D(QQuickCanvasItem);
868
869 static int id = 0;
870
871 d->animationCallbacks.insert(++id, QV4::PersistentValue(scope.engine, f->asReturnedValue()));
872
873 // QTBUG-55778: Calling polish directly here can lead to a polish loop
874 if (isVisible())
875 schedulePolish();
876
877 args->setReturnValue(QV4::Encode(id));
878}
879
887{
888 QV4::Scope scope(args->v4engine());
889 QV4::ScopedValue v(scope, (*args)[0]);
890 if (!v->isInteger()) {
891 qmlWarning(this) << "cancelRequestAnimationFrame should be called with an animation callback id";
892 args->setReturnValue(QV4::Encode::null());
893 return;
894 }
895
896 d_func()->animationCallbacks.remove(v->integerValue());
897}
898
899
909{
910 markDirty(d_func()->canvasWindow);
911}
912
923{
924 Q_D(QQuickCanvasItem);
925 if (!d->available)
926 return;
927
928 d->dirtyRect |= rect;
929
930 polish();
931}
932
933void QQuickCanvasItem::checkAnimationCallbacks()
934{
935 if (d_func()->animationCallbacks.size() > 0 && isVisible())
936 polish();
937}
938
954bool QQuickCanvasItem::save(const QString &filename, const QSizeF &imageSize) const
955{
956 Q_D(const QQuickCanvasItem);
957 QUrl url = d->baseUrl.resolved(QUrl::fromLocalFile(filename));
959}
960
962{
963 Q_D(QQuickCanvasItem);
964 QUrl fullPathUrl = d->baseUrl.resolved(url);
965 if (!d->pixmaps.contains(fullPathUrl)) {
966 loadImage(url, sourceSize);
967 }
968 return d->pixmaps.value(fullPathUrl);
969}
970
997{
998 Q_D(QQuickCanvasItem);
999 QUrl fullPathUrl = d->baseUrl.resolved(url);
1000 if (!d->pixmaps.contains(fullPathUrl)) {
1001 QQuickPixmap* pix = new QQuickPixmap();
1003 canvasPix.adopt(new QQuickCanvasPixmap(pix));
1004 d->pixmaps.insert(fullPathUrl, canvasPix);
1005
1006 pix->load(qmlEngine(this)
1007 , fullPathUrl
1008 , QRect()
1009 , sourceSize.toSize()
1011 if (pix->isLoading())
1012 pix->connectFinished(this, SIGNAL(imageLoaded()));
1013 }
1014}
1027{
1028 Q_D(QQuickCanvasItem);
1029 d->pixmaps.remove(d->baseUrl.resolved(url));
1030}
1031
1040{
1041 Q_D(const QQuickCanvasItem);
1042 QUrl fullPathUrl = d->baseUrl.resolved(url);
1043 return d->pixmaps.contains(fullPathUrl)
1044 && d->pixmaps.value(fullPathUrl)->pixmap()->isError();
1045}
1046
1054{
1055 Q_D(const QQuickCanvasItem);
1056 QUrl fullPathUrl = d->baseUrl.resolved(url);
1057 return d->pixmaps.contains(fullPathUrl)
1058 && d->pixmaps.value(fullPathUrl)->pixmap()->isLoading();
1059}
1067{
1068 Q_D(const QQuickCanvasItem);
1069 QUrl fullPathUrl = d->baseUrl.resolved(url);
1070 return d->pixmaps.contains(fullPathUrl)
1071 && d->pixmaps.value(fullPathUrl)->pixmap()->isReady();
1072}
1073
1081{
1082 Q_D(const QQuickCanvasItem);
1083
1084 if (!d->context)
1085 return QImage();
1086
1087 const QRectF &rectSource = rect.isEmpty() ? canvasWindow() : rect;
1088 const qreal dpr = window() && rect.isEmpty() ? window()->effectiveDevicePixelRatio() : qreal(1);
1089 const QRectF rectScaled(rectSource.topLeft() * dpr, rectSource.size() * dpr);
1090
1091 QImage image = d->context->toImage(rectScaled);
1092 image.setDevicePixelRatio(dpr);
1093 return image;
1094}
1095
1096static const char* mimeToType(const QString &mime)
1097{
1098 const QLatin1String imagePrefix("image/");
1099 if (!mime.startsWith(imagePrefix))
1100 return nullptr;
1101 const QStringView mimeExt = QStringView{mime}.mid(imagePrefix.size());
1102 if (mimeExt == QLatin1String("png"))
1103 return "png";
1104 else if (mimeExt == QLatin1String("bmp"))
1105 return "bmp";
1106 else if (mimeExt == QLatin1String("jpeg"))
1107 return "jpeg";
1108 else if (mimeExt == QLatin1String("x-portable-pixmap"))
1109 return "ppm";
1110 else if (mimeExt == QLatin1String("tiff"))
1111 return "tiff";
1112 else if (mimeExt == QLatin1String("xpm"))
1113 return "xpm";
1114 return nullptr;
1115}
1116
1127{
1128 QImage image = toImage();
1129
1130 if (!image.isNull()) {
1131 QByteArray ba;
1132 QBuffer buffer(&ba);
1134 const QString mime = mimeType.toLower();
1135 const char* type = mimeToType(mime);
1136 if (!type)
1137 return QStringLiteral("data:,");
1138
1139 image.save(&buffer, type);
1140 buffer.close();
1141 return QLatin1String("data:") + mime + QLatin1String(";base64,") + QLatin1String(ba.toBase64().constData());
1142 }
1143 return QStringLiteral("data:,");
1144}
1145
1146void QQuickCanvasItem::delayedCreate()
1147{
1148 Q_D(QQuickCanvasItem);
1149
1150 if (!d->context && !d->contextType.isNull())
1151 createContext(d->contextType);
1152
1153 requestPaint();
1154}
1155
1156bool QQuickCanvasItem::createContext(const QString &contextType)
1157{
1158 Q_D(QQuickCanvasItem);
1159
1160 if (!window())
1161 return false;
1162
1163 if (contextType == QLatin1String("2d")) {
1164 if (d->contextType.compare(QLatin1String("2d"), Qt::CaseInsensitive) != 0) {
1165 d->contextType = QLatin1String("2d");
1166 emit contextTypeChanged(); // XXX: can't be in setContextType()
1167 }
1168 initializeContext(new QQuickContext2D(this));
1169 return true;
1170 }
1171
1172 return false;
1173}
1174
1175void QQuickCanvasItem::initializeContext(QQuickCanvasContext *context, const QVariantMap &args)
1176{
1177 Q_D(QQuickCanvasItem);
1178
1179 d->context = context;
1180 d->context->init(this, args);
1181 d->context->setV4Engine(qmlEngine(this)->handle());
1182 connect(d->context, SIGNAL(textureChanged()), SLOT(update()));
1183 connect(d->context, SIGNAL(textureChanged()), SIGNAL(painted()));
1185}
1186
1187QRect QQuickCanvasItem::tiledRect(const QRectF &window, const QSize &tileSize)
1188{
1189 if (window.isEmpty())
1190 return QRect();
1191
1192 const int tw = tileSize.width();
1193 const int th = tileSize.height();
1194 const int h1 = window.left() / tw;
1195 const int v1 = window.top() / th;
1196
1197 const int htiles = ((window.right() - h1 * tw) + tw - 1)/tw;
1198 const int vtiles = ((window.bottom() - v1 * th) + th - 1)/th;
1199
1200 return QRect(h1 * tw, v1 * th, htiles * tw, vtiles * th);
1201}
1202
1221
1222#include "moc_qquickcanvasitem_p.cpp"
\inmodule QtCore \reentrant
Definition qbuffer.h:16
\inmodule QtCore
Definition qbytearray.h:57
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
Definition qbytearray.h:122
QByteArray toBase64(Base64Options options=Base64Encoding) const
static void postEvent(QObject *receiver, QEvent *event, int priority=Qt::NormalEventPriority)
static qint64 currentMSecsSinceEpoch() noexcept
\inmodule QtCore
Definition qcoreevent.h:45
@ PolishRequest
Definition qcoreevent.h:110
\inmodule QtCore
Definition qhash.h:818
bool remove(const Key &key)
Removes the item that has the key from the hash.
Definition qhash.h:956
bool contains(const Key &key) const noexcept
Returns true if the hash contains an item with the key; otherwise returns false.
Definition qhash.h:991
T value(const Key &key) const noexcept
Definition qhash.h:1044
void clear() noexcept(std::is_nothrow_destructible< Node >::value)
Removes all items from the hash and frees up all memory used by it.
Definition qhash.h:949
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition qhash.h:1283
\inmodule QtGui
Definition qimage.h:37
int width() const
Returns the width of the image.
bool save(const QString &fileName, const char *format=nullptr, int quality=-1) const
Saves the image to the file with the given fileName, using the given image file format and quality fa...
Definition qimage.cpp:3870
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition qimage.cpp:1197
int height() const
Returns the height of the image.
QV4::ExecutionEngine * handle() const
Definition qjsengine.h:292
static QJSValue fromReturnedValue(QV4::ReturnedValue d)
Definition qjsvalue_p.h:189
The QJSValue class acts as a container for Qt/JavaScript data types.
Definition qjsvalue.h:31
constexpr qsizetype size() const noexcept
void remove(qsizetype i, qsizetype n=1)
Definition qlist.h:787
Definition qmap.h:186
const_iterator cend() const
Definition qmap.h:604
const_iterator cbegin() const
Definition qmap.h:600
\inmodule QtCore
Definition qmutex.h:285
void unlock() noexcept
Unlocks the mutex.
Definition qmutex.h:293
void lock() noexcept
Locks the mutex.
Definition qmutex.h:290
\inmodule QtCore
Definition qobject.h:90
void moveToThread(QThread *thread)
Changes the thread affinity for this object and its children.
Definition qobject.cpp:1606
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2823
QThread * thread() const
Returns the thread in which the object lives.
Definition qobject.cpp:1561
void destroyed(QObject *=nullptr)
This signal is emitted immediately before the object obj is destroyed, after any instances of QPointe...
void deleteLater()
\threadsafe
Definition qobject.cpp:2352
bool load(const QString &fileName, const char *format=nullptr, Qt::ImageConversionFlags flags=Qt::AutoColor)
Loads a pixmap from the file with the given fileName.
Definition qpixmap.cpp:708
\inmodule QtCore\reentrant
Definition qpoint.h:214
\inmodule QtCore\reentrant
Definition qpoint.h:23
QUrl baseUrl() const
Returns the base url of the component, or the containing component if none is set.
The QQmlEngine class provides an environment for instantiating QML components.
Definition qqmlengine.h:57
static QQmlContext * contextForObject(const QObject *)
Returns the QQmlContext for the object, or nullptr if no context has been set.
QQmlRefPointer< T > & adopt(T *)
Takes ownership of other.
QQuickCanvasTextureProvider * textureProvider
QQuickCanvasContext * context
QHash< QUrl, QQmlRefPointer< QQuickCanvasPixmap > > pixmaps
QSGInternalImageNode * node
QQuickCanvasItem::RenderTarget renderTarget
QMap< int, QV4::PersistentValue > animationCallbacks
QQuickCanvasItem::RenderStrategy renderStrategy
void setTileSize(const QSize &)
void renderStrategyChanged()
void renderTargetChanged()
void setCanvasWindow(const QRectF &rect)
bool event(QEvent *event) override
This virtual function receives events to an object and should return true if the event e was recogniz...
Q_INVOKABLE QString toDataURL(const QString &type=QLatin1String("image/png")) const
\qmlmethod string QtQuick::Canvas::toDataURL(string mimeType)
bool isTextureProvider() const override
Returns true if this item is a texture provider.
void paint(const QRect &region)
bool isImageLoaded(const QUrl &url) const
\qmlmethod QtQuick::Canvas::isImageLoaded(url image) Returns true if the image is successfully loaded...
void setCanvasSize(const QSizeF &)
void setRenderStrategy(RenderStrategy strategy)
RenderStrategy renderStrategy
QQmlRefPointer< QQuickCanvasPixmap > loadedPixmap(const QUrl &url, QSizeF sourceSize=QSizeF())
void updatePolish() override
This function should perform any layout as required for this item.
QQuickCanvasContext * rawContext() const
Q_INVOKABLE void cancelRequestAnimationFrame(QQmlV4Function *args)
\qmlmethod QtQuick::Canvas::cancelRequestAnimationFrame(int handle)
QSGTextureProvider * textureProvider() const override
Returns the texture provider for an item.
void setContextType(const QString &contextType)
bool isAvailable() const
\qmlproperty bool QtQuick::Canvas::available
Q_INVOKABLE bool save(const QString &filename, const QSizeF &imageSize=QSizeF()) const
\qmlmethod bool QtQuick::Canvas::save(string filename, size imageSize = undefined)
Q_INVOKABLE void getContext(QQmlV4Function *args)
\qmlmethod object QtQuick::Canvas::getContext(string contextId, ... args)
void unloadImage(const QUrl &url)
\qmlmethod QtQuick::Canvas::unloadImage(url image)
bool isImageError(const QUrl &url) const
\qmlmethod QtQuick::Canvas::isImageError(url image)
void contextTypeChanged()
void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override
QQuickCanvasItem(QQuickItem *parent=nullptr)
\qmltype Canvas \instantiates QQuickCanvasItem \inqmlmodule QtQuick
QImage toImage(const QRectF &rect=QRectF()) const
void tileSizeChanged()
void canvasSizeChanged()
QSGNode * updatePaintNode(QSGNode *, UpdatePaintNodeData *) override
Called on the render thread when it is time to sync the state of the item with the scene graph.
void canvasWindowChanged()
void itemChange(QQuickItem::ItemChange, const QQuickItem::ItemChangeData &) override
Called when change occurs for this item.
void releaseResources() override
This function is called when an item should release graphics resources which are not already managed ...
bool isImageLoading(const QUrl &url) const
\qmlmethod QtQuick::Canvas::isImageLoading(url image) Returns true if the image is currently loading.
RenderTarget renderTarget
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
Q_INVOKABLE void markDirty(const QRectF &dirtyRect=QRectF())
\qmlmethod QtQuick::Canvas::markDirty(rect area)
void setRenderTarget(RenderTarget target)
void loadImage(const QUrl &url, QSizeF sourceSize=QSizeF())
\qmlsignal QtQuick::Canvas::imageLoaded()
Q_INVOKABLE void requestPaint()
\qmlmethod QtQuick::Canvas::requestPaint()
Q_INVOKABLE void requestAnimationFrame(QQmlV4Function *args)
\qmlmethod int QtQuick::Canvas::requestAnimationFrame(callback)
QQuickCanvasPixmap(const QImage &image)
QSGTexture * texture() const override
Returns a pointer to the texture object.
QQuickContext2DRenderThread(QQmlEngine *eng)
static QQuickContext2DRenderThread * instance(QQmlEngine *engine)
quint32 implicitAntialiasing
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:64
bool event(QEvent *) override
\reimp
void setFlag(Flag flag, bool enabled=true)
Enables the specified flag for this item if enabled is true; if enabled is false, the flag is disable...
virtual void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry)
void componentComplete() override
\reimp Derived classes should call the base class method before adding their own actions to perform a...
bool isVisible() const
virtual QSGTextureProvider * textureProvider() const
Returns the texture provider for an item.
void visibleChanged()
QSizeF size() const
QQuickWindow * window() const
Returns the window in which this item is rendered.
qreal width
This property holds the width of this item.
Definition qquickitem.h:76
virtual void itemChange(ItemChange, const ItemChangeData &)
Called when change occurs for this item.
bool antialiasing
\qmlproperty bool QtQuick::Item::antialiasing
Definition qquickitem.h:112
qreal height
This property holds the height of this item.
Definition qquickitem.h:77
virtual void updatePolish()
This function should perform any layout as required for this item.
ItemChange
Used in conjunction with QQuickItem::itemChange() to notify the item about certain types of changes.
Definition qquickitem.h:143
void update()
Schedules a call to updatePaintNode() for this item.
void polish()
Schedules a polish event for this item.
virtual bool isTextureProvider() const
Returns true if this item is a texture provider.
QImage image() const
static QQuickWindowPrivate * get(QQuickWindow *c)
QSGRenderContext * context
static void schedule(QQuickWindow *window, QObject *object)
\qmltype Window \instantiates QQuickWindow \inqmlmodule QtQuick
\inmodule QtCore\reentrant
Definition qrect.h:483
constexpr QPointF topLeft() const noexcept
Returns the position of the rectangle's top-left corner.
Definition qrect.h:510
constexpr QSizeF size() const noexcept
Returns the size of the rectangle.
Definition qrect.h:721
\inmodule QtCore\reentrant
Definition qrect.h:30
virtual QSGInternalImageNode * createInternalImageNode(QSGRenderContext *renderContext)=0
virtual void setTexture(QSGTexture *texture)=0
virtual void setTargetRect(const QRectF &rect)=0
virtual void setFiltering(QSGTexture::Filtering filtering)=0
virtual void update()=0
virtual void setInnerTargetRect(const QRectF &rect)=0
\group qtquick-scenegraph-nodes \title Qt Quick Scene Graph Node classes
Definition qsgnode.h:37
QSGContext * sceneGraphContext() const
The QSGTextureProvider class encapsulates texture based entities in QML.
void textureChanged()
This signal is emitted when the texture changes.
\inmodule QtQuick
Definition qsgtexture.h:20
\inmodule QtCore
Definition qsize.h:207
constexpr QSize toSize() const noexcept
Returns an integer based copy of this size.
Definition qsize.h:390
\inmodule QtCore
Definition qsize.h:25
constexpr int height() const noexcept
Returns the height.
Definition qsize.h:132
constexpr int width() const noexcept
Returns the width.
Definition qsize.h:129
\inmodule QtCore
Definition qstringview.h:76
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
int compare(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
Definition qstring.cpp:6498
void start(Priority=InheritPriority)
Definition qthread.cpp:923
static QThread * currentThread()
Definition qthread.cpp:966
@ IdlePriority
Definition qthread.h:42
bool wait(QDeadlineTimer deadline=QDeadlineTimer(QDeadlineTimer::Forever))
Definition qthread.cpp:950
void quit()
Definition qthread.cpp:935
\inmodule QtCore
Definition qurl.h:94
static QUrl fromLocalFile(const QString &localfile)
Returns a QUrl representation of localFile, interpreted as a local file.
Definition qurl.cpp:3354
QString toLocalFile() const
Returns the path of this URL formatted as a local file path.
Definition qurl.cpp:3411
EGLContext ctx
QString str
[2]
QSet< QString >::iterator it
rect
[4]
QPixmap pix
Combined button and popup list for selecting options.
@ CaseInsensitive
@ QueuedConnection
@ DirectConnection
Definition image.cpp:4
static void * context
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction function
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
const char * mimeType
#define qWarning
Definition qlogging.h:162
static QT_BEGIN_NAMESPACE const int tileSize
Definition qmemrotate.cpp:9
#define SLOT(a)
Definition qobjectdefs.h:51
#define SIGNAL(a)
Definition qobjectdefs.h:52
GLsizei const GLfloat * v
[13]
GLuint64 GLenum void * handle
GLfloat GLfloat GLfloat w
[0]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint GLuint end
GLfloat GLfloat f
GLenum GLuint buffer
GLenum type
GLenum target
GLint GLfloat GLfloat v1
GLenum GLuint texture
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei imageSize
struct _cl_event * event
QQmlEngine * qmlEngine(const QObject *obj)
Definition qqml.cpp:76
#define IS_SIGNAL_CONNECTED(Sender, SenderType, Name, Arguments)
Q_QML_EXPORT QQmlInfo qmlWarning(const QObject *me)
static const char * mimeToType(const QString &mime)
static QT_BEGIN_NAMESPACE qreal dpr(const QWindow *w)
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
QLatin1StringView QLatin1String
Definition qstringfwd.h:31
#define QStringLiteral(str)
#define emit
unsigned int uint
Definition qtypes.h:29
double qreal
Definition qtypes.h:92
QByteArray ba
[0]
QUrl url("example.com")
[constructor-url-reference]
application x qt windows mime
[2]
QObject::connect nullptr
QItemEditorFactory * factory
widget render & pixmap
aWidget window() -> setWindowTitle("New Window Title")
[2]
QJSValueList args
QJSEngine engine
[0]
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(nullptr), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
\threadsafe This is an overloaded member function, provided for convenience. It differs from the abov...
static constexpr ReturnedValue null()
static ReturnedValue wrap(ExecutionEngine *engine, QObject *object)
ExecutionEngine * engine
static Value fromUInt32(uint i)
Definition qv4value_p.h:203
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent
\inmodule QtQuick
Definition qquickitem.h:158