53 QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
55 Q_UNUSED(oldMaterial);
56 QSGCurveFillMaterial *m =
static_cast<QSGCurveFillMaterial *>(newMaterial);
57 const QSGCurveFillNode *node = m->node();
59 || (node->gradientType() == QGradient::NoGradient && node->fillTextureProvider() ==
nullptr)) {
63 QSGTexture *t =
nullptr;
64 if (node->gradientType() != QGradient::NoGradient) {
65 const QSGGradientCacheKey cacheKey(node->fillGradient()->stops,
66 node->fillGradient()->spread);
67 t = QSGGradientCache::cacheForRhi(state.rhi())->get(cacheKey);
68 }
else if (node->fillTextureProvider() !=
nullptr) {
69 t = node->fillTextureProvider()->texture();
70 if (t !=
nullptr && t->isAtlasTexture()) {
74 QSGTexture *newTexture = t->removedFromAtlas(state.resourceUpdateBatch());
75 if (newTexture !=
nullptr)
82 t->commitTextureOperations(state.rhi(), state.resourceUpdateBatch());
84 if (m->dummyTexture() ==
nullptr) {
85 QSGPlainTexture *dummyTexture =
new QSGPlainTexture;
86 dummyTexture->setFiltering(QSGTexture::Nearest);
87 dummyTexture->setHorizontalWrapMode(QSGTexture::Repeat);
88 dummyTexture->setVerticalWrapMode(QSGTexture::Repeat);
89 QImage img(128, 128, QImage::Format_ARGB32_Premultiplied);
91 dummyTexture->setImage(img);
92 dummyTexture->commitTextureOperations(state.rhi(), state.resourceUpdateBatch());
94 m->setDummyTexture(dummyTexture);
97 t = m->dummyTexture();
105 bool changed =
false;
106 QByteArray *buf = state.uniformData();
107 Q_ASSERT(buf->size() >= 80);
108 const int matrixCount = qMin(state.projectionMatrixCount(), newEffect->viewCount());
111 float matrixScale = 0.0f;
112 if (state.isMatrixDirty()) {
113 for (
int viewIndex = 0; viewIndex < matrixCount; ++viewIndex) {
114 const QMatrix4x4 m = state.combinedMatrix(viewIndex);
115 memcpy(buf->data() + offset + viewIndex * 64, m.constData(), 64);
118 matrixScale = qSqrt(qAbs(state.determinant())) * state.devicePixelRatio();
119 memcpy(buf->data() + offset + newEffect->viewCount() * 64, &matrixScale, 4);
123 offset += newEffect->viewCount() * 64 + 4;
125 if (state.isOpacityDirty()) {
126 const float opacity = state.opacity();
127 memcpy(buf->data() + offset, &opacity, 4);
132 QSGCurveFillMaterial *newMaterial =
static_cast<QSGCurveFillMaterial *>(newEffect);
133 QSGCurveFillMaterial *oldMaterial =
static_cast<QSGCurveFillMaterial *>(oldEffect);
135 QSGCurveFillNode *newNode = newMaterial !=
nullptr ? newMaterial->node() :
nullptr;
136 QSGCurveFillNode *oldNode = oldMaterial !=
nullptr ? oldMaterial->node() :
nullptr;
138 if (newNode ==
nullptr)
141 if (oldNode ==
nullptr || oldNode->debug() != newNode->debug()) {
142 float debug = newNode->debug();
143 memcpy(buf->data() + offset, &debug, 4);
148 if (newNode->gradientType() == QGradient::NoGradient
149 && newNode->fillTextureProvider() ==
nullptr) {
150 Q_ASSERT(buf->size() >= offset + 16);
152 QVector4D newColor = QVector4D(newNode->color().redF(),
153 newNode->color().greenF(),
154 newNode->color().blueF(),
155 newNode->color().alphaF());
156 QVector4D oldColor = oldNode !=
nullptr
157 ? QVector4D(oldNode->color().redF(),
158 oldNode->color().greenF(),
159 oldNode->color().blueF(),
160 oldNode->color().alphaF())
163 if (oldNode ==
nullptr || oldColor != newColor) {
164 memcpy(buf->data() + offset, &newColor, 16);
170 Q_ASSERT(buf->size() >= offset + 64);
172 if (!oldNode || *oldNode->fillTransform() != *newNode->fillTransform()) {
173 memcpy(buf->data() + offset, newNode->fillTransform()->invertedData(), 64);
180 if (newNode->gradientType() == QGradient::NoGradient
181 && newNode->fillTextureProvider() !=
nullptr) {
182 Q_ASSERT(buf->size() >= offset + 8);
183 const QSizeF newTextureSize = newNode->fillTextureProvider()->texture() !=
nullptr
184 ? newNode->fillTextureProvider()->texture()->textureSize()
186 const QVector2D newBoundsSize(newTextureSize.width() / state.devicePixelRatio(),
187 newTextureSize.height() / state.devicePixelRatio());
188 const QVector2D oldBoundsSize = oldNode !=
nullptr
189 ? oldNode->boundsSize()
192 if (oldEffect ==
nullptr || newBoundsSize != oldBoundsSize) {
193 newNode->setBoundsSize(newBoundsSize);
194 memcpy(buf->data() + offset, &newBoundsSize, 8);
199 }
else if (newNode->gradientType() == QGradient::LinearGradient) {
200 Q_ASSERT(buf->size() >= offset + 8 + 8);
202 QVector2D newGradientStart = QVector2D(newNode->fillGradient()->a);
203 QVector2D oldGradientStart = oldNode !=
nullptr
204 ? QVector2D(oldNode->fillGradient()->a)
207 if (newGradientStart != oldGradientStart || oldEffect ==
nullptr) {
208 memcpy(buf->data() + offset, &newGradientStart, 8);
213 QVector2D newGradientEnd = QVector2D(newNode->fillGradient()->b);
214 QVector2D oldGradientEnd = oldNode!=
nullptr
215 ? QVector2D(oldNode->fillGradient()->b)
218 if (newGradientEnd != oldGradientEnd || oldEffect ==
nullptr) {
219 memcpy(buf->data() + offset, &newGradientEnd, 8);
224 }
else if (newNode->gradientType() == QGradient::RadialGradient) {
225 Q_ASSERT(buf->size() >= offset + 8 + 8 + 4 + 4);
227 QVector2D newFocalPoint = QVector2D(newNode->fillGradient()->b);
228 QVector2D oldFocalPoint = oldNode !=
nullptr
229 ? QVector2D(oldNode->fillGradient()->b)
231 if (oldNode ==
nullptr || newFocalPoint != oldFocalPoint) {
232 memcpy(buf->data() + offset, &newFocalPoint, 8);
237 QVector2D newCenterPoint = QVector2D(newNode->fillGradient()->a);
238 QVector2D oldCenterPoint = oldNode !=
nullptr
239 ? QVector2D(oldNode->fillGradient()->a)
242 QVector2D newCenterToFocal = newCenterPoint - newFocalPoint;
243 QVector2D oldCenterToFocal = oldCenterPoint - oldFocalPoint;
244 if (oldNode ==
nullptr || newCenterToFocal != oldCenterToFocal) {
245 memcpy(buf->data() + offset, &newCenterToFocal, 8);
250 float newCenterRadius = newNode->fillGradient()->v0;
251 float oldCenterRadius = oldNode !=
nullptr
252 ? oldNode->fillGradient()->v0
254 if (oldNode ==
nullptr || !qFuzzyCompare(newCenterRadius, oldCenterRadius)) {
255 memcpy(buf->data() + offset, &newCenterRadius, 4);
260 float newFocalRadius = newNode->fillGradient()->v1;
261 float oldFocalRadius = oldNode !=
nullptr
262 ? oldNode->fillGradient()->v1
264 if (oldNode ==
nullptr || !qFuzzyCompare(newFocalRadius, oldFocalRadius)) {
265 memcpy(buf->data() + offset, &newFocalRadius, 4);
270 }
else if (newNode->gradientType() == QGradient::ConicalGradient) {
271 Q_ASSERT(buf->size() >= offset + 8 + 4);
273 QVector2D newFocalPoint = QVector2D(newNode->fillGradient()->a);
274 QVector2D oldFocalPoint = oldNode !=
nullptr
275 ? QVector2D(oldNode->fillGradient()->a)
277 if (oldNode ==
nullptr || newFocalPoint != oldFocalPoint) {
278 memcpy(buf->data() + offset, &newFocalPoint, 8);
283 float newAngle = newNode->fillGradient()->v0;
284 float oldAngle = oldNode !=
nullptr
285 ? oldNode->fillGradient()->v0
287 if (oldNode ==
nullptr || !qFuzzyCompare(newAngle, oldAngle)) {
288 newAngle = -qDegreesToRadians(newAngle);
289 memcpy(buf->data() + offset, &newAngle, 4);
312int QSGCurveFillMaterial::compare(
const QSGMaterial *other)
const
314 if (other->type() != type())
315 return (type() - other->type());
317 const QSGCurveFillMaterial *otherMaterial =
318 static_cast<
const QSGCurveFillMaterial *>(other);
320 QSGCurveFillNode *a = node();
321 QSGCurveFillNode *b = otherMaterial->node();
325 if (a->gradientType() == QGradient::NoGradient && a->fillTextureProvider() ==
nullptr) {
326 if (
int d = a->color().red() - b->color().red())
328 if (
int d = a->color().green() - b->color().green())
330 if (
int d = a->color().blue() - b->color().blue())
332 if (
int d = a->color().alpha() - b->color().alpha())
335 if (a->gradientType() != QGradient::NoGradient) {
336 const QSGGradientCache::GradientDesc &ga = *a->fillGradient();
337 const QSGGradientCache::GradientDesc &gb = *b->fillGradient();
339 if (
int d = ga.a.x() - gb.a.x())
341 if (
int d = ga.a.y() - gb.a.y())
343 if (
int d = ga.b.x() - gb.b.x())
345 if (
int d = ga.b.y() - gb.b.y())
348 if (
int d = ga.v0 - gb.v0)
350 if (
int d = ga.v1 - gb.v1)
353 if (
int d = ga.spread - gb.spread)
356 if (
int d = ga.stops.size() - gb.stops.size())
359 for (
int i = 0; i < ga.stops.size(); ++i) {
360 if (
int d = ga.stops[i].first - gb.stops[i].first)
362 if (
int d = ga.stops[i].second.rgba() - gb.stops[i].second.rgba())
367 if (
int d = a->fillTransform()->compareTo(*b->fillTransform()))
371 const qintptr diff = qintptr(a->fillTextureProvider()) - qintptr(b->fillTextureProvider());
372 return diff < 0 ? -1 : (diff > 0 ? 1 : 0);