Sk2DPathEffect.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 Sk2DPathEffect_DEFINED
  8. #define Sk2DPathEffect_DEFINED
  9. #include "SkFlattenable.h"
  10. #include "SkPath.h"
  11. #include "SkPathEffect.h"
  12. #include "SkMatrix.h"
  13. class SK_API Sk2DPathEffect : public SkPathEffect {
  14. protected:
  15. /** New virtual, to be overridden by subclasses.
  16. This is called once from filterPath, and provides the
  17. uv parameter bounds for the path. Subsequent calls to
  18. next() will receive u and v values within these bounds,
  19. and then a call to end() will signal the end of processing.
  20. */
  21. virtual void begin(const SkIRect& uvBounds, SkPath* dst) const;
  22. virtual void next(const SkPoint& loc, int u, int v, SkPath* dst) const;
  23. virtual void end(SkPath* dst) const;
  24. /** Low-level virtual called per span of locations in the u-direction.
  25. The default implementation calls next() repeatedly with each
  26. location.
  27. */
  28. virtual void nextSpan(int u, int v, int ucount, SkPath* dst) const;
  29. const SkMatrix& getMatrix() const { return fMatrix; }
  30. // protected so that subclasses can call this during unflattening
  31. explicit Sk2DPathEffect(const SkMatrix& mat);
  32. void flatten(SkWriteBuffer&) const override;
  33. bool onFilterPath(SkPath*, const SkPath&, SkStrokeRec*, const SkRect*) const override;
  34. private:
  35. SkMatrix fMatrix, fInverse;
  36. bool fMatrixIsInvertible;
  37. // illegal
  38. Sk2DPathEffect(const Sk2DPathEffect&);
  39. Sk2DPathEffect& operator=(const Sk2DPathEffect&);
  40. friend class Sk2DPathEffectBlitter;
  41. typedef SkPathEffect INHERITED;
  42. };
  43. class SK_API SkLine2DPathEffect : public Sk2DPathEffect {
  44. public:
  45. static sk_sp<SkPathEffect> Make(SkScalar width, const SkMatrix& matrix) {
  46. if (!(width >= 0)) {
  47. return nullptr;
  48. }
  49. return sk_sp<SkPathEffect>(new SkLine2DPathEffect(width, matrix));
  50. }
  51. protected:
  52. SkLine2DPathEffect(SkScalar width, const SkMatrix& matrix)
  53. : Sk2DPathEffect(matrix), fWidth(width) {
  54. SkASSERT(width >= 0);
  55. }
  56. void flatten(SkWriteBuffer&) const override;
  57. bool onFilterPath(SkPath* dst, const SkPath& src, SkStrokeRec*, const SkRect*) const override;
  58. void nextSpan(int u, int v, int ucount, SkPath*) const override;
  59. private:
  60. SK_FLATTENABLE_HOOKS(SkLine2DPathEffect)
  61. SkScalar fWidth;
  62. typedef Sk2DPathEffect INHERITED;
  63. };
  64. class SK_API SkPath2DPathEffect : public Sk2DPathEffect {
  65. public:
  66. /**
  67. * Stamp the specified path to fill the shape, using the matrix to define
  68. * the latice.
  69. */
  70. static sk_sp<SkPathEffect> Make(const SkMatrix& matrix, const SkPath& path) {
  71. return sk_sp<SkPathEffect>(new SkPath2DPathEffect(matrix, path));
  72. }
  73. protected:
  74. SkPath2DPathEffect(const SkMatrix&, const SkPath&);
  75. void flatten(SkWriteBuffer&) const override;
  76. void next(const SkPoint&, int u, int v, SkPath*) const override;
  77. private:
  78. SK_FLATTENABLE_HOOKS(SkPath2DPathEffect)
  79. SkPath fPath;
  80. typedef Sk2DPathEffect INHERITED;
  81. };
  82. #endif