blob: 13d8bc3cb93ccd64f87b3a43e66a369672128aef [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
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 */
Mike Reed98308fb2017-07-07 08:28:13 -040028 static sk_sp<GrFragmentProcessor> Make(Mode mode, Alpha alpha) {
29 return sk_sp<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
37private:
Mike Reed98308fb2017-07-07 08:28:13 -040038 GrSRGBEffect(Mode mode, Alpha);
brianosman2d1ee792016-05-05 12:24:31 -070039
40 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
Brian Salomon94efbf52016-11-29 13:43:05 -050041 void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
brianosman2d1ee792016-05-05 12:24:31 -070042 bool onIsEqual(const GrFragmentProcessor&) const override;
Brian Salomoncb30bb22017-02-12 09:28:54 -050043
Brian Salomon587e08f2017-01-27 10:59:27 -050044 GrColor4f constantOutputForConstantInput(GrColor4f input) const override;
brianosman2d1ee792016-05-05 12:24:31 -070045
brianosmanfe4d5d32016-05-11 06:49:32 -070046 Mode fMode;
Mike Reed98308fb2017-07-07 08:28:13 -040047 Alpha fAlpha;
brianosman2d1ee792016-05-05 12:24:31 -070048
Brian Salomon0c26a9d2017-07-06 10:09:38 -040049 GR_DECLARE_FRAGMENT_PROCESSOR_TEST
brianosman2d1ee792016-05-05 12:24:31 -070050
brianosmanfe4d5d32016-05-11 06:49:32 -070051 typedef GrFragmentProcessor INHERITED;
brianosman2d1ee792016-05-05 12:24:31 -070052};
53
54#endif