blob: f7a2491aee584eb5650534f6d592c698c94dd047 [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:
38 GrAlphaThresholdFragmentProcessor(GrTexture* texture,
Brian Osman6fb592e2016-10-03 13:15:12 -040039 sk_sp<GrColorSpaceXform> colorSpaceXform,
robertphillipsf7142e72016-04-18 07:20:05 -070040 GrTexture* maskTexture,
41 float innerThreshold,
42 float outerThreshold,
43 const SkIRect& bounds);
44
45 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
46
Brian Salomon94efbf52016-11-29 13:43:05 -050047 void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
robertphillipsf7142e72016-04-18 07:20:05 -070048
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 Salomon0bbecb22016-11-17 11:38:22 -050058 TextureSampler fImageTextureSampler;
Brian Osman6fb592e2016-10-03 13:15:12 -040059 // Color space transform is for the image (not the mask)
60 sk_sp<GrColorSpaceXform> fColorSpaceXform;
robertphillipsf7142e72016-04-18 07:20:05 -070061 GrCoordTransform fMaskCoordTransform;
Brian Salomon0bbecb22016-11-17 11:38:22 -050062 TextureSampler fMaskTextureSampler;
robertphillipsf7142e72016-04-18 07:20:05 -070063
64 typedef GrFragmentProcessor INHERITED;
65};
66
67#endif
68#endif