blob: 2aaaa0474fe39d399ade665898d9ccefa2d1d3b2 [file] [log] [blame]
joshualitt8072caa2015-02-12 14:20:52 -08001/*
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 */
16enum {
17 kMatrixTypeKeyBits = 1,
18 kMatrixTypeKeyMask = (1 << kMatrixTypeKeyBits) - 1,
19
20 kPrecisionBits = 2,
21 kPrecisionShift = kMatrixTypeKeyBits,
22
23 kPositionCoords_Flag = (1 << (kPrecisionShift + kPrecisionBits)),
joshualitt8072caa2015-02-12 14:20:52 -080024
25 kTransformKeyBits = kMatrixTypeKeyBits + kPrecisionBits + 2,
26};
27
28GR_STATIC_ASSERT(kHigh_GrSLPrecision < (1 << kPrecisionBits));
29
30/**
31 * We specialize the vertex code for each of these matrix types.
32 */
33enum MatrixType {
34 kNoPersp_MatrixType = 0,
35 kGeneral_MatrixType = 1,
36};
37
38uint32_t
wangyixa7f4c432015-08-20 07:25:02 -070039GrPrimitiveProcessor::getTransformKey(const SkTArray<const GrCoordTransform*, true>& coords,
40 int numCoords) const {
joshualitt8072caa2015-02-12 14:20:52 -080041 uint32_t totalKey = 0;
wangyixa7f4c432015-08-20 07:25:02 -070042 for (int t = 0; t < numCoords; ++t) {
joshualitt8072caa2015-02-12 14:20:52 -080043 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 Salomon2ebd0c82016-10-03 17:15:28 -040051 if (!this->hasExplicitLocalCoords()) {
joshualitt8072caa2015-02-12 14:20:52 -080052 key |= kPositionCoords_Flag;
joshualitt8072caa2015-02-12 14:20:52 -080053 }
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}