GrGradientShader.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright 2018 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 GrGradientShader_DEFINE
  8. #define GrGradientShader_DEFINE
  9. #include "src/gpu/GrFPArgs.h"
  10. #include "src/gpu/GrFragmentProcessor.h"
  11. #include "src/shaders/gradients/SkGradientShaderPriv.h"
  12. #include "src/shaders/gradients/SkLinearGradient.h"
  13. #include "src/shaders/gradients/SkRadialGradient.h"
  14. #include "src/shaders/gradients/SkSweepGradient.h"
  15. #include "src/shaders/gradients/SkTwoPointConicalGradient.h"
  16. #if GR_TEST_UTILS
  17. #include "include/utils/SkRandom.h"
  18. #endif
  19. namespace GrGradientShader {
  20. std::unique_ptr<GrFragmentProcessor> MakeLinear(const SkLinearGradient& shader,
  21. const GrFPArgs& args);
  22. std::unique_ptr<GrFragmentProcessor> MakeRadial(const SkRadialGradient& shader,
  23. const GrFPArgs& args);
  24. std::unique_ptr<GrFragmentProcessor> MakeSweep(const SkSweepGradient& shader,
  25. const GrFPArgs& args);
  26. std::unique_ptr<GrFragmentProcessor> MakeConical(const SkTwoPointConicalGradient& shader,
  27. const GrFPArgs& args);
  28. #if GR_TEST_UTILS
  29. /** Helper struct that stores (and populates) parameters to construct a random gradient.
  30. If fUseColors4f is true, then the SkColor4f factory should be called, with fColors4f and
  31. fColorSpace. Otherwise, the SkColor factory should be called, with fColors. fColorCount
  32. will be the number of color stops in either case, and fColors and fStops can be passed to
  33. the gradient factory. (The constructor may decide not to use stops, in which case fStops
  34. will be nullptr). */
  35. struct RandomParams {
  36. static constexpr int kMaxRandomGradientColors = 5;
  37. // Should be of similar magnitude to the draw area of the tests so that the gradient
  38. // sampling is done at an appropriate scale.
  39. static constexpr SkScalar kGradientScale = 256.0f;
  40. RandomParams(SkRandom* r);
  41. bool fUseColors4f;
  42. SkColor fColors[kMaxRandomGradientColors];
  43. SkColor4f fColors4f[kMaxRandomGradientColors];
  44. sk_sp<SkColorSpace> fColorSpace;
  45. SkScalar fStopStorage[kMaxRandomGradientColors];
  46. SkTileMode fTileMode;
  47. int fColorCount;
  48. SkScalar* fStops;
  49. };
  50. #endif
  51. }
  52. #endif // GrGradientShader_DEFINE