blob: b981977af3746a3f27b08a2e145bb808607ccc62 [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/**
Brian Osman5869ea92017-04-03 16:36:58 -040013 * 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.
joshualitt8072caa2015-02-12 14:20:52 -080015 */
16enum {
17 kMatrixTypeKeyBits = 1,
Brian Osman5869ea92017-04-03 16:36:58 -040018 kPositionCoords_Flag = 1 << kMatrixTypeKeyBits,
19 kTransformKeyBits = kMatrixTypeKeyBits + 1,
joshualitt8072caa2015-02-12 14:20:52 -080020};
21
joshualitt8072caa2015-02-12 14:20:52 -080022/**
23 * We specialize the vertex code for each of these matrix types.
24 */
25enum MatrixType {
26 kNoPersp_MatrixType = 0,
27 kGeneral_MatrixType = 1,
28};
29
30uint32_t
wangyixa7f4c432015-08-20 07:25:02 -070031GrPrimitiveProcessor::getTransformKey(const SkTArray<const GrCoordTransform*, true>& coords,
32 int numCoords) const {
joshualitt8072caa2015-02-12 14:20:52 -080033 uint32_t totalKey = 0;
wangyixa7f4c432015-08-20 07:25:02 -070034 for (int t = 0; t < numCoords; ++t) {
joshualitt8072caa2015-02-12 14:20:52 -080035 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 Salomon2ebd0c82016-10-03 17:15:28 -040043 if (!this->hasExplicitLocalCoords()) {
joshualitt8072caa2015-02-12 14:20:52 -080044 key |= kPositionCoords_Flag;
joshualitt8072caa2015-02-12 14:20:52 -080045 }
46
joshualitt8072caa2015-02-12 14:20:52 -080047 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}