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 
15 #include "GrColorSpaceXform.h"
16 #include "GrCoordTransform.h"
17 #include "GrFragmentProcessor.h"
18 #include "GrProcessorUnitTest.h"
19 
20 class GrAlphaThresholdFragmentProcessor : public GrFragmentProcessor {
21 
22 public:
Make(GrResourceProvider * resourceProvider,sk_sp<GrTextureProxy> proxy,sk_sp<GrColorSpaceXform> colorSpaceXform,sk_sp<GrTextureProxy> maskProxy,float innerThreshold,float outerThreshold,const SkIRect & bounds)23     static sk_sp<GrFragmentProcessor> Make(GrResourceProvider* resourceProvider,
24                                            sk_sp<GrTextureProxy> proxy,
25                                            sk_sp<GrColorSpaceXform> colorSpaceXform,
26                                            sk_sp<GrTextureProxy> maskProxy,
27                                            float innerThreshold,
28                                            float outerThreshold,
29                                            const SkIRect& bounds) {
30         return sk_sp<GrFragmentProcessor>(new GrAlphaThresholdFragmentProcessor(
31                                                                     resourceProvider,
32                                                                     std::move(proxy),
33                                                                     std::move(colorSpaceXform),
34                                                                     std::move(maskProxy),
35                                                                     innerThreshold, outerThreshold,
36                                                                     bounds));
37     }
38 
name()39     const char* name() const override { return "Alpha Threshold"; }
40 
innerThreshold()41     float innerThreshold() const { return fInnerThreshold; }
outerThreshold()42     float outerThreshold() const { return fOuterThreshold; }
43 
colorSpaceXform()44     GrColorSpaceXform* colorSpaceXform() const { return fColorSpaceXform.get(); }
45 
46 private:
47     static OptimizationFlags OptFlags(float outerThreshold);
48 
49     GrAlphaThresholdFragmentProcessor(GrResourceProvider*,
50                                       sk_sp<GrTextureProxy> proxy,
51                                       sk_sp<GrColorSpaceXform> colorSpaceXform,
52                                       sk_sp<GrTextureProxy> maskProxy,
53                                       float innerThreshold,
54                                       float outerThreshold,
55                                       const SkIRect& bounds);
56 
57     GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
58 
59     void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
60 
61     bool onIsEqual(const GrFragmentProcessor&) const override;
62 
63     GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
64 
65     float fInnerThreshold;
66     float fOuterThreshold;
67     GrCoordTransform fImageCoordTransform;
68     TextureSampler   fImageTextureSampler;
69     // Color space transform is for the image (not the mask)
70     sk_sp<GrColorSpaceXform> fColorSpaceXform;
71     GrCoordTransform fMaskCoordTransform;
72     TextureSampler   fMaskTextureSampler;
73 
74     typedef GrFragmentProcessor INHERITED;
75 };
76 
77 #endif
78 #endif
79