SkOpEdgeBuilder.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright 2012 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 SkOpEdgeBuilder_DEFINED
  8. #define SkOpEdgeBuilder_DEFINED
  9. #include "src/pathops/SkOpContour.h"
  10. #include "src/pathops/SkPathWriter.h"
  11. class SkOpEdgeBuilder {
  12. public:
  13. SkOpEdgeBuilder(const SkPathWriter& path, SkOpContourHead* contours2,
  14. SkOpGlobalState* globalState)
  15. : fGlobalState(globalState)
  16. , fPath(path.nativePath())
  17. , fContourBuilder(contours2)
  18. , fContoursHead(contours2)
  19. , fAllowOpenContours(true) {
  20. init();
  21. }
  22. SkOpEdgeBuilder(const SkPath& path, SkOpContourHead* contours2, SkOpGlobalState* globalState)
  23. : fGlobalState(globalState)
  24. , fPath(&path)
  25. , fContourBuilder(contours2)
  26. , fContoursHead(contours2)
  27. , fAllowOpenContours(false) {
  28. init();
  29. }
  30. void addOperand(const SkPath& path);
  31. void complete() {
  32. fContourBuilder.flush();
  33. SkOpContour* contour = fContourBuilder.contour();
  34. if (contour && contour->count()) {
  35. contour->complete();
  36. fContourBuilder.setContour(nullptr);
  37. }
  38. }
  39. bool finish();
  40. const SkOpContour* head() const {
  41. return fContoursHead;
  42. }
  43. void init();
  44. bool unparseable() const { return fUnparseable; }
  45. SkPathOpsMask xorMask() const { return fXorMask[fOperand]; }
  46. private:
  47. void closeContour(const SkPoint& curveEnd, const SkPoint& curveStart);
  48. bool close();
  49. int preFetch();
  50. bool walk();
  51. SkOpGlobalState* fGlobalState;
  52. const SkPath* fPath;
  53. SkTDArray<SkPoint> fPathPts;
  54. SkTDArray<SkScalar> fWeights;
  55. SkTDArray<uint8_t> fPathVerbs;
  56. SkOpContourBuilder fContourBuilder;
  57. SkOpContourHead* fContoursHead;
  58. SkPathOpsMask fXorMask[2];
  59. int fSecondHalf;
  60. bool fOperand;
  61. bool fAllowOpenContours;
  62. bool fUnparseable;
  63. };
  64. #endif