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