brianosman | 2d1ee79 | 2016-05-05 12:24:31 -0700 | [diff] [blame] | 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 | |
Brian Osman | 964dec3 | 2017-01-26 09:32:33 -0500 | [diff] [blame] | 8 | #ifndef GrSRGBEffect_DEFINED |
| 9 | #define GrSRGBEffect_DEFINED |
brianosman | 2d1ee79 | 2016-05-05 12:24:31 -0700 | [diff] [blame] | 10 | |
brianosman | fe4d5d3 | 2016-05-11 06:49:32 -0700 | [diff] [blame] | 11 | #include "GrFragmentProcessor.h" |
brianosman | 2d1ee79 | 2016-05-05 12:24:31 -0700 | [diff] [blame] | 12 | |
Brian Osman | 964dec3 | 2017-01-26 09:32:33 -0500 | [diff] [blame] | 13 | class GrSRGBEffect : public GrFragmentProcessor { |
brianosman | 2d1ee79 | 2016-05-05 12:24:31 -0700 | [diff] [blame] | 14 | public: |
brianosman | fe4d5d3 | 2016-05-11 06:49:32 -0700 | [diff] [blame] | 15 | enum class Mode { |
| 16 | kLinearToSRGB, |
| 17 | kSRGBToLinear, |
brianosman | fe4d5d3 | 2016-05-11 06:49:32 -0700 | [diff] [blame] | 18 | }; |
| 19 | |
brianosman | 2d1ee79 | 2016-05-05 12:24:31 -0700 | [diff] [blame] | 20 | /** |
Brian Osman | 964dec3 | 2017-01-26 09:32:33 -0500 | [diff] [blame] | 21 | * Creates an effect that applies the sRGB transfer function (or its inverse) |
| 22 | */ |
| 23 | static sk_sp<GrFragmentProcessor> Make(Mode mode); |
brianosman | 2d1ee79 | 2016-05-05 12:24:31 -0700 | [diff] [blame] | 24 | |
Brian Osman | 964dec3 | 2017-01-26 09:32:33 -0500 | [diff] [blame] | 25 | const char* name() const override { return "sRGB"; } |
brianosman | 2d1ee79 | 2016-05-05 12:24:31 -0700 | [diff] [blame] | 26 | |
brianosman | fe4d5d3 | 2016-05-11 06:49:32 -0700 | [diff] [blame] | 27 | Mode mode() const { return fMode; } |
brianosman | 2d1ee79 | 2016-05-05 12:24:31 -0700 | [diff] [blame] | 28 | |
| 29 | private: |
Brian Osman | 964dec3 | 2017-01-26 09:32:33 -0500 | [diff] [blame] | 30 | GrSRGBEffect(Mode mode); |
brianosman | 2d1ee79 | 2016-05-05 12:24:31 -0700 | [diff] [blame] | 31 | |
| 32 | GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 33 | void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; |
brianosman | 2d1ee79 | 2016-05-05 12:24:31 -0700 | [diff] [blame] | 34 | bool onIsEqual(const GrFragmentProcessor&) const override; |
Brian Salomon | cb30bb2 | 2017-02-12 09:28:54 -0500 | [diff] [blame] | 35 | |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 36 | GrColor4f constantOutputForConstantInput(GrColor4f input) const override; |
brianosman | 2d1ee79 | 2016-05-05 12:24:31 -0700 | [diff] [blame] | 37 | |
brianosman | fe4d5d3 | 2016-05-11 06:49:32 -0700 | [diff] [blame] | 38 | Mode fMode; |
brianosman | 2d1ee79 | 2016-05-05 12:24:31 -0700 | [diff] [blame] | 39 | |
| 40 | GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
| 41 | |
brianosman | fe4d5d3 | 2016-05-11 06:49:32 -0700 | [diff] [blame] | 42 | typedef GrFragmentProcessor INHERITED; |
brianosman | 2d1ee79 | 2016-05-05 12:24:31 -0700 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | #endif |