SkQuadClipper.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 SkQuadClipper_DEFINED
  8. #define SkQuadClipper_DEFINED
  9. #include "include/core/SkPath.h"
  10. /** This class is initialized with a clip rectangle, and then can be fed quads,
  11. which must already be monotonic in Y.
  12. In the future, it might return a series of segments, allowing it to clip
  13. also in X, to ensure that all segments fit in a finite coordinate system.
  14. */
  15. class SkQuadClipper {
  16. public:
  17. SkQuadClipper();
  18. void setClip(const SkIRect& clip);
  19. bool clipQuad(const SkPoint src[3], SkPoint dst[3]);
  20. private:
  21. SkRect fClip;
  22. };
  23. /** Iterator that returns the clipped segements of a quad clipped to a rect.
  24. The segments will be either lines or quads (based on SkPath::Verb), and
  25. will all be monotonic in Y
  26. */
  27. class SkQuadClipper2 {
  28. public:
  29. bool clipQuad(const SkPoint pts[3], const SkRect& clip);
  30. bool clipCubic(const SkPoint pts[4], const SkRect& clip);
  31. SkPath::Verb next(SkPoint pts[]);
  32. private:
  33. SkPoint* fCurrPoint;
  34. SkPath::Verb* fCurrVerb;
  35. enum {
  36. kMaxVerbs = 13,
  37. kMaxPoints = 32
  38. };
  39. SkPoint fPoints[kMaxPoints];
  40. SkPath::Verb fVerbs[kMaxVerbs];
  41. void clipMonoQuad(const SkPoint srcPts[3], const SkRect& clip);
  42. void clipMonoCubic(const SkPoint srcPts[4], const SkRect& clip);
  43. void appendVLine(SkScalar x, SkScalar y0, SkScalar y1, bool reverse);
  44. void appendQuad(const SkPoint pts[3], bool reverse);
  45. void appendCubic(const SkPoint pts[4], bool reverse);
  46. };
  47. #ifdef SK_DEBUG
  48. void sk_assert_monotonic_x(const SkPoint pts[], int count);
  49. void sk_assert_monotonic_y(const SkPoint pts[], int count);
  50. #else
  51. #define sk_assert_monotonic_x(pts, count)
  52. #define sk_assert_monotonic_y(pts, count)
  53. #endif
  54. #endif