blob: f2c14c64bc2268a40bc78b4d742abf3bccece77a [file] [log] [blame]
robertphillipsf7142e72016-04-18 07:20:05 -07001/*
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 Osman6fb592e2016-10-03 13:15:12 -040015#include "GrColorSpaceXform.h"
robertphillipsf7142e72016-04-18 07:20:05 -070016#include "GrCoordTransform.h"
17#include "GrFragmentProcessor.h"
18#include "GrProcessorUnitTest.h"
19
20class GrAlphaThresholdFragmentProcessor : public GrFragmentProcessor {
21
22public:
23 static sk_sp<GrFragmentProcessor> Make(GrTexture* texture,
Brian Osman6fb592e2016-10-03 13:15:12 -040024 sk_sp<GrColorSpaceXform> colorSpaceXform,
robertphillipsf7142e72016-04-18 07:20:05 -070025 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 Osman6fb592e2016-10-03 13:15:12 -040035 GrColorSpaceXform* colorSpaceXform() const { return fColorSpaceXform.get(); }
36
robertphillipsf7142e72016-04-18 07:20:05 -070037private:
Brian Salomon587e08f2017-01-27 10:59:27 -050038 static OptimizationFlags OptFlags(float outerThreshold);
39
robertphillipsf7142e72016-04-18 07:20:05 -070040 GrAlphaThresholdFragmentProcessor(GrTexture* texture,
Brian Osman6fb592e2016-10-03 13:15:12 -040041 sk_sp<GrColorSpaceXform> colorSpaceXform,
robertphillipsf7142e72016-04-18 07:20:05 -070042 GrTexture* maskTexture,
43 float innerThreshold,
44 float outerThreshold,
45 const SkIRect& bounds);
46
47 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
48
Brian Salomon94efbf52016-11-29 13:43:05 -050049 void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
robertphillipsf7142e72016-04-18 07:20:05 -070050
51 bool onIsEqual(const GrFragmentProcessor&) const override;
52
53 void onComputeInvariantOutput(GrInvariantOutput* inout) const override;
54
55 GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
56
57 float fInnerThreshold;
58 float fOuterThreshold;
59 GrCoordTransform fImageCoordTransform;
Brian Salomon0bbecb22016-11-17 11:38:22 -050060 TextureSampler fImageTextureSampler;
Brian Osman6fb592e2016-10-03 13:15:12 -040061 // Color space transform is for the image (not the mask)
62 sk_sp<GrColorSpaceXform> fColorSpaceXform;
robertphillipsf7142e72016-04-18 07:20:05 -070063 GrCoordTransform fMaskCoordTransform;
Brian Salomon0bbecb22016-11-17 11:38:22 -050064 TextureSampler fMaskTextureSampler;
robertphillipsf7142e72016-04-18 07:20:05 -070065
66 typedef GrFragmentProcessor INHERITED;
67};
68
69#endif
70#endif