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 | |
Robert Phillips | 787fd9d | 2021-03-22 14:48:09 -0400 | [diff] [blame] | 8 | #include "src/gpu/GrGeometryProcessor.h" |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 9 | |
Brian Salomon | 7eabfe8 | 2019-12-02 14:20:20 -0500 | [diff] [blame] | 10 | #include "src/gpu/GrFragmentProcessor.h" |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 11 | |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 12 | |
Robert Phillips | 787fd9d | 2021-03-22 14:48:09 -0400 | [diff] [blame] | 13 | GrGeometryProcessor::GrGeometryProcessor(ClassID classID) : GrProcessor(classID) {} |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 14 | |
Robert Phillips | 787fd9d | 2021-03-22 14:48:09 -0400 | [diff] [blame] | 15 | const GrGeometryProcessor::TextureSampler& GrGeometryProcessor::textureSampler(int i) const { |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 16 | SkASSERT(i >= 0 && i < this->numTextureSamplers()); |
| 17 | return this->onTextureSampler(i); |
| 18 | } |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 19 | |
Robert Phillips | 787fd9d | 2021-03-22 14:48:09 -0400 | [diff] [blame] | 20 | uint32_t GrGeometryProcessor::ComputeCoordTransformsKey(const GrFragmentProcessor& fp) { |
Michael Ludwig | e7e25ac | 2020-06-26 12:53:03 -0400 | [diff] [blame] | 21 | // This is highly coupled with the code in GrGLSLGeometryProcessor::collectTransforms(). |
Brian Salomon | 66b500a | 2021-08-02 12:37:14 -0400 | [diff] [blame^] | 22 | uint32_t key = static_cast<uint32_t>(fp.sampleUsage().kind()) << 1; |
| 23 | // This needs to be updated if GP starts specializing varyings on additional matrix types. |
| 24 | if (fp.sampleUsage().hasPerspective()) { |
| 25 | key |= 0b1; |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 26 | } |
Michael Ludwig | e88320b | 2020-06-24 09:04:56 -0400 | [diff] [blame] | 27 | return key; |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 28 | } |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 29 | |
| 30 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 31 | |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 32 | static inline GrSamplerState::Filter clamp_filter(GrTextureType type, |
| 33 | GrSamplerState::Filter requestedFilter) { |
| 34 | if (GrTextureTypeHasRestrictedSampling(type)) { |
Brian Salomon | a3b02f5 | 2020-07-15 16:02:01 -0400 | [diff] [blame] | 35 | return std::min(requestedFilter, GrSamplerState::Filter::kLinear); |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 36 | } |
| 37 | return requestedFilter; |
Brian Salomon | af87483 | 2018-08-03 11:53:40 -0400 | [diff] [blame] | 38 | } |
| 39 | |
Robert Phillips | 787fd9d | 2021-03-22 14:48:09 -0400 | [diff] [blame] | 40 | GrGeometryProcessor::TextureSampler::TextureSampler(GrSamplerState samplerState, |
| 41 | const GrBackendFormat& backendFormat, |
| 42 | const GrSwizzle& swizzle) { |
Robert Phillips | 323471e | 2019-11-11 11:33:37 -0500 | [diff] [blame] | 43 | this->reset(samplerState, backendFormat, swizzle); |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 44 | } |
| 45 | |
Robert Phillips | 787fd9d | 2021-03-22 14:48:09 -0400 | [diff] [blame] | 46 | void GrGeometryProcessor::TextureSampler::reset(GrSamplerState samplerState, |
| 47 | const GrBackendFormat& backendFormat, |
| 48 | const GrSwizzle& swizzle) { |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 49 | fSamplerState = samplerState; |
Robert Phillips | f272bea | 2019-10-17 08:56:16 -0400 | [diff] [blame] | 50 | fSamplerState.setFilterMode(clamp_filter(backendFormat.textureType(), samplerState.filter())); |
| 51 | fBackendFormat = backendFormat; |
Greg Daniel | 2c3398d | 2019-06-19 11:58:01 -0400 | [diff] [blame] | 52 | fSwizzle = swizzle; |
Brian Salomon | 67529b2 | 2019-08-13 15:31:04 -0400 | [diff] [blame] | 53 | fIsInitialized = true; |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 54 | } |