/* * Copyright 2017 Google Inc. * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file.
*/ #include"include/core/SkVertices.h"
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));
}
if (safe.ok()) {
fArrays = fVSize + fTSize + fCSize + fISize; // just the sum of the arrays
} else {
sk_bzero(this, sizeof(*this));
}
}
bool isValid() const { return fTotal != 0; }
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;
};
// 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.