OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkPath_DEFINED | 8 #ifndef SkPath_DEFINED |
9 #define SkPath_DEFINED | 9 #define SkPath_DEFINED |
10 | 10 |
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 void arcTo(const SkPoint p1, const SkPoint p2, SkScalar radius) { | 485 void arcTo(const SkPoint p1, const SkPoint p2, SkScalar radius) { |
486 this->arcTo(p1.fX, p1.fY, p2.fX, p2.fY, radius); | 486 this->arcTo(p1.fX, p1.fY, p2.fX, p2.fY, radius); |
487 } | 487 } |
488 | 488 |
489 /** Close the current contour. If the current point is not equal to the | 489 /** Close the current contour. If the current point is not equal to the |
490 first point of the contour, a line segment is automatically added. | 490 first point of the contour, a line segment is automatically added. |
491 */ | 491 */ |
492 void close(); | 492 void close(); |
493 | 493 |
494 enum Direction { | 494 enum Direction { |
495 /** Direction either has not been or could not be computed */ | |
496 kUnknown_Direction, | |
497 /** clockwise direction for adding closed contours */ | 495 /** clockwise direction for adding closed contours */ |
498 kCW_Direction, | 496 kCW_Direction, |
499 /** counter-clockwise direction for adding closed contours */ | 497 /** counter-clockwise direction for adding closed contours */ |
500 kCCW_Direction, | 498 kCCW_Direction, |
501 }; | 499 }; |
502 | 500 |
503 /** | 501 /** |
504 * Return the opposite of the specified direction. kUnknown is its own | |
505 * opposite. | |
506 */ | |
507 static Direction OppositeDirection(Direction dir) { | |
508 static const Direction gOppositeDir[] = { | |
509 kUnknown_Direction, kCCW_Direction, kCW_Direction | |
510 }; | |
511 return gOppositeDir[dir]; | |
512 } | |
513 | |
514 /** | |
515 * Returns whether or not a fill type is inverted | 502 * Returns whether or not a fill type is inverted |
516 * | 503 * |
517 * kWinding_FillType -> false | 504 * kWinding_FillType -> false |
518 * kEvenOdd_FillType -> false | 505 * kEvenOdd_FillType -> false |
519 * kInverseWinding_FillType -> true | 506 * kInverseWinding_FillType -> true |
520 * kInverseEvenOdd_FillType -> true | 507 * kInverseEvenOdd_FillType -> true |
521 */ | 508 */ |
522 static bool IsInverseFillType(FillType fill) { | 509 static bool IsInverseFillType(FillType fill) { |
523 SK_COMPILE_ASSERT(0 == kWinding_FillType, fill_type_mismatch); | 510 SK_COMPILE_ASSERT(0 == kWinding_FillType, fill_type_mismatch); |
524 SK_COMPILE_ASSERT(1 == kEvenOdd_FillType, fill_type_mismatch); | 511 SK_COMPILE_ASSERT(1 == kEvenOdd_FillType, fill_type_mismatch); |
(...skipping 12 matching lines...) Expand all Loading... |
537 */ | 524 */ |
538 static FillType ConvertToNonInverseFillType(FillType fill) { | 525 static FillType ConvertToNonInverseFillType(FillType fill) { |
539 SK_COMPILE_ASSERT(0 == kWinding_FillType, fill_type_mismatch); | 526 SK_COMPILE_ASSERT(0 == kWinding_FillType, fill_type_mismatch); |
540 SK_COMPILE_ASSERT(1 == kEvenOdd_FillType, fill_type_mismatch); | 527 SK_COMPILE_ASSERT(1 == kEvenOdd_FillType, fill_type_mismatch); |
541 SK_COMPILE_ASSERT(2 == kInverseWinding_FillType, fill_type_mismatch); | 528 SK_COMPILE_ASSERT(2 == kInverseWinding_FillType, fill_type_mismatch); |
542 SK_COMPILE_ASSERT(3 == kInverseEvenOdd_FillType, fill_type_mismatch); | 529 SK_COMPILE_ASSERT(3 == kInverseEvenOdd_FillType, fill_type_mismatch); |
543 return (FillType)(fill & 1); | 530 return (FillType)(fill & 1); |
544 } | 531 } |
545 | 532 |
546 /** | 533 /** |
547 * Tries to quickly compute the direction of the first non-degenerate | |
548 * contour. If it can be computed, return true and set dir to that | |
549 * direction. If it cannot be (quickly) determined, return false and ignore | |
550 * the dir parameter. If the direction was determined, it is cached to make | |
551 * subsequent calls return quickly. | |
552 */ | |
553 bool cheapComputeDirection(Direction* dir) const; | |
554 | |
555 /** | |
556 * Returns true if the path's direction can be computed via | |
557 * cheapComputDirection() and if that computed direction matches the | |
558 * specified direction. If dir is kUnknown, returns true if the direction | |
559 * cannot be computed. | |
560 */ | |
561 bool cheapIsDirection(Direction dir) const { | |
562 Direction computedDir = kUnknown_Direction; | |
563 (void)this->cheapComputeDirection(&computedDir); | |
564 return computedDir == dir; | |
565 } | |
566 | |
567 /** | |
568 * Returns true if the path specifies a rectangle. | 534 * Returns true if the path specifies a rectangle. |
569 * | 535 * |
570 * If this returns false, then all output parameters are ignored, and left | 536 * If this returns false, then all output parameters are ignored, and left |
571 * unchanged. If this returns true, then each of the output parameters | 537 * unchanged. If this returns true, then each of the output parameters |
572 * are checked for NULL. If they are not, they return their value. | 538 * are checked for NULL. If they are not, they return their value. |
573 * | 539 * |
574 * @param rect If not null, set to the bounds of the rectangle. | 540 * @param rect If not null, set to the bounds of the rectangle. |
575 * Note : this bounds may be smaller than the path's bounds, si
nce it is just | 541 * Note : this bounds may be smaller than the path's bounds, si
nce it is just |
576 * the bounds of the "drawable" parts of the path. e.g. a trail
ing MoveTo would | 542 * the bounds of the "drawable" parts of the path. e.g. a trail
ing MoveTo would |
577 * be ignored in this rect, but not by the path's bounds | 543 * be ignored in this rect, but not by the path's bounds |
(...skipping 13 matching lines...) Expand all Loading... |
591 | 557 |
592 @param rect If not null, returns the path as a pair of nested rectangles | 558 @param rect If not null, returns the path as a pair of nested rectangles |
593 @param dirs If not null, returns the direction of the rects | 559 @param dirs If not null, returns the direction of the rects |
594 @return true if the path describes a pair of nested rectangles | 560 @return true if the path describes a pair of nested rectangles |
595 */ | 561 */ |
596 bool isNestedFillRects(SkRect rect[2], Direction dirs[2] = NULL) const; | 562 bool isNestedFillRects(SkRect rect[2], Direction dirs[2] = NULL) const; |
597 | 563 |
598 /** | 564 /** |
599 * Add a closed rectangle contour to the path | 565 * Add a closed rectangle contour to the path |
600 * @param rect The rectangle to add as a closed contour to the path | 566 * @param rect The rectangle to add as a closed contour to the path |
601 * @param dir The direction to wind the rectangle's contour. Cannot be | 567 * @param dir The direction to wind the rectangle's contour. |
602 * kUnknown_Direction. | |
603 */ | 568 */ |
604 void addRect(const SkRect& rect, Direction dir = kCW_Direction); | 569 void addRect(const SkRect& rect, Direction dir = kCW_Direction); |
605 | 570 |
606 /** | 571 /** |
607 * Add a closed rectangle contour to the path | 572 * Add a closed rectangle contour to the path |
608 * | 573 * |
609 * @param left The left side of a rectangle to add as a closed contour | 574 * @param left The left side of a rectangle to add as a closed contour |
610 * to the path | 575 * to the path |
611 * @param top The top of a rectangle to add as a closed contour to the | 576 * @param top The top of a rectangle to add as a closed contour to the |
612 * path | 577 * path |
613 * @param right The right side of a rectangle to add as a closed contour | 578 * @param right The right side of a rectangle to add as a closed contour |
614 * to the path | 579 * to the path |
615 * @param bottom The bottom of a rectangle to add as a closed contour to | 580 * @param bottom The bottom of a rectangle to add as a closed contour to |
616 * the path | 581 * the path |
617 * @param dir The direction to wind the rectangle's contour. Cannot be | 582 * @param dir The direction to wind the rectangle's contour. |
618 * kUnknown_Direction. | |
619 */ | 583 */ |
620 void addRect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom, | 584 void addRect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom, |
621 Direction dir = kCW_Direction); | 585 Direction dir = kCW_Direction); |
622 | 586 |
623 /** | 587 /** |
624 * Add a closed oval contour to the path | 588 * Add a closed oval contour to the path |
625 * | 589 * |
626 * @param oval The bounding oval to add as a closed contour to the path | 590 * @param oval The bounding oval to add as a closed contour to the path |
627 * @param dir The direction to wind the oval's contour. Cannot be | 591 * @param dir The direction to wind the oval's contour. |
628 * kUnknown_Direction. | |
629 */ | 592 */ |
630 void addOval(const SkRect& oval, Direction dir = kCW_Direction); | 593 void addOval(const SkRect& oval, Direction dir = kCW_Direction); |
631 | 594 |
632 /** | 595 /** |
633 * Add a closed circle contour to the path | 596 * Add a closed circle contour to the path |
634 * | 597 * |
635 * @param x The x-coordinate of the center of a circle to add as a | 598 * @param x The x-coordinate of the center of a circle to add as a |
636 * closed contour to the path | 599 * closed contour to the path |
637 * @param y The y-coordinate of the center of a circle to add as a | 600 * @param y The y-coordinate of the center of a circle to add as a |
638 * closed contour to the path | 601 * closed contour to the path |
639 * @param radius The radius of a circle to add as a closed contour to the | 602 * @param radius The radius of a circle to add as a closed contour to the |
640 * path | 603 * path |
641 * @param dir The direction to wind the circle's contour. Cannot be | 604 * @param dir The direction to wind the circle's contour. |
642 * kUnknown_Direction. | |
643 */ | 605 */ |
644 void addCircle(SkScalar x, SkScalar y, SkScalar radius, | 606 void addCircle(SkScalar x, SkScalar y, SkScalar radius, |
645 Direction dir = kCW_Direction); | 607 Direction dir = kCW_Direction); |
646 | 608 |
647 /** Add the specified arc to the path as a new contour. | 609 /** Add the specified arc to the path as a new contour. |
648 | 610 |
649 @param oval The bounds of oval used to define the size of the arc | 611 @param oval The bounds of oval used to define the size of the arc |
650 @param startAngle Starting angle (in degrees) where the arc begins | 612 @param startAngle Starting angle (in degrees) where the arc begins |
651 @param sweepAngle Sweep angle (in degrees) measured clockwise | 613 @param sweepAngle Sweep angle (in degrees) measured clockwise |
652 */ | 614 */ |
653 void addArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle); | 615 void addArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle); |
654 | 616 |
655 /** | 617 /** |
656 * Add a closed round-rectangle contour to the path | 618 * Add a closed round-rectangle contour to the path |
657 * @param rect The bounds of a round-rectangle to add as a closed contour | 619 * @param rect The bounds of a round-rectangle to add as a closed contour |
658 * @param rx The x-radius of the rounded corners on the round-rectangle | 620 * @param rx The x-radius of the rounded corners on the round-rectangle |
659 * @param ry The y-radius of the rounded corners on the round-rectangle | 621 * @param ry The y-radius of the rounded corners on the round-rectangle |
660 * @param dir The direction to wind the rectangle's contour. Cannot be | 622 * @param dir The direction to wind the rectangle's contour. |
661 * kUnknown_Direction. | |
662 */ | 623 */ |
663 void addRoundRect(const SkRect& rect, SkScalar rx, SkScalar ry, | 624 void addRoundRect(const SkRect& rect, SkScalar rx, SkScalar ry, |
664 Direction dir = kCW_Direction); | 625 Direction dir = kCW_Direction); |
665 | 626 |
666 /** | 627 /** |
667 * Add a closed round-rectangle contour to the path. Each corner receives | 628 * Add a closed round-rectangle contour to the path. Each corner receives |
668 * two radius values [X, Y]. The corners are ordered top-left, top-right, | 629 * two radius values [X, Y]. The corners are ordered top-left, top-right, |
669 * bottom-right, bottom-left. | 630 * bottom-right, bottom-left. |
670 * @param rect The bounds of a round-rectangle to add as a closed contour | 631 * @param rect The bounds of a round-rectangle to add as a closed contour |
671 * @param radii Array of 8 scalars, 4 [X,Y] pairs for each corner | 632 * @param radii Array of 8 scalars, 4 [X,Y] pairs for each corner |
672 * @param dir The direction to wind the rectangle's contour. Cannot be | 633 * @param dir The direction to wind the rectangle's contour. |
673 * kUnknown_Direction. | |
674 * Note: The radii here now go through the same constraint handling as the | 634 * Note: The radii here now go through the same constraint handling as the |
675 * SkRRect radii (i.e., either radii at a corner being 0 implies a | 635 * SkRRect radii (i.e., either radii at a corner being 0 implies a |
676 * sqaure corner and oversized radii are proportionally scaled down). | 636 * sqaure corner and oversized radii are proportionally scaled down). |
677 */ | 637 */ |
678 void addRoundRect(const SkRect& rect, const SkScalar radii[], | 638 void addRoundRect(const SkRect& rect, const SkScalar radii[], |
679 Direction dir = kCW_Direction); | 639 Direction dir = kCW_Direction); |
680 | 640 |
681 /** | 641 /** |
682 * Add an SkRRect contour to the path | 642 * Add an SkRRect contour to the path |
683 * @param rrect The rounded rect to add as a closed contour | 643 * @param rrect The rounded rect to add as a closed contour |
684 * @param dir The winding direction for the new contour. Cannot be | 644 * @param dir The winding direction for the new contour. |
685 * kUnknown_Direction. | |
686 */ | 645 */ |
687 void addRRect(const SkRRect& rrect, Direction dir = kCW_Direction); | 646 void addRRect(const SkRRect& rrect, Direction dir = kCW_Direction); |
688 | 647 |
689 /** | 648 /** |
690 * Add a new contour made of just lines. This is just a fast version of | 649 * Add a new contour made of just lines. This is just a fast version of |
691 * the following: | 650 * the following: |
692 * this->moveTo(pts[0]); | 651 * this->moveTo(pts[0]); |
693 * for (int i = 1; i < count; ++i) { | 652 * for (int i = 1; i < count; ++i) { |
694 * this->lineTo(pts[i]); | 653 * this->lineTo(pts[i]); |
695 * } | 654 * } |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
969 kConvexity_SerializationShift = 16, // requires 8 bits | 928 kConvexity_SerializationShift = 16, // requires 8 bits |
970 kFillType_SerializationShift = 8, // requires 8 bits | 929 kFillType_SerializationShift = 8, // requires 8 bits |
971 // 8 free bits at 0 | 930 // 8 free bits at 0 |
972 }; | 931 }; |
973 | 932 |
974 SkAutoTUnref<SkPathRef> fPathRef; | 933 SkAutoTUnref<SkPathRef> fPathRef; |
975 | 934 |
976 int fLastMoveToIndex; | 935 int fLastMoveToIndex; |
977 uint8_t fFillType; | 936 uint8_t fFillType; |
978 mutable uint8_t fConvexity; | 937 mutable uint8_t fConvexity; |
979 mutable uint8_t fDirection; | 938 mutable uint8_t fFirstDirection; // SkPathPriv::FirstDirection |
980 mutable SkBool8 fIsVolatile; | 939 mutable SkBool8 fIsVolatile; |
981 | 940 |
982 /** Resets all fields other than fPathRef to their initial 'empty' values. | 941 /** Resets all fields other than fPathRef to their initial 'empty' values. |
983 * Assumes the caller has already emptied fPathRef. | 942 * Assumes the caller has already emptied fPathRef. |
984 * On Android increments fGenerationID without reseting it. | 943 * On Android increments fGenerationID without reseting it. |
985 */ | 944 */ |
986 void resetFields(); | 945 void resetFields(); |
987 | 946 |
988 /** Sets all fields other than fPathRef to the values in 'that'. | 947 /** Sets all fields other than fPathRef to the values in 'that'. |
989 * Assumes the caller has already set fPathRef. | 948 * Assumes the caller has already set fPathRef. |
990 * Doesn't change fGenerationID or fSourcePath on Android. | 949 * Doesn't change fGenerationID or fSourcePath on Android. |
991 */ | 950 */ |
992 void copyFields(const SkPath& that); | 951 void copyFields(const SkPath& that); |
993 | 952 |
994 friend class Iter; | 953 friend class Iter; |
995 | 954 friend class SkPathPriv; |
996 friend class SkPathStroker; | 955 friend class SkPathStroker; |
997 | 956 |
998 /* Append, in reverse order, the first contour of path, ignoring path's | 957 /* Append, in reverse order, the first contour of path, ignoring path's |
999 last point. If no moveTo() call has been made for this contour, the | 958 last point. If no moveTo() call has been made for this contour, the |
1000 first point is automatically set to (0,0). | 959 first point is automatically set to (0,0). |
1001 */ | 960 */ |
1002 void reversePathTo(const SkPath&); | 961 void reversePathTo(const SkPath&); |
1003 | 962 |
1004 // called before we add points for lineTo, quadTo, cubicTo, checking to see | 963 // called before we add points for lineTo, quadTo, cubicTo, checking to see |
1005 // if we need to inject a leading moveTo first | 964 // if we need to inject a leading moveTo first |
(...skipping 29 matching lines...) Expand all Loading... |
1035 void setPt(int index, SkScalar x, SkScalar y); | 994 void setPt(int index, SkScalar x, SkScalar y); |
1036 | 995 |
1037 friend class SkAutoPathBoundsUpdate; | 996 friend class SkAutoPathBoundsUpdate; |
1038 friend class SkAutoDisableOvalCheck; | 997 friend class SkAutoDisableOvalCheck; |
1039 friend class SkAutoDisableDirectionCheck; | 998 friend class SkAutoDisableDirectionCheck; |
1040 friend class SkBench_AddPathTest; // perf test reversePathTo | 999 friend class SkBench_AddPathTest; // perf test reversePathTo |
1041 friend class PathTest_Private; // unit test reversePathTo | 1000 friend class PathTest_Private; // unit test reversePathTo |
1042 }; | 1001 }; |
1043 | 1002 |
1044 #endif | 1003 #endif |
OLD | NEW |