SkDiscretePathEffect.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * Copyright 2006 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 SkDiscretePathEffect_DEFINED
  8. #define SkDiscretePathEffect_DEFINED
  9. #include "SkFlattenable.h"
  10. #include "SkPathEffect.h"
  11. /** \class SkDiscretePathEffect
  12. This path effect chops a path into discrete segments, and randomly displaces them.
  13. */
  14. class SK_API SkDiscretePathEffect : public SkPathEffect {
  15. public:
  16. /** Break the path into segments of segLength length, and randomly move the endpoints
  17. away from the original path by a maximum of deviation.
  18. Note: works on filled or framed paths
  19. @param seedAssist This is a caller-supplied seedAssist that modifies
  20. the seed value that is used to randomize the path
  21. segments' endpoints. If not supplied it defaults to 0,
  22. in which case filtering a path multiple times will
  23. result in the same set of segments (this is useful for
  24. testing). If a caller does not want this behaviour
  25. they can pass in a different seedAssist to get a
  26. different set of path segments.
  27. */
  28. static sk_sp<SkPathEffect> Make(SkScalar segLength, SkScalar dev, uint32_t seedAssist = 0);
  29. protected:
  30. SkDiscretePathEffect(SkScalar segLength,
  31. SkScalar deviation,
  32. uint32_t seedAssist);
  33. void flatten(SkWriteBuffer&) const override;
  34. bool onFilterPath(SkPath* dst, const SkPath& src, SkStrokeRec*, const SkRect*) const override;
  35. private:
  36. SK_FLATTENABLE_HOOKS(SkDiscretePathEffect)
  37. SkScalar fSegLength, fPerterb;
  38. /* Caller-supplied 32 bit seed assist */
  39. uint32_t fSeedAssist;
  40. typedef SkPathEffect INHERITED;
  41. };
  42. #endif