6#include <QtGui/private/qtriangulator_p.h>
7#include <QtGui/private/qtriangulatingstroker_p.h>
9#include <QSGVertexColorMaterial>
10#include <QSGTextureProvider>
11#include <private/qsgplaintexture_p.h>
13#include <QtQuick/private/qsggradientcache_p.h>
34 c.getRgbF(&r, &g, &b, &a);
36 uchar(qRound(r * a * 255)),
37 uchar(qRound(g * a * 255)),
38 uchar(qRound(b * a * 255)),
39 uchar(qRound(a * 255))
47 setFlag(QSGNode::OwnsGeometry,
true);
48 setFlag(QSGNode::UsePreprocess,
true);
49 setGeometry(
new QSGGeometry(QSGGeometry::defaultAttributes_ColoredPoint2D(), 0, 0));
50 activateMaterial(window, MatSolidColor);
52 qsgnode_set_description(
this, QLatin1String(
"stroke-fill"));
62 m_material.reset(QQuickShapeGenericMaterialFactory::createVertexColor(window));
64 case MatLinearGradient:
65 m_material.reset(QQuickShapeGenericMaterialFactory::createLinearGradient(window,
this));
67 case MatRadialGradient:
68 m_material.reset(QQuickShapeGenericMaterialFactory::createRadialGradient(window,
this));
70 case MatConicalGradient:
71 m_material.reset(QQuickShapeGenericMaterialFactory::createConicalGradient(window,
this));
74 m_material.reset(QQuickShapeGenericMaterialFactory::createTextureFill(window,
this));
77 qWarning(
"Unknown material %d", m);
81 if (material() != m_material.data())
82 setMaterial(m_material.data());
87 if (m_fillTextureProvider !=
nullptr) {
88 if (QSGDynamicTexture *texture = qobject_cast<QSGDynamicTexture *>(m_fillTextureProvider->texture()))
89 texture->updateTexture();
95 markDirty(QSGNode::DirtyMaterial);
100 m_fillTextureProvider =
nullptr;
101 markDirty(QSGNode::DirtyMaterial);
106 for (ShapePathData &d : m_sp) {
108 d.pendingFill->orphaned =
true;
110 d.pendingStroke->orphaned =
true;
119 for (
int i = totalCount; i < m_sp.size(); i++)
120 setFillTextureProvider(i,
nullptr);
122 if (m_sp.size() != totalCount) {
123 m_sp.resize(totalCount);
125 *countChanged =
true;
127 *countChanged =
false;
129 for (ShapePathData &d : m_sp)
135 ShapePathData &d(m_sp[index]);
142 ShapePathData &d(m_sp[index]);
143 const bool wasTransparent = d.strokeColor
.a == 0;
144 d.strokeColor = colorToColor4ub(color);
145 const bool isTransparent = d.strokeColor
.a == 0;
147 if (wasTransparent && !isTransparent)
153 ShapePathData &d(m_sp[index]);
162 ShapePathData &d(m_sp[index]);
163 d.pen.setCosmetic(c);
171 ShapePathData &d(m_sp[index]);
172 const bool wasTransparent = d.fillColor
.a == 0;
173 d.fillColor = colorToColor4ub(color);
174 const bool isTransparent = d.fillColor
.a == 0;
176 if (wasTransparent && !isTransparent)
182 ShapePathData &d(m_sp[index]);
183 d.fillRule = Qt::FillRule(fillRule);
189 ShapePathData &d(m_sp[index]);
190 d.pen.setJoinStyle(Qt::PenJoinStyle(joinStyle));
191 d.pen.setMiterLimit(miterLimit);
197 ShapePathData &d(m_sp[index]);
198 d.pen.setCapStyle(Qt::PenCapStyle(capStyle));
203 qreal dashOffset,
const QList<qreal> &dashPattern)
205 ShapePathData &d(m_sp[index]);
206 d.pen.setStyle(Qt::PenStyle(strokeStyle));
207 if (strokeStyle == QQuickShapePath::DashLine) {
208 d.pen.setDashPattern(dashPattern);
209 d.pen.setDashOffset(dashOffset);
217 Q_ASSERT(dst !=
nullptr);
218 if (gradient ==
nullptr)
219 return QQuickAbstractPathRenderer::NoGradient;
221 dst->stops = gradient->gradientStops();
222 dst->spread = QGradient::Spread(gradient->spread());
223 if (
const QQuickShapeLinearGradient *g = qobject_cast<
const QQuickShapeLinearGradient *>(gradient)) {
224 dst->a = QPointF(g->x1(), g->y1());
225 dst->b = QPointF(g->x2(), g->y2());
227 return QQuickAbstractPathRenderer::LinearGradient;
228 }
else if (
const QQuickShapeRadialGradient *g = qobject_cast<
const QQuickShapeRadialGradient *>(gradient)) {
229 dst->a = QPointF(g->centerX(), g->centerY());
230 dst->b = QPointF(g->focalX(), g->focalY());
231 dst->v0 = g->centerRadius();
232 dst->v1 = g->focalRadius();
234 return QQuickAbstractPathRenderer::RadialGradient;
235 }
else if (
const QQuickShapeConicalGradient *g = qobject_cast<
const QQuickShapeConicalGradient *>(gradient)) {
236 dst->a = QPointF(g->centerX(), g->centerY());
237 dst->v0 = g->angle();
239 return QQuickAbstractPathRenderer::ConicalGradient;
242 Q_UNREACHABLE_RETURN(QQuickAbstractPathRenderer::NoGradient);
247 ShapePathData &d(m_sp[index]);
248 d.fillGradientActive = copyGenericGradient(gradient, &d.fillGradient);
254 ShapePathData &d(m_sp[index]);
255 d.strokeGradientActive = copyGenericGradient(gradient, &d.strokeGradient);
261 ShapePathData &d(m_sp[index]);
262 if ((d.fillTextureProviderItem ==
nullptr) != (textureProviderItem ==
nullptr))
264 if (d.fillTextureProviderItem !=
nullptr)
265 QQuickItemPrivate::get(d.fillTextureProviderItem)->derefWindow();
266 d.fillTextureProviderItem = textureProviderItem;
267 if (d.fillTextureProviderItem !=
nullptr)
268 QQuickItemPrivate::get(d.fillTextureProviderItem)->refWindow(m_item->window());
274 for (
auto &pathData : m_sp) {
275 if (pathData.fillTextureProviderItem !=
nullptr) {
276 if (window ==
nullptr)
277 QQuickItemPrivate::get(pathData.fillTextureProviderItem)->derefWindow();
279 QQuickItemPrivate::get(pathData.fillTextureProviderItem)->refWindow(window);
287 ShapePathData &d(m_sp[index]);
288 d.fillTransform = transform;
294 ShapePathData &d(m_sp[index]);
295 d.triangulationScale = scale;
304 QMetaObject::invokeMethod(qApp, [
this]() { emit done(
this); }, Qt::QueuedConnection);
311 QMetaObject::invokeMethod(qApp, [
this]() { emit done(
this); }, Qt::QueuedConnection);
316 m_asyncCallback = callback;
317 m_asyncCallbackData = data;
321static QThreadPool *pathWorkThreadPool =
nullptr;
323static void deletePathWorkThreadPool()
325 delete pathWorkThreadPool;
326 pathWorkThreadPool =
nullptr;
332#if !QT_CONFIG(thread)
338 bool didKickOffAsync =
false;
340 for (
int i = 0; i < m_sp.size(); ++i) {
341 ShapePathData &d(m_sp[i]);
345 m_accDirty |= d.syncDirty;
352 d.effectiveDirty |= d.syncDirty;
354 if (d.path.isEmpty()) {
355 d.fillVertices.clear();
356 d.fillIndices.clear();
357 d.strokeVertices.clear();
362 if (async && !pathWorkThreadPool) {
363 qAddPostRoutine(deletePathWorkThreadPool);
364 pathWorkThreadPool =
new QThreadPool;
365 const int idealCount = QThread::idealThreadCount();
366 pathWorkThreadPool->setMaxThreadCount(idealCount > 0 ? idealCount * 2 : 4);
377 const bool supportsElementIndexUint = m_rhiBackendInitialized ? m_supportsElementIndexUint :
true;
379 d.path.setFillRule(d.fillRule);
380 if (m_api == QSGRendererInterface::Unknown)
381 m_api = m_item->window()->rendererInterface()->graphicsApi();
384 r->setAutoDelete(
false);
391 r->triangulationScale = d.triangulationScale;
394 QObject::connect(r, &QQuickShapeFillRunnable::done, qApp, [
this, i](QQuickShapeFillRunnable *r) {
397 if (!r->orphaned && i < m_sp.size()) {
398 ShapePathData &d(m_sp[i]);
399 d.fillVertices = r->fillVertices;
400 d.fillIndices = r->fillIndices;
401 d.indexType = r->indexType;
402 d.pendingFill =
nullptr;
403 d.effectiveDirty |= DirtyFillGeom;
404 maybeUpdateAsyncItem();
408 didKickOffAsync =
true;
412 qtVectorPathForPath(r->path);
413 pathWorkThreadPool->start(r);
416 triangulateFill(d.path, d.fillColor, &d.fillVertices, &d.fillIndices, &d.indexType,
417 supportsElementIndexUint,
418 d.triangulationScale);
422 if ((d.syncDirty &
DirtyStrokeGeom) && d.strokeWidth > 0.0f && (d.strokeColor
.a || d.strokeGradientActive)) {
425 r->setAutoDelete(
false);
432 r->clipSize = QSize(m_item->width(), m_item->height());
433 r->triangulationScale = d.triangulationScale;
434 QObject::connect(r, &QQuickShapeStrokeRunnable::done, qApp, [
this, i](QQuickShapeStrokeRunnable *r) {
435 if (!r->orphaned && i < m_sp.size()) {
436 ShapePathData &d(m_sp[i]);
437 d.strokeVertices = r->strokeVertices;
438 d.pendingStroke =
nullptr;
439 d.effectiveDirty |= DirtyStrokeGeom;
440 maybeUpdateAsyncItem();
444 didKickOffAsync =
true;
448 qtVectorPathForPath(r->path);
449 pathWorkThreadPool->start(r);
452 triangulateStroke(d.path, d.pen, d.strokeColor, &d.strokeVertices,
453 QSize(m_item->width(), m_item->height()), d.triangulationScale);
458 if (!didKickOffAsync && async && m_asyncCallback)
459 m_asyncCallback(m_asyncCallbackData);
464 for (
const ShapePathData &d : std::as_const(m_sp)) {
465 if (d.pendingFill || d.pendingStroke)
471 m_asyncCallback(m_asyncCallbackData);
480 QSGGeometry::Type *indexType,
481 bool supportsElementIndexUint,
482 qreal triangulationScale)
484 const QVectorPath &vp = qtVectorPathForPath(path);
486 QTriangleSet ts = qTriangulate(vp, QTransform::fromScale(triangulationScale, triangulationScale), 1, supportsElementIndexUint);
487 const int vertexCount = ts.vertices.size() / 2;
488 fillVertices->resize(vertexCount);
490 const qreal *vsrc = ts.vertices.constData();
491 for (
int i = 0; i < vertexCount; ++i)
492 vdst[i]
.set(vsrc[i * 2] / triangulationScale
, vsrc[i * 2 + 1] / triangulationScale
, fillColor
);
494 size_t indexByteSize;
495 if (ts.indices.type() == QVertexIndexVector::UnsignedShort || vertexCount <= 0xffff) {
496 *indexType = QSGGeometry::UnsignedShortType;
497 const int indexCount = ts.indices.size();
503 fillIndices->resize((indexCount + 1) / 2);
506 if (ts.indices.type() != QVertexIndexVector::UnsignedShort) {
507 quint16 *dst =
reinterpret_cast<quint16 *>(fillIndices->data());
508 const quint32 *src =
reinterpret_cast<
const quint32 *>(ts.indices.data());
509 for (
int i = 0; i < indexCount; ++i)
510 dst[i] = quint16(src[i]);
514 indexByteSize = indexCount *
sizeof(quint16);
516 *indexType = QSGGeometry::UnsignedIntType;
517 fillIndices->resize(ts.indices.size());
518 indexByteSize = ts.indices.size() *
sizeof(quint32);
521 Q_ASSERT(fillIndices->size() *
sizeof(quint32) >= indexByteSize);
522 memcpy(fillIndices->data(), ts.indices.data(), indexByteSize);
529 const QSize &clipSize,
530 qreal triangulationScale)
532 const QVectorPath &vp = qtVectorPathForPath(path);
533 const QRectF clip(QPointF(0, 0), clipSize);
534 const qreal inverseScale = 1.0 / triangulationScale;
536 QTriangulatingStroker stroker;
537 stroker.setInvScale(inverseScale);
539 if (pen.style() == Qt::SolidLine) {
540 stroker.process(vp, pen, clip, {});
542 QDashedStrokeProcessor dashStroker;
543 dashStroker.setInvScale(inverseScale);
544 dashStroker.process(vp, pen, clip, {});
545 QVectorPath dashStroke(dashStroker.points(), dashStroker.elementCount(),
546 dashStroker.elementTypes(), 0);
547 stroker.process(dashStroke, pen, clip, {});
550 if (!stroker.vertexCount()) {
551 strokeVertices->clear();
555 const int vertexCount = stroker.vertexCount() / 2;
556 strokeVertices->resize(vertexCount);
558 const float *vsrc = stroker.vertices();
559 for (
int i = 0; i < vertexCount; ++i)
560 vdst[i]
.set(vsrc[i * 2]
, vsrc[i * 2 + 1]
, strokeColor
);
565 if (m_rootNode != node) {
574 if (!m_rootNode || !m_accDirty)
578 if (!m_rhiBackendInitialized) {
579 auto findRHIBackend = [](QQuickItem *item) -> QRhi * {
580 if (
auto *w = item->window()) {
581 if (
auto *rhi = QQuickWindowPrivate::get(w)->rhi)
586 auto *rhi = findRHIBackend(m_item);
587 if (rhi !=
nullptr) {
588 m_rhiBackendInitialized =
true;
589 m_supportsElementIndexUint = rhi->isFeatureSupported(QRhi::ElementIndexUint);
606 for (ShapePathData &d : m_sp) {
609 *nodePtr =
new QQuickShapeGenericNode;
610 prevNode->m_next = *nodePtr;
611 prevNode->appendChildNode(*nodePtr);
614 QQuickShapeGenericNode *node = *nodePtr;
616 if (m_accDirty & DirtyList) {
617 d.effectiveDirty |= DirtyFillGeom | DirtyStrokeGeom | DirtyColor | DirtyFillGradient
618 | DirtyFillTransform | DirtyFillTexture | DirtyStrokeGradient;
621 if (!d.effectiveDirty) {
623 nodePtr = &node->m_next;
627 if (d.fillColor.a == 0) {
628 delete node->m_fillNode;
629 node->m_fillNode =
nullptr;
630 }
else if (!node->m_fillNode) {
631 node->m_fillNode =
new QQuickShapeGenericStrokeFillNode(m_item->window());
632 if (node->m_strokeNode)
633 node->removeChildNode(node->m_strokeNode);
634 node->appendChildNode(node->m_fillNode);
635 if (node->m_strokeNode)
636 node->appendChildNode(node->m_strokeNode);
637 d.effectiveDirty |= DirtyFillGeom;
640 if (d.strokeWidth <= 0.0f || d.strokeColor.a == 0) {
641 delete node->m_strokeNode;
642 node->m_strokeNode =
nullptr;
643 }
else if (!node->m_strokeNode) {
644 node->m_strokeNode =
new QQuickShapeGenericStrokeFillNode(m_item->window());
645 node->appendChildNode(node->m_strokeNode);
646 d.effectiveDirty |= DirtyStrokeGeom;
649 updateFillNode(&d, node);
650 updateStrokeNode(&d, node);
652 d.effectiveDirty = 0;
655 nodePtr = &node->m_next;
658 if (*nodePtr && prevNode) {
659 prevNode->removeChildNode(*nodePtr);
664 if (m_sp.isEmpty()) {
678 if (d->fillGradientActive) {
680 n->m_gradient = d->fillGradient;
684 bool needsUpdate = d->fillTextureProviderItem ==
nullptr && n->m_fillTextureProvider !=
nullptr;
686 && d->fillTextureProviderItem !=
nullptr
687 && n->m_fillTextureProvider != d->fillTextureProviderItem->textureProvider()) {
692 if (n->m_fillTextureProvider !=
nullptr) {
693 QObject::disconnect(n->m_fillTextureProvider, &QSGTextureProvider::textureChanged,
694 n, &QQuickShapeGenericStrokeFillNode::handleTextureChanged);
695 QObject::disconnect(n->m_fillTextureProvider, &QSGTextureProvider::destroyed,
696 n, &QQuickShapeGenericStrokeFillNode::handleTextureProviderDestroyed);
699 n->m_fillTextureProvider = d->fillTextureProviderItem ==
nullptr
701 : d->fillTextureProviderItem->textureProvider();
703 if (n->m_fillTextureProvider !=
nullptr) {
704 QObject::connect(n->m_fillTextureProvider, &QSGTextureProvider::textureChanged,
705 n, &QQuickShapeGenericStrokeFillNode::handleTextureChanged);
706 QObject::connect(n->m_fillTextureProvider, &QSGTextureProvider::destroyed,
707 n, &QQuickShapeGenericStrokeFillNode::handleTextureProviderDestroyed);
712 n->m_fillTransform = d->fillTransform;
725 updateShadowDataInNode(d, n);
727 QSGGeometry *g = n->geometry();
728 if (d->fillVertices.isEmpty()) {
729 if (g->vertexCount() || g->indexCount()) {
731 n->markDirty(QSGNode::DirtyGeometry);
736 if (d->fillGradientActive) {
738 switch (d->fillGradientActive) {
745 case ConicalGradient:
749 Q_UNREACHABLE_RETURN();
751 n->activateMaterial(m_item->window(), gradMat);
754 n->markDirty(QSGNode::DirtyMaterial);
759 }
else if (d->fillTextureProviderItem !=
nullptr) {
762 n->markDirty(QSGNode::DirtyMaterial);
766 if ((d->effectiveDirty &
DirtyColor) && !(d->effectiveDirty &
DirtyFillGeom) && d->fillTextureProviderItem ==
nullptr) {
767 ColoredVertex *vdst =
reinterpret_cast<ColoredVertex *>(g->vertexData());
768 for (
int i = 0; i < g->vertexCount(); ++i)
770 n->markDirty(QSGNode::DirtyGeometry);
775 const int indexCount = d->indexType == QSGGeometry::UnsignedShortType
776 ? d->fillIndices.size() * 2 : d->fillIndices.size();
777 if (g->indexType() != d->indexType) {
778 g =
new QSGGeometry(QSGGeometry::defaultAttributes_ColoredPoint2D(),
779 d->fillVertices.size(), indexCount, d->indexType);
782 g->allocate(d->fillVertices.size(), indexCount);
784 g->setDrawingMode(QSGGeometry::DrawTriangles);
786 memcpy(g->vertexData(), d->fillVertices.constData(), g->vertexCount() * g->sizeOfVertex());
787 memcpy(g->indexData(), d->fillIndices.constData(), g->indexCount() * g->sizeOfIndex());
789 n->markDirty(QSGNode::DirtyGeometry);
800 if (d->strokeGradientActive) {
802 n->m_gradient = d->strokeGradient;
805 QSGGeometry *g = n->geometry();
806 if (d->strokeVertices.isEmpty()) {
807 if (g->vertexCount() || g->indexCount()) {
809 n->markDirty(QSGNode::DirtyGeometry);
814 n->markDirty(QSGNode::DirtyGeometry);
819 if (!g->vertexCount())
820 n->markDirty(QSGNode::DirtyMaterial);
822 if (d->strokeGradientActive) {
824 switch (d->strokeGradientActive) {
831 case ConicalGradient:
835 Q_UNREACHABLE_RETURN();
837 n->activateMaterial(m_item->window(), gradMat);
840 n->markDirty(QSGNode::DirtyMaterial);
848 ColoredVertex *vdst =
reinterpret_cast<ColoredVertex *>(g->vertexData());
849 for (
int i = 0; i < g->vertexCount(); ++i)
855 g->allocate(d->strokeVertices.size(), 0);
856 g->setDrawingMode(QSGGeometry::DrawTriangleStrip);
857 memcpy(g->vertexData(), d->strokeVertices.constData(), g->vertexCount() * g->sizeOfVertex());
862 QSGRendererInterface::GraphicsApi api = window->rendererInterface()->graphicsApi();
864 if (api == QSGRendererInterface::OpenGL || QSGRendererInterface::isApiRhiBased(api))
865 return new QSGVertexColorMaterial;
867 qWarning(
"Vertex-color material: Unsupported graphics API %d", api);
874 QSGRendererInterface::GraphicsApi api = window->rendererInterface()->graphicsApi();
876 if (api == QSGRendererInterface::OpenGL || QSGRendererInterface::isApiRhiBased(api))
879 qWarning(
"Linear gradient material: Unsupported graphics API %d", api);
886 QSGRendererInterface::GraphicsApi api = window->rendererInterface()->graphicsApi();
888 if (api == QSGRendererInterface::OpenGL || QSGRendererInterface::isApiRhiBased(api))
891 qWarning(
"Radial gradient material: Unsupported graphics API %d", api);
898 QSGRendererInterface::GraphicsApi api = window->rendererInterface()->graphicsApi();
900 if (api == QSGRendererInterface::OpenGL || QSGRendererInterface::isApiRhiBased(api))
903 qWarning(
"Conical gradient material: Unsupported graphics API %d", api);
910 QSGRendererInterface::GraphicsApi api = window->rendererInterface()->graphicsApi();
912 if (api == QSGRendererInterface::OpenGL || QSGRendererInterface::isApiRhiBased(api))
915 qWarning(
"Texture fill material: Unsupported graphics API %d", api);
921 setShaderFileName(VertexStage, QStringLiteral(
":/qt-project.org/shapes/shaders_ng/lineargradient.vert.qsb"), viewCount);
922 setShaderFileName(FragmentStage, QStringLiteral(
":/qt-project.org/shapes/shaders_ng/lineargradient.frag.qsb"), viewCount);
926 QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
928 Q_ASSERT(oldMaterial ==
nullptr || newMaterial->type() == oldMaterial->type());
930 bool changed =
false;
931 QByteArray *buf = state.uniformData();
932 Q_ASSERT(buf->size() >= 84 + 64);
933 const int shaderMatrixCount = newMaterial->viewCount();
934 const int matrixCount = qMin(state.projectionMatrixCount(), shaderMatrixCount);
936 if (state.isMatrixDirty()) {
937 for (
int viewIndex = 0; viewIndex < matrixCount; ++viewIndex) {
938 const QMatrix4x4 m = state.combinedMatrix();
939 memcpy(buf->data() + 64 * viewIndex, m.constData(), 64);
946 if (!oldMaterial || m_fillTransform != node->m_fillTransform) {
947 memcpy(buf->data() + 64 * shaderMatrixCount, node->m_fillTransform.invertedData(), 64);
948 m_fillTransform = node->m_fillTransform;
952 if (!oldMaterial || m_gradA.x() != node->m_gradient.a.x() || m_gradA.y() != node->m_gradient.a.y()) {
953 m_gradA = QVector2D(node->m_gradient.a.x(), node->m_gradient.a.y());
954 Q_ASSERT(
sizeof(m_gradA) == 8);
955 memcpy(buf->data() + 64 * shaderMatrixCount + 64, &m_gradA, 8);
959 if (!oldMaterial || m_gradB.x() != node->m_gradient.b.x() || m_gradB.y() != node->m_gradient.b.y()) {
960 m_gradB = QVector2D(node->m_gradient.b.x(), node->m_gradient.b.y());
961 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8, &m_gradB, 8);
965 if (state.isOpacityDirty()) {
966 const float opacity = state.opacity();
967 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8 + 8, &opacity, 4);
975 QSGMaterial *newMaterial, QSGMaterial *)
982 const QSGGradientCacheKey cacheKey(node->m_gradient.stops, QGradient::Spread(node->m_gradient.spread));
983 QSGTexture *t = QSGGradientCache::cacheForRhi(state.rhi())->get(cacheKey);
984 t->commitTextureOperations(state.rhi(), state.resourceUpdateBatch());
990 static QSGMaterialType type;
996 Q_ASSERT(other && type() == other->type());
1005 const QSGGradientCache::GradientDesc *ga = &a->m_gradient;
1006 const QSGGradientCache::GradientDesc *gb = &b->m_gradient;
1008 if (
int d = ga->spread - gb->spread)
1011 if (
int d = ga->a.x() - gb->a.x())
1013 if (
int d = ga->a.y() - gb->a.y())
1015 if (
int d = ga->b.x() - gb->b.x())
1017 if (
int d = ga->b.y() - gb->b.y())
1020 if (
int d = ga->stops.size() - gb->stops.size())
1023 for (
int i = 0; i < ga->stops.size(); ++i) {
1024 if (
int d = ga->stops[i].first - gb->stops[i].first)
1026 if (
int d = ga->stops[i].second.rgba() - gb->stops[i].second.rgba())
1030 if (
int d = a->m_fillTransform.compareTo(b->m_fillTransform))
1038 Q_UNUSED(renderMode);
1044 setShaderFileName(VertexStage, QStringLiteral(
":/qt-project.org/shapes/shaders_ng/radialgradient.vert.qsb"), viewCount);
1045 setShaderFileName(FragmentStage, QStringLiteral(
":/qt-project.org/shapes/shaders_ng/radialgradient.frag.qsb"), viewCount);
1049 QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
1051 Q_ASSERT(oldMaterial ==
nullptr || newMaterial->type() == oldMaterial->type());
1053 bool changed =
false;
1054 QByteArray *buf = state.uniformData();
1055 Q_ASSERT(buf->size() >= 92 + 64);
1056 const int shaderMatrixCount = newMaterial->viewCount();
1057 const int matrixCount = qMin(state.projectionMatrixCount(), shaderMatrixCount);
1059 if (state.isMatrixDirty()) {
1060 for (
int viewIndex = 0; viewIndex < matrixCount; ++viewIndex) {
1061 const QMatrix4x4 m = state.combinedMatrix();
1062 memcpy(buf->data() + 64 * viewIndex, m.constData(), 64);
1069 if (!oldMaterial || m_fillTransform != node->m_fillTransform) {
1070 memcpy(buf->data() + 64 * shaderMatrixCount, node->m_fillTransform.invertedData(), 64);
1071 m_fillTransform = node->m_fillTransform;
1075 const QPointF centerPoint = node->m_gradient.a;
1076 const QPointF focalPoint = node->m_gradient.b;
1077 const QPointF focalToCenter = centerPoint - focalPoint;
1078 const float centerRadius = node->m_gradient.v0;
1079 const float focalRadius = node->m_gradient.v1;
1081 if (!oldMaterial || m_focalPoint.x() != focalPoint.x() || m_focalPoint.y() != focalPoint.y()) {
1082 m_focalPoint = QVector2D(focalPoint.x(), focalPoint.y());
1083 Q_ASSERT(
sizeof(m_focalPoint) == 8);
1084 memcpy(buf->data() + 64 * shaderMatrixCount + 64, &m_focalPoint, 8);
1088 if (!oldMaterial || m_focalToCenter.x() != focalToCenter.x() || m_focalToCenter.y() != focalToCenter.y()) {
1089 m_focalToCenter = QVector2D(focalToCenter.x(), focalToCenter.y());
1090 Q_ASSERT(
sizeof(m_focalToCenter) == 8);
1091 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8, &m_focalToCenter, 8);
1095 if (!oldMaterial || m_centerRadius != centerRadius) {
1096 m_centerRadius = centerRadius;
1097 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8 + 8, &m_centerRadius, 4);
1101 if (!oldMaterial || m_focalRadius != focalRadius) {
1102 m_focalRadius = focalRadius;
1103 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8 + 8 + 4, &m_focalRadius, 4);
1107 if (state.isOpacityDirty()) {
1108 const float opacity = state.opacity();
1109 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8 + 8 + 4 + 4, &opacity, 4);
1117 QSGMaterial *newMaterial, QSGMaterial *)
1124 const QSGGradientCacheKey cacheKey(node->m_gradient.stops, QGradient::Spread(node->m_gradient.spread));
1125 QSGTexture *t = QSGGradientCache::cacheForRhi(state.rhi())->get(cacheKey);
1126 t->commitTextureOperations(state.rhi(), state.resourceUpdateBatch());
1132 static QSGMaterialType type;
1138 Q_ASSERT(other && type() == other->type());
1147 const QSGGradientCache::GradientDesc *ga = &a->m_gradient;
1148 const QSGGradientCache::GradientDesc *gb = &b->m_gradient;
1150 if (
int d = ga->spread - gb->spread)
1153 if (
int d = ga->a.x() - gb->a.x())
1155 if (
int d = ga->a.y() - gb->a.y())
1157 if (
int d = ga->b.x() - gb->b.x())
1159 if (
int d = ga->b.y() - gb->b.y())
1162 if (
int d = ga->v0 - gb->v0)
1164 if (
int d = ga->v1 - gb->v1)
1167 if (
int d = ga->stops.size() - gb->stops.size())
1170 for (
int i = 0; i < ga->stops.size(); ++i) {
1171 if (
int d = ga->stops[i].first - gb->stops[i].first)
1173 if (
int d = ga->stops[i].second.rgba() - gb->stops[i].second.rgba())
1177 if (
int d = a->m_fillTransform.compareTo(b->m_fillTransform))
1185 Q_UNUSED(renderMode);
1191 setShaderFileName(VertexStage, QStringLiteral(
":/qt-project.org/shapes/shaders_ng/conicalgradient.vert.qsb"), viewCount);
1192 setShaderFileName(FragmentStage, QStringLiteral(
":/qt-project.org/shapes/shaders_ng/conicalgradient.frag.qsb"), viewCount);
1196 QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
1198 Q_ASSERT(oldMaterial ==
nullptr || newMaterial->type() == oldMaterial->type());
1200 bool changed =
false;
1201 QByteArray *buf = state.uniformData();
1202 Q_ASSERT(buf->size() >= 80 + 64);
1203 const int shaderMatrixCount = newMaterial->viewCount();
1204 const int matrixCount = qMin(state.projectionMatrixCount(), shaderMatrixCount);
1206 if (state.isMatrixDirty()) {
1207 for (
int viewIndex = 0; viewIndex < matrixCount; ++viewIndex) {
1208 const QMatrix4x4 m = state.combinedMatrix();
1209 memcpy(buf->data() + 64 * viewIndex, m.constData(), 64);
1216 if (!oldMaterial || m_fillTransform != node->m_fillTransform) {
1217 memcpy(buf->data() + 64 * shaderMatrixCount, node->m_fillTransform.invertedData(), 64);
1218 m_fillTransform = node->m_fillTransform;
1222 const QPointF centerPoint = node->m_gradient.a;
1223 const float angle = -qDegreesToRadians(node->m_gradient.v0);
1225 if (!oldMaterial || m_centerPoint.x() != centerPoint.x() || m_centerPoint.y() != centerPoint.y()) {
1226 m_centerPoint = QVector2D(centerPoint.x(), centerPoint.y());
1227 Q_ASSERT(
sizeof(m_centerPoint) == 8);
1228 memcpy(buf->data() + 64 * shaderMatrixCount + 64, &m_centerPoint, 8);
1232 if (!oldMaterial || m_angle != angle) {
1234 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8, &m_angle, 4);
1238 if (state.isOpacityDirty()) {
1239 const float opacity = state.opacity();
1240 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8 + 4, &opacity, 4);
1248 QSGMaterial *newMaterial, QSGMaterial *)
1255 const QSGGradientCacheKey cacheKey(node->m_gradient.stops, QGradient::Spread(node->m_gradient.spread));
1256 QSGTexture *t = QSGGradientCache::cacheForRhi(state.rhi())->get(cacheKey);
1257 t->commitTextureOperations(state.rhi(), state.resourceUpdateBatch());
1263 static QSGMaterialType type;
1269 Q_ASSERT(other && type() == other->type());
1278 const QSGGradientCache::GradientDesc *ga = &a->m_gradient;
1279 const QSGGradientCache::GradientDesc *gb = &b->m_gradient;
1281 if (
int d = ga->a.x() - gb->a.x())
1283 if (
int d = ga->a.y() - gb->a.y())
1286 if (
int d = ga->v0 - gb->v0)
1289 if (
int d = ga->stops.size() - gb->stops.size())
1292 for (
int i = 0; i < ga->stops.size(); ++i) {
1293 if (
int d = ga->stops[i].first - gb->stops[i].first)
1295 if (
int d = ga->stops[i].second.rgba() - gb->stops[i].second.rgba())
1299 if (
int d = a->m_fillTransform.compareTo(b->m_fillTransform))
1307 Q_UNUSED(renderMode);
1313 setShaderFileName(VertexStage, QStringLiteral(
":/qt-project.org/shapes/shaders_ng/texturefill.vert.qsb"), viewCount);
1314 setShaderFileName(FragmentStage, QStringLiteral(
":/qt-project.org/shapes/shaders_ng/texturefill.frag.qsb"), viewCount);
1318 QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
1320 Q_ASSERT(oldMaterial ==
nullptr || newMaterial->type() == oldMaterial->type());
1322 bool changed =
false;
1323 QByteArray *buf = state.uniformData();
1324 const int shaderMatrixCount = newMaterial->viewCount();
1325 const int matrixCount = qMin(state.projectionMatrixCount(), shaderMatrixCount);
1326 Q_ASSERT(buf->size() >= 64 * shaderMatrixCount + 64 + 8 + 4);
1328 if (state.isMatrixDirty()) {
1329 for (
int viewIndex = 0; viewIndex < matrixCount; ++viewIndex) {
1330 const QMatrix4x4 m = state.combinedMatrix();
1331 memcpy(buf->data() + 64 * viewIndex, m.constData(), 64);
1338 if (!oldMaterial || m_fillTransform != node->m_fillTransform) {
1339 memcpy(buf->data() + 64 * shaderMatrixCount, node->m_fillTransform.invertedData(), 64);
1340 m_fillTransform = node->m_fillTransform;
1344 const QSizeF boundsSize = node->m_fillTextureProvider !=
nullptr && node->m_fillTextureProvider->texture() !=
nullptr
1345 ? node->m_fillTextureProvider->texture()->textureSize()
1349 const QVector2D boundsVector(boundsSize.width() / state.devicePixelRatio(),
1350 boundsSize.height() / state.devicePixelRatio());
1351 if (!oldMaterial || m_boundsSize != boundsVector) {
1352 m_boundsSize = boundsVector;
1353 Q_ASSERT(
sizeof(m_boundsSize) == 8);
1354 memcpy(buf->data() + 64 * shaderMatrixCount + 64, &m_boundsSize, 8);
1358 if (state.isOpacityDirty()) {
1359 const float opacity = state.opacity();
1360 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8, &opacity, 4);
1368 QSGMaterial *newMaterial, QSGMaterial *)
1375 if (node->m_fillTextureProvider !=
nullptr) {
1376 QSGTexture *providedTexture = node->m_fillTextureProvider->texture();
1377 if (providedTexture !=
nullptr) {
1378 if (providedTexture->isAtlasTexture()) {
1382 QSGTexture *newTexture = providedTexture->removedFromAtlas(state.resourceUpdateBatch());
1383 if (newTexture !=
nullptr)
1384 providedTexture = newTexture;
1387 providedTexture->commitTextureOperations(state.rhi(), state.resourceUpdateBatch());
1388 *texture = providedTexture;
1393 if (m->dummyTexture() ==
nullptr) {
1394 QSGPlainTexture *dummyTexture =
new QSGPlainTexture;
1395 dummyTexture->setFiltering(QSGTexture::Nearest);
1396 dummyTexture->setHorizontalWrapMode(QSGTexture::Repeat);
1397 dummyTexture->setVerticalWrapMode(QSGTexture::Repeat);
1398 QImage img(128, 128, QImage::Format_ARGB32_Premultiplied);
1400 dummyTexture->setImage(img);
1401 dummyTexture->commitTextureOperations(state.rhi(), state.resourceUpdateBatch());
1403 m->setDummyTexture(dummyTexture);
1406 *texture = m->dummyTexture();
1411 delete m_dummyTexture;
1416 static QSGMaterialType type;
1422 Q_ASSERT(other && type() == other->type());
1431 if (
int d = a->m_fillTransform.compareTo(b->m_fillTransform))
1434 const qintptr diff = qintptr(a->m_fillTextureProvider) - qintptr(b->m_fillTextureProvider);
1435 return diff < 0 ? -1 : (diff > 0 ? 1 : 0);
1440 Q_UNUSED(renderMode);
1446#include "moc_qquickshapegenericrenderer_p.cpp"
QSGMaterialType * type() const override
This function is called by the scene graph to query an identifier that is unique to the QSGMaterialSh...
QQuickShapeConicalGradientMaterial(QQuickShapeGenericStrokeFillNode *node)
int compare(const QSGMaterial *other) const override
Compares this material to other and returns 0 if they are equal; -1 if this material should sort befo...
QSGMaterialShader * createShader(QSGRendererInterface::RenderMode renderMode) const override
This function returns a new instance of a the QSGMaterialShader implementation used to render geometr...
QQuickShapeGenericStrokeFillNode * node() const
void updateSampledImage(RenderState &state, int binding, QSGTexture **texture, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to prepare use of sampled images in the shader,...
bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to get the contents of the shader program's uniform buffer...
QQuickShapeConicalGradientRhiShader(int viewCount)
bool supportsElementIndexUint
QQuickShapeGenericRenderer::Color4ub fillColor
QQuickShapeGenericRenderer::VertexContainerType fillVertices
QQuickShapeGenericRenderer::IndexContainerType fillIndices
QQuickShapeGenericStrokeFillNode * m_fillNode
QQuickShapeGenericStrokeFillNode * m_strokeNode
QQuickShapeGenericNode * m_next
void setAsyncCallback(void(*)(void *), void *) override
void setFillGradient(int index, QQuickShapeGradient *gradient) override
void setStrokeStyle(int index, QQuickShapePath::StrokeStyle strokeStyle, qreal dashOffset, const QList< qreal > &dashPattern) override
void setFillTransform(int index, const QSGTransform &transform) override
QList< quint32 > IndexContainerType
void setCosmeticStroke(int index, bool c) override
void setStrokeGradient(int index, QQuickShapeGradient *gradient) override
QList< QSGGeometry::ColoredPoint2D > VertexContainerType
void setPath(int index, const QPainterPath &path, QQuickShapePath::PathHints pathHints={}) override
void setStrokeColor(int index, const QColor &color) override
void setFillRule(int index, QQuickShapePath::FillRule fillRule) override
void setFillTextureProvider(int index, QQuickItem *textureProviderItem) override
void setFillColor(int index, const QColor &color) override
void setTriangulationScale(int index, qreal scale) override
void setJoinStyle(int index, QQuickShapePath::JoinStyle joinStyle, int miterLimit) override
void setStrokeWidth(int index, qreal w) override
~QQuickShapeGenericRenderer()
void setRootNode(QQuickShapeGenericNode *node)
void handleSceneChange(QQuickWindow *window) override
void beginSync(int totalCount, bool *countChanged) override
void setCapStyle(int index, QQuickShapePath::CapStyle capStyle) override
void updateNode() override
void endSync(bool async) override
void preprocess() override
Override this function to do processing on the node before it is rendered.
void activateMaterial(QQuickWindow *window, Material m)
QQuickShapeLinearGradientMaterial(QQuickShapeGenericStrokeFillNode *node)
QSGMaterialShader * createShader(QSGRendererInterface::RenderMode renderMode) const override
This function returns a new instance of a the QSGMaterialShader implementation used to render geometr...
int compare(const QSGMaterial *other) const override
Compares this material to other and returns 0 if they are equal; -1 if this material should sort befo...
QSGMaterialType * type() const override
This function is called by the scene graph to query an identifier that is unique to the QSGMaterialSh...
QQuickShapeGenericStrokeFillNode * node() const
void updateSampledImage(RenderState &state, int binding, QSGTexture **texture, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to prepare use of sampled images in the shader,...
QQuickShapeLinearGradientRhiShader(int viewCount)
bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to get the contents of the shader program's uniform buffer...
QQuickShapeGenericStrokeFillNode * node() const
QQuickShapeRadialGradientMaterial(QQuickShapeGenericStrokeFillNode *node)
QSGMaterialType * type() const override
This function is called by the scene graph to query an identifier that is unique to the QSGMaterialSh...
QSGMaterialShader * createShader(QSGRendererInterface::RenderMode renderMode) const override
This function returns a new instance of a the QSGMaterialShader implementation used to render geometr...
int compare(const QSGMaterial *other) const override
Compares this material to other and returns 0 if they are equal; -1 if this material should sort befo...
bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to get the contents of the shader program's uniform buffer...
QQuickShapeRadialGradientRhiShader(int viewCount)
void updateSampledImage(RenderState &state, int binding, QSGTexture **texture, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to prepare use of sampled images in the shader,...
QQuickShapeGenericRenderer::Color4ub strokeColor
QQuickShapeGenericRenderer::VertexContainerType strokeVertices
QQuickShapeTextureFillMaterial(QQuickShapeGenericStrokeFillNode *node)
QSGMaterialShader * createShader(QSGRendererInterface::RenderMode renderMode) const override
This function returns a new instance of a the QSGMaterialShader implementation used to render geometr...
int compare(const QSGMaterial *other) const override
Compares this material to other and returns 0 if they are equal; -1 if this material should sort befo...
QQuickShapeGenericStrokeFillNode * node() const
~QQuickShapeTextureFillMaterial() override
QSGMaterialType * type() const override
This function is called by the scene graph to query an identifier that is unique to the QSGMaterialSh...
QQuickShapeTextureFillRhiShader(int viewCount)
bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to get the contents of the shader program's uniform buffer...
void updateSampledImage(RenderState &state, int binding, QSGTexture **texture, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to prepare use of sampled images in the shader,...
Combined button and popup list for selecting options.
static QQuickShapeGenericRenderer::Color4ub colorToColor4ub(const QColor &c)
static QQuickAbstractPathRenderer::FillGradientType copyGenericGradient(const QQuickShapeGradient *gradient, QSGGradientCache::GradientDesc *dst)
#define QSG_RUNTIME_DESCRIPTION
void set(float nx, float ny, QQuickShapeGenericRenderer::Color4ub ncolor)