fBuilderTriFanISize = 0;
fISize = safe.mul(desc.fIndexCount, sizeof(uint16_t)); if (kTriangleFan_VertexMode == desc.fMode) { int numFanTris = 0; if (desc.fIndexCount) {
fBuilderTriFanISize = fISize;
numFanTris = desc.fIndexCount - 2;
} else {
numFanTris = desc.fVertexCount - 2; // By forcing this to become indexed we are adding a constraint to the maximum // number of vertices. if (desc.fVertexCount > (SkTo<int>(UINT16_MAX) + 1)) {
sk_bzero(this, sizeof(*this)); return;
}
} if (numFanTris <= 0) {
sk_bzero(this, sizeof(*this)); return;
}
fISize = safe.mul(numFanTris, 3 * sizeof(uint16_t));
}
size_t fTotal = 0; // size of entire SkVertices allocation (obj + arrays)
size_t fArrays; // size of all the data arrays (V + D + T + C + I)
size_t fVSize;
size_t fTSize;
size_t fCSize;
size_t fISize;
// For indexed tri-fans this is the number of amount of space fo indices needed in the builder // before conversion to indexed triangles (or zero if not indexed or not a triangle fan).
size_t fBuilderTriFanISize;
};
// need to point past the object to store the arrays char* ptr = (char*)storage + sizeof(SkVertices);
// return the original ptr (or null), but then advance it by size auto advance = [&ptr](size_t size) { char* new_ptr = size ? ptr : nullptr;
ptr += size; return new_ptr;
};
// The builder can update the number of indices. const size_t isize = ((mode == kTriangleFan_VertexMode) ? sizes.fBuilderTriFanISize
: sizes.fISize),
icount = isize / sizeof(uint16_t);
// Ensure that indices are valid for the given vertex count.
SkASSERT(vertexCount > 0); const uint16_t max_index = SkToU16(vertexCount - 1);
size_t i = 0; for (; i + 8 <= icount; i += 8) { const skvx::ushort8 ind8 = skvx::ushort8::Load(indices + i),
clamped_ind8 = skvx::min(ind8, max_index);
clamped_ind8.store(builder.indices() + i);
} if (i + 4 <= icount) { const skvx::ushort4 ind4 = skvx::ushort4::Load(indices + i),
clamped_ind4 = skvx::min(ind4, max_index);
clamped_ind4.store(builder.indices() + i);
i += 4;
} if (i + 2 <= icount) { const skvx::ushort2 ind2 = skvx::ushort2::Load(indices + i),
clamped_ind2 = skvx::min(ind2, max_index);
clamped_ind2.store(builder.indices() + i);
i += 2;
} if (i < icount) {
builder.indices()[i] = std::min(indices[i], max_index);
SkDEBUGCODE(i += 1);
}
SkASSERT(i == icount);
// Data arrays
buffer.writeByteArray(fVertices->fPositions, sizes.fVSize);
buffer.writeByteArray(fVertices->fTexs, sizes.fTSize);
buffer.writeByteArray(fVertices->fColors, sizes.fCSize); // if index-count is odd, we won't be 4-bytes aligned, so we call the pad version
buffer.writeByteArray(fVertices->fIndices, sizes.fISize);
}
// Check that the header fields and buffer are valid. If this is data with the experimental // custom attributes feature - we don't support that any more. // We also don't support serialized triangle-fan data. We stopped writing that long ago, // so it should never appear in valid encoded data. if (!safe || !buffer.isValid() || attrCount ||
mode == SkVertices::kTriangleFan_VertexMode) { return nullptr;
}
if (indexCount > 0) { // validate that the indices are in range const uint16_t* indices = builder.indices(); for (int i = 0; i < indexCount; ++i) { if (indices[i] >= (unsigned)vertexCount) { return nullptr;
}
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.