• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 GrSRGBEffect_DEFINED
9 #define GrSRGBEffect_DEFINED
10 
11 #include "GrFragmentProcessor.h"
12 
13 class GrSRGBEffect : public GrFragmentProcessor {
14 public:
15     enum class Mode {
16         kLinearToSRGB,
17         kSRGBToLinear,
18     };
19 
20     enum class Alpha {
21         kPremul,
22         kOpaque,
23     };
24 
25     /**
26      * Creates an effect that applies the sRGB transfer function (or its inverse)
27      */
Make(Mode mode,Alpha alpha)28     static sk_sp<GrFragmentProcessor> Make(Mode mode, Alpha alpha) {
29         return sk_sp<GrFragmentProcessor>(new GrSRGBEffect(mode, alpha));
30     }
31 
name()32     const char* name() const override { return "sRGB"; }
33 
mode()34     Mode mode() const { return fMode; }
alpha()35     Alpha alpha() const { return fAlpha; }
36 
37 private:
38     GrSRGBEffect(Mode mode, Alpha);
39 
40     GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
41     void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
42     bool onIsEqual(const GrFragmentProcessor&) const override;
43 
44     GrColor4f constantOutputForConstantInput(GrColor4f input) const override;
45 
46     Mode fMode;
47     Alpha fAlpha;
48 
49     GR_DECLARE_FRAGMENT_PROCESSOR_TEST
50 
51     typedef GrFragmentProcessor INHERITED;
52 };
53 
54 #endif
55