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 8#ifndef GrSRGBEffect_DEFINED 9#define GrSRGBEffect_DEFINED 10 11#include "GrFragmentProcessor.h" 12 13class GrSRGBEffect : public GrFragmentProcessor { 14public: 15 enum class Mode { 16 kLinearToSRGB, 17 kSRGBToLinear, 18 }; 19 20 enum class Alpha { 21 kPremul, 22 kOpaque, 23 }; 24 25 /** 26 * Creates an effect that applies the sRGB transfer function (or its inverse) 27 */ 28 static std::unique_ptr<GrFragmentProcessor> Make(Mode mode, Alpha alpha) { 29 return std::unique_ptr<GrFragmentProcessor>(new GrSRGBEffect(mode, alpha)); 30 } 31 32 const char* name() const override { return "sRGB"; } 33 34 Mode mode() const { return fMode; } 35 Alpha alpha() const { return fAlpha; } 36 37 std::unique_ptr<GrFragmentProcessor> clone() const override; 38 39private: 40 GrSRGBEffect(Mode mode, Alpha); 41 42 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; 43 void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; 44 bool onIsEqual(const GrFragmentProcessor&) const override; 45 46 GrColor4f constantOutputForConstantInput(GrColor4f input) const override; 47 48 Mode fMode; 49 Alpha fAlpha; 50 51 GR_DECLARE_FRAGMENT_PROCESSOR_TEST 52 53 typedef GrFragmentProcessor INHERITED; 54}; 55 56#endif 57