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 * 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 20 GrPrimitiveProcessor::GrPrimitiveProcessor(ClassID classID) : GrProcessor(classID) {} 21 22 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 28 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 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 56 GrPrimitiveProcessor::TextureSampler::TextureSampler(GrTextureType textureType, 57 GrPixelConfig config, 58 const GrSamplerState& samplerState, 59 uint32_t extraSamplerKey) { 60 this->reset(textureType, config, samplerState, extraSamplerKey); 61 } 62 63 GrPrimitiveProcessor::TextureSampler::TextureSampler(GrTextureType textureType, 64 GrPixelConfig config, 65 GrSamplerState::Filter filterMode, 66 GrSamplerState::WrapMode wrapXAndY) { 67 this->reset(textureType, config, filterMode, wrapXAndY); 68 } 69 70 void GrPrimitiveProcessor::TextureSampler::reset(GrTextureType textureType, 71 GrPixelConfig config, 72 const GrSamplerState& samplerState, 73 uint32_t extraSamplerKey) { 74 SkASSERT(kUnknown_GrPixelConfig != config); 75 fSamplerState = samplerState; 76 fSamplerState.setFilterMode(clamp_filter(textureType, samplerState.filter())); 77 fTextureType = textureType; 78 fConfig = config; 79 fExtraSamplerKey = extraSamplerKey; 80 SkASSERT(!fExtraSamplerKey || textureType == GrTextureType::kExternal); 81 } 82 83 void GrPrimitiveProcessor::TextureSampler::reset(GrTextureType textureType, 84 GrPixelConfig config, 85 GrSamplerState::Filter filterMode, 86 GrSamplerState::WrapMode wrapXAndY) { 87 SkASSERT(kUnknown_GrPixelConfig != config); 88 filterMode = clamp_filter(textureType, filterMode); 89 fSamplerState = GrSamplerState(wrapXAndY, filterMode); 90 fTextureType = textureType; 91 fConfig = config; 92 } 93