SkEdgeClipper.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright 2009 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 SkEdgeClipper_DEFINED
  8. #define SkEdgeClipper_DEFINED
  9. #include "include/core/SkPath.h"
  10. /** This is basically an iterator. It is initialized with an edge and a clip,
  11. and then next() is called until it returns kDone_Verb.
  12. */
  13. class SkEdgeClipper {
  14. public:
  15. SkEdgeClipper(bool canCullToTheRight) : fCanCullToTheRight(canCullToTheRight) {}
  16. bool clipLine(SkPoint p0, SkPoint p1, const SkRect& clip);
  17. bool clipQuad(const SkPoint pts[3], const SkRect& clip);
  18. bool clipCubic(const SkPoint pts[4], const SkRect& clip);
  19. SkPath::Verb next(SkPoint pts[]);
  20. bool canCullToTheRight() const { return fCanCullToTheRight; }
  21. private:
  22. SkPoint* fCurrPoint;
  23. SkPath::Verb* fCurrVerb;
  24. const bool fCanCullToTheRight;
  25. enum {
  26. kMaxVerbs = 18, // max curvature in X and Y split cubic into 9 pieces, * (line + cubic)
  27. kMaxPoints = 54 // 2 lines + 1 cubic require 6 points; times 9 pieces
  28. };
  29. SkPoint fPoints[kMaxPoints];
  30. SkPath::Verb fVerbs[kMaxVerbs];
  31. void clipMonoQuad(const SkPoint srcPts[3], const SkRect& clip);
  32. void clipMonoCubic(const SkPoint srcPts[4], const SkRect& clip);
  33. void appendLine(SkPoint p0, SkPoint p1);
  34. void appendVLine(SkScalar x, SkScalar y0, SkScalar y1, bool reverse);
  35. void appendQuad(const SkPoint pts[3], bool reverse);
  36. void appendCubic(const SkPoint pts[4], bool reverse);
  37. };
  38. #ifdef SK_DEBUG
  39. void sk_assert_monotonic_x(const SkPoint pts[], int count);
  40. void sk_assert_monotonic_y(const SkPoint pts[], int count);
  41. #else
  42. #define sk_assert_monotonic_x(pts, count)
  43. #define sk_assert_monotonic_y(pts, count)
  44. #endif
  45. #endif