robertphillips | f7142e7 | 2016-04-18 07:20:05 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 GrAlphaThresholdFragmentProcessor_DEFINED |
| 9 | #define GrAlphaThresholdFragmentProcessor_DEFINED |
| 10 | |
| 11 | #include "SkTypes.h" |
| 12 | |
| 13 | #if SK_SUPPORT_GPU |
| 14 | |
Brian Osman | 6fb592e | 2016-10-03 13:15:12 -0400 | [diff] [blame] | 15 | #include "GrColorSpaceXform.h" |
robertphillips | f7142e7 | 2016-04-18 07:20:05 -0700 | [diff] [blame] | 16 | #include "GrCoordTransform.h" |
| 17 | #include "GrFragmentProcessor.h" |
| 18 | #include "GrProcessorUnitTest.h" |
| 19 | |
| 20 | class GrAlphaThresholdFragmentProcessor : public GrFragmentProcessor { |
| 21 | |
| 22 | public: |
| 23 | static sk_sp<GrFragmentProcessor> Make(GrTexture* texture, |
Brian Osman | 6fb592e | 2016-10-03 13:15:12 -0400 | [diff] [blame] | 24 | sk_sp<GrColorSpaceXform> colorSpaceXform, |
robertphillips | f7142e7 | 2016-04-18 07:20:05 -0700 | [diff] [blame] | 25 | GrTexture* maskTexture, |
| 26 | float innerThreshold, |
| 27 | float outerThreshold, |
| 28 | const SkIRect& bounds); |
| 29 | |
| 30 | const char* name() const override { return "Alpha Threshold"; } |
| 31 | |
| 32 | float innerThreshold() const { return fInnerThreshold; } |
| 33 | float outerThreshold() const { return fOuterThreshold; } |
| 34 | |
Brian Osman | 6fb592e | 2016-10-03 13:15:12 -0400 | [diff] [blame] | 35 | GrColorSpaceXform* colorSpaceXform() const { return fColorSpaceXform.get(); } |
| 36 | |
robertphillips | f7142e7 | 2016-04-18 07:20:05 -0700 | [diff] [blame] | 37 | private: |
| 38 | GrAlphaThresholdFragmentProcessor(GrTexture* texture, |
Brian Osman | 6fb592e | 2016-10-03 13:15:12 -0400 | [diff] [blame] | 39 | sk_sp<GrColorSpaceXform> colorSpaceXform, |
robertphillips | f7142e7 | 2016-04-18 07:20:05 -0700 | [diff] [blame] | 40 | GrTexture* maskTexture, |
| 41 | float innerThreshold, |
| 42 | float outerThreshold, |
| 43 | const SkIRect& bounds); |
| 44 | |
| 45 | GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; |
| 46 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame^] | 47 | void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; |
robertphillips | f7142e7 | 2016-04-18 07:20:05 -0700 | [diff] [blame] | 48 | |
| 49 | bool onIsEqual(const GrFragmentProcessor&) const override; |
| 50 | |
| 51 | void onComputeInvariantOutput(GrInvariantOutput* inout) const override; |
| 52 | |
| 53 | GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
| 54 | |
| 55 | float fInnerThreshold; |
| 56 | float fOuterThreshold; |
| 57 | GrCoordTransform fImageCoordTransform; |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 58 | TextureSampler fImageTextureSampler; |
Brian Osman | 6fb592e | 2016-10-03 13:15:12 -0400 | [diff] [blame] | 59 | // Color space transform is for the image (not the mask) |
| 60 | sk_sp<GrColorSpaceXform> fColorSpaceXform; |
robertphillips | f7142e7 | 2016-04-18 07:20:05 -0700 | [diff] [blame] | 61 | GrCoordTransform fMaskCoordTransform; |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 62 | TextureSampler fMaskTextureSampler; |
robertphillips | f7142e7 | 2016-04-18 07:20:05 -0700 | [diff] [blame] | 63 | |
| 64 | typedef GrFragmentProcessor INHERITED; |
| 65 | }; |
| 66 | |
| 67 | #endif |
| 68 | #endif |