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: |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame] | 23 | static sk_sp<GrFragmentProcessor> Make(GrResourceProvider* resourceProvider, |
Robert Phillips | 8e1c4e6 | 2017-02-19 12:27:01 -0500 | [diff] [blame] | 24 | sk_sp<GrTextureProxy> proxy, |
| 25 | sk_sp<GrColorSpaceXform> colorSpaceXform, |
Robert Phillips | dbc8eeb | 2017-02-21 10:04:31 -0500 | [diff] [blame] | 26 | sk_sp<GrTextureProxy> maskProxy, |
Robert Phillips | 8e1c4e6 | 2017-02-19 12:27:01 -0500 | [diff] [blame] | 27 | float innerThreshold, |
| 28 | float outerThreshold, |
| 29 | const SkIRect& bounds) { |
| 30 | return sk_sp<GrFragmentProcessor>(new GrAlphaThresholdFragmentProcessor( |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame] | 31 | resourceProvider, |
Robert Phillips | 8e1c4e6 | 2017-02-19 12:27:01 -0500 | [diff] [blame] | 32 | std::move(proxy), |
| 33 | std::move(colorSpaceXform), |
Robert Phillips | dbc8eeb | 2017-02-21 10:04:31 -0500 | [diff] [blame] | 34 | std::move(maskProxy), |
Robert Phillips | 8e1c4e6 | 2017-02-19 12:27:01 -0500 | [diff] [blame] | 35 | innerThreshold, outerThreshold, |
| 36 | bounds)); |
| 37 | } |
robertphillips | f7142e7 | 2016-04-18 07:20:05 -0700 | [diff] [blame] | 38 | |
| 39 | const char* name() const override { return "Alpha Threshold"; } |
| 40 | |
| 41 | float innerThreshold() const { return fInnerThreshold; } |
| 42 | float outerThreshold() const { return fOuterThreshold; } |
| 43 | |
Brian Osman | 6fb592e | 2016-10-03 13:15:12 -0400 | [diff] [blame] | 44 | GrColorSpaceXform* colorSpaceXform() const { return fColorSpaceXform.get(); } |
| 45 | |
robertphillips | f7142e7 | 2016-04-18 07:20:05 -0700 | [diff] [blame] | 46 | private: |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 47 | static OptimizationFlags OptFlags(float outerThreshold); |
| 48 | |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame] | 49 | GrAlphaThresholdFragmentProcessor(GrResourceProvider*, |
Robert Phillips | 8e1c4e6 | 2017-02-19 12:27:01 -0500 | [diff] [blame] | 50 | sk_sp<GrTextureProxy> proxy, |
| 51 | sk_sp<GrColorSpaceXform> colorSpaceXform, |
Robert Phillips | dbc8eeb | 2017-02-21 10:04:31 -0500 | [diff] [blame] | 52 | sk_sp<GrTextureProxy> maskProxy, |
Robert Phillips | 8e1c4e6 | 2017-02-19 12:27:01 -0500 | [diff] [blame] | 53 | float innerThreshold, |
| 54 | float outerThreshold, |
| 55 | const SkIRect& bounds); |
| 56 | |
robertphillips | f7142e7 | 2016-04-18 07:20:05 -0700 | [diff] [blame] | 57 | GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; |
| 58 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 59 | void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; |
robertphillips | f7142e7 | 2016-04-18 07:20:05 -0700 | [diff] [blame] | 60 | |
| 61 | bool onIsEqual(const GrFragmentProcessor&) const override; |
| 62 | |
robertphillips | f7142e7 | 2016-04-18 07:20:05 -0700 | [diff] [blame] | 63 | GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
| 64 | |
| 65 | float fInnerThreshold; |
| 66 | float fOuterThreshold; |
| 67 | GrCoordTransform fImageCoordTransform; |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 68 | TextureSampler fImageTextureSampler; |
Brian Osman | 6fb592e | 2016-10-03 13:15:12 -0400 | [diff] [blame] | 69 | // Color space transform is for the image (not the mask) |
| 70 | sk_sp<GrColorSpaceXform> fColorSpaceXform; |
robertphillips | f7142e7 | 2016-04-18 07:20:05 -0700 | [diff] [blame] | 71 | GrCoordTransform fMaskCoordTransform; |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 72 | TextureSampler fMaskTextureSampler; |
robertphillips | f7142e7 | 2016-04-18 07:20:05 -0700 | [diff] [blame] | 73 | |
| 74 | typedef GrFragmentProcessor INHERITED; |
| 75 | }; |
| 76 | |
| 77 | #endif |
| 78 | #endif |