54 QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
56 Q_UNUSED(oldMaterial);
57 QSGCurveFillMaterial *m =
static_cast<QSGCurveFillMaterial *>(newMaterial);
58 const QSGCurveFillNode *node = m->node();
60 || (node->gradientType() == QGradient::NoGradient && node->fillTextureProvider() ==
nullptr)) {
64 QSGTexture *t =
nullptr;
65 if (node->gradientType() != QGradient::NoGradient) {
66 const QSGGradientCacheKey cacheKey(node->fillGradient()->stops,
67 node->fillGradient()->spread);
68 t = QSGGradientCache::cacheForRhi(state.rhi())->get(cacheKey);
69 }
else if (node->fillTextureProvider() !=
nullptr) {
70 t = node->fillTextureProvider()->texture();
71 if (t !=
nullptr && t->isAtlasTexture()) {
75 QSGTexture *newTexture = t->removedFromAtlas(state.resourceUpdateBatch());
76 if (newTexture !=
nullptr)
83 t->commitTextureOperations(state.rhi(), state.resourceUpdateBatch());
85 if (m->dummyTexture() ==
nullptr) {
86 QSGPlainTexture *dummyTexture =
new QSGPlainTexture;
87 dummyTexture->setFiltering(QSGTexture::Nearest);
88 dummyTexture->setHorizontalWrapMode(QSGTexture::Repeat);
89 dummyTexture->setVerticalWrapMode(QSGTexture::Repeat);
90 QImage img(128, 128, QImage::Format_ARGB32_Premultiplied);
92 dummyTexture->setImage(img);
93 dummyTexture->commitTextureOperations(state.rhi(), state.resourceUpdateBatch());
95 m->setDummyTexture(dummyTexture);
98 t = m->dummyTexture();
106 bool changed =
false;
107 QByteArray *buf = state.uniformData();
108 Q_ASSERT(buf->size() >= 80);
109 const int matrixCount = qMin(state.projectionMatrixCount(), newEffect->viewCount());
112 float matrixScale = 0.0f;
113 if (state.isMatrixDirty()) {
114 for (
int viewIndex = 0; viewIndex < matrixCount; ++viewIndex) {
115 const QMatrix4x4 m = state.combinedMatrix(viewIndex);
116 memcpy(buf->data() + offset + viewIndex * 64, m.constData(), 64);
119 matrixScale = qSqrt(qAbs(state.determinant())) * state.devicePixelRatio();
120 memcpy(buf->data() + offset + newEffect->viewCount() * 64, &matrixScale, 4);
124 offset += newEffect->viewCount() * 64 + 4;
126 if (state.isOpacityDirty()) {
127 const float opacity = state.opacity();
128 memcpy(buf->data() + offset, &opacity, 4);
133 QSGCurveFillMaterial *newMaterial =
static_cast<QSGCurveFillMaterial *>(newEffect);
134 QSGCurveFillMaterial *oldMaterial =
static_cast<QSGCurveFillMaterial *>(oldEffect);
136 QSGCurveFillNode *newNode = newMaterial !=
nullptr ? newMaterial->node() :
nullptr;
137 QSGCurveFillNode *oldNode = oldMaterial !=
nullptr ? oldMaterial->node() :
nullptr;
139 if (newNode ==
nullptr)
142 if (oldNode ==
nullptr || oldNode->debug() != newNode->debug()) {
143 float debug = newNode->debug();
144 memcpy(buf->data() + offset, &debug, 4);
149 if (newNode->gradientType() == QGradient::NoGradient
150 && newNode->fillTextureProvider() ==
nullptr) {
151 Q_ASSERT(buf->size() >= offset + 16);
153 QVector4D newColor = QVector4D(newNode->color().redF(),
154 newNode->color().greenF(),
155 newNode->color().blueF(),
156 newNode->color().alphaF());
157 QVector4D oldColor = oldNode !=
nullptr
158 ? QVector4D(oldNode->color().redF(),
159 oldNode->color().greenF(),
160 oldNode->color().blueF(),
161 oldNode->color().alphaF())
164 if (oldNode ==
nullptr || oldColor != newColor) {
165 memcpy(buf->data() + offset, &newColor, 16);
171 Q_ASSERT(buf->size() >= offset + 64);
173 if (!oldNode || *oldNode->fillTransform() != *newNode->fillTransform()) {
174 memcpy(buf->data() + offset, newNode->fillTransform()->invertedData(), 64);
181 if (newNode->gradientType() == QGradient::NoGradient
182 && newNode->fillTextureProvider() !=
nullptr) {
183 Q_ASSERT(buf->size() >= offset + 8);
184 const QSizeF newTextureSize = newNode->fillTextureProvider()->texture() !=
nullptr
185 ? newNode->fillTextureProvider()->texture()->textureSize()
187 const QVector2D newBoundsSize(newTextureSize.width() / state.devicePixelRatio(),
188 newTextureSize.height() / state.devicePixelRatio());
189 const QVector2D oldBoundsSize = oldNode !=
nullptr
190 ? oldNode->boundsSize()
193 if (oldEffect ==
nullptr || newBoundsSize != oldBoundsSize) {
194 newNode->setBoundsSize(newBoundsSize);
195 memcpy(buf->data() + offset, &newBoundsSize, 8);
200 }
else if (newNode->gradientType() == QGradient::LinearGradient) {
201 Q_ASSERT(buf->size() >= offset + 8 + 8);
203 QVector2D newGradientStart = QVector2D(newNode->fillGradient()->a);
204 QVector2D oldGradientStart = oldNode !=
nullptr
205 ? QVector2D(oldNode->fillGradient()->a)
208 if (newGradientStart != oldGradientStart || oldEffect ==
nullptr) {
209 memcpy(buf->data() + offset, &newGradientStart, 8);
214 QVector2D newGradientEnd = QVector2D(newNode->fillGradient()->b);
215 QVector2D oldGradientEnd = oldNode!=
nullptr
216 ? QVector2D(oldNode->fillGradient()->b)
219 if (newGradientEnd != oldGradientEnd || oldEffect ==
nullptr) {
220 memcpy(buf->data() + offset, &newGradientEnd, 8);
225 }
else if (newNode->gradientType() == QGradient::RadialGradient) {
226 Q_ASSERT(buf->size() >= offset + 8 + 8 + 4 + 4);
228 QVector2D newFocalPoint = QVector2D(newNode->fillGradient()->b);
229 QVector2D oldFocalPoint = oldNode !=
nullptr
230 ? QVector2D(oldNode->fillGradient()->b)
232 if (oldNode ==
nullptr || newFocalPoint != oldFocalPoint) {
233 memcpy(buf->data() + offset, &newFocalPoint, 8);
238 QVector2D newCenterPoint = QVector2D(newNode->fillGradient()->a);
239 QVector2D oldCenterPoint = oldNode !=
nullptr
240 ? QVector2D(oldNode->fillGradient()->a)
243 QVector2D newCenterToFocal = newCenterPoint - newFocalPoint;
244 QVector2D oldCenterToFocal = oldCenterPoint - oldFocalPoint;
245 if (oldNode ==
nullptr || newCenterToFocal != oldCenterToFocal) {
246 memcpy(buf->data() + offset, &newCenterToFocal, 8);
251 float newCenterRadius = newNode->fillGradient()->v0;
252 float oldCenterRadius = oldNode !=
nullptr
253 ? oldNode->fillGradient()->v0
255 if (oldNode ==
nullptr || !qFuzzyCompare(newCenterRadius, oldCenterRadius)) {
256 memcpy(buf->data() + offset, &newCenterRadius, 4);
261 float newFocalRadius = newNode->fillGradient()->v1;
262 float oldFocalRadius = oldNode !=
nullptr
263 ? oldNode->fillGradient()->v1
265 if (oldNode ==
nullptr || !qFuzzyCompare(newFocalRadius, oldFocalRadius)) {
266 memcpy(buf->data() + offset, &newFocalRadius, 4);
271 }
else if (newNode->gradientType() == QGradient::ConicalGradient) {
272 Q_ASSERT(buf->size() >= offset + 8 + 4);
274 QVector2D newFocalPoint = QVector2D(newNode->fillGradient()->a);
275 QVector2D oldFocalPoint = oldNode !=
nullptr
276 ? QVector2D(oldNode->fillGradient()->a)
278 if (oldNode ==
nullptr || newFocalPoint != oldFocalPoint) {
279 memcpy(buf->data() + offset, &newFocalPoint, 8);
284 float newAngle = newNode->fillGradient()->v0;
285 float oldAngle = oldNode !=
nullptr
286 ? oldNode->fillGradient()->v0
288 if (oldNode ==
nullptr || !qFuzzyCompare(newAngle, oldAngle)) {
289 newAngle = -qDegreesToRadians(newAngle);
290 memcpy(buf->data() + offset, &newAngle, 4);
313int QSGCurveFillMaterial::compare(
const QSGMaterial *other)
const
315 if (other->type() != type())
316 return (type() - other->type());
318 const QSGCurveFillMaterial *otherMaterial =
319 static_cast<
const QSGCurveFillMaterial *>(other);
321 QSGCurveFillNode *a = node();
322 QSGCurveFillNode *b = otherMaterial->node();
326 if (a->gradientType() == QGradient::NoGradient && a->fillTextureProvider() ==
nullptr) {
327 if (
int d = a->color().red() - b->color().red())
329 if (
int d = a->color().green() - b->color().green())
331 if (
int d = a->color().blue() - b->color().blue())
333 if (
int d = a->color().alpha() - b->color().alpha())
336 if (a->gradientType() != QGradient::NoGradient) {
337 const QSGGradientCache::GradientDesc &ga = *a->fillGradient();
338 const QSGGradientCache::GradientDesc &gb = *b->fillGradient();
340 if (
int d = ga.a.x() - gb.a.x())
342 if (
int d = ga.a.y() - gb.a.y())
344 if (
int d = ga.b.x() - gb.b.x())
346 if (
int d = ga.b.y() - gb.b.y())
349 if (
int d = ga.v0 - gb.v0)
351 if (
int d = ga.v1 - gb.v1)
354 if (
int d = ga.spread - gb.spread)
357 if (
int d = ga.stops.size() - gb.stops.size())
360 for (
int i = 0; i < ga.stops.size(); ++i) {
361 if (
int d = ga.stops[i].first - gb.stops[i].first)
363 if (
int d = ga.stops[i].second.rgba() - gb.stops[i].second.rgba())
368 if (
int d = a->fillTransform()->compareTo(*b->fillTransform()))
372 const qintptr diff = qintptr(a->fillTextureProvider()) - qintptr(b->fillTextureProvider());
373 return diff < 0 ? -1 : (diff > 0 ? 1 : 0);