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, 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 GrPrimitiveProcessor::getTransformKey(const SkTArray<const GrCoordTransform*, true>& coords,
     32                                       int numCoords) const {
     33     uint32_t totalKey = 0;
     34     for (int t = 0; t < numCoords; ++t) {
     35         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 
     43         if (!this->hasExplicitLocalCoords()) {
     44             key |= kPositionCoords_Flag;
     45         }
     46 
     47         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 }
     54