Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Side by Side Diff: include/core/SkPath.h

Issue 16195004: add asserts to point<-->verb helpers (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « include/core/SkGeometry.h ('k') | src/core/SkEdgeBuilder.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #ifndef SkPath_DEFINED 10 #ifndef SkPath_DEFINED
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 this contour, to specify the control point of a quadratic curve 406 this contour, to specify the control point of a quadratic curve
407 @param dy1 The amount to add to the y-coordinate of the last point on 407 @param dy1 The amount to add to the y-coordinate of the last point on
408 this contour, to specify the control point of a quadratic curve 408 this contour, to specify the control point of a quadratic curve
409 @param dx2 The amount to add to the x-coordinate of the last point on 409 @param dx2 The amount to add to the x-coordinate of the last point on
410 this contour, to specify the end point of a quadratic curve 410 this contour, to specify the end point of a quadratic curve
411 @param dy2 The amount to add to the y-coordinate of the last point on 411 @param dy2 The amount to add to the y-coordinate of the last point on
412 this contour, to specify the end point of a quadratic curve 412 this contour, to specify the end point of a quadratic curve
413 */ 413 */
414 void rQuadTo(SkScalar dx1, SkScalar dy1, SkScalar dx2, SkScalar dy2); 414 void rQuadTo(SkScalar dx1, SkScalar dy1, SkScalar dx2, SkScalar dy2);
415 415
416 void conicTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2,
417 SkScalar w);
418 void conicTo(const SkPoint& p1, const SkPoint& p2, SkScalar w) {
419 this->conicTo(p1.fX, p1.fY, p2.fX, p2.fY, w);
420 }
421 void rConicTo(SkScalar dx1, SkScalar dy1, SkScalar dx2, SkScalar dy2,
422 SkScalar w);
423
416 /** Add a cubic bezier from the last point, approaching control points 424 /** Add a cubic bezier from the last point, approaching control points
417 (x1,y1) and (x2,y2), and ending at (x3,y3). If no moveTo() call has been 425 (x1,y1) and (x2,y2), and ending at (x3,y3). If no moveTo() call has been
418 made for this contour, the first point is automatically set to (0,0). 426 made for this contour, the first point is automatically set to (0,0).
419 427
420 @param x1 The x-coordinate of the 1st control point on a cubic curve 428 @param x1 The x-coordinate of the 1st control point on a cubic curve
421 @param y1 The y-coordinate of the 1st control point on a cubic curve 429 @param y1 The y-coordinate of the 1st control point on a cubic curve
422 @param x2 The x-coordinate of the 2nd control point on a cubic curve 430 @param x2 The x-coordinate of the 2nd control point on a cubic curve
423 @param y2 The y-coordinate of the 2nd control point on a cubic curve 431 @param y2 The y-coordinate of the 2nd control point on a cubic curve
424 @param x3 The x-coordinate of the end point on a cubic curve 432 @param x3 The x-coordinate of the end point on a cubic curve
425 @param y3 The y-coordinate of the end point on a cubic curve 433 @param y3 The y-coordinate of the end point on a cubic curve
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 780
773 @param p The new location for the last point 781 @param p The new location for the last point
774 */ 782 */
775 void setLastPt(const SkPoint& p) { 783 void setLastPt(const SkPoint& p) {
776 this->setLastPt(p.fX, p.fY); 784 this->setLastPt(p.fX, p.fY);
777 } 785 }
778 786
779 enum SegmentMask { 787 enum SegmentMask {
780 kLine_SegmentMask = 1 << 0, 788 kLine_SegmentMask = 1 << 0,
781 kQuad_SegmentMask = 1 << 1, 789 kQuad_SegmentMask = 1 << 1,
782 kCubic_SegmentMask = 1 << 2 790 kConic_SegmentMask = 1 << 2,
791 kCubic_SegmentMask = 1 << 3,
783 }; 792 };
784 793
785 /** 794 /**
786 * Returns a mask, where each bit corresponding to a SegmentMask is 795 * Returns a mask, where each bit corresponding to a SegmentMask is
787 * set if the path contains 1 or more segments of that type. 796 * set if the path contains 1 or more segments of that type.
788 * Returns 0 for an empty path (no segments). 797 * Returns 0 for an empty path (no segments).
789 */ 798 */
790 uint32_t getSegmentMasks() const { return fSegmentMask; } 799 uint32_t getSegmentMasks() const { return fSegmentMask; }
791 800
792 enum Verb { 801 enum Verb {
793 kMove_Verb, //!< iter.next returns 1 point 802 kMove_Verb, //!< iter.next returns 1 point
794 kLine_Verb, //!< iter.next returns 2 points 803 kLine_Verb, //!< iter.next returns 2 points
795 kQuad_Verb, //!< iter.next returns 3 points 804 kQuad_Verb, //!< iter.next returns 3 points
805 kConic_Verb, //!< iter.next returns 3 points + iter.conicWeight()
796 kCubic_Verb, //!< iter.next returns 4 points 806 kCubic_Verb, //!< iter.next returns 4 points
797 kClose_Verb, //!< iter.next returns 1 point (contour's moveTo pt) 807 kClose_Verb, //!< iter.next returns 1 point (contour's moveTo pt)
798 kDone_Verb //!< iter.next returns 0 points 808 kDone_Verb, //!< iter.next returns 0 points
799 }; 809 };
800 810
801 /** Iterate through all of the segments (lines, quadratics, cubics) of 811 /** Iterate through all of the segments (lines, quadratics, cubics) of
802 each contours in a path. 812 each contours in a path.
803 813
804 The iterator cleans up the segments along the way, removing degenerate 814 The iterator cleans up the segments along the way, removing degenerate
805 segments and adding close verbs where necessary. When the forceClose 815 segments and adding close verbs where necessary. When the forceClose
806 argument is provided, each contour (as defined by a new starting 816 argument is provided, each contour (as defined by a new starting
807 move command) will be completed with a close verb regardless of the 817 move command) will be completed with a close verb regardless of the
808 contour's contents. 818 contour's contents.
(...skipping 13 matching lines...) Expand all
822 deemed degenerate (too short) and skip those. 832 deemed degenerate (too short) and skip those.
823 @return The verb for the current segment 833 @return The verb for the current segment
824 */ 834 */
825 Verb next(SkPoint pts[4], bool doConsumeDegerates = true) { 835 Verb next(SkPoint pts[4], bool doConsumeDegerates = true) {
826 if (doConsumeDegerates) { 836 if (doConsumeDegerates) {
827 this->consumeDegenerateSegments(); 837 this->consumeDegenerateSegments();
828 } 838 }
829 return this->doNext(pts); 839 return this->doNext(pts);
830 } 840 }
831 841
842 /**
843 * Return the weight for the current conic. Only valid if the current
844 * segment return by next() was a conic.
845 */
846 SkScalar conicWeight() const { return *fConicWeights; }
847
832 /** If next() returns kLine_Verb, then this query returns true if the 848 /** If next() returns kLine_Verb, then this query returns true if the
833 line was the result of a close() command (i.e. the end point is the 849 line was the result of a close() command (i.e. the end point is the
834 initial moveto for this contour). If next() returned a different 850 initial moveto for this contour). If next() returned a different
835 verb, this returns an undefined value. 851 verb, this returns an undefined value.
836 852
837 @return If the last call to next() returned kLine_Verb, return true 853 @return If the last call to next() returned kLine_Verb, return true
838 if it was the result of an explicit close command. 854 if it was the result of an explicit close command.
839 */ 855 */
840 bool isCloseLine() const { return SkToBool(fCloseLine); } 856 bool isCloseLine() const { return SkToBool(fCloseLine); }
841 857
842 /** Returns true if the current contour is closed (has a kClose_Verb) 858 /** Returns true if the current contour is closed (has a kClose_Verb)
843 @return true if the current contour is closed (has a kClose_Verb) 859 @return true if the current contour is closed (has a kClose_Verb)
844 */ 860 */
845 bool isClosedContour() const; 861 bool isClosedContour() const;
846 862
847 private: 863 private:
848 const SkPoint* fPts; 864 const SkPoint* fPts;
849 const uint8_t* fVerbs; 865 const uint8_t* fVerbs;
850 const uint8_t* fVerbStop; 866 const uint8_t* fVerbStop;
867 const SkScalar* fConicWeights;
851 SkPoint fMoveTo; 868 SkPoint fMoveTo;
852 SkPoint fLastPt; 869 SkPoint fLastPt;
853 SkBool8 fForceClose; 870 SkBool8 fForceClose;
854 SkBool8 fNeedClose; 871 SkBool8 fNeedClose;
855 SkBool8 fCloseLine; 872 SkBool8 fCloseLine;
856 SkBool8 fSegmentState; 873 SkBool8 fSegmentState;
857 874
858 inline const SkPoint& cons_moveTo(); 875 inline const SkPoint& cons_moveTo();
859 Verb autoClose(SkPoint pts[2]); 876 Verb autoClose(SkPoint pts[2]);
860 void consumeDegenerateSegments(); 877 void consumeDegenerateSegments();
(...skipping 11 matching lines...) Expand all
872 889
873 /** Return the next verb in this iteration of the path. When all 890 /** Return the next verb in this iteration of the path. When all
874 segments have been visited, return kDone_Verb. 891 segments have been visited, return kDone_Verb.
875 892
876 @param pts The points representing the current verb and/or segment 893 @param pts The points representing the current verb and/or segment
877 This must not be NULL. 894 This must not be NULL.
878 @return The verb for the current segment 895 @return The verb for the current segment
879 */ 896 */
880 Verb next(SkPoint pts[4]); 897 Verb next(SkPoint pts[4]);
881 898
899 SkScalar conicWeight() const { return *fConicWeights; }
900
882 private: 901 private:
883 const SkPoint* fPts; 902 const SkPoint* fPts;
884 const uint8_t* fVerbs; 903 const uint8_t* fVerbs;
885 const uint8_t* fVerbStop; 904 const uint8_t* fVerbStop;
905 const SkScalar* fConicWeights;
886 SkPoint fMoveTo; 906 SkPoint fMoveTo;
887 SkPoint fLastPt; 907 SkPoint fLastPt;
888 }; 908 };
889 909
890 /** 910 /**
891 * Returns true if the point { x, y } is contained by the path, taking into 911 * Returns true if the point { x, y } is contained by the path, taking into
892 * account the FillType. 912 * account the FillType.
893 */ 913 */
894 bool contains(SkScalar x, SkScalar y) const; 914 bool contains(SkScalar x, SkScalar y) const;
895 915
(...skipping 19 matching lines...) Expand all
915 935
916 SkDEBUGCODE(void validate() const;) 936 SkDEBUGCODE(void validate() const;)
917 937
918 private: 938 private:
919 enum SerializationOffsets { 939 enum SerializationOffsets {
920 kDirection_SerializationShift = 26, // requires 2 bits 940 kDirection_SerializationShift = 26, // requires 2 bits
921 kIsFinite_SerializationShift = 25, // requires 1 bit 941 kIsFinite_SerializationShift = 25, // requires 1 bit
922 kIsOval_SerializationShift = 24, // requires 1 bit 942 kIsOval_SerializationShift = 24, // requires 1 bit
923 kConvexity_SerializationShift = 16, // requires 2 bits 943 kConvexity_SerializationShift = 16, // requires 2 bits
924 kFillType_SerializationShift = 8, // requires 2 bits 944 kFillType_SerializationShift = 8, // requires 2 bits
925 kSegmentMask_SerializationShift = 0 // requires 3 bits 945 kSegmentMask_SerializationShift = 0 // requires 4 bits
926 }; 946 };
927 947
928 #if SK_DEBUG_PATH_REF 948 #if SK_DEBUG_PATH_REF
929 public: 949 public:
930 /** Debugging wrapper for SkAutoTUnref<SkPathRef> used to track owners (SkPa ths) 950 /** Debugging wrapper for SkAutoTUnref<SkPathRef> used to track owners (SkPa ths)
931 of SkPathRefs */ 951 of SkPathRefs */
932 class PathRefDebugRef { 952 class PathRefDebugRef {
933 public: 953 public:
934 PathRefDebugRef(SkPath* owner); 954 PathRefDebugRef(SkPath* owner);
935 PathRefDebugRef(SkPathRef* pr, SkPath* owner); 955 PathRefDebugRef(SkPathRef* pr, SkPath* owner);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
997 bool isRectContour(bool allowPartial, int* currVerb, const SkPoint** pts, 1017 bool isRectContour(bool allowPartial, int* currVerb, const SkPoint** pts,
998 bool* isClosed, Direction* direction) const; 1018 bool* isClosed, Direction* direction) const;
999 1019
1000 friend class SkAutoPathBoundsUpdate; 1020 friend class SkAutoPathBoundsUpdate;
1001 friend class SkAutoDisableOvalCheck; 1021 friend class SkAutoDisableOvalCheck;
1002 friend class SkAutoDisableDirectionCheck; 1022 friend class SkAutoDisableDirectionCheck;
1003 friend class SkBench_AddPathTest; // perf test pathTo/reversePathTo 1023 friend class SkBench_AddPathTest; // perf test pathTo/reversePathTo
1004 }; 1024 };
1005 1025
1006 #endif 1026 #endif
OLDNEW
« no previous file with comments | « include/core/SkGeometry.h ('k') | src/core/SkEdgeBuilder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698