• 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 "src/gpu/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 std::unique_ptr<GrFragmentProcessor> Make(Mode mode, Alpha alpha) {
29         return std::unique_ptr<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     std::unique_ptr<GrFragmentProcessor> clone() const override;
38 
39 private:
40     GrSRGBEffect(Mode mode, Alpha);
41 
42     GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
43     void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
44     bool onIsEqual(const GrFragmentProcessor&) const override;
45 
46     SkPMColor4f constantOutputForConstantInput(const SkPMColor4f& input) const override;
47 
48     Mode fMode;
49     Alpha fAlpha;
50 
51     GR_DECLARE_FRAGMENT_PROCESSOR_TEST
52 
53     typedef GrFragmentProcessor INHERITED;
54 };
55 
56 #endif
57