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 | 0f70be8 | 2018-10-08 17:35:08 +0000 | [diff] [blame] | 58 | const GrSamplerState& samplerState) { |
| 59 | this->reset(textureType, config, samplerState); |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | GrPrimitiveProcessor::TextureSampler::TextureSampler(GrTextureType textureType, |
| 63 | GrPixelConfig config, |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 64 | GrSamplerState::Filter filterMode, |
Greg Daniel | 0f70be8 | 2018-10-08 17:35:08 +0000 | [diff] [blame] | 65 | GrSamplerState::WrapMode wrapXAndY) { |
| 66 | this->reset(textureType, config, filterMode, wrapXAndY); |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 67 | } |
| 68 | |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 69 | void GrPrimitiveProcessor::TextureSampler::reset(GrTextureType textureType, |
| 70 | GrPixelConfig config, |
Greg Daniel | 0f70be8 | 2018-10-08 17:35:08 +0000 | [diff] [blame] | 71 | const GrSamplerState& samplerState) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 72 | SkASSERT(kUnknown_GrPixelConfig != config); |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 73 | fSamplerState = samplerState; |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 74 | fSamplerState.setFilterMode(clamp_filter(textureType, samplerState.filter())); |
| 75 | fTextureType = textureType; |
| 76 | fConfig = config; |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 77 | } |
| 78 | |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 79 | void GrPrimitiveProcessor::TextureSampler::reset(GrTextureType textureType, |
| 80 | GrPixelConfig config, |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 81 | GrSamplerState::Filter filterMode, |
Greg Daniel | 0f70be8 | 2018-10-08 17:35:08 +0000 | [diff] [blame] | 82 | GrSamplerState::WrapMode wrapXAndY) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 83 | SkASSERT(kUnknown_GrPixelConfig != config); |
| 84 | filterMode = clamp_filter(textureType, filterMode); |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 85 | fSamplerState = GrSamplerState(wrapXAndY, filterMode); |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 86 | fTextureType = textureType; |
| 87 | fConfig = config; |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 88 | } |