blob: 180217e26166bb0031cd578b6777378ae90fb7ad [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
wangyixa7f4c432015-08-20 07:25:02 -070040GrPrimitiveProcessor::getTransformKey(const SkTArray<const GrCoordTransform*, true>& coords,
41 int numCoords) const {
joshualitt8072caa2015-02-12 14:20:52 -080042 uint32_t totalKey = 0;
wangyixa7f4c432015-08-20 07:25:02 -070043 for (int t = 0; t < numCoords; ++t) {
joshualitt8072caa2015-02-12 14:20:52 -080044 uint32_t key = 0;
45 const GrCoordTransform* coordTransform = coords[t];
46 if (coordTransform->getMatrix().hasPerspective()) {
47 key |= kGeneral_MatrixType;
48 } else {
49 key |= kNoPersp_MatrixType;
50 }
51
52 if (kLocal_GrCoordSet == coordTransform->sourceCoords() &&
53 !this->hasExplicitLocalCoords()) {
54 key |= kPositionCoords_Flag;
55 } else if (kDevice_GrCoordSet == coordTransform->sourceCoords()) {
56 key |= kDeviceCoords_Flag;
57 }
58
59 GR_STATIC_ASSERT(kGrSLPrecisionCount <= (1 << kPrecisionBits));
60 key |= (coordTransform->precision() << kPrecisionShift);
61
62 key <<= kTransformKeyBits * t;
63
64 SkASSERT(0 == (totalKey & key)); // keys for each transform ought not to overlap
65 totalKey |= key;
66 }
67 return totalKey;
68}