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