aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/core/SkRRect.h
diff options
context:
space:
mode:
authorGravatar robertphillips <robertphillips@google.com>2015-09-29 11:24:07 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-09-29 11:24:07 -0700
commit05302f8f24cf0254e1fa713fbfc766387505e511 (patch)
tree40a6bc68a769be7150b7144d739d673526de43a3 /include/core/SkRRect.h
parent3d096654b910e52768d7335a0c2c7d7cd32c8bb7 (diff)
Handle inverted rects in SkRRect creation methods
An alternative way of addressing this is to alter SkCanvas::drawRoundRect to just reject isEmpty (i.e., un-sorted or truly empty) input rects. BUG=skia:3786 Review URL: https://codereview.chromium.org/1373293002
Diffstat (limited to 'include/core/SkRRect.h')
-rw-r--r--include/core/SkRRect.h16
1 files changed, 10 insertions, 6 deletions
diff --git a/include/core/SkRRect.h b/include/core/SkRRect.h
index 064e7be8e4..8d8cdbf02c 100644
--- a/include/core/SkRRect.h
+++ b/include/core/SkRRect.h
@@ -127,12 +127,14 @@ public:
* Set this RR to match the supplied rect. All radii will be 0.
*/
void setRect(const SkRect& rect) {
- if (rect.isEmpty()) {
+ fRect = rect;
+ fRect.sort();
+
+ if (fRect.isEmpty()) {
this->setEmpty();
return;
}
- fRect = rect;
memset(fRadii, 0, sizeof(fRadii));
fType = kRect_Type;
@@ -156,15 +158,17 @@ public:
* width and all y radii will equal half the height.
*/
void setOval(const SkRect& oval) {
- if (oval.isEmpty()) {
+ fRect = oval;
+ fRect.sort();
+
+ if (fRect.isEmpty()) {
this->setEmpty();
return;
}
- SkScalar xRad = SkScalarHalf(oval.width());
- SkScalar yRad = SkScalarHalf(oval.height());
+ SkScalar xRad = SkScalarHalf(fRect.width());
+ SkScalar yRad = SkScalarHalf(fRect.height());
- fRect = oval;
for (int i = 0; i < 4; ++i) {
fRadii[i].set(xRad, yRad);
}