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;
314 m_asyncCallback = callback;
315 m_asyncCallbackData = data;
319static QThreadPool *pathWorkThreadPool =
nullptr;
321static void deletePathWorkThreadPool()
323 delete pathWorkThreadPool;
324 pathWorkThreadPool =
nullptr;
330#if !QT_CONFIG(thread)
336 bool didKickOffAsync =
false;
338 for (
int i = 0; i < m_sp.size(); ++i) {
339 ShapePathData &d(m_sp[i]);
343 m_accDirty |= d.syncDirty;
350 d.effectiveDirty |= d.syncDirty;
352 if (d.path.isEmpty()) {
353 d.fillVertices.clear();
354 d.fillIndices.clear();
355 d.strokeVertices.clear();
360 if (async && !pathWorkThreadPool) {
361 qAddPostRoutine(deletePathWorkThreadPool);
362 pathWorkThreadPool =
new QThreadPool;
363 const int idealCount = QThread::idealThreadCount();
364 pathWorkThreadPool->setMaxThreadCount(idealCount > 0 ? idealCount * 2 : 4);
367 auto testFeatureIndexUint = [](QQuickItem *item) ->
bool {
368 if (
auto *w = item->window()) {
369 if (
auto *rhi = QQuickWindowPrivate::get(w)->rhi)
370 return rhi->isFeatureSupported(QRhi::ElementIndexUint);
374 static bool supportsElementIndexUint = testFeatureIndexUint(m_item);
376 d.path.setFillRule(d.fillRule);
377 if (m_api == QSGRendererInterface::Unknown)
378 m_api = m_item->window()->rendererInterface()->graphicsApi();
381 r->setAutoDelete(
false);
388 r->triangulationScale = d.triangulationScale;
391 QObject::connect(r, &QQuickShapeFillRunnable::done, qApp, [
this, i](QQuickShapeFillRunnable *r) {
394 if (!r->orphaned && i < m_sp.size()) {
395 ShapePathData &d(m_sp[i]);
396 d.fillVertices = r->fillVertices;
397 d.fillIndices = r->fillIndices;
398 d.indexType = r->indexType;
399 d.pendingFill =
nullptr;
400 d.effectiveDirty |= DirtyFillGeom;
401 maybeUpdateAsyncItem();
405 didKickOffAsync =
true;
409 qtVectorPathForPath(r->path);
410 pathWorkThreadPool->start(r);
413 triangulateFill(d.path, d.fillColor, &d.fillVertices, &d.fillIndices, &d.indexType,
414 supportsElementIndexUint,
415 d.triangulationScale);
419 if ((d.syncDirty &
DirtyStrokeGeom) && d.strokeWidth > 0.0f && (d.strokeColor
.a || d.strokeGradientActive)) {
422 r->setAutoDelete(
false);
429 r->clipSize = QSize(m_item->width(), m_item->height());
430 r->triangulationScale = d.triangulationScale;
431 QObject::connect(r, &QQuickShapeStrokeRunnable::done, qApp, [
this, i](QQuickShapeStrokeRunnable *r) {
432 if (!r->orphaned && i < m_sp.size()) {
433 ShapePathData &d(m_sp[i]);
434 d.strokeVertices = r->strokeVertices;
435 d.pendingStroke =
nullptr;
436 d.effectiveDirty |= DirtyStrokeGeom;
437 maybeUpdateAsyncItem();
441 didKickOffAsync =
true;
445 qtVectorPathForPath(r->path);
446 pathWorkThreadPool->start(r);
449 triangulateStroke(d.path, d.pen, d.strokeColor, &d.strokeVertices,
450 QSize(m_item->width(), m_item->height()), d.triangulationScale);
455 if (!didKickOffAsync && async && m_asyncCallback)
456 m_asyncCallback(m_asyncCallbackData);
461 for (
const ShapePathData &d : std::as_const(m_sp)) {
462 if (d.pendingFill || d.pendingStroke)
468 m_asyncCallback(m_asyncCallbackData);
477 QSGGeometry::Type *indexType,
478 bool supportsElementIndexUint,
479 qreal triangulationScale)
481 const QVectorPath &vp = qtVectorPathForPath(path);
483 QTriangleSet ts = qTriangulate(vp, QTransform::fromScale(triangulationScale, triangulationScale), 1, supportsElementIndexUint);
484 const int vertexCount = ts.vertices.size() / 2;
485 fillVertices->resize(vertexCount);
487 const qreal *vsrc = ts.vertices.constData();
488 for (
int i = 0; i < vertexCount; ++i)
489 vdst[i]
.set(vsrc[i * 2] / triangulationScale
, vsrc[i * 2 + 1] / triangulationScale
, fillColor
);
491 size_t indexByteSize;
492 if (ts.indices.type() == QVertexIndexVector::UnsignedShort) {
493 *indexType = QSGGeometry::UnsignedShortType;
496 fillIndices->resize(ts.indices.size() / 2);
497 indexByteSize = ts.indices.size() *
sizeof(quint16);
499 *indexType = QSGGeometry::UnsignedIntType;
500 fillIndices->resize(ts.indices.size());
501 indexByteSize = ts.indices.size() *
sizeof(quint32);
503 memcpy(fillIndices->data(), ts.indices.data(), indexByteSize);
510 const QSize &clipSize,
511 qreal triangulationScale)
513 const QVectorPath &vp = qtVectorPathForPath(path);
514 const QRectF clip(QPointF(0, 0), clipSize);
515 const qreal inverseScale = 1.0 / triangulationScale;
517 QTriangulatingStroker stroker;
518 stroker.setInvScale(inverseScale);
520 if (pen.style() == Qt::SolidLine) {
521 stroker.process(vp, pen, clip, {});
523 QDashedStrokeProcessor dashStroker;
524 dashStroker.setInvScale(inverseScale);
525 dashStroker.process(vp, pen, clip, {});
526 QVectorPath dashStroke(dashStroker.points(), dashStroker.elementCount(),
527 dashStroker.elementTypes(), 0);
528 stroker.process(dashStroke, pen, clip, {});
531 if (!stroker.vertexCount()) {
532 strokeVertices->clear();
536 const int vertexCount = stroker.vertexCount() / 2;
537 strokeVertices->resize(vertexCount);
539 const float *vsrc = stroker.vertices();
540 for (
int i = 0; i < vertexCount; ++i)
541 vdst[i]
.set(vsrc[i * 2]
, vsrc[i * 2 + 1]
, strokeColor
);
546 if (m_rootNode != node) {
555 if (!m_rootNode || !m_accDirty)
571 for (ShapePathData &d : m_sp) {
574 *nodePtr =
new QQuickShapeGenericNode;
575 prevNode->m_next = *nodePtr;
576 prevNode->appendChildNode(*nodePtr);
579 QQuickShapeGenericNode *node = *nodePtr;
581 if (m_accDirty & DirtyList) {
582 d.effectiveDirty |= DirtyFillGeom | DirtyStrokeGeom | DirtyColor | DirtyFillGradient
583 | DirtyFillTransform | DirtyFillTexture | DirtyStrokeGradient;
586 if (!d.effectiveDirty) {
588 nodePtr = &node->m_next;
592 if (d.fillColor.a == 0) {
593 delete node->m_fillNode;
594 node->m_fillNode =
nullptr;
595 }
else if (!node->m_fillNode) {
596 node->m_fillNode =
new QQuickShapeGenericStrokeFillNode(m_item->window());
597 if (node->m_strokeNode)
598 node->removeChildNode(node->m_strokeNode);
599 node->appendChildNode(node->m_fillNode);
600 if (node->m_strokeNode)
601 node->appendChildNode(node->m_strokeNode);
602 d.effectiveDirty |= DirtyFillGeom;
605 if (d.strokeWidth <= 0.0f || d.strokeColor.a == 0) {
606 delete node->m_strokeNode;
607 node->m_strokeNode =
nullptr;
608 }
else if (!node->m_strokeNode) {
609 node->m_strokeNode =
new QQuickShapeGenericStrokeFillNode(m_item->window());
610 node->appendChildNode(node->m_strokeNode);
611 d.effectiveDirty |= DirtyStrokeGeom;
614 updateFillNode(&d, node);
615 updateStrokeNode(&d, node);
617 d.effectiveDirty = 0;
620 nodePtr = &node->m_next;
623 if (*nodePtr && prevNode) {
624 prevNode->removeChildNode(*nodePtr);
629 if (m_sp.isEmpty()) {
643 if (d->fillGradientActive) {
645 n->m_gradient = d->fillGradient;
649 bool needsUpdate = d->fillTextureProviderItem ==
nullptr && n->m_fillTextureProvider !=
nullptr;
651 && d->fillTextureProviderItem !=
nullptr
652 && n->m_fillTextureProvider != d->fillTextureProviderItem->textureProvider()) {
657 if (n->m_fillTextureProvider !=
nullptr) {
658 QObject::disconnect(n->m_fillTextureProvider, &QSGTextureProvider::textureChanged,
659 n, &QQuickShapeGenericStrokeFillNode::handleTextureChanged);
660 QObject::disconnect(n->m_fillTextureProvider, &QSGTextureProvider::destroyed,
661 n, &QQuickShapeGenericStrokeFillNode::handleTextureProviderDestroyed);
664 n->m_fillTextureProvider = d->fillTextureProviderItem ==
nullptr
666 : d->fillTextureProviderItem->textureProvider();
668 if (n->m_fillTextureProvider !=
nullptr) {
669 QObject::connect(n->m_fillTextureProvider, &QSGTextureProvider::textureChanged,
670 n, &QQuickShapeGenericStrokeFillNode::handleTextureChanged);
671 QObject::connect(n->m_fillTextureProvider, &QSGTextureProvider::destroyed,
672 n, &QQuickShapeGenericStrokeFillNode::handleTextureProviderDestroyed);
677 n->m_fillTransform = d->fillTransform;
690 updateShadowDataInNode(d, n);
692 QSGGeometry *g = n->geometry();
693 if (d->fillVertices.isEmpty()) {
694 if (g->vertexCount() || g->indexCount()) {
696 n->markDirty(QSGNode::DirtyGeometry);
701 if (d->fillGradientActive) {
703 switch (d->fillGradientActive) {
710 case ConicalGradient:
714 Q_UNREACHABLE_RETURN();
716 n->activateMaterial(m_item->window(), gradMat);
719 n->markDirty(QSGNode::DirtyMaterial);
724 }
else if (d->fillTextureProviderItem !=
nullptr) {
727 n->markDirty(QSGNode::DirtyMaterial);
731 if ((d->effectiveDirty &
DirtyColor) && !(d->effectiveDirty &
DirtyFillGeom) && d->fillTextureProviderItem ==
nullptr) {
732 ColoredVertex *vdst =
reinterpret_cast<ColoredVertex *>(g->vertexData());
733 for (
int i = 0; i < g->vertexCount(); ++i)
735 n->markDirty(QSGNode::DirtyGeometry);
740 const int indexCount = d->indexType == QSGGeometry::UnsignedShortType
741 ? d->fillIndices.size() * 2 : d->fillIndices.size();
742 if (g->indexType() != d->indexType) {
743 g =
new QSGGeometry(QSGGeometry::defaultAttributes_ColoredPoint2D(),
744 d->fillVertices.size(), indexCount, d->indexType);
747 g->allocate(d->fillVertices.size(), indexCount);
749 g->setDrawingMode(QSGGeometry::DrawTriangles);
751 memcpy(g->vertexData(), d->fillVertices.constData(), g->vertexCount() * g->sizeOfVertex());
752 memcpy(g->indexData(), d->fillIndices.constData(), g->indexCount() * g->sizeOfIndex());
754 n->markDirty(QSGNode::DirtyGeometry);
765 if (d->strokeGradientActive) {
767 n->m_gradient = d->strokeGradient;
770 QSGGeometry *g = n->geometry();
771 if (d->strokeVertices.isEmpty()) {
772 if (g->vertexCount() || g->indexCount()) {
774 n->markDirty(QSGNode::DirtyGeometry);
779 n->markDirty(QSGNode::DirtyGeometry);
784 if (!g->vertexCount())
785 n->markDirty(QSGNode::DirtyMaterial);
787 if (d->strokeGradientActive) {
789 switch (d->strokeGradientActive) {
796 case ConicalGradient:
800 Q_UNREACHABLE_RETURN();
802 n->activateMaterial(m_item->window(), gradMat);
805 n->markDirty(QSGNode::DirtyMaterial);
813 ColoredVertex *vdst =
reinterpret_cast<ColoredVertex *>(g->vertexData());
814 for (
int i = 0; i < g->vertexCount(); ++i)
820 g->allocate(d->strokeVertices.size(), 0);
821 g->setDrawingMode(QSGGeometry::DrawTriangleStrip);
822 memcpy(g->vertexData(), d->strokeVertices.constData(), g->vertexCount() * g->sizeOfVertex());
827 QSGRendererInterface::GraphicsApi api = window->rendererInterface()->graphicsApi();
829 if (api == QSGRendererInterface::OpenGL || QSGRendererInterface::isApiRhiBased(api))
830 return new QSGVertexColorMaterial;
832 qWarning(
"Vertex-color material: Unsupported graphics API %d", api);
839 QSGRendererInterface::GraphicsApi api = window->rendererInterface()->graphicsApi();
841 if (api == QSGRendererInterface::OpenGL || QSGRendererInterface::isApiRhiBased(api))
844 qWarning(
"Linear gradient material: Unsupported graphics API %d", api);
851 QSGRendererInterface::GraphicsApi api = window->rendererInterface()->graphicsApi();
853 if (api == QSGRendererInterface::OpenGL || QSGRendererInterface::isApiRhiBased(api))
856 qWarning(
"Radial gradient material: Unsupported graphics API %d", api);
863 QSGRendererInterface::GraphicsApi api = window->rendererInterface()->graphicsApi();
865 if (api == QSGRendererInterface::OpenGL || QSGRendererInterface::isApiRhiBased(api))
868 qWarning(
"Conical gradient material: Unsupported graphics API %d", api);
875 QSGRendererInterface::GraphicsApi api = window->rendererInterface()->graphicsApi();
877 if (api == QSGRendererInterface::OpenGL || QSGRendererInterface::isApiRhiBased(api))
880 qWarning(
"Texture fill material: Unsupported graphics API %d", api);
886 setShaderFileName(VertexStage, QStringLiteral(
":/qt-project.org/shapes/shaders_ng/lineargradient.vert.qsb"), viewCount);
887 setShaderFileName(FragmentStage, QStringLiteral(
":/qt-project.org/shapes/shaders_ng/lineargradient.frag.qsb"), viewCount);
891 QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
893 Q_ASSERT(oldMaterial ==
nullptr || newMaterial->type() == oldMaterial->type());
895 bool changed =
false;
896 QByteArray *buf = state.uniformData();
897 Q_ASSERT(buf->size() >= 84 + 64);
898 const int shaderMatrixCount = newMaterial->viewCount();
899 const int matrixCount = qMin(state.projectionMatrixCount(), shaderMatrixCount);
901 if (state.isMatrixDirty()) {
902 for (
int viewIndex = 0; viewIndex < matrixCount; ++viewIndex) {
903 const QMatrix4x4 m = state.combinedMatrix();
904 memcpy(buf->data() + 64 * viewIndex, m.constData(), 64);
911 if (!oldMaterial || m_fillTransform != node->m_fillTransform) {
912 memcpy(buf->data() + 64 * shaderMatrixCount, node->m_fillTransform.invertedData(), 64);
913 m_fillTransform = node->m_fillTransform;
917 if (!oldMaterial || m_gradA.x() != node->m_gradient.a.x() || m_gradA.y() != node->m_gradient.a.y()) {
918 m_gradA = QVector2D(node->m_gradient.a.x(), node->m_gradient.a.y());
919 Q_ASSERT(
sizeof(m_gradA) == 8);
920 memcpy(buf->data() + 64 * shaderMatrixCount + 64, &m_gradA, 8);
924 if (!oldMaterial || m_gradB.x() != node->m_gradient.b.x() || m_gradB.y() != node->m_gradient.b.y()) {
925 m_gradB = QVector2D(node->m_gradient.b.x(), node->m_gradient.b.y());
926 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8, &m_gradB, 8);
930 if (state.isOpacityDirty()) {
931 const float opacity = state.opacity();
932 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8 + 8, &opacity, 4);
940 QSGMaterial *newMaterial, QSGMaterial *)
947 const QSGGradientCacheKey cacheKey(node->m_gradient.stops, QGradient::Spread(node->m_gradient.spread));
948 QSGTexture *t = QSGGradientCache::cacheForRhi(state.rhi())->get(cacheKey);
949 t->commitTextureOperations(state.rhi(), state.resourceUpdateBatch());
955 static QSGMaterialType type;
961 Q_ASSERT(other && type() == other->type());
970 const QSGGradientCache::GradientDesc *ga = &a->m_gradient;
971 const QSGGradientCache::GradientDesc *gb = &b->m_gradient;
973 if (
int d = ga->spread - gb->spread)
976 if (
int d = ga->a.x() - gb->a.x())
978 if (
int d = ga->a.y() - gb->a.y())
980 if (
int d = ga->b.x() - gb->b.x())
982 if (
int d = ga->b.y() - gb->b.y())
985 if (
int d = ga->stops.size() - gb->stops.size())
988 for (
int i = 0; i < ga->stops.size(); ++i) {
989 if (
int d = ga->stops[i].first - gb->stops[i].first)
991 if (
int d = ga->stops[i].second.rgba() - gb->stops[i].second.rgba())
995 if (
int d = a->m_fillTransform.compareTo(b->m_fillTransform))
1003 Q_UNUSED(renderMode);
1009 setShaderFileName(VertexStage, QStringLiteral(
":/qt-project.org/shapes/shaders_ng/radialgradient.vert.qsb"), viewCount);
1010 setShaderFileName(FragmentStage, QStringLiteral(
":/qt-project.org/shapes/shaders_ng/radialgradient.frag.qsb"), viewCount);
1014 QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
1016 Q_ASSERT(oldMaterial ==
nullptr || newMaterial->type() == oldMaterial->type());
1018 bool changed =
false;
1019 QByteArray *buf = state.uniformData();
1020 Q_ASSERT(buf->size() >= 92 + 64);
1021 const int shaderMatrixCount = newMaterial->viewCount();
1022 const int matrixCount = qMin(state.projectionMatrixCount(), shaderMatrixCount);
1024 if (state.isMatrixDirty()) {
1025 for (
int viewIndex = 0; viewIndex < matrixCount; ++viewIndex) {
1026 const QMatrix4x4 m = state.combinedMatrix();
1027 memcpy(buf->data() + 64 * viewIndex, m.constData(), 64);
1034 if (!oldMaterial || m_fillTransform != node->m_fillTransform) {
1035 memcpy(buf->data() + 64 * shaderMatrixCount, node->m_fillTransform.invertedData(), 64);
1036 m_fillTransform = node->m_fillTransform;
1040 const QPointF centerPoint = node->m_gradient.a;
1041 const QPointF focalPoint = node->m_gradient.b;
1042 const QPointF focalToCenter = centerPoint - focalPoint;
1043 const float centerRadius = node->m_gradient.v0;
1044 const float focalRadius = node->m_gradient.v1;
1046 if (!oldMaterial || m_focalPoint.x() != focalPoint.x() || m_focalPoint.y() != focalPoint.y()) {
1047 m_focalPoint = QVector2D(focalPoint.x(), focalPoint.y());
1048 Q_ASSERT(
sizeof(m_focalPoint) == 8);
1049 memcpy(buf->data() + 64 * shaderMatrixCount + 64, &m_focalPoint, 8);
1053 if (!oldMaterial || m_focalToCenter.x() != focalToCenter.x() || m_focalToCenter.y() != focalToCenter.y()) {
1054 m_focalToCenter = QVector2D(focalToCenter.x(), focalToCenter.y());
1055 Q_ASSERT(
sizeof(m_focalToCenter) == 8);
1056 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8, &m_focalToCenter, 8);
1060 if (!oldMaterial || m_centerRadius != centerRadius) {
1061 m_centerRadius = centerRadius;
1062 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8 + 8, &m_centerRadius, 4);
1066 if (!oldMaterial || m_focalRadius != focalRadius) {
1067 m_focalRadius = focalRadius;
1068 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8 + 8 + 4, &m_focalRadius, 4);
1072 if (state.isOpacityDirty()) {
1073 const float opacity = state.opacity();
1074 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8 + 8 + 4 + 4, &opacity, 4);
1082 QSGMaterial *newMaterial, QSGMaterial *)
1089 const QSGGradientCacheKey cacheKey(node->m_gradient.stops, QGradient::Spread(node->m_gradient.spread));
1090 QSGTexture *t = QSGGradientCache::cacheForRhi(state.rhi())->get(cacheKey);
1091 t->commitTextureOperations(state.rhi(), state.resourceUpdateBatch());
1097 static QSGMaterialType type;
1103 Q_ASSERT(other && type() == other->type());
1112 const QSGGradientCache::GradientDesc *ga = &a->m_gradient;
1113 const QSGGradientCache::GradientDesc *gb = &b->m_gradient;
1115 if (
int d = ga->spread - gb->spread)
1118 if (
int d = ga->a.x() - gb->a.x())
1120 if (
int d = ga->a.y() - gb->a.y())
1122 if (
int d = ga->b.x() - gb->b.x())
1124 if (
int d = ga->b.y() - gb->b.y())
1127 if (
int d = ga->v0 - gb->v0)
1129 if (
int d = ga->v1 - gb->v1)
1132 if (
int d = ga->stops.size() - gb->stops.size())
1135 for (
int i = 0; i < ga->stops.size(); ++i) {
1136 if (
int d = ga->stops[i].first - gb->stops[i].first)
1138 if (
int d = ga->stops[i].second.rgba() - gb->stops[i].second.rgba())
1142 if (
int d = a->m_fillTransform.compareTo(b->m_fillTransform))
1150 Q_UNUSED(renderMode);
1156 setShaderFileName(VertexStage, QStringLiteral(
":/qt-project.org/shapes/shaders_ng/conicalgradient.vert.qsb"), viewCount);
1157 setShaderFileName(FragmentStage, QStringLiteral(
":/qt-project.org/shapes/shaders_ng/conicalgradient.frag.qsb"), viewCount);
1161 QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
1163 Q_ASSERT(oldMaterial ==
nullptr || newMaterial->type() == oldMaterial->type());
1165 bool changed =
false;
1166 QByteArray *buf = state.uniformData();
1167 Q_ASSERT(buf->size() >= 80 + 64);
1168 const int shaderMatrixCount = newMaterial->viewCount();
1169 const int matrixCount = qMin(state.projectionMatrixCount(), shaderMatrixCount);
1171 if (state.isMatrixDirty()) {
1172 for (
int viewIndex = 0; viewIndex < matrixCount; ++viewIndex) {
1173 const QMatrix4x4 m = state.combinedMatrix();
1174 memcpy(buf->data() + 64 * viewIndex, m.constData(), 64);
1181 if (!oldMaterial || m_fillTransform != node->m_fillTransform) {
1182 memcpy(buf->data() + 64 * shaderMatrixCount, node->m_fillTransform.invertedData(), 64);
1183 m_fillTransform = node->m_fillTransform;
1187 const QPointF centerPoint = node->m_gradient.a;
1188 const float angle = -qDegreesToRadians(node->m_gradient.v0);
1190 if (!oldMaterial || m_centerPoint.x() != centerPoint.x() || m_centerPoint.y() != centerPoint.y()) {
1191 m_centerPoint = QVector2D(centerPoint.x(), centerPoint.y());
1192 Q_ASSERT(
sizeof(m_centerPoint) == 8);
1193 memcpy(buf->data() + 64 * shaderMatrixCount + 64, &m_centerPoint, 8);
1197 if (!oldMaterial || m_angle != angle) {
1199 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8, &m_angle, 4);
1203 if (state.isOpacityDirty()) {
1204 const float opacity = state.opacity();
1205 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8 + 4, &opacity, 4);
1213 QSGMaterial *newMaterial, QSGMaterial *)
1220 const QSGGradientCacheKey cacheKey(node->m_gradient.stops, QGradient::Spread(node->m_gradient.spread));
1221 QSGTexture *t = QSGGradientCache::cacheForRhi(state.rhi())->get(cacheKey);
1222 t->commitTextureOperations(state.rhi(), state.resourceUpdateBatch());
1228 static QSGMaterialType type;
1234 Q_ASSERT(other && type() == other->type());
1243 const QSGGradientCache::GradientDesc *ga = &a->m_gradient;
1244 const QSGGradientCache::GradientDesc *gb = &b->m_gradient;
1246 if (
int d = ga->a.x() - gb->a.x())
1248 if (
int d = ga->a.y() - gb->a.y())
1251 if (
int d = ga->v0 - gb->v0)
1254 if (
int d = ga->stops.size() - gb->stops.size())
1257 for (
int i = 0; i < ga->stops.size(); ++i) {
1258 if (
int d = ga->stops[i].first - gb->stops[i].first)
1260 if (
int d = ga->stops[i].second.rgba() - gb->stops[i].second.rgba())
1264 if (
int d = a->m_fillTransform.compareTo(b->m_fillTransform))
1272 Q_UNUSED(renderMode);
1278 setShaderFileName(VertexStage, QStringLiteral(
":/qt-project.org/shapes/shaders_ng/texturefill.vert.qsb"), viewCount);
1279 setShaderFileName(FragmentStage, QStringLiteral(
":/qt-project.org/shapes/shaders_ng/texturefill.frag.qsb"), viewCount);
1283 QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
1285 Q_ASSERT(oldMaterial ==
nullptr || newMaterial->type() == oldMaterial->type());
1287 bool changed =
false;
1288 QByteArray *buf = state.uniformData();
1289 const int shaderMatrixCount = newMaterial->viewCount();
1290 const int matrixCount = qMin(state.projectionMatrixCount(), shaderMatrixCount);
1291 Q_ASSERT(buf->size() >= 64 * shaderMatrixCount + 64 + 8 + 4);
1293 if (state.isMatrixDirty()) {
1294 for (
int viewIndex = 0; viewIndex < matrixCount; ++viewIndex) {
1295 const QMatrix4x4 m = state.combinedMatrix();
1296 memcpy(buf->data() + 64 * viewIndex, m.constData(), 64);
1303 if (!oldMaterial || m_fillTransform != node->m_fillTransform) {
1304 memcpy(buf->data() + 64 * shaderMatrixCount, node->m_fillTransform.invertedData(), 64);
1305 m_fillTransform = node->m_fillTransform;
1309 const QSizeF boundsSize = node->m_fillTextureProvider !=
nullptr && node->m_fillTextureProvider->texture() !=
nullptr
1310 ? node->m_fillTextureProvider->texture()->textureSize()
1314 const QVector2D boundsVector(boundsSize.width() / state.devicePixelRatio(),
1315 boundsSize.height() / state.devicePixelRatio());
1316 if (!oldMaterial || m_boundsSize != boundsVector) {
1317 m_boundsSize = boundsVector;
1318 Q_ASSERT(
sizeof(m_boundsSize) == 8);
1319 memcpy(buf->data() + 64 * shaderMatrixCount + 64, &m_boundsSize, 8);
1323 if (state.isOpacityDirty()) {
1324 const float opacity = state.opacity();
1325 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8, &opacity, 4);
1333 QSGMaterial *newMaterial, QSGMaterial *)
1340 if (node->m_fillTextureProvider !=
nullptr) {
1341 QSGTexture *providedTexture = node->m_fillTextureProvider->texture();
1342 if (providedTexture !=
nullptr) {
1343 if (providedTexture->isAtlasTexture()) {
1347 QSGTexture *newTexture = providedTexture->removedFromAtlas(state.resourceUpdateBatch());
1348 if (newTexture !=
nullptr)
1349 providedTexture = newTexture;
1352 providedTexture->commitTextureOperations(state.rhi(), state.resourceUpdateBatch());
1353 *texture = providedTexture;
1358 if (m->dummyTexture() ==
nullptr) {
1359 QSGPlainTexture *dummyTexture =
new QSGPlainTexture;
1360 dummyTexture->setFiltering(QSGTexture::Nearest);
1361 dummyTexture->setHorizontalWrapMode(QSGTexture::Repeat);
1362 dummyTexture->setVerticalWrapMode(QSGTexture::Repeat);
1363 QImage img(128, 128, QImage::Format_ARGB32_Premultiplied);
1365 dummyTexture->setImage(img);
1366 dummyTexture->commitTextureOperations(state.rhi(), state.resourceUpdateBatch());
1368 m->setDummyTexture(dummyTexture);
1371 *texture = m->dummyTexture();
1376 delete m_dummyTexture;
1381 static QSGMaterialType type;
1387 Q_ASSERT(other && type() == other->type());
1396 if (
int d = a->m_fillTransform.compareTo(b->m_fillTransform))
1399 const qintptr diff = qintptr(a->m_fillTextureProvider) - qintptr(b->m_fillTextureProvider);
1400 return diff < 0 ? -1 : (diff > 0 ? 1 : 0);
1405 Q_UNUSED(renderMode);
1411#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)