joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "GrPrimitiveProcessor.h" |
| 9 | |
| 10 | #include "GrCoordTransform.h" |
| 11 | |
| 12 | /** |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 13 | * We specialize the vertex code for each of these matrix types. |
| 14 | */ |
| 15 | enum MatrixType { |
| 16 | kNoPersp_MatrixType = 0, |
| 17 | kGeneral_MatrixType = 1, |
| 18 | }; |
| 19 | |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 20 | GrPrimitiveProcessor::GrPrimitiveProcessor(ClassID classID) : GrResourceIOProcessor(classID) {} |
| 21 | |
| 22 | const GrPrimitiveProcessor::Attribute& GrPrimitiveProcessor::vertexAttribute(int i) const { |
| 23 | SkASSERT(i >= 0 && i < this->numVertexAttributes()); |
| 24 | const auto& result = this->onVertexAttribute(i); |
| 25 | SkASSERT(result.isInitialized()); |
| 26 | return result; |
| 27 | } |
| 28 | |
| 29 | const GrPrimitiveProcessor::Attribute& GrPrimitiveProcessor::instanceAttribute(int i) const { |
| 30 | SkASSERT(i >= 0 && i < this->numInstanceAttributes()); |
| 31 | const auto& result = this->onInstanceAttribute(i); |
| 32 | SkASSERT(result.isInitialized()); |
| 33 | return result; |
| 34 | } |
| 35 | |
| 36 | #ifdef SK_DEBUG |
| 37 | size_t GrPrimitiveProcessor::debugOnly_vertexStride() const { |
| 38 | size_t stride = 0; |
| 39 | for (int i = 0; i < fVertexAttributeCnt; ++i) { |
| 40 | stride += this->vertexAttribute(i).sizeAlign4(); |
| 41 | } |
| 42 | return stride; |
| 43 | } |
| 44 | |
| 45 | size_t GrPrimitiveProcessor::debugOnly_instanceStride() const { |
| 46 | size_t stride = 0; |
| 47 | for (int i = 0; i < fInstanceAttributeCnt; ++i) { |
| 48 | stride += this->instanceAttribute(i).sizeAlign4(); |
| 49 | } |
| 50 | return stride; |
| 51 | } |
| 52 | |
| 53 | size_t GrPrimitiveProcessor::debugOnly_vertexAttributeOffset(int i) const { |
| 54 | SkASSERT(i >= 0 && i < fVertexAttributeCnt); |
| 55 | size_t offset = 0; |
| 56 | for (int j = 0; j < i; ++j) { |
| 57 | offset += this->vertexAttribute(j).sizeAlign4(); |
| 58 | } |
| 59 | return offset; |
| 60 | } |
| 61 | |
| 62 | size_t GrPrimitiveProcessor::debugOnly_instanceAttributeOffset(int i) const { |
| 63 | SkASSERT(i >= 0 && i < fInstanceAttributeCnt); |
| 64 | size_t offset = 0; |
| 65 | for (int j = 0; j < i; ++j) { |
| 66 | offset += this->instanceAttribute(j).sizeAlign4(); |
| 67 | } |
| 68 | return offset; |
| 69 | } |
| 70 | #endif |
| 71 | |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 72 | uint32_t |
wangyix | a7f4c43 | 2015-08-20 07:25:02 -0700 | [diff] [blame] | 73 | GrPrimitiveProcessor::getTransformKey(const SkTArray<const GrCoordTransform*, true>& coords, |
| 74 | int numCoords) const { |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 75 | uint32_t totalKey = 0; |
wangyix | a7f4c43 | 2015-08-20 07:25:02 -0700 | [diff] [blame] | 76 | for (int t = 0; t < numCoords; ++t) { |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 77 | uint32_t key = 0; |
| 78 | const GrCoordTransform* coordTransform = coords[t]; |
| 79 | if (coordTransform->getMatrix().hasPerspective()) { |
| 80 | key |= kGeneral_MatrixType; |
| 81 | } else { |
| 82 | key |= kNoPersp_MatrixType; |
| 83 | } |
Brian Salomon | 969bdef | 2018-06-06 17:16:05 -0400 | [diff] [blame] | 84 | key <<= t; |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 85 | SkASSERT(0 == (totalKey & key)); // keys for each transform ought not to overlap |
| 86 | totalKey |= key; |
| 87 | } |
| 88 | return totalKey; |
| 89 | } |