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);
216 ShapePathData &d(m_sp[index]);
218 d.fillGradient.stops = gradient->gradientStops();
219 d.fillGradient.spread = QGradient::Spread(gradient->spread());
220 if (QQuickShapeLinearGradient *g = qobject_cast<QQuickShapeLinearGradient *>(gradient)) {
221 d.fillGradientActive = LinearGradient;
222 d.fillGradient.a = QPointF(g->x1(), g->y1());
223 d.fillGradient.b = QPointF(g->x2(), g->y2());
224 }
else if (QQuickShapeRadialGradient *g = qobject_cast<QQuickShapeRadialGradient *>(gradient)) {
225 d.fillGradientActive = RadialGradient;
226 d.fillGradient.a = QPointF(g->centerX(), g->centerY());
227 d.fillGradient.b = QPointF(g->focalX(), g->focalY());
228 d.fillGradient.v0 = g->centerRadius();
229 d.fillGradient.v1 = g->focalRadius();
230 }
else if (QQuickShapeConicalGradient *g = qobject_cast<QQuickShapeConicalGradient *>(gradient)) {
231 d.fillGradientActive = ConicalGradient;
232 d.fillGradient.a = QPointF(g->centerX(), g->centerY());
233 d.fillGradient.v0 = g->angle();
238 d.fillGradientActive = NoGradient;
245 ShapePathData &d(m_sp[index]);
246 if ((d.fillTextureProviderItem ==
nullptr) != (textureProviderItem ==
nullptr))
248 if (d.fillTextureProviderItem !=
nullptr)
249 QQuickItemPrivate::get(d.fillTextureProviderItem)->derefWindow();
250 d.fillTextureProviderItem = textureProviderItem;
251 if (d.fillTextureProviderItem !=
nullptr)
252 QQuickItemPrivate::get(d.fillTextureProviderItem)->refWindow(m_item->window());
258 for (
auto &pathData : m_sp) {
259 if (pathData.fillTextureProviderItem !=
nullptr) {
260 if (window ==
nullptr)
261 QQuickItemPrivate::get(pathData.fillTextureProviderItem)->derefWindow();
263 QQuickItemPrivate::get(pathData.fillTextureProviderItem)->refWindow(window);
271 ShapePathData &d(m_sp[index]);
272 d.fillTransform = transform;
278 ShapePathData &d(m_sp[index]);
279 d.triangulationScale = scale;
298 m_asyncCallback = callback;
299 m_asyncCallbackData = data;
303static QThreadPool *pathWorkThreadPool =
nullptr;
305static void deletePathWorkThreadPool()
307 delete pathWorkThreadPool;
308 pathWorkThreadPool =
nullptr;
314#if !QT_CONFIG(thread)
320 bool didKickOffAsync =
false;
322 for (
int i = 0; i < m_sp.size(); ++i) {
323 ShapePathData &d(m_sp[i]);
327 m_accDirty |= d.syncDirty;
334 d.effectiveDirty |= d.syncDirty;
336 if (d.path.isEmpty()) {
337 d.fillVertices.clear();
338 d.fillIndices.clear();
339 d.strokeVertices.clear();
344 if (async && !pathWorkThreadPool) {
345 qAddPostRoutine(deletePathWorkThreadPool);
346 pathWorkThreadPool =
new QThreadPool;
347 const int idealCount = QThread::idealThreadCount();
348 pathWorkThreadPool->setMaxThreadCount(idealCount > 0 ? idealCount * 2 : 4);
351 auto testFeatureIndexUint = [](QQuickItem *item) ->
bool {
352 if (
auto *w = item->window()) {
353 if (
auto *rhi = QQuickWindowPrivate::get(w)->rhi)
354 return rhi->isFeatureSupported(QRhi::ElementIndexUint);
358 static bool supportsElementIndexUint = testFeatureIndexUint(m_item);
360 d.path.setFillRule(d.fillRule);
361 if (m_api == QSGRendererInterface::Unknown)
362 m_api = m_item->window()->rendererInterface()->graphicsApi();
365 r->setAutoDelete(
false);
372 r->triangulationScale = d.triangulationScale;
375 QObject::connect(r, &QQuickShapeFillRunnable::done, qApp, [
this, i](QQuickShapeFillRunnable *r) {
378 if (!r->orphaned && i < m_sp.size()) {
379 ShapePathData &d(m_sp[i]);
380 d.fillVertices = r->fillVertices;
381 d.fillIndices = r->fillIndices;
382 d.indexType = r->indexType;
383 d.pendingFill =
nullptr;
384 d.effectiveDirty |= DirtyFillGeom;
385 maybeUpdateAsyncItem();
389 didKickOffAsync =
true;
393 qtVectorPathForPath(r->path);
394 pathWorkThreadPool->start(r);
397 triangulateFill(d.path, d.fillColor, &d.fillVertices, &d.fillIndices, &d.indexType,
398 supportsElementIndexUint,
399 d.triangulationScale);
403 if ((d.syncDirty &
DirtyStrokeGeom) && d.strokeWidth > 0.0f && d.strokeColor
.a) {
406 r->setAutoDelete(
false);
413 r->clipSize = QSize(m_item->width(), m_item->height());
414 r->triangulationScale = d.triangulationScale;
415 QObject::connect(r, &QQuickShapeStrokeRunnable::done, qApp, [
this, i](QQuickShapeStrokeRunnable *r) {
416 if (!r->orphaned && i < m_sp.size()) {
417 ShapePathData &d(m_sp[i]);
418 d.strokeVertices = r->strokeVertices;
419 d.pendingStroke =
nullptr;
420 d.effectiveDirty |= DirtyStrokeGeom;
421 maybeUpdateAsyncItem();
425 didKickOffAsync =
true;
429 qtVectorPathForPath(r->path);
430 pathWorkThreadPool->start(r);
433 triangulateStroke(d.path, d.pen, d.strokeColor, &d.strokeVertices,
434 QSize(m_item->width(), m_item->height()), d.triangulationScale);
439 if (!didKickOffAsync && async && m_asyncCallback)
440 m_asyncCallback(m_asyncCallbackData);
445 for (
const ShapePathData &d : std::as_const(m_sp)) {
446 if (d.pendingFill || d.pendingStroke)
452 m_asyncCallback(m_asyncCallbackData);
461 QSGGeometry::Type *indexType,
462 bool supportsElementIndexUint,
463 qreal triangulationScale)
465 const QVectorPath &vp = qtVectorPathForPath(path);
467 QTriangleSet ts = qTriangulate(vp, QTransform::fromScale(triangulationScale, triangulationScale), 1, supportsElementIndexUint);
468 const int vertexCount = ts.vertices.size() / 2;
469 fillVertices->resize(vertexCount);
471 const qreal *vsrc = ts.vertices.constData();
472 for (
int i = 0; i < vertexCount; ++i)
473 vdst[i]
.set(vsrc[i * 2] / triangulationScale
, vsrc[i * 2 + 1] / triangulationScale
, fillColor
);
475 size_t indexByteSize;
476 if (ts.indices.type() == QVertexIndexVector::UnsignedShort) {
477 *indexType = QSGGeometry::UnsignedShortType;
480 fillIndices->resize(ts.indices.size() / 2);
481 indexByteSize = ts.indices.size() *
sizeof(quint16);
483 *indexType = QSGGeometry::UnsignedIntType;
484 fillIndices->resize(ts.indices.size());
485 indexByteSize = ts.indices.size() *
sizeof(quint32);
487 memcpy(fillIndices->data(), ts.indices.data(), indexByteSize);
494 const QSize &clipSize,
495 qreal triangulationScale)
497 const QVectorPath &vp = qtVectorPathForPath(path);
498 const QRectF clip(QPointF(0, 0), clipSize);
499 const qreal inverseScale = 1.0 / triangulationScale;
501 QTriangulatingStroker stroker;
502 stroker.setInvScale(inverseScale);
504 if (pen.style() == Qt::SolidLine) {
505 stroker.process(vp, pen, clip, {});
507 QDashedStrokeProcessor dashStroker;
508 dashStroker.setInvScale(inverseScale);
509 dashStroker.process(vp, pen, clip, {});
510 QVectorPath dashStroke(dashStroker.points(), dashStroker.elementCount(),
511 dashStroker.elementTypes(), 0);
512 stroker.process(dashStroke, pen, clip, {});
515 if (!stroker.vertexCount()) {
516 strokeVertices->clear();
520 const int vertexCount = stroker.vertexCount() / 2;
521 strokeVertices->resize(vertexCount);
523 const float *vsrc = stroker.vertices();
524 for (
int i = 0; i < vertexCount; ++i)
525 vdst[i]
.set(vsrc[i * 2]
, vsrc[i * 2 + 1]
, strokeColor
);
530 if (m_rootNode != node) {
539 if (!m_rootNode || !m_accDirty)
555 for (ShapePathData &d : m_sp) {
558 *nodePtr =
new QQuickShapeGenericNode;
559 prevNode->m_next = *nodePtr;
560 prevNode->appendChildNode(*nodePtr);
563 QQuickShapeGenericNode *node = *nodePtr;
565 if (m_accDirty & DirtyList)
566 d.effectiveDirty |= DirtyFillGeom | DirtyStrokeGeom | DirtyColor | DirtyFillGradient | DirtyFillTransform | DirtyFillTexture;
568 if (!d.effectiveDirty) {
570 nodePtr = &node->m_next;
574 if (d.fillColor.a == 0) {
575 delete node->m_fillNode;
576 node->m_fillNode =
nullptr;
577 }
else if (!node->m_fillNode) {
578 node->m_fillNode =
new QQuickShapeGenericStrokeFillNode(m_item->window());
579 if (node->m_strokeNode)
580 node->removeChildNode(node->m_strokeNode);
581 node->appendChildNode(node->m_fillNode);
582 if (node->m_strokeNode)
583 node->appendChildNode(node->m_strokeNode);
584 d.effectiveDirty |= DirtyFillGeom;
587 if (d.strokeWidth <= 0.0f || d.strokeColor.a == 0) {
588 delete node->m_strokeNode;
589 node->m_strokeNode =
nullptr;
590 }
else if (!node->m_strokeNode) {
591 node->m_strokeNode =
new QQuickShapeGenericStrokeFillNode(m_item->window());
592 node->appendChildNode(node->m_strokeNode);
593 d.effectiveDirty |= DirtyStrokeGeom;
596 updateFillNode(&d, node);
597 updateStrokeNode(&d, node);
599 d.effectiveDirty = 0;
602 nodePtr = &node->m_next;
605 if (*nodePtr && prevNode) {
606 prevNode->removeChildNode(*nodePtr);
611 if (m_sp.isEmpty()) {
625 if (d->fillGradientActive) {
627 n->m_fillGradient = d->fillGradient;
630 bool needsUpdate = d->fillTextureProviderItem ==
nullptr && n->m_fillTextureProvider !=
nullptr;
632 && d->fillTextureProviderItem !=
nullptr
633 && n->m_fillTextureProvider != d->fillTextureProviderItem->textureProvider()) {
638 if (n->m_fillTextureProvider !=
nullptr) {
639 QObject::disconnect(n->m_fillTextureProvider, &QSGTextureProvider::textureChanged,
640 n, &QQuickShapeGenericStrokeFillNode::handleTextureChanged);
641 QObject::disconnect(n->m_fillTextureProvider, &QSGTextureProvider::destroyed,
642 n, &QQuickShapeGenericStrokeFillNode::handleTextureProviderDestroyed);
645 n->m_fillTextureProvider = d->fillTextureProviderItem ==
nullptr
647 : d->fillTextureProviderItem->textureProvider();
649 if (n->m_fillTextureProvider !=
nullptr) {
650 QObject::connect(n->m_fillTextureProvider, &QSGTextureProvider::textureChanged,
651 n, &QQuickShapeGenericStrokeFillNode::handleTextureChanged);
652 QObject::connect(n->m_fillTextureProvider, &QSGTextureProvider::destroyed,
653 n, &QQuickShapeGenericStrokeFillNode::handleTextureProviderDestroyed);
658 n->m_fillTransform = d->fillTransform;
671 updateShadowDataInNode(d, n);
673 QSGGeometry *g = n->geometry();
674 if (d->fillVertices.isEmpty()) {
675 if (g->vertexCount() || g->indexCount()) {
677 n->markDirty(QSGNode::DirtyGeometry);
682 if (d->fillGradientActive) {
684 switch (d->fillGradientActive) {
691 case ConicalGradient:
695 Q_UNREACHABLE_RETURN();
697 n->activateMaterial(m_item->window(), gradMat);
700 n->markDirty(QSGNode::DirtyMaterial);
705 }
else if (d->fillTextureProviderItem !=
nullptr) {
708 n->markDirty(QSGNode::DirtyMaterial);
712 if ((d->effectiveDirty &
DirtyColor) && !(d->effectiveDirty &
DirtyFillGeom) && d->fillTextureProviderItem ==
nullptr) {
713 ColoredVertex *vdst =
reinterpret_cast<ColoredVertex *>(g->vertexData());
714 for (
int i = 0; i < g->vertexCount(); ++i)
716 n->markDirty(QSGNode::DirtyGeometry);
721 const int indexCount = d->indexType == QSGGeometry::UnsignedShortType
722 ? d->fillIndices.size() * 2 : d->fillIndices.size();
723 if (g->indexType() != d->indexType) {
724 g =
new QSGGeometry(QSGGeometry::defaultAttributes_ColoredPoint2D(),
725 d->fillVertices.size(), indexCount, d->indexType);
728 g->allocate(d->fillVertices.size(), indexCount);
730 g->setDrawingMode(QSGGeometry::DrawTriangles);
732 memcpy(g->vertexData(), d->fillVertices.constData(), g->vertexCount() * g->sizeOfVertex());
733 memcpy(g->indexData(), d->fillIndices.constData(), g->indexCount() * g->sizeOfIndex());
735 n->markDirty(QSGNode::DirtyGeometry);
746 QSGGeometry *g = n->geometry();
747 if (d->strokeVertices.isEmpty()) {
748 if (g->vertexCount() || g->indexCount()) {
750 n->markDirty(QSGNode::DirtyGeometry);
755 n->markDirty(QSGNode::DirtyGeometry);
760 if (!g->vertexCount())
761 n->markDirty(QSGNode::DirtyMaterial);
764 ColoredVertex *vdst =
reinterpret_cast<ColoredVertex *>(g->vertexData());
765 for (
int i = 0; i < g->vertexCount(); ++i)
770 g->allocate(d->strokeVertices.size(), 0);
771 g->setDrawingMode(QSGGeometry::DrawTriangleStrip);
772 memcpy(g->vertexData(), d->strokeVertices.constData(), g->vertexCount() * g->sizeOfVertex());
777 QSGRendererInterface::GraphicsApi api = window->rendererInterface()->graphicsApi();
779 if (api == QSGRendererInterface::OpenGL || QSGRendererInterface::isApiRhiBased(api))
780 return new QSGVertexColorMaterial;
782 qWarning(
"Vertex-color material: Unsupported graphics API %d", api);
789 QSGRendererInterface::GraphicsApi api = window->rendererInterface()->graphicsApi();
791 if (api == QSGRendererInterface::OpenGL || QSGRendererInterface::isApiRhiBased(api))
794 qWarning(
"Linear gradient material: Unsupported graphics API %d", api);
801 QSGRendererInterface::GraphicsApi api = window->rendererInterface()->graphicsApi();
803 if (api == QSGRendererInterface::OpenGL || QSGRendererInterface::isApiRhiBased(api))
806 qWarning(
"Radial gradient material: Unsupported graphics API %d", api);
813 QSGRendererInterface::GraphicsApi api = window->rendererInterface()->graphicsApi();
815 if (api == QSGRendererInterface::OpenGL || QSGRendererInterface::isApiRhiBased(api))
818 qWarning(
"Conical gradient material: Unsupported graphics API %d", api);
825 QSGRendererInterface::GraphicsApi api = window->rendererInterface()->graphicsApi();
827 if (api == QSGRendererInterface::OpenGL || QSGRendererInterface::isApiRhiBased(api))
830 qWarning(
"Texture fill material: Unsupported graphics API %d", api);
836 setShaderFileName(VertexStage, QStringLiteral(
":/qt-project.org/shapes/shaders_ng/lineargradient.vert.qsb"), viewCount);
837 setShaderFileName(FragmentStage, QStringLiteral(
":/qt-project.org/shapes/shaders_ng/lineargradient.frag.qsb"), viewCount);
841 QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
843 Q_ASSERT(oldMaterial ==
nullptr || newMaterial->type() == oldMaterial->type());
845 bool changed =
false;
846 QByteArray *buf = state.uniformData();
847 Q_ASSERT(buf->size() >= 84 + 64);
848 const int shaderMatrixCount = newMaterial->viewCount();
849 const int matrixCount = qMin(state.projectionMatrixCount(), shaderMatrixCount);
851 if (state.isMatrixDirty()) {
852 for (
int viewIndex = 0; viewIndex < matrixCount; ++viewIndex) {
853 const QMatrix4x4 m = state.combinedMatrix();
854 memcpy(buf->data() + 64 * viewIndex, m.constData(), 64);
861 if (!oldMaterial || m_fillTransform != node->m_fillTransform) {
862 memcpy(buf->data() + 64 * shaderMatrixCount, node->m_fillTransform.invertedData(), 64);
863 m_fillTransform = node->m_fillTransform;
867 if (!oldMaterial || m_gradA.x() != node->m_fillGradient.a.x() || m_gradA.y() != node->m_fillGradient.a.y()) {
868 m_gradA = QVector2D(node->m_fillGradient.a.x(), node->m_fillGradient.a.y());
869 Q_ASSERT(
sizeof(m_gradA) == 8);
870 memcpy(buf->data() + 64 * shaderMatrixCount + 64, &m_gradA, 8);
874 if (!oldMaterial || m_gradB.x() != node->m_fillGradient.b.x() || m_gradB.y() != node->m_fillGradient.b.y()) {
875 m_gradB = QVector2D(node->m_fillGradient.b.x(), node->m_fillGradient.b.y());
876 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8, &m_gradB, 8);
880 if (state.isOpacityDirty()) {
881 const float opacity = state.opacity();
882 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8 + 8, &opacity, 4);
890 QSGMaterial *newMaterial, QSGMaterial *)
897 const QSGGradientCacheKey cacheKey(node->m_fillGradient.stops, QGradient::Spread(node->m_fillGradient.spread));
898 QSGTexture *t = QSGGradientCache::cacheForRhi(state.rhi())->get(cacheKey);
899 t->commitTextureOperations(state.rhi(), state.resourceUpdateBatch());
905 static QSGMaterialType type;
911 Q_ASSERT(other && type() == other->type());
920 const QSGGradientCache::GradientDesc *ga = &a->m_fillGradient;
921 const QSGGradientCache::GradientDesc *gb = &b->m_fillGradient;
923 if (
int d = ga->spread - gb->spread)
926 if (
int d = ga->a.x() - gb->a.x())
928 if (
int d = ga->a.y() - gb->a.y())
930 if (
int d = ga->b.x() - gb->b.x())
932 if (
int d = ga->b.y() - gb->b.y())
935 if (
int d = ga->stops.size() - gb->stops.size())
938 for (
int i = 0; i < ga->stops.size(); ++i) {
939 if (
int d = ga->stops[i].first - gb->stops[i].first)
941 if (
int d = ga->stops[i].second.rgba() - gb->stops[i].second.rgba())
945 if (
int d = a->m_fillTransform.compareTo(b->m_fillTransform))
953 Q_UNUSED(renderMode);
959 setShaderFileName(VertexStage, QStringLiteral(
":/qt-project.org/shapes/shaders_ng/radialgradient.vert.qsb"), viewCount);
960 setShaderFileName(FragmentStage, QStringLiteral(
":/qt-project.org/shapes/shaders_ng/radialgradient.frag.qsb"), viewCount);
964 QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
966 Q_ASSERT(oldMaterial ==
nullptr || newMaterial->type() == oldMaterial->type());
968 bool changed =
false;
969 QByteArray *buf = state.uniformData();
970 Q_ASSERT(buf->size() >= 92 + 64);
971 const int shaderMatrixCount = newMaterial->viewCount();
972 const int matrixCount = qMin(state.projectionMatrixCount(), shaderMatrixCount);
974 if (state.isMatrixDirty()) {
975 for (
int viewIndex = 0; viewIndex < matrixCount; ++viewIndex) {
976 const QMatrix4x4 m = state.combinedMatrix();
977 memcpy(buf->data() + 64 * viewIndex, m.constData(), 64);
984 if (!oldMaterial || m_fillTransform != node->m_fillTransform) {
985 memcpy(buf->data() + 64 * shaderMatrixCount, node->m_fillTransform.invertedData(), 64);
986 m_fillTransform = node->m_fillTransform;
990 const QPointF centerPoint = node->m_fillGradient.a;
991 const QPointF focalPoint = node->m_fillGradient.b;
992 const QPointF focalToCenter = centerPoint - focalPoint;
993 const float centerRadius = node->m_fillGradient.v0;
994 const float focalRadius = node->m_fillGradient.v1;
996 if (!oldMaterial || m_focalPoint.x() != focalPoint.x() || m_focalPoint.y() != focalPoint.y()) {
997 m_focalPoint = QVector2D(focalPoint.x(), focalPoint.y());
998 Q_ASSERT(
sizeof(m_focalPoint) == 8);
999 memcpy(buf->data() + 64 * shaderMatrixCount + 64, &m_focalPoint, 8);
1003 if (!oldMaterial || m_focalToCenter.x() != focalToCenter.x() || m_focalToCenter.y() != focalToCenter.y()) {
1004 m_focalToCenter = QVector2D(focalToCenter.x(), focalToCenter.y());
1005 Q_ASSERT(
sizeof(m_focalToCenter) == 8);
1006 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8, &m_focalToCenter, 8);
1010 if (!oldMaterial || m_centerRadius != centerRadius) {
1011 m_centerRadius = centerRadius;
1012 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8 + 8, &m_centerRadius, 4);
1016 if (!oldMaterial || m_focalRadius != focalRadius) {
1017 m_focalRadius = focalRadius;
1018 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8 + 8 + 4, &m_focalRadius, 4);
1022 if (state.isOpacityDirty()) {
1023 const float opacity = state.opacity();
1024 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8 + 8 + 4 + 4, &opacity, 4);
1032 QSGMaterial *newMaterial, QSGMaterial *)
1039 const QSGGradientCacheKey cacheKey(node->m_fillGradient.stops, QGradient::Spread(node->m_fillGradient.spread));
1040 QSGTexture *t = QSGGradientCache::cacheForRhi(state.rhi())->get(cacheKey);
1041 t->commitTextureOperations(state.rhi(), state.resourceUpdateBatch());
1047 static QSGMaterialType type;
1053 Q_ASSERT(other && type() == other->type());
1062 const QSGGradientCache::GradientDesc *ga = &a->m_fillGradient;
1063 const QSGGradientCache::GradientDesc *gb = &b->m_fillGradient;
1065 if (
int d = ga->spread - gb->spread)
1068 if (
int d = ga->a.x() - gb->a.x())
1070 if (
int d = ga->a.y() - gb->a.y())
1072 if (
int d = ga->b.x() - gb->b.x())
1074 if (
int d = ga->b.y() - gb->b.y())
1077 if (
int d = ga->v0 - gb->v0)
1079 if (
int d = ga->v1 - gb->v1)
1082 if (
int d = ga->stops.size() - gb->stops.size())
1085 for (
int i = 0; i < ga->stops.size(); ++i) {
1086 if (
int d = ga->stops[i].first - gb->stops[i].first)
1088 if (
int d = ga->stops[i].second.rgba() - gb->stops[i].second.rgba())
1092 if (
int d = a->m_fillTransform.compareTo(b->m_fillTransform))
1100 Q_UNUSED(renderMode);
1106 setShaderFileName(VertexStage, QStringLiteral(
":/qt-project.org/shapes/shaders_ng/conicalgradient.vert.qsb"), viewCount);
1107 setShaderFileName(FragmentStage, QStringLiteral(
":/qt-project.org/shapes/shaders_ng/conicalgradient.frag.qsb"), viewCount);
1111 QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
1113 Q_ASSERT(oldMaterial ==
nullptr || newMaterial->type() == oldMaterial->type());
1115 bool changed =
false;
1116 QByteArray *buf = state.uniformData();
1117 Q_ASSERT(buf->size() >= 80 + 64);
1118 const int shaderMatrixCount = newMaterial->viewCount();
1119 const int matrixCount = qMin(state.projectionMatrixCount(), shaderMatrixCount);
1121 if (state.isMatrixDirty()) {
1122 for (
int viewIndex = 0; viewIndex < matrixCount; ++viewIndex) {
1123 const QMatrix4x4 m = state.combinedMatrix();
1124 memcpy(buf->data() + 64 * viewIndex, m.constData(), 64);
1131 if (!oldMaterial || m_fillTransform != node->m_fillTransform) {
1132 memcpy(buf->data() + 64 * shaderMatrixCount, node->m_fillTransform.invertedData(), 64);
1133 m_fillTransform = node->m_fillTransform;
1137 const QPointF centerPoint = node->m_fillGradient.a;
1138 const float angle = -qDegreesToRadians(node->m_fillGradient.v0);
1140 if (!oldMaterial || m_centerPoint.x() != centerPoint.x() || m_centerPoint.y() != centerPoint.y()) {
1141 m_centerPoint = QVector2D(centerPoint.x(), centerPoint.y());
1142 Q_ASSERT(
sizeof(m_centerPoint) == 8);
1143 memcpy(buf->data() + 64 * shaderMatrixCount + 64, &m_centerPoint, 8);
1147 if (!oldMaterial || m_angle != angle) {
1149 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8, &m_angle, 4);
1153 if (state.isOpacityDirty()) {
1154 const float opacity = state.opacity();
1155 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8 + 4, &opacity, 4);
1163 QSGMaterial *newMaterial, QSGMaterial *)
1170 const QSGGradientCacheKey cacheKey(node->m_fillGradient.stops, QGradient::Spread(node->m_fillGradient.spread));
1171 QSGTexture *t = QSGGradientCache::cacheForRhi(state.rhi())->get(cacheKey);
1172 t->commitTextureOperations(state.rhi(), state.resourceUpdateBatch());
1178 static QSGMaterialType type;
1184 Q_ASSERT(other && type() == other->type());
1193 const QSGGradientCache::GradientDesc *ga = &a->m_fillGradient;
1194 const QSGGradientCache::GradientDesc *gb = &b->m_fillGradient;
1196 if (
int d = ga->a.x() - gb->a.x())
1198 if (
int d = ga->a.y() - gb->a.y())
1201 if (
int d = ga->v0 - gb->v0)
1204 if (
int d = ga->stops.size() - gb->stops.size())
1207 for (
int i = 0; i < ga->stops.size(); ++i) {
1208 if (
int d = ga->stops[i].first - gb->stops[i].first)
1210 if (
int d = ga->stops[i].second.rgba() - gb->stops[i].second.rgba())
1214 if (
int d = a->m_fillTransform.compareTo(b->m_fillTransform))
1222 Q_UNUSED(renderMode);
1228 setShaderFileName(VertexStage, QStringLiteral(
":/qt-project.org/shapes/shaders_ng/texturefill.vert.qsb"), viewCount);
1229 setShaderFileName(FragmentStage, QStringLiteral(
":/qt-project.org/shapes/shaders_ng/texturefill.frag.qsb"), viewCount);
1233 QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
1235 Q_ASSERT(oldMaterial ==
nullptr || newMaterial->type() == oldMaterial->type());
1237 bool changed =
false;
1238 QByteArray *buf = state.uniformData();
1239 const int shaderMatrixCount = newMaterial->viewCount();
1240 const int matrixCount = qMin(state.projectionMatrixCount(), shaderMatrixCount);
1241 Q_ASSERT(buf->size() >= 64 * shaderMatrixCount + 64 + 8 + 4);
1243 if (state.isMatrixDirty()) {
1244 for (
int viewIndex = 0; viewIndex < matrixCount; ++viewIndex) {
1245 const QMatrix4x4 m = state.combinedMatrix();
1246 memcpy(buf->data() + 64 * viewIndex, m.constData(), 64);
1253 if (!oldMaterial || m_fillTransform != node->m_fillTransform) {
1254 memcpy(buf->data() + 64 * shaderMatrixCount, node->m_fillTransform.invertedData(), 64);
1255 m_fillTransform = node->m_fillTransform;
1259 const QSizeF boundsSize = node->m_fillTextureProvider !=
nullptr && node->m_fillTextureProvider->texture() !=
nullptr
1260 ? node->m_fillTextureProvider->texture()->textureSize()
1264 const QVector2D boundsVector(boundsSize.width() / state.devicePixelRatio(),
1265 boundsSize.height() / state.devicePixelRatio());
1266 if (!oldMaterial || m_boundsSize != boundsVector) {
1267 m_boundsSize = boundsVector;
1268 Q_ASSERT(
sizeof(m_boundsSize) == 8);
1269 memcpy(buf->data() + 64 * shaderMatrixCount + 64, &m_boundsSize, 8);
1273 if (state.isOpacityDirty()) {
1274 const float opacity = state.opacity();
1275 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8, &opacity, 4);
1283 QSGMaterial *newMaterial, QSGMaterial *)
1290 if (node->m_fillTextureProvider !=
nullptr) {
1291 QSGTexture *providedTexture = node->m_fillTextureProvider->texture();
1292 if (providedTexture !=
nullptr) {
1293 if (providedTexture->isAtlasTexture()) {
1297 QSGTexture *newTexture = providedTexture->removedFromAtlas(state.resourceUpdateBatch());
1298 if (newTexture !=
nullptr)
1299 providedTexture = newTexture;
1302 providedTexture->commitTextureOperations(state.rhi(), state.resourceUpdateBatch());
1303 *texture = providedTexture;
1308 if (m->dummyTexture() ==
nullptr) {
1309 QSGPlainTexture *dummyTexture =
new QSGPlainTexture;
1310 dummyTexture->setFiltering(QSGTexture::Nearest);
1311 dummyTexture->setHorizontalWrapMode(QSGTexture::Repeat);
1312 dummyTexture->setVerticalWrapMode(QSGTexture::Repeat);
1313 QImage img(128, 128, QImage::Format_ARGB32_Premultiplied);
1315 dummyTexture->setImage(img);
1316 dummyTexture->commitTextureOperations(state.rhi(), state.resourceUpdateBatch());
1318 m->setDummyTexture(dummyTexture);
1321 *texture = m->dummyTexture();
1326 delete m_dummyTexture;
1331 static QSGMaterialType type;
1337 Q_ASSERT(other && type() == other->type());
1346 if (
int d = a->m_fillTransform.compareTo(b->m_fillTransform))
1349 const qintptr diff = qintptr(a->m_fillTextureProvider) - qintptr(b->m_fillTextureProvider);
1350 return diff < 0 ? -1 : (diff > 0 ? 1 : 0);
1355 Q_UNUSED(renderMode);
1361#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)