2015-02-12 22:20:52 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "GrPrimitiveProcessor.h"
|
|
|
|
|
|
|
|
#include "GrCoordTransform.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* We specialize the vertex code for each of these matrix types.
|
|
|
|
*/
|
|
|
|
enum MatrixType {
|
|
|
|
kNoPersp_MatrixType = 0,
|
|
|
|
kGeneral_MatrixType = 1,
|
|
|
|
};
|
|
|
|
|
2018-06-19 18:33:47 +00:00
|
|
|
GrPrimitiveProcessor::GrPrimitiveProcessor(ClassID classID) : GrResourceIOProcessor(classID) {}
|
|
|
|
|
|
|
|
const GrPrimitiveProcessor::Attribute& GrPrimitiveProcessor::vertexAttribute(int i) const {
|
|
|
|
SkASSERT(i >= 0 && i < this->numVertexAttributes());
|
|
|
|
const auto& result = this->onVertexAttribute(i);
|
|
|
|
SkASSERT(result.isInitialized());
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
const GrPrimitiveProcessor::Attribute& GrPrimitiveProcessor::instanceAttribute(int i) const {
|
|
|
|
SkASSERT(i >= 0 && i < this->numInstanceAttributes());
|
|
|
|
const auto& result = this->onInstanceAttribute(i);
|
|
|
|
SkASSERT(result.isInitialized());
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef SK_DEBUG
|
|
|
|
size_t GrPrimitiveProcessor::debugOnly_vertexStride() const {
|
|
|
|
size_t stride = 0;
|
|
|
|
for (int i = 0; i < fVertexAttributeCnt; ++i) {
|
|
|
|
stride += this->vertexAttribute(i).sizeAlign4();
|
|
|
|
}
|
|
|
|
return stride;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t GrPrimitiveProcessor::debugOnly_instanceStride() const {
|
|
|
|
size_t stride = 0;
|
|
|
|
for (int i = 0; i < fInstanceAttributeCnt; ++i) {
|
|
|
|
stride += this->instanceAttribute(i).sizeAlign4();
|
|
|
|
}
|
|
|
|
return stride;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t GrPrimitiveProcessor::debugOnly_vertexAttributeOffset(int i) const {
|
|
|
|
SkASSERT(i >= 0 && i < fVertexAttributeCnt);
|
|
|
|
size_t offset = 0;
|
|
|
|
for (int j = 0; j < i; ++j) {
|
|
|
|
offset += this->vertexAttribute(j).sizeAlign4();
|
|
|
|
}
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t GrPrimitiveProcessor::debugOnly_instanceAttributeOffset(int i) const {
|
|
|
|
SkASSERT(i >= 0 && i < fInstanceAttributeCnt);
|
|
|
|
size_t offset = 0;
|
|
|
|
for (int j = 0; j < i; ++j) {
|
|
|
|
offset += this->instanceAttribute(j).sizeAlign4();
|
|
|
|
}
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-02-12 22:20:52 +00:00
|
|
|
uint32_t
|
2015-08-20 14:25:02 +00:00
|
|
|
GrPrimitiveProcessor::getTransformKey(const SkTArray<const GrCoordTransform*, true>& coords,
|
|
|
|
int numCoords) const {
|
2015-02-12 22:20:52 +00:00
|
|
|
uint32_t totalKey = 0;
|
2015-08-20 14:25:02 +00:00
|
|
|
for (int t = 0; t < numCoords; ++t) {
|
2015-02-12 22:20:52 +00:00
|
|
|
uint32_t key = 0;
|
|
|
|
const GrCoordTransform* coordTransform = coords[t];
|
|
|
|
if (coordTransform->getMatrix().hasPerspective()) {
|
|
|
|
key |= kGeneral_MatrixType;
|
|
|
|
} else {
|
|
|
|
key |= kNoPersp_MatrixType;
|
|
|
|
}
|
2018-06-06 21:16:05 +00:00
|
|
|
key <<= t;
|
2015-02-12 22:20:52 +00:00
|
|
|
SkASSERT(0 == (totalKey & key)); // keys for each transform ought not to overlap
|
|
|
|
totalKey |= key;
|
|
|
|
}
|
|
|
|
return totalKey;
|
|
|
|
}
|