blob: de58bbfc620f93c2de57336fb7e1d93636932134 [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 Phillipsfbcef6e2017-06-15 12:07:18 -040023 static sk_sp<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy,
Robert Phillips8e1c4e62017-02-19 12:27:01 -050024 sk_sp<GrColorSpaceXform> colorSpaceXform,
Robert Phillipsdbc8eeb2017-02-21 10:04:31 -050025 sk_sp<GrTextureProxy> maskProxy,
Robert Phillips8e1c4e62017-02-19 12:27:01 -050026 float innerThreshold,
27 float outerThreshold,
28 const SkIRect& bounds) {
29 return sk_sp<GrFragmentProcessor>(new GrAlphaThresholdFragmentProcessor(
Robert Phillips8e1c4e62017-02-19 12:27:01 -050030 std::move(proxy),
31 std::move(colorSpaceXform),
Robert Phillipsdbc8eeb2017-02-21 10:04:31 -050032 std::move(maskProxy),
Robert Phillips8e1c4e62017-02-19 12:27:01 -050033 innerThreshold, outerThreshold,
34 bounds));
35 }
robertphillipsf7142e72016-04-18 07:20:05 -070036
37 const char* name() const override { return "Alpha Threshold"; }
38
39 float innerThreshold() const { return fInnerThreshold; }
40 float outerThreshold() const { return fOuterThreshold; }
41
Brian Osman6fb592e2016-10-03 13:15:12 -040042 GrColorSpaceXform* colorSpaceXform() const { return fColorSpaceXform.get(); }
43
robertphillipsf7142e72016-04-18 07:20:05 -070044private:
Brian Salomon587e08f2017-01-27 10:59:27 -050045 static OptimizationFlags OptFlags(float outerThreshold);
46
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040047 GrAlphaThresholdFragmentProcessor(sk_sp<GrTextureProxy> proxy,
Robert Phillips8e1c4e62017-02-19 12:27:01 -050048 sk_sp<GrColorSpaceXform> colorSpaceXform,
Robert Phillipsdbc8eeb2017-02-21 10:04:31 -050049 sk_sp<GrTextureProxy> maskProxy,
Robert Phillips8e1c4e62017-02-19 12:27:01 -050050 float innerThreshold,
51 float outerThreshold,
52 const SkIRect& bounds);
53
robertphillipsf7142e72016-04-18 07:20:05 -070054 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
55
Brian Salomon94efbf52016-11-29 13:43:05 -050056 void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
robertphillipsf7142e72016-04-18 07:20:05 -070057
58 bool onIsEqual(const GrFragmentProcessor&) const override;
59
robertphillipsf7142e72016-04-18 07:20:05 -070060 GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
61
62 float fInnerThreshold;
63 float fOuterThreshold;
64 GrCoordTransform fImageCoordTransform;
Brian Salomon0bbecb22016-11-17 11:38:22 -050065 TextureSampler fImageTextureSampler;
Brian Osman6fb592e2016-10-03 13:15:12 -040066 // Color space transform is for the image (not the mask)
67 sk_sp<GrColorSpaceXform> fColorSpaceXform;
robertphillipsf7142e72016-04-18 07:20:05 -070068 GrCoordTransform fMaskCoordTransform;
Brian Salomon0bbecb22016-11-17 11:38:22 -050069 TextureSampler fMaskTextureSampler;
robertphillipsf7142e72016-04-18 07:20:05 -070070
71 typedef GrFragmentProcessor INHERITED;
72};
73
74#endif
75#endif