blob: beb385010c4c338a3108e85683d9d346498e6175 [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 {
Brian Salomon7a538b12019-11-21 22:03:09 -050012 SkAlphaType alphaType,
Robert Phillipsa98183a2018-03-23 11:44:25 +000013 GrSamplerState samplerParams
14}
15
Ethan Nicholas68990be2017-07-13 09:36:52 -040016@coordTransform(image) {
17 matrix
18}
19
20@samplerParams(image) {
21 samplerParams
22}
23
24@make {
Brian Salomonaff329b2017-08-11 09:40:37 -040025 static std::unique_ptr<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy,
Brian Salomon7a538b12019-11-21 22:03:09 -050026 SkAlphaType alphaType,
Brian Salomonaff329b2017-08-11 09:40:37 -040027 const SkMatrix& matrix) {
28 return std::unique_ptr<GrFragmentProcessor>(
Brian Salomon7a538b12019-11-21 22:03:09 -050029 new GrSimpleTextureEffect(std::move(proxy), matrix, alphaType,
Brian Salomon2bbdcc42017-09-07 12:36:34 -040030 GrSamplerState(GrSamplerState::WrapMode::kClamp, GrSamplerState::Filter::kNearest)));
Ethan Nicholas68990be2017-07-13 09:36:52 -040031 }
32
33 /* clamp mode */
Brian Salomonaff329b2017-08-11 09:40:37 -040034 static std::unique_ptr<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy,
Brian Salomon7a538b12019-11-21 22:03:09 -050035 SkAlphaType alphaType,
Brian Salomonaff329b2017-08-11 09:40:37 -040036 const SkMatrix& matrix,
Brian Salomon2bbdcc42017-09-07 12:36:34 -040037 GrSamplerState::Filter filter) {
Brian Salomonaff329b2017-08-11 09:40:37 -040038 return std::unique_ptr<GrFragmentProcessor>(
Brian Salomon7a538b12019-11-21 22:03:09 -050039 new GrSimpleTextureEffect(std::move(proxy), matrix, alphaType,
Brian Salomon2bbdcc42017-09-07 12:36:34 -040040 GrSamplerState(GrSamplerState::WrapMode::kClamp, filter)));
Ethan Nicholas68990be2017-07-13 09:36:52 -040041 }
42
Brian Salomonaff329b2017-08-11 09:40:37 -040043 static std::unique_ptr<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy,
Brian Salomon7a538b12019-11-21 22:03:09 -050044 SkAlphaType alphaType,
Brian Salomonaff329b2017-08-11 09:40:37 -040045 const SkMatrix& matrix,
Brian Salomon2bbdcc42017-09-07 12:36:34 -040046 const GrSamplerState& p) {
Brian Salomonaff329b2017-08-11 09:40:37 -040047 return std::unique_ptr<GrFragmentProcessor>(
Brian Salomon7a538b12019-11-21 22:03:09 -050048 new GrSimpleTextureEffect(std::move(proxy), matrix, alphaType, p));
Ethan Nicholas68990be2017-07-13 09:36:52 -040049 }
50}
51
Robert Phillipsa98183a2018-03-23 11:44:25 +000052@optimizationFlags {
Brian Salomon7a538b12019-11-21 22:03:09 -050053 ModulateForSamplerOptFlags(alphaType,
Michael Ludwig257a03d2018-12-13 14:07:07 -050054 samplerParams.wrapModeX() == GrSamplerState::WrapMode::kClampToBorder ||
55 samplerParams.wrapModeY() == GrSamplerState::WrapMode::kClampToBorder)
Ethan Nicholas68990be2017-07-13 09:36:52 -040056}
57
58void main() {
Ethan Nicholas13863662019-07-29 13:05:15 -040059 sk_OutColor = sk_InColor * sample(image, sk_TransformedCoords2D[0]);
Ethan Nicholas68990be2017-07-13 09:36:52 -040060}
61
62@test(testData) {
63 int texIdx = testData->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx
64 : GrProcessorUnitTest::kAlphaTextureIdx;
Brian Salomon2bbdcc42017-09-07 12:36:34 -040065 GrSamplerState::WrapMode wrapModes[2];
66 GrTest::TestWrapModes(testData->fRandom, wrapModes);
Robert Phillipsb350f1c2017-10-20 17:26:51 -040067 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 Salomon2bbdcc42017-09-07 12:36:34 -040074 GrSamplerState params(wrapModes, testData->fRandom->nextBool()
75 ? GrSamplerState::Filter::kBilerp
76 : GrSamplerState::Filter::kNearest);
Ethan Nicholas68990be2017-07-13 09:36:52 -040077
78 const SkMatrix& matrix = GrTest::TestMatrix(testData->fRandom);
Brian Salomon7a538b12019-11-21 22:03:09 -050079 auto alphaType = static_cast<SkAlphaType>(
80 testData->fRandom->nextULessThan(kLastEnum_SkAlphaType + 1));
Greg Danielc594e622019-10-15 14:01:49 -040081 return GrSimpleTextureEffect::Make(testData->textureProxy(texIdx),
Brian Salomon7a538b12019-11-21 22:03:09 -050082 alphaType, matrix, params);}