blob: f91224e56d67b7fefd8e457d231b1feb60b1d586 [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
brianosmanfe4d5d32016-05-11 06:49:32 -070011#include "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
brianosman2d1ee792016-05-05 12:24:31 -070020 /**
Brian Osman964dec32017-01-26 09:32:33 -050021 * Creates an effect that applies the sRGB transfer function (or its inverse)
22 */
Robert Phillips1c9686b2017-06-30 08:40:28 -040023 static sk_sp<GrFragmentProcessor> Make(Mode mode) {
24 return sk_sp<GrFragmentProcessor>(new GrSRGBEffect(mode));
25 }
brianosman2d1ee792016-05-05 12:24:31 -070026
Brian Osman964dec32017-01-26 09:32:33 -050027 const char* name() const override { return "sRGB"; }
brianosman2d1ee792016-05-05 12:24:31 -070028
brianosmanfe4d5d32016-05-11 06:49:32 -070029 Mode mode() const { return fMode; }
brianosman2d1ee792016-05-05 12:24:31 -070030
31private:
Brian Osman964dec32017-01-26 09:32:33 -050032 GrSRGBEffect(Mode mode);
brianosman2d1ee792016-05-05 12:24:31 -070033
34 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
Brian Salomon94efbf52016-11-29 13:43:05 -050035 void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
brianosman2d1ee792016-05-05 12:24:31 -070036 bool onIsEqual(const GrFragmentProcessor&) const override;
Brian Salomoncb30bb22017-02-12 09:28:54 -050037
Brian Salomon587e08f2017-01-27 10:59:27 -050038 GrColor4f constantOutputForConstantInput(GrColor4f input) const override;
brianosman2d1ee792016-05-05 12:24:31 -070039
brianosmanfe4d5d32016-05-11 06:49:32 -070040 Mode fMode;
brianosman2d1ee792016-05-05 12:24:31 -070041
Brian Salomon0c26a9d2017-07-06 10:09:38 -040042 GR_DECLARE_FRAGMENT_PROCESSOR_TEST
brianosman2d1ee792016-05-05 12:24:31 -070043
brianosmanfe4d5d32016-05-11 06:49:32 -070044 typedef GrFragmentProcessor INHERITED;
brianosman2d1ee792016-05-05 12:24:31 -070045};
46
47#endif