blob: 673656821b61b1f65a6031400b89f70b251ceb3e [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)),
24 kDeviceCoords_Flag = kPositionCoords_Flag + kPositionCoords_Flag,
25
26 kTransformKeyBits = kMatrixTypeKeyBits + kPrecisionBits + 2,
27};
28
29GR_STATIC_ASSERT(kHigh_GrSLPrecision < (1 << kPrecisionBits));
30
31/**
32 * We specialize the vertex code for each of these matrix types.
33 */
34enum MatrixType {
35 kNoPersp_MatrixType = 0,
36 kGeneral_MatrixType = 1,
37};
38
39uint32_t
40GrPrimitiveProcessor::getTransformKey(const SkTArray<const GrCoordTransform*, true>& coords) const {
41 uint32_t totalKey = 0;
42 for (int t = 0; t < coords.count(); ++t) {
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
51 if (kLocal_GrCoordSet == coordTransform->sourceCoords() &&
52 !this->hasExplicitLocalCoords()) {
53 key |= kPositionCoords_Flag;
54 } else if (kDevice_GrCoordSet == coordTransform->sourceCoords()) {
55 key |= kDeviceCoords_Flag;
56 }
57
58 GR_STATIC_ASSERT(kGrSLPrecisionCount <= (1 << kPrecisionBits));
59 key |= (coordTransform->precision() << kPrecisionShift);
60
61 key <<= kTransformKeyBits * t;
62
63 SkASSERT(0 == (totalKey & key)); // keys for each transform ought not to overlap
64 totalKey |= key;
65 }
66 return totalKey;
67}