robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +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 | |
| 8 | #ifndef SkRRect_DEFINED |
| 9 | #define SkRRect_DEFINED |
| 10 | |
| 11 | #include "SkRect.h" |
| 12 | #include "SkPoint.h" |
| 13 | |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 14 | class SkPath; |
scroggo@google.com | 20e3cd2 | 2013-11-05 15:54:42 +0000 | [diff] [blame] | 15 | class SkMatrix; |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 16 | |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 17 | // Path forward: |
| 18 | // core work |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 19 | // add contains(SkRect&) - for clip stack |
| 20 | // add contains(SkRRect&) - for clip stack |
| 21 | // add heart rect computation (max rect inside RR) |
| 22 | // add 9patch rect computation |
| 23 | // add growToInclude(SkPath&) |
| 24 | // analysis |
| 25 | // use growToInclude to fit skp round rects & generate stats (RRs vs. real paths) |
| 26 | // check on # of rectorus's the RRs could handle |
| 27 | // rendering work |
commit-bot@chromium.org | 14e50ae | 2014-02-16 23:35:31 +0000 | [diff] [blame] | 28 | // update SkPath.addRRect() to only use quads |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 29 | // add GM and bench |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 30 | // further out |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 31 | // detect and triangulate RRectorii rather than falling back to SW in Ganesh |
skia.committer@gmail.com | c3d7d90 | 2012-11-30 02:01:24 +0000 | [diff] [blame] | 32 | // |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 33 | |
| 34 | /** \class SkRRect |
| 35 | |
skia.committer@gmail.com | c3d7d90 | 2012-11-30 02:01:24 +0000 | [diff] [blame] | 36 | The SkRRect class represents a rounded rect with a potentially different |
| 37 | radii for each corner. It does not have a constructor so must be |
| 38 | initialized with one of the initialization functions (e.g., setEmpty, |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 39 | setRectRadii, etc.) |
| 40 | |
skia.committer@gmail.com | c3d7d90 | 2012-11-30 02:01:24 +0000 | [diff] [blame] | 41 | This class is intended to roughly match CSS' border-*-*-radius capabilities. |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 42 | This means: |
skia.committer@gmail.com | c3d7d90 | 2012-11-30 02:01:24 +0000 | [diff] [blame] | 43 | If either of a corner's radii are 0 the corner will be square. |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 44 | Negative radii are not allowed (they are clamped to zero). |
| 45 | If the corner curves overlap they will be proportionally reduced to fit. |
| 46 | */ |
| 47 | class SK_API SkRRect { |
| 48 | public: |
Brian Salomon | 0a241ce | 2017-12-15 11:31:05 -0500 | [diff] [blame] | 49 | /** Default initialized to a rrect at the origin with zero width and height. */ |
| 50 | SkRRect() = default; |
| 51 | |
Cary Clark | 1e447df | 2018-06-12 16:49:49 -0400 | [diff] [blame] | 52 | SkRRect(const SkRRect& rrect) = default; |
| 53 | SkRRect& operator=(const SkRRect& rrect) = default; |
bsalomon | 7f0d9f3 | 2016-08-15 14:49:10 -0700 | [diff] [blame] | 54 | |
skia.committer@gmail.com | c3d7d90 | 2012-11-30 02:01:24 +0000 | [diff] [blame] | 55 | /** |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 56 | * Enum to capture the various possible subtypes of RR. Accessed |
| 57 | * by type(). The subtypes become progressively less restrictive. |
| 58 | */ |
| 59 | enum Type { |
Brian Salomon | 0a241ce | 2017-12-15 11:31:05 -0500 | [diff] [blame] | 60 | // !< The RR has zero width and/or zero height. All radii are zero. |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 61 | kEmpty_Type, |
| 62 | |
| 63 | //!< The RR is actually a (non-empty) rect (i.e., at least one radius |
| 64 | //!< at each corner is zero) |
skia.committer@gmail.com | c3d7d90 | 2012-11-30 02:01:24 +0000 | [diff] [blame] | 65 | kRect_Type, |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 66 | |
skia.committer@gmail.com | c3d7d90 | 2012-11-30 02:01:24 +0000 | [diff] [blame] | 67 | //!< The RR is actually a (non-empty) oval (i.e., all x radii are equal |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 68 | //!< and >= width/2 and all the y radii are equal and >= height/2 |
skia.committer@gmail.com | c3d7d90 | 2012-11-30 02:01:24 +0000 | [diff] [blame] | 69 | kOval_Type, |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 70 | |
skia.committer@gmail.com | c3d7d90 | 2012-11-30 02:01:24 +0000 | [diff] [blame] | 71 | //!< The RR is non-empty and all the x radii are equal & all y radii |
| 72 | //!< are equal but it is not an oval (i.e., there are lines between |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 73 | //!< the curves) nor a rect (i.e., both radii are non-zero) |
skia.committer@gmail.com | c3d7d90 | 2012-11-30 02:01:24 +0000 | [diff] [blame] | 74 | kSimple_Type, |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 75 | |
commit-bot@chromium.org | f338d7c | 2014-03-17 21:17:30 +0000 | [diff] [blame] | 76 | //!< The RR is non-empty and the two left x radii are equal, the two top |
| 77 | //!< y radii are equal, and the same for the right and bottom but it is |
| 78 | //!< neither an rect, oval, nor a simple RR. It is called "nine patch" |
| 79 | //!< because the centers of the corner ellipses form an axis aligned |
| 80 | //!< rect with edges that divide the RR into an 9 rectangular patches: |
| 81 | //!< an interior patch, four edge patches, and four corner patches. |
| 82 | kNinePatch_Type, |
| 83 | |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 84 | //!< A fully general (non-empty) RR. Some of the x and/or y radii are |
| 85 | //!< different from the others and there must be one corner where |
| 86 | //!< both radii are non-zero. |
| 87 | kComplex_Type, |
Adrienne Walker | ba9741d | 2017-08-23 13:26:32 -0700 | [diff] [blame] | 88 | |
| 89 | kLastType = kComplex_Type, |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 90 | }; |
| 91 | |
skia.committer@gmail.com | c3d7d90 | 2012-11-30 02:01:24 +0000 | [diff] [blame] | 92 | /** |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 93 | * Returns the RR's sub type. |
| 94 | */ |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 95 | Type getType() const { |
Robert Phillips | 49da334 | 2016-09-23 14:23:22 -0400 | [diff] [blame] | 96 | SkASSERT(this->isValid()); |
reed | 727b8c1 | 2014-10-22 11:23:56 -0700 | [diff] [blame] | 97 | return static_cast<Type>(fType); |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 98 | } |
| 99 | |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 100 | Type type() const { return this->getType(); } |
| 101 | |
| 102 | inline bool isEmpty() const { return kEmpty_Type == this->getType(); } |
| 103 | inline bool isRect() const { return kRect_Type == this->getType(); } |
| 104 | inline bool isOval() const { return kOval_Type == this->getType(); } |
| 105 | inline bool isSimple() const { return kSimple_Type == this->getType(); } |
commit-bot@chromium.org | f338d7c | 2014-03-17 21:17:30 +0000 | [diff] [blame] | 106 | inline bool isNinePatch() const { return kNinePatch_Type == this->getType(); } |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 107 | inline bool isComplex() const { return kComplex_Type == this->getType(); } |
| 108 | |
mike@reedtribe.org | 3707164 | 2012-12-17 02:10:42 +0000 | [diff] [blame] | 109 | SkScalar width() const { return fRect.width(); } |
| 110 | SkScalar height() const { return fRect.height(); } |
| 111 | |
skia.committer@gmail.com | c3d7d90 | 2012-11-30 02:01:24 +0000 | [diff] [blame] | 112 | /** |
Mike Reed | 242135a | 2018-02-22 13:41:39 -0500 | [diff] [blame] | 113 | * kSimple means that all corners have the same x,y radii. This returns the top/left |
| 114 | * corner's radii as representative of all corners. If the RRect is kComplex, then |
| 115 | * this still returns that corner's radii, but it is not indicative of the other corners. |
| 116 | */ |
| 117 | SkVector getSimpleRadii() const { |
| 118 | return fRadii[0]; |
| 119 | } |
| 120 | |
| 121 | /** |
Brian Salomon | 0a241ce | 2017-12-15 11:31:05 -0500 | [diff] [blame] | 122 | * Same as default initialized - zero width and height at the origin. |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 123 | */ |
Brian Salomon | 0a241ce | 2017-12-15 11:31:05 -0500 | [diff] [blame] | 124 | void setEmpty() { *this = SkRRect(); } |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 125 | |
skia.committer@gmail.com | c3d7d90 | 2012-11-30 02:01:24 +0000 | [diff] [blame] | 126 | /** |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 127 | * Set this RR to match the supplied rect. All radii will be 0. |
| 128 | */ |
| 129 | void setRect(const SkRect& rect) { |
Brian Salomon | 0a241ce | 2017-12-15 11:31:05 -0500 | [diff] [blame] | 130 | if (!this->initializeRect(rect)) { |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 131 | return; |
| 132 | } |
| 133 | |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 134 | memset(fRadii, 0, sizeof(fRadii)); |
| 135 | fType = kRect_Type; |
| 136 | |
Robert Phillips | 49da334 | 2016-09-23 14:23:22 -0400 | [diff] [blame] | 137 | SkASSERT(this->isValid()); |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 138 | } |
| 139 | |
Brian Salomon | 0a241ce | 2017-12-15 11:31:05 -0500 | [diff] [blame] | 140 | /** Makes an empty rrect at the origin with zero width and height. */ |
| 141 | static SkRRect MakeEmpty() { return SkRRect(); } |
bsalomon | ee29564 | 2016-06-06 14:01:25 -0700 | [diff] [blame] | 142 | |
reed | 021f631 | 2015-08-09 19:41:13 -0700 | [diff] [blame] | 143 | static SkRRect MakeRect(const SkRect& r) { |
| 144 | SkRRect rr; |
| 145 | rr.setRect(r); |
| 146 | return rr; |
| 147 | } |
bsalomon | ee29564 | 2016-06-06 14:01:25 -0700 | [diff] [blame] | 148 | |
robertphillips | 30c4cae | 2015-09-15 10:20:55 -0700 | [diff] [blame] | 149 | static SkRRect MakeOval(const SkRect& oval) { |
| 150 | SkRRect rr; |
| 151 | rr.setOval(oval); |
| 152 | return rr; |
| 153 | } |
| 154 | |
bsalomon | 4a4f14b | 2015-12-09 10:17:35 -0800 | [diff] [blame] | 155 | static SkRRect MakeRectXY(const SkRect& rect, SkScalar xRad, SkScalar yRad) { |
| 156 | SkRRect rr; |
| 157 | rr.setRectXY(rect, xRad, yRad); |
| 158 | return rr; |
| 159 | } |
| 160 | |
skia.committer@gmail.com | c3d7d90 | 2012-11-30 02:01:24 +0000 | [diff] [blame] | 161 | /** |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 162 | * Set this RR to match the supplied oval. All x radii will equal half the |
| 163 | * width and all y radii will equal half the height. |
| 164 | */ |
| 165 | void setOval(const SkRect& oval) { |
Brian Salomon | 0a241ce | 2017-12-15 11:31:05 -0500 | [diff] [blame] | 166 | if (!this->initializeRect(oval)) { |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 167 | return; |
| 168 | } |
| 169 | |
robertphillips | 05302f8 | 2015-09-29 11:24:07 -0700 | [diff] [blame] | 170 | SkScalar xRad = SkScalarHalf(fRect.width()); |
| 171 | SkScalar yRad = SkScalarHalf(fRect.height()); |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 172 | |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 173 | for (int i = 0; i < 4; ++i) { |
| 174 | fRadii[i].set(xRad, yRad); |
| 175 | } |
| 176 | fType = kOval_Type; |
| 177 | |
Robert Phillips | 49da334 | 2016-09-23 14:23:22 -0400 | [diff] [blame] | 178 | SkASSERT(this->isValid()); |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 179 | } |
| 180 | |
skia.committer@gmail.com | c3d7d90 | 2012-11-30 02:01:24 +0000 | [diff] [blame] | 181 | /** |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 182 | * Initialize the RR with the same radii for all four corners. |
| 183 | */ |
| 184 | void setRectXY(const SkRect& rect, SkScalar xRad, SkScalar yRad); |
| 185 | |
skia.committer@gmail.com | c3d7d90 | 2012-11-30 02:01:24 +0000 | [diff] [blame] | 186 | /** |
commit-bot@chromium.org | f338d7c | 2014-03-17 21:17:30 +0000 | [diff] [blame] | 187 | * Initialize the rr with one radius per-side. |
| 188 | */ |
| 189 | void setNinePatch(const SkRect& rect, SkScalar leftRad, SkScalar topRad, |
| 190 | SkScalar rightRad, SkScalar bottomRad); |
| 191 | |
| 192 | /** |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 193 | * Initialize the RR with potentially different radii for all four corners. |
| 194 | */ |
| 195 | void setRectRadii(const SkRect& rect, const SkVector radii[4]); |
| 196 | |
skia.committer@gmail.com | c3d7d90 | 2012-11-30 02:01:24 +0000 | [diff] [blame] | 197 | // The radii are stored in UL, UR, LR, LL order. |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 198 | enum Corner { |
| 199 | kUpperLeft_Corner, |
| 200 | kUpperRight_Corner, |
| 201 | kLowerRight_Corner, |
Cary Clark | 1e447df | 2018-06-12 16:49:49 -0400 | [diff] [blame] | 202 | kLowerLeft_Corner, |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 203 | }; |
| 204 | |
| 205 | const SkRect& rect() const { return fRect; } |
Mike Reed | 242135a | 2018-02-22 13:41:39 -0500 | [diff] [blame] | 206 | SkVector radii(Corner corner) const { return fRadii[corner]; } |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 207 | const SkRect& getBounds() const { return fRect; } |
| 208 | |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 209 | friend bool operator==(const SkRRect& a, const SkRRect& b) { |
Cary Clark | df429f3 | 2017-11-08 11:44:31 -0500 | [diff] [blame] | 210 | return a.fRect == b.fRect && SkScalarsEqual(&a.fRadii[0].fX, &b.fRadii[0].fX, 8); |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | friend bool operator!=(const SkRRect& a, const SkRRect& b) { |
Cary Clark | df429f3 | 2017-11-08 11:44:31 -0500 | [diff] [blame] | 214 | return a.fRect != b.fRect || !SkScalarsEqual(&a.fRadii[0].fX, &b.fRadii[0].fX, 8); |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | /** |
mike@reedtribe.org | bcbef57 | 2012-12-23 23:11:21 +0000 | [diff] [blame] | 218 | * Call inset on the bounds, and adjust the radii to reflect what happens |
| 219 | * in stroking: If the corner is sharp (no curvature), leave it alone, |
| 220 | * otherwise we grow/shrink the radii by the amount of the inset. If a |
| 221 | * given radius becomes negative, it is pinned to 0. |
| 222 | * |
Brian Salomon | 0a241ce | 2017-12-15 11:31:05 -0500 | [diff] [blame] | 223 | * If the inset amount is larger than the width/height then the rrect collapses to |
| 224 | * a degenerate line or point. |
| 225 | * |
| 226 | * If the inset is sufficiently negative to cause the bounds to become infinite then |
| 227 | * the result is a default initialized rrect. |
| 228 | * |
mike@reedtribe.org | bcbef57 | 2012-12-23 23:11:21 +0000 | [diff] [blame] | 229 | * It is valid for dst == this. |
| 230 | */ |
mike@reedtribe.org | 3707164 | 2012-12-17 02:10:42 +0000 | [diff] [blame] | 231 | void inset(SkScalar dx, SkScalar dy, SkRRect* dst) const; |
mike@reedtribe.org | bcbef57 | 2012-12-23 23:11:21 +0000 | [diff] [blame] | 232 | |
mike@reedtribe.org | 3707164 | 2012-12-17 02:10:42 +0000 | [diff] [blame] | 233 | void inset(SkScalar dx, SkScalar dy) { |
| 234 | this->inset(dx, dy, this); |
| 235 | } |
mike@reedtribe.org | bcbef57 | 2012-12-23 23:11:21 +0000 | [diff] [blame] | 236 | |
| 237 | /** |
| 238 | * Call outset on the bounds, and adjust the radii to reflect what happens |
| 239 | * in stroking: If the corner is sharp (no curvature), leave it alone, |
| 240 | * otherwise we grow/shrink the radii by the amount of the inset. If a |
| 241 | * given radius becomes negative, it is pinned to 0. |
| 242 | * |
| 243 | * It is valid for dst == this. |
| 244 | */ |
mike@reedtribe.org | 3707164 | 2012-12-17 02:10:42 +0000 | [diff] [blame] | 245 | void outset(SkScalar dx, SkScalar dy, SkRRect* dst) const { |
| 246 | this->inset(-dx, -dy, dst); |
| 247 | } |
| 248 | void outset(SkScalar dx, SkScalar dy) { |
| 249 | this->inset(-dx, -dy, this); |
| 250 | } |
skia.committer@gmail.com | f1f66c0 | 2014-03-05 03:02:06 +0000 | [diff] [blame] | 251 | |
commit-bot@chromium.org | fbde87f | 2014-03-04 16:25:34 +0000 | [diff] [blame] | 252 | /** |
| 253 | * Translate the rrect by (dx, dy). |
| 254 | */ |
| 255 | void offset(SkScalar dx, SkScalar dy) { |
| 256 | fRect.offset(dx, dy); |
| 257 | } |
mike@reedtribe.org | 3707164 | 2012-12-17 02:10:42 +0000 | [diff] [blame] | 258 | |
bsalomon | 7f0d9f3 | 2016-08-15 14:49:10 -0700 | [diff] [blame] | 259 | SkRRect SK_WARN_UNUSED_RESULT makeOffset(SkScalar dx, SkScalar dy) const { |
| 260 | return SkRRect(fRect.makeOffset(dx, dy), fRadii, fType); |
| 261 | } |
| 262 | |
robertphillips@google.com | 32c1b66 | 2013-04-25 12:23:00 +0000 | [diff] [blame] | 263 | /** |
| 264 | * Returns true if 'rect' is wholy inside the RR, and both |
| 265 | * are not empty. |
| 266 | */ |
| 267 | bool contains(const SkRect& rect) const; |
| 268 | |
Robert Phillips | 49da334 | 2016-09-23 14:23:22 -0400 | [diff] [blame] | 269 | bool isValid() const; |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 270 | |
Cary Clark | d98f78c | 2018-04-26 08:32:37 -0400 | [diff] [blame] | 271 | static constexpr size_t kSizeInMemory = 12 * sizeof(SkScalar); |
skia.committer@gmail.com | 306ab9d | 2012-12-13 02:01:33 +0000 | [diff] [blame] | 272 | |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 273 | /** |
| 274 | * Write the rrect into the specified buffer. This is guaranteed to always |
| 275 | * write kSizeInMemory bytes, and that value is guaranteed to always be |
| 276 | * a multiple of 4. Return kSizeInMemory. |
| 277 | */ |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 278 | size_t writeToMemory(void* buffer) const; |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 279 | |
| 280 | /** |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 281 | * Reads the rrect from the specified buffer |
| 282 | * |
| 283 | * If the specified buffer is large enough, this will read kSizeInMemory bytes, |
| 284 | * and that value is guaranteed to always be a multiple of 4. |
| 285 | * |
| 286 | * @param buffer Memory to read from |
| 287 | * @param length Amount of memory available in the buffer |
| 288 | * @return number of bytes read (must be a multiple of 4) or |
| 289 | * 0 if there was not enough memory available |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 290 | */ |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 291 | size_t readFromMemory(const void* buffer, size_t length); |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 292 | |
scroggo@google.com | 20e3cd2 | 2013-11-05 15:54:42 +0000 | [diff] [blame] | 293 | /** |
| 294 | * Transform by the specified matrix, and put the result in dst. |
| 295 | * |
| 296 | * @param matrix SkMatrix specifying the transform. Must only contain |
| 297 | * scale and/or translate, or this call will fail. |
| 298 | * @param dst SkRRect to store the result. It is an error to use this, |
| 299 | * which would make this function no longer const. |
Mike Klein | 20d479c | 2017-10-11 17:13:28 -0400 | [diff] [blame] | 300 | * @return true on success, false on failure. |
scroggo@google.com | 20e3cd2 | 2013-11-05 15:54:42 +0000 | [diff] [blame] | 301 | */ |
| 302 | bool transform(const SkMatrix& matrix, SkRRect* dst) const; |
| 303 | |
reed | e05fed0 | 2014-12-15 07:59:53 -0800 | [diff] [blame] | 304 | void dump(bool asHex) const; |
| 305 | void dump() const { this->dump(false); } |
| 306 | void dumpHex() const { this->dump(true); } |
bsalomon | b6b0252 | 2014-06-09 07:59:06 -0700 | [diff] [blame] | 307 | |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 308 | private: |
Mike Reed | 242135a | 2018-02-22 13:41:39 -0500 | [diff] [blame] | 309 | static bool AreRectAndRadiiValid(const SkRect&, const SkVector[4]); |
| 310 | |
bsalomon | 7f0d9f3 | 2016-08-15 14:49:10 -0700 | [diff] [blame] | 311 | SkRRect(const SkRect& rect, const SkVector radii[4], int32_t type) |
| 312 | : fRect(rect) |
| 313 | , fRadii{radii[0], radii[1], radii[2], radii[3]} |
| 314 | , fType(type) {} |
| 315 | |
Brian Salomon | 0a241ce | 2017-12-15 11:31:05 -0500 | [diff] [blame] | 316 | /** |
| 317 | * Initializes fRect. If the passed in rect is not finite or empty the rrect will be fully |
| 318 | * initialized and false is returned. Otherwise, just fRect is initialized and true is returned. |
| 319 | */ |
| 320 | bool initializeRect(const SkRect&); |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 321 | |
mtklein | 8aacf20 | 2014-12-18 13:29:54 -0800 | [diff] [blame] | 322 | void computeType(); |
robertphillips@google.com | 32c1b66 | 2013-04-25 12:23:00 +0000 | [diff] [blame] | 323 | bool checkCornerContainment(SkScalar x, SkScalar y) const; |
Cary Clark | 9b8b0ce | 2018-03-21 16:17:10 -0400 | [diff] [blame] | 324 | void scaleRadii(const SkRect& rect); |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 325 | |
Brian Salomon | 0a241ce | 2017-12-15 11:31:05 -0500 | [diff] [blame] | 326 | SkRect fRect = SkRect::MakeEmpty(); |
| 327 | // Radii order is UL, UR, LR, LL. Use Corner enum to index into fRadii[] |
| 328 | SkVector fRadii[4] = {{0, 0}, {0, 0}, {0,0}, {0,0}}; |
| 329 | // use an explicitly sized type so we're sure the class is dense (no uninitialized bytes) |
| 330 | int32_t fType = kEmpty_Type; |
| 331 | // TODO: add padding so we can use memcpy for flattening and not copy uninitialized data |
| 332 | |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 333 | // to access fRadii directly |
| 334 | friend class SkPath; |
Mike Reed | 242135a | 2018-02-22 13:41:39 -0500 | [diff] [blame] | 335 | friend class SkRRectPriv; |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 336 | }; |
| 337 | |
robertphillips@google.com | 8520301 | 2012-11-29 13:49:33 +0000 | [diff] [blame] | 338 | #endif |