OLD | NEW |
---|---|
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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
180 /** Returns true if the path is empty (contains no lines or curves) | 180 /** Returns true if the path is empty (contains no lines or curves) |
181 | 181 |
182 @return true if the path is empty (contains no lines or curves) | 182 @return true if the path is empty (contains no lines or curves) |
183 */ | 183 */ |
184 bool isEmpty() const; | 184 bool isEmpty() const; |
185 | 185 |
186 /** | 186 /** |
187 * Returns true if all of the points in this path are finite, meaning there | 187 * Returns true if all of the points in this path are finite, meaning there |
188 * are no infinities and no NaNs. | 188 * are no infinities and no NaNs. |
189 */ | 189 */ |
190 bool isFinite() const { | 190 bool isFinite() const; |
191 if (fBoundsIsDirty) { | |
192 this->computeBounds(); | |
193 } | |
194 return SkToBool(fIsFinite); | |
195 } | |
196 | 191 |
197 /** Test a line for zero length | 192 /** Test a line for zero length |
198 | 193 |
199 @return true if the line is of zero length; otherwise false. | 194 @return true if the line is of zero length; otherwise false. |
200 */ | 195 */ |
201 static bool IsLineDegenerate(const SkPoint& p1, const SkPoint& p2) { | 196 static bool IsLineDegenerate(const SkPoint& p1, const SkPoint& p2) { |
202 return p1.equalsWithinTolerance(p2); | 197 return p1.equalsWithinTolerance(p2); |
203 } | 198 } |
204 | 199 |
205 /** Test a quad for zero length | 200 /** Test a quad for zero length |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
273 int getVerbs(uint8_t verbs[], int max) const; | 268 int getVerbs(uint8_t verbs[], int max) const; |
274 | 269 |
275 //! Swap contents of this and other. Guaranteed not to throw | 270 //! Swap contents of this and other. Guaranteed not to throw |
276 void swap(SkPath& other); | 271 void swap(SkPath& other); |
277 | 272 |
278 /** Returns the bounds of the path's points. If the path contains 0 or 1 | 273 /** Returns the bounds of the path's points. If the path contains 0 or 1 |
279 points, the bounds is set to (0,0,0,0), and isEmpty() will return true. | 274 points, the bounds is set to (0,0,0,0), and isEmpty() will return true. |
280 Note: this bounds may be larger than the actual shape, since curves | 275 Note: this bounds may be larger than the actual shape, since curves |
281 do not extend as far as their control points. | 276 do not extend as far as their control points. |
282 */ | 277 */ |
283 const SkRect& getBounds() const { | 278 const SkRect& getBounds() const; |
284 if (fBoundsIsDirty) { | |
285 this->computeBounds(); | |
286 } | |
287 return fBounds; | |
288 } | |
289 | 279 |
290 /** Calling this will, if the internal cache of the bounds is out of date, | 280 /** Calling this will, if the internal cache of the bounds is out of date, |
291 update it so that subsequent calls to getBounds will be instantaneous. | 281 update it so that subsequent calls to getBounds will be instantaneous. |
292 This also means that any copies or simple transformations of the path | 282 This also means that any copies or simple transformations of the path |
293 will inherit the cached bounds. | 283 will inherit the cached bounds. |
294 */ | 284 */ |
295 void updateBoundsCache() const { | 285 void updateBoundsCache() const { |
296 // for now, just calling getBounds() is sufficient | 286 // for now, just calling getBounds() is sufficient |
297 this->getBounds(); | 287 this->getBounds(); |
298 } | 288 } |
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
925 #ifdef SK_BUILD_FOR_ANDROID | 915 #ifdef SK_BUILD_FOR_ANDROID |
926 uint32_t getGenerationID() const; | 916 uint32_t getGenerationID() const; |
927 const SkPath* getSourcePath() const; | 917 const SkPath* getSourcePath() const; |
928 void setSourcePath(const SkPath* path); | 918 void setSourcePath(const SkPath* path); |
929 #endif | 919 #endif |
930 | 920 |
931 SkDEBUGCODE(void validate() const;) | 921 SkDEBUGCODE(void validate() const;) |
932 | 922 |
933 private: | 923 private: |
934 enum SerializationOffsets { | 924 enum SerializationOffsets { |
925 #ifndef DELETE_THIS_CODE_WHEN_SKPS_ARE_REBUILT_AT_V14_AND_ALL_OTHER_INSTANCES_TO O | |
926 kNewFormat_SerializationShift = 28, // requires 1 bit | |
927 #endif | |
935 kDirection_SerializationShift = 26, // requires 2 bits | 928 kDirection_SerializationShift = 26, // requires 2 bits |
936 kIsFinite_SerializationShift = 25, // requires 1 bit | 929 #ifndef DELETE_THIS_CODE_WHEN_SKPS_ARE_REBUILT_AT_V14_AND_ALL_OTHER_INSTANCES_TO O |
930 // rename to kUnused_SerializationShift | |
931 kOldIsFinite_SerializationShift = 25, // 1 bit | |
932 #endif | |
937 kIsOval_SerializationShift = 24, // requires 1 bit | 933 kIsOval_SerializationShift = 24, // requires 1 bit |
938 kConvexity_SerializationShift = 16, // requires 2 bits | 934 kConvexity_SerializationShift = 16, // requires 8 bits |
939 kFillType_SerializationShift = 8, // requires 2 bits | 935 kFillType_SerializationShift = 8, // requires 8 bits |
940 kSegmentMask_SerializationShift = 0 // requires 4 bits | 936 kSegmentMask_SerializationShift = 0 // requires 4 bits |
941 }; | 937 }; |
942 | 938 |
943 SkAutoTUnref<SkPathRef> fPathRef; | 939 SkAutoTUnref<SkPathRef> fPathRef; |
944 | 940 |
945 mutable SkRect fBounds; | |
946 int fLastMoveToIndex; | 941 int fLastMoveToIndex; |
947 uint8_t fFillType; | 942 uint8_t fFillType; |
948 uint8_t fSegmentMask; | 943 uint8_t fSegmentMask; |
949 mutable uint8_t fBoundsIsDirty; | |
950 mutable uint8_t fConvexity; | 944 mutable uint8_t fConvexity; |
951 mutable uint8_t fDirection; | 945 mutable uint8_t fDirection; |
952 mutable SkBool8 fIsFinite; // only meaningful if bounds are valid | |
953 mutable SkBool8 fIsOval; | 946 mutable SkBool8 fIsOval; |
954 #ifdef SK_BUILD_FOR_ANDROID | 947 #ifdef SK_BUILD_FOR_ANDROID |
955 uint32_t fGenerationID; | 948 uint32_t fGenerationID; |
956 const SkPath* fSourcePath; | 949 const SkPath* fSourcePath; |
957 #endif | 950 #endif |
958 | 951 |
959 /** Resets all fields other than fPathRef to their initial 'empty' values. | 952 /** Resets all fields other than fPathRef to their initial 'empty' values. |
960 * Assumes the caller has already emptied fPathRef. | 953 * Assumes the caller has already emptied fPathRef. |
961 * On Android increments fGenerationID without reseting it. | 954 * On Android increments fGenerationID without reseting it. |
962 */ | 955 */ |
963 void resetFields(); | 956 void resetFields(); |
964 | 957 |
965 /** Sets all fields other than fPathRef to the values in 'that'. | 958 /** Sets all fields other than fPathRef to the values in 'that'. |
966 * Assumes the caller has already set fPathRef. | 959 * Assumes the caller has already set fPathRef. |
967 * Doesn't change fGenerationID or fSourcePath on Android. | 960 * Doesn't change fGenerationID or fSourcePath on Android. |
968 */ | 961 */ |
969 void copyFields(const SkPath& that); | 962 void copyFields(const SkPath& that); |
970 | 963 |
971 // called, if dirty, by getBounds() | |
972 void computeBounds() const; | |
973 | |
974 friend class Iter; | 964 friend class Iter; |
975 | 965 |
976 friend class SkPathStroker; | 966 friend class SkPathStroker; |
977 /* Append the first contour of path, ignoring path's initial point. If no | 967 /* Append the first contour of path, ignoring path's initial point. If no |
978 moveTo() call has been made for this contour, the first point is | 968 moveTo() call has been made for this contour, the first point is |
979 automatically set to (0,0). | 969 automatically set to (0,0). |
980 */ | 970 */ |
981 void pathTo(const SkPath& path); | 971 void pathTo(const SkPath& path); |
982 | 972 |
983 /* Append, in reverse order, the first contour of path, ignoring path's | 973 /* Append, in reverse order, the first contour of path, ignoring path's |
(...skipping 10 matching lines...) Expand all Loading... | |
994 // | 984 // |
995 inline void injectMoveToIfNeeded(); | 985 inline void injectMoveToIfNeeded(); |
996 | 986 |
997 inline bool hasOnlyMoveTos() const; | 987 inline bool hasOnlyMoveTos() const; |
998 | 988 |
999 Convexity internalGetConvexity() const; | 989 Convexity internalGetConvexity() const; |
1000 | 990 |
1001 bool isRectContour(bool allowPartial, int* currVerb, const SkPoint** pts, | 991 bool isRectContour(bool allowPartial, int* currVerb, const SkPoint** pts, |
1002 bool* isClosed, Direction* direction) const; | 992 bool* isClosed, Direction* direction) const; |
1003 | 993 |
994 /** Returns if the path can return a bound at no cost (true) or will have to | |
995 perform some computation (false). | |
996 */ | |
997 bool hasComputedBounds() const; | |
998 | |
999 // 'rect' needs to be sorted | |
1000 void setBounds(const SkRect& rect); | |
bsalomon
2013/09/23 18:39:39
Eek... I didn't realize we let clients set the bou
robertphillips
2013/09/23 18:56:42
This is only used in SkAutoPathBoundsUpdate to avo
| |
1001 | |
1002 #ifndef DELETE_THIS_CODE_WHEN_SKPS_ARE_REBUILT_AT_V14_AND_ALL_OTHER_INSTANCES_TO O | |
1003 friend class SkPathRef; // just for SerializationOffsets | |
1004 #endif | |
1004 friend class SkAutoPathBoundsUpdate; | 1005 friend class SkAutoPathBoundsUpdate; |
1005 friend class SkAutoDisableOvalCheck; | 1006 friend class SkAutoDisableOvalCheck; |
1006 friend class SkAutoDisableDirectionCheck; | 1007 friend class SkAutoDisableDirectionCheck; |
1007 friend class SkBench_AddPathTest; // perf test pathTo/reversePathTo | 1008 friend class SkBench_AddPathTest; // perf test pathTo/reversePathTo |
1008 }; | 1009 }; |
1009 | 1010 |
1010 #endif | 1011 #endif |
OLD | NEW |