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, 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 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 39GrPrimitiveProcessor::getTransformKey(const SkTArray<const GrCoordTransform*, true>& coords, 40 int numCoords) const { 41 uint32_t totalKey = 0; 42 for (int t = 0; t < numCoords; ++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 (!this->hasExplicitLocalCoords()) { 52 key |= kPositionCoords_Flag; 53 } 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} 65