Ethan Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 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 | in uniform sampler2D image; |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 9 | in half4x4 matrix; |
Ethan Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 10 | |
Robert Phillips | a98183a | 2018-03-23 11:44:25 +0000 | [diff] [blame] | 11 | @constructorParams { |
Brian Salomon | 7a538b1 | 2019-11-21 22:03:09 -0500 | [diff] [blame^] | 12 | SkAlphaType alphaType, |
Robert Phillips | a98183a | 2018-03-23 11:44:25 +0000 | [diff] [blame] | 13 | GrSamplerState samplerParams |
| 14 | } |
| 15 | |
Ethan Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 16 | @coordTransform(image) { |
| 17 | matrix |
| 18 | } |
| 19 | |
| 20 | @samplerParams(image) { |
| 21 | samplerParams |
| 22 | } |
| 23 | |
| 24 | @make { |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 25 | static std::unique_ptr<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy, |
Brian Salomon | 7a538b1 | 2019-11-21 22:03:09 -0500 | [diff] [blame^] | 26 | SkAlphaType alphaType, |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 27 | const SkMatrix& matrix) { |
| 28 | return std::unique_ptr<GrFragmentProcessor>( |
Brian Salomon | 7a538b1 | 2019-11-21 22:03:09 -0500 | [diff] [blame^] | 29 | new GrSimpleTextureEffect(std::move(proxy), matrix, alphaType, |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 30 | GrSamplerState(GrSamplerState::WrapMode::kClamp, GrSamplerState::Filter::kNearest))); |
Ethan Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | /* clamp mode */ |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 34 | static std::unique_ptr<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy, |
Brian Salomon | 7a538b1 | 2019-11-21 22:03:09 -0500 | [diff] [blame^] | 35 | SkAlphaType alphaType, |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 36 | const SkMatrix& matrix, |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 37 | GrSamplerState::Filter filter) { |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 38 | return std::unique_ptr<GrFragmentProcessor>( |
Brian Salomon | 7a538b1 | 2019-11-21 22:03:09 -0500 | [diff] [blame^] | 39 | new GrSimpleTextureEffect(std::move(proxy), matrix, alphaType, |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 40 | GrSamplerState(GrSamplerState::WrapMode::kClamp, filter))); |
Ethan Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 41 | } |
| 42 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 43 | static std::unique_ptr<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy, |
Brian Salomon | 7a538b1 | 2019-11-21 22:03:09 -0500 | [diff] [blame^] | 44 | SkAlphaType alphaType, |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 45 | const SkMatrix& matrix, |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 46 | const GrSamplerState& p) { |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 47 | return std::unique_ptr<GrFragmentProcessor>( |
Brian Salomon | 7a538b1 | 2019-11-21 22:03:09 -0500 | [diff] [blame^] | 48 | new GrSimpleTextureEffect(std::move(proxy), matrix, alphaType, p)); |
Ethan Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 49 | } |
| 50 | } |
| 51 | |
Robert Phillips | a98183a | 2018-03-23 11:44:25 +0000 | [diff] [blame] | 52 | @optimizationFlags { |
Brian Salomon | 7a538b1 | 2019-11-21 22:03:09 -0500 | [diff] [blame^] | 53 | ModulateForSamplerOptFlags(alphaType, |
Michael Ludwig | 257a03d | 2018-12-13 14:07:07 -0500 | [diff] [blame] | 54 | samplerParams.wrapModeX() == GrSamplerState::WrapMode::kClampToBorder || |
| 55 | samplerParams.wrapModeY() == GrSamplerState::WrapMode::kClampToBorder) |
Ethan Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | void main() { |
Ethan Nicholas | 1386366 | 2019-07-29 13:05:15 -0400 | [diff] [blame] | 59 | sk_OutColor = sk_InColor * sample(image, sk_TransformedCoords2D[0]); |
Ethan Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | @test(testData) { |
| 63 | int texIdx = testData->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx |
| 64 | : GrProcessorUnitTest::kAlphaTextureIdx; |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 65 | GrSamplerState::WrapMode wrapModes[2]; |
| 66 | GrTest::TestWrapModes(testData->fRandom, wrapModes); |
Robert Phillips | b350f1c | 2017-10-20 17:26:51 -0400 | [diff] [blame] | 67 | if (!testData->caps()->npotTextureTileSupport()) { |
| 68 | // Performing repeat sampling on npot textures will cause asserts on HW |
| 69 | // that lacks support. |
| 70 | wrapModes[0] = GrSamplerState::WrapMode::kClamp; |
| 71 | wrapModes[1] = GrSamplerState::WrapMode::kClamp; |
| 72 | } |
| 73 | |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 74 | GrSamplerState params(wrapModes, testData->fRandom->nextBool() |
| 75 | ? GrSamplerState::Filter::kBilerp |
| 76 | : GrSamplerState::Filter::kNearest); |
Ethan Nicholas | 68990be | 2017-07-13 09:36:52 -0400 | [diff] [blame] | 77 | |
| 78 | const SkMatrix& matrix = GrTest::TestMatrix(testData->fRandom); |
Brian Salomon | 7a538b1 | 2019-11-21 22:03:09 -0500 | [diff] [blame^] | 79 | auto alphaType = static_cast<SkAlphaType>( |
| 80 | testData->fRandom->nextULessThan(kLastEnum_SkAlphaType + 1)); |
Greg Daniel | c594e62 | 2019-10-15 14:01:49 -0400 | [diff] [blame] | 81 | return GrSimpleTextureEffect::Make(testData->textureProxy(texIdx), |
Brian Salomon | 7a538b1 | 2019-11-21 22:03:09 -0500 | [diff] [blame^] | 82 | alphaType, matrix, params);} |