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 | */ | ||||
Robert Phillips | 1c9686b | 2017-06-30 08:40:28 -0400 | [diff] [blame] | 23 | static sk_sp<GrFragmentProcessor> Make(Mode mode) { |
24 | return sk_sp<GrFragmentProcessor>(new GrSRGBEffect(mode)); | ||||
25 | } | ||||
brianosman | 2d1ee79 | 2016-05-05 12:24:31 -0700 | [diff] [blame] | 26 | |
Brian Osman | 964dec3 | 2017-01-26 09:32:33 -0500 | [diff] [blame] | 27 | const char* name() const override { return "sRGB"; } |
brianosman | 2d1ee79 | 2016-05-05 12:24:31 -0700 | [diff] [blame] | 28 | |
brianosman | fe4d5d3 | 2016-05-11 06:49:32 -0700 | [diff] [blame] | 29 | Mode mode() const { return fMode; } |
brianosman | 2d1ee79 | 2016-05-05 12:24:31 -0700 | [diff] [blame] | 30 | |
31 | private: | ||||
Brian Osman | 964dec3 | 2017-01-26 09:32:33 -0500 | [diff] [blame] | 32 | GrSRGBEffect(Mode mode); |
brianosman | 2d1ee79 | 2016-05-05 12:24:31 -0700 | [diff] [blame] | 33 | |
34 | GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; | ||||
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 35 | void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; |
brianosman | 2d1ee79 | 2016-05-05 12:24:31 -0700 | [diff] [blame] | 36 | bool onIsEqual(const GrFragmentProcessor&) const override; |
Brian Salomon | cb30bb2 | 2017-02-12 09:28:54 -0500 | [diff] [blame] | 37 | |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 38 | GrColor4f constantOutputForConstantInput(GrColor4f input) const override; |
brianosman | 2d1ee79 | 2016-05-05 12:24:31 -0700 | [diff] [blame] | 39 | |
brianosman | fe4d5d3 | 2016-05-11 06:49:32 -0700 | [diff] [blame] | 40 | Mode fMode; |
brianosman | 2d1ee79 | 2016-05-05 12:24:31 -0700 | [diff] [blame] | 41 | |
Brian Salomon | 0c26a9d | 2017-07-06 10:09:38 -0400 | [diff] [blame^] | 42 | GR_DECLARE_FRAGMENT_PROCESSOR_TEST |
brianosman | 2d1ee79 | 2016-05-05 12:24:31 -0700 | [diff] [blame] | 43 | |
brianosman | fe4d5d3 | 2016-05-11 06:49:32 -0700 | [diff] [blame] | 44 | typedef GrFragmentProcessor INHERITED; |
brianosman | 2d1ee79 | 2016-05-05 12:24:31 -0700 | [diff] [blame] | 45 | }; |
46 | |||||
47 | #endif |