joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 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 | /** |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 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 | |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 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 | } |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 26 | |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 27 | uint32_t |
wangyix | a7f4c43 | 2015-08-20 07:25:02 -0700 | [diff] [blame] | 28 | GrPrimitiveProcessor::getTransformKey(const SkTArray<const GrCoordTransform*, true>& coords, |
| 29 | int numCoords) const { |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 30 | uint32_t totalKey = 0; |
wangyix | a7f4c43 | 2015-08-20 07:25:02 -0700 | [diff] [blame] | 31 | for (int t = 0; t < numCoords; ++t) { |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 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 | } |
Brian Salomon | 969bdef | 2018-06-06 17:16:05 -0400 | [diff] [blame] | 39 | key <<= t; |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 40 | SkASSERT(0 == (totalKey & key)); // keys for each transform ought not to overlap |
| 41 | totalKey |= key; |
| 42 | } |
| 43 | return totalKey; |
| 44 | } |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 45 | |
| 46 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 47 | |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 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; |
Brian Salomon | af87483 | 2018-08-03 11:53:40 -0400 | [diff] [blame] | 54 | } |
| 55 | |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 56 | GrPrimitiveProcessor::TextureSampler::TextureSampler(GrTextureType textureType, |
| 57 | GrPixelConfig config, |
Greg Daniel | 7a82edf | 2018-12-04 10:54:34 -0500 | [diff] [blame] | 58 | const GrSamplerState& samplerState, |
| 59 | uint32_t extraSamplerKey) { |
| 60 | this->reset(textureType, config, samplerState, extraSamplerKey); |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | GrPrimitiveProcessor::TextureSampler::TextureSampler(GrTextureType textureType, |
| 64 | GrPixelConfig config, |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 65 | GrSamplerState::Filter filterMode, |
Greg Daniel | 0f70be8 | 2018-10-08 17:35:08 +0000 | [diff] [blame] | 66 | GrSamplerState::WrapMode wrapXAndY) { |
| 67 | this->reset(textureType, config, filterMode, wrapXAndY); |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 68 | } |
| 69 | |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 70 | void GrPrimitiveProcessor::TextureSampler::reset(GrTextureType textureType, |
| 71 | GrPixelConfig config, |
Greg Daniel | 7a82edf | 2018-12-04 10:54:34 -0500 | [diff] [blame] | 72 | const GrSamplerState& samplerState, |
| 73 | uint32_t extraSamplerKey) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 74 | SkASSERT(kUnknown_GrPixelConfig != config); |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 75 | fSamplerState = samplerState; |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 76 | fSamplerState.setFilterMode(clamp_filter(textureType, samplerState.filter())); |
| 77 | fTextureType = textureType; |
| 78 | fConfig = config; |
Greg Daniel | 7a82edf | 2018-12-04 10:54:34 -0500 | [diff] [blame] | 79 | fExtraSamplerKey = extraSamplerKey; |
| 80 | SkASSERT(!fExtraSamplerKey || textureType == GrTextureType::kExternal); |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 81 | } |
| 82 | |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 83 | void GrPrimitiveProcessor::TextureSampler::reset(GrTextureType textureType, |
| 84 | GrPixelConfig config, |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 85 | GrSamplerState::Filter filterMode, |
Greg Daniel | 0f70be8 | 2018-10-08 17:35:08 +0000 | [diff] [blame] | 86 | GrSamplerState::WrapMode wrapXAndY) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 87 | SkASSERT(kUnknown_GrPixelConfig != config); |
| 88 | filterMode = clamp_filter(textureType, filterMode); |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 89 | fSamplerState = GrSamplerState(wrapXAndY, filterMode); |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 90 | fTextureType = textureType; |
| 91 | fConfig = config; |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 92 | } |