blob: 06d36d2be0d7dcaaa78496d2d6396ad63bbeb61d [file] [log] [blame]
Ethan Nicholas68990be2017-07-13 09:36:52 -04001/*
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
8in uniform sampler2D image;
Ethan Nicholasf7b88202017-09-18 14:10:39 -04009in half4x4 matrix;
Ethan Nicholas68990be2017-07-13 09:36:52 -040010
Robert Phillipsa98183a2018-03-23 11:44:25 +000011@constructorParams {
12 GrSamplerState samplerParams
13}
14
Ethan Nicholas68990be2017-07-13 09:36:52 -040015@coordTransform(image) {
16 matrix
17}
18
19@samplerParams(image) {
20 samplerParams
21}
22
23@make {
Brian Salomonaff329b2017-08-11 09:40:37 -040024 static std::unique_ptr<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy,
Brian Salomonaff329b2017-08-11 09:40:37 -040025 const SkMatrix& matrix) {
26 return std::unique_ptr<GrFragmentProcessor>(
Brian Osman2240be92017-10-18 13:15:13 -040027 new GrSimpleTextureEffect(std::move(proxy), matrix,
Brian Salomon2bbdcc42017-09-07 12:36:34 -040028 GrSamplerState(GrSamplerState::WrapMode::kClamp, GrSamplerState::Filter::kNearest)));
Ethan Nicholas68990be2017-07-13 09:36:52 -040029 }
30
31 /* clamp mode */
Brian Salomonaff329b2017-08-11 09:40:37 -040032 static std::unique_ptr<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy,
Brian Salomonaff329b2017-08-11 09:40:37 -040033 const SkMatrix& matrix,
Brian Salomon2bbdcc42017-09-07 12:36:34 -040034 GrSamplerState::Filter filter) {
Brian Salomonaff329b2017-08-11 09:40:37 -040035 return std::unique_ptr<GrFragmentProcessor>(
Brian Osman2240be92017-10-18 13:15:13 -040036 new GrSimpleTextureEffect(std::move(proxy), matrix,
Brian Salomon2bbdcc42017-09-07 12:36:34 -040037 GrSamplerState(GrSamplerState::WrapMode::kClamp, filter)));
Ethan Nicholas68990be2017-07-13 09:36:52 -040038 }
39
Brian Salomonaff329b2017-08-11 09:40:37 -040040 static std::unique_ptr<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy,
Brian Salomonaff329b2017-08-11 09:40:37 -040041 const SkMatrix& matrix,
Brian Salomon2bbdcc42017-09-07 12:36:34 -040042 const GrSamplerState& p) {
Brian Salomonaff329b2017-08-11 09:40:37 -040043 return std::unique_ptr<GrFragmentProcessor>(
Brian Osman2240be92017-10-18 13:15:13 -040044 new GrSimpleTextureEffect(std::move(proxy), matrix, p));
Ethan Nicholas68990be2017-07-13 09:36:52 -040045 }
46}
47
Robert Phillipsa98183a2018-03-23 11:44:25 +000048@optimizationFlags {
Michael Ludwig257a03d2018-12-13 14:07:07 -050049 ModulateForSamplerOptFlags(image->config(),
50 samplerParams.wrapModeX() == GrSamplerState::WrapMode::kClampToBorder ||
51 samplerParams.wrapModeY() == GrSamplerState::WrapMode::kClampToBorder)
Ethan Nicholas68990be2017-07-13 09:36:52 -040052}
53
54void main() {
Brian Osman2240be92017-10-18 13:15:13 -040055 sk_OutColor = sk_InColor * texture(image, sk_TransformedCoords2D[0]);
Ethan Nicholas68990be2017-07-13 09:36:52 -040056}
57
58@test(testData) {
59 int texIdx = testData->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx
60 : GrProcessorUnitTest::kAlphaTextureIdx;
Brian Salomon2bbdcc42017-09-07 12:36:34 -040061 GrSamplerState::WrapMode wrapModes[2];
62 GrTest::TestWrapModes(testData->fRandom, wrapModes);
Robert Phillipsb350f1c2017-10-20 17:26:51 -040063 if (!testData->caps()->npotTextureTileSupport()) {
64 // Performing repeat sampling on npot textures will cause asserts on HW
65 // that lacks support.
66 wrapModes[0] = GrSamplerState::WrapMode::kClamp;
67 wrapModes[1] = GrSamplerState::WrapMode::kClamp;
68 }
69
Brian Salomon2bbdcc42017-09-07 12:36:34 -040070 GrSamplerState params(wrapModes, testData->fRandom->nextBool()
71 ? GrSamplerState::Filter::kBilerp
72 : GrSamplerState::Filter::kNearest);
Ethan Nicholas68990be2017-07-13 09:36:52 -040073
74 const SkMatrix& matrix = GrTest::TestMatrix(testData->fRandom);
Robert Phillips2b2936e2017-10-20 15:11:35 -040075 return GrSimpleTextureEffect::Make(testData->textureProxy(texIdx), matrix, params);
Ethan Nicholas68990be2017-07-13 09:36:52 -040076}