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 */ |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame] | 24 | static sk_sp<GrFragmentProcessor> Make(GrResourceProvider* resourceProvider, |
| 25 | sk_sp<GrTextureProxy> proxy, |
Robert Phillips | 40fd7c9 | 2017-01-30 08:06:27 -0500 | [diff] [blame] | 26 | sk_sp<GrColorSpaceXform> colorSpaceXform, |
| 27 | const SkMatrix& matrix) { |
Robert Phillips | dd3b3f4 | 2017-04-24 10:57:28 -0400 | [diff] [blame] | 28 | // MDB TODO: remove this instantiation once instantiation is pushed past the |
| 29 | // TextureSamplers. Instantiation failure in the TextureSampler is difficult to |
| 30 | // recover from. |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 31 | if (!proxy->instantiate(resourceProvider)) { |
Robert Phillips | dd3b3f4 | 2017-04-24 10:57:28 -0400 | [diff] [blame] | 32 | return nullptr; |
| 33 | } |
| 34 | |
Robert Phillips | 40fd7c9 | 2017-01-30 08:06:27 -0500 | [diff] [blame] | 35 | return sk_sp<GrFragmentProcessor>( |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame] | 36 | new GrSimpleTextureEffect(resourceProvider, std::move(proxy), |
| 37 | std::move(colorSpaceXform), matrix, |
Robert Phillips | 40fd7c9 | 2017-01-30 08:06:27 -0500 | [diff] [blame] | 38 | GrSamplerParams::kNone_FilterMode)); |
| 39 | } |
| 40 | |
| 41 | /* clamp mode */ |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame] | 42 | static sk_sp<GrFragmentProcessor> Make(GrResourceProvider* resourceProvider, |
| 43 | sk_sp<GrTextureProxy> proxy, |
Robert Phillips | 901f29a | 2017-01-24 16:24:41 -0500 | [diff] [blame] | 44 | sk_sp<GrColorSpaceXform> colorSpaceXform, |
| 45 | const SkMatrix& matrix, |
| 46 | GrSamplerParams::FilterMode filterMode) { |
Robert Phillips | dd3b3f4 | 2017-04-24 10:57:28 -0400 | [diff] [blame] | 47 | // MDB TODO: remove this instantiation once instantiation is pushed past the |
| 48 | // TextureSamplers. Instantiation failure in the TextureSampler is difficult to |
| 49 | // recover from. |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 50 | if (!proxy->instantiate(resourceProvider)) { |
Robert Phillips | dd3b3f4 | 2017-04-24 10:57:28 -0400 | [diff] [blame] | 51 | return nullptr; |
| 52 | } |
| 53 | |
Robert Phillips | 901f29a | 2017-01-24 16:24:41 -0500 | [diff] [blame] | 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), |
Robert Phillips | 901f29a | 2017-01-24 16:24:41 -0500 | [diff] [blame] | 57 | matrix, filterMode)); |
| 58 | } |
| 59 | |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame] | 60 | static sk_sp<GrFragmentProcessor> Make(GrResourceProvider* resourceProvider, |
| 61 | sk_sp<GrTextureProxy> proxy, |
Robert Phillips | 901f29a | 2017-01-24 16:24:41 -0500 | [diff] [blame] | 62 | sk_sp<GrColorSpaceXform> colorSpaceXform, |
| 63 | const SkMatrix& matrix, |
| 64 | const GrSamplerParams& p) { |
Robert Phillips | dd3b3f4 | 2017-04-24 10:57:28 -0400 | [diff] [blame] | 65 | // MDB TODO: remove this instantiation once instantiation is pushed past the |
| 66 | // TextureSamplers. Instantiation failure in the TextureSampler is difficult to |
| 67 | // recover from. |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 68 | if (!proxy->instantiate(resourceProvider)) { |
Robert Phillips | dd3b3f4 | 2017-04-24 10:57:28 -0400 | [diff] [blame] | 69 | return nullptr; |
| 70 | } |
| 71 | |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame] | 72 | return sk_sp<GrFragmentProcessor>(new GrSimpleTextureEffect(resourceProvider, |
| 73 | std::move(proxy), |
Robert Phillips | 901f29a | 2017-01-24 16:24:41 -0500 | [diff] [blame] | 74 | std::move(colorSpaceXform), |
| 75 | matrix, p)); |
| 76 | } |
| 77 | |
Brian Salomon | d3b6597 | 2017-03-22 12:05:03 -0400 | [diff] [blame] | 78 | ~GrSimpleTextureEffect() override {} |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 79 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 80 | const char* name() const override { return "SimpleTexture"; } |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 81 | |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 82 | private: |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame] | 83 | GrSimpleTextureEffect(GrResourceProvider*, sk_sp<GrTextureProxy>, |
| 84 | sk_sp<GrColorSpaceXform>, const SkMatrix& matrix, |
| 85 | GrSamplerParams::FilterMode); |
Robert Phillips | 40fd7c9 | 2017-01-30 08:06:27 -0500 | [diff] [blame] | 86 | |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame] | 87 | GrSimpleTextureEffect(GrResourceProvider*, sk_sp<GrTextureProxy>, |
| 88 | sk_sp<GrColorSpaceXform>, const SkMatrix& matrix, |
| 89 | const GrSamplerParams&); |
Robert Phillips | 901f29a | 2017-01-24 16:24:41 -0500 | [diff] [blame] | 90 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 91 | GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; |
wangyix | b1daa86 | 2015-08-18 11:29:31 -0700 | [diff] [blame] | 92 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 93 | void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; |
wangyix | 4b3050b | 2015-08-04 07:59:37 -0700 | [diff] [blame] | 94 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 95 | bool onIsEqual(const GrFragmentProcessor& other) const override { return true; } |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 96 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 97 | GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 98 | |
| 99 | typedef GrSingleTextureEffect INHERITED; |
| 100 | }; |
| 101 | |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 102 | #endif |