blob: fa7a760e23d4ae86a9577a8bd6ed5eda5657b326 [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,
Robert Phillips8e1c4e62017-02-19 12:27:01 -050028 const SkIRect& bounds) {
29 return sk_sp<GrFragmentProcessor>(new GrAlphaThresholdFragmentProcessor(
30 texture,
31 std::move(colorSpaceXform),
32 maskTexture,
33 innerThreshold, outerThreshold,
34 bounds));
35 }
36
37 static sk_sp<GrFragmentProcessor> Make(GrContext* context,
38 sk_sp<GrTextureProxy> proxy,
39 sk_sp<GrColorSpaceXform> colorSpaceXform,
Robert Phillipsdbc8eeb2017-02-21 10:04:31 -050040 sk_sp<GrTextureProxy> maskProxy,
Robert Phillips8e1c4e62017-02-19 12:27:01 -050041 float innerThreshold,
42 float outerThreshold,
43 const SkIRect& bounds) {
44 return sk_sp<GrFragmentProcessor>(new GrAlphaThresholdFragmentProcessor(
45 context,
46 std::move(proxy),
47 std::move(colorSpaceXform),
Robert Phillipsdbc8eeb2017-02-21 10:04:31 -050048 std::move(maskProxy),
Robert Phillips8e1c4e62017-02-19 12:27:01 -050049 innerThreshold, outerThreshold,
50 bounds));
51 }
robertphillipsf7142e72016-04-18 07:20:05 -070052
53 const char* name() const override { return "Alpha Threshold"; }
54
55 float innerThreshold() const { return fInnerThreshold; }
56 float outerThreshold() const { return fOuterThreshold; }
57
Brian Osman6fb592e2016-10-03 13:15:12 -040058 GrColorSpaceXform* colorSpaceXform() const { return fColorSpaceXform.get(); }
59
robertphillipsf7142e72016-04-18 07:20:05 -070060private:
Brian Salomon587e08f2017-01-27 10:59:27 -050061 static OptimizationFlags OptFlags(float outerThreshold);
62
robertphillipsf7142e72016-04-18 07:20:05 -070063 GrAlphaThresholdFragmentProcessor(GrTexture* texture,
Brian Osman6fb592e2016-10-03 13:15:12 -040064 sk_sp<GrColorSpaceXform> colorSpaceXform,
robertphillipsf7142e72016-04-18 07:20:05 -070065 GrTexture* maskTexture,
66 float innerThreshold,
67 float outerThreshold,
68 const SkIRect& bounds);
69
Robert Phillips8e1c4e62017-02-19 12:27:01 -050070 GrAlphaThresholdFragmentProcessor(GrContext*,
71 sk_sp<GrTextureProxy> proxy,
72 sk_sp<GrColorSpaceXform> colorSpaceXform,
Robert Phillipsdbc8eeb2017-02-21 10:04:31 -050073 sk_sp<GrTextureProxy> maskProxy,
Robert Phillips8e1c4e62017-02-19 12:27:01 -050074 float innerThreshold,
75 float outerThreshold,
76 const SkIRect& bounds);
77
robertphillipsf7142e72016-04-18 07:20:05 -070078 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
79
Brian Salomon94efbf52016-11-29 13:43:05 -050080 void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
robertphillipsf7142e72016-04-18 07:20:05 -070081
82 bool onIsEqual(const GrFragmentProcessor&) const override;
83
robertphillipsf7142e72016-04-18 07:20:05 -070084 GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
85
86 float fInnerThreshold;
87 float fOuterThreshold;
88 GrCoordTransform fImageCoordTransform;
Brian Salomon0bbecb22016-11-17 11:38:22 -050089 TextureSampler fImageTextureSampler;
Brian Osman6fb592e2016-10-03 13:15:12 -040090 // Color space transform is for the image (not the mask)
91 sk_sp<GrColorSpaceXform> fColorSpaceXform;
robertphillipsf7142e72016-04-18 07:20:05 -070092 GrCoordTransform fMaskCoordTransform;
Brian Salomon0bbecb22016-11-17 11:38:22 -050093 TextureSampler fMaskTextureSampler;
robertphillipsf7142e72016-04-18 07:20:05 -070094
95 typedef GrFragmentProcessor INHERITED;
96};
97
98#endif
99#endif