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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "src/gpu/GrPrimitiveProcessor.h" |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "src/gpu/GrCoordTransform.h" |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 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 |
Ethan Nicholas | d4efe68 | 2019-08-29 16:10:13 -0400 | [diff] [blame^] | 28 | GrPrimitiveProcessor::getTransformKey(const SkTArray<GrCoordTransform*, true>& coords, |
wangyix | a7f4c43 | 2015-08-20 07:25:02 -0700 | [diff] [blame] | 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, |
Greg Daniel | 7a82edf | 2018-12-04 10:54:34 -0500 | [diff] [blame] | 57 | const GrSamplerState& samplerState, |
Greg Daniel | 2c3398d | 2019-06-19 11:58:01 -0400 | [diff] [blame] | 58 | const GrSwizzle& swizzle, |
Greg Daniel | 7a82edf | 2018-12-04 10:54:34 -0500 | [diff] [blame] | 59 | uint32_t extraSamplerKey) { |
Brian Salomon | 67529b2 | 2019-08-13 15:31:04 -0400 | [diff] [blame] | 60 | this->reset(textureType, samplerState, swizzle, extraSamplerKey); |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | GrPrimitiveProcessor::TextureSampler::TextureSampler(GrTextureType textureType, |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 64 | GrSamplerState::Filter filterMode, |
Greg Daniel | 2c3398d | 2019-06-19 11:58:01 -0400 | [diff] [blame] | 65 | GrSamplerState::WrapMode wrapXAndY, |
| 66 | const GrSwizzle& swizzle) { |
Brian Salomon | 67529b2 | 2019-08-13 15:31:04 -0400 | [diff] [blame] | 67 | this->reset(textureType, filterMode, wrapXAndY, swizzle); |
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, |
Greg Daniel | 7a82edf | 2018-12-04 10:54:34 -0500 | [diff] [blame] | 71 | const GrSamplerState& samplerState, |
Greg Daniel | 2c3398d | 2019-06-19 11:58:01 -0400 | [diff] [blame] | 72 | const GrSwizzle& swizzle, |
Greg Daniel | 7a82edf | 2018-12-04 10:54:34 -0500 | [diff] [blame] | 73 | uint32_t extraSamplerKey) { |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 74 | fSamplerState = samplerState; |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 75 | fSamplerState.setFilterMode(clamp_filter(textureType, samplerState.filter())); |
Greg Daniel | 2c3398d | 2019-06-19 11:58:01 -0400 | [diff] [blame] | 76 | fSwizzle = swizzle; |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 77 | fTextureType = textureType; |
Greg Daniel | 7a82edf | 2018-12-04 10:54:34 -0500 | [diff] [blame] | 78 | fExtraSamplerKey = extraSamplerKey; |
Brian Salomon | 67529b2 | 2019-08-13 15:31:04 -0400 | [diff] [blame] | 79 | fIsInitialized = true; |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 80 | } |
| 81 | |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 82 | void GrPrimitiveProcessor::TextureSampler::reset(GrTextureType textureType, |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 83 | GrSamplerState::Filter filterMode, |
Greg Daniel | 2c3398d | 2019-06-19 11:58:01 -0400 | [diff] [blame] | 84 | GrSamplerState::WrapMode wrapXAndY, |
| 85 | const GrSwizzle& swizzle) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 86 | filterMode = clamp_filter(textureType, filterMode); |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 87 | fSamplerState = GrSamplerState(wrapXAndY, filterMode); |
Greg Daniel | 2c3398d | 2019-06-19 11:58:01 -0400 | [diff] [blame] | 88 | fSwizzle = swizzle; |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 89 | fTextureType = textureType; |
Brian Salomon | 67529b2 | 2019-08-13 15:31:04 -0400 | [diff] [blame] | 90 | fIsInitialized = true; |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 91 | } |