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