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: |
tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame] | 24 | virtual ~GrSingleTextureEffect(); |
| 25 | |
bsalomon@google.com | 0ac6af4 | 2013-01-16 15:16:18 +0000 | [diff] [blame] | 26 | protected: |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 27 | /** unfiltered, clamp mode */ |
bsalomon@google.com | 77af680 | 2013-10-02 13:04:56 +0000 | [diff] [blame] | 28 | GrSingleTextureEffect(GrTexture*, const SkMatrix&, GrCoordSet = kLocal_GrCoordSet); |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 29 | /** clamp mode */ |
skia.committer@gmail.com | 956b310 | 2013-07-26 07:00:58 +0000 | [diff] [blame] | 30 | GrSingleTextureEffect(GrTexture*, const SkMatrix&, GrTextureParams::FilterMode filterMode, |
bsalomon@google.com | 77af680 | 2013-10-02 13:04:56 +0000 | [diff] [blame] | 31 | GrCoordSet = kLocal_GrCoordSet); |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 32 | GrSingleTextureEffect(GrTexture*, |
| 33 | const SkMatrix&, |
| 34 | const GrTextureParams&, |
bsalomon@google.com | 77af680 | 2013-10-02 13:04:56 +0000 | [diff] [blame] | 35 | GrCoordSet = kLocal_GrCoordSet); |
bsalomon@google.com | 0ac6af4 | 2013-01-16 15:16:18 +0000 | [diff] [blame] | 36 | |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 37 | /** |
egdaniel | 1a8ecdf | 2014-10-03 06:24:12 -0700 | [diff] [blame] | 38 | * 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] | 39 | * the subclass output color will be a modulation of the input color with a value read from the |
| 40 | * texture. |
| 41 | */ |
egdaniel | 605dd0f | 2014-11-12 08:35:25 -0800 | [diff] [blame] | 42 | void updateInvariantOutputForModulation(GrInvariantOutput* inout) const { |
egdaniel | f8449ba | 2014-11-25 10:24:56 -0800 | [diff] [blame] | 43 | if (GrPixelConfigIsAlphaOnly(this->texture(0)->config())) { |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 44 | inout->mulByUnknownSingleComponent(); |
egdaniel | f8449ba | 2014-11-25 10:24:56 -0800 | [diff] [blame] | 45 | } else if (GrPixelConfigIsOpaque(this->texture(0)->config())) { |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 46 | inout->mulByUnknownOpaqueFourComponents(); |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 47 | } else { |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 48 | inout->mulByUnknownFourComponents(); |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 49 | } |
| 50 | } |
| 51 | |
tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame] | 52 | private: |
bsalomon@google.com | 77af680 | 2013-10-02 13:04:56 +0000 | [diff] [blame] | 53 | GrCoordTransform fCoordTransform; |
| 54 | GrTextureAccess fTextureAccess; |
tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame] | 55 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 56 | typedef GrFragmentProcessor INHERITED; |
tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | #endif |