Line data Source code
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, and a bit that indicates
14 : * the source of the input coords.
15 : */
16 : enum {
17 : kMatrixTypeKeyBits = 1,
18 : kPositionCoords_Flag = 1 << kMatrixTypeKeyBits,
19 : kTransformKeyBits = kMatrixTypeKeyBits + 1,
20 : };
21 :
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
31 0 : GrPrimitiveProcessor::getTransformKey(const SkTArray<const GrCoordTransform*, true>& coords,
32 : int numCoords) const {
33 0 : uint32_t totalKey = 0;
34 0 : for (int t = 0; t < numCoords; ++t) {
35 0 : uint32_t key = 0;
36 0 : const GrCoordTransform* coordTransform = coords[t];
37 0 : if (coordTransform->getMatrix().hasPerspective()) {
38 0 : key |= kGeneral_MatrixType;
39 : } else {
40 0 : key |= kNoPersp_MatrixType;
41 : }
42 :
43 0 : if (!this->hasExplicitLocalCoords()) {
44 0 : key |= kPositionCoords_Flag;
45 : }
46 :
47 0 : key <<= kTransformKeyBits * t;
48 :
49 0 : SkASSERT(0 == (totalKey & key)); // keys for each transform ought not to overlap
50 0 : totalKey |= key;
51 : }
52 0 : return totalKey;
53 : }
|