• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "src/gpu/GrPrimitiveProcessor.h"
9 
10 #include "src/gpu/GrCoordTransform.h"
11 
12 /**
13  * We specialize the vertex code for each of these matrix types.
14  */
15 enum MatrixType {
16     kNoPersp_MatrixType  = 0,
17     kGeneral_MatrixType  = 1,
18 };
19 
GrPrimitiveProcessor(ClassID classID)20 GrPrimitiveProcessor::GrPrimitiveProcessor(ClassID classID) : GrProcessor(classID) {}
21 
textureSampler(int i) const22 const GrPrimitiveProcessor::TextureSampler& GrPrimitiveProcessor::textureSampler(int i) const {
23     SkASSERT(i >= 0 && i < this->numTextureSamplers());
24     return this->onTextureSampler(i);
25 }
26 
27 uint32_t
getTransformKey(const SkTArray<const GrCoordTransform *,true> & coords,int numCoords) const28 GrPrimitiveProcessor::getTransformKey(const SkTArray<const GrCoordTransform*, true>& coords,
29                                       int numCoords) const {
30     uint32_t totalKey = 0;
31     for (int t = 0; t < numCoords; ++t) {
32         uint32_t key = 0;
33         const GrCoordTransform* coordTransform = coords[t];
34         if (coordTransform->getMatrix().hasPerspective()) {
35             key |= kGeneral_MatrixType;
36         } else {
37             key |= kNoPersp_MatrixType;
38         }
39         key <<= t;
40         SkASSERT(0 == (totalKey & key)); // keys for each transform ought not to overlap
41         totalKey |= key;
42     }
43     return totalKey;
44 }
45 
46 ///////////////////////////////////////////////////////////////////////////////////////////////////
47 
clamp_filter(GrTextureType type,GrSamplerState::Filter requestedFilter)48 static inline GrSamplerState::Filter clamp_filter(GrTextureType type,
49                                                   GrSamplerState::Filter requestedFilter) {
50     if (GrTextureTypeHasRestrictedSampling(type)) {
51         return SkTMin(requestedFilter, GrSamplerState::Filter::kBilerp);
52     }
53     return requestedFilter;
54 }
55 
TextureSampler(GrTextureType textureType,const GrSamplerState & samplerState,const GrSwizzle & swizzle,uint32_t extraSamplerKey)56 GrPrimitiveProcessor::TextureSampler::TextureSampler(GrTextureType textureType,
57                                                      const GrSamplerState& samplerState,
58                                                      const GrSwizzle& swizzle,
59                                                      uint32_t extraSamplerKey) {
60     this->reset(textureType, samplerState, swizzle, extraSamplerKey);
61 }
62 
TextureSampler(GrTextureType textureType,GrSamplerState::Filter filterMode,GrSamplerState::WrapMode wrapXAndY,const GrSwizzle & swizzle)63 GrPrimitiveProcessor::TextureSampler::TextureSampler(GrTextureType textureType,
64                                                      GrSamplerState::Filter filterMode,
65                                                      GrSamplerState::WrapMode wrapXAndY,
66                                                      const GrSwizzle& swizzle) {
67     this->reset(textureType, filterMode, wrapXAndY, swizzle);
68 }
69 
reset(GrTextureType textureType,const GrSamplerState & samplerState,const GrSwizzle & swizzle,uint32_t extraSamplerKey)70 void GrPrimitiveProcessor::TextureSampler::reset(GrTextureType textureType,
71                                                  const GrSamplerState& samplerState,
72                                                  const GrSwizzle& swizzle,
73                                                  uint32_t extraSamplerKey) {
74     fSamplerState = samplerState;
75     fSamplerState.setFilterMode(clamp_filter(textureType, samplerState.filter()));
76     fSwizzle = swizzle;
77     fTextureType = textureType;
78     fExtraSamplerKey = extraSamplerKey;
79     fIsInitialized = true;
80 }
81 
reset(GrTextureType textureType,GrSamplerState::Filter filterMode,GrSamplerState::WrapMode wrapXAndY,const GrSwizzle & swizzle)82 void GrPrimitiveProcessor::TextureSampler::reset(GrTextureType textureType,
83                                                  GrSamplerState::Filter filterMode,
84                                                  GrSamplerState::WrapMode wrapXAndY,
85                                                  const GrSwizzle& swizzle) {
86     filterMode = clamp_filter(textureType, filterMode);
87     fSamplerState = GrSamplerState(wrapXAndY, filterMode);
88     fSwizzle = swizzle;
89     fTextureType = textureType;
90     fIsInitialized = true;
91 }
92