| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
| 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 #ifndef SkPathOps_DEFINED | 7 #ifndef SkPathOps_DEFINED |
| 8 #define SkPathOps_DEFINED | 8 #define SkPathOps_DEFINED |
| 9 | 9 |
| 10 #include "SkPreConfig.h" | 10 #include "SkPreConfig.h" |
| 11 #include "SkTArray.h" |
| 12 #include "SkTDArray.h" |
| 11 | 13 |
| 12 class SkPath; | 14 class SkPath; |
| 13 struct SkRect; | 15 struct SkRect; |
| 14 | 16 |
| 15 // FIXME: move everything below into the SkPath class | 17 // FIXME: move everything below into the SkPath class |
| 16 /** | 18 /** |
| 17 * The logical operations that can be performed when combining two paths. | 19 * The logical operations that can be performed when combining two paths. |
| 18 */ | 20 */ |
| 19 enum SkPathOp { | 21 enum SkPathOp { |
| 20 kDifference_PathOp, //!< subtract the op path from the first path | 22 kDifference_SkPathOp, //!< subtract the op path from the first path |
| 21 kIntersect_PathOp, //!< intersect the two paths | 23 kIntersect_SkPathOp, //!< intersect the two paths |
| 22 kUnion_PathOp, //!< union (inclusive-or) the two paths | 24 kUnion_SkPathOp, //!< union (inclusive-or) the two paths |
| 23 kXOR_PathOp, //!< exclusive-or the two paths | 25 kXOR_SkPathOp, //!< exclusive-or the two paths |
| 24 kReverseDifference_PathOp, //!< subtract the first path from the op path | 26 kReverseDifference_SkPathOp, //!< subtract the first path from the op path |
| 25 }; | 27 }; |
| 26 | 28 |
| 27 /** Set this path to the result of applying the Op to this path and the | 29 /** Set this path to the result of applying the Op to this path and the |
| 28 specified path: this = (this op operand). | 30 specified path: this = (this op operand). |
| 29 The resulting path will be constructed from non-overlapping contours. | 31 The resulting path will be constructed from non-overlapping contours. |
| 30 The curve order is reduced where possible so that cubics may be turned | 32 The curve order is reduced where possible so that cubics may be turned |
| 31 into quadratics, and quadratics maybe turned into lines. | 33 into quadratics, and quadratics maybe turned into lines. |
| 32 | 34 |
| 33 Returns true if operation was able to produce a result; | 35 Returns true if operation was able to produce a result; |
| 34 otherwise, result is unmodified. | 36 otherwise, result is unmodified. |
| 35 | 37 |
| 36 @param one The first operand (for difference, the minuend) | 38 @param one The first operand (for difference, the minuend) |
| 37 @param two The second operand (for difference, the subtrahend) | 39 @param two The second operand (for difference, the subtrahend) |
| 40 @param op The operator to apply. |
| 38 @param result The product of the operands. The result may be one of the | 41 @param result The product of the operands. The result may be one of the |
| 39 inputs. | 42 inputs. |
| 40 @return True if operation succeeded. | 43 @return True if the operation succeeded. |
| 41 */ | 44 */ |
| 42 bool SK_API Op(const SkPath& one, const SkPath& two, SkPathOp op, SkPath* result
); | 45 bool SK_API Op(const SkPath& one, const SkPath& two, SkPathOp op, SkPath* result
); |
| 43 | 46 |
| 44 /** Set this path to a set of non-overlapping contours that describe the | 47 /** Set this path to a set of non-overlapping contours that describe the |
| 45 same area as the original path. | 48 same area as the original path. |
| 46 The curve order is reduced where possible so that cubics may | 49 The curve order is reduced where possible so that cubics may |
| 47 be turned into quadratics, and quadratics maybe turned into lines. | 50 be turned into quadratics, and quadratics maybe turned into lines. |
| 48 | 51 |
| 49 Returns true if operation was able to produce a result; | 52 Returns true if operation was able to produce a result; |
| 50 otherwise, result is unmodified. | 53 otherwise, result is unmodified. |
| 51 | 54 |
| 52 @param path The path to simplify. | 55 @param path The path to simplify. |
| 53 @param result The simplified path. The result may be the input. | 56 @param result The simplified path. The result may be the input. |
| 54 @return True if simplification succeeded. | 57 @return True if simplification succeeded. |
| 55 */ | 58 */ |
| 56 bool SK_API Simplify(const SkPath& path, SkPath* result); | 59 bool SK_API Simplify(const SkPath& path, SkPath* result); |
| 57 | 60 |
| 58 /** Set the resulting rectangle to the tight bounds of the path. | 61 /** Set the resulting rectangle to the tight bounds of the path. |
| 59 | 62 |
| 60 @param path The path measured. | 63 @param path The path measured. |
| 61 @param result The tight bounds of the path. | 64 @param result The tight bounds of the path. |
| 62 @return True if the bounds could be computed. | 65 @return True if the bounds could be computed. |
| 63 */ | 66 */ |
| 64 bool SK_API TightBounds(const SkPath& path, SkRect* result); | 67 bool SK_API TightBounds(const SkPath& path, SkRect* result); |
| 65 | 68 |
| 69 /** Perform a series of path operations, optimized for unioning many paths toget
her. |
| 70 */ |
| 71 class SK_API SkOpBuilder { |
| 72 public: |
| 73 /** Add one or more paths and their operand. The builder is empty before the
first |
| 74 path is added, so the result of a single add is (emptyPath OP path). |
| 75 |
| 76 @param path The second operand. |
| 77 @param _operator The operator to apply to the existing and supplied path
s. |
| 78 */ |
| 79 void add(const SkPath& path, SkPathOp _operator); |
| 80 |
| 81 /** Computes the sum of all paths and operands, and resets the builder to it
s |
| 82 initial state. |
| 83 |
| 84 @param result The product of the operands. |
| 85 @return True if the operation succeeded. |
| 86 */ |
| 87 bool resolve(SkPath* result); |
| 88 |
| 89 private: |
| 90 SkTArray<SkPath> fPathRefs; |
| 91 SkTDArray<SkPathOp> fOps; |
| 92 |
| 93 void reset(); |
| 94 }; |
| 95 |
| 66 #endif | 96 #endif |
| OLD | NEW |