tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 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 GrSingleTextureEffect_DEFINED |
| 9 | #define GrSingleTextureEffect_DEFINED |
| 10 | |
bsalomon | 6251d17 | 2014-10-15 10:50:36 -0700 | [diff] [blame] | 11 | #include "GrFragmentProcessor.h" |
bsalomon@google.com | 77af680 | 2013-10-02 13:04:56 +0000 | [diff] [blame] | 12 | #include "GrCoordTransform.h" |
egdaniel | 605dd0f | 2014-11-12 08:35:25 -0800 | [diff] [blame] | 13 | #include "GrInvariantOutput.h" |
| 14 | #include "SkMatrix.h" |
tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame] | 15 | |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 16 | class GrTexture; |
tomhudson@google.com | aa72eab | 2012-07-19 18:01:07 +0000 | [diff] [blame] | 17 | |
| 18 | /** |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 19 | * A base class for effects that draw a single texture with a texture matrix. This effect has no |
| 20 | * backend implementations. One must be provided by the subclass. |
tomhudson@google.com | aa72eab | 2012-07-19 18:01:07 +0000 | [diff] [blame] | 21 | */ |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 22 | class GrSingleTextureEffect : public GrFragmentProcessor { |
tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame] | 23 | public: |
robertphillips | e004bfc | 2015-11-16 09:06:59 -0800 | [diff] [blame] | 24 | ~GrSingleTextureEffect() override; |
| 25 | |
| 26 | SkString dumpInfo() const override { |
| 27 | SkString str; |
| 28 | str.appendf("Texture: %d", fTextureAccess.getTexture()->getUniqueID()); |
| 29 | return str; |
| 30 | } |
tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame] | 31 | |
bsalomon@google.com | 0ac6af4 | 2013-01-16 15:16:18 +0000 | [diff] [blame] | 32 | protected: |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 33 | /** unfiltered, clamp mode */ |
bsalomon | 4a33952 | 2015-10-06 08:40:50 -0700 | [diff] [blame] | 34 | GrSingleTextureEffect(GrTexture*, const SkMatrix&, GrCoordSet = kLocal_GrCoordSet); |
joshualitt | 5f10b5c | 2015-07-09 10:24:35 -0700 | [diff] [blame] | 35 | /** clamp mode */ |
bsalomon | 4a33952 | 2015-10-06 08:40:50 -0700 | [diff] [blame] | 36 | GrSingleTextureEffect(GrTexture*, const SkMatrix&, GrTextureParams::FilterMode filterMode, |
joshualitt | 5f10b5c | 2015-07-09 10:24:35 -0700 | [diff] [blame] | 37 | GrCoordSet = kLocal_GrCoordSet); |
bsalomon | 4a33952 | 2015-10-06 08:40:50 -0700 | [diff] [blame] | 38 | GrSingleTextureEffect(GrTexture*, |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 39 | const SkMatrix&, |
| 40 | const GrTextureParams&, |
bsalomon@google.com | 77af680 | 2013-10-02 13:04:56 +0000 | [diff] [blame] | 41 | GrCoordSet = kLocal_GrCoordSet); |
bsalomon@google.com | 0ac6af4 | 2013-01-16 15:16:18 +0000 | [diff] [blame] | 42 | |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 43 | /** |
egdaniel | 1a8ecdf | 2014-10-03 06:24:12 -0700 | [diff] [blame] | 44 | * Can be used as a helper to implement subclass onComputeInvariantOutput(). It assumes that |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 45 | * the subclass output color will be a modulation of the input color with a value read from the |
| 46 | * texture. |
| 47 | */ |
egdaniel | 605dd0f | 2014-11-12 08:35:25 -0800 | [diff] [blame] | 48 | void updateInvariantOutputForModulation(GrInvariantOutput* inout) const { |
egdaniel | f8449ba | 2014-11-25 10:24:56 -0800 | [diff] [blame] | 49 | if (GrPixelConfigIsAlphaOnly(this->texture(0)->config())) { |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 50 | inout->mulByUnknownSingleComponent(); |
egdaniel | f8449ba | 2014-11-25 10:24:56 -0800 | [diff] [blame] | 51 | } else if (GrPixelConfigIsOpaque(this->texture(0)->config())) { |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 52 | inout->mulByUnknownOpaqueFourComponents(); |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 53 | } else { |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 54 | inout->mulByUnknownFourComponents(); |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 55 | } |
| 56 | } |
| 57 | |
tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame] | 58 | private: |
bsalomon@google.com | 77af680 | 2013-10-02 13:04:56 +0000 | [diff] [blame] | 59 | GrCoordTransform fCoordTransform; |
| 60 | GrTextureAccess fTextureAccess; |
tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame] | 61 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 62 | typedef GrFragmentProcessor INHERITED; |
tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | #endif |