Home | History | Annotate | Download | only in gpu
      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  */
     16 enum {
     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 
     29 GR_STATIC_ASSERT(kHigh_GrSLPrecision < (1 << kPrecisionBits));
     30 
     31 /**
     32  * We specialize the vertex code for each of these matrix types.
     33  */
     34 enum MatrixType {
     35     kNoPersp_MatrixType  = 0,
     36     kGeneral_MatrixType  = 1,
     37 };
     38 
     39 uint32_t
     40 GrPrimitiveProcessor::getTransformKey(const SkTArray<const GrCoordTransform*, true>& coords,
     41                                       int numCoords) const {
     42     uint32_t totalKey = 0;
     43     for (int t = 0; t < numCoords; ++t) {
     44         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 }
     69