bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 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 | #ifndef GrSimpleTextureEffect_DEFINED |
| 9 | #define GrSimpleTextureEffect_DEFINED |
| 10 | |
| 11 | #include "GrSingleTextureEffect.h" |
Robert Phillips | 901f29a | 2017-01-24 16:24:41 -0500 | [diff] [blame] | 12 | #include "GrTextureProxy.h" |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 13 | |
egdaniel | 605dd0f | 2014-11-12 08:35:25 -0800 | [diff] [blame] | 14 | class GrInvariantOutput; |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 15 | |
| 16 | /** |
| 17 | * The output color of this effect is a modulation of the input color and a sample from a texture. |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 18 | * It allows explicit specification of the filtering and wrap modes (GrSamplerParams) and accepts |
Brian Salomon | 2ebd0c8 | 2016-10-03 17:15:28 -0400 | [diff] [blame] | 19 | * a matrix that is used to compute texture coordinates from local coordinates. |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 20 | */ |
| 21 | class GrSimpleTextureEffect : public GrSingleTextureEffect { |
| 22 | public: |
| 23 | /* unfiltered, clamp mode */ |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 24 | static sk_sp<GrFragmentProcessor> Make(GrTexture* tex, |
brianosman | 54f30c1 | 2016-07-18 10:53:52 -0700 | [diff] [blame] | 25 | sk_sp<GrColorSpaceXform> colorSpaceXform, |
Brian Salomon | 2ebd0c8 | 2016-10-03 17:15:28 -0400 | [diff] [blame] | 26 | const SkMatrix& matrix) { |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 27 | return sk_sp<GrFragmentProcessor>( |
brianosman | 54f30c1 | 2016-07-18 10:53:52 -0700 | [diff] [blame] | 28 | new GrSimpleTextureEffect(tex, std::move(colorSpaceXform), matrix, |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 29 | GrSamplerParams::kNone_FilterMode)); |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | /* clamp mode */ |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 33 | static sk_sp<GrFragmentProcessor> Make(GrTexture* tex, |
brianosman | 54f30c1 | 2016-07-18 10:53:52 -0700 | [diff] [blame] | 34 | sk_sp<GrColorSpaceXform> colorSpaceXform, |
Brian Salomon | 739c5bf | 2016-11-07 09:53:44 -0500 | [diff] [blame] | 35 | const SkMatrix& matrix, |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 36 | GrSamplerParams::FilterMode filterMode) { |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 37 | return sk_sp<GrFragmentProcessor>( |
Brian Salomon | 2ebd0c8 | 2016-10-03 17:15:28 -0400 | [diff] [blame] | 38 | new GrSimpleTextureEffect(tex, std::move(colorSpaceXform), matrix, filterMode)); |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 39 | } |
| 40 | |
Robert Phillips | 40fd7c9 | 2017-01-30 08:06:27 -0500 | [diff] [blame] | 41 | static sk_sp<GrFragmentProcessor> Make(GrTexture* tex, |
| 42 | sk_sp<GrColorSpaceXform> colorSpaceXform, |
| 43 | const SkMatrix& matrix, |
| 44 | const GrSamplerParams& p) { |
| 45 | return sk_sp<GrFragmentProcessor>(new GrSimpleTextureEffect(tex, std::move(colorSpaceXform), |
| 46 | matrix, p)); |
| 47 | } |
| 48 | |
| 49 | /* unfiltered, clamp mode */ |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame^] | 50 | static sk_sp<GrFragmentProcessor> Make(GrResourceProvider* resourceProvider, |
| 51 | sk_sp<GrTextureProxy> proxy, |
Robert Phillips | 40fd7c9 | 2017-01-30 08:06:27 -0500 | [diff] [blame] | 52 | sk_sp<GrColorSpaceXform> colorSpaceXform, |
| 53 | const SkMatrix& matrix) { |
| 54 | return sk_sp<GrFragmentProcessor>( |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame^] | 55 | new GrSimpleTextureEffect(resourceProvider, std::move(proxy), |
| 56 | std::move(colorSpaceXform), matrix, |
Robert Phillips | 40fd7c9 | 2017-01-30 08:06:27 -0500 | [diff] [blame] | 57 | GrSamplerParams::kNone_FilterMode)); |
| 58 | } |
| 59 | |
| 60 | /* clamp mode */ |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame^] | 61 | static sk_sp<GrFragmentProcessor> Make(GrResourceProvider* resourceProvider, |
| 62 | sk_sp<GrTextureProxy> proxy, |
Robert Phillips | 901f29a | 2017-01-24 16:24:41 -0500 | [diff] [blame] | 63 | sk_sp<GrColorSpaceXform> colorSpaceXform, |
| 64 | const SkMatrix& matrix, |
| 65 | GrSamplerParams::FilterMode filterMode) { |
| 66 | return sk_sp<GrFragmentProcessor>( |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame^] | 67 | new GrSimpleTextureEffect(resourceProvider, std::move(proxy), |
| 68 | std::move(colorSpaceXform), |
Robert Phillips | 901f29a | 2017-01-24 16:24:41 -0500 | [diff] [blame] | 69 | matrix, filterMode)); |
| 70 | } |
| 71 | |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame^] | 72 | static sk_sp<GrFragmentProcessor> Make(GrResourceProvider* resourceProvider, |
| 73 | sk_sp<GrTextureProxy> proxy, |
Robert Phillips | 901f29a | 2017-01-24 16:24:41 -0500 | [diff] [blame] | 74 | sk_sp<GrColorSpaceXform> colorSpaceXform, |
| 75 | const SkMatrix& matrix, |
| 76 | const GrSamplerParams& p) { |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame^] | 77 | return sk_sp<GrFragmentProcessor>(new GrSimpleTextureEffect(resourceProvider, |
| 78 | std::move(proxy), |
Robert Phillips | 901f29a | 2017-01-24 16:24:41 -0500 | [diff] [blame] | 79 | std::move(colorSpaceXform), |
| 80 | matrix, p)); |
| 81 | } |
| 82 | |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 83 | virtual ~GrSimpleTextureEffect() {} |
| 84 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 85 | const char* name() const override { return "SimpleTexture"; } |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 86 | |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 87 | private: |
bsalomon | 4a33952 | 2015-10-06 08:40:50 -0700 | [diff] [blame] | 88 | GrSimpleTextureEffect(GrTexture* texture, |
brianosman | 54f30c1 | 2016-07-18 10:53:52 -0700 | [diff] [blame] | 89 | sk_sp<GrColorSpaceXform> colorSpaceXform, |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 90 | const SkMatrix& matrix, |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 91 | GrSamplerParams::FilterMode filterMode) |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 92 | : INHERITED(texture, std::move(colorSpaceXform), matrix, filterMode, |
| 93 | ModulationFlags(texture->config())) { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 94 | this->initClassID<GrSimpleTextureEffect>(); |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 95 | } |
| 96 | |
bsalomon | 4a33952 | 2015-10-06 08:40:50 -0700 | [diff] [blame] | 97 | GrSimpleTextureEffect(GrTexture* texture, |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 98 | sk_sp<GrColorSpaceXform>colorSpaceXform, |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 99 | const SkMatrix& matrix, |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 100 | const GrSamplerParams& params) |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 101 | : INHERITED(texture, std::move(colorSpaceXform), matrix, params, |
| 102 | ModulationFlags(texture->config())) { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 103 | this->initClassID<GrSimpleTextureEffect>(); |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 104 | } |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 105 | |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame^] | 106 | GrSimpleTextureEffect(GrResourceProvider*, sk_sp<GrTextureProxy>, |
| 107 | sk_sp<GrColorSpaceXform>, const SkMatrix& matrix, |
| 108 | GrSamplerParams::FilterMode); |
Robert Phillips | 40fd7c9 | 2017-01-30 08:06:27 -0500 | [diff] [blame] | 109 | |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame^] | 110 | GrSimpleTextureEffect(GrResourceProvider*, sk_sp<GrTextureProxy>, |
| 111 | sk_sp<GrColorSpaceXform>, const SkMatrix& matrix, |
| 112 | const GrSamplerParams&); |
Robert Phillips | 901f29a | 2017-01-24 16:24:41 -0500 | [diff] [blame] | 113 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 114 | GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; |
wangyix | b1daa86 | 2015-08-18 11:29:31 -0700 | [diff] [blame] | 115 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 116 | void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; |
wangyix | 4b3050b | 2015-08-04 07:59:37 -0700 | [diff] [blame] | 117 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 118 | bool onIsEqual(const GrFragmentProcessor& other) const override { return true; } |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 119 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 120 | GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 121 | |
| 122 | typedef GrSingleTextureEffect INHERITED; |
| 123 | }; |
| 124 | |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 125 | #endif |