aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/effects/GrAlphaThresholdFragmentProcessor.h
blob: f2c14c64bc2268a40bc78b4d742abf3bccece77a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
 * Copyright 2016 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef GrAlphaThresholdFragmentProcessor_DEFINED
#define GrAlphaThresholdFragmentProcessor_DEFINED

#include "SkTypes.h"

#if SK_SUPPORT_GPU

#include "GrColorSpaceXform.h"
#include "GrCoordTransform.h"
#include "GrFragmentProcessor.h"
#include "GrProcessorUnitTest.h"

class GrAlphaThresholdFragmentProcessor : public GrFragmentProcessor {

public:
    static sk_sp<GrFragmentProcessor> Make(GrTexture* texture,
                                           sk_sp<GrColorSpaceXform> colorSpaceXform,
                                           GrTexture* maskTexture,
                                           float innerThreshold,
                                           float outerThreshold,
                                           const SkIRect& bounds);

    const char* name() const override { return "Alpha Threshold"; }

    float innerThreshold() const { return fInnerThreshold; }
    float outerThreshold() const { return fOuterThreshold; }

    GrColorSpaceXform* colorSpaceXform() const { return fColorSpaceXform.get(); }

private:
    static OptimizationFlags OptFlags(float outerThreshold);

    GrAlphaThresholdFragmentProcessor(GrTexture* texture,
                                      sk_sp<GrColorSpaceXform> colorSpaceXform,
                                      GrTexture* maskTexture,
                                      float innerThreshold,
                                      float outerThreshold,
                                      const SkIRect& bounds);

    GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;

    void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;

    bool onIsEqual(const GrFragmentProcessor&) const override;

    void onComputeInvariantOutput(GrInvariantOutput* inout) const override;

    GR_DECLARE_FRAGMENT_PROCESSOR_TEST;

    float fInnerThreshold;
    float fOuterThreshold;
    GrCoordTransform fImageCoordTransform;
    TextureSampler   fImageTextureSampler;
    // Color space transform is for the image (not the mask)
    sk_sp<GrColorSpaceXform> fColorSpaceXform;
    GrCoordTransform fMaskCoordTransform;
    TextureSampler   fMaskTextureSampler;

    typedef GrFragmentProcessor INHERITED;
};

#endif
#endif