blob: 2135a5027903cf5c1ee9c0a25d996ebbfff2b524 [file] [log] [blame]
brianosman2d1ee792016-05-05 12:24:31 -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
Brian Osman964dec32017-01-26 09:32:33 -05008#ifndef GrSRGBEffect_DEFINED
9#define GrSRGBEffect_DEFINED
brianosman2d1ee792016-05-05 12:24:31 -070010
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "src/gpu/GrFragmentProcessor.h"
brianosman2d1ee792016-05-05 12:24:31 -070012
Brian Osman964dec32017-01-26 09:32:33 -050013class GrSRGBEffect : public GrFragmentProcessor {
brianosman2d1ee792016-05-05 12:24:31 -070014public:
brianosmanfe4d5d32016-05-11 06:49:32 -070015 enum class Mode {
16 kLinearToSRGB,
17 kSRGBToLinear,
brianosmanfe4d5d32016-05-11 06:49:32 -070018 };
19
Mike Reed98308fb2017-07-07 08:28:13 -040020 enum class Alpha {
21 kPremul,
22 kOpaque,
23 };
24
brianosman2d1ee792016-05-05 12:24:31 -070025 /**
Brian Osman964dec32017-01-26 09:32:33 -050026 * Creates an effect that applies the sRGB transfer function (or its inverse)
27 */
Brian Salomonaff329b2017-08-11 09:40:37 -040028 static std::unique_ptr<GrFragmentProcessor> Make(Mode mode, Alpha alpha) {
29 return std::unique_ptr<GrFragmentProcessor>(new GrSRGBEffect(mode, alpha));
Robert Phillips1c9686b2017-06-30 08:40:28 -040030 }
brianosman2d1ee792016-05-05 12:24:31 -070031
Brian Osman964dec32017-01-26 09:32:33 -050032 const char* name() const override { return "sRGB"; }
brianosman2d1ee792016-05-05 12:24:31 -070033
brianosmanfe4d5d32016-05-11 06:49:32 -070034 Mode mode() const { return fMode; }
Mike Reed98308fb2017-07-07 08:28:13 -040035 Alpha alpha() const { return fAlpha; }
brianosman2d1ee792016-05-05 12:24:31 -070036
Brian Salomonaff329b2017-08-11 09:40:37 -040037 std::unique_ptr<GrFragmentProcessor> clone() const override;
Brian Salomon1a2a7ab2017-07-26 13:11:51 -040038
brianosman2d1ee792016-05-05 12:24:31 -070039private:
Mike Reed98308fb2017-07-07 08:28:13 -040040 GrSRGBEffect(Mode mode, Alpha);
brianosman2d1ee792016-05-05 12:24:31 -070041
42 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
Brian Salomon94efbf52016-11-29 13:43:05 -050043 void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
brianosman2d1ee792016-05-05 12:24:31 -070044 bool onIsEqual(const GrFragmentProcessor&) const override;
Brian Salomoncb30bb22017-02-12 09:28:54 -050045
Brian Osman1d5b5982018-10-01 13:41:39 -040046 SkPMColor4f constantOutputForConstantInput(const SkPMColor4f& input) const override;
brianosman2d1ee792016-05-05 12:24:31 -070047
brianosmanfe4d5d32016-05-11 06:49:32 -070048 Mode fMode;
Mike Reed98308fb2017-07-07 08:28:13 -040049 Alpha fAlpha;
brianosman2d1ee792016-05-05 12:24:31 -070050
Brian Salomon0c26a9d2017-07-06 10:09:38 -040051 GR_DECLARE_FRAGMENT_PROCESSOR_TEST
brianosman2d1ee792016-05-05 12:24:31 -070052
brianosmanfe4d5d32016-05-11 06:49:32 -070053 typedef GrFragmentProcessor INHERITED;
brianosman2d1ee792016-05-05 12:24:31 -070054};
55
56#endif