SkColorShader.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright 2007 The Android Open Source Project
  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 SkColorShader_DEFINED
  8. #define SkColorShader_DEFINED
  9. #include "src/shaders/SkShaderBase.h"
  10. /** \class SkColorShader
  11. A Shader that represents a single color. In general, this effect can be
  12. accomplished by just using the color field on the paint, but if an
  13. actual shader object is needed, this provides that feature.
  14. */
  15. class SkColorShader : public SkShaderBase {
  16. public:
  17. /** Create a ColorShader that ignores the color in the paint, and uses the
  18. specified color. Note: like all shaders, at draw time the paint's alpha
  19. will be respected, and is applied to the specified color.
  20. */
  21. explicit SkColorShader(SkColor c);
  22. bool isOpaque() const override;
  23. bool isConstant() const override { return true; }
  24. GradientType asAGradient(GradientInfo* info) const override;
  25. #if SK_SUPPORT_GPU
  26. std::unique_ptr<GrFragmentProcessor> asFragmentProcessor(const GrFPArgs&) const override;
  27. #endif
  28. private:
  29. SK_FLATTENABLE_HOOKS(SkColorShader)
  30. void flatten(SkWriteBuffer&) const override;
  31. bool onAsLuminanceColor(SkColor* lum) const override {
  32. *lum = fColor;
  33. return true;
  34. }
  35. bool onAppendStages(const SkStageRec&) const override;
  36. SkColor fColor;
  37. };
  38. class SkColor4Shader : public SkShaderBase {
  39. public:
  40. SkColor4Shader(const SkColor4f&, sk_sp<SkColorSpace>);
  41. bool isOpaque() const override { return fColor.isOpaque(); }
  42. bool isConstant() const override { return true; }
  43. #if SK_SUPPORT_GPU
  44. std::unique_ptr<GrFragmentProcessor> asFragmentProcessor(const GrFPArgs&) const override;
  45. #endif
  46. private:
  47. SK_FLATTENABLE_HOOKS(SkColor4Shader)
  48. void flatten(SkWriteBuffer&) const override;
  49. bool onAppendStages(const SkStageRec&) const override;
  50. sk_sp<SkColorSpace> fColorSpace;
  51. const SkColor4f fColor;
  52. };
  53. #endif