GrSRGBEffect.h 1.4 KB

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