5#include <QtGui/private/qtriangulator_p.h>
6#include <QtGui/private/qtriangulatingstroker_p.h>
8#include <QSGVertexColorMaterial>
9#include <QSGTextureProvider>
10#include <private/qsgplaintexture_p.h>
12#include <QtQuick/private/qsggradientcache_p.h>
33 c.getRgbF(&r, &g, &b, &a);
35 uchar(qRound(r * a * 255)),
36 uchar(qRound(g * a * 255)),
37 uchar(qRound(b * a * 255)),
38 uchar(qRound(a * 255))
46 setFlag(QSGNode::OwnsGeometry,
true);
47 setFlag(QSGNode::UsePreprocess,
true);
48 setGeometry(
new QSGGeometry(QSGGeometry::defaultAttributes_ColoredPoint2D(), 0, 0));
49 activateMaterial(window, MatSolidColor);
51 qsgnode_set_description(
this, QLatin1String(
"stroke-fill"));
61 m_material.reset(QQuickShapeGenericMaterialFactory::createVertexColor(window));
63 case MatLinearGradient:
64 m_material.reset(QQuickShapeGenericMaterialFactory::createLinearGradient(window,
this));
66 case MatRadialGradient:
67 m_material.reset(QQuickShapeGenericMaterialFactory::createRadialGradient(window,
this));
69 case MatConicalGradient:
70 m_material.reset(QQuickShapeGenericMaterialFactory::createConicalGradient(window,
this));
73 m_material.reset(QQuickShapeGenericMaterialFactory::createTextureFill(window,
this));
76 qWarning(
"Unknown material %d", m);
80 if (material() != m_material.data())
81 setMaterial(m_material.data());
86 if (m_fillTextureProvider !=
nullptr) {
87 if (QSGDynamicTexture *texture = qobject_cast<QSGDynamicTexture *>(m_fillTextureProvider->texture()))
88 texture->updateTexture();
94 markDirty(QSGNode::DirtyMaterial);
99 m_fillTextureProvider =
nullptr;
100 markDirty(QSGNode::DirtyMaterial);
105 for (ShapePathData &d : m_sp) {
107 d.pendingFill->orphaned =
true;
109 d.pendingStroke->orphaned =
true;
118 for (
int i = totalCount; i < m_sp.size(); i++)
119 setFillTextureProvider(i,
nullptr);
121 if (m_sp.size() != totalCount) {
122 m_sp.resize(totalCount);
124 *countChanged =
true;
126 *countChanged =
false;
128 for (ShapePathData &d : m_sp)
134 ShapePathData &d(m_sp[index]);
141 ShapePathData &d(m_sp[index]);
142 const bool wasTransparent = d.strokeColor
.a == 0;
143 d.strokeColor = colorToColor4ub(color);
144 const bool isTransparent = d.strokeColor
.a == 0;
146 if (wasTransparent && !isTransparent)
152 ShapePathData &d(m_sp[index]);
161 ShapePathData &d(m_sp[index]);
162 d.pen.setCosmetic(c);
170 ShapePathData &d(m_sp[index]);
171 const bool wasTransparent = d.fillColor
.a == 0;
172 d.fillColor = colorToColor4ub(color);
173 const bool isTransparent = d.fillColor
.a == 0;
175 if (wasTransparent && !isTransparent)
181 ShapePathData &d(m_sp[index]);
182 d.fillRule = Qt::FillRule(fillRule);
188 ShapePathData &d(m_sp[index]);
189 d.pen.setJoinStyle(Qt::PenJoinStyle(joinStyle));
190 d.pen.setMiterLimit(miterLimit);
196 ShapePathData &d(m_sp[index]);
197 d.pen.setCapStyle(Qt::PenCapStyle(capStyle));
202 qreal dashOffset,
const QList<qreal> &dashPattern)
204 ShapePathData &d(m_sp[index]);
205 d.pen.setStyle(Qt::PenStyle(strokeStyle));
206 if (strokeStyle == QQuickShapePath::DashLine) {
207 d.pen.setDashPattern(dashPattern);
208 d.pen.setDashOffset(dashOffset);
215 ShapePathData &d(m_sp[index]);
217 d.fillGradient.stops = gradient->gradientStops();
218 d.fillGradient.spread = QGradient::Spread(gradient->spread());
219 if (QQuickShapeLinearGradient *g = qobject_cast<QQuickShapeLinearGradient *>(gradient)) {
220 d.fillGradientActive = LinearGradient;
221 d.fillGradient.a = QPointF(g->x1(), g->y1());
222 d.fillGradient.b = QPointF(g->x2(), g->y2());
223 }
else if (QQuickShapeRadialGradient *g = qobject_cast<QQuickShapeRadialGradient *>(gradient)) {
224 d.fillGradientActive = RadialGradient;
225 d.fillGradient.a = QPointF(g->centerX(), g->centerY());
226 d.fillGradient.b = QPointF(g->focalX(), g->focalY());
227 d.fillGradient.v0 = g->centerRadius();
228 d.fillGradient.v1 = g->focalRadius();
229 }
else if (QQuickShapeConicalGradient *g = qobject_cast<QQuickShapeConicalGradient *>(gradient)) {
230 d.fillGradientActive = ConicalGradient;
231 d.fillGradient.a = QPointF(g->centerX(), g->centerY());
232 d.fillGradient.v0 = g->angle();
237 d.fillGradientActive = NoGradient;
244 ShapePathData &d(m_sp[index]);
245 if ((d.fillTextureProviderItem ==
nullptr) != (textureProviderItem ==
nullptr))
247 if (d.fillTextureProviderItem !=
nullptr)
248 QQuickItemPrivate::get(d.fillTextureProviderItem)->derefWindow();
249 d.fillTextureProviderItem = textureProviderItem;
250 if (d.fillTextureProviderItem !=
nullptr)
251 QQuickItemPrivate::get(d.fillTextureProviderItem)->refWindow(m_item->window());
257 for (
auto &pathData : m_sp) {
258 if (pathData.fillTextureProviderItem !=
nullptr) {
259 if (window ==
nullptr)
260 QQuickItemPrivate::get(pathData.fillTextureProviderItem)->derefWindow();
262 QQuickItemPrivate::get(pathData.fillTextureProviderItem)->refWindow(window);
270 ShapePathData &d(m_sp[index]);
271 d.fillTransform = transform;
277 ShapePathData &d(m_sp[index]);
278 d.triangulationScale = scale;
297 m_asyncCallback = callback;
298 m_asyncCallbackData = data;
302static QThreadPool *pathWorkThreadPool =
nullptr;
304static void deletePathWorkThreadPool()
306 delete pathWorkThreadPool;
307 pathWorkThreadPool =
nullptr;
313#if !QT_CONFIG(thread)
319 bool didKickOffAsync =
false;
321 for (
int i = 0; i < m_sp.size(); ++i) {
322 ShapePathData &d(m_sp[i]);
326 m_accDirty |= d.syncDirty;
333 d.effectiveDirty |= d.syncDirty;
335 if (d.path.isEmpty()) {
336 d.fillVertices.clear();
337 d.fillIndices.clear();
338 d.strokeVertices.clear();
343 if (async && !pathWorkThreadPool) {
344 qAddPostRoutine(deletePathWorkThreadPool);
345 pathWorkThreadPool =
new QThreadPool;
346 const int idealCount = QThread::idealThreadCount();
347 pathWorkThreadPool->setMaxThreadCount(idealCount > 0 ? idealCount * 2 : 4);
350 auto testFeatureIndexUint = [](QQuickItem *item) ->
bool {
351 if (
auto *w = item->window()) {
352 if (
auto *rhi = QQuickWindowPrivate::get(w)->rhi)
353 return rhi->isFeatureSupported(QRhi::ElementIndexUint);
357 static bool supportsElementIndexUint = testFeatureIndexUint(m_item);
359 d.path.setFillRule(d.fillRule);
360 if (m_api == QSGRendererInterface::Unknown)
361 m_api = m_item->window()->rendererInterface()->graphicsApi();
364 r->setAutoDelete(
false);
371 r->triangulationScale = d.triangulationScale;
374 QObject::connect(r, &QQuickShapeFillRunnable::done, qApp, [
this, i](QQuickShapeFillRunnable *r) {
377 if (!r->orphaned && i < m_sp.size()) {
378 ShapePathData &d(m_sp[i]);
379 d.fillVertices = r->fillVertices;
380 d.fillIndices = r->fillIndices;
381 d.indexType = r->indexType;
382 d.pendingFill =
nullptr;
383 d.effectiveDirty |= DirtyFillGeom;
384 maybeUpdateAsyncItem();
388 didKickOffAsync =
true;
392 qtVectorPathForPath(r->path);
393 pathWorkThreadPool->start(r);
396 triangulateFill(d.path, d.fillColor, &d.fillVertices, &d.fillIndices, &d.indexType,
397 supportsElementIndexUint,
398 d.triangulationScale);
402 if ((d.syncDirty &
DirtyStrokeGeom) && d.strokeWidth > 0.0f && d.strokeColor
.a) {
405 r->setAutoDelete(
false);
412 r->clipSize = QSize(m_item->width(), m_item->height());
413 r->triangulationScale = d.triangulationScale;
414 QObject::connect(r, &QQuickShapeStrokeRunnable::done, qApp, [
this, i](QQuickShapeStrokeRunnable *r) {
415 if (!r->orphaned && i < m_sp.size()) {
416 ShapePathData &d(m_sp[i]);
417 d.strokeVertices = r->strokeVertices;
418 d.pendingStroke =
nullptr;
419 d.effectiveDirty |= DirtyStrokeGeom;
420 maybeUpdateAsyncItem();
424 didKickOffAsync =
true;
428 qtVectorPathForPath(r->path);
429 pathWorkThreadPool->start(r);
432 triangulateStroke(d.path, d.pen, d.strokeColor, &d.strokeVertices,
433 QSize(m_item->width(), m_item->height()), d.triangulationScale);
438 if (!didKickOffAsync && async && m_asyncCallback)
439 m_asyncCallback(m_asyncCallbackData);
444 for (
const ShapePathData &d : std::as_const(m_sp)) {
445 if (d.pendingFill || d.pendingStroke)
451 m_asyncCallback(m_asyncCallbackData);
460 QSGGeometry::Type *indexType,
461 bool supportsElementIndexUint,
462 qreal triangulationScale)
464 const QVectorPath &vp = qtVectorPathForPath(path);
466 QTriangleSet ts = qTriangulate(vp, QTransform::fromScale(triangulationScale, triangulationScale), 1, supportsElementIndexUint);
467 const int vertexCount = ts.vertices.size() / 2;
468 fillVertices->resize(vertexCount);
470 const qreal *vsrc = ts.vertices.constData();
471 for (
int i = 0; i < vertexCount; ++i)
472 vdst[i]
.set(vsrc[i * 2] / triangulationScale
, vsrc[i * 2 + 1] / triangulationScale
, fillColor
);
474 size_t indexByteSize;
475 if (ts.indices.type() == QVertexIndexVector::UnsignedShort) {
476 *indexType = QSGGeometry::UnsignedShortType;
479 fillIndices->resize(ts.indices.size() / 2);
480 indexByteSize = ts.indices.size() *
sizeof(quint16);
482 *indexType = QSGGeometry::UnsignedIntType;
483 fillIndices->resize(ts.indices.size());
484 indexByteSize = ts.indices.size() *
sizeof(quint32);
486 memcpy(fillIndices->data(), ts.indices.data(), indexByteSize);
493 const QSize &clipSize,
494 qreal triangulationScale)
496 const QVectorPath &vp = qtVectorPathForPath(path);
497 const QRectF clip(QPointF(0, 0), clipSize);
498 const qreal inverseScale = 1.0 / triangulationScale;
500 QTriangulatingStroker stroker;
501 stroker.setInvScale(inverseScale);
503 if (pen.style() == Qt::SolidLine) {
504 stroker.process(vp, pen, clip, {});
506 QDashedStrokeProcessor dashStroker;
507 dashStroker.setInvScale(inverseScale);
508 dashStroker.process(vp, pen, clip, {});
509 QVectorPath dashStroke(dashStroker.points(), dashStroker.elementCount(),
510 dashStroker.elementTypes(), 0);
511 stroker.process(dashStroke, pen, clip, {});
514 if (!stroker.vertexCount()) {
515 strokeVertices->clear();
519 const int vertexCount = stroker.vertexCount() / 2;
520 strokeVertices->resize(vertexCount);
522 const float *vsrc = stroker.vertices();
523 for (
int i = 0; i < vertexCount; ++i)
524 vdst[i]
.set(vsrc[i * 2]
, vsrc[i * 2 + 1]
, strokeColor
);
529 if (m_rootNode != node) {
538 if (!m_rootNode || !m_accDirty)
554 for (ShapePathData &d : m_sp) {
557 *nodePtr =
new QQuickShapeGenericNode;
558 prevNode->m_next = *nodePtr;
559 prevNode->appendChildNode(*nodePtr);
562 QQuickShapeGenericNode *node = *nodePtr;
564 if (m_accDirty & DirtyList)
565 d.effectiveDirty |= DirtyFillGeom | DirtyStrokeGeom | DirtyColor | DirtyFillGradient | DirtyFillTransform | DirtyFillTexture;
567 if (!d.effectiveDirty) {
569 nodePtr = &node->m_next;
573 if (d.fillColor.a == 0) {
574 delete node->m_fillNode;
575 node->m_fillNode =
nullptr;
576 }
else if (!node->m_fillNode) {
577 node->m_fillNode =
new QQuickShapeGenericStrokeFillNode(m_item->window());
578 if (node->m_strokeNode)
579 node->removeChildNode(node->m_strokeNode);
580 node->appendChildNode(node->m_fillNode);
581 if (node->m_strokeNode)
582 node->appendChildNode(node->m_strokeNode);
583 d.effectiveDirty |= DirtyFillGeom;
586 if (d.strokeWidth <= 0.0f || d.strokeColor.a == 0) {
587 delete node->m_strokeNode;
588 node->m_strokeNode =
nullptr;
589 }
else if (!node->m_strokeNode) {
590 node->m_strokeNode =
new QQuickShapeGenericStrokeFillNode(m_item->window());
591 node->appendChildNode(node->m_strokeNode);
592 d.effectiveDirty |= DirtyStrokeGeom;
595 updateFillNode(&d, node);
596 updateStrokeNode(&d, node);
598 d.effectiveDirty = 0;
601 nodePtr = &node->m_next;
604 if (*nodePtr && prevNode) {
605 prevNode->removeChildNode(*nodePtr);
610 if (m_sp.isEmpty()) {
624 if (d->fillGradientActive) {
626 n->m_fillGradient = d->fillGradient;
629 bool needsUpdate = d->fillTextureProviderItem ==
nullptr && n->m_fillTextureProvider !=
nullptr;
631 && d->fillTextureProviderItem !=
nullptr
632 && n->m_fillTextureProvider != d->fillTextureProviderItem->textureProvider()) {
637 if (n->m_fillTextureProvider !=
nullptr) {
638 QObject::disconnect(n->m_fillTextureProvider, &QSGTextureProvider::textureChanged,
639 n, &QQuickShapeGenericStrokeFillNode::handleTextureChanged);
640 QObject::disconnect(n->m_fillTextureProvider, &QSGTextureProvider::destroyed,
641 n, &QQuickShapeGenericStrokeFillNode::handleTextureProviderDestroyed);
644 n->m_fillTextureProvider = d->fillTextureProviderItem ==
nullptr
646 : d->fillTextureProviderItem->textureProvider();
648 if (n->m_fillTextureProvider !=
nullptr) {
649 QObject::connect(n->m_fillTextureProvider, &QSGTextureProvider::textureChanged,
650 n, &QQuickShapeGenericStrokeFillNode::handleTextureChanged);
651 QObject::connect(n->m_fillTextureProvider, &QSGTextureProvider::destroyed,
652 n, &QQuickShapeGenericStrokeFillNode::handleTextureProviderDestroyed);
657 n->m_fillTransform = d->fillTransform;
670 updateShadowDataInNode(d, n);
672 QSGGeometry *g = n->geometry();
673 if (d->fillVertices.isEmpty()) {
674 if (g->vertexCount() || g->indexCount()) {
676 n->markDirty(QSGNode::DirtyGeometry);
681 if (d->fillGradientActive) {
683 switch (d->fillGradientActive) {
690 case ConicalGradient:
694 Q_UNREACHABLE_RETURN();
696 n->activateMaterial(m_item->window(), gradMat);
699 n->markDirty(QSGNode::DirtyMaterial);
704 }
else if (d->fillTextureProviderItem !=
nullptr) {
707 n->markDirty(QSGNode::DirtyMaterial);
711 if ((d->effectiveDirty &
DirtyColor) && !(d->effectiveDirty &
DirtyFillGeom) && d->fillTextureProviderItem ==
nullptr) {
712 ColoredVertex *vdst =
reinterpret_cast<ColoredVertex *>(g->vertexData());
713 for (
int i = 0; i < g->vertexCount(); ++i)
715 n->markDirty(QSGNode::DirtyGeometry);
720 const int indexCount = d->indexType == QSGGeometry::UnsignedShortType
721 ? d->fillIndices.size() * 2 : d->fillIndices.size();
722 if (g->indexType() != d->indexType) {
723 g =
new QSGGeometry(QSGGeometry::defaultAttributes_ColoredPoint2D(),
724 d->fillVertices.size(), indexCount, d->indexType);
727 g->allocate(d->fillVertices.size(), indexCount);
729 g->setDrawingMode(QSGGeometry::DrawTriangles);
731 memcpy(g->vertexData(), d->fillVertices.constData(), g->vertexCount() * g->sizeOfVertex());
732 memcpy(g->indexData(), d->fillIndices.constData(), g->indexCount() * g->sizeOfIndex());
734 n->markDirty(QSGNode::DirtyGeometry);
745 QSGGeometry *g = n->geometry();
746 if (d->strokeVertices.isEmpty()) {
747 if (g->vertexCount() || g->indexCount()) {
749 n->markDirty(QSGNode::DirtyGeometry);
754 n->markDirty(QSGNode::DirtyGeometry);
759 if (!g->vertexCount())
760 n->markDirty(QSGNode::DirtyMaterial);
763 ColoredVertex *vdst =
reinterpret_cast<ColoredVertex *>(g->vertexData());
764 for (
int i = 0; i < g->vertexCount(); ++i)
769 g->allocate(d->strokeVertices.size(), 0);
770 g->setDrawingMode(QSGGeometry::DrawTriangleStrip);
771 memcpy(g->vertexData(), d->strokeVertices.constData(), g->vertexCount() * g->sizeOfVertex());
776 QSGRendererInterface::GraphicsApi api = window->rendererInterface()->graphicsApi();
778 if (api == QSGRendererInterface::OpenGL || QSGRendererInterface::isApiRhiBased(api))
779 return new QSGVertexColorMaterial;
781 qWarning(
"Vertex-color material: Unsupported graphics API %d", api);
788 QSGRendererInterface::GraphicsApi api = window->rendererInterface()->graphicsApi();
790 if (api == QSGRendererInterface::OpenGL || QSGRendererInterface::isApiRhiBased(api))
793 qWarning(
"Linear gradient material: Unsupported graphics API %d", api);
800 QSGRendererInterface::GraphicsApi api = window->rendererInterface()->graphicsApi();
802 if (api == QSGRendererInterface::OpenGL || QSGRendererInterface::isApiRhiBased(api))
805 qWarning(
"Radial gradient material: Unsupported graphics API %d", api);
812 QSGRendererInterface::GraphicsApi api = window->rendererInterface()->graphicsApi();
814 if (api == QSGRendererInterface::OpenGL || QSGRendererInterface::isApiRhiBased(api))
817 qWarning(
"Conical gradient material: Unsupported graphics API %d", api);
824 QSGRendererInterface::GraphicsApi api = window->rendererInterface()->graphicsApi();
826 if (api == QSGRendererInterface::OpenGL || QSGRendererInterface::isApiRhiBased(api))
829 qWarning(
"Texture fill material: Unsupported graphics API %d", api);
835 setShaderFileName(VertexStage, QStringLiteral(
":/qt-project.org/shapes/shaders_ng/lineargradient.vert.qsb"), viewCount);
836 setShaderFileName(FragmentStage, QStringLiteral(
":/qt-project.org/shapes/shaders_ng/lineargradient.frag.qsb"), viewCount);
840 QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
842 Q_ASSERT(oldMaterial ==
nullptr || newMaterial->type() == oldMaterial->type());
844 bool changed =
false;
845 QByteArray *buf = state.uniformData();
846 Q_ASSERT(buf->size() >= 84 + 64);
847 const int shaderMatrixCount = newMaterial->viewCount();
848 const int matrixCount = qMin(state.projectionMatrixCount(), shaderMatrixCount);
850 if (state.isMatrixDirty()) {
851 for (
int viewIndex = 0; viewIndex < matrixCount; ++viewIndex) {
852 const QMatrix4x4 m = state.combinedMatrix();
853 memcpy(buf->data() + 64 * viewIndex, m.constData(), 64);
860 if (!oldMaterial || m_fillTransform != node->m_fillTransform) {
861 memcpy(buf->data() + 64 * shaderMatrixCount, node->m_fillTransform.invertedData(), 64);
862 m_fillTransform = node->m_fillTransform;
866 if (!oldMaterial || m_gradA.x() != node->m_fillGradient.a.x() || m_gradA.y() != node->m_fillGradient.a.y()) {
867 m_gradA = QVector2D(node->m_fillGradient.a.x(), node->m_fillGradient.a.y());
868 Q_ASSERT(
sizeof(m_gradA) == 8);
869 memcpy(buf->data() + 64 * shaderMatrixCount + 64, &m_gradA, 8);
873 if (!oldMaterial || m_gradB.x() != node->m_fillGradient.b.x() || m_gradB.y() != node->m_fillGradient.b.y()) {
874 m_gradB = QVector2D(node->m_fillGradient.b.x(), node->m_fillGradient.b.y());
875 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8, &m_gradB, 8);
879 if (state.isOpacityDirty()) {
880 const float opacity = state.opacity();
881 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8 + 8, &opacity, 4);
889 QSGMaterial *newMaterial, QSGMaterial *)
896 const QSGGradientCacheKey cacheKey(node->m_fillGradient.stops, QGradient::Spread(node->m_fillGradient.spread));
897 QSGTexture *t = QSGGradientCache::cacheForRhi(state.rhi())->get(cacheKey);
898 t->commitTextureOperations(state.rhi(), state.resourceUpdateBatch());
904 static QSGMaterialType type;
910 Q_ASSERT(other && type() == other->type());
919 const QSGGradientCache::GradientDesc *ga = &a->m_fillGradient;
920 const QSGGradientCache::GradientDesc *gb = &b->m_fillGradient;
922 if (
int d = ga->spread - gb->spread)
925 if (
int d = ga->a.x() - gb->a.x())
927 if (
int d = ga->a.y() - gb->a.y())
929 if (
int d = ga->b.x() - gb->b.x())
931 if (
int d = ga->b.y() - gb->b.y())
934 if (
int d = ga->stops.size() - gb->stops.size())
937 for (
int i = 0; i < ga->stops.size(); ++i) {
938 if (
int d = ga->stops[i].first - gb->stops[i].first)
940 if (
int d = ga->stops[i].second.rgba() - gb->stops[i].second.rgba())
944 if (
int d = a->m_fillTransform.compareTo(b->m_fillTransform))
952 Q_UNUSED(renderMode);
958 setShaderFileName(VertexStage, QStringLiteral(
":/qt-project.org/shapes/shaders_ng/radialgradient.vert.qsb"), viewCount);
959 setShaderFileName(FragmentStage, QStringLiteral(
":/qt-project.org/shapes/shaders_ng/radialgradient.frag.qsb"), viewCount);
963 QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
965 Q_ASSERT(oldMaterial ==
nullptr || newMaterial->type() == oldMaterial->type());
967 bool changed =
false;
968 QByteArray *buf = state.uniformData();
969 Q_ASSERT(buf->size() >= 92 + 64);
970 const int shaderMatrixCount = newMaterial->viewCount();
971 const int matrixCount = qMin(state.projectionMatrixCount(), shaderMatrixCount);
973 if (state.isMatrixDirty()) {
974 for (
int viewIndex = 0; viewIndex < matrixCount; ++viewIndex) {
975 const QMatrix4x4 m = state.combinedMatrix();
976 memcpy(buf->data() + 64 * viewIndex, m.constData(), 64);
983 if (!oldMaterial || m_fillTransform != node->m_fillTransform) {
984 memcpy(buf->data() + 64 * shaderMatrixCount, node->m_fillTransform.invertedData(), 64);
985 m_fillTransform = node->m_fillTransform;
989 const QPointF centerPoint = node->m_fillGradient.a;
990 const QPointF focalPoint = node->m_fillGradient.b;
991 const QPointF focalToCenter = centerPoint - focalPoint;
992 const float centerRadius = node->m_fillGradient.v0;
993 const float focalRadius = node->m_fillGradient.v1;
995 if (!oldMaterial || m_focalPoint.x() != focalPoint.x() || m_focalPoint.y() != focalPoint.y()) {
996 m_focalPoint = QVector2D(focalPoint.x(), focalPoint.y());
997 Q_ASSERT(
sizeof(m_focalPoint) == 8);
998 memcpy(buf->data() + 64 * shaderMatrixCount + 64, &m_focalPoint, 8);
1002 if (!oldMaterial || m_focalToCenter.x() != focalToCenter.x() || m_focalToCenter.y() != focalToCenter.y()) {
1003 m_focalToCenter = QVector2D(focalToCenter.x(), focalToCenter.y());
1004 Q_ASSERT(
sizeof(m_focalToCenter) == 8);
1005 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8, &m_focalToCenter, 8);
1009 if (!oldMaterial || m_centerRadius != centerRadius) {
1010 m_centerRadius = centerRadius;
1011 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8 + 8, &m_centerRadius, 4);
1015 if (!oldMaterial || m_focalRadius != focalRadius) {
1016 m_focalRadius = focalRadius;
1017 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8 + 8 + 4, &m_focalRadius, 4);
1021 if (state.isOpacityDirty()) {
1022 const float opacity = state.opacity();
1023 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8 + 8 + 4 + 4, &opacity, 4);
1031 QSGMaterial *newMaterial, QSGMaterial *)
1038 const QSGGradientCacheKey cacheKey(node->m_fillGradient.stops, QGradient::Spread(node->m_fillGradient.spread));
1039 QSGTexture *t = QSGGradientCache::cacheForRhi(state.rhi())->get(cacheKey);
1040 t->commitTextureOperations(state.rhi(), state.resourceUpdateBatch());
1046 static QSGMaterialType type;
1052 Q_ASSERT(other && type() == other->type());
1061 const QSGGradientCache::GradientDesc *ga = &a->m_fillGradient;
1062 const QSGGradientCache::GradientDesc *gb = &b->m_fillGradient;
1064 if (
int d = ga->spread - gb->spread)
1067 if (
int d = ga->a.x() - gb->a.x())
1069 if (
int d = ga->a.y() - gb->a.y())
1071 if (
int d = ga->b.x() - gb->b.x())
1073 if (
int d = ga->b.y() - gb->b.y())
1076 if (
int d = ga->v0 - gb->v0)
1078 if (
int d = ga->v1 - gb->v1)
1081 if (
int d = ga->stops.size() - gb->stops.size())
1084 for (
int i = 0; i < ga->stops.size(); ++i) {
1085 if (
int d = ga->stops[i].first - gb->stops[i].first)
1087 if (
int d = ga->stops[i].second.rgba() - gb->stops[i].second.rgba())
1091 if (
int d = a->m_fillTransform.compareTo(b->m_fillTransform))
1099 Q_UNUSED(renderMode);
1105 setShaderFileName(VertexStage, QStringLiteral(
":/qt-project.org/shapes/shaders_ng/conicalgradient.vert.qsb"), viewCount);
1106 setShaderFileName(FragmentStage, QStringLiteral(
":/qt-project.org/shapes/shaders_ng/conicalgradient.frag.qsb"), viewCount);
1110 QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
1112 Q_ASSERT(oldMaterial ==
nullptr || newMaterial->type() == oldMaterial->type());
1114 bool changed =
false;
1115 QByteArray *buf = state.uniformData();
1116 Q_ASSERT(buf->size() >= 80 + 64);
1117 const int shaderMatrixCount = newMaterial->viewCount();
1118 const int matrixCount = qMin(state.projectionMatrixCount(), shaderMatrixCount);
1120 if (state.isMatrixDirty()) {
1121 for (
int viewIndex = 0; viewIndex < matrixCount; ++viewIndex) {
1122 const QMatrix4x4 m = state.combinedMatrix();
1123 memcpy(buf->data() + 64 * viewIndex, m.constData(), 64);
1130 if (!oldMaterial || m_fillTransform != node->m_fillTransform) {
1131 memcpy(buf->data() + 64 * shaderMatrixCount, node->m_fillTransform.invertedData(), 64);
1132 m_fillTransform = node->m_fillTransform;
1136 const QPointF centerPoint = node->m_fillGradient.a;
1137 const float angle = -qDegreesToRadians(node->m_fillGradient.v0);
1139 if (!oldMaterial || m_centerPoint.x() != centerPoint.x() || m_centerPoint.y() != centerPoint.y()) {
1140 m_centerPoint = QVector2D(centerPoint.x(), centerPoint.y());
1141 Q_ASSERT(
sizeof(m_centerPoint) == 8);
1142 memcpy(buf->data() + 64 * shaderMatrixCount + 64, &m_centerPoint, 8);
1146 if (!oldMaterial || m_angle != angle) {
1148 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8, &m_angle, 4);
1152 if (state.isOpacityDirty()) {
1153 const float opacity = state.opacity();
1154 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8 + 4, &opacity, 4);
1162 QSGMaterial *newMaterial, QSGMaterial *)
1169 const QSGGradientCacheKey cacheKey(node->m_fillGradient.stops, QGradient::Spread(node->m_fillGradient.spread));
1170 QSGTexture *t = QSGGradientCache::cacheForRhi(state.rhi())->get(cacheKey);
1171 t->commitTextureOperations(state.rhi(), state.resourceUpdateBatch());
1177 static QSGMaterialType type;
1183 Q_ASSERT(other && type() == other->type());
1192 const QSGGradientCache::GradientDesc *ga = &a->m_fillGradient;
1193 const QSGGradientCache::GradientDesc *gb = &b->m_fillGradient;
1195 if (
int d = ga->a.x() - gb->a.x())
1197 if (
int d = ga->a.y() - gb->a.y())
1200 if (
int d = ga->v0 - gb->v0)
1203 if (
int d = ga->stops.size() - gb->stops.size())
1206 for (
int i = 0; i < ga->stops.size(); ++i) {
1207 if (
int d = ga->stops[i].first - gb->stops[i].first)
1209 if (
int d = ga->stops[i].second.rgba() - gb->stops[i].second.rgba())
1213 if (
int d = a->m_fillTransform.compareTo(b->m_fillTransform))
1221 Q_UNUSED(renderMode);
1227 setShaderFileName(VertexStage, QStringLiteral(
":/qt-project.org/shapes/shaders_ng/texturefill.vert.qsb"), viewCount);
1228 setShaderFileName(FragmentStage, QStringLiteral(
":/qt-project.org/shapes/shaders_ng/texturefill.frag.qsb"), viewCount);
1232 QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
1234 Q_ASSERT(oldMaterial ==
nullptr || newMaterial->type() == oldMaterial->type());
1236 bool changed =
false;
1237 QByteArray *buf = state.uniformData();
1238 const int shaderMatrixCount = newMaterial->viewCount();
1239 const int matrixCount = qMin(state.projectionMatrixCount(), shaderMatrixCount);
1240 Q_ASSERT(buf->size() >= 64 * shaderMatrixCount + 64 + 8 + 4);
1242 if (state.isMatrixDirty()) {
1243 for (
int viewIndex = 0; viewIndex < matrixCount; ++viewIndex) {
1244 const QMatrix4x4 m = state.combinedMatrix();
1245 memcpy(buf->data() + 64 * viewIndex, m.constData(), 64);
1252 if (!oldMaterial || m_fillTransform != node->m_fillTransform) {
1253 memcpy(buf->data() + 64 * shaderMatrixCount, node->m_fillTransform.invertedData(), 64);
1254 m_fillTransform = node->m_fillTransform;
1258 const QSizeF boundsSize = node->m_fillTextureProvider !=
nullptr && node->m_fillTextureProvider->texture() !=
nullptr
1259 ? node->m_fillTextureProvider->texture()->textureSize()
1263 const QVector2D boundsVector(boundsSize.width() / state.devicePixelRatio(),
1264 boundsSize.height() / state.devicePixelRatio());
1265 if (!oldMaterial || m_boundsSize != boundsVector) {
1266 m_boundsSize = boundsVector;
1267 Q_ASSERT(
sizeof(m_boundsSize) == 8);
1268 memcpy(buf->data() + 64 * shaderMatrixCount + 64, &m_boundsSize, 8);
1272 if (state.isOpacityDirty()) {
1273 const float opacity = state.opacity();
1274 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8, &opacity, 4);
1282 QSGMaterial *newMaterial, QSGMaterial *)
1289 if (node->m_fillTextureProvider !=
nullptr) {
1290 QSGTexture *providedTexture = node->m_fillTextureProvider->texture();
1291 if (providedTexture !=
nullptr) {
1292 if (providedTexture->isAtlasTexture()) {
1296 QSGTexture *newTexture = providedTexture->removedFromAtlas(state.resourceUpdateBatch());
1297 if (newTexture !=
nullptr)
1298 providedTexture = newTexture;
1301 providedTexture->commitTextureOperations(state.rhi(), state.resourceUpdateBatch());
1302 *texture = providedTexture;
1307 if (m->dummyTexture() ==
nullptr) {
1308 QSGPlainTexture *dummyTexture =
new QSGPlainTexture;
1309 dummyTexture->setFiltering(QSGTexture::Nearest);
1310 dummyTexture->setHorizontalWrapMode(QSGTexture::Repeat);
1311 dummyTexture->setVerticalWrapMode(QSGTexture::Repeat);
1312 QImage img(128, 128, QImage::Format_ARGB32_Premultiplied);
1314 dummyTexture->setImage(img);
1315 dummyTexture->commitTextureOperations(state.rhi(), state.resourceUpdateBatch());
1317 m->setDummyTexture(dummyTexture);
1320 *texture = m->dummyTexture();
1325 delete m_dummyTexture;
1330 static QSGMaterialType type;
1336 Q_ASSERT(other && type() == other->type());
1345 if (
int d = a->m_fillTransform.compareTo(b->m_fillTransform))
1348 const qintptr diff = qintptr(a->m_fillTextureProvider) - qintptr(b->m_fillTextureProvider);
1349 return diff < 0 ? -1 : (diff > 0 ? 1 : 0);
1354 Q_UNUSED(renderMode);
1360#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
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)
#define QSG_RUNTIME_DESCRIPTION
void set(float nx, float ny, QQuickShapeGenericRenderer::Color4ub ncolor)