blob: f7690d3b9791c26b7b8b7a239f7f40580d955d02 [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:
Robert Phillips296b1cc2017-03-15 10:42:12 -040023 static sk_sp<GrFragmentProcessor> Make(GrResourceProvider* resourceProvider,
Robert Phillips8e1c4e62017-02-19 12:27:01 -050024 sk_sp<GrTextureProxy> proxy,
25 sk_sp<GrColorSpaceXform> colorSpaceXform,
Robert Phillipsdbc8eeb2017-02-21 10:04:31 -050026 sk_sp<GrTextureProxy> maskProxy,
Robert Phillips8e1c4e62017-02-19 12:27:01 -050027 float innerThreshold,
28 float outerThreshold,
29 const SkIRect& bounds) {
30 return sk_sp<GrFragmentProcessor>(new GrAlphaThresholdFragmentProcessor(
Robert Phillips296b1cc2017-03-15 10:42:12 -040031 resourceProvider,
Robert Phillips8e1c4e62017-02-19 12:27:01 -050032 std::move(proxy),
33 std::move(colorSpaceXform),
Robert Phillipsdbc8eeb2017-02-21 10:04:31 -050034 std::move(maskProxy),
Robert Phillips8e1c4e62017-02-19 12:27:01 -050035 innerThreshold, outerThreshold,
36 bounds));
37 }
robertphillipsf7142e72016-04-18 07:20:05 -070038
39 const char* name() const override { return "Alpha Threshold"; }
40
41 float innerThreshold() const { return fInnerThreshold; }
42 float outerThreshold() const { return fOuterThreshold; }
43
Brian Osman6fb592e2016-10-03 13:15:12 -040044 GrColorSpaceXform* colorSpaceXform() const { return fColorSpaceXform.get(); }
45
robertphillipsf7142e72016-04-18 07:20:05 -070046private:
Brian Salomon587e08f2017-01-27 10:59:27 -050047 static OptimizationFlags OptFlags(float outerThreshold);
48
Robert Phillips296b1cc2017-03-15 10:42:12 -040049 GrAlphaThresholdFragmentProcessor(GrResourceProvider*,
Robert Phillips8e1c4e62017-02-19 12:27:01 -050050 sk_sp<GrTextureProxy> proxy,
51 sk_sp<GrColorSpaceXform> colorSpaceXform,
Robert Phillipsdbc8eeb2017-02-21 10:04:31 -050052 sk_sp<GrTextureProxy> maskProxy,
Robert Phillips8e1c4e62017-02-19 12:27:01 -050053 float innerThreshold,
54 float outerThreshold,
55 const SkIRect& bounds);
56
robertphillipsf7142e72016-04-18 07:20:05 -070057 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
58
Brian Salomon94efbf52016-11-29 13:43:05 -050059 void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
robertphillipsf7142e72016-04-18 07:20:05 -070060
61 bool onIsEqual(const GrFragmentProcessor&) const override;
62
robertphillipsf7142e72016-04-18 07:20:05 -070063 GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
64
65 float fInnerThreshold;
66 float fOuterThreshold;
67 GrCoordTransform fImageCoordTransform;
Brian Salomon0bbecb22016-11-17 11:38:22 -050068 TextureSampler fImageTextureSampler;
Brian Osman6fb592e2016-10-03 13:15:12 -040069 // Color space transform is for the image (not the mask)
70 sk_sp<GrColorSpaceXform> fColorSpaceXform;
robertphillipsf7142e72016-04-18 07:20:05 -070071 GrCoordTransform fMaskCoordTransform;
Brian Salomon0bbecb22016-11-17 11:38:22 -050072 TextureSampler fMaskTextureSampler;
robertphillipsf7142e72016-04-18 07:20:05 -070073
74 typedef GrFragmentProcessor INHERITED;
75};
76
77#endif
78#endif