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 | /** |
| 13 | * The key for an individual coord transform is made up of a matrix type, a precision, and a bit |
| 14 | * that indicates the source of the input coords. |
| 15 | */ |
| 16 | enum { |
| 17 | kMatrixTypeKeyBits = 1, |
| 18 | kMatrixTypeKeyMask = (1 << kMatrixTypeKeyBits) - 1, |
| 19 | |
| 20 | kPrecisionBits = 2, |
| 21 | kPrecisionShift = kMatrixTypeKeyBits, |
| 22 | |
| 23 | kPositionCoords_Flag = (1 << (kPrecisionShift + kPrecisionBits)), |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 24 | |
| 25 | kTransformKeyBits = kMatrixTypeKeyBits + kPrecisionBits + 2, |
| 26 | }; |
| 27 | |
| 28 | GR_STATIC_ASSERT(kHigh_GrSLPrecision < (1 << kPrecisionBits)); |
| 29 | |
| 30 | /** |
| 31 | * We specialize the vertex code for each of these matrix types. |
| 32 | */ |
| 33 | enum MatrixType { |
| 34 | kNoPersp_MatrixType = 0, |
| 35 | kGeneral_MatrixType = 1, |
| 36 | }; |
| 37 | |
| 38 | uint32_t |
wangyix | a7f4c43 | 2015-08-20 07:25:02 -0700 | [diff] [blame] | 39 | GrPrimitiveProcessor::getTransformKey(const SkTArray<const GrCoordTransform*, true>& coords, |
| 40 | int numCoords) const { |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 41 | uint32_t totalKey = 0; |
wangyix | a7f4c43 | 2015-08-20 07:25:02 -0700 | [diff] [blame] | 42 | for (int t = 0; t < numCoords; ++t) { |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 43 | uint32_t key = 0; |
| 44 | const GrCoordTransform* coordTransform = coords[t]; |
| 45 | if (coordTransform->getMatrix().hasPerspective()) { |
| 46 | key |= kGeneral_MatrixType; |
| 47 | } else { |
| 48 | key |= kNoPersp_MatrixType; |
| 49 | } |
| 50 | |
Brian Salomon | 2ebd0c8 | 2016-10-03 17:15:28 -0400 | [diff] [blame] | 51 | if (!this->hasExplicitLocalCoords()) { |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 52 | key |= kPositionCoords_Flag; |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | GR_STATIC_ASSERT(kGrSLPrecisionCount <= (1 << kPrecisionBits)); |
| 56 | key |= (coordTransform->precision() << kPrecisionShift); |
| 57 | |
| 58 | key <<= kTransformKeyBits * t; |
| 59 | |
| 60 | SkASSERT(0 == (totalKey & key)); // keys for each transform ought not to overlap |
| 61 | totalKey |= key; |
| 62 | } |
| 63 | return totalKey; |
| 64 | } |